Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 19, 2021. It is now read-only.

Commit d068675

Browse files
fix alpha, beta and patch release download in browser links fixes #93
1 parent 718d0bc commit d068675

File tree

2 files changed

+83
-18
lines changed

2 files changed

+83
-18
lines changed

‎UnityLauncher/Form1.cs‎

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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(inti=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);

‎UnityLauncher/Tools.cs‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ public static bool OpenReleaseNotes(string version)
178178
public static string GetUnityReleaseURL(string version)
179179
{
180180
string url = "";
181-
182-
183-
if (version.Contains("f")) // archived
181+
if (VersionIsArchived(version))
184182
{
185183
// remove f#
186184
version = Regex.Replace(version, @"f.", "", RegexOptions.IgnoreCase);
@@ -199,24 +197,47 @@ public static string GetUnityReleaseURL(string version)
199197
url = "https://unity3d.com/unity/" + whatsnew + "/" + padding + version;
200198
}
201199
else
202-
if (version.Contains("p"))// patch version
200+
if (VersionIsPatch(version))
203201
{
204202
url = "https://unity3d.com/unity/qa/patch-releases/" + version;
205203
}
206204
else
207-
if (version.Contains("b"))// beta version
205+
if (VersionIsBeta(version))
208206
{
209207
url = "https://unity3d.com/unity/beta/" + version;
210208
}
211209
else
212-
if (version.Contains("a"))// alpha version
210+
if (VersionIsAlpha(version))
213211
{
214212
url = "https://unity3d.com/unity/alpha/" + version;
215213
}
216214

215+
Console.WriteLine(url);
216+
217217
return url;
218218
}
219219

220+
// if version contains *f* its archived version
221+
public static bool VersionIsArchived(string version)
222+
{
223+
return version.Contains("f");
224+
}
225+
226+
public static bool VersionIsPatch(string version)
227+
{
228+
return version.Contains("p");
229+
}
230+
231+
public static bool VersionIsBeta(string version)
232+
{
233+
return version.Contains("b");
234+
}
235+
236+
public static bool VersionIsAlpha(string version)
237+
{
238+
return version.Contains("a");
239+
}
240+
220241
/// <summary>
221242
/// uninstall context menu item from registry
222243
/// </summary>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /