Skip to content

Commit

Permalink
fix automatic gsi patcher not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln committed Sep 6, 2024
1 parent cbd6a7c commit 96049bf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 18 deletions.
59 changes: 49 additions & 10 deletions Project-Aurora/Project-Aurora/Modules/AutomaticGsiPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using System.Windows;
using AuroraRgb.Profiles;
using Application = AuroraRgb.Profiles.Application;
Expand Down Expand Up @@ -26,17 +27,20 @@ protected override async Task Initialize()
var lightEvent = args.Application;
Task.Run(async () =>
{
var installGsi = await userPromptTcs.Task;
if (!installGsi)
{
return;
}
await InstallAppGsi(lightEvent);
await RunInstallation(userPromptTcs, lightEvent);
});
};
foreach (var application in lsm.Events.Values)
{
_ = Task.Run(async () =>
{
await RunInstallation(userPromptTcs, application);
});
}

if (Global.Configuration.AutoInstallGsi != null)
{
userPromptTcs.SetResult(Global.Configuration.AutoInstallGsi ?? false);
return;
}

Expand All @@ -50,15 +54,50 @@ protected override async Task Initialize()
userPromptTcs.SetResult(Global.Configuration.AutoInstallGsi ?? false);
}

private static async Task RunInstallation(TaskCompletionSource<bool> userPromptTcs, Application lightEvent)
{
try
{
var installGsi = await userPromptTcs.Task;
if (!installGsi)
{
return;
}

await InstallAppGsi(lightEvent);
}
catch (Exception e)
{
Global.logger.Error(e, "[AutomaticGsiPatcher] An error occured while installing Gsi of {App}", lightEvent.Config.Name);
}
}

private static async Task InstallAppGsi(Application lightEvent)
{
switch (lightEvent)
{
case GsiApplication application:
if (application.Settings?.InstallationCompleted ?? false)
var retries = 5;
while (retries-- > 0)
{
await application.InstallGsi();
await application.SaveSettings();
if (application.Settings != null)
{
if (!application.Settings.InstallationCompleted)
{
Global.logger.Information("[AutomaticGsiPatcher] Installing {App} Gsi", application.Config.Name);
await application.InstallGsi();
await application.SaveSettings();
Global.logger.Information("[AutomaticGsiPatcher] {App} Gsi installed", application.Config.Name);
}
}
else
{
Global.logger.Error("[AutomaticGsiPatcher] {App} settings not loaded to determine GSI installation status", application.Config.Name);
await Task.Delay(200);
continue;
}

break;
}

break;
Expand Down
9 changes: 1 addition & 8 deletions Project-Aurora/Project-Aurora/Settings/ObjectSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,12 @@ protected virtual async Task LoadSettings(Type settingsType)
try
{
var json = await File.ReadAllTextAsync(SettingsSavePath);
Settings = (T)JsonConvert.DeserializeObject(json, settingsType, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None });
if (Settings == null)
{
await SaveSettings(settingsType);
}
Settings = JsonConvert.DeserializeObject<T>(json, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None });
}
catch (Exception exc)
{
Global.logger.Error(exc, "Exception occured while loading \\\"{Name}\\\" Settings", GetType().Name);
await SaveSettings(settingsType);
}
}
else
await SaveSettings(settingsType);
}
}
9 changes: 9 additions & 0 deletions Project-Aurora/Project-Aurora/Utils/Steam/SteamUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Win32;
using VdfParser;
Expand All @@ -12,6 +13,8 @@ namespace AuroraRgb.Utils.Steam;
public static class SteamUtils
{
private static readonly VdfDeserializer VdfDeserializer = new();

private static readonly SemaphoreSlim SteamReadLock = new(1, 1);

public static async Task<bool> InstallGsiFile(int gameId, string gameRelativeFilePath, byte[] gsiFile)
{
Expand Down Expand Up @@ -74,6 +77,7 @@ public static async Task<bool> InstallGsiFile(int gameId, string gameRelativeFil
if (Directory.Exists(appIdPath))
return appIdPath;
}

return null;
}
catch (Exception exc)
Expand All @@ -90,6 +94,7 @@ public static async Task<bool> InstallGsiFile(int gameId, string gameRelativeFil
/// <returns>Path to the location of AppID's install</returns>
public static async Task<string?> GetGamePathAsync(int gameId)
{
await SteamReadLock.WaitAsync();
Global.logger.Debug("Trying to get game path for: {GameId}", gameId);

try
Expand Down Expand Up @@ -129,6 +134,10 @@ public static async Task<bool> InstallGsiFile(int gameId, string gameRelativeFil
Global.logger.Error(exc, "SteamUtils: GetGamePath({GameId})", gameId);
return null;
}
finally
{
SteamReadLock.Release();
}
}

private static string? GetSteamPath()
Expand Down

0 comments on commit 96049bf

Please sign in to comment.