From e1dfd1f0d07c9e351fd93f38e3368b7b1d682dc2 Mon Sep 17 00:00:00 2001 From: Macocian Alexandru Victor Date: Sun, 19 Nov 2023 00:40:09 +0100 Subject: [PATCH] Update to .net8.0 (#486) Fix uMod installation steps ReShade monitor config changes --- .github/workflows/cd.yaml | 4 +- .github/workflows/ci.yaml | 2 +- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/version_check.yaml | 7 +- .../Daybreak.7ZipExtractor.csproj | 2 +- Daybreak.Installer/Daybreak.Installer.csproj | 2 +- Daybreak.Tests/Daybreak.Tests.csproj | 2 +- Daybreak/Configuration/Options/UModOptions.cs | 4 - .../Configuration/ProjectConfiguration.cs | 2 + Daybreak/Daybreak.csproj | 20 ++-- .../ApplicationLauncher.cs | 4 +- .../Services/Charts/LiveChartInitializer.cs | 9 +- Daybreak/Services/ReShade/IReShadeService.cs | 1 + .../ReShadeConfigChangedHandler.cs | 28 +++++ Daybreak/Services/ReShade/ReShadeService.cs | 106 +++++++++++++++++- Daybreak/Services/UMod/IUModService.cs | 2 - Daybreak/Services/UMod/UModService.cs | 30 +---- .../UMod/UModInstallationChoiceView.xaml | 2 +- .../UMod/UModInstallationChoiceView.xaml.cs | 11 +- 19 files changed, 164 insertions(+), 76 deletions(-) create mode 100644 Daybreak/Services/ReShade/Notifications/ReShadeConfigChangedHandler.cs diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index f9e43d24..aa8623c0 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -52,7 +52,7 @@ jobs: - name: Install .NET Core uses: actions/setup-dotnet@v3 with: - dotnet-version: '7.x' + dotnet-version: '8.x' - name: Setup MSBuild.exe uses: microsoft/setup-msbuild@v1.3.1 @@ -83,7 +83,7 @@ jobs: echo "::set-env name=Version::$version" - name: Create publish launcher files - run: dotnet publish .\Daybreak\Daybreak.csproj -c $env:Configuration -r $env:RuntimeIdentifier --property:SolutionDir=$env:GITHUB_WORKSPACE -p:PublishReadyToRun=true -p:PublishSingleFile=true --self-contained true -o .\Publish + run: dotnet publish .\Daybreak\Daybreak.csproj -c $env:Configuration -r $env:RuntimeIdentifier --property:SolutionDir=$env:GITHUB_WORKSPACE -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:PublishTrimmed --self-contained true -o .\Publish env: RuntimeIdentifier: win-${{ matrix.targetplatform }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f74a8a99..fc3c3bd9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -38,7 +38,7 @@ jobs: - name: Install .NET Core uses: actions/setup-dotnet@v3 with: - dotnet-version: '7.x' + dotnet-version: '8.x' - name: Setup MSBuild.exe uses: microsoft/setup-msbuild@v1.3.1 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index dc3ebe5c..45a253ca 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -72,7 +72,7 @@ jobs: - name: Install .NET Core uses: actions/setup-dotnet@v3 with: - dotnet-version: '7.x' + dotnet-version: '8.x' #- name: Autobuild # uses: github/codeql-action/autobuild@v2 diff --git a/.github/workflows/version_check.yaml b/.github/workflows/version_check.yaml index e7453cfa..d3741dbd 100644 --- a/.github/workflows/version_check.yaml +++ b/.github/workflows/version_check.yaml @@ -28,7 +28,12 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - + + - name: Install .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.x' + - name: Get Latest Tag id: getLatestTag uses: WyriHaximus/github-action-get-previous-tag@v1 diff --git a/Daybreak.7ZipExtractor/Daybreak.7ZipExtractor.csproj b/Daybreak.7ZipExtractor/Daybreak.7ZipExtractor.csproj index dea9bed8..b669c3ce 100644 --- a/Daybreak.7ZipExtractor/Daybreak.7ZipExtractor.csproj +++ b/Daybreak.7ZipExtractor/Daybreak.7ZipExtractor.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 Daybreak._7ZipExtractor enable enable diff --git a/Daybreak.Installer/Daybreak.Installer.csproj b/Daybreak.Installer/Daybreak.Installer.csproj index a78fef3a..59d69650 100644 --- a/Daybreak.Installer/Daybreak.Installer.csproj +++ b/Daybreak.Installer/Daybreak.Installer.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 enable enable AnyCPU;x86;x64 diff --git a/Daybreak.Tests/Daybreak.Tests.csproj b/Daybreak.Tests/Daybreak.Tests.csproj index 3fc59bd8..d19e66af 100644 --- a/Daybreak.Tests/Daybreak.Tests.csproj +++ b/Daybreak.Tests/Daybreak.Tests.csproj @@ -1,7 +1,7 @@ - net7.0-windows + net8.0-windows false AnyCPU;x86;x64 diff --git a/Daybreak/Configuration/Options/UModOptions.cs b/Daybreak/Configuration/Options/UModOptions.cs index 344484ed..a7973dab 100644 --- a/Daybreak/Configuration/Options/UModOptions.cs +++ b/Daybreak/Configuration/Options/UModOptions.cs @@ -8,10 +8,6 @@ namespace Daybreak.Configuration.Options; [OptionsName(Name = "uMod")] public sealed class UModOptions { - [JsonProperty(nameof(DllPath))] - [OptionName(Name = "Dll Path", Description = "The path to the uMod dll")] - public string? DllPath { get; set; } - [JsonProperty(nameof(Enabled))] [OptionName(Name = "Enabled", Description = "If true, Daybreak will also launch uMod when launching GuildWars")] public bool Enabled { get; set; } diff --git a/Daybreak/Configuration/ProjectConfiguration.cs b/Daybreak/Configuration/ProjectConfiguration.cs index af74b1f4..31e7a5ac 100644 --- a/Daybreak/Configuration/ProjectConfiguration.cs +++ b/Daybreak/Configuration/ProjectConfiguration.cs @@ -81,6 +81,7 @@ using Daybreak.Services.DirectSong; using Daybreak.Views.Onboarding.DirectSong; using Daybreak.Services.SevenZip; +using Daybreak.Services.ReShade.Notifications; namespace Daybreak.Configuration; @@ -427,6 +428,7 @@ public override void RegisterNotificationHandlers(INotificationHandlerProducer n notificationHandlerProducer.RegisterNotificationHandler(); notificationHandlerProducer.RegisterNotificationHandler(); notificationHandlerProducer.RegisterNotificationHandler(); + notificationHandlerProducer.RegisterNotificationHandler(); } public override void RegisterMods(IModsManager modsManager) diff --git a/Daybreak/Daybreak.csproj b/Daybreak/Daybreak.csproj index a7528e00..3815478f 100644 --- a/Daybreak/Daybreak.csproj +++ b/Daybreak/Daybreak.csproj @@ -1,10 +1,10 @@ - + WinExe Daybreak - net6.0-windows + net8.0-windows true enable true @@ -13,7 +13,7 @@ preview Daybreak.ico true - 0.9.8.149 + 0.9.8.150 true cfb2a489-db80-448d-a969-80270f314c46 True @@ -93,12 +93,12 @@ - + - - - + + + @@ -106,10 +106,10 @@ - + - - + + diff --git a/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs b/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs index 5044075f..3c4bd8d2 100644 --- a/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs +++ b/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs @@ -188,8 +188,8 @@ public void RestartDaybreakAsNormalUser() args.Add($"\"{character}\""); } - var mods = this.modsManager.GetMods().Where(m => m.IsEnabled).ToList(); - var disabledmods = this.modsManager.GetMods().Where(m => !m.IsEnabled).ToList(); + var mods = this.modsManager.GetMods().Where(m => m.IsEnabled && m.IsInstalled).ToList(); + var disabledmods = this.modsManager.GetMods().Where(m => !m.IsEnabled && m.IsInstalled).ToList(); foreach(var mod in mods) { args.AddRange(mod.GetCustomArguments()); diff --git a/Daybreak/Services/Charts/LiveChartInitializer.cs b/Daybreak/Services/Charts/LiveChartInitializer.cs index a2f54927..37db54bb 100644 --- a/Daybreak/Services/Charts/LiveChartInitializer.cs +++ b/Daybreak/Services/Charts/LiveChartInitializer.cs @@ -1,6 +1,7 @@ using Daybreak.Models.Metrics; using Daybreak.Models.Trade; using LiveChartsCore; +using LiveChartsCore.Kernel; using LiveChartsCore.SkiaSharpView; using System; using System.Windows.Extensions.Services; @@ -20,15 +21,13 @@ public void OnStartup() .AddDefaultMappers() .AddDarkTheme() .AddLightTheme() - .HasMap((metric, point) => + .HasMap((metric, index) => { - point.SecondaryValue = metric.Timestamp.Ticks; - point.PrimaryValue = Convert.ToDouble(metric.Measurement); + return new Coordinate(Convert.ToDouble(metric.Measurement), metric.Timestamp.Ticks); }) .HasMap((quote, point) => { - point.SecondaryValue = quote.Timestamp?.Ticks ?? 0; - point.PrimaryValue = ((double)quote.Price) / 20d; + return new Coordinate(((double)quote.Price) / 20d, quote.Timestamp?.Ticks ?? 0); })); } } diff --git a/Daybreak/Services/ReShade/IReShadeService.cs b/Daybreak/Services/ReShade/IReShadeService.cs index e6b0b45b..4c44480f 100644 --- a/Daybreak/Services/ReShade/IReShadeService.cs +++ b/Daybreak/Services/ReShade/IReShadeService.cs @@ -18,4 +18,5 @@ public interface IReShadeService : IModService Task SaveConfig(string config, CancellationToken cancellationToken); Task GetPreset(CancellationToken cancellationToken); Task SavePreset(string config, CancellationToken cancellationToken); + Task UpdateIniFromPath(string pathToIni, CancellationToken cancellationToken); } diff --git a/Daybreak/Services/ReShade/Notifications/ReShadeConfigChangedHandler.cs b/Daybreak/Services/ReShade/Notifications/ReShadeConfigChangedHandler.cs new file mode 100644 index 00000000..0feb1a4e --- /dev/null +++ b/Daybreak/Services/ReShade/Notifications/ReShadeConfigChangedHandler.cs @@ -0,0 +1,28 @@ +using Daybreak.Models.Notifications; +using Daybreak.Models.Notifications.Handling; +using System.Core.Extensions; +using System.IO; +using System.Threading; + +namespace Daybreak.Services.ReShade.Notifications; +internal sealed class ReShadeConfigChangedHandler : INotificationHandler +{ + private readonly IReShadeService reShadeService; + + public ReShadeConfigChangedHandler( + IReShadeService reShadeService) + { + this.reShadeService = reShadeService.ThrowIfNull(); + } + + public async void OpenNotification(Notification notification) + { + var presetPath = Path.GetFullPath(notification.Metadata); + if (!File.Exists(presetPath)) + { + return; + } + + await this.reShadeService.UpdateIniFromPath(presetPath, CancellationToken.None); + } +} diff --git a/Daybreak/Services/ReShade/ReShadeService.cs b/Daybreak/Services/ReShade/ReShadeService.cs index 1fe62fad..21179141 100644 --- a/Daybreak/Services/ReShade/ReShadeService.cs +++ b/Daybreak/Services/ReShade/ReShadeService.cs @@ -5,6 +5,7 @@ using Daybreak.Services.Downloads; using Daybreak.Services.Injection; using Daybreak.Services.Notifications; +using Daybreak.Services.ReShade.Notifications; using Daybreak.Services.ReShade.Utils; using Daybreak.Services.Scanner; using HtmlAgilityPack; @@ -16,12 +17,10 @@ using System.Collections.Generic; using System.Configuration; using System.Core.Extensions; -using System.Diagnostics; using System.Extensions; using System.IO; using System.Linq; using System.Net.Http; -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using System.Windows.Extensions.Services; @@ -44,9 +43,9 @@ public sealed class ReShadeService : IReShadeService, IApplicationLifetimeServic private static readonly string ReShadePresetPath = Path.Combine(Path.GetFullPath(ReShadePath), ReShadePreset); private static readonly string ReShadeLogPath = Path.Combine(Path.GetFullPath(ReShadePath), ReShadeLog); private static readonly string SourcePresetsFolderPath = Path.Combine(Path.GetFullPath(ReShadePath), PresetsFolder); - private static readonly string[] TextureExtensions = new string[] { ".png", ".jpg", ".jpeg" }; - private static readonly string[] FxExtensions = new string[] { ".fx", }; - private static readonly string[] FxHeaderExtensions = new string[] { ".fxh" }; + private static readonly string[] TextureExtensions = [".png", ".jpg", ".jpeg"]; + private static readonly string[] FxExtensions = [".fx",]; + private static readonly string[] FxHeaderExtensions = [".fxh"]; private readonly IGuildwarsMemoryCache guildwarsMemoryCache; private readonly INotificationService notificationService; @@ -140,7 +139,14 @@ public async Task OnGuildWarsCreated(ApplicationLauncherContext applicationLaunc } } - public Task OnGuildWarsStarted(ApplicationLauncherContext applicationLauncherContext, CancellationToken cancellationToken) => Task.CompletedTask; + public Task OnGuildWarsStarted(ApplicationLauncherContext applicationLauncherContext, CancellationToken cancellationToken) + { + var destinationDirectory = Path.GetFullPath(new FileInfo(applicationLauncherContext.ExecutablePath).DirectoryName!); + var destinationPreset = Path.Combine(destinationDirectory, ReShadePreset); + var destinationIni = Path.Combine(destinationDirectory, ConfigIni); + this.PeriodicallyCheckPresetChanges(applicationLauncherContext, destinationPreset, destinationIni); + return Task.CompletedTask; + } public Task OnGuildWarsStarting(ApplicationLauncherContext applicationLauncherContext, CancellationToken cancellationToken) { @@ -325,6 +331,94 @@ public async Task SavePreset(string config, CancellationToken cancellation return true; } + public async Task UpdateIniFromPath(string pathToIni, CancellationToken cancellationToken) + { + pathToIni = Path.GetFullPath(pathToIni); + var scopedLogger = this.logger.CreateScopedLogger(nameof(this.UpdateIniFromPath), pathToIni); + if (!File.Exists(pathToIni)) + { + scopedLogger.LogError("File doesn't exist"); + return false; + } + + var config = await File.ReadAllTextAsync(pathToIni, cancellationToken); + if (pathToIni.Contains(ConfigIni)) + { + await this.SaveConfig(config, cancellationToken); + } + + if (pathToIni.Contains(ReShadePreset)) + { + await this.SavePreset(config, cancellationToken); + } + + return true; + } + + private async void PeriodicallyCheckPresetChanges(ApplicationLauncherContext applicationLauncherContext, string presetsFile, string configFile) + { + var scopedLogger = this.logger.CreateScopedLogger(nameof(this.PeriodicallyCheckPresetChanges), presetsFile); + if (!File.Exists(presetsFile)) + { + scopedLogger.LogError("File does not exist"); + return; + } + + var presetsCache = File.ReadAllText(presetsFile); + var configCache = File.ReadAllText(configFile); + try + { + while (true) + { + if (applicationLauncherContext.Process.HasExited) + { + scopedLogger.LogInformation("Process has exited"); + return; + } + + await Task.Delay(1000); + if (!File.Exists(presetsFile)) + { + scopedLogger.LogError("Preset file has been deleted"); + return; + } + + if (!File.Exists(configFile)) + { + scopedLogger.LogError("Config file has been deleted"); + return; + } + + var currentPresets = File.ReadAllText(presetsFile); + if (currentPresets != presetsCache) + { + presetsCache = currentPresets; + this.notificationService.NotifyInformation( + title: "ReShade presets changed", + description: $"ReShade presets have been changed by {applicationLauncherContext.ExecutablePath}. Click on this notification to save the changes in Daybreak", + metaData: presetsFile); + continue; + } + + var currentConfig = File.ReadAllText(configFile); + if (currentConfig != configCache) + { + configCache = currentConfig; + this.notificationService.NotifyInformation( + title: "ReShade config changed", + description: $"ReShade config has been changed by {applicationLauncherContext.ExecutablePath}. Click on this notification to save the changes in Daybreak", + metaData: configFile); + continue; + } + } + } + catch(Exception e) + { + scopedLogger.LogError(e, "Encountered exception. Cancelling preset monitoring"); + return; + } + } + private async Task InstallPackageInternal( ZipFile archive, CancellationToken cancellationToken, diff --git a/Daybreak/Services/UMod/IUModService.cs b/Daybreak/Services/UMod/IUModService.cs index 2a6ade09..7290c640 100644 --- a/Daybreak/Services/UMod/IUModService.cs +++ b/Daybreak/Services/UMod/IUModService.cs @@ -8,8 +8,6 @@ namespace Daybreak.Services.UMod; public interface IUModService : IModService { - bool LoadUModFromDisk(); - Task SetupUMod(UModInstallationStatus uModInstallationStatus); Task CheckAndUpdateUMod(CancellationToken cancellationToken); diff --git a/Daybreak/Services/UMod/UModService.cs b/Daybreak/Services/UMod/UModService.cs index 272b03b7..d195965d 100644 --- a/Daybreak/Services/UMod/UModService.cs +++ b/Daybreak/Services/UMod/UModService.cs @@ -8,7 +8,6 @@ using Daybreak.Services.Notifications; using Daybreak.Services.Toolbox.Models; using Microsoft.Extensions.Logging; -using Microsoft.Win32; using System; using System.Collections.Generic; using System.Configuration; @@ -52,8 +51,7 @@ public bool IsEnabled } } - public bool IsInstalled => File.Exists(this.uModOptions.Value.DllPath) && - Path.GetFileName(this.uModOptions.Value.DllPath) == UModDll; + public bool IsInstalled => File.Exists(Path.GetFullPath(Path.Combine(UModDirectory, UModDll))); public UModService( IProcessInjector processInjector, @@ -107,26 +105,6 @@ public async Task OnGuildWarsCreated(ApplicationLauncherContext applicationLaunc public Task OnGuildWarsStarted(ApplicationLauncherContext applicationLauncherContext, CancellationToken cancellationToken) => Task.CompletedTask; - public bool LoadUModFromDisk() - { - var filePicker = new OpenFileDialog - { - Filter = "Dll Files (uMod.dll)|uMod.dll", - Multiselect = false, - RestoreDirectory = true, - Title = "Please select the uMod.dll" - }; - if (filePicker.ShowDialog() is false) - { - return false; - } - - var fileName = filePicker.FileName; - this.uModOptions.Value.DllPath = Path.GetFullPath(fileName); - this.uModOptions.UpdateOption(); - return true; - } - public async Task SetupUMod(UModInstallationStatus uModInstallationStatus) { if ((await this.SetupUModDll(uModInstallationStatus)) is false) @@ -272,12 +250,6 @@ private async Task SetupUModDll(UModInstallationStatus uModInstallationSta return false; } - Directory.CreateDirectory(Path.GetFullPath(UModDirectory)); - var uModPath = Path.GetFullPath(Path.Combine(UModDirectory, UModDll)); - - var uModOptions = this.uModOptions.Value; - uModOptions.DllPath = uModPath; - this.uModOptions.UpdateOption(); return true; } diff --git a/Daybreak/Views/Onboarding/UMod/UModInstallationChoiceView.xaml b/Daybreak/Views/Onboarding/UMod/UModInstallationChoiceView.xaml index 599b8990..92463e33 100644 --- a/Daybreak/Views/Onboarding/UMod/UModInstallationChoiceView.xaml +++ b/Daybreak/Views/Onboarding/UMod/UModInstallationChoiceView.xaml @@ -12,7 +12,7 @@ - diff --git a/Daybreak/Views/Onboarding/UMod/UModInstallationChoiceView.xaml.cs b/Daybreak/Views/Onboarding/UMod/UModInstallationChoiceView.xaml.cs index 3dc8716a..ef41709c 100644 --- a/Daybreak/Views/Onboarding/UMod/UModInstallationChoiceView.xaml.cs +++ b/Daybreak/Views/Onboarding/UMod/UModInstallationChoiceView.xaml.cs @@ -1,5 +1,4 @@ using Daybreak.Services.Navigation; -using Daybreak.Services.UMod; using Microsoft.Extensions.Logging; using System.Core.Extensions; using System.Windows.Controls; @@ -10,16 +9,13 @@ namespace Daybreak.Views.Onboarding.UMod; /// public partial class UModInstallationChoiceView : UserControl { - private readonly IUModService uModService; private readonly IViewManager viewManager; private readonly ILogger logger; public UModInstallationChoiceView( - IUModService uModService, IViewManager viewManager, ILogger logger) { - this.uModService = uModService.ThrowIfNull(); this.viewManager = viewManager.ThrowIfNull(); this.logger = logger.ThrowIfNull(); @@ -28,14 +24,11 @@ public UModInstallationChoiceView( private void OpaqueButtonNo_Clicked(object sender, System.EventArgs e) { - this.viewManager.ShowView(); + this.viewManager.ShowView(); } private void OpaqueButtonYes_Clicked(object sender, System.EventArgs e) { - if (this.uModService.LoadUModFromDisk()) - { - this.viewManager.ShowView(); - } + this.viewManager.ShowView(); } }