From 0cbc98f6a773375a6c0a7869028229d01da524be Mon Sep 17 00:00:00 2001 From: pointfeev Date: Sun, 24 Oct 2021 20:33:37 -0400 Subject: [PATCH] Revert "small refactor" This reverts commit 6da7d0cc00dad91003fbb6018ff8c8752ea37c26. --- CreamInstaller/CustomMessageException.cs | 7 ++- CreamInstaller/Program.cs | 58 +++++++++++++++++++----- CreamInstaller/ProgramSelection.cs | 15 ++++-- 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/CreamInstaller/CustomMessageException.cs b/CreamInstaller/CustomMessageException.cs index f12dda2..d42b3b4 100644 --- a/CreamInstaller/CustomMessageException.cs +++ b/CreamInstaller/CustomMessageException.cs @@ -4,11 +4,14 @@ namespace CreamInstaller { public class CustomMessageException : Exception { - public CustomMessageException(string message) => this.message = message; - private string message; public override string Message => message ?? "CustomMessageException"; public override string ToString() => Message; + + public CustomMessageException(string message) + { + this.message = message; + } } } \ No newline at end of file diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index a8579f5..98f304e 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -41,18 +41,34 @@ namespace CreamInstaller public static bool IsProgramRunningDialog(Form form, ProgramSelection selection) { if (selection.IsProgramRunning) - if (new DialogForm(form).Show(ApplicationName, SystemIcons.Error, $"ERROR: {selection.ProgramName} is currently running!" + - $"\n\nPlease close the program/game to continue . . . ", "Retry", "Cancel") == DialogResult.OK) + { + if (new DialogForm(form).Show(ApplicationName, SystemIcons.Error, + $"ERROR: {selection.ProgramName} is currently running!" + + "\n\nPlease close the program/game to continue . . . ", + "Retry", "Cancel") == DialogResult.OK) + { return IsProgramRunningDialog(form, selection); - else return true; - else return false; + } + } + else + { + return true; + } + return false; } public static bool IsFilePathLocked(this string filePath) { - try { File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None).Close(); } - catch (IOException) { return true; } - return false; + bool Locked = false; + try + { + File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None).Close(); + } + catch (IOException) + { + Locked = true; + } + return Locked; } public static SelectForm SelectForm; @@ -71,16 +87,25 @@ namespace CreamInstaller { Canceled = cancel; if (OutputArchive != null || CancellationTokenSource != null || OutputTask != null || OutputFile != null) + { InstallForm?.UpdateUser("Cleaning up . . . ", LogColor.Cleanup); + } if (OutputArchive != null) { OutputArchive.Dispose(); OutputArchive = null; } - if (CancellationTokenSource != null) CancellationTokenSource.Cancel(); + if (CancellationTokenSource != null) + { + CancellationTokenSource.Cancel(); + } if (OutputTask != null) { - try { OutputTask.Wait(); } catch (AggregateException) { } + try + { + OutputTask.Wait(); + } + catch (AggregateException) { } OutputTask.Dispose(); OutputTask = null; } @@ -91,8 +116,14 @@ namespace CreamInstaller } if (OutputFile != null && File.Exists(OutputFile)) { - try { File.Delete(OutputFile); } - catch { InstallForm?.UpdateUser($"WARNING: Failed to clean up downloaded archive: {OutputFile}", LogColor.Warning); } + try + { + File.Delete(OutputFile); + } + catch + { + InstallForm?.UpdateUser($"WARNING: Failed to clean up downloaded archive: {OutputFile}", LogColor.Warning); + } OutputFile = null; } if (logout && MegaApiClient != null && MegaApiClient.IsLoggedIn) @@ -102,6 +133,9 @@ namespace CreamInstaller } } - private static void OnApplicationExit(object s, EventArgs e) => Cleanup(); + private static void OnApplicationExit(object s, EventArgs e) + { + Cleanup(); + } } } \ No newline at end of file diff --git a/CreamInstaller/ProgramSelection.cs b/CreamInstaller/ProgramSelection.cs index 57aa9f8..5c35469 100644 --- a/CreamInstaller/ProgramSelection.cs +++ b/CreamInstaller/ProgramSelection.cs @@ -19,14 +19,23 @@ namespace CreamInstaller foreach (string directory in SteamApiDllDirectories) { string file = directory + "\\steam_api64.dll"; - if (file.IsFilePathLocked()) return true; + if (file.IsFilePathLocked()) + { + return true; + } } return false; } } - public ProgramSelection() => Program.ProgramSelections.Add(this); + public ProgramSelection() + { + Program.ProgramSelections.Add(this); + } - public void Toggle(bool Enabled) => this.Enabled = Enabled; + public void Toggle(bool Enabled) + { + this.Enabled = Enabled; + } } } \ No newline at end of file