@@ -20,12 +20,7 @@ public static class GetUnityUpdates
20
20
public static async Task < List < UnityVersion > > FetchAll ( )
21
21
{
22
22
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 ) ;
29
24
30
25
var allVersions = newVersions . Concat ( cachedVersions ) . ToList ( ) ;
31
26
@@ -34,8 +29,6 @@ public static async Task<List<UnityVersion>> FetchAll()
34
29
SaveCachedVersions ( allVersions ) ;
35
30
}
36
31
37
- //Console.WriteLine("all "+ allVersions);
38
-
39
32
return allVersions ;
40
33
}
41
34
@@ -62,7 +55,6 @@ public static async Task<string> FetchDownloadUrl(string unityVersion)
62
55
63
56
private static async Task < string > ExtractDownloadUrlAsync ( string json , string unityVersion )
64
57
{
65
-
66
58
int resultsIndex = json . IndexOf ( "\" results\" :" ) ;
67
59
if ( resultsIndex == - 1 ) return null ;
68
60
@@ -122,28 +114,39 @@ private static async Task<bool> CheckAssistantUrl(string assistantUrl)
122
114
}
123
115
}
124
116
125
- private static async Task < List < UnityVersion > > FetchNewVersions ( UnityVersion latestCachedVersion )
117
+ private static async Task < List < UnityVersion > > FetchNewVersions ( List < UnityVersion > cachedVersions )
126
118
{
127
119
var newVersions = new List < UnityVersion > ( ) ;
120
+ var cachedVersionSet = new HashSet < string > ( cachedVersions . Select ( v => v . Version ) ) ;
128
121
int offset = 0 ;
129
122
int total = int . MaxValue ;
123
+ bool foundNewVersionInBatch ;
130
124
131
125
while ( offset < total )
132
126
{
133
127
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 ;
136
131
137
132
foreach ( var version in batchUpdates )
138
133
{
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
+ }
141
140
142
- newVersions . Add ( version ) ;
141
+ if ( ! foundNewVersionInBatch )
142
+ {
143
+ // Exit if no new versions are found in the current batch
144
+ break ;
143
145
}
144
146
145
147
offset += batchUpdates . Count ;
146
148
149
+ // Apply delay if reaching batch limit
147
150
if ( offset % ( BatchSize * RequestsPerBatch ) == 0 )
148
151
{
149
152
await Task . Delay ( DelayBetweenBatches ) ;
@@ -153,6 +156,8 @@ private static async Task<List<UnityVersion>> FetchNewVersions(UnityVersion late
153
156
return newVersions ;
154
157
}
155
158
159
+
160
+
156
161
private static async Task < List < UnityVersion > > FetchBatch ( int offset )
157
162
{
158
163
string url = $ "{ BaseApiUrl } ?limit={ BatchSize } &offset={ offset } &architecture=X86_64&platform=WINDOWS";
@@ -187,6 +192,7 @@ private static List<UnityVersion> ParseUnityVersions(string json)
187
192
ReleaseDate = DateTime . TryParse ( GetStringValue ( item , "releaseDate" ) , out var date ) ? date : default ,
188
193
Stream = Enum . TryParse < UnityVersionStream > ( GetStringValue ( item , "stream" ) , true , out var stream ) ? stream : UnityVersionStream . Tech
189
194
} ;
195
+ //Console.WriteLine(version.Version);
190
196
versions . Add ( version ) ;
191
197
}
192
198
}
0 commit comments