Skip to content

Commit

Permalink
Merge pull request #17 from Drommedhar/async_gather
Browse files Browse the repository at this point in the history
# 2.0.4.0
* Improve speed of game gather step
* Fix bug after adding a new game the game will be already selected on adding another manual game
* Changing game data in configuration view only applies if clicking apply now not in realtime
  • Loading branch information
Drommedhar authored Oct 10, 2024
2 parents e20105f + ee9707a commit 9f3a59b
Show file tree
Hide file tree
Showing 12 changed files with 351 additions and 224 deletions.
4 changes: 2 additions & 2 deletions DlssUpdater/DLSSUpdater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Platforms>x64</Platforms>
<FileVersion>2.0.3.0</FileVersion>
<FileVersion>2.0.4.0</FileVersion>
<SelfContained>true</SelfContained>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<SignAssembly>False</SignAssembly>
<AssemblyVersion>2.0.3.0</AssemblyVersion>
<AssemblyVersion>2.0.4.0</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down
31 changes: 23 additions & 8 deletions DlssUpdater/Defines/GameInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -58,19 +59,25 @@ public GameInfo(GameInfo gameInfo)
{
GameName = gameInfo.GameName;
GamePath = gameInfo.GamePath;
GameImageUri = gameInfo.GameImageUri;
LibraryType = gameInfo.LibraryType;
_removeVisible = LibraryType == LibraryType.Manual ? Visibility.Visible : Visibility.Collapsed;
UniqueId = gameInfo.UniqueId;
IsHidden = gameInfo.IsHidden;
GameImage = gameInfo.GameImage;
InstalledDlls = gameInfo.InstalledDlls;
GameImageUri = gameInfo.GameImageUri;
foreach(var kvp in gameInfo.InstalledDlls)
{
InstalledDlls.Add(kvp.Key, kvp.Value);
}
_updater = gameInfo._updater;
_logger = gameInfo._logger;
_libPage = gameInfo._libPage;
InstalledVersionDlss = "N/A";
InstalledVersionDlssD = "N/A";
InstalledVersionDlssG = "N/A";
InstalledVersionDlss = gameInfo.InstalledVersionDlss;
InstalledVersionDlssD = gameInfo.InstalledVersionDlssD;
InstalledVersionDlssG = gameInfo._installedVersionDlssG;
GenerateGameImage();
setLibraryImage();
setHideImage();
SetAntiCheatImage();

Self = this;
}
Expand Down Expand Up @@ -210,14 +217,18 @@ public bool HasInstalledDlls()
public void SetGameImageUri(string imageUri)
{
GameImageUri = imageUri;
}

public void GenerateGameImage()
{
try
{
if (!string.IsNullOrEmpty(GameImageUri))
{
GameImage = new BitmapImage(new Uri(GameImageUri));
}
}
catch(FileNotFoundException ex)
catch (FileNotFoundException ex)
{
_logger.Error($"Image not found: {ex}");
}
Expand Down Expand Up @@ -263,7 +274,11 @@ public class GameConvert : JsonConverter<GameInfo>
}
info.UniqueId = uniqueId!;
info.IsHidden = isHidden;
if (!string.IsNullOrEmpty(gameImageUri)) info.SetGameImageUri(gameImageUri);
if (!string.IsNullOrEmpty(gameImageUri))
{
info.SetGameImageUri(gameImageUri);
info.GenerateGameImage();
}
return info;
}

Expand Down
90 changes: 53 additions & 37 deletions DlssUpdater/GameLibrary/EpicGames/EpicGamesLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text;
using System.Text.Json;
using System.Xml.Linq;
using DlssUpdater;
using DlssUpdater.GameLibrary;
using DlssUpdater.Helpers;
using DLSSUpdater.Defines;
Expand Down Expand Up @@ -90,57 +91,72 @@ private async Task<List<GameInfo>> getGames()
}
}

