Skip to content

Commit 454afeb

Browse files
committed
handle missing releases, comparing batches to all cached versions (since releases api is not in order)
1 parent 2b676ed commit 454afeb

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

Diff for: UnityLauncherPro/GetUnityUpdates.cs

+21-15
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ public static class GetUnityUpdates
2020
public static async Task<List<UnityVersion>> FetchAll()
2121
{
2222
var cachedVersions = LoadCachedVersions();
23-
//Console.WriteLine("cachedVersions: "+ cachedVersions);
24-
var latestCachedVersion = cachedVersions.FirstOrDefault();
25-
26-
//Console.WriteLine("FetchAll "+ latestCachedVersion);
27-
var newVersions = await FetchNewVersions(latestCachedVersion);
28-
//Console.WriteLine("newVersions " + newVersions);
23+
var newVersions = await FetchNewVersions(cachedVersions);
2924

3025
var allVersions = newVersions.Concat(cachedVersions).ToList();
3126

@@ -34,8 +29,6 @@ public static async Task<List<UnityVersion>> FetchAll()
3429
SaveCachedVersions(allVersions);
3530
}
3631

37-
//Console.WriteLine("all "+ allVersions);
38-
3932
return allVersions;
4033
}
4134

@@ -62,7 +55,6 @@ public static async Task<string> FetchDownloadUrl(string unityVersion)
6255

6356
private static async Task<string> ExtractDownloadUrlAsync(string json, string unityVersion)
6457
{
65-
6658
int resultsIndex = json.IndexOf("\"results\":");
6759
if (resultsIndex == -1) return null;
6860

@@ -122,28 +114,39 @@ private static async Task<bool> CheckAssistantUrl(string assistantUrl)
122114
}
123115
}
124116

125-
private static async Task<List<UnityVersion>> FetchNewVersions(UnityVersion latestCachedVersion)
117+
private static async Task<List<UnityVersion>> FetchNewVersions(List<UnityVersion> cachedVersions)
126118
{
127119
var newVersions = new List<UnityVersion>();
120+
var cachedVersionSet = new HashSet<string>(cachedVersions.Select(v => v.Version));
128121
int offset = 0;
129122
int total = int.MaxValue;
123+
bool foundNewVersionInBatch;
130124

131125
while (offset < total)
132126
{
133127
var batchUpdates = await FetchBatch(offset);
134-
if (batchUpdates == null || batchUpdates.Count == 0)
135-
break;
128+
if (batchUpdates == null || batchUpdates.Count == 0) break;
129+
130+
foundNewVersionInBatch = false;
136131

137132
foreach (var version in batchUpdates)
138133
{
139-
if (version.Version == latestCachedVersion?.Version)
140-
return newVersions;
134+
if (!cachedVersionSet.Contains(version.Version))
135+
{
136+
newVersions.Add(version);
137+
foundNewVersionInBatch = true;
138+
}
139+
}
141140

142-
newVersions.Add(version);
141+
if (!foundNewVersionInBatch)
142+
{
143+
// Exit if no new versions are found in the current batch
144+
break;
143145
}
144146

145147
offset += batchUpdates.Count;
146148

149+
// Apply delay if reaching batch limit
147150
if (offset % (BatchSize * RequestsPerBatch) == 0)
148151
{
149152
await Task.Delay(DelayBetweenBatches);
@@ -153,6 +156,8 @@ private static async Task<List<UnityVersion>> FetchNewVersions(UnityVersion late
153156
return newVersions;
154157
}
155158

159+
160+
156161
private static async Task<List<UnityVersion>> FetchBatch(int offset)
157162
{
158163
string url = $"{BaseApiUrl}?limit={BatchSize}&offset={offset}&architecture=X86_64&platform=WINDOWS";
@@ -187,6 +192,7 @@ private static List<UnityVersion> ParseUnityVersions(string json)
187192
ReleaseDate = DateTime.TryParse(GetStringValue(item, "releaseDate"), out var date) ? date : default,
188193
Stream = Enum.TryParse<UnityVersionStream>(GetStringValue(item, "stream"), true, out var stream) ? stream : UnityVersionStream.Tech
189194
};
195+
//Console.WriteLine(version.Version);
190196
versions.Add(version);
191197
}
192198
}

Diff for: UnityLauncherPro/Tools.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ public static Process LaunchExe(string path, string param = null)
520520
}
521521
return newProcess;
522522
}
523-
Console.WriteLine("Failed to run exe: " + path + " " + param);
524-
return null;
523+
// Console.WriteLine("Failed to run exe: " + path + " " + param);
524+
// return null;
525525
}
526526

527527

@@ -868,8 +868,6 @@ public static string CleanVersionNumber(string version)
868868

869869
private static string FetchUnityVersionNumberFromHTML(string url)
870870
{
871-
string version = null;
872-
873871
string sourceHTML = DownloadHTML(url);
874872

875873
if (string.IsNullOrEmpty(sourceHTML)) return null;
@@ -882,7 +880,7 @@ private static string FetchUnityVersionNumberFromHTML(string url)
882880
{
883881
Console.WriteLine("Extracted number: " + match.Value);
884882
return match.Value;
885-
break;
883+
//break;
886884
}
887885
}
888886
else
@@ -902,7 +900,7 @@ private static string FetchUnityVersionNumberFromHTML(string url)
902900
// version = match.Value.Replace("UnityDownloadAssistant-", "").Replace(".exe", "");
903901
// }
904902
//}
905-
return version;
903+
//return version;
906904
}
907905

908906
public static string FindNearestVersion(string currentVersion, List<string> allAvailable, bool checkBelow = false)

0 commit comments

Comments
 (0)