@@ -16,6 +16,7 @@ public static class GetUnityUpdates
1616 private const int DelayBetweenBatches = 1000 ; // 1 second in milliseconds
1717 private const string CacheFileName = "UnityVersionCache.json" ;
1818 private static readonly HttpClient Client = new HttpClient ( ) ;
19+ public static string unofficalReleasesURL = "https://raw.githubusercontent.com/unitycoder/UnofficialUnityReleasesWatcher/refs/heads/main/unity-releases.md" ;
1920
2021 static Dictionary < string , string > unofficialReleaseURLs = new Dictionary < string , string > ( ) ;
2122
@@ -30,15 +31,19 @@ public static async Task<List<UnityVersion>> FetchAll(bool useUnofficialList = f
3031 {
3132 var unofficialVersions = await FetchUnofficialVersions ( cachedVersions ) ;
3233 unofficialReleaseURLs . Clear ( ) ;
33- // TODO modify FetchUnofficialVersions to put items in this dictionary directlys
34+
35+ // TODO modify FetchUnofficialVersions to put items in this dictionary directly
3436 foreach ( var version in unofficialVersions )
3537 {
36- //Console.WriteLine("unofficial: " + version.Version + " , " + version.directURL);
38+ Console . WriteLine ( "version in unofficials: " + version ) ;
39+ // add only if not there yet
3740 if ( unofficialReleaseURLs . ContainsKey ( version . Version ) == false )
3841 {
42+ Console . WriteLine ( "added unofficial: " + version . Version + " , " + version . directURL ) ;
3943 unofficialReleaseURLs . Add ( version . Version , version . directURL ) ;
4044 }
4145 }
46+ // combine
4247 allVersions = unofficialVersions . Concat ( allVersions ) . ToList ( ) ;
4348 }
4449
@@ -58,23 +63,28 @@ public static async Task<List<UnityVersion>> FetchUnofficialVersions(List<UnityV
5863
5964 try
6065 {
61- string url = "https://raw.githubusercontent.com/unitycoder/UnofficialUnityReleasesWatcher/refs/heads/main/unity-releases.md" ;
62-
63- var content = await Client . GetStringAsync ( url ) ;
66+ var content = await Client . GetStringAsync ( unofficalReleasesURL ) ;
6467
6568 // Parse the Markdown content
6669 var lines = content . Split ( new [ ] { '\n ' , '\r ' } , StringSplitOptions . RemoveEmptyEntries ) ;
6770 foreach ( var line in lines )
6871 {
72+ //Console.WriteLine(line);
73+
6974 if ( line . StartsWith ( "- " ) ) // Identify Markdown list items
7075 {
71- var urlPart = line . Substring ( 2 ) . Trim ( ) ;
76+ var urlPart = line . Substring ( 4 ) . Trim ( ) ; // bug in server, has double -
7277 var version = ExtractVersionFromUrl ( urlPart ) ;
7378
74- if ( ! string . IsNullOrEmpty ( version ) && ! existingVersions . Contains ( version ) )
79+ //Console.WriteLine("VERSION: " + version);
80+ //Console.WriteLine("IsNullOrEmpty: " + (string.IsNullOrEmpty(version)) + ", existingVersions:" + (existingVersions.Contains(version)));
81+
82+ if ( string . IsNullOrEmpty ( version ) == false && existingVersions . Contains ( version ) == false )
7583 {
7684 var stream = InferStreamFromVersion ( version ) ;
7785
86+ Console . WriteLine ( version + " , " + urlPart ) ;
87+
7888 unofficialVersions . Add ( new UnityVersion
7989 {
8090 Version = version ,
@@ -148,28 +158,25 @@ public static async Task<string> FetchDownloadUrl(string unityVersion)
148158 }
149159 }
150160
151- static string ParseHashCodeFromURL ( string url )
152- {
153- // https://beta.unity3d.com/download/330fbefc18b7/download.html#6000.1.0a8 > 330fbefc18b7
154-
155- int hashStart = url . IndexOf ( "download/" ) + 9 ;
156- int hashEnd = url . IndexOf ( "/download.html" , hashStart ) ;
157- return url . Substring ( hashStart , hashEnd - hashStart ) ;
158- }
159-
160161 private static async Task < string > ExtractDownloadUrlAsync ( string json , string unityVersion )
161162 {
162163 //Console.WriteLine("json: " + json + " vers: " + unityVersion);
163164
164165 if ( json . Contains ( "\" results\" :[]" ) )
165166 {
166- Console . WriteLine ( "No results found from releases API, checking unofficial list (if enabled)" ) ;
167+ Console . WriteLine ( "No results found from releases API, checking unofficial list (if enabled), v=" + unityVersion ) ;
168+
169+ // print unofficialReleaseURLs
170+ foreach ( var kvp in unofficialReleaseURLs )
171+ {
172+ Console . WriteLine ( $ "Unofficial: { kvp . Key } => { kvp . Value } ") ;
173+ }
167174
168175 if ( unofficialReleaseURLs . ContainsKey ( unityVersion ) )
169176 {
170- Console . WriteLine ( "Unofficial release found in the list. " ) ;
177+ Console . WriteLine ( "Unofficial release found in the list: " ) ;
171178
172- string unityHash = ParseHashCodeFromURL ( unofficialReleaseURLs [ unityVersion ] ) ;
179+ string unityHash = Tools . ParseHashCodeFromURL ( unofficialReleaseURLs [ unityVersion ] ) ;
173180 // Console.WriteLine(unityHash);
174181 string downloadURL = Tools . ParseDownloadURLFromWebpage ( unityVersion , unityHash , false , true ) ;
175182 // Console.WriteLine("direct download url: "+downloadURL);
@@ -385,6 +392,8 @@ private static List<UnityVersion> LoadCachedVersions()
385392 string cacheFilePath = Path . Combine ( configDirectory , CacheFileName ) ;
386393 if ( ! File . Exists ( cacheFilePath ) ) return new List < UnityVersion > ( ) ;
387394
395+ Console . WriteLine ( "cache file: " + cacheFilePath ) ;
396+
388397 string json = File . ReadAllText ( cacheFilePath ) ;
389398 return ParseCachedUnityVersions ( json ) ;
390399 }
@@ -406,5 +415,27 @@ private static void SaveCachedVersions(List<UnityVersion> versions)
406415 //Console.WriteLine("Saving cachedrelease: " + cacheFilePath);
407416 File . WriteAllText ( cacheFilePath , json ) ;
408417 }
418+
419+ internal static async Task < string > CheckUnofficialVersionList ( string version )
420+ {
421+ // fetch md page from unofficalReleasesURL
422+ var content = await Client . GetStringAsync ( unofficalReleasesURL ) ;
423+ // parse lines
424+ var lines = content . Split ( new [ ] { '\n ' , '\r ' } , StringSplitOptions . RemoveEmptyEntries ) ;
425+ foreach ( var line in lines )
426+ {
427+ if ( line . StartsWith ( "- " ) ) // Identify Markdown list items
428+ {
429+ var urlPart = line . Substring ( 4 ) . Trim ( ) ; // bug in server, has double -
430+ var foundVersion = ExtractVersionFromUrl ( urlPart ) ;
431+ if ( foundVersion == version )
432+ {
433+ Console . WriteLine ( "Found unofficial version in the list: " + foundVersion + " , " + urlPart ) ;
434+ return urlPart ;
435+ }
436+ }
437+ }
438+ return null ;
439+ }
409440 }
410441}
0 commit comments