Skip to content

Commit

Permalink
Update to .net8.0 (#486)
Browse files Browse the repository at this point in the history
Fix uMod installation steps
ReShade monitor config changes
  • Loading branch information
AlexMacocian authored Nov 18, 2023
1 parent cd2a529 commit e1dfd1f
Show file tree
Hide file tree
Showing 19 changed files with 164 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand Down Expand Up @@ -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 }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/version_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Daybreak.7ZipExtractor/Daybreak.7ZipExtractor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Daybreak._7ZipExtractor</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
2 changes: 1 addition & 1 deletion Daybreak.Installer/Daybreak.Installer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>AnyCPU;x86;x64</Platforms>
Expand Down
2 changes: 1 addition & 1 deletion Daybreak.Tests/Daybreak.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<IsPackable>false</IsPackable>
<Platforms>AnyCPU;x86;x64</Platforms>
</PropertyGroup>
Expand Down
4 changes: 0 additions & 4 deletions Daybreak/Configuration/Options/UModOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 2 additions & 0 deletions Daybreak/Configuration/ProjectConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -427,6 +428,7 @@ public override void RegisterNotificationHandlers(INotificationHandlerProducer n
notificationHandlerProducer.RegisterNotificationHandler<TradeMessageNotificationHandler>();
notificationHandlerProducer.RegisterNotificationHandler<FixSymbolicLinkNotificationHandler>();
notificationHandlerProducer.RegisterNotificationHandler<UpdateNotificationHandler>();
notificationHandlerProducer.RegisterNotificationHandler<ReShadeConfigChangedHandler>();
}

public override void RegisterMods(IModsManager modsManager)
Expand Down
20 changes: 10 additions & 10 deletions Daybreak/Daybreak.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<RootNamespace>Daybreak</RootNamespace>
<!--Unable to migrate to .net 7 due to issues with font families not being found #140-->
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
Expand All @@ -13,7 +13,7 @@
<LangVersion>preview</LangVersion>
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<Version>0.9.8.149</Version>
<Version>0.9.8.150</Version>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<UserSecretsId>cfb2a489-db80-448d-a969-80270f314c46</UserSecretsId>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
Expand Down Expand Up @@ -93,23 +93,23 @@
<PackageReference Include="HtmlAgilityPack" Version="1.11.54" />
<PackageReference Include="ini-parser-netstandard" Version="2.5.2" />
<PackageReference Include="LiteDB" Version="5.0.17" />
<PackageReference Include="LiveChartsCore.SkiaSharpView.WPF" Version="2.0.0-rc1.2" />
<PackageReference Include="LiveChartsCore.SkiaSharpView.WPF" Version="2.0.0-rc2" />
<PackageReference Include="MahApps.Metro" Version="2.4.10" />
<PackageReference Include="Microsoft.CorrelationVector" Version="1.0.42" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2151.40" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Plumsy" Version="1.1.0" />
<PackageReference Include="securifybv.ShellLink" Version="0.1.0" />
<PackageReference Include="Slim" Version="1.9.2" />
<PackageReference Include="Svg" Version="3.4.5" />
<PackageReference Include="Svg" Version="3.4.6" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="System.Reflection.Metadata" Version="7.0.2" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
<PackageReference Include="System.Reflection.Metadata" Version="8.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
<PackageReference Include="SystemExtensions.NetCore" Version="1.0.1" />
<PackageReference Include="SystemExtensions.NetStandard" Version="1.6.2" />
<PackageReference Include="SystemExtensions.NetStandard.DependencyInjection" Version="1.3.1" />
Expand Down
4 changes: 2 additions & 2 deletions Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
9 changes: 4 additions & 5 deletions Daybreak/Services/Charts/LiveChartInitializer.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,15 +21,13 @@ public void OnStartup()
.AddDefaultMappers()
.AddDarkTheme()
.AddLightTheme()
.HasMap<Metric>((metric, point) =>
.HasMap<Metric>((metric, index) =>
{
point.SecondaryValue = metric.Timestamp.Ticks;
point.PrimaryValue = Convert.ToDouble(metric.Measurement);
return new Coordinate(Convert.ToDouble(metric.Measurement), metric.Timestamp.Ticks);
})
.HasMap<TraderQuote>((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);
}));
}
}
1 change: 1 addition & 0 deletions Daybreak/Services/ReShade/IReShadeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public interface IReShadeService : IModService
Task<bool> SaveConfig(string config, CancellationToken cancellationToken);
Task<string> GetPreset(CancellationToken cancellationToken);
Task<bool> SavePreset(string config, CancellationToken cancellationToken);
Task<bool> UpdateIniFromPath(string pathToIni, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
106 changes: 100 additions & 6 deletions Daybreak/Services/ReShade/ReShadeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -325,6 +331,94 @@ public async Task<bool> SavePreset(string config, CancellationToken cancellation
return true;
}

public async Task<bool> 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<ReShadeConfigChangedHandler>(
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<ReShadeConfigChangedHandler>(
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,
Expand Down
2 changes: 0 additions & 2 deletions Daybreak/Services/UMod/IUModService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
namespace Daybreak.Services.UMod;
public interface IUModService : IModService
{
bool LoadUModFromDisk();

Task<bool> SetupUMod(UModInstallationStatus uModInstallationStatus);

Task CheckAndUpdateUMod(CancellationToken cancellationToken);
Expand Down
Loading

0 comments on commit e1dfd1f

Please sign in to comment.