From e8eeb94d372380f99af722c90ea6c7f4d7674207 Mon Sep 17 00:00:00 2001 From: Tomasz Kolodziejczyk Date: Sat, 21 Sep 2024 18:40:36 +0200 Subject: [PATCH 1/4] Update to .NET 8.0 and refactor tests Updated target frameworks to .NET 8.0 in `launch.json`, `IntelOrca.OpenLauncher.Core.csproj`, `openlauncher.csproj`, and `IntelOrca.OpenLauncher.Tests.csproj`. Upgraded various NuGet packages to their latest Minor versions. Refactored `BuildServiceTests.cs` to use `[Theory]` with `InlineData` and introduced a helper method for asset matching. --- .vscode/launch.json | 2 +- .../IntelOrca.OpenLauncher.Core.csproj | 6 ++--- src/openlauncher/openlauncher.csproj | 8 +++---- .../BuildServiceTests.cs | 22 +++++++++++-------- .../IntelOrca.OpenLauncher.Tests.csproj | 8 +++---- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 28b83d5..1827231 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/src/openlauncher/bin/Debug/net7.0/openlauncher.dll", + "program": "${workspaceFolder}/src/openlauncher/bin/Debug/net8.0/openlauncher.dll", "args": [], "cwd": "${workspaceFolder}", "console": "internalConsole", diff --git a/src/IntelOrca.OpenLauncher.Core/IntelOrca.OpenLauncher.Core.csproj b/src/IntelOrca.OpenLauncher.Core/IntelOrca.OpenLauncher.Core.csproj index 6f40e3b..b6dac24 100644 --- a/src/IntelOrca.OpenLauncher.Core/IntelOrca.OpenLauncher.Core.csproj +++ b/src/IntelOrca.OpenLauncher.Core/IntelOrca.OpenLauncher.Core.csproj @@ -1,11 +1,11 @@ - netstandard2.1 + net8.0 enable - - + + diff --git a/src/openlauncher/openlauncher.csproj b/src/openlauncher/openlauncher.csproj index f73256c..d18ef31 100644 --- a/src/openlauncher/openlauncher.csproj +++ b/src/openlauncher/openlauncher.csproj @@ -6,7 +6,7 @@ WinExe - net7.0 + net8.0 enable @@ -42,10 +42,10 @@ - - + + - + diff --git a/test/IntelOrca.OpenLauncher.Tests/BuildServiceTests.cs b/test/IntelOrca.OpenLauncher.Tests/BuildServiceTests.cs index 953354c..8acfbd5 100644 --- a/test/IntelOrca.OpenLauncher.Tests/BuildServiceTests.cs +++ b/test/IntelOrca.OpenLauncher.Tests/BuildServiceTests.cs @@ -8,18 +8,22 @@ namespace IntelOrca.OpenLauncher.Tests { public class BuildServiceTests { - [Fact] - public async Task GetBuildsAsync_OpenLoco_v22_05_1() + [Theory] + [InlineData("macos", "v22.05.1", 4157592, "2022-05-17T20:06:15Z")] + public async Task GetBuildsAsync_OpenLoco_v22_05_1(string system, string version, int size, string publishtime) { var buildService = new BuildService(); var builds = await buildService.GetBuildsAsync(Game.OpenLoco, includeDevelop: false); - var build = builds.First(x => x.Version == "v22.05.1"); - Assert.Equal("v22.05.1", build.Version); - Assert.Equal(new DateTime(2022, 5, 17, 20, 6, 15), build.PublishedAt); - Assert.Equal("OpenLoco-v22.05.1-macos.zip", build.Assets[0].Name); - Assert.Equal(new Uri("https://github.com/OpenLoco/OpenLoco/releases/download/v22.05.1/OpenLoco-v22.05.1-macos.zip"), build.Assets[0].Uri); - Assert.Equal("application/x-zip-compressed", build.Assets[0].ContentType); - Assert.Equal(4157592, build.Assets[0].Size); + var build = builds.First(x => x.Version == version && x.Assets.Any(t => IsMatchingSystemAsset(system, t))); + + Assert.Equal(version, build.Version); + Assert.Equal(DateTime.Parse(publishtime).ToUniversalTime(), build.PublishedAt); + Assert.Equal($"OpenLoco-{version}-{system}.zip", build.Assets.Where(t => IsMatchingSystemAsset(system, t)).First().Name); + Assert.Equal(new Uri($"https://github.com/OpenLoco/OpenLoco/releases/download/{version}/OpenLoco-{version}-{system}.zip"), build.Assets.Where(t => t.Uri.AbsoluteUri.Contains("macos.zip")).First().Uri); + Assert.Equal("application/x-zip-compressed", build.Assets.Where(t => IsMatchingSystemAsset(system, t)).First().ContentType); + Assert.Equal(size, build.Assets.Where(t => IsMatchingSystemAsset(system, t)).First().Size); } + + private static bool IsMatchingSystemAsset(string system, BuildAsset t) => t.Uri.AbsoluteUri.Contains($"{system}.zip"); } } diff --git a/test/IntelOrca.OpenLauncher.Tests/IntelOrca.OpenLauncher.Tests.csproj b/test/IntelOrca.OpenLauncher.Tests/IntelOrca.OpenLauncher.Tests.csproj index 77844f1..c2952b0 100644 --- a/test/IntelOrca.OpenLauncher.Tests/IntelOrca.OpenLauncher.Tests.csproj +++ b/test/IntelOrca.OpenLauncher.Tests/IntelOrca.OpenLauncher.Tests.csproj @@ -1,16 +1,16 @@ - net7.0 + net8.0 enable false - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all From daf4b64ce9f17d8c878c7e5a7563a51b0007be16 Mon Sep 17 00:00:00 2001 From: Tomasz Kolodziejczyk Date: Sat, 21 Sep 2024 18:46:52 +0200 Subject: [PATCH 2/4] Update github action to v8 support --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aacfe1a..f6f5bd0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: - name: Setup .NET Core SDK uses: actions/setup-dotnet@v1 with: - dotnet-version: '7.0.x' + dotnet-version: '8.0.x' - name: Restore run: dotnet restore - name: Build @@ -30,14 +30,14 @@ jobs: working-directory: src/openlauncher run: dotnet publish -c Release -r ${{ matrix.rid }} --self-contained - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: "OpenLauncher-${{ matrix.rid }}" - path: src/openlauncher/bin/Release/net7.0/${{ matrix.rid }}/publish/**/* + path: src/openlauncher/bin/Release/net8.0/${{ matrix.rid }}/publish/**/* - name: Create release uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/v') with: files: | - src/openlauncher/bin/Release/net7.0/${{ matrix.rid }}/publish/openlauncher - src/openlauncher/bin/Release/net7.0/${{ matrix.rid }}/publish/openlauncher.exe + src/openlauncher/bin/Release/net8.0/${{ matrix.rid }}/publish/openlauncher + src/openlauncher/bin/Release/net8.0/${{ matrix.rid }}/publish/openlauncher.exe From 895a869c271c50a811d4c003ac1c3e8290d9cba5 Mon Sep 17 00:00:00 2001 From: Tomasz Kolodziejczyk Date: Fri, 27 Sep 2024 19:18:07 +0200 Subject: [PATCH 3/4] Fix warnings Handle nulls, update process handling, and add config UseRidGraph --- src/IntelOrca.OpenLauncher.Core/Build.cs | 6 +++++- src/IntelOrca.OpenLauncher.Core/BuildAsset.cs | 7 ++++++- src/IntelOrca.OpenLauncher.Core/InstallService.cs | 8 ++++++-- .../IntelOrca.OpenLauncher.Core.csproj | 2 -- src/IntelOrca.OpenLauncher.Core/Shell.cs | 2 +- src/openlauncher/openlauncher.csproj | 3 +++ 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/IntelOrca.OpenLauncher.Core/Build.cs b/src/IntelOrca.OpenLauncher.Core/Build.cs index 8941766..fa1f345 100644 --- a/src/IntelOrca.OpenLauncher.Core/Build.cs +++ b/src/IntelOrca.OpenLauncher.Core/Build.cs @@ -33,16 +33,20 @@ public Version? ParsedVersion public override string ToString() => Version; - public int CompareTo(Build other) + public int CompareTo(Build? other) { + ArgumentNullException.ThrowIfNull(other); + var a = PublishedAt; var b = other.PublishedAt; + if (a is null && b is null) return 0; if (a is null) return 1; if (b is null) return -1; + return b.Value.CompareTo(a.Value); } } diff --git a/src/IntelOrca.OpenLauncher.Core/BuildAsset.cs b/src/IntelOrca.OpenLauncher.Core/BuildAsset.cs index 0ebea75..eb0fbd4 100644 --- a/src/IntelOrca.OpenLauncher.Core/BuildAsset.cs +++ b/src/IntelOrca.OpenLauncher.Core/BuildAsset.cs @@ -117,8 +117,13 @@ public class BuildAssetComparer : IComparer public static BuildAssetComparer Default = new BuildAssetComparer(); - public int Compare(BuildAsset x, BuildAsset y) + public int Compare(BuildAsset? x, BuildAsset? y) { + if (x == null || y == null) + { + throw new ArgumentNullException("BuildAsset objects cannot be null"); + } + if (x.Platform == y.Platform) { if (x.Arch != y.Arch) diff --git a/src/IntelOrca.OpenLauncher.Core/InstallService.cs b/src/IntelOrca.OpenLauncher.Core/InstallService.cs index e5c29eb..a957dec 100644 --- a/src/IntelOrca.OpenLauncher.Core/InstallService.cs +++ b/src/IntelOrca.OpenLauncher.Core/InstallService.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Xml.Linq; namespace IntelOrca.OpenLauncher.Core { @@ -73,12 +74,15 @@ public Task Launch() { RedirectStandardError = true }; - var process = Process.Start(psi); + + var process = Process.Start(psi) ?? throw new InvalidOperationException($"Failed to start process '{psi}'"); + var outputBuilder = new StringBuilder(); var sw = Stopwatch.StartNew(); + while (sw.ElapsedMilliseconds < 2000) { - var s = process.StandardError.ReadToEnd(); + string? s = process.StandardError.ReadToEnd(); if (s != null) outputBuilder.Append(s); diff --git a/src/IntelOrca.OpenLauncher.Core/IntelOrca.OpenLauncher.Core.csproj b/src/IntelOrca.OpenLauncher.Core/IntelOrca.OpenLauncher.Core.csproj index b6dac24..be1456e 100644 --- a/src/IntelOrca.OpenLauncher.Core/IntelOrca.OpenLauncher.Core.csproj +++ b/src/IntelOrca.OpenLauncher.Core/IntelOrca.OpenLauncher.Core.csproj @@ -5,7 +5,5 @@ - - diff --git a/src/IntelOrca.OpenLauncher.Core/Shell.cs b/src/IntelOrca.OpenLauncher.Core/Shell.cs index 4222dd2..cad7d88 100644 --- a/src/IntelOrca.OpenLauncher.Core/Shell.cs +++ b/src/IntelOrca.OpenLauncher.Core/Shell.cs @@ -25,7 +25,7 @@ public int RunProcess(string name, params string[] args) { psi.ArgumentList.Add(arg); } - var p = Process.Start(psi); + var p = Process.Start(psi) ?? throw new InvalidOperationException($"Failed to start process '{name}'"); p.WaitForExit(); return p.ExitCode; } diff --git a/src/openlauncher/openlauncher.csproj b/src/openlauncher/openlauncher.csproj index d18ef31..76852a3 100644 --- a/src/openlauncher/openlauncher.csproj +++ b/src/openlauncher/openlauncher.csproj @@ -18,6 +18,9 @@ true resources\logo.ico + + + True From 0ca131ce2622cc4b66ce8bb4f3e35b404b4a7115 Mon Sep 17 00:00:00 2001 From: Tomasz Kolodziejczyk Date: Fri, 27 Sep 2024 19:29:08 +0200 Subject: [PATCH 4/4] fix documentation Update .NET version to 8.0 in README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ed30f23..226b099 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ A launcher for automatically downloading the latest, or specific versions of [Op # 🔨 Building -**Open Launcher** is written in C# using the [AvaloniaUI](http://avaloniaui.net) framework. The application currently targets [.NET 6](https://dotnet.microsoft.com) and is typically distributed as a self contained executable. +**Open Launcher** is written in C# using the [AvaloniaUI](http://avaloniaui.net) framework. The application currently targets [.NET 8](https://dotnet.microsoft.com) and is typically distributed as a self contained executable. ### Prerequisites -* [.NET 6 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) +* [.NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) * [Visual Studio](https://visualstudio.microsoft.com) (optional) * [AvaloniaUI extension](https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaVS) (optional) * [Visual Studio Code](https://code.visualstudio.com) (optional)