@@ -18,7 +18,7 @@ public static class GetUnityUpdates
18
18
private const int DelayBetweenBatches = 1000 ; // 1 second in milliseconds
19
19
private const string CacheFileName = "UnityVersionCache.json" ;
20
20
21
- private static readonly HttpClient httpClient = new HttpClient ( ) ;
21
+ private static readonly HttpClient Client = new HttpClient ( ) ;
22
22
23
23
public static async Task < List < UnityVersion > > FetchAll ( )
24
24
{
@@ -37,7 +37,7 @@ public static async Task<List<UnityVersion>> FetchAll()
37
37
return allVersions ;
38
38
}
39
39
40
- public static async Task < string > FetchDownloadUrl ( string unityVersion , bool assistantUrl = false )
40
+ public static async Task < string > FetchDownloadUrl ( string unityVersion )
41
41
{
42
42
if ( string . IsNullOrEmpty ( unityVersion ) )
43
43
{
@@ -48,7 +48,7 @@ public static async Task<string> FetchDownloadUrl(string unityVersion, bool assi
48
48
49
49
try
50
50
{
51
- string responseString = await httpClient . GetStringAsync ( apiUrl ) ;
51
+ string responseString = await Client . GetStringAsync ( apiUrl ) ;
52
52
JsonDocument doc = JsonDocument . Parse ( responseString ) ;
53
53
try
54
54
{
@@ -75,21 +75,37 @@ public static async Task<string> FetchDownloadUrl(string unityVersion, bool assi
75
75
76
76
if ( ! string . IsNullOrEmpty ( downloadUrl ) )
77
77
{
78
- if ( ! assistantUrl ) return downloadUrl ;
79
-
80
78
if ( ! string . IsNullOrEmpty ( shortRevision ) )
81
79
{
82
80
var startIndex = downloadUrl . LastIndexOf ( shortRevision , StringComparison . Ordinal ) + shortRevision . Length + 1 ;
83
81
var endIndex = downloadUrl . Length - startIndex ;
84
- return downloadUrl . Replace ( downloadUrl . Substring ( startIndex , endIndex ) ,
82
+ var assistantUrl = downloadUrl . Replace ( downloadUrl . Substring ( startIndex , endIndex ) ,
85
83
$ "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
+ }
86
97
}
87
98
else
88
99
{
89
100
Console . WriteLine ( "ShortRevision not found, returning original download URL." ) ;
90
101
return downloadUrl ;
91
102
}
92
103
}
104
+ else
105
+ {
106
+ Console . WriteLine ( "No download URL found." ) ;
107
+ return downloadUrl ;
108
+ }
93
109
}
94
110
95
111
Console . WriteLine ( $ "No download URL found for version { unityVersion } ") ;
@@ -145,7 +161,7 @@ private static async Task<UnityVersionResponse> FetchBatch(int offset)
145
161
146
162
try
147
163
{
148
- var response = await httpClient . GetStringAsync ( url ) ;
164
+ var response = await Client . GetStringAsync ( url ) ;
149
165
return JsonSerializer . Deserialize < UnityVersionResponse > ( response ) ;
150
166
}
151
167
catch ( Exception e )
0 commit comments