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 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/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) 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 6f40e3b..be1456e 100644 --- a/src/IntelOrca.OpenLauncher.Core/IntelOrca.OpenLauncher.Core.csproj +++ b/src/IntelOrca.OpenLauncher.Core/IntelOrca.OpenLauncher.Core.csproj @@ -1,11 +1,9 @@ - netstandard2.1 + net8.0 enable - - 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 f73256c..76852a3 100644 --- a/src/openlauncher/openlauncher.csproj +++ b/src/openlauncher/openlauncher.csproj @@ -6,7 +6,7 @@ WinExe - net7.0 + net8.0 enable @@ -18,6 +18,9 @@ true resources\logo.ico + + + True @@ -42,10 +45,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