From 2d3460960145d096582a1b82c26936674224fe99 Mon Sep 17 00:00:00 2001 From: rounk-ctrl <70931017+rounk-ctrl@users.noreply.github.com> Date: Mon, 25 Sep 2023 19:53:40 +0400 Subject: [PATCH] improve logging --- Rectify11Installer/Core/Backend/Common.cs | 271 +++++++++--------- Rectify11Installer/Core/Backend/Extras.cs | 169 +++++------ Rectify11Installer/Core/Backend/Icons.cs | 218 +++++++------- Rectify11Installer/Core/Backend/Installer.cs | 23 +- Rectify11Installer/Core/Backend/MMCHelper.cs | 62 ++-- Rectify11Installer/Core/Backend/Themes.cs | 233 ++++++++------- .../Core/Backend/Uninstaller.cs | 6 +- Rectify11Installer/Core/Helpers.cs | 32 ++- Rectify11Installer/Pages/ProgressPage.cs | 12 +- 9 files changed, 537 insertions(+), 489 deletions(-) diff --git a/Rectify11Installer/Core/Backend/Common.cs b/Rectify11Installer/Core/Backend/Common.cs index 437d37ad6..d649ae89b 100644 --- a/Rectify11Installer/Core/Backend/Common.cs +++ b/Rectify11Installer/Core/Backend/Common.cs @@ -18,38 +18,48 @@ internal class Common /// indicates whether theme only files are written public static bool WriteFiles(bool icons, bool themes) { - if (icons) - { - if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "aRun.exe"), Properties.Resources.AdvancedRun, Helper.OperationType.Write)) - return false; - if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe"), Properties.Resources.Rectify11Phase2, Helper.OperationType.Write)) - return false; - } - if (themes) + try { - if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "themes.7z"), Properties.Resources.themes, Helper.OperationType.Write)) - return false; + if (icons) + { + if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "aRun.exe"), Properties.Resources.AdvancedRun, Helper.OperationType.Write)) + return false; + if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe"), Properties.Resources.Rectify11Phase2, Helper.OperationType.Write)) + return false; + } + if (themes) + { + if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "themes.7z"), Properties.Resources.themes, Helper.OperationType.Write)) + return false; - var s = NativeMethods.IsArm64() ? Properties.Resources.secureux_arm64 : Properties.Resources.secureux_x64; - var dll = NativeMethods.IsArm64() ? Properties.Resources.ThemeDll_arm64 : Properties.Resources.ThemeDll_x64; + var s = NativeMethods.IsArm64() ? Properties.Resources.secureux_arm64 : Properties.Resources.secureux_x64; + var dll = NativeMethods.IsArm64() ? Properties.Resources.ThemeDll_arm64 : Properties.Resources.ThemeDll_x64; - if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe"), s, Helper.OperationType.Write)) - return false; - if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "ThemeDll.dll"), dll, Helper.OperationType.Write)) - return false; + if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe"), s, Helper.OperationType.Write)) + return false; + if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "ThemeDll.dll"), dll, Helper.OperationType.Write)) + return false; + } + if (!themes && !icons) + { + if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "7za.exe"), Properties.Resources._7za, Helper.OperationType.Write)) + return false; + if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "files.7z"), Properties.Resources.files7z, Helper.OperationType.Write)) + return false; + if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "extras.7z"), Properties.Resources.extras, Helper.OperationType.Write)) + return false; + if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "ResourceHacker.exe"), Properties.Resources.ResourceHacker, Helper.OperationType.Write)) + return false; + } + + Logger.WriteLine("WriteFiles() succeeded"); + return true; } - if (!themes && !icons) + catch (Exception ex) { - if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "7za.exe"), Properties.Resources._7za, Helper.OperationType.Write)) - return false; - if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "files.7z"), Properties.Resources.files7z, Helper.OperationType.Write)) - return false; - if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "extras.7z"), Properties.Resources.extras, Helper.OperationType.Write)) - return false; - if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "ResourceHacker.exe"), Properties.Resources.ResourceHacker, Helper.OperationType.Write)) - return false; + Logger.WriteLine("WriteFiles() failed", ex); + return false; } - return true; } /// @@ -57,63 +67,22 @@ public static bool WriteFiles(bool icons, bool themes) /// public static bool CreateDirs() { - if (!Directory.Exists(Path.Combine(Variables.r11Folder, "Backup"))) + try { - try - { + if (!Directory.Exists(Path.Combine(Variables.r11Folder, "Backup"))) Directory.CreateDirectory(Path.Combine(Variables.r11Folder, "Backup")); - Logger.WriteLine("Created " + Path.Combine(Variables.r11Folder, "Backup")); - } - catch (Exception ex) - { - Logger.WriteLine("Error creating " + Path.Combine(Variables.r11Folder, "Backup"), ex); - return false; - } - } - else - { - Logger.WriteLine(Path.Combine(Variables.r11Folder, "Backup") + " already exists."); - } + else + Logger.WriteLine(Path.Combine(Variables.r11Folder, "Backup") + " already exists."); - if (Directory.Exists(Path.Combine(Variables.r11Folder, "Tmp"))) - { - Logger.WriteLine(Path.Combine(Variables.r11Folder, "Tmp") + " exists. Deleting it."); - try - { - Directory.Delete(Path.Combine(Variables.r11Folder, "Tmp"), true); - } - catch - { - string name = Path.GetRandomFileName(); - string tmpPath = Path.Combine(Path.GetTempPath(), name); - Directory.Move(Path.Combine(Variables.r11Folder, "Tmp"), tmpPath); - var files = Directory.GetFiles(tmpPath); - for (int i = 0; i < files.Length; i++) - { - try - { - File.Delete(files[i]); - } - catch - { - NativeMethods.MoveFileEx(files[i], null, NativeMethods.MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT); - } - } - NativeMethods.MoveFileEx(tmpPath, null, NativeMethods.MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT); - return false; - } - } - try - { + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "Tmp"), false); Directory.CreateDirectory(Path.Combine(Variables.r11Folder, "Tmp")); - Logger.WriteLine("Created " + Path.Combine(Variables.r11Folder, "Tmp")); + return true; } catch (Exception ex) { - Logger.WriteLine("Error creating " + Path.Combine(Variables.r11Folder, "Tmp"), ex); + Logger.WriteLine("CreateDirs() failed", ex); return false; } - return true; } /// @@ -121,29 +90,38 @@ public static bool CreateDirs() /// public static bool CreateUninstall() { - // backup - // fails anyways if you use uninstaller.exe - Helper.SafeFileOperation(Assembly.GetExecutingAssembly().Location, Path.Combine(Variables.r11Folder, "Uninstall.exe"), Helper.OperationType.Copy); - Logger.WriteLine("Installer copied to " + Path.Combine(Variables.r11Folder, "Uninstall.exe")); + try + { - var r11key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true)?.CreateSubKey("Rectify11", true); - if (r11key != null) + // backup + // fails anyways if you use uninstaller.exe + Helper.SafeFileOperation(Assembly.GetExecutingAssembly().Location, Path.Combine(Variables.r11Folder, "Uninstall.exe"), Helper.OperationType.Copy); + Logger.WriteLine("Installer copied to " + Path.Combine(Variables.r11Folder, "Uninstall.exe")); + + var r11key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true)?.CreateSubKey("Rectify11", true); + if (r11key != null) + { + r11key.SetValue("DisplayName", "Rectify11", RegistryValueKind.String); + r11key.SetValue("DisplayVersion", Assembly.GetEntryAssembly()?.GetName().Version.ToString() ?? string.Empty, RegistryValueKind.String); + r11key.SetValue("DisplayIcon", Path.Combine(Variables.r11Folder, "Uninstall.exe"), RegistryValueKind.String); + r11key.SetValue("InstallLocation", Variables.r11Folder, RegistryValueKind.String); + r11key.SetValue("UninstallString", Path.Combine(Variables.r11Folder, "Uninstall.exe"), RegistryValueKind.String); + r11key.SetValue("ModifyPath", Path.Combine(Variables.r11Folder, "Uninstall.exe"), RegistryValueKind.String); + r11key.SetValue("NoRepair", 1, RegistryValueKind.DWord); + r11key.SetValue("VersionMajor", Assembly.GetEntryAssembly()?.GetName().Version.Major.ToString() ?? string.Empty, RegistryValueKind.String); + r11key.SetValue("VersionMinor", Assembly.GetEntryAssembly()?.GetName().Version.Minor.ToString() ?? string.Empty, RegistryValueKind.String); + r11key.SetValue("Build", Assembly.GetEntryAssembly()?.GetName().Version.Build.ToString() ?? string.Empty, RegistryValueKind.String); + r11key.SetValue("Publisher", "The Rectify11 Team", RegistryValueKind.String); + r11key.SetValue("URLInfoAbout", "https://rectify11.net/", RegistryValueKind.String); + return true; + } + return false; + } + catch (Exception ex) { - r11key.SetValue("DisplayName", "Rectify11", RegistryValueKind.String); - r11key.SetValue("DisplayVersion", Assembly.GetEntryAssembly()?.GetName().Version.ToString() ?? string.Empty, RegistryValueKind.String); - r11key.SetValue("DisplayIcon", Path.Combine(Variables.r11Folder, "Uninstall.exe"), RegistryValueKind.String); - r11key.SetValue("InstallLocation", Variables.r11Folder, RegistryValueKind.String); - r11key.SetValue("UninstallString", Path.Combine(Variables.r11Folder, "Uninstall.exe"), RegistryValueKind.String); - r11key.SetValue("ModifyPath", Path.Combine(Variables.r11Folder, "Uninstall.exe"), RegistryValueKind.String); - r11key.SetValue("NoRepair", 1, RegistryValueKind.DWord); - r11key.SetValue("VersionMajor", Assembly.GetEntryAssembly()?.GetName().Version.Major.ToString() ?? string.Empty, RegistryValueKind.String); - r11key.SetValue("VersionMinor", Assembly.GetEntryAssembly()?.GetName().Version.Minor.ToString() ?? string.Empty, RegistryValueKind.String); - r11key.SetValue("Build", Assembly.GetEntryAssembly()?.GetName().Version.Build.ToString() ?? string.Empty, RegistryValueKind.String); - r11key.SetValue("Publisher", "The Rectify11 Team", RegistryValueKind.String); - r11key.SetValue("URLInfoAbout", "https://rectify11.net/", RegistryValueKind.String); - return true; + Logger.Warn("CreateUninstall() failed", ex); + return false; } - return false; } /// @@ -151,23 +129,24 @@ public static bool CreateUninstall() /// public static bool InstallRuntimes() { - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "vcredist.exe")); - Logger.WriteLine("Extracting vcredist.exe from extras.7z"); - Helper.SvExtract(true, "extras.7z", "vcredist.exe"); - - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "core31.exe")); - Logger.WriteLine("Extracting core31.exe from extras.7z"); - Helper.SvExtract(true, "extras.7z", "core31.exe"); - - Logger.WriteLine("Executing vcredist.exe with arguments /install /quiet /norestart"); - ProcessStartInfo vcinfo = new() - { - FileName = Path.Combine(Variables.r11Folder, "vcredist.exe"), - WindowStyle = ProcessWindowStyle.Hidden, - Arguments = " /install /quiet /norestart" - }; try { + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "vcredist.exe")); + Logger.WriteLine("Extracting vcredist.exe from extras.7z"); + Helper.SvExtract(true, "extras.7z", "vcredist.exe"); + + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "core31.exe")); + Logger.WriteLine("Extracting core31.exe from extras.7z"); + Helper.SvExtract(true, "extras.7z", "core31.exe"); + + // vcredist + Logger.WriteLine("Executing vcredist.exe with arguments /install /quiet /norestart"); + ProcessStartInfo vcinfo = new() + { + FileName = Path.Combine(Variables.r11Folder, "vcredist.exe"), + WindowStyle = ProcessWindowStyle.Hidden, + Arguments = " /install /quiet /norestart" + }; var vcproc = Process.Start(vcinfo); if (vcproc == null) return false; vcproc.WaitForExit(); @@ -179,20 +158,16 @@ public static bool InstallRuntimes() } else Variables.vcRedist = true; if (vcproc.ExitCode == 0) Variables.RestartRequired = true; - } - catch - { - return false; - } - Logger.WriteLine("Executing core31.exe with arguments /install /quiet /norestart"); - ProcessStartInfo core3info = new() - { - FileName = Path.Combine(Variables.r11Folder, "core31.exe"), - WindowStyle = ProcessWindowStyle.Hidden, - Arguments = " /install /quiet /norestart" - }; - try - { + + // .net core + Logger.WriteLine("Executing core31.exe with arguments /install /quiet /norestart"); + ProcessStartInfo core3info = new() + { + FileName = Path.Combine(Variables.r11Folder, "core31.exe"), + WindowStyle = ProcessWindowStyle.Hidden, + Arguments = " /install /quiet /norestart" + }; + var core3proc = Process.Start(core3info); if (core3proc == null) return false; core3proc.WaitForExit(); @@ -204,12 +179,13 @@ public static bool InstallRuntimes() } else Variables.core31 = true; if (core3proc.ExitCode == 0) Variables.RestartRequired = true; + return true; } - catch + catch (Exception ex) { + Logger.WriteLine("InstallRuntimes() failed", ex); return false; } - return true; } /// @@ -242,28 +218,37 @@ public static void RuntimeInstallError(string app, string info, string link) /// public static bool Cleanup() { - // we dont care about returned value - Helper.SafeDirectoryDeletion(Variables.r11Files, false); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "files.7z")); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "extras.7z")); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "vcredist.exe")); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "extras", "vcredist.exe")); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "core31.exe")); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "extras", "core31.exe")); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "newfiles.txt")); - Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "themes"), false); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "themes.7z")); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "7za.exe")); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "aRun.exe")); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "ResourceHacker.exe")); - if (Directory.Exists(Path.Combine(Variables.r11Folder, "extras"))) + try { - if (Directory.GetDirectories(Path.Combine(Variables.r11Folder, "extras")).Length == 0) + // we dont care about returned value + Helper.SafeDirectoryDeletion(Variables.r11Files, false); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "files.7z")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "extras.7z")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "vcredist.exe")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "extras", "vcredist.exe")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "core31.exe")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "extras", "core31.exe")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "newfiles.txt")); + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "themes"), false); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "themes.7z")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "7za.exe")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "aRun.exe")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "ResourceHacker.exe")); + if (Directory.Exists(Path.Combine(Variables.r11Folder, "extras"))) { - Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "extras"), false); + if (Directory.GetDirectories(Path.Combine(Variables.r11Folder, "extras")).Length == 0) + { + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "extras"), false); + } } + Logger.WriteLine("Cleanup() succeeded"); + return true; + } + catch (Exception ex) + { + Logger.WriteLine("Cleanup() failed", ex); + return false; } - return true; } #endregion } diff --git a/Rectify11Installer/Core/Backend/Extras.cs b/Rectify11Installer/Core/Backend/Extras.cs index 54507c702..e8541e8f2 100644 --- a/Rectify11Installer/Core/Backend/Extras.cs +++ b/Rectify11Installer/Core/Backend/Extras.cs @@ -13,98 +13,87 @@ internal class Extras { public static bool Install(FrmWizard frm) { - Logger.WriteLine("Installing Extras"); - Logger.WriteLine("─────────────────"); - - if (InstallOptions.InstallWallpaper) - { - frm.InstallerProgress = "Installing extras: Wallpapers"; - - if (InstallWallpapers()) - Logger.WriteLine("InstallWallpapers() succeeded."); - } - if (InstallOptions.InstallASDF) + try { - frm.InstallerProgress = "Installing extras: AccentColorizer"; - - if (Installasdf()) - Logger.WriteLine("Installasdf() succeeded."); + Logger.WriteLine("Installing Extras"); + Logger.WriteLine("─────────────────"); - if (!Variables.RestartRequired) + if (InstallOptions.InstallWallpaper) { - Interaction.Shell(Path.Combine(Variables.r11Folder, "extras", "AccentColorizer", "AccentColorizer.exe"), AppWinStyle.Hide); - Interaction.Shell(Path.Combine(Variables.r11Folder, "extras", "AccentColorizer", "AccentColorizerEleven.exe"), AppWinStyle.Hide); + frm.InstallerProgress = "Installing extras: Wallpapers"; + + if (InstallWallpapers()) + Logger.WriteLine("InstallWallpapers() succeeded."); } - } - if (InstallOptions.InstallGadgets) - { - frm.InstallerProgress = "Installing extras: Gadgets"; + if (InstallOptions.InstallASDF) + { + frm.InstallerProgress = "Installing extras: AccentColorizer"; - InstallGadgets(); - Logger.WriteLine("InstallGadgets() succeeded."); - Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "GadgetPack"), true); - } - if (InstallOptions.InstallShell) - { - frm.InstallerProgress = "Installing extras: Enhanced context menu"; + Installasdf(); - if (InstallShell()) - Logger.WriteLine("InstallShell() succeeded."); + if (!Variables.RestartRequired) + { + Interaction.Shell(Path.Combine(Variables.r11Folder, "extras", "AccentColorizer", "AccentColorizer.exe"), AppWinStyle.Hide); + Interaction.Shell(Path.Combine(Variables.r11Folder, "extras", "AccentColorizer", "AccentColorizerEleven.exe"), AppWinStyle.Hide); + } + } + if (InstallOptions.InstallGadgets) + { + frm.InstallerProgress = "Installing extras: Gadgets"; - try + InstallGadgets(); + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "extras", "GadgetPack"), false); + } + if (InstallOptions.InstallShell) { - Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "Nilesoft"), true); + frm.InstallerProgress = "Installing extras: Enhanced context menu"; + + InstallShell(); + + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "extras", "Nilesoft"), false); + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "extras", "NilesoftArm64"), false); } - catch { } - try + if (InstallOptions.userAvatars) { - Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "NilesoftArm64"), true); + frm.InstallerProgress = "Installing extras: User avatars"; + + InstallUserAvatars(); + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "extras", "userAV"), false); } - catch { } + Logger.WriteLine("InstallExtras() succeeded."); + Logger.WriteLine("══════════════════════════════════════════════"); + return true; } - if (InstallOptions.userAvatars) + catch (Exception ex) { - frm.InstallerProgress = "Installing extras: User avatars"; - - if (InstallUserAvatars()) - Logger.WriteLine("InstallUserAvatars() succeeded."); - Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "userAV"), true); + Logger.WriteLine("Extras.Install() failed", ex); + return false; } - Logger.WriteLine("InstallExtras() succeeded."); - Logger.WriteLine("══════════════════════════════════════════════"); - return true; } public static bool Uninstall() { - for (int i = 0; i < UninstallOptions.uninstExtrasList.Count; i++) + try { - if (UninstallOptions.uninstExtrasList[i] == "wallpapersNode") - { - UninstallWallpapers(); - Logger.WriteLine("Uninstalled wallpapers"); - } - if (UninstallOptions.uninstExtrasList[i] == "asdfNode") + for (int i = 0; i < UninstallOptions.uninstExtrasList.Count; i++) { - UninstallAsdf(); - Logger.WriteLine("Uninstalled asdf"); - } - if (UninstallOptions.uninstExtrasList[i] == "useravNode") - { - UninstallUserAv(); - Logger.WriteLine("Uninstalled user avatars"); - } - if (UninstallOptions.uninstExtrasList[i] == "shellNode") - { - UninstallShell(); - Logger.WriteLine("Uninstalled shell"); - } - if (UninstallOptions.uninstExtrasList[i] == "gadgetsNode") - { - UninstallGadgets(); - Logger.WriteLine("Uninstalled gadgets"); + if (UninstallOptions.uninstExtrasList[i] == "wallpapersNode") + UninstallWallpapers(); + if (UninstallOptions.uninstExtrasList[i] == "asdfNode") + UninstallAsdf(); + if (UninstallOptions.uninstExtrasList[i] == "useravNode") + UninstallUserAv(); + if (UninstallOptions.uninstExtrasList[i] == "shellNode") + UninstallShell(); + if (UninstallOptions.uninstExtrasList[i] == "gadgetsNode") + UninstallGadgets(); } + return true; + } + catch (Exception ex) + { + Logger.WriteLine("Extras.Uninstall() failed", ex); + return false; } - return true; } /// @@ -117,8 +106,7 @@ private static bool InstallWallpapers() UninstallWallpapers(); string path = Path.Combine(Variables.r11Folder, "extras", "wallpapers"); - if (Directory.Exists(path)) - Directory.Delete(path, true); + Helper.SafeDirectoryDeletion(path, false); // extract the 7z Helper.SvExtract("extras.7z", "extras", "wallpapers"); @@ -142,7 +130,9 @@ private static bool InstallWallpapers() { File.Copy(files[i].FullName, Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified", files[i].Name), true); } - Directory.Delete(path, true); + Helper.SafeDirectoryDeletion(path, false); + + Logger.WriteLine("InstallWallpapers() succeeded"); return true; } catch (Exception ex) @@ -173,10 +163,12 @@ private static bool Installasdf() asdf11.Target = Path.Combine(Variables.r11Folder, "extras", "AccentColorizer", "AccentColorizerEleven.exe"); asdf11.Save(Path.Combine(GetFolderPath(SpecialFolder.CommonStartMenu), "programs", "startup", "Accentcolorizer11.lnk")); + Logger.WriteLine("Installasdf() succeeded."); return true; } catch (Exception ex) { + UninstallAsdf(); Logger.WriteLine("Installasdf() failed", ex); return false; } @@ -190,10 +182,7 @@ private static void InstallGadgets() try { UninstallGadgets(); - if (Directory.Exists(Path.Combine(Variables.r11Folder, "extras", "GadgetPack"))) - { - Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "GadgetPack"), true); - } + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "extras", "GadgetPack"), false); // extract the 7z Helper.SvExtract("extras.7z", "extras", "GadgetPack"); @@ -206,9 +195,12 @@ private static void InstallGadgets() }; var vcproc = Process.Start(gad); vcproc.WaitForExit(); + + Logger.WriteLine("InstallGadgets() succeeded."); } catch (Exception ex) { + UninstallGadgets(); Logger.WriteLine("InstallGadgets() failed", ex); } } @@ -261,10 +253,13 @@ private static bool InstallShell() Thread.Sleep(3000); if (num == 4) Process.Start(Path.Combine(GetFolderPath(SpecialFolder.CommonStartMenu), "programs", "startup", "acrylmenu.lnk")); } + + Logger.WriteLine("InstallShell() succeeded."); return true; } catch (Exception ex) { + UninstallShell(); Logger.WriteLine("InstallShell() failed", ex); return false; } @@ -278,11 +273,7 @@ private static bool InstallUserAvatars() try { UninstallUserAv(); - - if (Directory.Exists(Path.Combine(Variables.r11Folder, "extras", "userAV"))) - { - Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "userAV"), true); - } + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "extras", "userAV"), false); // extract the 7z Helper.SvExtract("extras.7z", "extras", "userAV"); @@ -295,16 +286,18 @@ private static bool InstallUserAvatars() File.Copy(Path.Combine(Variables.r11Folder, "extras", "userAV", info.GetFiles("*.*")[i].Name), Path.Combine(Variables.progdata, "Microsoft", "User Account Pictures", "Default Pictures", info.GetFiles("*.*")[i].Name), true); } + + Logger.WriteLine("InstallUserAvatars() succeeded."); return true; } catch (Exception ex) { + UninstallUserAv(); Logger.WriteLine("InstallUserAvatars() failed", ex); return false; } } - private static bool UninstallWallpapers() { try @@ -331,6 +324,8 @@ private static bool UninstallWallpapers() Helper.SafeDirectoryDeletion(Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified"), false); } } + + Logger.WriteLine("UninstallWallpapers() succeeded"); return true; } catch (Exception ex) @@ -365,6 +360,8 @@ private static bool UninstallAsdf() { Helper.SafeDirectoryDeletion(epath, false); } + + Logger.WriteLine("UninstallAsdf() succeeded"); return true; } return true; @@ -384,6 +381,8 @@ private static bool UninstallGadgets() var gaduns = Process.Start(uns); gaduns.WaitForExit(); } + + Logger.WriteLine("UninstallGadgets() succeeded"); return true; } catch (Exception ex) @@ -432,6 +431,7 @@ private static bool UninstallShell() Thread.Sleep(3000); } } + Logger.WriteLine("UninstallShell() succeeded"); return true; } catch (Exception ex) @@ -445,6 +445,7 @@ private static bool UninstallUserAv() try { Helper.SafeDirectoryDeletion(Path.Combine(Variables.progdata, "Microsoft", "User Account Pictures", "Default Pictures"), false); + Logger.WriteLine("UninstallUserAv() succeeded"); return true; } catch (Exception ex) diff --git a/Rectify11Installer/Core/Backend/Icons.cs b/Rectify11Installer/Core/Backend/Icons.cs index 677053c2f..f8ac29a69 100644 --- a/Rectify11Installer/Core/Backend/Icons.cs +++ b/Rectify11Installer/Core/Backend/Icons.cs @@ -20,124 +20,117 @@ private enum PatchType x86 } #endregion + + /// + /// icon installation logic + /// + /// FrmWizard instance + /// true if succeeds, else returns false public static bool Install(FrmWizard frm) { - Logger.WriteLine("Installing icons"); - Logger.WriteLine("────────────────"); - // extract files, delete if folder exists - frm.InstallerProgress = "Extracting files..."; - Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "files"), false); try { - File.WriteAllBytes(Path.Combine(Variables.r11Folder, "files.7z"), Properties.Resources.files7z); - Logger.LogFile("files.7z"); - } - catch (Exception ex) - { - Logger.LogFile("files.7z", ex); - return false; - } + Logger.WriteLine("Installing icons"); + Logger.WriteLine("────────────────"); + // extract files, delete if folder exists + frm.InstallerProgress = "Extracting files..."; + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "files"), false); + if (!Helper.SafeFileOperation( + Path.Combine(Variables.r11Folder, "files.7z"), + Properties.Resources.files7z, + Helper.OperationType.Write)) + return false; - // extract the 7z - Helper.SvExtract("files.7z", "files"); - Logger.WriteLine("Extracted files.7z"); - - // Get all patches - var patches = PatchesParser.GetAll(); - var patch = patches.Items; - decimal progress = 0; - List fileList = new(); - List x86List = new(); - for (var i = 0; i < patch.Length; i++) - { - for (var j = 0; j < InstallOptions.iconsList.Count; j++) + // extract the 7z + Helper.SvExtract("files.7z", "files"); + + // Get all patches + var patches = PatchesParser.GetAll(); + var patch = patches.Items; + decimal progress = 0; + List fileList = new(); + List x86List = new(); + for (var i = 0; i < patch.Length; i++) { - if (patch[i].Mui.Contains(InstallOptions.iconsList[j])) + for (var j = 0; j < InstallOptions.iconsList.Count; j++) { - var number = Math.Round((progress / InstallOptions.iconsList.Count) * 100m); - frm.InstallerProgress = "Patching " + patch[i].Mui + " (" + number + "%)"; - if (!MatchAndApplyRule(patch[i])) - { - Logger.Warn("MatchAndApplyRule() on " + patch[i].Mui + " failed"); - } - else + if (patch[i].Mui.Contains(InstallOptions.iconsList[j])) { - fileList.Add(patch[i].HardlinkTarget); - if (!string.IsNullOrWhiteSpace(patch[i].x86)) + var number = Math.Round((progress / InstallOptions.iconsList.Count) * 100m); + frm.InstallerProgress = "Patching " + patch[i].Mui + " (" + number + "%)"; + if (!MatchAndApplyRule(patch[i])) + { + Logger.Warn("MatchAndApplyRule() on " + patch[i].Mui + " failed"); + } + else { - x86List.Add(patch[i].HardlinkTarget); + fileList.Add(patch[i].HardlinkTarget); + if (!string.IsNullOrWhiteSpace(patch[i].x86)) + { + x86List.Add(patch[i].HardlinkTarget); + } } + progress++; } - progress++; } } - } - Logger.WriteLine("MatchAndApplyRule() succeeded"); + Logger.WriteLine("MatchAndApplyRule() succeeded"); - if (!WritePendingFiles(fileList, x86List)) - { - Logger.WriteLine("WritePendingFiles() failed"); - return false; - } - Logger.WriteLine("WritePendingFiles() succeeded"); - - if (!Common.WriteFiles(true, false)) - { - Logger.WriteLine("WriteFiles() failed"); - return false; - } - Logger.WriteLine("WriteFiles() succeeded"); + if (!WritePendingFiles(fileList, x86List)) + return false; - frm.InstallerProgress = "Replacing files"; + if (!Common.WriteFiles(true, false)) + return false; - // runs only if SSText3D.scr is selected - if (InstallOptions.iconsList.Contains("SSText3D.scr")) - { - Interaction.Shell(Path.Combine(Variables.sys32Folder, "reg.exe") + " import " + Path.Combine(Variables.r11Files, "screensaver.reg"), AppWinStyle.Hide); - Logger.WriteLine("screensaver.reg succeeded"); - } + frm.InstallerProgress = "Replacing files"; - // runs only if any one of mmcbase.dll.mun, mmc.exe.mui or mmcndmgr.dll.mun is selected - if (InstallOptions.iconsList.Contains("mmcbase.dll.mun") - || InstallOptions.iconsList.Contains("mmc.exe.mui") - || InstallOptions.iconsList.Contains("mmcndmgr.dll.mun")) - { - if (!MMCHelper.PatchAll()) + // runs only if SSText3D.scr is selected + if (InstallOptions.iconsList.Contains("SSText3D.scr")) { - Logger.WriteLine("MmcHelper.PatchAll() failed"); - return false; + Helper.ImportReg(Path.Combine(Variables.r11Files, "screensaver.reg")); } - Logger.WriteLine("MmcHelper.PatchAll() succeeded"); - } - if (InstallOptions.iconsList.Contains("odbcad32.exe")) - { - if (!FixOdbc()) - { - Logger.Warn("FixOdbc() failed"); - } - else + // runs only if any one of mmcbase.dll.mun, mmc.exe.mui or mmcndmgr.dll.mun is selected + if (InstallOptions.iconsList.Contains("mmcbase.dll.mun") + || InstallOptions.iconsList.Contains("mmc.exe.mui") + || InstallOptions.iconsList.Contains("mmcndmgr.dll.mun")) { - Logger.WriteLine("FixOdbc() succeeded"); + if (!MMCHelper.PatchAll()) + return false; } - } - // phase 2 - Helper.RunAsTI(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe"), "/install"); - // reg files for various file extensions - Interaction.Shell(Path.Combine(Variables.sys32Folder, "reg.exe") + " import " + Path.Combine(Variables.r11Files, "icons.reg"), AppWinStyle.Hide); - Logger.WriteLine("icons.reg succeeded"); + if (InstallOptions.iconsList.Contains("odbcad32.exe")) + FixOdbc(); - Variables.RestartRequired = true; - return true; + // phase 2 + Helper.RunAsTI(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe"), "/install"); + + // reg files for various file extensions + Helper.ImportReg(Path.Combine(Variables.r11Files, "icons.reg")); + + Variables.RestartRequired = true; + return true; + } + catch (Exception ex) + { + // rollback + // ikr amazing + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "Tmp"), false); + Logger.WriteLine("Icons.Install() failed", ex); + return false; + } } + /// + /// icon uninstallation logic + /// + /// true if succeeds, else returns false public static bool Uninstall() { - Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe"), Properties.Resources.Rectify11Phase2, Helper.OperationType.Write); - Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "aRun.exe"), Properties.Resources.AdvancedRun, Helper.OperationType.Write); try { + Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe"), Properties.Resources.Rectify11Phase2, Helper.OperationType.Write); + Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "aRun.exe"), Properties.Resources.AdvancedRun, Helper.OperationType.Write); Registry.LocalMachine.OpenSubKey(@"SOFTWARE", true) ?.CreateSubKey("Rectify11", true) ?.SetValue("UninstallFiles", UninstallOptions.uninstIconsList.ToArray()); @@ -147,15 +140,16 @@ public static bool Uninstall() Logger.WriteLine("Executed Rectify11.Phase2.exe"); Helper.RunAsTI(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe"), "/uninstall"); } + + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "aRun.exe")); + return true; } - catch + catch (Exception ex) { + Logger.WriteLine("Icons.Uninstall() failed", ex); return false; } - - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe")); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "aRun.exe")); - return true; } /// @@ -163,18 +157,20 @@ public static bool Uninstall() /// private static bool FixOdbc() { - var filename = string.Empty; - var admintools = Path.Combine(GetFolderPath(SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "Administrative Tools"); - var files = Directory.GetFiles(admintools); - for (var i = 0; i < files.Length; i++) - { - if (!Path.GetFileName(files[i]).Contains("ODBC") || - !Path.GetFileName(files[i])!.Contains("32")) continue; - filename = Path.GetFileName(files[i]); - File.Delete(files[i]); - } try { + var filename = string.Empty; + var admintools = Path.Combine(GetFolderPath(SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "Administrative Tools"); + if (!Directory.Exists(admintools)) return false; + + var files = Directory.GetFiles(admintools); + for (var i = 0; i < files.Length; i++) + { + if (!Path.GetFileName(files[i]).Contains("ODBC") || + !Path.GetFileName(files[i])!.Contains("32")) continue; + filename = Path.GetFileName(files[i]); + File.Delete(files[i]); + } using ShellLink shortcut = new(); shortcut.Target = Path.Combine(Variables.sysWOWFolder, "odbcad32.exe"); shortcut.WorkingDirectory = @"%windir%\system32"; @@ -182,12 +178,15 @@ private static bool FixOdbc() shortcut.IconIndex = 0; shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; if (filename != null) shortcut.Save(Path.Combine(admintools, filename)); + + Logger.WriteLine("FixOdbc() succeeded"); + return true; } - catch + catch (Exception ex) { + Logger.Warn("FixOdbc() failed", ex); return false; } - return true; } @@ -212,12 +211,15 @@ private static bool WritePendingFiles(List fileList, List x86Lis using var ubrReg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false); string build = OSVersion.Version.Major + "." + OSVersion.Version.Minor + "." + OSVersion.Version.Build + "." + ubrReg.GetValue("UBR").ToString(); SafeWriteReg(reg, "OSVersion", build, false); + + Logger.WriteLine("WritePendingFiles() succeeded."); + return true; } - catch + catch (Exception ex) { + Logger.WriteLine("WritePendingFiles() failed", ex); return false; } - return true; } /// @@ -273,7 +275,7 @@ private static bool Patch(string file, PatchesPatch patch, PatchType type) if (patch.mask.Contains("|")) { - if (!string.IsNullOrWhiteSpace(patch.Ignore) + if (!string.IsNullOrWhiteSpace(patch.Ignore) && ((!string.IsNullOrWhiteSpace(patch.MinVersion) && OSVersion.Version.Build <= int.Parse(patch.MinVersion)) || (!string.IsNullOrWhiteSpace(patch.MaxVersion) && OSVersion.Version.Build >= int.Parse(patch.MaxVersion)))) { masks = masks.Replace(patch.Ignore, ""); diff --git a/Rectify11Installer/Core/Backend/Installer.cs b/Rectify11Installer/Core/Backend/Installer.cs index 6e1d2ab53..9ffb2ec6b 100644 --- a/Rectify11Installer/Core/Backend/Installer.cs +++ b/Rectify11Installer/Core/Backend/Installer.cs @@ -23,22 +23,13 @@ public bool Install(FrmWizard frm) ?.DeleteValue("x86PendingFiles", false); if (!Common.WriteFiles(false, false)) - { - Logger.WriteLine("WriteFiles() failed."); return false; - } - Logger.WriteLine("WriteFiles() succeeded."); if (!Common.CreateDirs()) - { - Logger.WriteLine("CreateDirs() failed."); return false; - } - Logger.WriteLine("CreateDirs() succeeded."); try { - // create restore point frm.InstallerProgress = "Begin creating a restore point"; CreateSystemRestorePoint(false); } @@ -49,11 +40,7 @@ public bool Install(FrmWizard frm) // runtimes frm.InstallerProgress = "Installing runtimes"; - if (!Common.InstallRuntimes()) - { - Logger.WriteLine("InstallRuntimes() failed."); - return false; - } + Common.InstallRuntimes(); if (Variables.vcRedist && Variables.core31) { Logger.WriteLine("InstallRuntimes() succeeded."); @@ -95,19 +82,13 @@ public bool Install(FrmWizard frm) } frm.InstallerProgress = "Creating uninstaller"; - if (!Common.CreateUninstall()) - { - Logger.WriteLine("CreateUninstall() failed"); - return false; - } - Logger.WriteLine("CreateUninstall() succeeded"); + Common.CreateUninstall(); InstallStatus.IsRectify11Installed = true; Logger.WriteLine("══════════════════════════════════════════════"); try { - // create restore point frm.InstallerProgress = "End creating a restore point"; CreateSystemRestorePoint(true); } diff --git a/Rectify11Installer/Core/Backend/MMCHelper.cs b/Rectify11Installer/Core/Backend/MMCHelper.cs index c9e9f56ae..70f15ab5a 100644 --- a/Rectify11Installer/Core/Backend/MMCHelper.cs +++ b/Rectify11Installer/Core/Backend/MMCHelper.cs @@ -1,6 +1,6 @@ #nullable enable +using System; using System.Collections.Generic; -using System.Diagnostics; using System.Globalization; using System.IO; using System.Xml; @@ -17,39 +17,49 @@ internal class MMCHelper #region Public Methods public static bool PatchAll() { - var langFolder = Path.Combine(Variables.sys32Folder, CultureInfo.CurrentUICulture.Name); - var usaFolder = Path.Combine(Variables.sys32Folder, "en-US"); - List langMsc = new(Directory.GetFiles(langFolder, "*.msc", SearchOption.TopDirectoryOnly)); - List usaMsc = new(Directory.GetFiles(usaFolder, "*.msc", SearchOption.TopDirectoryOnly)); - List r11Msc = new(Directory.GetFiles(Path.Combine(Variables.r11Files, "mmc"), "*.msc", SearchOption.TopDirectoryOnly)); - CopyFiles(langMsc, usaMsc, r11Msc); + try + { + var langFolder = Path.Combine(Variables.sys32Folder, CultureInfo.CurrentUICulture.Name); + var usaFolder = Path.Combine(Variables.sys32Folder, "en-US"); + List langMsc = new(Directory.GetFiles(langFolder, "*.msc", SearchOption.TopDirectoryOnly)); + List usaMsc = new(Directory.GetFiles(usaFolder, "*.msc", SearchOption.TopDirectoryOnly)); + List r11Msc = new(Directory.GetFiles(Path.Combine(Variables.r11Files, "mmc"), "*.msc", SearchOption.TopDirectoryOnly)); + CopyFiles(langMsc, usaMsc, r11Msc); - // exit if current language is en-us - if (CultureInfo.CurrentUICulture.Name == "en-US") return true; + // exit if current language is en-us + if (CultureInfo.CurrentUICulture.Name == "en-US") return true; - List r11LangMsc = new(Directory.GetFiles(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name), "*.msc", SearchOption.TopDirectoryOnly)); - List sysMsc = new(Directory.GetFiles(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name, "temp"), "*.msc", SearchOption.TopDirectoryOnly)); - for (var i = 0; i < r11LangMsc.Count; i++) - { - for (var j = 0; j < sysMsc.Count; j++) + List r11LangMsc = new(Directory.GetFiles(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name), "*.msc", SearchOption.TopDirectoryOnly)); + List sysMsc = new(Directory.GetFiles(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name, "temp"), "*.msc", SearchOption.TopDirectoryOnly)); + for (var i = 0; i < r11LangMsc.Count; i++) { - if (Path.GetFileName(r11LangMsc[i]) == Path.GetFileName(sysMsc[j])) + for (var j = 0; j < sysMsc.Count; j++) { - ReplaceString(r11LangMsc[i], sysMsc[j]); + if (Path.GetFileName(r11LangMsc[i]) == Path.GetFileName(sysMsc[j])) + { + ReplaceString(r11LangMsc[i], sysMsc[j]); + } } } - } - Helper.SafeDirectoryDeletion(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name, "temp"), false); - var msc = Path.Combine(tempDir, "msc"); - if (CultureInfo.CurrentUICulture.Name != "en-US") - { - File.Copy(Path.Combine(msc, "lusrmgr.msc"), Path.Combine(msc, CultureInfo.CurrentUICulture.Name, "lusrmgr.msc"), true); - File.Copy(Path.Combine(msc, "taskschd.msc"), Path.Combine(msc, CultureInfo.CurrentUICulture.Name, "taskschd.msc"), true); - File.Copy(Path.Combine(msc, "WmiMgmt.msc"), Path.Combine(msc, CultureInfo.CurrentUICulture.Name, "WmiMgmt.msc"), true); + Helper.SafeDirectoryDeletion(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name, "temp"), false); + var msc = Path.Combine(tempDir, "msc"); + if (CultureInfo.CurrentUICulture.Name != "en-US") + { + File.Copy(Path.Combine(msc, "lusrmgr.msc"), Path.Combine(msc, CultureInfo.CurrentUICulture.Name, "lusrmgr.msc"), true); + File.Copy(Path.Combine(msc, "taskschd.msc"), Path.Combine(msc, CultureInfo.CurrentUICulture.Name, "taskschd.msc"), true); + File.Copy(Path.Combine(msc, "WmiMgmt.msc"), Path.Combine(msc, CultureInfo.CurrentUICulture.Name, "WmiMgmt.msc"), true); + } + + Logger.WriteLine("MmcHelper.PatchAll() succeeded"); + return true; } - return true; - } + catch (Exception ex) + { + Logger.WriteLine("MmcHelper.PatchAll() failed", ex); + return false; + } + } #endregion #region Private Methods private static void ReplaceString(string file, string r11file) diff --git a/Rectify11Installer/Core/Backend/Themes.cs b/Rectify11Installer/Core/Backend/Themes.cs index ed07adf77..988a1d9fe 100644 --- a/Rectify11Installer/Core/Backend/Themes.cs +++ b/Rectify11Installer/Core/Backend/Themes.cs @@ -5,127 +5,145 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Runtime.InteropServices.WindowsRuntime; using static Rectify11Installer.Win32.NativeMethods; namespace Rectify11Installer.Core { internal class Themes { + /// + /// themes installation logic + /// + /// true if succeeds, else returns false public static bool Install() { - Logger.WriteLine("Installing Themes"); - Logger.WriteLine("─────────────────"); - if (!Common.WriteFiles(false, true)) + try { - Logger.WriteLine("WriteFiles() failed."); - return false; - } - Logger.WriteLine("WriteFiles() succeeded."); + Logger.WriteLine("Installing Themes"); + Logger.WriteLine("─────────────────"); + if (!Common.WriteFiles(false, true)) + return false; - if (Directory.Exists(Path.Combine(Variables.r11Folder, "themes"))) - { - Logger.WriteLine(Path.Combine(Variables.r11Folder, "themes") + " exists. Deleting it."); - if (!Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "themes"), false)) + if (Directory.Exists(Path.Combine(Variables.r11Folder, "themes"))) { - Logger.WriteLine("Deleting " + Path.Combine(Variables.r11Folder, "themes") + " failed. "); - return false; + Logger.WriteLine(Path.Combine(Variables.r11Folder, "themes") + " exists. Deleting it."); + if (!Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "themes"), false)) + { + return false; + } } - } - // extract the 7z - Helper.SvExtract("themes.7z", "themes"); + // extract the 7z + Helper.SvExtract("themes.7z", "themes"); - Logger.WriteLine("Extracted themes.7z"); - if (!InstallThemes()) - { - Logger.WriteLine("InstallThemes() failed."); - return false; - } - try - { - if (!InstallOptions.SkipMFE) + if (!InstallThemes()) + return false; + + try { + if (!InstallOptions.SkipMFE) + { + InstallMfe(); + Logger.WriteLine("InstallMfe() succeeded."); + } + } + catch (Exception ex) + { + Logger.Warn("InstallMfe() failed", ex); + } - InstallMfe(); - Logger.WriteLine("InstallMfe() succeeded."); + try + { + Installr11cpl(); + Logger.WriteLine("Installr11cpl() succeeded."); } + catch (Exception ex) + { + Logger.Warn("Installr11cpl() failed", ex); + } + Variables.RestartRequired = true; + Logger.WriteLine("InstallThemes() succeeded."); + Logger.WriteLine("══════════════════════════════════════════════"); + return true; } - catch - { - Logger.WriteLine("InstallMfe() failed."); - } - try - { - Installr11cpl(); - Logger.WriteLine("Installr11cpl() succeeded."); - } - catch + catch (Exception ex) { - Logger.WriteLine("Installr11cpl() failed."); + Logger.WriteLine("Themes.Install() failed", ex); + return false; } - Variables.RestartRequired = true; - Logger.WriteLine("InstallThemes() succeeded."); - Logger.WriteLine("══════════════════════════════════════════════"); - return true; } + + /// + /// themes uninstallation logic + /// + /// true if succeeds, else returns false public static bool Uninstall() { - var s = IsArm64() ? Properties.Resources.secureux_arm64 : Properties.Resources.secureux_x64; - var dll = IsArm64() ? Properties.Resources.ThemeDll_arm64 : Properties.Resources.ThemeDll_x64; + try + { + var s = IsArm64() ? Properties.Resources.secureux_arm64 : Properties.Resources.secureux_x64; + var dll = IsArm64() ? Properties.Resources.ThemeDll_arm64 : Properties.Resources.ThemeDll_x64; - if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe"), s, Helper.OperationType.Write)) - return false; - if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "ThemeDll.dll"), dll, Helper.OperationType.Write)) - return false; + if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe"), s, Helper.OperationType.Write)) + return false; + if (!Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "ThemeDll.dll"), dll, Helper.OperationType.Write)) + return false; - string mode = Theme.IsUsingDarkMode ? "dark.theme" : "aero.theme"; - Process.Start(Path.Combine(Variables.Windir, "Resources", "Themes", mode)); - string theme = Theme.IsUsingDarkMode ? "Windows (dark)" : "Windows (light)"; - Interaction.Shell(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " apply " + '"' + theme + '"', AppWinStyle.Hide, true); + string mode = Theme.IsUsingDarkMode ? "dark.theme" : "aero.theme"; + Process.Start(Path.Combine(Variables.Windir, "Resources", "Themes", mode)); + string theme = Theme.IsUsingDarkMode ? "Windows (dark)" : "Windows (light)"; + Interaction.Shell(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " apply " + '"' + theme + '"', AppWinStyle.Hide, true); - UninstallThemeWallpapers(); + UninstallThemeWallpapers(); - Interaction.Shell(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " uninstall", AppWinStyle.Hide, true); - Helper.SafeFileDeletion(Path.Combine(Variables.Windir, "Themetool.exe")); - Logger.WriteLine("Deleted " + Path.Combine(Variables.Windir, "Themetool.exe")); + Interaction.Shell(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " uninstall", AppWinStyle.Hide, true); + Helper.SafeFileDeletion(Path.Combine(Variables.Windir, "Themetool.exe")); - UninstallCursors(); + UninstallCursors(); - UninstallMsstyles(); + UninstallMsstyles(); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe")); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "ThemeDll.dll")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "ThemeDll.dll")); - UninstallMfe(); + UninstallMfe(); - try - { - var key = Registry.ClassesRoot.OpenSubKey(@"CLSID", true); - key.DeleteSubKeyTree("{959E11F4-0A48-49cf-8416-FF9BC49D9656}", false); - key.Dispose(); - key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace", true); - key.DeleteSubKeyTree("{959E11F4-0A48-49cf-8416-FF9BC49D9656}", false); - key.Dispose(); - key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes", true); - key.SetValue("MS Shell Dlg 2", "Tahoma"); - key.SetValue("MS Shell Dlg", "Microsoft Sans Serif"); - key.Dispose(); - key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop\WindowMetrics", true); - key.SetValue("MenuHeight", "-285"); - key.SetValue("MenuWidth", "-285"); - key.Dispose(); - Logger.WriteLine("Remove registry entries"); - } - catch { } + try + { + var key = Registry.ClassesRoot.OpenSubKey(@"CLSID", true); + key.DeleteSubKeyTree("{959E11F4-0A48-49cf-8416-FF9BC49D9656}", false); + key.Dispose(); + key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace", true); + key.DeleteSubKeyTree("{959E11F4-0A48-49cf-8416-FF9BC49D9656}", false); + key.Dispose(); + key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes", true); + key.SetValue("MS Shell Dlg 2", "Tahoma"); + key.SetValue("MS Shell Dlg", "Microsoft Sans Serif"); + key.Dispose(); + key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop\WindowMetrics", true); + key.SetValue("MenuHeight", "-285"); + key.SetValue("MenuWidth", "-285"); + key.Dispose(); + Logger.WriteLine("Remove registry entries"); + } + catch { } - // nuke r11cp - Helper.SafeFileDeletion(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "Rectify11 Control Center.lnk")); - Helper.SafeFileDeletion(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Rectify11 Control Center.lnk")); - Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "Rectify11ControlCenter"), false); + // nuke r11cp + Helper.SafeFileDeletion(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "Rectify11 Control Center.lnk")); + Helper.SafeFileDeletion(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Rectify11 Control Center.lnk")); + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "Rectify11ControlCenter"), false); + Logger.WriteLine("Deleted Rectify11 Control Center"); - Logger.WriteLine("Deleted Rectify11 Control Center"); - return true; + Logger.WriteLine("Uninstall() succeeded"); + return true; + } + catch (Exception ex) + { + Logger.WriteLine("Themes.Uninstall() failed", ex); + return false; + } } /// @@ -133,17 +151,33 @@ public static bool Uninstall() /// private static bool InstallThemes() { - InstallThemeWallpapers(); + try + { + InstallThemeWallpapers(); - // todo: remove r11cp - File.Copy(Path.Combine(Variables.r11Folder, "themes", "ThemeTool.exe"), Path.Combine(Variables.Windir, "ThemeTool.exe"), true); - Logger.WriteLine("Copied Themetool."); - Interaction.Shell(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " install", AppWinStyle.Hide, true); - Interaction.Shell(Path.Combine(Variables.sys32Folder, "reg.exe") + " import " + Path.Combine(Variables.r11Folder, "themes", "Themes.reg"), AppWinStyle.Hide, true); + Helper.SafeFileOperation( + Path.Combine(Variables.r11Folder, "themes", "ThemeTool.exe"), + Path.Combine(Variables.Windir, "ThemeTool.exe"), + Helper.OperationType.Copy); - InstallCursors(); - InstallMsstyles(); - return true; + Logger.WriteLine("Copied Themetool."); + Interaction.Shell(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " install", AppWinStyle.Hide, true); + Helper.ImportReg(Path.Combine(Variables.r11Folder, "themes", "Themes.reg")); + + InstallCursors(); + InstallMsstyles(); + return true; + } + catch (Exception ex) + { + Logger.WriteLine("InstallThemes() failed", ex); + UninstallThemeWallpapers(); + UninstallCursors(); + UninstallMsstyles(); + Helper.SafeFileDeletion(Path.Combine(Variables.Windir, "ThemeTool.exe")); + Interaction.Shell(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " uninstall", AppWinStyle.Hide, true); + return false; + } } @@ -161,7 +195,10 @@ private static void Installr11cpl() shortcut.IconPath = Path.Combine(Variables.r11Folder, "Rectify11ControlCenter", "Rectify11ControlCenter.exe"); shortcut.IconIndex = 0; shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; - shortcut.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "Rectify11 Control Center.lnk")); + string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "Rectify11 Control Center.lnk"); + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + shortcut.Save(path); shortcut.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Rectify11 Control Center.lnk")); shortcut.Dispose(); } @@ -267,7 +304,7 @@ private static bool InstallCursors() } catch (Exception ex) { - Logger.WriteLine("Error copying " + curdir[i].Name + ". " + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine); + Logger.WriteLine("Error copying " + curdir[i].Name, ex); return false; } } @@ -348,7 +385,7 @@ private static bool InstallMsstyles() } catch (Exception ex) { - Logger.WriteLine("Error copying " + msstyleDirList[i].Name + ". " + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine); + Logger.WriteLine("Error copying " + msstyleDirList[i].Name, ex); return false; } } diff --git a/Rectify11Installer/Core/Backend/Uninstaller.cs b/Rectify11Installer/Core/Backend/Uninstaller.cs index a019321f2..38d81c8de 100644 --- a/Rectify11Installer/Core/Backend/Uninstaller.cs +++ b/Rectify11Installer/Core/Backend/Uninstaller.cs @@ -13,7 +13,7 @@ public bool Uninstall(FrmWizard frm) Logger.WriteLine("Uninstalling icons"); Logger.WriteLine("──────────────────"); frm.InstallerProgress = "Uninstalling icons"; - Icons.Uninstall(); + if (!Icons.Uninstall()) return false; Variables.RestartRequired = true; Console.WriteLine("══════════════════════════════════════════════"); } @@ -22,7 +22,7 @@ public bool Uninstall(FrmWizard frm) Logger.WriteLine("Uninstalling themes"); Logger.WriteLine("───────────────────"); frm.InstallerProgress = "Uninstalling themes"; - Themes.Uninstall(); + if (!Themes.Uninstall()) return false; Variables.RestartRequired = true; Console.WriteLine("══════════════════════════════════════════════"); } @@ -31,7 +31,7 @@ public bool Uninstall(FrmWizard frm) Logger.WriteLine("Uninstalling extras"); Logger.WriteLine("───────────────────"); frm.InstallerProgress = "Uninstalling Extras"; - Extras.Uninstall(); + if (!Extras.Uninstall()) return false; Console.WriteLine("══════════════════════════════════════════════"); } // cleanup diff --git a/Rectify11Installer/Core/Helpers.cs b/Rectify11Installer/Core/Helpers.cs index c3b1a038f..f366cdb3b 100644 --- a/Rectify11Installer/Core/Helpers.cs +++ b/Rectify11Installer/Core/Helpers.cs @@ -30,10 +30,19 @@ public static bool CheckIfUpdatesPending() } public static bool SvExtract(string file, string path) { - Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") + - " x -o" + Path.Combine(Variables.r11Folder, path) + - " " + Path.Combine(Variables.r11Folder, file), AppWinStyle.Hide, true); - return true; + try + { + Interaction.Shell(Path.Combine(Variables.r11Folder, "7za.exe") + + " x -o" + Path.Combine(Variables.r11Folder, path) + + " " + Path.Combine(Variables.r11Folder, file), AppWinStyle.Hide, true); + Logger.WriteLine("Extracted files.7z"); + return true; + } + catch (Exception ex) + { + Logger.WriteLine("Error extracting files.7z", ex); + return false; + } } public static bool SvExtract(string file, string path, string folder) @@ -218,6 +227,18 @@ public static void DeleteTask(string name) Interaction.Shell(Path.Combine(Variables.sys32Folder, "schtasks.exe") + " /end /tn " + name, AppWinStyle.Hide, true); Interaction.Shell(Path.Combine(Variables.sys32Folder, "schtasks.exe") + " /delete /f /tn " + name, AppWinStyle.Hide, true); } + public static void ImportReg(string path) + { + try + { + Interaction.Shell(Path.Combine(Variables.sys32Folder, "reg.exe") + " import " + path, AppWinStyle.Hide); + Logger.WriteLine(Path.GetFileName(path) + " succeeded."); + } + catch (Exception ex) + { + Logger.Warn(Path.GetFileName(path) + " failed.", ex); + } + } public enum OperationType { @@ -328,8 +349,9 @@ public static bool SafeDirectoryDeletion(string path, bool ischild) } return true; } - catch + catch (Exception ex) { + Logger.WriteLine("Deleting " + path + " failed", ex); return false; } } diff --git a/Rectify11Installer/Pages/ProgressPage.cs b/Rectify11Installer/Pages/ProgressPage.cs index aa200a214..fd58a2fd3 100644 --- a/Rectify11Installer/Pages/ProgressPage.cs +++ b/Rectify11Installer/Pages/ProgressPage.cs @@ -96,7 +96,17 @@ private async void NavigationHelper_OnNavigate(object sender, EventArgs e) RectifyPages.ProgressPage.Start(); NativeMethods.SetCloseButton(frmwiz, false); Uninstaller uninstaller = new(); - await Task.Run(() => uninstaller.Uninstall(frmwiz)); + if (!await Task.Run(() => uninstaller.Uninstall(frmwiz))) + { + Common.Cleanup(); + Logger.CommitLog(); + TaskDialog.Show(text: "Rectify11 setup encountered an error, for more information, see the log in " + Path.Combine(Variables.r11Folder, "installer.log") + ", and report it to rectify11 development server", + title: "Error", + buttons: TaskDialogButtons.OK, + icon: TaskDialogStandardIcon.Error); + Application.Exit(); + } + if (Variables.RestartRequired) { NativeMethods.SetCloseButton(frmwiz, false);