From 8edcd530174b6dfea415b627c6d5afffa13dbd41 Mon Sep 17 00:00:00 2001 From: pointfeev Date: Fri, 30 Jul 2021 06:01:42 -0500 Subject: [PATCH] Update 1.0.4 - Fixed unhandled exceptions when cleaning up files - Added Mutex to make sure only one instance of program is active at a time --- CreamInstaller/CreamInstaller.csproj | 8 ++------ CreamInstaller/InstallForm.cs | 4 ++-- CreamInstaller/Program.cs | 21 +++++++++++++++------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index 937156e..10fa14b 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -43,12 +43,8 @@ - - Form - - - Form - + + True True diff --git a/CreamInstaller/InstallForm.cs b/CreamInstaller/InstallForm.cs index a1d5f3b..7bf1af8 100644 --- a/CreamInstaller/InstallForm.cs +++ b/CreamInstaller/InstallForm.cs @@ -55,7 +55,7 @@ namespace CreamInstaller { File.Delete(Program.OutputFile); } - catch (UnauthorizedAccessException) + catch { throw new Exception("Unable to delete old archive file for " + selection.ProgramName); } @@ -121,7 +121,7 @@ namespace CreamInstaller { File.Delete(file); } - catch (UnauthorizedAccessException) + catch { throw new Exception("Unable to delete Steam API files for " + selection.ProgramName); } diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index ec7ac3d..92a225f 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -18,6 +18,9 @@ namespace CreamInstaller [return: MarshalAs(UnmanagedType.Bool)] static extern bool AllocConsole(); + [DllImport("user32.dll")] + static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); + public static string ApplicationName = "CreamInstaller v" + Application.ProductVersion + ": CreamAPI Downloader & Installer"; public static Assembly EntryAssembly = Assembly.GetEntryAssembly(); @@ -28,11 +31,17 @@ namespace CreamInstaller [STAThread] static void Main() { - Application.SetHighDpiMode(HighDpiMode.SystemAware); - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.ApplicationExit += new EventHandler(OnApplicationExit); - Application.Run(new MainForm()); + bool createdNew = true; + Mutex mutex = new Mutex(true, "CreamInstaller", out createdNew); + if (createdNew) + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.ApplicationExit += new EventHandler(OnApplicationExit); + Application.Run(new MainForm()); + } + mutex.Close(); } public static bool IsFilePathLocked(this string filePath) @@ -111,7 +120,7 @@ namespace CreamInstaller { File.Delete(OutputFile); } - catch (UnauthorizedAccessException) + catch { InstallForm?.UpdateUser($"WARNING: Couldn't clean up downloaded archive ({OutputFile})", LogColor.Warning); }