Skip to content

Commit 710e14d

Browse files
committed
add full installer exe download option to DownloadInBrowser(), add await for extract urls (got stuck otherwise),
1 parent ca48d57 commit 710e14d

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

Diff for: UnityLauncherPro/GetUnityUpdates.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static async Task<string> FetchDownloadUrl(string unityVersion)
5151
try
5252
{
5353
string responseString = await Client.GetStringAsync(apiUrl);
54-
return ExtractDownloadUrl(responseString, unityVersion);
54+
return await ExtractDownloadUrlAsync(responseString, unityVersion);
5555
}
5656
catch (Exception e)
5757
{
@@ -60,8 +60,9 @@ public static async Task<string> FetchDownloadUrl(string unityVersion)
6060
}
6161
}
6262

63-
private static string ExtractDownloadUrl(string json, string unityVersion)
63+
private static async Task<string> ExtractDownloadUrlAsync(string json, string unityVersion)
6464
{
65+
6566
int resultsIndex = json.IndexOf("\"results\":");
6667
if (resultsIndex == -1) return null;
6768

@@ -87,10 +88,9 @@ private static string ExtractDownloadUrl(string json, string unityVersion)
8788
if (!string.IsNullOrEmpty(downloadUrl) && !string.IsNullOrEmpty(shortRevision))
8889
{
8990
int revisionPosition = downloadUrl.LastIndexOf(shortRevision, StringComparison.Ordinal) + shortRevision.Length + 1;
90-
string assistantUrl = downloadUrl.Substring(0, revisionPosition) +
91-
$"UnityDownloadAssistant-{unityVersion}.exe";
91+
string assistantUrl = downloadUrl.Substring(0, revisionPosition) + $"UnityDownloadAssistant-{unityVersion}.exe";
9292

93-
if (CheckAssistantUrl(assistantUrl).Result)
93+
if (await CheckAssistantUrl(assistantUrl))
9494
{
9595
Console.WriteLine("Assistant download URL found.");
9696
return assistantUrl;
@@ -115,8 +115,9 @@ private static async Task<bool> CheckAssistantUrl(string assistantUrl)
115115
return response.IsSuccessStatusCode;
116116
}
117117
}
118-
catch
118+
catch (Exception ex)
119119
{
120+
Console.WriteLine($"Request failed: {ex.Message}");
120121
return false;
121122
}
122123
}

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ private void BtnDownloadInBrowser_Click(object sender, RoutedEventArgs e)
15171517
private void BtnDownloadInBrowserFull_Click(object sender, RoutedEventArgs e)
15181518
{
15191519
var unity = GetSelectedUpdate();
1520-
Tools.DownloadInBrowser(unity?.Version);
1520+
Tools.DownloadInBrowser(unity?.Version, true);
15211521
}
15221522

15231523
private void btnDownloadInstallUpdate_Click(object sender, RoutedEventArgs e)

Diff for: UnityLauncherPro/Tools.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,16 @@ public static void OpenURL(string url)
659659
Process.Start(url);
660660
}
661661

662-
public static async void DownloadInBrowser(string version)
662+
public static async void DownloadInBrowser(string version, bool preferFullInstaller = false)
663663
{
664664
if (version == null) return;
665665
string exeURL = await GetUnityUpdates.FetchDownloadUrl(version);
666666

667+
if (preferFullInstaller == true)
668+
{
669+
exeURL = exeURL.Replace("UnityDownloadAssistant-" + version + ".exe", "Windows64EditorInstaller/UnitySetup64-" + version + ".exe");
670+
}
671+
667672
Console.WriteLine("DownloadInBrowser exeURL= '" + exeURL + "'");
668673

669674
if (string.IsNullOrEmpty(exeURL) == false && exeURL.StartsWith("https"))

0 commit comments

Comments
 (0)