From d70f68394367e4effc5c5cdf9e9cffa164daa4eb Mon Sep 17 00:00:00 2001 From: pointfeev Date: Fri, 6 Aug 2021 22:55:12 -0500 Subject: [PATCH] Code aesthetics, unused library cleanup --- CreamInstaller/DialogForm.cs | 3 +-- CreamInstaller/InstallForm.cs | 25 +++++-------------------- CreamInstaller/MainForm.cs | 2 -- CreamInstaller/Program.cs | 18 ++++++++++++++++++ CreamInstaller/ProgramSelection.cs | 2 +- CreamInstaller/SelectForm.cs | 18 +----------------- 6 files changed, 26 insertions(+), 42 deletions(-) diff --git a/CreamInstaller/DialogForm.cs b/CreamInstaller/DialogForm.cs index b280e6e..df222b6 100644 --- a/CreamInstaller/DialogForm.cs +++ b/CreamInstaller/DialogForm.cs @@ -1,5 +1,4 @@ -using System; -using System.Drawing; +using System.Drawing; using System.Windows.Forms; namespace CreamInstaller diff --git a/CreamInstaller/InstallForm.cs b/CreamInstaller/InstallForm.cs index 3af910f..fb037ac 100644 --- a/CreamInstaller/InstallForm.cs +++ b/CreamInstaller/InstallForm.cs @@ -101,6 +101,9 @@ namespace CreamInstaller } UpdateProgress(100); + if (!Program.IsProgramRunningDialog(this, selection)) + throw new OperationCanceledException(); + UpdateProgress(0); UpdateUser("Installing CreamAPI files for " + selection.ProgramName + " . . . ", LogColor.Operation); int currentFileCount = 0; @@ -171,26 +174,8 @@ namespace CreamInstaller Program.Cleanup(cancel: false, logout: false); - bool Check() - { - if (selection.ProgramIsRunning) - { - if (new DialogForm(this).Show(Program.ApplicationName, SystemIcons.Error, - $"ERROR: {selection.ProgramName} is currently running!" + - "\n\nPlease close the program/game to continue . . .", - "Retry", "Cancel") == DialogResult.OK) - return Check(); - } - else - { - return true; - } - return false; - } - if (!Check()) - { - throw new Exception("The operation was canceled."); - } + if (!Program.IsProgramRunningDialog(this, selection)) + throw new OperationCanceledException(); try { diff --git a/CreamInstaller/MainForm.cs b/CreamInstaller/MainForm.cs index 764ec0b..b467ea2 100644 --- a/CreamInstaller/MainForm.cs +++ b/CreamInstaller/MainForm.cs @@ -1,8 +1,6 @@ using System; -using System.Diagnostics; using System.Drawing; using System.IO; -using System.Reflection; using System.Threading; using System.Windows.Forms; using CG.Web.MegaApiClient; diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index 90631de..85e5d5f 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -2,6 +2,7 @@ using CG.Web.MegaApiClient; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Drawing; using System.IO; using System.IO.Compression; using System.Reflection; @@ -46,6 +47,23 @@ namespace CreamInstaller mutex.Close(); } + 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) + return IsProgramRunningDialog(form, selection); + } + else + { + return true; + } + return false; + } + public static bool IsFilePathLocked(this string filePath) { bool Locked = false; diff --git a/CreamInstaller/ProgramSelection.cs b/CreamInstaller/ProgramSelection.cs index 529bef4..bc1438b 100644 --- a/CreamInstaller/ProgramSelection.cs +++ b/CreamInstaller/ProgramSelection.cs @@ -10,7 +10,7 @@ namespace CreamInstaller public List SteamApiDllDirectories; public INode DownloadNode; - public bool ProgramIsRunning + public bool IsProgramRunning { get { diff --git a/CreamInstaller/SelectForm.cs b/CreamInstaller/SelectForm.cs index d70e481..326e882 100644 --- a/CreamInstaller/SelectForm.cs +++ b/CreamInstaller/SelectForm.cs @@ -235,23 +235,7 @@ namespace CreamInstaller { foreach (ProgramSelection selection in Program.ProgramSelections) { - bool Check() - { - if (selection.ProgramIsRunning) - { - if (new DialogForm(this).Show(Program.ApplicationName, SystemIcons.Error, - $"ERROR: {selection.ProgramName} is currently running!" + - "\n\nPlease close the program/game to continue . . .", - "Retry", "Cancel") == DialogResult.OK) - return Check(); - } - else - { - return true; - } - return false; - } - if (!Check()) + if (!Program.IsProgramRunningDialog(this, selection)) return; }