@@ -20,12 +20,7 @@ public static class GetUnityUpdates
2020public static async Task < List < UnityVersion > > FetchAll ( )
2121{
2222var 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
3025var allVersions = newVersions . Concat ( cachedVersions ) . ToList ( ) ;
3126
@@ -34,8 +29,6 @@ public static async Task<List<UnityVersion>> FetchAll()
3429SaveCachedVersions ( allVersions ) ;
3530}
3631
37- //Console.WriteLine("all "+ allVersions);
38-
3932return allVersions ;
4033}
4134
@@ -62,7 +55,6 @@ public static async Task<string> FetchDownloadUrl(string unityVersion)
6255
6356private static async Task < string > ExtractDownloadUrlAsync ( string json , string unityVersion )
6457{
65-
6658int resultsIndex = json . IndexOf ( "\" results\" :" ) ;
6759if ( 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{
127119var newVersions = new List < UnityVersion > ( ) ;
120+ var cachedVersionSet = new HashSet < string > ( cachedVersions . Select ( v=> v . Version ) ) ;
128121int offset = 0 ;
129122int total = int . MaxValue ;
123+ bool foundNewVersionInBatch ;
130124
131125while ( offset < total )
132126{
133127var 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
137132foreach ( 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
145147offset += batchUpdates . Count ;
146148
149+ // Apply delay if reaching batch limit
147150if ( offset % ( BatchSize * RequestsPerBatch ) == 0 )
148151{
149152await Task . Delay ( DelayBetweenBatches ) ;
@@ -153,6 +156,8 @@ private static async Task<List<UnityVersion>> FetchNewVersions(UnityVersion late
153156return newVersions ;
154157}
155158
159+
160+
156161private static async Task < List < UnityVersion > > FetchBatch ( int offset )
157162{
158163string url = $ "{ BaseApiUrl } ?limit={ BatchSize } &offset={ offset } &architecture=X86_64&platform=WINDOWS";
@@ -187,6 +192,7 @@ private static List<UnityVersion> ParseUnityVersions(string json)
187192ReleaseDate = DateTime . TryParse ( GetStringValue ( item , "releaseDate" ) , out var date ) ? date : default ,
188193Stream = Enum . TryParse < UnityVersionStream > ( GetStringValue ( item , "stream" ) , true , out var stream ) ? stream : UnityVersionStream . Tech
189194} ;
195+ //Console.WriteLine(version.Version);
190196versions . Add ( version ) ;
191197}
192198}