Skip to content

Commit 64cc970

Browse files
committed
Try to download the download assistant by default
1 parent 4678cbf commit 64cc970

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

UnityLauncherPro/GetUnityUpdates.cs

+23-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class GetUnityUpdates
1818
private const int DelayBetweenBatches = 1000; // 1 second in milliseconds
1919
private const string CacheFileName = "UnityVersionCache.json";
2020

21-
private static readonly HttpClient httpClient = new HttpClient();
21+
private static readonly HttpClient Client = new HttpClient();
2222

2323
public static async Task<List<UnityVersion>> FetchAll()
2424
{
@@ -37,7 +37,7 @@ public static async Task<List<UnityVersion>> FetchAll()
3737
return allVersions;
3838
}
3939

40-
public static async Task<string> FetchDownloadUrl(string unityVersion, bool assistantUrl = false)
40+
public static async Task<string> FetchDownloadUrl(string unityVersion)
4141
{
4242
if (string.IsNullOrEmpty(unityVersion))
4343
{
@@ -48,7 +48,7 @@ public static async Task<string> FetchDownloadUrl(string unityVersion, bool assi
4848

4949
try
5050
{
51-
string responseString = await httpClient.GetStringAsync(apiUrl);
51+
string responseString = await Client.GetStringAsync(apiUrl);
5252
JsonDocument doc = JsonDocument.Parse(responseString);
5353
try
5454
{
@@ -75,21 +75,37 @@ public static async Task<string> FetchDownloadUrl(string unityVersion, bool assi
7575

7676
if (!string.IsNullOrEmpty(downloadUrl))
7777
{
78-
if (!assistantUrl) return downloadUrl;
79-
8078
if (!string.IsNullOrEmpty(shortRevision))
8179
{
8280
var startIndex = downloadUrl.LastIndexOf(shortRevision, StringComparison.Ordinal) + shortRevision.Length + 1;
8381
var endIndex = downloadUrl.Length - startIndex;
84-
return downloadUrl.Replace(downloadUrl.Substring(startIndex, endIndex),
82+
var assistantUrl = downloadUrl.Replace(downloadUrl.Substring(startIndex, endIndex),
8583
$"UnityDownloadAssistant-{unityVersion}.exe");
84+
using (var assistantResponse = await Client.GetAsync(assistantUrl))
85+
{
86+
if (assistantResponse.IsSuccessStatusCode)
87+
{
88+
Console.WriteLine("Assistant download URL found.");
89+
return assistantUrl;
90+
}
91+
else
92+
{
93+
Console.WriteLine("Assistant download URL not found, returning original download URL.");
94+
return downloadUrl;
95+
}
96+
}
8697
}
8798
else
8899
{
89100
Console.WriteLine("ShortRevision not found, returning original download URL.");
90101
return downloadUrl;
91102
}
92103
}
104+
else
105+
{
106+
Console.WriteLine("No download URL found.");
107+
return downloadUrl;
108+
}
93109
}
94110

95111
Console.WriteLine($"No download URL found for version {unityVersion}");
@@ -145,7 +161,7 @@ private static async Task<UnityVersionResponse> FetchBatch(int offset)
145161

146162
try
147163
{
148-
var response = await httpClient.GetStringAsync(url);
164+
var response = await Client.GetStringAsync(url);
149165
return JsonSerializer.Deserialize<UnityVersionResponse>(response);
150166
}
151167
catch (Exception e)

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, true);
1520+
Tools.DownloadInBrowser(unity?.Version);
15211521
}
15221522

15231523
private void btnDownloadInstallUpdate_Click(object sender, RoutedEventArgs e)

UnityLauncherPro/Tools.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -659,14 +659,14 @@ public static void OpenURL(string url)
659659
Process.Start(url);
660660
}
661661

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

667667
Console.WriteLine("DownloadInBrowser exeURL= '" + exeURL + "'");
668668

669-
if (string.IsNullOrEmpty(exeURL) == false && exeURL.StartsWith("https") == true)
669+
if (string.IsNullOrEmpty(exeURL) == false && exeURL.StartsWith("https"))
670670
{
671671
//SetStatus("Download installer in browser: " + exeURL);
672672
Process.Start(exeURL);
@@ -2255,7 +2255,10 @@ private static async Task<bool> DownloadFileAsync(string fileUrl, string destina
22552255
}
22562256
finally
22572257
{
2258-
DeleteTempFile(destinationPath);
2258+
if (!result)
2259+
{
2260+
DeleteTempFile(destinationPath);
2261+
}
22592262
progressWindow.Close();
22602263
}
22612264
return result;

UnityLauncherPro/UpgradeWindow.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private void BtnOpenReleasePage_Click(object sender, RoutedEventArgs e)
7878

7979
private void BtnDownloadEditor_Click(object sender, RoutedEventArgs e)
8080
{
81-
Tools.DownloadInBrowser(txtCurrentVersion.Text, true);
81+
Tools.DownloadInBrowser(txtCurrentVersion.Text);
8282
}
8383

8484
private void BtnDownload_Click(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)