From 9b07880d9cffceb8dbef76c6e28c6bc8428f7195 Mon Sep 17 00:00:00 2001 From: KoalaBear Date: Fri, 26 Mar 2021 10:03:18 +0100 Subject: [PATCH] - Overwrite installer when it already exists --- HAClimateDeskbandInstaller/Program.cs | 82 +++++++++++++++------------ 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/HAClimateDeskbandInstaller/Program.cs b/HAClimateDeskbandInstaller/Program.cs index 4be1944..c96646a 100644 --- a/HAClimateDeskbandInstaller/Program.cs +++ b/HAClimateDeskbandInstaller/Program.cs @@ -63,52 +63,60 @@ static void Install(InstallInfo info) Console.WriteLine("Installing HA Climate Deskband on your computer, please wait."); RestartExplorer restartExplorer = new RestartExplorer(); - // Create directory - if (!Directory.Exists(info.TargetPath)) - { - Console.Write("Creating target directory.. "); - Directory.CreateDirectory(info.TargetPath); - Console.WriteLine("OK."); - CopyFiles(info); - - // Copy the uninstaller too - File.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(info.TargetPath, InstallerExecutableName)); - } - else + try { - restartExplorer.Execute(() => + // Create directory + if (!Directory.Exists(info.TargetPath)) { + Console.Write("Creating target directory.. "); + Directory.CreateDirectory(info.TargetPath); + Console.WriteLine("OK."); CopyFiles(info); // Copy the uninstaller too - File.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(info.TargetPath, InstallerExecutableName)); - }); - } - - // Register assemblies - foreach (string filename in info.FilesToRegister) - { - string targetFilePath = Path.Combine(info.TargetPath, filename); - Console.Write($"Registering {filename}.. "); - RegisterDLL(targetFilePath, true, false); - Console.WriteLine("OK."); - } + File.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(info.TargetPath, InstallerExecutableName), true); + } + else + { + restartExplorer.Execute(() => + { + CopyFiles(info); - Console.Write("Registering uninstaller.. "); - FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(info.TargetPath, DllName)); - CreateUninstaller(Path.Combine(info.TargetPath, InstallerExecutableName), Version.Parse(fileVersionInfo.FileVersion)); - Console.WriteLine("OK."); + // Copy the uninstaller too + File.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(info.TargetPath, InstallerExecutableName), true); + }); + } - // Remove pending delete operations - Console.Write("Cleaning up previous pending uninstalls.. "); + // Register assemblies + foreach (string filename in info.FilesToRegister) + { + string targetFilePath = Path.Combine(info.TargetPath, filename); + Console.Write($"Registering {filename}.. "); + RegisterDLL(targetFilePath, true, false); + Console.WriteLine("OK."); + } - if (CleanUpPendingDeleteOperations(info.TargetPath, out string errorMessage)) - { + Console.Write("Registering uninstaller.. "); + FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(info.TargetPath, DllName)); + CreateUninstaller(Path.Combine(info.TargetPath, InstallerExecutableName), Version.Parse(fileVersionInfo.FileVersion)); Console.WriteLine("OK."); + + // Remove pending delete operations + Console.Write("Cleaning up previous pending uninstalls.. "); + + if (CleanUpPendingDeleteOperations(info.TargetPath, out string errorMessage)) + { + Console.WriteLine("OK."); + } + else + { + Console.WriteLine($"ERROR: {errorMessage}"); + } } - else + catch (Exception ex) { - Console.WriteLine($"ERROR: {errorMessage}"); + Console.WriteLine("Error while installing.."); + Console.WriteLine(ex.ToString()); } } @@ -306,7 +314,7 @@ static bool CleanUpPendingDeleteOperations(string basepath, out string errorMess { string[] values = o as string[]; List dest = new List(); - + for (int i = 0; i < values.Length; i += 2) { if (!values[i].Contains(basepath)) @@ -324,7 +332,7 @@ static bool CleanUpPendingDeleteOperations(string basepath, out string errorMess } errorMessage = ""; - + return true; } catch (Exception ex)