@@ -542,30 +542,73 @@ bool CheckCrashBackupScene(string projectPath)
542542
543543 // parse Unity installer exe from release page
544544 // thanks to https://github.com/softfruit
545- string GetDownloadUrlForUnityVersion ( string version )
545+ string ParseDownloadURLFromWebpage ( string version )
546546 {
547547 string url = "" ;
548548
549549 using ( WebClient client = new WebClient ( ) )
550550 {
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 ) )
555563 {
556- if ( lines [ i ] . Contains ( "UnitySetup64-" + version ) )
564+ for ( int i = 0 ; i < lines . Length ; i ++ )
557565 {
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+ }
563603 }
564604 }
565605 }
566606
607+ // didnt find installer
567608 if ( string . IsNullOrEmpty ( url ) )
609+ {
568610 SetStatus ( "Cannot find UnityDownloadAssistant.exe for this version." ) ;
611+ }
569612
570613 return url ;
571614 }
@@ -576,7 +619,8 @@ string GetDownloadUrlForUnityVersion(string version)
576619 /// <param name="url">full url to installer</param>
577620 void DownloadInBrowser ( string url , string version )
578621 {
579- string exeURL = GetDownloadUrlForUnityVersion ( version ) ;
622+ string exeURL = ParseDownloadURLFromWebpage ( version ) ;
623+
580624 if ( string . IsNullOrEmpty ( exeURL ) == false )
581625 {
582626 SetStatus ( "Download installer in browser: " + exeURL ) ;
0 commit comments