77
88// VS is a slow POS
99
10+ static class SubstringExtensions
11+ {
12+ public static string EncloseWithQuoteMarks ( this string value )
13+ {
14+ return '"' + value + '"' ;
15+ }
16+
17+ public static string Between ( this string value , string a , string b )
18+ {
19+ int posA = value . IndexOf ( a ) ;
20+ int posB = value . LastIndexOf ( b ) ;
21+ if ( posA == - 1 )
22+ {
23+ return "" ;
24+ }
25+ if ( posB == - 1 )
26+ {
27+ return "" ;
28+ }
29+ int adjustedPosA = posA + a . Length ;
30+ if ( adjustedPosA >= posB )
31+ {
32+ return "" ;
33+ }
34+ return value . Substring ( adjustedPosA , posB - adjustedPosA ) ;
35+ }
36+
37+ /// <summary>
38+ /// Get string value after [first] a.
39+ /// </summary>
40+ public static string Before ( this string value , string a )
41+ {
42+ int posA = value . IndexOf ( a ) ;
43+ if ( posA == - 1 )
44+ {
45+ return "" ;
46+ }
47+ return value . Substring ( 0 , posA ) ;
48+ }
49+
50+ /// <summary>
51+ /// Get string value after [last] a.
52+ /// </summary>
53+ public static string After ( this string value , string a )
54+ {
55+ int posA = value . LastIndexOf ( a ) ;
56+ if ( posA == - 1 )
57+ {
58+ return "" ;
59+ }
60+ int adjustedPosA = posA + a . Length ;
61+ if ( adjustedPosA >= value . Length )
62+ {
63+ return "" ;
64+ }
65+ return value . Substring ( adjustedPosA ) ;
66+ }
67+ }
1068class Program
1169{
1270 static byte [ ] logoBits = {
@@ -149,12 +207,22 @@ static void Main(string[] args)
149207 Directory . SetCurrentDirectory ( dir ) ; // make path ensuring less redundant like in the launcher
150208
151209 // is this even in the right place
152- if ( ! File . Exists ( "FastGH3.exe" ) ||
153- ! File . Exists ( "game.exe" ) ||
154- ! File . Exists ( "fmodex.dll" ) )
210+ string [ ] requiredFiles = new string [ ] {
211+ "AWL.dll" ,
212+ "binkw32.dll" ,
213+ "FastGH3.exe" ,
214+ "fmodex.dll" ,
215+ "game.exe" ,
216+ "Ionic.Zip.dll" ,
217+ "mid2chart.exe" ,
218+ } ;
219+ foreach ( string i in requiredFiles )
155220 {
156- Console . WriteLine ( "No familiar mod files can be found, exiting..." ) ;
157- return ;
221+ if ( ! File . Exists ( dir + i ) ) // EXCEPT HERE SOMEHOW
222+ {
223+ Console . WriteLine ( "No familiar files can be found, exiting..." ) ;
224+ return ;
225+ }
158226 }
159227
160228 DateTime buildtime = new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
@@ -187,22 +255,22 @@ static void Main(string[] args)
187255
188256 Console . WriteLine ( "Downloading version info..." ) ;
189257 uint latestTimestamp = 0 ;
258+ uint latestVerTime = 0 ;
190259 JSONNode devVers , buildList ;
260+ WebClient fetcher = new WebClient ( ) ;
191261 try
192262 {
193- using ( WebClient fetcher = new WebClient ( ) )
194- {
195- fetcher . Proxy = null ;
196- fetcher . Headers . Add ( "user-agent" , "Anything" ) ;
197- ServicePointManager . SecurityProtocol = ( SecurityProtocolType ) ( 0xc0 | 0x300 | 0xc00 ) ;
198- latestTimestamp = Eswap ( BitConverter . ToUInt32 ( fetcher . DownloadData ( "https://raw.githubusercontent.com/donnaken15/FastGH3/main/DATA/MUSIC/TOOLS/bt.bin" ) , 0 ) ) ;
199- latesttime = latesttime . AddSeconds ( latestTimestamp ) . ToLocalTime ( ) ;
200- Console . WriteLine ( "Build timestamp: " + buildtime . ToString ( ) ) ;
201- Console . WriteLine ( "Got latest timestamp: " + latesttime . ToString ( ) ) ;
202- devVers = JSON . Parse ( fetcher . DownloadString ( "https://donnaken15.tk/fastgh3/devvers.json" ) ) ;
203- buildList = JSON . Parse ( fetcher . DownloadString ( "https://donnaken15.tk/fastgh3/vl.json" ) ) ;
204- latestname = Encoding . UTF8 . GetString ( Convert . FromBase64String ( fetcher . DownloadString ( "https://donnaken15.tk/fastgh3/v" ) ) ) ;
205- }
263+ fetcher . Proxy = null ;
264+ fetcher . Headers . Add ( "user-agent" , "Anything" ) ;
265+ ServicePointManager . SecurityProtocol = ( SecurityProtocolType ) ( 0xc0 | 0x300 | 0xc00 ) ;
266+ latestTimestamp = Eswap ( BitConverter . ToUInt32 ( fetcher . DownloadData ( "https://raw.githubusercontent.com/donnaken15/FastGH3/main/DATA/MUSIC/TOOLS/bt.bin" ) , 0 ) ) ;
267+ latesttime = latesttime . AddSeconds ( latestTimestamp ) . ToLocalTime ( ) ;
268+ Console . WriteLine ( "Build timestamp: " + buildtime . ToString ( ) ) ;
269+ Console . WriteLine ( "Got latest timestamp: " + latesttime . ToString ( ) ) ;
270+ devVers = JSON . Parse ( fetcher . DownloadString ( "https://donnaken15.tk/fastgh3/devvers.json" ) ) ;
271+ buildList = JSON . Parse ( fetcher . DownloadString ( "https://donnaken15.tk/fastgh3/vl.json" ) ) ;
272+ latestname = Encoding . UTF8 . GetString ( Convert . FromBase64String ( fetcher . DownloadString ( "https://donnaken15.tk/fastgh3/v" ) ) ) ;
273+ //latestVerTime = Convert.ToUInt32(Convert.FromBase64String(fetcher.DownloadString("https://raw.githubusercontent.com/donnaken15/FastGH3/main/DATA/MUSIC/TOOLS/v.bin")));
206274 }
207275 catch ( Exception ex )
208276 {
@@ -228,11 +296,42 @@ static void Main(string[] args)
228296 // also TODO: downgrading maybe for checking errors and for when they started to appear
229297 // as a consequence of me making this mod the most user friendly for charts
230298
299+ string [ ] blacklist = new string [ ] {
300+ "aspyrconfig.bat" ,
301+ "settings.ini" ,
302+ "data\\ user.pak.xen" ,
303+ "data\\ movies\\ bik\\ backgrnd_video.bik.xen" ,
304+ "data\\ music\\ fastgh3.fsb.xen" ,
305+ "data\\ pak\\ dbg.pak.xen" ,
306+ "data\\ pak\\ player.pak.xen" ,
307+ "data\\ pak\\ song.pak.xen" ,
308+ "data\\ pak\\ global.pab.xen" ,
309+ "data\\ pak\\ global.pak.xen" ,
310+ "data\\ pak\\ global_sfx.pak.xen" ,
311+ "ionic.zip.dll" ,
312+ "updater.exe" ,
313+ ".gitignore" ,
314+ ".gitmodules" ,
315+ // TODO: check for if this is the default PAK
316+ // in case of a later occurence of being
317+ // able to remove more unneeded stuff like the
318+ // thousands of blank textures and new menu
319+ // no longer using older textures
320+ } ;
321+
322+ ZipFile buildZip ;
323+ string zipPath = Path . GetTempPath ( ) + "\\ FGH3_UPD.ZIP" ;
324+ string zipURL = "https://github.com/donnaken15/FastGH3/releases/latest/download/FastGH3_1.0.zip" ;
325+
326+ // TODO: display changes since
327+ // TODO: also update updater.exe to update this
328+ // update the updater :^)
231329 if ( bleeding )
232330 {
233331 if ( latesttime > buildtime )
234332 {
235333 Console . WriteLine ( "Found a new dev build!" ) ;
334+ zipURL = "https://github.com/donnaken15/FastGH3/archive/refs/heads/main.zip" ;
236335 }
237336 else
238337 {
@@ -257,6 +356,53 @@ static void Main(string[] args)
257356 return ;
258357 }
259358 }
359+ fetcher . DownloadFile ( new Uri ( zipURL ) , zipPath ) ;
360+ buildZip = ZipFile . Read ( zipPath ) ;
361+ foreach ( ZipEntry f in buildZip )
362+ {
363+ try {
364+ if ( f . IsDirectory ) continue ;
365+ bool ugh = false ;
366+ string truename = f . FileName . ToLower ( ) ;
367+ if ( bleeding )
368+ {
369+ truename = truename . After ( "fastgh3-main/" ) ;
370+ }
371+ if ( truename . StartsWith ( "source/" ) ) continue ;
372+ if ( truename . StartsWith ( ".github/" ) ) continue ;
373+ truename = truename . Replace ( "/" , "\\ " ) ;
374+ foreach ( string g in blacklist )
375+ {
376+ if ( truename == g )
377+ {
378+ ugh = true ;
379+ break ;
380+ }
381+ }
382+ if ( ugh ) continue ;
383+ f . ExtractExistingFile = ExtractExistingFileAction . OverwriteSilently ;
384+ f . Extract ( ) ;
385+ if ( bleeding )
386+ {
387+ File . Copy ( "FastGH3-main\\ " + truename , truename , true ) ;
388+ File . Delete ( "FastGH3-main\\ " + truename ) ;
389+ // NET is the worst thing ever
390+ // READ THESE REMARKS, THESE DEVS ARE INSANE!!!!
391+ // https://learn.microsoft.com/en-us/dotnet/api/system.io.file.move?view=netframework-4.0#system-io-file-move(system-string-system-string-system-boolean)
392+ }
393+ }
394+ catch ( Exception ex )
395+ {
396+ Console . WriteLine ( "Error occured from extracting " + f . FileName ) ;
397+ Console . WriteLine ( ex ) ;
398+ }
399+ }
400+ if ( bleeding )
401+ {
402+ Directory . Delete ( "FastGH3-main\\ " , true ) ;
403+ }
404+ buildZip . Dispose ( ) ;
405+ File . Delete ( zipPath ) ;
260406 Console . WriteLine ( "Done." ) ;
261407 Console . ReadKey ( ) ;
262408 }
0 commit comments