Skip to content

Commit

Permalink
Fix a ton of warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Mar 8, 2024
1 parent 8a2f2a4 commit 179419f
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 72 deletions.
9 changes: 1 addition & 8 deletions Launchpad.Common/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ public static void AddOrUpdate<TKey, TValue>(this IDictionary<TKey, TValue> dict
throw new ArgumentNullException(nameof(dictionary));
}

if (dictionary.ContainsKey(key))
{
dictionary[key] = value;
}
else
{
dictionary.Add(key, value);
}
dictionary[key] = value;
}
}
2 changes: 1 addition & 1 deletion Launchpad.Launcher/Handlers/ChecksHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}

Expand Down
27 changes: 14 additions & 13 deletions Launchpad.Launcher/Handlers/GameHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ DirectoryHelpers directoryHelpers
/// <returns>A <see cref="System.Threading.Tasks.Task"/> representing the asynchronous operation.</returns>
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();
}

Expand All @@ -146,7 +146,7 @@ public async Task InstallGameAsync()
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
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);
}

Expand All @@ -156,7 +156,7 @@ public async Task UpdateGameAsync()
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public async Task VerifyGameAsync()
{
_log.LogInformation("Beginning verification of game files.");
_log.LogInformation("Beginning verification of game files");
await _patch.VerifyModuleAsync(EModule.Game);
}

Expand All @@ -166,16 +166,16 @@ public async Task VerifyGameAsync()
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
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());
}

Expand Down Expand Up @@ -207,22 +207,23 @@ 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
{
StartInfo = gameStartInfo,
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
);
}

Expand All @@ -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();
}
Expand Down
10 changes: 5 additions & 5 deletions Launchpad.Launcher/Handlers/LauncherHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -139,7 +139,7 @@ public async Task<bool> CanAccessStandardChangelog()
}
catch (WebException wex)
{
_log.LogWarning("Could not access standard changelog (WebException): " + wex.Message);
_log.LogWarning(wex, "Could not access standard changelog");
return false;
}
}
Expand All @@ -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
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ DirectoryHelpers directoryHelpers
/// <inheritdoc />
public override async Task<Result<bool>> 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;

Expand Down Expand Up @@ -132,13 +132,13 @@ public override async Task<Result<bool>> 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;
}

Expand Down Expand Up @@ -222,10 +222,6 @@ protected override async Task<Result<string>> 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())
Expand Down Expand Up @@ -262,7 +258,7 @@ protected override async Task<Result<string>> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ DirectoryHelpers directoryHelpers
/// <inheritdoc />
public override async Task<Result<bool>> 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;

Expand Down Expand Up @@ -120,13 +120,13 @@ public override async Task<Result<bool>> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public override async Task<Result> 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;
Expand All @@ -292,8 +292,9 @@ public override async Task<Result> 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);
Expand Down Expand Up @@ -468,7 +469,7 @@ public override async Task<Result<bool>> 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;
}
}
Expand Down Expand Up @@ -568,13 +569,13 @@ protected virtual async Task<Result> 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);
Expand All @@ -593,8 +594,10 @@ protected virtual async Task<Result> 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);
Expand Down
Loading

0 comments on commit 179419f

Please sign in to comment.