Skip to content

Commit

Permalink
Add logging, fix warnings & more
Browse files Browse the repository at this point in the history
  • Loading branch information
Drommedhar committed Sep 25, 2024
1 parent b737960 commit 16d262f
Show file tree
Hide file tree
Showing 37 changed files with 193 additions and 125 deletions.
2 changes: 1 addition & 1 deletion DlssUpdater/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemesDictionary Theme="Light" />
<ui:ThemesDictionary Theme="Dark" />
<ui:ControlsDictionary />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Expand Down
3 changes: 2 additions & 1 deletion DlssUpdater/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public partial class App
services.AddSingleton<SettingsViewModel>();
services.AddSingleton<ChangelogPage>();
services.AddSingleton<ChangelogViewModel>();
services.AddSingleton(NLog.LogManager.GetCurrentClassLogger());

services.AddSingleton<Settings>();
services.AddSingleton<DllUpdater>();
Expand All @@ -76,7 +77,7 @@ public partial class App
/// </summary>
/// <typeparam name="T">Type of the service to get.</typeparam>
/// <returns>Instance of the service or <see langword="null" />.</returns>
public static T GetService<T>()
public static T? GetService<T>()
where T : class
{
return _host.Services.GetService(typeof(T)) as T;
Expand Down
Binary file removed DlssUpdater/Assets/wpfui-icon-1024.png
Binary file not shown.
Binary file removed DlssUpdater/Assets/wpfui-icon-256.png
Binary file not shown.
4 changes: 2 additions & 2 deletions DlssUpdater/Controls/DownloadButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public partial class DownloadButton : UserControl

public DownloadButton()
{
_updater = App.GetService<DllUpdater>();
_snackbar = App.GetService<ISnackbarService>();
_updater = App.GetService<DllUpdater>()!;
_snackbar = App.GetService<ISnackbarService>()!;

InitializeComponent();

Expand Down
2 changes: 1 addition & 1 deletion DlssUpdater/Controls/GameButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class GameButton : UserControl
public GameButton()
{
InitializeComponent();
_gameContainer = App.GetService<GameContainer>();
_gameContainer = App.GetService<GameContainer>()!;
gridAntiCheat.Visibility = Visibility.Hidden;
selectionBox.Visibility = Visibility.Hidden;
}
Expand Down
17 changes: 12 additions & 5 deletions DlssUpdater/DLSSUpdater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
<AssemblyVersion>1.0.0.2</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<Content Include="icon.ico" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Expression.Blend.Sdk" Version="1.0.2" />
<PackageReference Include="MdXaml" Version="1.27.0" />
<PackageReference Include="NLog" Version="5.3.4" />
<PackageReference Include="System.Drawing.Common" Version="8.0.8" />
<PackageReference Include="WPF-UI" Version="3.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
Expand All @@ -31,21 +39,20 @@
</ItemGroup>

<ItemGroup>
<None Remove="Assets\wpfui-icon-256.png" />
<None Remove="Assets\wpfui-icon-1024.png" />
<None Remove="Windows\Splashscreen\splash.png" />
</ItemGroup>

<ItemGroup>
<Resource Include="Assets\wpfui-icon-256.png" />
<Resource Include="Assets\wpfui-icon-1024.png" />
<Resource Include="Windows\Splashscreen\splash.png" />
</ItemGroup>

<ItemGroup>
<None Update="changelog.md">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="version.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
4 changes: 2 additions & 2 deletions DlssUpdater/Defines/GameInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public GameInfo(string gameName, string gamePath, LibraryType type)
foreach (DllType dllType in Enum.GetValues(typeof(DllType))) InstalledDlls.Add(dllType, new InstalledPackage());

Self = this;
HasAntiCheat = App.GetService<AntiCheatChecker>().Check(gamePath);
HasAntiCheat = App.GetService<AntiCheatChecker>()!.Check(gamePath);
}

[JsonIgnore] public Dictionary<DllType, InstalledPackage> InstalledDlls { get; set; } = [];
Expand Down Expand Up @@ -86,7 +86,7 @@ public class GameConvert : JsonConverter<GameInfo>
{
if (reader.TokenType == JsonTokenType.EndObject)
{
var info = new GameInfo(gameName, gamePath, LibraryType.Manual);
var info = new GameInfo(gameName!, gamePath!, LibraryType.Manual);
if (!string.IsNullOrEmpty(gameImageUri)) info.SetGameImageUri(gameImageUri);
return info;
}
Expand Down
7 changes: 7 additions & 0 deletions DlssUpdater/Defines/InstalledPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ public class InstalledPackage
public string VersionDetailed { get; set; }
public string Path { get; set; }

public InstalledPackage()
{
Version = string.Empty;
VersionDetailed = string.Empty;
Path = string.Empty;
}

public override string ToString()
{
return Version;
Expand Down
7 changes: 7 additions & 0 deletions DlssUpdater/Defines/OnlinePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ public class OnlinePackage
public string MD5 { get; set; }
public string DownloadId { get; set; }

public OnlinePackage()
{
Version = string.Empty;
MD5 = string.Empty;
DownloadId = string.Empty;
}

public override string ToString()
{
return Version;
Expand Down
8 changes: 4 additions & 4 deletions DlssUpdater/GameLibrary/ILibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public interface ILibrary
{
public Task<List<GameInfo>> GatherGamesAsync();

static ILibrary Create(LibraryType type)
static ILibrary Create(LibraryType type, NLog.Logger logger)
{
return type switch
{
LibraryType.Manual => new ManualLibrary(),
LibraryType.Steam => new SteamLibrary(),
LibraryType.Ubisoft => new UbisoftConnectLibrary(),
LibraryType.Manual => new ManualLibrary(logger),
LibraryType.Steam => new SteamLibrary(logger),
LibraryType.Ubisoft => new UbisoftConnectLibrary(logger),
_ => throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(LibraryType))
};
}
Expand Down
5 changes: 5 additions & 0 deletions DlssUpdater/GameLibrary/ManualLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace DlssUpdater.GameLibrary;

public class ManualLibrary : ILibrary
{
public ManualLibrary(NLog.Logger logger)
{

}

public async Task<List<GameInfo>> GatherGamesAsync()

Check warning on line 12 in DlssUpdater/GameLibrary/ManualLibrary.cs

View workflow job for this annotation

GitHub Actions / build (x64)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 12 in DlssUpdater/GameLibrary/ManualLibrary.cs

View workflow job for this annotation

GitHub Actions / build (x64)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
List<GameInfo> ret = [];
Expand Down
42 changes: 33 additions & 9 deletions DlssUpdater/GameLibrary/Steam/SteamLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ namespace DlssUpdater.GameLibrary.Steam;
public class SteamLibrary : ILibrary
{
private string? _installPath;
private readonly NLog.Logger _logger;

internal SteamLibrary()
internal SteamLibrary(NLog.Logger logger)
{
_logger = logger;

getInstallationDirectory();
}

Expand Down Expand Up @@ -59,6 +62,9 @@ private void getInstallationDirectory()
using var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
using var steamRegistryKey = hklm.OpenSubKey(@"SOFTWARE\Valve\Steam");
var installPath = steamRegistryKey?.GetValue("InstallPath") as string;

_logger.Debug($"Steam install directory: {installPath ?? "N/A"}");

if (!string.IsNullOrEmpty(installPath)) _installPath = installPath;
}

Expand All @@ -67,13 +73,22 @@ private async Task<List<GameInfo>> getGames(List<LibraryFolder> folder)
List<GameInfo> ret = [];

foreach (var folderItem in folder)
foreach (var app in folderItem.Apps)
{
var appPath = Path.Combine(folderItem.Path, $"appmanifest_{app}.acf");
if (!File.Exists(appPath)) continue;

var info = await getGameFromManifest(appPath, app);
if (info is not null) ret.Add(info);
foreach (var app in folderItem.Apps)
{
var appPath = Path.Combine(folderItem.Path, $"appmanifest_{app}.acf");
if (!File.Exists(appPath))
{
_logger.Warn($"Steam: {appPath} not found.");
continue;
}

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

return ret;
Expand All @@ -86,10 +101,18 @@ private async Task<List<GameInfo>> getGames(List<LibraryFolder> folder)

var gameName = parser.GetValuesForKey<string>("name");
var gamePath = parser.GetValuesForKey<string>("installdir");
if (gameName.Count != 1 || gamePath.Count != 1) return null;
if (gameName.Count != 1 || gamePath.Count != 1)
{
_logger.Warn($"Steam: getGameFromManifest returned {gameName.Count} and {gamePath.Count}");
return null;
}

var finalGamePath = Path.Combine(Path.GetDirectoryName(path)!, "common", gamePath[0]);
if (!Directory.Exists(finalGamePath)) return null;
if (!Directory.Exists(finalGamePath))
{
_logger.Warn($"Steam: getGameFromManifest could not find file {finalGamePath}");
return null;
}
var info = new GameInfo(gameName[0], finalGamePath, LibraryType.Steam);
var imageUri = getGameImage(appId);
if (imageUri != null)
Expand All @@ -101,6 +124,7 @@ private async Task<List<GameInfo>> getGames(List<LibraryFolder> folder)
await info.GatherInstalledVersions();
if (info.HasInstalledDlls()) return info;

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

Expand Down
18 changes: 9 additions & 9 deletions DlssUpdater/GameLibrary/Steam/VdfParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,32 @@ public List<T> GetValuesForKey<T>(string key)

private string? getString(int start)
{
var startIndex = _data.IndexOf('\"', start + 1);
var endIndex = _data.IndexOf('\"', startIndex + 1);
var startIndex = _data!.IndexOf('\"', start + 1);
var endIndex = _data!.IndexOf('\"', startIndex + 1);
if (startIndex == -1 || endIndex == -1) return null;

return _data.Substring(startIndex + 1, endIndex - startIndex - 1);
return _data!.Substring(startIndex + 1, endIndex - startIndex - 1);
}

private List<string> getObject(int start)
{
List<string> objects = [];

var objectStart = _data.IndexOf('{', start + 1);
var objectEnd = _data.IndexOf('}', start + 1);
var objectStart = _data!.IndexOf('{', start + 1);
var objectEnd = _data!.IndexOf('}', start + 1);
if (objectStart == -1 || objectEnd == -1) return objects;

var startIndex = objectStart;
int index;
while ((index = _data.IndexOf('\"', startIndex)) != -1 && index <= objectEnd)
while ((index = _data!.IndexOf('\"', startIndex)) != -1 && index <= objectEnd)
{
// index now contains the start of the value, find the end
var valueEndIndex = _data.IndexOf('\"', index + 1);
var valueEndIndex = _data!.IndexOf('\"', index + 1);
if (valueEndIndex == -1)
// Should not happen, but better be safe
break;

var value = _data.Substring(index + 1, valueEndIndex - index - 1);
var value = _data!.Substring(index + 1, valueEndIndex - index - 1);
objects.Add(value.Trim());
startIndex = valueEndIndex + 1;
}
Expand All @@ -91,7 +91,7 @@ private List<int> findKeyIndices(string key)

var startIndex = 0;
int index;
while ((index = _data.IndexOf(key, startIndex)) != -1)
while ((index = _data!.IndexOf(key, startIndex)) != -1)
{
keyIndidices.Add(index);
startIndex = index + 1;
Expand Down
15 changes: 13 additions & 2 deletions DlssUpdater/GameLibrary/UbisoftConnectLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ namespace DlssUpdater.GameLibrary;
public class UbisoftConnectLibrary : ILibrary
{
private string? _installPath;
private readonly NLog.Logger _logger;

internal UbisoftConnectLibrary()
internal UbisoftConnectLibrary(NLog.Logger logger)
{
_logger = logger;

getInstallationDirectory();
}

Expand All @@ -28,6 +31,9 @@ private void getInstallationDirectory()
using var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
using var ubiRegKey = hklm.OpenSubKey(@"SOFTWARE\Ubisoft\Launcher");
var installPath = ubiRegKey?.GetValue("InstallDir") as string;

_logger.Debug($"Ubisoft Connect install directory: {installPath ?? "N/A"}");

if (!string.IsNullOrEmpty(installPath)) _installPath = installPath;
}

Expand All @@ -42,6 +48,7 @@ private async Task<List<GameInfo>> getGames()
var configPath = Path.Combine(_installPath, "cache", "configuration", "configurations");
if(!File.Exists(configPath))
{
_logger.Warn($"Ubisoft connect: Could not find configurations file at {configPath}");
return ret;
}

Expand Down Expand Up @@ -73,6 +80,7 @@ private async Task<List<GameInfo>> getGames()
var gamePath = gameRegKey?.GetValue("InstallDir") as string;
if (string.IsNullOrEmpty(gamePath))
{
_logger.Warn($"Ubisoft connect: Could not find regkey for {registerKey}");
continue;
}

Expand All @@ -88,7 +96,10 @@ private async Task<List<GameInfo>> getGames()
}
ret.Add(info);
}

else
{
_logger.Debug($"Ubisoft connect: '{info.GameName}' does not have any DLSS dll.");
}
}

return ret;
Expand Down
2 changes: 1 addition & 1 deletion DlssUpdater/Helpers/EnumHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static T SetFlag<T>(this Enum value, T flag, bool set)

// note: AsInt mean: math integer vs enum (not the c# int type)
dynamic valueAsInt = Convert.ChangeType(value, underlyingType);
dynamic flagAsInt = Convert.ChangeType(flag, underlyingType);
dynamic flagAsInt = Convert.ChangeType(flag, underlyingType)!;
if (set)
{
valueAsInt |= flagAsInt;
Expand Down
Loading

0 comments on commit 16d262f

Please sign in to comment.