@@ -23,6 +23,11 @@ public Form1()
23
23
}
24
24
25
25
private void Form1_Load ( object sender , EventArgs e )
26
+ {
27
+ Start ( ) ;
28
+ }
29
+
30
+ void Start ( )
26
31
{
27
32
SetStatus ( "Initializing.." ) ;
28
33
@@ -35,13 +40,7 @@ private void Form1_Load(object sender, EventArgs e)
35
40
SetStatus ( "Ready" ) ;
36
41
}
37
42
38
- // update settings window
39
- chkMinimizeToTaskbar . Checked = Properties . Settings . Default . minimizeToTaskbar ;
40
-
41
- // update installations folder listbox
42
- lstRootFolders . Items . AddRange ( Properties . Settings . Default . rootFolders . Cast < string > ( ) . ToArray ( ) ) ;
43
- // update packages folder listbox
44
- lstPackageFolders . Items . AddRange ( Properties . Settings . Default . packageFolders . Cast < string > ( ) . ToArray ( ) ) ;
43
+ LoadSettings ( ) ;
45
44
46
45
// scan installed unitys, TODO: could cache results, at least fileinfo's
47
46
bool foundedUnitys = ScanUnityInstallations ( ) ;
@@ -63,13 +62,17 @@ private void Form1_Load(object sender, EventArgs e)
63
62
SetStatus ( "Launching from commandline.." ) ;
64
63
65
64
var pathArg = args [ 2 ] ;
66
- // Console.WriteLine("\nPATH: " + pathArg);
67
65
LaunchProject ( pathArg ) ;
68
66
SetStatus ( "Ready" ) ;
67
+
68
+ // quit after launch if enabled in settings
69
+ if ( Properties . Settings . Default . closeAfterExplorer == true )
70
+ {
71
+ Application . Exit ( ) ;
72
+ }
69
73
}
70
74
else
71
75
{
72
- // Console.WriteLine("Invalid arguments:" + args[1]);
73
76
SetStatus ( "Error> Invalid arguments:" + args [ 1 ] ) ;
74
77
}
75
78
@@ -81,6 +84,18 @@ private void Form1_Load(object sender, EventArgs e)
81
84
gridRecent . Select ( ) ;
82
85
}
83
86
87
+ void LoadSettings ( )
88
+ {
89
+ // update settings window
90
+ chkMinimizeToTaskbar . Checked = Properties . Settings . Default . minimizeToTaskbar ;
91
+ chkQuitAfterCommandline . Checked = Properties . Settings . Default . closeAfterExplorer ;
92
+
93
+ // update installations folder listbox
94
+ lstRootFolders . Items . AddRange ( Properties . Settings . Default . rootFolders . Cast < string > ( ) . ToArray ( ) ) ;
95
+ // update packages folder listbox
96
+ lstPackageFolders . Items . AddRange ( Properties . Settings . Default . packageFolders . Cast < string > ( ) . ToArray ( ) ) ;
97
+ }
98
+
84
99
/// <summary>
85
100
/// returns true if we have exact version installed
86
101
/// </summary>
@@ -339,64 +354,64 @@ void LaunchProject(string pathArg = null)
339
354
}
340
355
}
341
356
357
+ // parse unity installer exe from release page
358
+ // thanks to https://github.com/softfruit
359
+ string GetDownloadUrlForUnityVersion ( string releaseUrl )
360
+ {
361
+ string url = "" ;
362
+ ServicePointManager . SecurityProtocol = SecurityProtocolType . Tls12 ;
363
+ using ( WebClient client = new WebClient ( ) )
364
+ {
365
+ string html = client . DownloadString ( releaseUrl ) ;
366
+ Regex regex = new Regex ( @"(http).+(UnityDownloadAssistant)+[^\s*]*(.exe)" ) ;
367
+ Match match = regex . Match ( html ) ;
368
+ url = match . Groups [ 0 ] . Captures [ 0 ] . Value ;
369
+ Console . WriteLine ( url ) ;
370
+ }
371
+ return url ;
372
+ }
373
+
342
374
/// <summary>
343
375
/// downloads unity installer and launches it
344
376
/// </summary>
345
377
/// <param name="url"></param>
346
378
void DownloadAndRun ( string url )
347
379
{
348
- ServicePointManager . SecurityProtocol = SecurityProtocolType . Tls12 ;
349
- using ( WebClient client = new WebClient ( ) )
350
- {
351
- string html = client . DownloadString ( url ) ;
380
+ string exeURL = GetDownloadUrlForUnityVersion ( url ) ;
352
381
353
- string foundedURL = "" ;
354
- var allLines = html . Split ( '\n ' ) ;
355
- for ( int i = 0 , length = allLines . Length ; i < length ; i ++ )
382
+ if ( string . IsNullOrEmpty ( exeURL ) == false )
383
+ {
384
+ SetStatus ( "Download installer: " + exeURL ) ;
385
+ // download temp file
386
+ using ( WebClient downloader = new WebClient ( ) )
356
387
{
357
- if ( allLines [ i ] . Contains ( "UnityDownloadAssistant" ) && allLines [ i ] . Contains ( ".exe" ) )
388
+ var f = GetFileNameFromUrl ( exeURL ) ;
389
+ FileInfo fileInfo = new FileInfo ( f ) ;
390
+ downloader . DownloadFile ( exeURL , f ) ;
391
+ if ( File . Exists ( fileInfo . FullName ) )
358
392
{
359
- var dlURL = allLines [ i ] . Split ( ' \" ' ) ;
360
- if ( dlURL . Length > 1 )
393
+ SetStatus ( "Running installer" ) ;
394
+ try
361
395
{
362
- Console . WriteLine ( dlURL [ 1 ] ) ;
363
- foundedURL = dlURL [ 1 ] ;
364
- break ;
396
+ Process myProcess = new Process ( ) ;
397
+ myProcess . StartInfo . FileName = fileInfo . FullName ;
398
+ myProcess . Start ( ) ;
399
+ myProcess . WaitForExit ( ) ;
365
400
}
366
- break ;
367
- }
368
- }
369
-
370
- if ( string . IsNullOrEmpty ( foundedURL ) == false )
371
- {
372
- // download temp file
373
- using ( WebClient downloader = new WebClient ( ) )
374
- {
375
- var f = GetFileNameFromUrl ( foundedURL ) ;
376
- FileInfo fileInfo = new FileInfo ( f ) ;
377
- downloader . DownloadFile ( foundedURL , f ) ;
378
- if ( File . Exists ( fileInfo . FullName ) )
401
+ catch ( Exception ex )
379
402
{
380
- try
381
- {
382
- Process myProcess = new Process ( ) ;
383
- myProcess . StartInfo . FileName = fileInfo . FullName ;
384
- myProcess . Start ( ) ;
385
- myProcess . WaitForExit ( ) ;
386
- }
387
- catch ( Exception ex )
388
- {
389
- Console . WriteLine ( ex ) ;
390
- }
391
-
403
+ Console . WriteLine ( ex ) ;
404
+ SetStatus ( "Failed running installer" ) ;
392
405
}
406
+
393
407
}
394
408
}
395
- else // not found
396
- {
397
- Console . WriteLine ( "Cannot parse exe.. opening website instead" ) ;
398
- Process . Start ( url ) ;
399
- }
409
+ SetStatus ( "Finished Running installer" ) ;
410
+ }
411
+ else // not found
412
+ {
413
+ SetStatus ( "Error> Cannot find installer exe.. opening website instead" ) ;
414
+ Process . Start ( url ) ;
400
415
}
401
416
}
402
417
@@ -407,6 +422,7 @@ void DownloadAndRun(string url)
407
422
/// <returns></returns>
408
423
string GetFileNameFromUrl ( string url )
409
424
{
425
+ Console . WriteLine ( url ) ;
410
426
var uri = new Uri ( url ) ;
411
427
var filename = uri . Segments . Last ( ) ;
412
428
return filename ;
@@ -786,5 +802,10 @@ private void btnAddRegister_Click(object sender, EventArgs e)
786
802
}
787
803
#endregion
788
804
805
+ private void chkQuitAfterCommandline_CheckedChanged ( object sender , EventArgs e )
806
+ {
807
+ Properties . Settings . Default . closeAfterExplorer = chkQuitAfterCommandline . Checked ;
808
+ Properties . Settings . Default . Save ( ) ;
809
+ }
789
810
}
790
811
}
0 commit comments