List<Task> tasks = [];
var throttler = new SemaphoreSlim(initialCount: Settings.Constants.CoreCount);
var files = Directory.GetFiles(path);
foreach (var file in files)
{
var data = await File.ReadAllBytesAsync(file);
var yourObject = JsonDocument.Parse(data);

try
var task = Task.Run(async () =>
{
var isApp = yourObject.RootElement.GetProperty("bIsApplication").GetBoolean();
if (!isApp)
{
continue;
}

var displayName = yourObject.RootElement.GetProperty("DisplayName").GetString();
var location = yourObject.RootElement.GetProperty("InstallLocation").GetString()?.Replace('/', '\\');
var catalogId = yourObject.RootElement.GetProperty("CatalogItemId").GetString();

var cachedData = cachedGames.FirstOrDefault(g => g.Id == catalogId);
if (cachedData is null || string.IsNullOrEmpty(displayName) || string.IsNullOrEmpty(location))
{
continue;
}
// do an async wait until we can schedule again
await throttler.WaitAsync();

var imageObj = cachedData.KeyImages.FirstOrDefault(i => i.Type == "DieselGameBoxTall");
var data = await File.ReadAllBytesAsync(file);
var yourObject = JsonDocument.Parse(data);

var info = new GameInfo(displayName, location, GetLibraryType())
{
UniqueId = "epic_" + catalogId!
};
if (imageObj is not null && !string.IsNullOrEmpty(imageObj.Url))
try
{
info.SetGameImageUri(imageObj.Url);
var isApp = yourObject.RootElement.GetProperty("bIsApplication").GetBoolean();
if (!isApp)
{
return;
}

var displayName = yourObject.RootElement.GetProperty("DisplayName").GetString();
var location = yourObject.RootElement.GetProperty("InstallLocation").GetString()?.Replace('/', '\\');
var catalogId = yourObject.RootElement.GetProperty("CatalogItemId").GetString();

var cachedData = cachedGames.FirstOrDefault(g => g.Id == catalogId);
if (cachedData is null || string.IsNullOrEmpty(displayName) || string.IsNullOrEmpty(location))
{
return;
}

var imageObj = cachedData.KeyImages.FirstOrDefault(i => i.Type == "DieselGameBoxTall");

var info = new GameInfo(displayName, location, GetLibraryType())
{
UniqueId = "epic_" + catalogId!
};
if (imageObj is not null && !string.IsNullOrEmpty(imageObj.Url))
{
info.SetGameImageUri(imageObj.Url);
}

await info.GatherInstalledVersions();
if (info.HasInstalledDlls())
{
ret.Add(info);
}
else
{
_logger.Debug($"EpicGames: '{info.GameName}' does not have any DLSS dll and is being ignored.");
}
}

await info.GatherInstalledVersions();
if (info.HasInstalledDlls())
catch (Exception ex)
{
ret.Add(info);
_logger.Warn($"EpicGames Parsing manifest failed with: {ex}");
}
else
finally
{
_logger.Debug($"EpicGames: '{info.GameName}' does not have any DLSS dll and is being ignored.");
throttler.Release();
}
}
catch (Exception ex)
{
_logger.Warn($"EpicGames Parsing manifest failed with: {ex}");
}
});

tasks.Add(task);
}

await Task.WhenAll(tasks);
return ret;
}

Expand Down
94 changes: 57 additions & 37 deletions DlssUpdater/GameLibrary/GOGLibrary.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO;
using System.Text.Json;
using DlssUpdater;
using DlssUpdater.GameLibrary;
using DlssUpdater.Helpers;
using DLSSUpdater.Defines;
Expand Down Expand Up @@ -51,47 +52,66 @@ private async Task<List<GameInfo>> getGames()
return ret;
}

