1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Collections . Immutable ;
4
+ using System . ComponentModel . DataAnnotations ;
4
5
using System . Drawing ;
5
6
using System . IO ;
6
7
using System . Linq ;
@@ -28,11 +29,10 @@ internal record UnoConfig(Uri assembliesPath, string? mainAssembly, string[]? as
28
29
public record AssemblyDetail ( string ? name , string version , string fileVersion , string configuration , string targetFramework , string ? commit ) ;
29
30
30
31
private ImmutableArray < AssemblyDetail > _assemblies ;
31
- private UnoConfig _unoConfig ;
32
- private DotnetConfig _dotnetConfig ;
32
+ private UnoConfig ? _unoConfig ;
33
+ private DotnetConfig ? _dotnetConfig ;
33
34
private AssemblyDetail ? _mainAssemblyDetails ;
34
35
private ( string ? version , string ? name ) _framework ;
35
- private bool _isAot ;
36
36
37
37
public UnoVersionExtractor ( Uri siteUri )
38
38
{
@@ -66,7 +66,7 @@ public async Task<int> Extract()
66
66
var web = new HtmlWeb ( ) ;
67
67
var doc = await web . LoadFromWebAsync ( _siteUri , default , default , default ) ;
68
68
69
- Console . WriteLine ( "Trying to find Uno bootstrapper configuration..." , Color . Gray ) ;
69
+ Console . WriteLine ( "Trying to find App configuration..." , Color . Gray ) ;
70
70
71
71
var files = doc ? . DocumentNode
72
72
. SelectNodes ( "//script" )
@@ -109,52 +109,54 @@ public async Task<int> Extract()
109
109
}
110
110
}
111
111
112
- if ( unoConfigPath is null )
113
- {
114
- Console . WriteLine ( "No Uno / Uno.UI application found." , Color . Red ) ;
115
- return 2 ;
116
- }
117
-
118
112
Console . WriteLine ( "Application found." , Color . LightGreen ) ;
119
113
120
- Console . WriteLineFormatted ( "Configuration url is {0}." , Color . Gray , new Formatter ( unoConfigPath , Color . Aqua ) ) ;
114
+ if ( unoConfigPath is not null )
115
+ {
116
+ Console . WriteLineFormatted ( "Uno configuration url is {0}." , Color . Gray , new Formatter ( unoConfigPath , Color . Aqua ) ) ;
117
+ _unoConfig = await GetUnoConfig ( unoConfigPath ) ;
118
+ }
121
119
122
- _unoConfig = await GetUnoConfig ( unoConfigPath ) ;
123
120
_dotnetConfig = await GetDotnetConfig ( dotnetConfigPath ) ;
124
121
125
- if ( _unoConfig . server is { Length : > 0 } )
122
+ if ( _dotnetConfig . mainAssemblyName is not null )
123
+ {
124
+ Console . WriteLineFormatted ( "Dotnet configuration url is {0}." , Color . Gray , new Formatter ( dotnetConfigPath , Color . Aqua ) ) ;
125
+ }
126
+
127
+ if ( _unoConfig ? . server is { Length : > 0 } )
126
128
{
127
129
Console . WriteLineFormatted (
128
130
"Server is {0}" ,
129
131
Color . Gray ,
130
132
new Formatter ( _unoConfig . server , Color . Aqua ) ) ;
131
133
}
132
134
133
- if ( _unoConfig . mainAssembly is { Length : > 0 } )
135
+ if ( _unoConfig ? . mainAssembly is { Length : > 0 } )
134
136
{
135
137
Console . WriteLineFormatted ( "Starting assembly is {0}." , Color . Gray ,
136
138
new Formatter ( _unoConfig . mainAssembly , Color . Aqua ) ) ;
137
139
}
138
140
139
- if ( _dotnetConfig . mainAssemblyName is { Length : > 0 } )
141
+ if ( _dotnetConfig ? . mainAssemblyName is { Length : > 0 } )
140
142
{
141
143
Console . WriteLineFormatted ( "Starting assembly is {0}." , Color . Gray ,
142
144
new Formatter ( _dotnetConfig . mainAssemblyName , Color . Aqua ) ) ;
143
145
}
144
146
145
147
if (
146
- ( _unoConfig . assemblies is null || _unoConfig . assemblies is { Length : 0 } )
147
- && _dotnetConfig . assemblies . Length == 0 )
148
+ ( _unoConfig ? . assemblies is null || _unoConfig . assemblies is { Length : 0 } )
149
+ && _dotnetConfig ? . assemblies . Length == 0 )
148
150
{
149
151
Console . WriteLine ( "No assemblies found." , Color . Red ) ;
150
152
return 1 ;
151
153
}
152
154
153
- if ( _unoConfig . assemblies is { Length : > 0 } )
155
+ if ( _unoConfig ? . assemblies is { Length : > 0 } )
154
156
{
155
157
await DumpAssemblies ( _unoConfig . assembliesPath , _unoConfig . assemblies ) ;
156
158
}
157
- else if ( _dotnetConfig . assembliesPath is not null )
159
+ else if ( _dotnetConfig ? . assembliesPath is not null )
158
160
{
159
161
await DumpAssemblies ( _dotnetConfig . assembliesPath , _dotnetConfig . assemblies ) ;
160
162
}
@@ -187,7 +189,7 @@ private async Task DumpAssemblies(Uri basePath, string[] assemblies)
187
189
188
190
foreach ( var assemblyDetail in _assemblies )
189
191
{
190
- if ( assemblyDetail . name == _unoConfig . mainAssembly )
192
+ if ( assemblyDetail . name == _unoConfig ? . mainAssembly )
191
193
{
192
194
_mainAssemblyDetails = assemblyDetail ;
193
195
}
@@ -199,24 +201,34 @@ private async Task DumpAssemblies(Uri basePath, string[] assemblies)
199
201
{
200
202
_framework = ( assemblyDetail . version , assemblyDetail . targetFramework ) ;
201
203
}
202
- else if ( assemblyDetail . name == "aot-instances" )
203
- {
204
- _isAot = true ;
205
- }
206
204
}
207
205
}
208
206
209
207
private async Task < Uri ? > GetDotnetConfigPath ( )
210
208
{
211
209
using var http = new HttpClient ( ) ;
212
- var dotnetConfig = new Uri ( _siteUri , "_framework/blazor.boot.json" ) ;
210
+
211
+ if ( await GetFile ( http , new ( _siteUri , "_framework/blazor.boot.json" ) ) is { } frameworkFile )
212
+ {
213
+ return frameworkFile ;
214
+ }
215
+ else if ( await GetFile ( http , new ( _siteUri , "blazor.boot.json" ) ) is { } baseFile )
216
+ {
217
+ return baseFile ;
218
+ }
219
+
220
+ return null ;
221
+ }
222
+
223
+ private static async Task < Uri ? > GetFile ( HttpClient http , Uri dotnetConfig )
224
+ {
213
225
var embeddedResponse = await http . GetAsync ( dotnetConfig ) ;
214
226
215
227
if ( embeddedResponse . IsSuccessStatusCode )
216
228
{
217
229
var response = await embeddedResponse . Content . ReadAsStringAsync ( ) ;
218
230
219
- if ( response . StartsWith ( "{" ) )
231
+ if ( response . StartsWith ( "{" ) )
220
232
{
221
233
return dotnetConfig ;
222
234
}
@@ -307,9 +319,13 @@ public void OutputResults()
307
319
List < string > assemblies = new ( ) ;
308
320
309
321
var resources = json . RootElement . GetProperty ( "resources" ) ;
322
+
323
+ resources . TryGetProperty ( "coreAssembly" , out var coreAssembly ) ;
324
+ resources . TryGetProperty ( "assembly" , out var assembly ) ;
325
+
310
326
var assembliesList =
311
- resources . GetProperty ( " coreAssembly" ) . EnumerateObject ( )
312
- . Concat ( resources . GetProperty ( " assembly" ) . EnumerateObject ( ) ) ;
327
+ ( coreAssembly . ValueKind == JsonValueKind . Undefined ? [ ] : coreAssembly . EnumerateObject ( ) )
328
+ . Concat ( assembly . ValueKind == JsonValueKind . Undefined ? [ ] : assembly. EnumerateObject ( ) ) ;
313
329
314
330
foreach ( var resource in assembliesList )
315
331
{
@@ -319,7 +335,7 @@ public void OutputResults()
319
335
}
320
336
}
321
337
322
- var assembliesPath = new Uri ( _siteUri , "_framework/ " ) ;
338
+ var assembliesPath = new Uri ( _siteUri , dotnetConfigPath . OriginalString . Contains ( "_framework" ) ? "_framework/" : " ") ;
323
339
324
340
return ( mainAssemblyName , globalizationMode , assemblies . ToArray ( ) , assembliesPath ) ;
325
341
}
@@ -410,17 +426,17 @@ private async Task<UnoConfig> GetUnoConfig(Uri uri)
410
426
var details = await ReadPE ( stream ) ;
411
427
412
428
stream . Position = 0 ;
413
- details ??= await ReadWebCIL ( stream ) ;
429
+ details ??= ReadWebCIL ( stream ) ;
414
430
415
431
return details ;
416
432
}
417
- catch ( Exception ex )
433
+ catch ( Exception )
418
434
{
419
435
return null ;
420
436
}
421
437
}
422
438
423
- private static async Task < AssemblyDetail ? > ReadWebCIL ( MemoryStream stream )
439
+ private static AssemblyDetail ? ReadWebCIL ( MemoryStream stream )
424
440
{
425
441
var asmStream = WebcilConverterUtil . ConvertFromWebcil ( stream ) ;
426
442
@@ -496,7 +512,7 @@ private async Task<UnoConfig> GetUnoConfig(Uri uri)
496
512
public void Dispose ( ) => _httpClient . Dispose ( ) ;
497
513
}
498
514
499
- internal record struct DotnetConfig ( string ? mainAssemblyName , string ? globalizationMode , string [ ] assemblies , Uri ? assembliesPath )
515
+ internal record DotnetConfig ( string ? mainAssemblyName , string ? globalizationMode , string [ ] assemblies , Uri ? assembliesPath )
500
516
{
501
517
public static implicit operator ( string ? mainAssemblyName , string ? globalizationMode , string [ ] assemblies , Uri ? assembliesPath ) ( DotnetConfig value ) => ( value . mainAssemblyName , value . globalizationMode , value . assemblies , value . assembliesPath ) ;
502
518
public static implicit operator DotnetConfig ( ( string ? mainAssemblyName , string ? globalizationMode , string [ ] assemblies , Uri ? assembliesPath ) value ) => new DotnetConfig ( value . mainAssemblyName , value . globalizationMode , value . assemblies , value . assembliesPath ) ;
0 commit comments