From 6da7d0cc00dad91003fbb6018ff8c8752ea37c26 Mon Sep 17 00:00:00 2001 From: pointfeev Date: Sun, 24 Oct 2021 20:26:44 -0400 Subject: [PATCH] small refactor --- CreamInstaller/CustomMessageException.cs | 7 +-- CreamInstaller/Program.cs | 58 +++++------------------- CreamInstaller/ProgramSelection.cs | 15 ++---- 3 files changed, 17 insertions(+), 63 deletions(-) diff --git a/CreamInstaller/CustomMessageException.cs b/CreamInstaller/CustomMessageException.cs index d42b3b4..f12dda2 100644 --- a/CreamInstaller/CustomMessageException.cs +++ b/CreamInstaller/CustomMessageException.cs @@ -4,14 +4,11 @@ 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 98f304e..a8579f5 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -41,34 +41,18 @@ 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; - } - return false; + else return true; + else return false; } public static bool IsFilePathLocked(this string filePath) { - bool Locked = false; - try - { - File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None).Close(); - } - catch (IOException) - { - Locked = true; - } - return Locked; + try { File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None).Close(); } + catch (IOException) { return true; } + return false; } public static SelectForm SelectForm; @@ -87,25 +71,16 @@ 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; } @@ -116,14 +91,8 @@ 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) @@ -133,9 +102,6 @@ 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 5c35469..57aa9f8 100644 --- a/CreamInstaller/ProgramSelection.cs +++ b/CreamInstaller/ProgramSelection.cs @@ -19,23 +19,14 @@ 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