Skip to content

Commit e320993

Browse files
committed
Fix to .net 8 AOT, related fixes
Json.Net first deserializes arrays as lists and the list type is trimmed. Use list type directly to avoid it being trimmed.
1 parent 5a82e4f commit e320993

File tree

7 files changed

+25
-27
lines changed

7 files changed

+25
-27
lines changed

Command/Command.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net8.0</TargetFramework>
66
<LangVersion>latest</LangVersion>
7-
<PublishSingleFile>true</PublishSingleFile>
7+
<PublishAot>true</PublishAot>
88
<PublishReadyToRun>true</PublishReadyToRun>
99
<PublishTrimmed>true</PublishTrimmed>
1010
</PropertyGroup>

Command/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ void DetailedModulesList(IEnumerable<Module> modules)
981981
WriteField("Hidden", (module.hidden ? "yes" : null));
982982
WriteField("Size", $"{Helpers.FormatSize(module.downloadSize.GetBytes())} ({Helpers.FormatSize(module.installedSize.GetBytes())} installed)");
983983

984-
if (module.eula?.Length > 0) {
984+
if (module.eula?.Count > 0) {
985985
WriteField("EULA", module.eula[0].message);
986986
foreach (var eula in module.eula) {
987987
WriteField("", eula.label + ": " + eula.url);
@@ -1189,7 +1189,7 @@ public async Task Install()
11891189
// Make user accept additional EULAs
11901190
var hasEula = false;
11911191
foreach (var module in resolved.OfType<Module>()) {
1192-
if (module.eula == null || module.eula.Length == 0) continue;
1192+
if (module.eula == null || module.eula.Count == 0) continue;
11931193
hasEula = true;
11941194
Console.WriteLine();
11951195
SetForeground(ConsoleColor.Yellow);

sttz.InstallUnity/Installer/Configuration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace sttz.InstallUnity
1212
/// <summary>
1313
/// Configuration of the Unity installer.
1414
/// </summary>
15+
[JsonObject(MemberSerialization.Fields)]
1516
public class Configuration
1617
{
1718
[Description("After how many seconds the cache is considered to be outdated.")]

sttz.InstallUnity/Installer/Scraper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,20 +461,20 @@ void SetModuleKeys(Module download, IniParser.Model.SectionData section)
461461
var eulaUrl2 = section.Keys["eulaurl2"];
462462

463463
var eulaCount = (eulaUrl2 != null ? 2 : 1);
464-
download.eula = new Eula[eulaCount];
464+
download.eula = new(eulaCount);
465465

466-
download.eula[0] = new Eula() {
466+
download.eula.Add(new Eula() {
467467
message = eulaMessage,
468468
label = section.Keys["eulalabel1"],
469469
url = eulaUrl1
470-
};
470+
});
471471

472472
if (eulaCount > 1) {
473-
download.eula[1] = new Eula() {
473+
download.eula.Add(new Eula() {
474474
message = eulaMessage,
475475
label = section.Keys["eulalabel2"],
476476
url = eulaUrl2
477-
};
477+
});
478478
}
479479
}
480480

sttz.InstallUnity/Installer/UnityReleaseAPIClient.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.Extensions.Logging;
22
using Newtonsoft.Json;
33
using System;
4+
using System.Collections;
45
using System.Collections.Generic;
56
using System.Net;
67
using System.Net.Http;
@@ -117,7 +118,7 @@ public class Response
117118
/// <summary>
118119
/// The release results.
119120
/// </summary>
120-
public Release[] results;
121+
public List<Release> results;
121122

122123
// -------- Error fields --------
123124

@@ -184,7 +185,7 @@ public class Release
184185
/// <summary>
185186
/// The Third Party Notices of the Unity Release.
186187
/// </summary>
187-
public ThirdPartyNotice[] thirdPartyNotices;
188+
public List<ThirdPartyNotice> thirdPartyNotices;
188189

189190
[OnDeserialized]
190191
internal void OnDeserializedMethod(StreamingContext context)
@@ -429,7 +430,7 @@ public class Module : Download
429430
/// <summary>
430431
/// EULAs the user should accept before installing.
431432
/// </summary>
432-
public Eula[] eula;
433+
public List<Eula> eula;
433434
/// <summary>
434435
/// Sub-Modules of this module.
435436
/// </summary>
@@ -653,30 +654,25 @@ public async Task<Response> Send(RequestParams request, CancellationToken cancel
653654
/// <param name="maxResults">Limit returned results to not make too many requests</param>
654655
/// <param name="cancellation">Cancellation token</param>
655656
/// <returns>The results returned from the API</returns>
656-
public async Task<Release[]> LoadAll(RequestParams request, int maxResults = 200, CancellationToken cancellation = default)
657+
public async Task<IEnumerable<Release>> LoadAll(RequestParams request, int maxResults = 200, CancellationToken cancellation = default)
657658
{
658659
request.limit = 25;
659660

660661
int maxTotal = 0, currentOffset = 0;
661-
Release[] releases = null;
662-
Response response = null;
662+
var releases = new List<Release>();
663+
Response response;
663664
do {
664665
response = await Send(request, cancellation);
665666
if (!response.IsSuccess) {
666667
throw new Exception($"Unity Release API request failed: {response.title} - {response.detail}");
667668
}
668669

669-
maxTotal = Math.Min(response.total, maxResults);
670-
if (releases == null) {
671-
releases = new Release[maxTotal];
672-
}
673-
674-
Array.Copy(response.results, 0, releases, currentOffset, response.results.Length);
675-
currentOffset += response.results.Length;
670+
releases.AddRange(response.results);
671+
currentOffset += response.results.Count;
676672

677-
request.offset += response.results.Length;
673+
request.offset += response.results.Count;
678674

679-
} while (currentOffset < maxTotal && response.results.Length > 0);
675+
} while (currentOffset < maxTotal && response.results.Count > 0);
680676

681677
return releases;
682678
}
@@ -701,12 +697,12 @@ public async Task<IEnumerable<Release>> LoadLatest(RequestParams request, TimeSp
701697
response = await Send(request, cancellation);
702698
if (!response.IsSuccess) {
703699
throw new Exception($"Unity Release API request failed: {response.title} - {response.detail}");
704-
} else if (response.results.Length == 0) {
700+
} else if (response.results.Count == 0) {
705701
break;
706702
}
707703

708704
releases.AddRange(response.results);
709-
request.offset += response.results.Length;
705+
request.offset += response.results.Count;
710706

711707
var oldestReleaseDate = response.results[^1].releaseDate;
712708
var releasedSince = now - oldestReleaseDate;
@@ -758,7 +754,7 @@ public async Task<Release> FindRelease(UnityVersion version, Platform platform,
758754
var result = await Send(req, cancellation);
759755
if (!result.IsSuccess) {
760756
throw new Exception($"Unity Release API request failed: {result.title} - {result.detail}");
761-
} else if (result.results.Length == 0) {
757+
} else if (result.results.Count == 0) {
762758
return null;
763759
}
764760

sttz.InstallUnity/Installer/VirtualPackages.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static IEnumerable<Module> Generator(UnityVersion version, EditorDownload editor
8888
downloadSize = FileSize.FromMegaBytes(148),
8989
installedSize = FileSize.FromMegaBytes(174),
9090
parentModuleId = "Android",
91-
eula = new Eula[] {
91+
eula = new() {
9292
new Eula() {
9393
url = "https://dl.google.com/dl/android/repository/repository2-1.xml",
9494
label = "Android SDK and NDK License Terms from Google",

sttz.InstallUnity/sttz.InstallUnity.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
<RootNamespace>sttz.InstallUnity</RootNamespace>
7+
<IsAotCompatible>true</IsAotCompatible>
78
</PropertyGroup>
89

910
<PropertyGroup Label="Package">

0 commit comments

Comments
 (0)