From 179419f3e62bd9b054830f42ea994119a7ff14ab Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 8 Mar 2024 21:16:51 +0100 Subject: [PATCH] Fix a ton of warnings. --- Launchpad.Common/ExtensionMethods.cs | 9 +---- Launchpad.Launcher/Handlers/ChecksHandler.cs | 2 +- Launchpad.Launcher/Handlers/GameHandler.cs | 27 +++++++------- .../Handlers/LauncherHandler.cs | 10 +++--- .../Protocols/Manifest/FTPProtocolHandler.cs | 12 +++---- .../Protocols/Manifest/HTTPProtocolHandler.cs | 6 ++-- .../Manifest/ManifestBasedProtocolHandler.cs | 19 +++++----- Launchpad.Launcher/Interface/MainWindow.cs | 35 +++++++++---------- Launchpad.Launcher/Program.cs | 8 ++--- .../Services/LocalVersionService.cs | 4 +-- .../Handlers/ManifestGenerationHandler.cs | 2 +- Launchpad.Utilities/Program.cs | 2 +- 12 files changed, 64 insertions(+), 72 deletions(-) diff --git a/Launchpad.Common/ExtensionMethods.cs b/Launchpad.Common/ExtensionMethods.cs index 8174d73..0fcf7cd 100644 --- a/Launchpad.Common/ExtensionMethods.cs +++ b/Launchpad.Common/ExtensionMethods.cs @@ -57,13 +57,6 @@ public static void AddOrUpdate(this IDictionary dict throw new ArgumentNullException(nameof(dictionary)); } - if (dictionary.ContainsKey(key)) - { - dictionary[key] = value; - } - else - { - dictionary.Add(key, value); - } + dictionary[key] = value; } } diff --git a/Launchpad.Launcher/Handlers/ChecksHandler.cs b/Launchpad.Launcher/Handlers/ChecksHandler.cs index dfaf7a3..de2e1f2 100644 --- a/Launchpad.Launcher/Handlers/ChecksHandler.cs +++ b/Launchpad.Launcher/Handlers/ChecksHandler.cs @@ -98,7 +98,7 @@ public bool IsGameInstalled() "No GameVersion.txt file was found in the installation directory.\n" + "This may be due to a download error, or the developer may not have included one.\n" + "Without it, the game cannot be considered fully installed.\n" + - "If you are the developer of this game, add one to your game files with your desired version in it." + "If you are the developer of this game, add one to your game files with your desired version in it" ); } diff --git a/Launchpad.Launcher/Handlers/GameHandler.cs b/Launchpad.Launcher/Handlers/GameHandler.cs index 931f40f..1a5c8b4 100644 --- a/Launchpad.Launcher/Handlers/GameHandler.cs +++ b/Launchpad.Launcher/Handlers/GameHandler.cs @@ -136,7 +136,7 @@ DirectoryHelpers directoryHelpers /// A representing the asynchronous operation. public async Task InstallGameAsync() { - _log.LogInformation($"Starting installation of game files using protocol \"{_patch.GetType().Name}\""); + _log.LogInformation("Starting installation of game files using protocol \"{Protocol}\"", _patch.GetType().Name); await _patch.InstallGameAsync(); } @@ -146,7 +146,7 @@ public async Task InstallGameAsync() /// A representing the asynchronous operation. public async Task UpdateGameAsync() { - _log.LogInformation($"Starting update of game files using protocol \"{_patch.GetType().Name}\""); + _log.LogInformation("Starting update of game files using protocol \"{Protocol}\"", _patch.GetType().Name); await _patch.UpdateModuleAsync(EModule.Game); } @@ -156,7 +156,7 @@ public async Task UpdateGameAsync() /// A representing the asynchronous operation. public async Task VerifyGameAsync() { - _log.LogInformation("Beginning verification of game files."); + _log.LogInformation("Beginning verification of game files"); await _patch.VerifyModuleAsync(EModule.Game); } @@ -166,16 +166,16 @@ public async Task VerifyGameAsync() /// A representing the asynchronous operation. public async Task ReinstallGameAsync() { - _log.LogInformation("Beginning full reinstall of game files."); + _log.LogInformation("Beginning full reinstall of game files"); if (Directory.Exists(_directoryHelpers.GetLocalGameDirectory())) { - _log.LogInformation("Deleting existing game files."); + _log.LogInformation("Deleting existing game files"); Directory.Delete(_directoryHelpers.GetLocalGameDirectory(), true); } if (File.Exists(_directoryHelpers.GetGameTagfilePath())) { - _log.LogInformation("Deleting install progress cookie."); + _log.LogInformation("Deleting install progress cookie"); File.Delete(_directoryHelpers.GetGameTagfilePath()); } @@ -207,7 +207,7 @@ public void LaunchGame() WorkingDirectory = executableDir }; - _log.LogInformation($"Launching game. \n\tExecutable path: {gameStartInfo.FileName}"); + _log.LogInformation("Launching game. \n\tExecutable path: {Executable}", gameStartInfo.FileName); var gameProcess = new Process { @@ -215,14 +215,15 @@ public void LaunchGame() EnableRaisingEvents = true }; - gameProcess.Exited += (sender, args) => + gameProcess.Exited += (_, _) => { if (gameProcess.ExitCode != 0) { _log.LogInformation ( - $"The game exited with an exit code of {gameProcess.ExitCode}. " + - "There may have been issues during runtime, or the game may not have started at all." + "The game exited with an exit code of {ExitCode}. " + + "There may have been issues during runtime, or the game may not have started at all", + gameProcess.ExitCode ); } @@ -242,14 +243,14 @@ public void LaunchGame() } catch (FileNotFoundException fex) { - _log.LogWarning($"Game launch failed (FileNotFoundException): {fex.Message}"); - _log.LogWarning("If the game executable is there, try overriding the executable name in the configuration file."); + _log.LogWarning(fex, "Game launch failed"); + _log.LogWarning("If the game executable is there, try overriding the executable name in the configuration file"); OnGameLaunchFailed(); } catch (IOException ioex) { - _log.LogWarning($"Game launch failed (IOException): {ioex.Message}"); + _log.LogWarning(ioex, $"Game launch failed"); OnGameLaunchFailed(); } diff --git a/Launchpad.Launcher/Handlers/LauncherHandler.cs b/Launchpad.Launcher/Handlers/LauncherHandler.cs index 7e7d224..0dbdac2 100644 --- a/Launchpad.Launcher/Handlers/LauncherHandler.cs +++ b/Launchpad.Launcher/Handlers/LauncherHandler.cs @@ -100,13 +100,13 @@ public async Task UpdateLauncherAsync() { try { - _log.LogInformation($"Starting update of lancher files using protocol \"{_patch.GetType().Name}\""); + _log.LogInformation("Starting update of lancher files using protocol \"{Protocol}\"", _patch.GetType().Name); await _patch.UpdateModuleAsync(EModule.Launcher); } catch (IOException ioex) { - _log.LogWarning("The launcher update failed (IOException): " + ioex.Message); + _log.LogWarning(ioex, "The launcher update failed"); } } @@ -139,7 +139,7 @@ public async Task CanAccessStandardChangelog() } catch (WebException wex) { - _log.LogWarning("Could not access standard changelog (WebException): " + wex.Message); + _log.LogWarning(wex, "Could not access standard changelog"); return false; } } @@ -160,7 +160,7 @@ public ProcessStartInfo CreateUpdateScript() if (PlatformHelpers.IsRunningOnUnix()) { var chmod = Process.Start("chmod", $"+x {updateScriptPath}"); - chmod?.WaitForExit(); + chmod.WaitForExit(); } var updateShellProcess = new ProcessStartInfo @@ -176,7 +176,7 @@ public ProcessStartInfo CreateUpdateScript() } catch (IOException ioex) { - _log.LogWarning("Failed to create update script (IOException): " + ioex.Message); + _log.LogWarning(ioex, "Failed to create update script"); throw new InvalidOperationException(); } diff --git a/Launchpad.Launcher/Handlers/Protocols/Manifest/FTPProtocolHandler.cs b/Launchpad.Launcher/Handlers/Protocols/Manifest/FTPProtocolHandler.cs index 8211df4..6937fc3 100644 --- a/Launchpad.Launcher/Handlers/Protocols/Manifest/FTPProtocolHandler.cs +++ b/Launchpad.Launcher/Handlers/Protocols/Manifest/FTPProtocolHandler.cs @@ -88,7 +88,7 @@ DirectoryHelpers directoryHelpers /// public override async Task> CanPatchAsync() { - _log.LogInformation("Pinging remote patching server to determine if we can connect to it."); + _log.LogInformation("Pinging remote patching server to determine if we can connect to it"); var canConnect = false; @@ -132,13 +132,13 @@ public override async Task> CanPatchAsync() } catch (WebException wex) { - _log.LogWarning("Unable to connect to remote patch server (WebException): " + wex.Message); + _log.LogWarning(wex, "Unable to connect to remote patch server"); canConnect = false; } } catch (WebException wex) { - _log.LogWarning("Unable to connect due a malformed url in the configuration (WebException): " + wex.Message); + _log.LogWarning(wex, "Unable to connect due a malformed url in the configuration"); canConnect = false; } @@ -222,10 +222,6 @@ protected override async Task> ReadRemoteFileAsync(string url, bo var data = string.Empty; await using var remoteStream = (await request.GetResponseAsync()).GetResponseStream(); - if (remoteStream == null) - { - return string.Empty; - } long fileSize; using (var sizeResponse = (FtpWebResponse)await sizeRequest.GetResponseAsync()) @@ -262,7 +258,7 @@ protected override async Task> ReadRemoteFileAsync(string url, bo } catch (WebException wex) { - _log.LogError($"Failed to read the contents of remote file \"{remoteURL}\" (WebException): {wex.Message}"); + _log.LogError(wex, "Failed to read the contents of remote file \"{RemoteUrl}\"", remoteURL); return string.Empty; } } diff --git a/Launchpad.Launcher/Handlers/Protocols/Manifest/HTTPProtocolHandler.cs b/Launchpad.Launcher/Handlers/Protocols/Manifest/HTTPProtocolHandler.cs index 6b54989..23a9d7b 100644 --- a/Launchpad.Launcher/Handlers/Protocols/Manifest/HTTPProtocolHandler.cs +++ b/Launchpad.Launcher/Handlers/Protocols/Manifest/HTTPProtocolHandler.cs @@ -87,7 +87,7 @@ DirectoryHelpers directoryHelpers /// public override async Task> CanPatchAsync() { - _log.LogInformation("Pinging remote patching server to determine if we can connect to it."); + _log.LogInformation("Pinging remote patching server to determine if we can connect to it"); var canConnect = false; @@ -120,13 +120,13 @@ public override async Task> CanPatchAsync() } catch (WebException wex) { - _log.LogWarning("Unable to connect to remote patch server (WebException): " + wex.Message); + _log.LogWarning(wex, "Unable to connect to remote patch server"); canConnect = false; } } catch (WebException wex) { - _log.LogWarning("Unable to connect due a malformed url in the configuration (WebException): " + wex.Message); + _log.LogWarning(wex, "Unable to connect due a malformed url in the configuration"); canConnect = false; } diff --git a/Launchpad.Launcher/Handlers/Protocols/Manifest/ManifestBasedProtocolHandler.cs b/Launchpad.Launcher/Handlers/Protocols/Manifest/ManifestBasedProtocolHandler.cs index 3e05456..ef29347 100644 --- a/Launchpad.Launcher/Handlers/Protocols/Manifest/ManifestBasedProtocolHandler.cs +++ b/Launchpad.Launcher/Handlers/Protocols/Manifest/ManifestBasedProtocolHandler.cs @@ -268,7 +268,7 @@ public override async Task VerifyModuleAsync(EModule module) } brokenFiles.Add(fileEntry); - _log.LogInformation($"File \"{Path.GetFileName(fileEntry.RelativePath)}\" failed its integrity check and was queued for redownload."); + _log.LogInformation("File \"{File}\" failed its integrity check and was queued for redownload", Path.GetFileName(fileEntry.RelativePath)); } var downloadedFiles = 0; @@ -292,8 +292,9 @@ public override async Task VerifyModuleAsync(EModule module) { _log.LogInformation ( - $"File \"{Path.GetFileName(fileEntry.RelativePath)}\" failed its integrity check " + - $"again after redownloading. ({retries} retries)" + "File \"{File}\" failed its integrity check again after redownloading. ({Retries} retries)", + Path.GetFileName(fileEntry.RelativePath), + retries ); var downloadEntry = await DownloadManifestEntryAsync(fileEntry, module); @@ -468,7 +469,7 @@ public override async Task> IsModuleOutdatedAsync(EModule module) } catch (WebException wex) { - _log.LogWarning("Unable to determine whether or not the launcher was outdated (WebException): " + wex.Message); + _log.LogWarning(wex, "Unable to determine whether or not the launcher was outdated"); return false; } } @@ -568,13 +569,13 @@ protected virtual async Task DownloadManifestEntryAsync // If the file is partial, resume the download. if (fileInfo.Length < fileEntry.Size) { - _log.LogInformation($"Resuming interrupted file \"{Path.GetFileNameWithoutExtension(fileEntry.RelativePath)}\" at byte {fileInfo.Length}."); + _log.LogInformation("Resuming interrupted file \"{File}\" at byte {Byte}", Path.GetFileNameWithoutExtension(fileEntry.RelativePath), fileInfo.Length); await DownloadRemoteFileAsync(remoteURL, localPath, fileEntry.Size, fileInfo.Length); } else { // If it's larger than expected, toss it in the bin and try again. - _log.LogInformation($"Restarting interrupted file \"{Path.GetFileNameWithoutExtension(fileEntry.RelativePath)}\": File bigger than expected."); + _log.LogInformation("Restarting interrupted file \"{File}\": File bigger than expected", Path.GetFileNameWithoutExtension(fileEntry.RelativePath)); File.Delete(localPath); await DownloadRemoteFileAsync(remoteURL, localPath, fileEntry.Size); @@ -593,8 +594,10 @@ protected virtual async Task DownloadManifestEntryAsync // If the hash doesn't match, toss it in the bin and try again. _log.LogInformation ( - $"Redownloading file \"{Path.GetFileNameWithoutExtension(fileEntry.RelativePath)}\": " + - $"Hash sum mismatch. Local: {localHash}, Expected: {fileEntry.Hash}" + "Redownloading file \"{File}\": Hash sum mismatch. Local: {LocalHash}, Expected: {ExpectedHash}", + Path.GetFileNameWithoutExtension(fileEntry.RelativePath), + localHash, + fileEntry.Hash ); File.Delete(localPath); diff --git a/Launchpad.Launcher/Interface/MainWindow.cs b/Launchpad.Launcher/Interface/MainWindow.cs index f876e76..628ac43 100644 --- a/Launchpad.Launcher/Interface/MainWindow.cs +++ b/Launchpad.Launcher/Interface/MainWindow.cs @@ -37,7 +37,6 @@ using Microsoft.Extensions.Logging; using NGettext; using Remora.Results; -using SixLabors.ImageSharp; using SixLabors.ImageSharp.Processing; using Application = Gtk.Application; using Process = System.Diagnostics.Process; @@ -230,8 +229,8 @@ public async Task InitializeAsync() { _log.LogInformation ( - $"The server does not provide files for platform \"{PlatformHelpers.GetCurrentPlatform()}\". " + - "A .provides file must be present in the platforms' root directory." + "The server does not provide files for platform \"{Platform}\". A .provides file must be present in the platforms' root directory", + PlatformHelpers.GetCurrentPlatform() ); SetLauncherMode(ELauncherMode.Inactive, false); @@ -241,7 +240,7 @@ public async Task InitializeAsync() if (!_checks.IsGameInstalled()) { // If the game is not installed, offer to install it - _log.LogInformation("The game has not yet been installed."); + _log.LogInformation("The game has not yet been installed"); SetLauncherMode(ELauncherMode.Install, false); // Since the game has not yet been installed, disallow manual repairs @@ -262,13 +261,13 @@ public async Task InitializeAsync() if (getIsGameOutdated.Entity) { // If it does, offer to update it - _log.LogInformation("The game is outdated."); + _log.LogInformation("The game is outdated"); SetLauncherMode(ELauncherMode.Update, false); } else { // All checks passed, so we can offer to launch the game. - _log.LogInformation("All checks passed. Game can be launched."); + _log.LogInformation("All checks passed. Game can be launched"); SetLauncherMode(ELauncherMode.Launch, false); } } @@ -277,7 +276,7 @@ public async Task InitializeAsync() else { // The launcher was outdated. - _log.LogInformation($"The launcher is outdated. \n\tLocal version: {_localVersionService.GetLocalLauncherVersion()}"); + _log.LogInformation("The launcher is outdated. \n\tLocal version: {LocalVersion}", _localVersionService.GetLocalLauncherVersion()); SetLauncherMode(ELauncherMode.Update, false); } } @@ -312,7 +311,7 @@ private async Task LoadChangelogAsync() private void DisplayInitialStartupDialog() { - _log.LogInformation("This instance is the first start of the application in this folder."); + _log.LogInformation("This instance is the first start of the application in this folder"); var text = LocalizationCatalog.GetString ( @@ -331,7 +330,7 @@ private void DisplayInitialStartupDialog() if (shouldInstallHereDialog.Run() == (int)ResponseType.Ok) { // Yes, install here - _log.LogInformation("User accepted installation in this directory. Installing in current directory."); + _log.LogInformation("User accepted installation in this directory. Installing in current directory"); _tagfileService.CreateLauncherTagfile(); } @@ -521,8 +520,8 @@ private async void OnMainButtonClicked(object? sender, EventArgs e) _log.LogInformation ( - $"The server does not provide files for platform \"{PlatformHelpers.GetCurrentPlatform()}\". " + - "A .provides file must be present in the platforms' root directory." + "The server does not provide files for platform \"{Platform}\". A .provides file must be present in the platforms' root directory", + PlatformHelpers.GetCurrentPlatform() ); SetLauncherMode(ELauncherMode.Inactive, false); @@ -585,7 +584,7 @@ private async void OnMainButtonClicked(object? sender, EventArgs e) } default: { - _log.LogWarning("The main button was pressed with an invalid active mode. No functionality has been defined for this mode."); + _log.LogWarning("The main button was pressed with an invalid active mode. No functionality has been defined for this mode"); break; } } @@ -596,7 +595,7 @@ private async void OnMainButtonClicked(object? sender, EventArgs e) /// private void OnLauncherDownloadFinished(object? sender, EventArgs e) { - Application.Invoke((o, args) => + Application.Invoke((_, _) => { var script = _launcher.CreateUpdateScript(); @@ -613,7 +612,7 @@ private void OnLauncherDownloadFinished(object? sender, EventArgs e) /// Empty event args. private void OnGameLaunchFailed(object? sender, EventArgs e) { - Application.Invoke((o, args) => + Application.Invoke((_, _) => { _statusLabel.Text = LocalizationCatalog.GetString("The game failed to launch. Try repairing the installation."); _mainProgressBar.Text = string.Empty; @@ -629,7 +628,7 @@ private void OnGameLaunchFailed(object? sender, EventArgs e) /// Contains the type of failure that occurred. private void OnGameDownloadFailed(object? sender, EventArgs e) { - Application.Invoke((o, args) => + Application.Invoke((_, _) => { switch (_mode) { @@ -660,7 +659,7 @@ private void OnGameDownloadFailed(object? sender, EventArgs e) /// Contains the progress values and current filename. private void OnModuleInstallationProgressChanged(object? sender, ModuleProgressChangedArgs e) { - Application.Invoke((o, args) => + Application.Invoke((_, _) => { _mainProgressBar.Text = e.ProgressBarMessage; _statusLabel.Text = e.IndicatorLabelMessage; @@ -675,7 +674,7 @@ private void OnModuleInstallationProgressChanged(object? sender, ModuleProgressC /// Contains the result of the download. private void OnGameDownloadFinished(object? sender, EventArgs e) { - Application.Invoke((o, args) => + Application.Invoke((_, _) => { _statusLabel.Text = LocalizationCatalog.GetString("Idle"); @@ -713,7 +712,7 @@ private void OnGameDownloadFinished(object? sender, EventArgs e) /// private void OnGameExited(object? sender, int exitCode) { - Application.Invoke((o, args) => + Application.Invoke((_, _) => { if (exitCode != 0) { diff --git a/Launchpad.Launcher/Program.cs b/Launchpad.Launcher/Program.cs index 1bf310a..da7d033 100644 --- a/Launchpad.Launcher/Program.cs +++ b/Launchpad.Launcher/Program.cs @@ -101,16 +101,16 @@ private static async Task Main(string[] args) /// The event object containing the information about the exception. private static void OnUnhandledGLibException(UnhandledExceptionArgs args) { - Log.LogError((Exception)args.ExceptionObject, "Unhandled GLib exception."); + Log.LogError((Exception)args.ExceptionObject, "Unhandled GLib exception"); } private static IHostBuilder CreateHostBuilder(string[] args) => new HostBuilder() - .ConfigureAppConfiguration((hostingContext, config) => + .ConfigureAppConfiguration((_, config) => { config.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "config")); config.AddJsonFile("appsettings.json"); }) - .ConfigureServices((hostingContext, services) => + .ConfigureServices((_, services) => { services .AddSingleton() @@ -137,7 +137,7 @@ private static void OnUnhandledGLibException(UnhandledExceptionArgs args) } ) .AddSingleton(s => s.GetRequiredService().Configuration) - .AddSingleton(s => new Catalog("Launchpad", "./Content/locale")) + .AddSingleton(_ => new Catalog("Launchpad", "./Content/locale")) .AddSingleton ( s => diff --git a/Launchpad.Launcher/Services/LocalVersionService.cs b/Launchpad.Launcher/Services/LocalVersionService.cs index 1e581b3..12dd3cc 100644 --- a/Launchpad.Launcher/Services/LocalVersionService.cs +++ b/Launchpad.Launcher/Services/LocalVersionService.cs @@ -68,12 +68,12 @@ public Version GetLocalGameVersion() return gameVersion; } - _log.LogWarning("Could not parse local game version. Contents: " + rawGameVersion); + _log.LogWarning("Could not parse local game version. Contents: {Contents}", rawGameVersion); return new Version("0.0.0"); } catch (IOException ioex) { - _log.LogWarning("Could not read local game version (IOException): " + ioex.Message); + _log.LogWarning(ioex, "Could not read local game version"); return new Version("0.0.0"); } } diff --git a/Launchpad.Utilities/Handlers/ManifestGenerationHandler.cs b/Launchpad.Utilities/Handlers/ManifestGenerationHandler.cs index 6d71c87..92c0cf1 100644 --- a/Launchpad.Utilities/Handlers/ManifestGenerationHandler.cs +++ b/Launchpad.Utilities/Handlers/ManifestGenerationHandler.cs @@ -97,7 +97,7 @@ CancellationToken ct var newEntry = CreateEntryForFile(targetPath, filePath); await tw.WriteLineAsync(newEntry.ToString()); - await tw.FlushAsync(); + await tw.FlushAsync(ct); completedFiles++; diff --git a/Launchpad.Utilities/Program.cs b/Launchpad.Utilities/Program.cs index 62ea69b..f613a0c 100644 --- a/Launchpad.Utilities/Program.cs +++ b/Launchpad.Utilities/Program.cs @@ -60,7 +60,7 @@ private static async Task Main(string[] args) var options = new CLIOptions(); Parser.Default.ParseArguments(args) .WithParsed(r => options = r) - .WithNotParsed(r => options = null); + .WithNotParsed(_ => options = null); if (options is null) {