diff --git a/DlssUpdater/App.xaml b/DlssUpdater/App.xaml index 64459c9..828c5dd 100644 --- a/DlssUpdater/App.xaml +++ b/DlssUpdater/App.xaml @@ -9,7 +9,7 @@ - + diff --git a/DlssUpdater/App.xaml.cs b/DlssUpdater/App.xaml.cs index 7fe6f6e..e95bf31 100644 --- a/DlssUpdater/App.xaml.cs +++ b/DlssUpdater/App.xaml.cs @@ -61,6 +61,7 @@ public partial class App services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(NLog.LogManager.GetCurrentClassLogger()); services.AddSingleton(); services.AddSingleton(); @@ -76,7 +77,7 @@ public partial class App /// /// Type of the service to get. /// Instance of the service or . - public static T GetService() + public static T? GetService() where T : class { return _host.Services.GetService(typeof(T)) as T; diff --git a/DlssUpdater/Assets/wpfui-icon-1024.png b/DlssUpdater/Assets/wpfui-icon-1024.png deleted file mode 100644 index b70c4ed..0000000 Binary files a/DlssUpdater/Assets/wpfui-icon-1024.png and /dev/null differ diff --git a/DlssUpdater/Assets/wpfui-icon-256.png b/DlssUpdater/Assets/wpfui-icon-256.png deleted file mode 100644 index 6b5cf5d..0000000 Binary files a/DlssUpdater/Assets/wpfui-icon-256.png and /dev/null differ diff --git a/DlssUpdater/Controls/DownloadButton.xaml.cs b/DlssUpdater/Controls/DownloadButton.xaml.cs index 900204b..dcdfa36 100644 --- a/DlssUpdater/Controls/DownloadButton.xaml.cs +++ b/DlssUpdater/Controls/DownloadButton.xaml.cs @@ -28,8 +28,8 @@ public partial class DownloadButton : UserControl public DownloadButton() { - _updater = App.GetService(); - _snackbar = App.GetService(); + _updater = App.GetService()!; + _snackbar = App.GetService()!; InitializeComponent(); diff --git a/DlssUpdater/Controls/GameButton.xaml.cs b/DlssUpdater/Controls/GameButton.xaml.cs index 8dd0a1d..614d1ae 100644 --- a/DlssUpdater/Controls/GameButton.xaml.cs +++ b/DlssUpdater/Controls/GameButton.xaml.cs @@ -18,7 +18,7 @@ public partial class GameButton : UserControl public GameButton() { InitializeComponent(); - _gameContainer = App.GetService(); + _gameContainer = App.GetService()!; gridAntiCheat.Visibility = Visibility.Hidden; selectionBox.Visibility = Visibility.Hidden; } diff --git a/DlssUpdater/DLSSUpdater.csproj b/DlssUpdater/DLSSUpdater.csproj index 878a9a1..65379e4 100644 --- a/DlssUpdater/DLSSUpdater.csproj +++ b/DlssUpdater/DLSSUpdater.csproj @@ -16,13 +16,21 @@ 1.0.0.2 + + False + + + + False + + - + @@ -31,14 +39,10 @@ - - - - @@ -46,6 +50,9 @@ Always + + Always + Always diff --git a/DlssUpdater/Defines/GameInfo.cs b/DlssUpdater/Defines/GameInfo.cs index a64f9b0..91093b1 100644 --- a/DlssUpdater/Defines/GameInfo.cs +++ b/DlssUpdater/Defines/GameInfo.cs @@ -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().Check(gamePath); + HasAntiCheat = App.GetService()!.Check(gamePath); } [JsonIgnore] public Dictionary InstalledDlls { get; set; } = []; @@ -86,7 +86,7 @@ public class GameConvert : JsonConverter { 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; } diff --git a/DlssUpdater/Defines/InstalledPackage.cs b/DlssUpdater/Defines/InstalledPackage.cs index 7ea7f39..e7ecb61 100644 --- a/DlssUpdater/Defines/InstalledPackage.cs +++ b/DlssUpdater/Defines/InstalledPackage.cs @@ -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; diff --git a/DlssUpdater/Defines/OnlinePackage.cs b/DlssUpdater/Defines/OnlinePackage.cs index 9d01e3b..66eafe6 100644 --- a/DlssUpdater/Defines/OnlinePackage.cs +++ b/DlssUpdater/Defines/OnlinePackage.cs @@ -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; diff --git a/DlssUpdater/GameLibrary/ILibrary.cs b/DlssUpdater/GameLibrary/ILibrary.cs index 413e418..eee613c 100644 --- a/DlssUpdater/GameLibrary/ILibrary.cs +++ b/DlssUpdater/GameLibrary/ILibrary.cs @@ -17,13 +17,13 @@ public interface ILibrary { public Task> 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)) }; } diff --git a/DlssUpdater/GameLibrary/ManualLibrary.cs b/DlssUpdater/GameLibrary/ManualLibrary.cs index 04cc2b9..7f34869 100644 --- a/DlssUpdater/GameLibrary/ManualLibrary.cs +++ b/DlssUpdater/GameLibrary/ManualLibrary.cs @@ -4,6 +4,11 @@ namespace DlssUpdater.GameLibrary; public class ManualLibrary : ILibrary { + public ManualLibrary(NLog.Logger logger) + { + + } + public async Task> GatherGamesAsync() { List ret = []; diff --git a/DlssUpdater/GameLibrary/Steam/SteamLibrary.cs b/DlssUpdater/GameLibrary/Steam/SteamLibrary.cs index a9a1301..6503092 100644 --- a/DlssUpdater/GameLibrary/Steam/SteamLibrary.cs +++ b/DlssUpdater/GameLibrary/Steam/SteamLibrary.cs @@ -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(); } @@ -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; } @@ -67,13 +73,22 @@ private async Task> getGames(List folder) List 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; @@ -86,10 +101,18 @@ private async Task> getGames(List folder) var gameName = parser.GetValuesForKey("name"); var gamePath = parser.GetValuesForKey("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) @@ -101,6 +124,7 @@ private async Task> getGames(List 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; } diff --git a/DlssUpdater/GameLibrary/Steam/VdfParser.cs b/DlssUpdater/GameLibrary/Steam/VdfParser.cs index 9e11e4f..732f3b4 100644 --- a/DlssUpdater/GameLibrary/Steam/VdfParser.cs +++ b/DlssUpdater/GameLibrary/Steam/VdfParser.cs @@ -52,32 +52,32 @@ public List GetValuesForKey(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 getObject(int start) { List 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; } @@ -91,7 +91,7 @@ private List 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; diff --git a/DlssUpdater/GameLibrary/UbisoftConnectLibrary.cs b/DlssUpdater/GameLibrary/UbisoftConnectLibrary.cs index 772a587..63650b1 100644 --- a/DlssUpdater/GameLibrary/UbisoftConnectLibrary.cs +++ b/DlssUpdater/GameLibrary/UbisoftConnectLibrary.cs @@ -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(); } @@ -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; } @@ -42,6 +48,7 @@ private async Task> 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; } @@ -73,6 +80,7 @@ private async Task> getGames() var gamePath = gameRegKey?.GetValue("InstallDir") as string; if (string.IsNullOrEmpty(gamePath)) { + _logger.Warn($"Ubisoft connect: Could not find regkey for {registerKey}"); continue; } @@ -88,7 +96,10 @@ private async Task> getGames() } ret.Add(info); } - + else + { + _logger.Debug($"Ubisoft connect: '{info.GameName}' does not have any DLSS dll."); + } } return ret; diff --git a/DlssUpdater/Helpers/EnumHelper.cs b/DlssUpdater/Helpers/EnumHelper.cs index 5f9b876..fd18681 100644 --- a/DlssUpdater/Helpers/EnumHelper.cs +++ b/DlssUpdater/Helpers/EnumHelper.cs @@ -14,7 +14,7 @@ public static T SetFlag(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; diff --git a/DlssUpdater/Helpers/ScrollViewerExtension.cs b/DlssUpdater/Helpers/ScrollViewerExtension.cs deleted file mode 100644 index 628a491..0000000 --- a/DlssUpdater/Helpers/ScrollViewerExtension.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Windows.Controls; -using System.Windows.Media; - -namespace DlssUpdater.Helpers; - -public class ScrollViewerExtension : DependencyObject -{ - // Using a DependencyProperty as the backing store for DisableParentScrollViewer. This enables animation, styling, binding, etc... - public static readonly DependencyProperty DisableParentScrollViewerProperty = - DependencyProperty.RegisterAttached("DisableParentScrollViewer", typeof(bool), typeof(ScrollViewerExtension), - new PropertyMetadata(false, OnDisableParentScrollViewerChanged)); - - public static bool GetDisableParentScrollViewer(DependencyObject obj) - { - return (bool)obj.GetValue(DisableParentScrollViewerProperty); - } - - public static void SetDisableParentScrollViewer(DependencyObject obj, bool value) - { - obj.SetValue(DisableParentScrollViewerProperty, value); - } - - private static void OnDisableParentScrollViewerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - if (d is FrameworkElement) - (d as FrameworkElement).Loaded += (_, __) => - { - var scrollViewer = FindAncestor(d as Visual, typeof(ScrollViewer)) as ScrollViewer; - if (scrollViewer != null && (bool)e.NewValue) - scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; - }; - } - - public static Visual FindAncestor(Visual startingFrom, Type typeAncestor) - { - if (startingFrom != null) - { - var parent = VisualTreeHelper.GetParent(startingFrom); - - while (parent != null && !typeAncestor.IsInstanceOfType(parent)) - parent = VisualTreeHelper.GetParent(parent); - - return parent as Visual; - } - - return null; - } -} \ No newline at end of file diff --git a/DlssUpdater/Helpers/WebHelper.cs b/DlssUpdater/Helpers/WebHelper.cs index 16ed45c..ab1e0eb 100644 --- a/DlssUpdater/Helpers/WebHelper.cs +++ b/DlssUpdater/Helpers/WebHelper.cs @@ -15,14 +15,20 @@ public static bool UrlIsValid(string url) { try { +#pragma warning disable SYSLIB0014 // Type or member is obsolete var request = WebRequest.Create(url) as HttpWebRequest; +#pragma warning restore SYSLIB0014 // Type or member is obsolete + if(request is null ) + { + return false; + } request.Timeout = 5000; //set the timeout to 5 seconds to keep the user from waiting too long for the page to load request.Method = "HEAD"; //Get only the header information -- no need to download any content using (var response = request.GetResponse() as HttpWebResponse) { - var statusCode = (int)response.StatusCode; + var statusCode = (int)response!.StatusCode; if (statusCode >= 100 && statusCode < 400) //Good requests return true; @@ -39,7 +45,7 @@ public static bool UrlIsValid(string url) if (ex.Status == WebExceptionStatus.ProtocolError) //400 errors return false; } - catch (Exception ex) + catch (Exception) { } diff --git a/DlssUpdater/Models/AppConfig.cs b/DlssUpdater/Models/AppConfig.cs deleted file mode 100644 index 6112c7e..0000000 --- a/DlssUpdater/Models/AppConfig.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace DlssUpdater.Models; - -public class AppConfig -{ - public string ConfigurationsFolder { get; set; } - - public string AppPropertiesFileName { get; set; } -} \ No newline at end of file diff --git a/DlssUpdater/Models/DataColor.cs b/DlssUpdater/Models/DataColor.cs deleted file mode 100644 index 2644ee9..0000000 --- a/DlssUpdater/Models/DataColor.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Windows.Media; - -namespace DlssUpdater.Models; - -public struct DataColor -{ - public Brush Color { get; set; } -} \ No newline at end of file diff --git a/DlssUpdater/NLog.config b/DlssUpdater/NLog.config new file mode 100644 index 0000000..8bfc9ad --- /dev/null +++ b/DlssUpdater/NLog.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/DlssUpdater/Services/ApplicationHostService.cs b/DlssUpdater/Services/ApplicationHostService.cs index 707d409..3a3e6f3 100644 --- a/DlssUpdater/Services/ApplicationHostService.cs +++ b/DlssUpdater/Services/ApplicationHostService.cs @@ -10,7 +10,7 @@ public class ApplicationHostService : IHostedService { private readonly IServiceProvider _serviceProvider; - private Splashscreen _splashscreen; + private Splashscreen? _splashscreen; public ApplicationHostService(IServiceProvider serviceProvider) { diff --git a/DlssUpdater/Settings.cs b/DlssUpdater/Settings.cs index 41dfe2d..9f12ad3 100644 --- a/DlssUpdater/Settings.cs +++ b/DlssUpdater/Settings.cs @@ -36,6 +36,7 @@ public class AntiCheat public Paths Directories { get; set; } = new(); public AntiCheat AntiCheatSettings { get; set; } = new(); public bool ShowChangelogOnStartup { get; set; } = false; + public WindowState WindowState { get; set; } = WindowState.Normal; public void Save() { @@ -62,5 +63,6 @@ private void copyData(Settings other) Directories = other.Directories; AntiCheatSettings = other.AntiCheatSettings; ShowChangelogOnStartup = other.ShowChangelogOnStartup; + WindowState = other.WindowState; } } \ No newline at end of file diff --git a/DlssUpdater/Singletons/AntiCheatChecker/AntiCheatChecker.cs b/DlssUpdater/Singletons/AntiCheatChecker/AntiCheatChecker.cs index a62b9b2..48c792b 100644 --- a/DlssUpdater/Singletons/AntiCheatChecker/AntiCheatChecker.cs +++ b/DlssUpdater/Singletons/AntiCheatChecker/AntiCheatChecker.cs @@ -5,11 +5,13 @@ namespace DlssUpdater.Singletons.AntiCheatChecker; public class AntiCheatChecker { private Settings _settings; + private readonly NLog.Logger _logger; private readonly List _providers = []; - public AntiCheatChecker(Settings settings) + public AntiCheatChecker(Settings settings, NLog.Logger logger) { _settings = settings; + _logger = logger; } public bool Check(string directory) @@ -24,11 +26,13 @@ public void Init() _providers.Clear(); if (_settings.AntiCheatSettings.ActiveAntiCheatChecks.HasFlag(AntiCheatProvider.EasyAntiCheat)) { - _providers.Add(new EasyAntiCheatProvider()); + _logger.Debug($"Add 'EasyAntiCheat' provider"); + _providers.Add(new EasyAntiCheatProvider(_logger)); } if (_settings.AntiCheatSettings.ActiveAntiCheatChecks.HasFlag(AntiCheatProvider.BattlEye)) { - _providers.Add(new BattlEyeProvider()); + _logger.Debug($"Add 'BattlEye' provider"); + _providers.Add(new BattlEyeProvider(_logger)); } } } \ No newline at end of file diff --git a/DlssUpdater/Singletons/AntiCheatChecker/BattlEyeProvider.cs b/DlssUpdater/Singletons/AntiCheatChecker/BattlEyeProvider.cs index e826848..1a83563 100644 --- a/DlssUpdater/Singletons/AntiCheatChecker/BattlEyeProvider.cs +++ b/DlssUpdater/Singletons/AntiCheatChecker/BattlEyeProvider.cs @@ -6,10 +6,17 @@ public class BattlEyeProvider : IAntiCheatProvider { public AntiCheatProvider ProviderType => AntiCheatProvider.BattlEye; + private readonly NLog.Logger _logger; + + public BattlEyeProvider(NLog.Logger logger) + { + _logger = logger; + } + public bool Check(string directory) { var allFiles = Directory.GetFiles(directory, "*BEService*", SearchOption.AllDirectories); - + _logger.Debug($"Checked BattlEye for '{directory}' and found {allFiles.Length} files"); return allFiles.Length > 0; } } \ No newline at end of file diff --git a/DlssUpdater/Singletons/AntiCheatChecker/EasyAntiCheatProvider.cs b/DlssUpdater/Singletons/AntiCheatChecker/EasyAntiCheatProvider.cs index 4094b3a..bd55f6d 100644 --- a/DlssUpdater/Singletons/AntiCheatChecker/EasyAntiCheatProvider.cs +++ b/DlssUpdater/Singletons/AntiCheatChecker/EasyAntiCheatProvider.cs @@ -6,10 +6,17 @@ public class EasyAntiCheatProvider : IAntiCheatProvider { public AntiCheatProvider ProviderType => AntiCheatProvider.EasyAntiCheat; + private readonly NLog.Logger _logger; + + public EasyAntiCheatProvider(NLog.Logger logger) + { + _logger = logger; + } + public bool Check(string directory) { var allFiles = Directory.GetFiles(directory, "*EasyAntiCheat*", SearchOption.AllDirectories); - + _logger.Debug($"Checked EAC for '{directory}' and found {allFiles.Length} files"); return allFiles.Length > 0; } } \ No newline at end of file diff --git a/DlssUpdater/Singletons/DllUpdater.cs b/DlssUpdater/Singletons/DllUpdater.cs index 7609f58..afddc95 100644 --- a/DlssUpdater/Singletons/DllUpdater.cs +++ b/DlssUpdater/Singletons/DllUpdater.cs @@ -24,17 +24,19 @@ public enum UpdateResult [JsonIgnore] private readonly Settings _settings; + [JsonIgnore] + private readonly NLog.Logger _logger; public DateTime LastUpdate { get; set; } = DateTime.MinValue; public DllUpdater() { - } - public DllUpdater(Settings settings) + public DllUpdater(Settings settings, NLog.Logger logger) { _settings = settings; + _logger = logger; } public Dictionary> OnlinePackages { get; set; } = []; @@ -56,6 +58,7 @@ public async Task UpdateDlssVersionsAsync() var nextCheck = LastUpdate.Add(Constants.CacheTime); if(DateTime.UtcNow > nextCheck) { + _logger.Debug($"Updating online DLSS libs."); OnlinePackages.Clear(); foreach (DllType dllType in Enum.GetValues(typeof(DllType))) { @@ -105,7 +108,11 @@ public async Task DownloadDll(DllType dllType, string version) } // Something failed - if (!File.Exists(outputPath)) return false; + if (!File.Exists(outputPath)) + { + _logger.Warn($"DllUpdater: Could not download file to {outputPath}"); + return false; + } var dllTargetPath = Path.Combine(_settings.Directories.InstallPath, GetName(package.DllType), package.Version.Replace(' ', '_')); @@ -168,8 +175,9 @@ public UpdateResult UpdateGameDlls(GameInfo gameInfo) File.Copy(package.Path, info.Path, true); result = UpdateResult.Success; } - catch (Exception) + catch (Exception ex) { + _logger.Error($"DllUpdater: Exception on UpdateGameDlls: {ex}"); result = UpdateResult.Failure; return result; } diff --git a/DlssUpdater/Singletons/GameContainer.cs b/DlssUpdater/Singletons/GameContainer.cs index 8041507..d64f209 100644 --- a/DlssUpdater/Singletons/GameContainer.cs +++ b/DlssUpdater/Singletons/GameContainer.cs @@ -22,15 +22,17 @@ public class GameContainer private readonly Settings _settings; private readonly AntiCheatChecker.AntiCheatChecker _antiCheatChecker; + private readonly NLog.Logger _logger; - public GameContainer(Settings settings, AntiCheatChecker.AntiCheatChecker antiCheatChecker) + public GameContainer(Settings settings, AntiCheatChecker.AntiCheatChecker antiCheatChecker, NLog.Logger logger) { _settings = settings; _antiCheatChecker = antiCheatChecker; + _logger = logger; // TODO: Add settings for active libraries - _libraries.Add(ILibrary.Create(LibraryType.Steam)); - _libraries.Add(ILibrary.Create(LibraryType.Ubisoft)); + _libraries.Add(ILibrary.Create(LibraryType.Steam, _logger)); + _libraries.Add(ILibrary.Create(LibraryType.Ubisoft, _logger)); } public SortableObservableCollection Games { get; } = new() diff --git a/DlssUpdater/Singletons/VersionUpdater.cs b/DlssUpdater/Singletons/VersionUpdater.cs index eb97537..a2cce90 100644 --- a/DlssUpdater/Singletons/VersionUpdater.cs +++ b/DlssUpdater/Singletons/VersionUpdater.cs @@ -68,7 +68,7 @@ public async Task DoUpdate(string updateFile, string installPath, int processId) } Application.Current.Shutdown(); } - catch (Exception ex) + catch (Exception) { } diff --git a/DlssUpdater/ViewModels/Pages/DLSSViewModel.cs b/DlssUpdater/ViewModels/Pages/DLSSViewModel.cs index c69f3dc..3babd0e 100644 --- a/DlssUpdater/ViewModels/Pages/DLSSViewModel.cs +++ b/DlssUpdater/ViewModels/Pages/DLSSViewModel.cs @@ -15,7 +15,6 @@ public partial class DLSSViewModel : ObservableObject, INavigationAware [ObservableProperty] private IEnumerable? _dlssG; private bool _isInitialized; - private ISnackbarService _snackbar; public DLSSViewModel(DllUpdater updater) { diff --git a/DlssUpdater/ViewModels/Windows/MainWindowViewModel.cs b/DlssUpdater/ViewModels/Windows/MainWindowViewModel.cs index e7bbbac..05853ff 100644 --- a/DlssUpdater/ViewModels/Windows/MainWindowViewModel.cs +++ b/DlssUpdater/ViewModels/Windows/MainWindowViewModel.cs @@ -52,4 +52,6 @@ public partial class MainWindowViewModel : ObservableObject { new MenuItem { Header = "Home", Tag = "tray_home" } }; + + [ObservableProperty] private WindowState _windowState; } \ No newline at end of file diff --git a/DlssUpdater/Views/Pages/GamesPage.xaml.cs b/DlssUpdater/Views/Pages/GamesPage.xaml.cs index d0c37a6..29f7c5a 100644 --- a/DlssUpdater/Views/Pages/GamesPage.xaml.cs +++ b/DlssUpdater/Views/Pages/GamesPage.xaml.cs @@ -152,7 +152,7 @@ private void ButtonImage_Click(object sender, RoutedEventArgs e) foreach (var c in codecs) { - var codecName = c.CodecName.Substring(8).Replace("Codec", "Files").Trim(); + var codecName = c.CodecName!.Substring(8).Replace("Codec", "Files").Trim(); dlg.Filter = string.Format("{0}{1}{2} ({3})|{3}", dlg.Filter, sep, codecName, c.FilenameExtension); sep = "|"; } diff --git a/DlssUpdater/Views/Windows/MainWindow.xaml b/DlssUpdater/Views/Windows/MainWindow.xaml index 24c27fe..de6ec4e 100644 --- a/DlssUpdater/Views/Windows/MainWindow.xaml +++ b/DlssUpdater/Views/Windows/MainWindow.xaml @@ -20,7 +20,7 @@ WindowBackdropType="Mica" WindowCornerPreference="Round" WindowStartupLocation="CenterScreen" - mc:Ignorable="d" MinWidth="800" MinHeight="600"> + mc:Ignorable="d" MinWidth="800" MinHeight="600" WindowState="{Binding ViewModel.WindowState}" SizeChanged="FluentWindow_SizeChanged"> diff --git a/DlssUpdater/Views/Windows/MainWindow.xaml.cs b/DlssUpdater/Views/Windows/MainWindow.xaml.cs index 9271a4c..c103e9f 100644 --- a/DlssUpdater/Views/Windows/MainWindow.xaml.cs +++ b/DlssUpdater/Views/Windows/MainWindow.xaml.cs @@ -20,8 +20,6 @@ public MainWindow(MainWindowViewModel viewModel, IPageService pageService, INavi _settings = settings; DataContext = this; - SystemThemeWatcher.Watch(this); - InitializeComponent(); SetPageService(pageService); @@ -69,6 +67,8 @@ public void SetPageService(IPageService pageService) public void ShowWindow() { + ViewModel.WindowState = _settings.WindowState; + Show(); if (_settings.ShowChangelogOnStartup) { @@ -88,4 +88,10 @@ public void CloseWindow() } #endregion INavigationWindow methods + + private void FluentWindow_SizeChanged(object sender, SizeChangedEventArgs e) + { + _settings.WindowState = WindowState; + _settings.Save(); + } } \ No newline at end of file diff --git a/DlssUpdater/Windows/Splashscreen/Splashscreen.xaml.cs b/DlssUpdater/Windows/Splashscreen/Splashscreen.xaml.cs index 2c26a5a..17072e5 100644 --- a/DlssUpdater/Windows/Splashscreen/Splashscreen.xaml.cs +++ b/DlssUpdater/Windows/Splashscreen/Splashscreen.xaml.cs @@ -26,15 +26,19 @@ public partial class Splashscreen : Window private readonly DllUpdater _updater; private readonly VersionUpdater _versionUpdater; private readonly Settings _settings; + private readonly NLog.Logger _logger; private bool _runInit = true; public Splashscreen(MainWindow mainWindow, DllUpdater updater, GameContainer container, Settings settings, - AntiCheatChecker cheatChecker, VersionUpdater versionUpdater) + AntiCheatChecker cheatChecker, VersionUpdater versionUpdater, NLog.Logger logger) { _updater = updater; _gameContainer = container; _versionUpdater = versionUpdater; + _logger = logger; + _logger.Debug("### STARTUP ###"); + settings.Load(); _settings = settings; cheatChecker.Init(); @@ -98,6 +102,8 @@ protected override async void OnContentRendered(EventArgs e) _settings.ShowChangelogOnStartup = true; _settings.Save(); + _logger.Debug("Downloading update file"); + // Download the update and start the ApplicationUpdater var outputPath = Path.Combine(AppContext.BaseDirectory, _settings.Directories.DownloadPath, "update.zip"); var updateUrl = "http://github.com/Drommedhar/DlssUpdater/releases/latest/download/dlssupdater.zip"; @@ -122,6 +128,7 @@ protected override async void OnContentRendered(EventArgs e) // Now let's finally start the updater var updateArgs = $"{outputPath} {AppContext.BaseDirectory} {Environment.ProcessId}"; await File.WriteAllTextAsync(Path.Combine(_settings.Directories.DownloadPath, "update.txt"), updateArgs); + _logger.Debug($"Starting update with the following args: {updateArgs}"); Process.Start(Path.Combine(_settings.Directories.DownloadPath, "DlssUpdater.exe")); Application.Current.Shutdown(); } @@ -136,6 +143,7 @@ protected override async void OnContentRendered(EventArgs e) catch (HttpRequestException ex) { _updater.OnInfo -= Updater_OnInfo; + _logger.Error($"Request for UpdateDlssVersions failed: {ex}"); SplashscreenViewModel.InfoText = $"ERROR: {ex}"; await Task.Delay(5000); Application.Current.Shutdown(); diff --git a/DlssUpdater/changelog.md b/DlssUpdater/changelog.md index 76d3bd3..fac65fb 100644 --- a/DlssUpdater/changelog.md +++ b/DlssUpdater/changelog.md @@ -1,4 +1,9 @@ -# v1.0.0.2 +# 1.0.1.0 +* Add logging to narrow down common problems. These can be found in 'logs' directory next to the executable +* Window now stores if it was previously maximized or not +* Will now correctly always use dark theme no matter what the windows setting is set to + +# v1.0.0.2 * Reduce archive footprint by not bundling the .NET Framework with the application archive # v1.0.0.1 diff --git a/DlssUpdater/version.json b/DlssUpdater/version.json index 21bb5f8..5e810f1 100644 --- a/DlssUpdater/version.json +++ b/DlssUpdater/version.json @@ -1,3 +1,3 @@ { - "version": "1.0.0.2" + "version": "1.0.1.0" } \ No newline at end of file