List<Task> tasks = [];
var throttler = new SemaphoreSlim(initialCount: Settings.Constants.CoreCount);
foreach (var subKey in subKeys)
{
var gameKey = hklm.OpenSubKey(Path.Combine(@"SOFTWARE\GOG.com\Games", subKey));
if (gameKey == null)
var task = Task.Run(async () =>
{
continue;
}

var dependsOn = gameKey.GetValue("dependsOn") as string;
if (!string.IsNullOrEmpty(dependsOn))
{
continue;
}

var name = gameKey.GetValue("gameName") as string;
var path = gameKey.GetValue("path") as string;
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(path))
{
continue;
}

var info = new GameInfo(name, path, GetLibraryType())
{
UniqueId = "gog_" + subKey
};
var gameImage = await getGameImage(subKey) ?? string.Empty;
if (!string.IsNullOrEmpty(gameImage))
{
info.SetGameImageUri(gameImage);
}

await info.GatherInstalledVersions();
if (info.HasInstalledDlls())
{
ret.Add(info);
}
else
{
_logger.Debug($"GOG: '{info.GameName}' does not have any DLSS dll and is being ignored.");
}
try
{
// do an async wait until we can schedule again
await throttler.WaitAsync();

var gameKey = hklm.OpenSubKey(Path.Combine(@"SOFTWARE\GOG.com\Games", subKey));
if (gameKey == null)
{
return;
}

var dependsOn = gameKey.GetValue("dependsOn") as string;
if (!string.IsNullOrEmpty(dependsOn))
{
return;
}

var name = gameKey.GetValue("gameName") as string;
var path = gameKey.GetValue("path") as string;
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(path))
{
return;
}

var info = new GameInfo(name, path, GetLibraryType())
{
UniqueId = "gog_" + subKey
};
var gameImage = await getGameImage(subKey) ?? string.Empty;
if (!string.IsNullOrEmpty(gameImage))
{
info.SetGameImageUri(gameImage);
}

await info.GatherInstalledVersions();
if (info.HasInstalledDlls())
{
ret.Add(info);
}
else
{
_logger.Debug($"GOG: '{info.GameName}' does not have any DLSS dll and is being ignored.");
}
}
finally
{
throttler.Release();
}
});

tasks.Add(task);
}
await Task.WhenAll(tasks);

return ret;
}

Expand Down
47 changes: 34 additions & 13 deletions DlssUpdater/GameLibrary/Steam/SteamLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ private async Task<List<LibraryFolder>> getLibraryFolders()
for (var i = 0; i < paths.Count; i++)
{
var path = paths[i];
var appIds = apps[i];
List<string> appIds = [];
foreach (var a in apps[i])
{
appIds.Add(a);
}

LibraryFolder folder = new(Path.Combine(path, "steamapps"))
{
Apps = appIds
Expand All @@ -93,27 +98,43 @@ public void GetInstallationDirectory()

private async Task<List<GameInfo>> getGames(List<LibraryFolder> folder)
{
List<Task> tasks = [];
List<GameInfo> ret = [];

var throttler = new SemaphoreSlim(initialCount: Settings.Constants.CoreCount);

foreach (var folderItem in folder)
{
foreach (var app in folderItem.Apps)
{
var appPath = Path.Combine(folderItem.Path, $"appmanifest_{app}.acf");
if (!File.Exists(appPath))
var task = Task.Run(async () =>
{
_logger.Warn($"Steam: {appPath} not found.");
continue;
}

var info = await getGameFromManifest(appPath, app);
if (info is not null)
{
ret.Add(info);
}
// do an async wait until we can schedule again
await throttler.WaitAsync();

var appPath = Path.Combine(folderItem.Path, $"appmanifest_{app}.acf");
if (!File.Exists(appPath))
{
_logger.Warn($"Steam: {appPath} not found.");
}
else
{

var info = await getGameFromManifest(appPath, app);
if (info is not null)
{
ret.Add(info);
}
}

throttler.Release();
});
tasks.Add(task);
}
}

await Task.WhenAll(tasks);

return ret;
}

Expand All @@ -136,6 +157,7 @@ private async Task<List<GameInfo>> getGames(List<LibraryFolder> folder)
_logger.Warn($"Steam: getGameFromManifest could not find file {finalGamePath}");
return null;
}

var info = new GameInfo(gameName[0], finalGamePath, LibraryType.Steam)
{
UniqueId = "steam_" + appId,
Expand All @@ -150,7 +172,6 @@ private async Task<List<GameInfo>> getGames(List<LibraryFolder> folder)
if (info.HasInstalledDlls()) return info;

_logger.Debug($"Steam: '{info.GameName}' does not have any DLSS dll and is being ignored.");

return null;
}

Expand Down
Loading

0 comments on commit 9f3a59b

Please sign in to comment.