@@ -542,30 +542,73 @@ bool CheckCrashBackupScene(string projectPath)
542
542
543
543
// parse Unity installer exe from release page
544
544
// thanks to https://github.com/softfruit
545
- string GetDownloadUrlForUnityVersion ( string version )
545
+ string ParseDownloadURLFromWebpage ( string version )
546
546
{
547
547
string url = "" ;
548
548
549
549
using ( WebClient client = new WebClient ( ) )
550
550
{
551
- string htmlCode = client . DownloadString ( "https://unity3d.com/get-unity/download/archive" ) ;
552
- string [ ] lines = htmlCode . Split ( new [ ] { "\r \n " , "\r " , "\n " } , StringSplitOptions . None ) ;
553
-
554
- for ( int i = 0 ; i < lines . Length ; i ++ )
551
+ // get correct page url
552
+ string website = "https://unity3d.com/get-unity/download/archive" ;
553
+ if ( Tools . VersionIsPatch ( version ) ) website = "https://unity3d.com/unity/qa/patch-releases" ;
554
+ if ( Tools . VersionIsBeta ( version ) ) website = "https://unity3d.com/unity/beta/" + version ;
555
+ if ( Tools . VersionIsAlpha ( version ) ) website = "https://unity3d.com/unity/alpha/" + version ;
556
+
557
+ // download html
558
+ string sourceHTML = client . DownloadString ( website ) ;
559
+ string [ ] lines = sourceHTML . Split ( new [ ] { "\r \n " , "\r " , "\n " } , StringSplitOptions . None ) ;
560
+
561
+ // patch version download assistant finder
562
+ if ( Tools . VersionIsPatch ( version ) )
555
563
{
556
- if ( lines [ i ] . Contains ( "UnitySetup64-" + version ) )
564
+ for ( int i = 0 ; i < lines . Length ; i ++ )
557
565
{
558
- string line = lines [ i - 1 ] ;
559
- int start = line . IndexOf ( '"' ) + 1 ;
560
- int end = line . IndexOf ( '"' , start ) ;
561
- url = @"https://unity3d.com" + line . Substring ( start , end - start ) ;
562
- break ;
566
+ if ( lines [ i ] . Contains ( "UnityDownloadAssistant-" + version + ".exe" ) )
567
+ {
568
+ int start = lines [ i ] . IndexOf ( '"' ) + 1 ;
569
+ int end = lines [ i ] . IndexOf ( '"' , start ) ;
570
+ url = lines [ i ] . Substring ( start , end - start ) ;
571
+ break ;
572
+ }
573
+ }
574
+ }
575
+ else if ( Tools . VersionIsArchived ( version ) )
576
+ {
577
+ // archived version download assistant finder
578
+ for ( int i = 0 ; i < lines . Length ; i ++ )
579
+ {
580
+ // find line where full installer is (from archive page)
581
+ if ( lines [ i ] . Contains ( "UnitySetup64-" + version ) )
582
+ {
583
+ // take previous line, which contains download assistant url
584
+ string line = lines [ i - 1 ] ;
585
+ int start = line . IndexOf ( '"' ) + 1 ;
586
+ int end = line . IndexOf ( '"' , start ) ;
587
+ url = @"https://unity3d.com" + line . Substring ( start , end - start ) ;
588
+ break ;
589
+ }
590
+ }
591
+ }
592
+ else // alpha or beta version download assistant finder
593
+ {
594
+ for ( int i = 0 ; i < lines . Length ; i ++ )
595
+ {
596
+ if ( lines [ i ] . Contains ( "UnityDownloadAssistant.exe" ) )
597
+ {
598
+ int start = lines [ i ] . IndexOf ( '"' ) + 1 ;
599
+ int end = lines [ i ] . IndexOf ( '"' , start ) ;
600
+ url = lines [ i ] . Substring ( start , end - start ) + "#version=" + version ;
601
+ break ;
602
+ }
563
603
}
564
604
}
565
605
}
566
606
607
+ // didnt find installer
567
608
if ( string . IsNullOrEmpty ( url ) )
609
+ {
568
610
SetStatus ( "Cannot find UnityDownloadAssistant.exe for this version." ) ;
611
+ }
569
612
570
613
return url ;
571
614
}
@@ -576,7 +619,8 @@ string GetDownloadUrlForUnityVersion(string version)
576
619
/// <param name="url">full url to installer</param>
577
620
void DownloadInBrowser ( string url , string version )
578
621
{
579
- string exeURL = GetDownloadUrlForUnityVersion ( version ) ;
622
+ string exeURL = ParseDownloadURLFromWebpage ( version ) ;
623
+
580
624
if ( string . IsNullOrEmpty ( exeURL ) == false )
581
625
{
582
626
SetStatus ( "Download installer in browser: " + exeURL ) ;
0 commit comments