diff --git a/Rectify11Installer/Core/Backend/Themes.cs b/Rectify11Installer/Core/Backend/Themes.cs index a5ef329da..d425a256d 100644 --- a/Rectify11Installer/Core/Backend/Themes.cs +++ b/Rectify11Installer/Core/Backend/Themes.cs @@ -5,462 +5,460 @@ 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() - { - try - { - 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)) - { - return false; - } - } - - // extract the 7z - Helper.SvExtract("themes.7z", "themes"); - - if (!InstallThemes()) - return false; - - try - { - if (!InstallOptions.SkipMFE) - { - InstallMfe(); - Logger.WriteLine("InstallMfe() succeeded."); - } - } - catch (Exception ex) - { - Logger.Warn("InstallMfe() failed", ex); - } - - try - { - InstallR11Cpl(); - Logger.WriteLine("Installr11cpl() succeeded."); - } - catch (Exception ex) - { - Logger.Warn("Installr11cpl() failed", ex); - } - Variables.RestartRequired = true; - Logger.WriteLine("Themes.Install() succeeded."); - Logger.WriteLine("══════════════════════════════════════════════"); - return true; - } - catch (Exception ex) - { - Logger.WriteLine("Themes.Install() failed", ex); - return false; - } - } - - /// - /// themes uninstallation logic - /// - /// true if succeeds, else returns false - public static bool Uninstall() - { - 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; - - string mode = Theme.IsUsingDarkMode ? "dark.theme" : "aero.theme"; - if (File.Exists(Path.Combine(Variables.Windir, "Resources", "Themes", mode))) - 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(); - - Interaction.Shell(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " uninstall", AppWinStyle.Hide, true); - Helper.SafeFileDeletion(Path.Combine(Variables.Windir, "Themetool.exe")); - - UninstallCursors(); - - UninstallMsstyles(); - - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe")); - Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "ThemeDll.dll")); - - 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("Removed registry entries."); - } - catch { } - - UninstallR11Cpl(); - Logger.WriteLine("Deleted Rectify11 Control Center."); - - Logger.WriteLine("Themes.Uninstall() succeeded."); - Logger.WriteLine("══════════════════════════════════════════════"); - return true; - } - catch (Exception ex) - { - Logger.WriteLine("Themes.Uninstall() failed", ex); - return false; - } - } - - /// - /// installs themes - /// - private static bool InstallThemes() - { - try - { - InstallThemeWallpapers(); - - Helper.SafeFileOperation( - Path.Combine(Variables.r11Folder, "themes", "ThemeTool.exe"), - Path.Combine(Variables.Windir, "ThemeTool.exe"), - Helper.OperationType.Copy); - - 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; - } - } - - - /// - /// installs control center - /// - private static void InstallR11Cpl() - { - UninstallR11Cpl(); - string cplPath = Path.Combine(Variables.r11Folder, "Rectify11CPL", "Rectify11CPL.dll"); - - //create files - Directory.CreateDirectory(Path.Combine(Variables.r11Folder, "Rectify11CPL")); - - File.WriteAllBytes(cplPath, Properties.Resources.Rectify11CPL); - - // create shortcut - using ShellLink shortcut = new(); - shortcut.Target = "control.exe /name Rectify11.SettingsCPL"; - shortcut.IconPath = Path.Combine(Variables.r11Folder, "Rectify11CPL", "Rectify11CPL.dll"); - shortcut.IconIndex = 0; - shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; - - string startmenu = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "Rectify11 Control Center.lnk"); - Directory.CreateDirectory(startmenu); - try - { - shortcut.Save(startmenu); - } - catch (Exception ex) - { - Logger.Warn("Error while saving shortcut: " + ex); - } - shortcut.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Rectify11 Control Center.lnk")); - - shortcut.Dispose(); - - // register CPL - var proc = new Process(); - proc.StartInfo.FileName = "regsvr32.exe"; - proc.StartInfo.Arguments = "/s \"" + cplPath + "\""; - proc.Start(); - proc.WaitForExit(); - - if (proc.ExitCode != 0) - { - Logger.WriteLine("Error while registering CPL: " + proc.ExitCode); - } - } - /// - /// uninstalls control center - /// - private static void UninstallR11Cpl() - { - string cplPath = Path.Combine(Variables.r11Folder, "Rectify11CPL", "Rectify11CPL.dll"); - string startmenuShortcut = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "Rectify11 Control Center.lnk"); - string desktopShortcut = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Rectify11 Control Center.lnk"); - - // delete shortcut - Helper.SafeFileDeletion(startmenuShortcut); - Helper.SafeFileDeletion(desktopShortcut); - - if (!File.Exists(cplPath)) return; - - // unregister CPL - var proc = new Process(); - proc.StartInfo.FileName = "regsvr32.exe"; - proc.StartInfo.Arguments = "/s /u \"" + cplPath + "\""; - proc.Start(); - proc.WaitForExit(); - - if (proc.ExitCode != 0) - { - Logger.Warn("Error while unregistering CPL: " + proc.ExitCode); - } - - //delete folder - Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "Rectify11CPL"), false); - } - - /// - /// installs mfe - /// - private static void InstallMfe() - { - UninstallMfe(); - Directory.Move(Path.Combine(Variables.r11Folder, "Themes", "MicaForEveryone"), Path.Combine(Variables.Windir, "MicaForEveryone")); - Interaction.Shell(Path.Combine(Variables.sys32Folder, "schtasks.exe") + " /create /tn mfe /xml " + Path.Combine(Variables.Windir, "MicaForEveryone", "XML", "mfe.xml"), AppWinStyle.Hide, true); - - string path = Path.Combine(Environment.GetEnvironmentVariable("localappdata"), "Mica For Everyone"); - Helper.SafeDirectoryDeletion(path, false); - string t = InstallOptions.TabbedNotMica ? "T" : ""; - string val = ""; - if (InstallOptions.ThemeLight) val = t + "lightrectified.conf"; - else if (InstallOptions.ThemeDark) val = t + "darkrectified.conf"; - else if (InstallOptions.ThemeBlack) - { - val = t + "black.conf"; - string amdorarm = NativeMethods.IsArm64() ? "ARM" : "AMD"; - Interaction.Shell(Path.Combine(Variables.sys32Folder, "schtasks.exe") + " /create /tn micafix /xml " + Path.Combine(Variables.Windir, "MicaForEveryone", "XML", "micafix" + amdorarm + "64.xml"), AppWinStyle.Hide, true); - } - - if (!string.IsNullOrWhiteSpace(val)) - { - File.Copy(Path.Combine(Variables.Windir, "MicaForEveryone", "CONF", val), - Path.Combine(Variables.Windir, "MicaForEveryone", "MicaForEveryone.conf"), true); - } - } - - #region Internal - private static bool InstallThemeWallpapers() - { - UninstallThemeWallpapers(); - Directory.CreateDirectory(Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified")); - try - { - var files = Directory.GetFiles(Path.Combine(Variables.r11Folder, "themes", "wallpapers")); - for (int j = 0; j < files.Length; j++) - { - File.Copy(files[j], Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified", Path.GetFileName(files[j])), true); - } - Logger.WriteLine("Copied wallpapers to " + Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified")); - } - catch (Exception ex) - { - Logger.WriteLine("Error copying wallpapers", ex); - } - return true; - } - private static bool UninstallThemeWallpapers() - { - if (Directory.Exists(Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified"))) - { - try - { - List wallpapers = new() - { - "cosmic.png", - "img0.png", - "img19.png", - "metal.png" - }; - string path = Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified"); - var files = Directory.GetFiles(path); - for (int j = 0; j < files.Length; j++) - { - if (!wallpapers.Contains(Path.GetFileName(files[j]))) - Helper.SafeFileDeletion(files[j]); - } - if (Directory.GetFiles(path).Length == 0) - { - Helper.SafeDirectoryDeletion(path, false); - Logger.WriteLine("Deleted " + path); - } - Logger.WriteLine("Deleted old wallpapers."); - } - catch (Exception ex) - { - Logger.WriteLine("Error deleting old wallpapers", ex); - } - } - return true; - } - private static bool InstallCursors() - { - UninstallCursors(); - var curdir = new DirectoryInfo(Path.Combine(Variables.r11Folder, "themes", "cursors")) - .GetDirectories("*", SearchOption.TopDirectoryOnly); - - for (var i = 0; i < curdir.Length; i++) - { - try - { - Directory.Move(curdir[i].FullName, Path.Combine(Variables.Windir, "cursors", curdir[i].Name)); - Logger.WriteLine("Copied " + curdir[i].Name + " cursors"); - } - catch (Exception ex) - { - Logger.WriteLine("Error copying " + curdir[i].Name, ex); - return false; - } - } - return true; - } - private static bool UninstallCursors() - { - var dirs = Directory.GetDirectories(Path.Combine(Variables.Windir, "cursors"), "WindowsRectified*"); - for (int i = 0; i < dirs.Length; i++) - { - try - { - Helper.SafeDirectoryDeletion(dirs[i], false); - Logger.WriteLine("Deleted existing cursor directory " + dirs[i]); - } - catch - { - return false; - } - } - return true; - } - private static bool UninstallMsstyles() - { - // .theme files - List themefiles = new() - { - "black.theme", - "darkcolorized.theme", - "darkrectified.theme", - "lightrectified.theme" - }; - try - { - for (int i = 0; i < themefiles.Count; i++) - { - Helper.SafeFileDeletion(Path.Combine(Variables.Windir, "Resources", "Themes", themefiles[i])); - } - Logger.WriteLine("Deleted themes."); - } - catch (Exception ex) - { - Logger.WriteLine("Error deleting themes", ex); - } - - // msstyles - try - { - Helper.SafeDirectoryDeletion(Path.Combine(Variables.Windir, "Resources", "Themes", "Rectified"), false); - } - catch (Exception ex) - { - Logger.WriteLine("Error deleting " + Path.Combine(Variables.Windir, "Resources", "Themes", "Rectified"), ex); - return false; - } - return true; - } - private static bool InstallMsstyles() - { - UninstallMsstyles(); - DirectoryInfo themedir = new(Path.Combine(Variables.r11Folder, "themes", "themes")); - var msstyleDirList = themedir.GetDirectories("*", SearchOption.TopDirectoryOnly); - var themefiles = themedir.GetFiles("*.theme"); - - for (var i = 0; i < themefiles.Length; i++) - { - // why would it fail - File.Copy(themefiles[i].FullName, Path.Combine(Variables.Windir, "Resources", "Themes", themefiles[i].Name), true); - } - - File.WriteAllBytes(Path.Combine(Variables.r11Folder, "aRun1.exe"), Properties.Resources.AdvancedRun); - for (var i = 0; i < msstyleDirList.Length; i++) - { - try - { - Directory.Move(msstyleDirList[i].FullName, Path.Combine(Variables.Windir, "Resources", "Themes", msstyleDirList[i].Name)); - Logger.WriteLine("Copied " + msstyleDirList[i].Name + " directory."); - } - catch (Exception ex) - { - Logger.WriteLine("Error copying " + msstyleDirList[i].Name, ex); - return false; - } - } - File.Delete(Path.Combine(Variables.r11Folder, "aRun1.exe")); - return true; - } - private static bool UninstallMfe() - { - try - { - Helper.KillProcess("micaforeveryone.exe"); - Helper.KillProcess("micafix.exe"); - Helper.KillProcess("explorerframe.exe"); - Helper.DeleteTask("mfe"); - Helper.DeleteTask("micafix"); - if (!Helper.SafeDirectoryDeletion(Path.Combine(Variables.Windir, "MicaForEveryone"), false)) - { - Logger.WriteLine("Deleting " + Path.Combine(Variables.Windir, "MicaForEveryone") + " failed. "); - return false; - } - return true; - } - catch { return false; } - } - #endregion - } + internal class Themes + { + /// + /// themes installation logic + /// + /// true if succeeds, else returns false + public static bool Install() + { + try + { + 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)) + { + return false; + } + } + + // extract the 7z + Helper.SvExtract("themes.7z", "themes"); + + if (!InstallThemes()) + return false; + + try + { + if (!InstallOptions.SkipMFE) + { + InstallMfe(); + Logger.WriteLine("InstallMfe() succeeded."); + } + } + catch (Exception ex) + { + Logger.Warn("InstallMfe() failed", ex); + } + + try + { + InstallR11Cpl(); + Logger.WriteLine("Installr11cpl() succeeded."); + } + catch (Exception ex) + { + Logger.Warn("Installr11cpl() failed", ex); + } + Variables.RestartRequired = true; + Logger.WriteLine("Themes.Install() succeeded."); + Logger.WriteLine("══════════════════════════════════════════════"); + return true; + } + catch (Exception ex) + { + Logger.WriteLine("Themes.Install() failed", ex); + return false; + } + } + + /// + /// themes uninstallation logic + /// + /// true if succeeds, else returns false + public static bool Uninstall() + { + 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; + + string mode = Theme.IsUsingDarkMode ? "dark.theme" : "aero.theme"; + if (File.Exists(Path.Combine(Variables.Windir, "Resources", "Themes", mode))) + 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(); + + Interaction.Shell(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " uninstall", AppWinStyle.Hide, true); + Helper.SafeFileDeletion(Path.Combine(Variables.Windir, "Themetool.exe")); + + UninstallCursors(); + + UninstallMsstyles(); + + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "SecureUXHelper.exe")); + Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "ThemeDll.dll")); + + 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("Removed registry entries."); + } + catch { } + + UninstallR11Cpl(); + Logger.WriteLine("Deleted Rectify11 Control Center."); + + Logger.WriteLine("Themes.Uninstall() succeeded."); + Logger.WriteLine("══════════════════════════════════════════════"); + return true; + } + catch (Exception ex) + { + Logger.WriteLine("Themes.Uninstall() failed", ex); + return false; + } + } + + /// + /// installs themes + /// + private static bool InstallThemes() + { + try + { + InstallThemeWallpapers(); + + Helper.SafeFileOperation( + Path.Combine(Variables.r11Folder, "themes", "ThemeTool.exe"), + Path.Combine(Variables.Windir, "ThemeTool.exe"), + Helper.OperationType.Copy); + + 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; + } + } + + /// + /// installs control center + /// + public static void InstallR11Cpl() + { + UninstallR11Cpl(); + string cplPath = Path.Combine(Variables.r11Folder, "Rectify11CPL", "Rectify11CPL.dll"); + + //create files + Directory.CreateDirectory(Path.Combine(Variables.r11Folder, "Rectify11CPL")); + + File.WriteAllBytes(cplPath, Properties.Resources.Rectify11CPL); + + // create shortcut + using ShellLink shortcut = new(); + shortcut.Target = Path.Combine(Variables.sys32Folder, "control.exe"); + shortcut.Arguments = "/name Rectify11.SettingsCPL"; + shortcut.WorkingDirectory = @"%windir%\system32"; + shortcut.IconPath = Path.Combine(Variables.r11Folder, "Rectify11CPL", "Rectify11CPL.dll"); + shortcut.IconIndex = 0; + shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; + + string startmenu = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "Rectify11 Control Center.lnk"); + Directory.CreateDirectory(startmenu); + try + { + shortcut.Save(startmenu); + } + catch (Exception ex) + { + Logger.Warn("Error while saving shortcut: " + ex); + } + shortcut.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Rectify11 Control Center.lnk")); + + // register CPL + var proc = new Process(); + proc.StartInfo.FileName = "regsvr32.exe"; + proc.StartInfo.Arguments = "/s \"" + cplPath + "\""; + proc.Start(); + proc.WaitForExit(); + + if (proc.ExitCode != 0) + { + Logger.WriteLine("Error while registering CPL: " + proc.ExitCode); + } + } + /// + /// uninstalls control center + /// + private static void UninstallR11Cpl() + { + string cplPath = Path.Combine(Variables.r11Folder, "Rectify11CPL", "Rectify11CPL.dll"); + string startmenuShortcut = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "Rectify11 Control Center.lnk"); + string desktopShortcut = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Rectify11 Control Center.lnk"); + + // delete shortcut + Helper.SafeFileDeletion(startmenuShortcut); + Helper.SafeFileDeletion(desktopShortcut); + + if (!File.Exists(cplPath)) return; + + // unregister CPL + var proc = new Process(); + proc.StartInfo.FileName = "regsvr32.exe"; + proc.StartInfo.Arguments = "/s /u \"" + cplPath + "\""; + proc.Start(); + proc.WaitForExit(); + + if (proc.ExitCode != 0) + { + Logger.Warn("Error while unregistering CPL: " + proc.ExitCode); + } + + //delete folder + Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "Rectify11CPL"), false); + } + + /// + /// installs mfe + /// + private static void InstallMfe() + { + UninstallMfe(); + Directory.Move(Path.Combine(Variables.r11Folder, "Themes", "MicaForEveryone"), Path.Combine(Variables.Windir, "MicaForEveryone")); + Interaction.Shell(Path.Combine(Variables.sys32Folder, "schtasks.exe") + " /create /tn mfe /xml " + Path.Combine(Variables.Windir, "MicaForEveryone", "XML", "mfe.xml"), AppWinStyle.Hide, true); + + string path = Path.Combine(Environment.GetEnvironmentVariable("localappdata"), "Mica For Everyone"); + Helper.SafeDirectoryDeletion(path, false); + string t = InstallOptions.TabbedNotMica ? "T" : ""; + string val = ""; + if (InstallOptions.ThemeLight) val = t + "lightrectified.conf"; + else if (InstallOptions.ThemeDark) val = t + "darkrectified.conf"; + else if (InstallOptions.ThemeBlack) + { + val = t + "black.conf"; + string amdorarm = NativeMethods.IsArm64() ? "ARM" : "AMD"; + Interaction.Shell(Path.Combine(Variables.sys32Folder, "schtasks.exe") + " /create /tn micafix /xml " + Path.Combine(Variables.Windir, "MicaForEveryone", "XML", "micafix" + amdorarm + "64.xml"), AppWinStyle.Hide, true); + } + + if (!string.IsNullOrWhiteSpace(val)) + { + File.Copy(Path.Combine(Variables.Windir, "MicaForEveryone", "CONF", val), + Path.Combine(Variables.Windir, "MicaForEveryone", "MicaForEveryone.conf"), true); + } + } + + #region Internal + private static bool InstallThemeWallpapers() + { + UninstallThemeWallpapers(); + Directory.CreateDirectory(Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified")); + try + { + var files = Directory.GetFiles(Path.Combine(Variables.r11Folder, "themes", "wallpapers")); + for (int j = 0; j < files.Length; j++) + { + File.Copy(files[j], Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified", Path.GetFileName(files[j])), true); + } + Logger.WriteLine("Copied wallpapers to " + Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified")); + } + catch (Exception ex) + { + Logger.WriteLine("Error copying wallpapers", ex); + } + return true; + } + private static bool UninstallThemeWallpapers() + { + if (Directory.Exists(Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified"))) + { + try + { + List wallpapers = new() + { + "cosmic.png", + "img0.png", + "img19.png", + "metal.png" + }; + string path = Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified"); + var files = Directory.GetFiles(path); + for (int j = 0; j < files.Length; j++) + { + if (!wallpapers.Contains(Path.GetFileName(files[j]))) + Helper.SafeFileDeletion(files[j]); + } + if (Directory.GetFiles(path).Length == 0) + { + Helper.SafeDirectoryDeletion(path, false); + Logger.WriteLine("Deleted " + path); + } + Logger.WriteLine("Deleted old wallpapers."); + } + catch (Exception ex) + { + Logger.WriteLine("Error deleting old wallpapers", ex); + } + } + return true; + } + private static bool InstallCursors() + { + UninstallCursors(); + var curdir = new DirectoryInfo(Path.Combine(Variables.r11Folder, "themes", "cursors")) + .GetDirectories("*", SearchOption.TopDirectoryOnly); + + for (var i = 0; i < curdir.Length; i++) + { + try + { + Directory.Move(curdir[i].FullName, Path.Combine(Variables.Windir, "cursors", curdir[i].Name)); + Logger.WriteLine("Copied " + curdir[i].Name + " cursors"); + } + catch (Exception ex) + { + Logger.WriteLine("Error copying " + curdir[i].Name, ex); + return false; + } + } + return true; + } + private static bool UninstallCursors() + { + var dirs = Directory.GetDirectories(Path.Combine(Variables.Windir, "cursors"), "WindowsRectified*"); + for (int i = 0; i < dirs.Length; i++) + { + try + { + Helper.SafeDirectoryDeletion(dirs[i], false); + Logger.WriteLine("Deleted existing cursor directory " + dirs[i]); + } + catch + { + return false; + } + } + return true; + } + private static bool UninstallMsstyles() + { + // .theme files + List themefiles = new() + { + "black.theme", + "darkcolorized.theme", + "darkrectified.theme", + "lightrectified.theme" + }; + try + { + for (int i = 0; i < themefiles.Count; i++) + { + Helper.SafeFileDeletion(Path.Combine(Variables.Windir, "Resources", "Themes", themefiles[i])); + } + Logger.WriteLine("Deleted themes."); + } + catch (Exception ex) + { + Logger.WriteLine("Error deleting themes", ex); + } + + // msstyles + try + { + Helper.SafeDirectoryDeletion(Path.Combine(Variables.Windir, "Resources", "Themes", "Rectified"), false); + } + catch (Exception ex) + { + Logger.WriteLine("Error deleting " + Path.Combine(Variables.Windir, "Resources", "Themes", "Rectified"), ex); + return false; + } + return true; + } + private static bool InstallMsstyles() + { + UninstallMsstyles(); + DirectoryInfo themedir = new(Path.Combine(Variables.r11Folder, "themes", "themes")); + var msstyleDirList = themedir.GetDirectories("*", SearchOption.TopDirectoryOnly); + var themefiles = themedir.GetFiles("*.theme"); + + for (var i = 0; i < themefiles.Length; i++) + { + // why would it fail + File.Copy(themefiles[i].FullName, Path.Combine(Variables.Windir, "Resources", "Themes", themefiles[i].Name), true); + } + + File.WriteAllBytes(Path.Combine(Variables.r11Folder, "aRun1.exe"), Properties.Resources.AdvancedRun); + for (var i = 0; i < msstyleDirList.Length; i++) + { + try + { + Directory.Move(msstyleDirList[i].FullName, Path.Combine(Variables.Windir, "Resources", "Themes", msstyleDirList[i].Name)); + Logger.WriteLine("Copied " + msstyleDirList[i].Name + " directory."); + } + catch (Exception ex) + { + Logger.WriteLine("Error copying " + msstyleDirList[i].Name, ex); + return false; + } + } + File.Delete(Path.Combine(Variables.r11Folder, "aRun1.exe")); + return true; + } + private static bool UninstallMfe() + { + try + { + Helper.KillProcess("micaforeveryone.exe"); + Helper.KillProcess("micafix.exe"); + Helper.KillProcess("explorerframe.exe"); + Helper.DeleteTask("mfe"); + Helper.DeleteTask("micafix"); + if (!Helper.SafeDirectoryDeletion(Path.Combine(Variables.Windir, "MicaForEveryone"), false)) + { + Logger.WriteLine("Deleting " + Path.Combine(Variables.Windir, "MicaForEveryone") + " failed. "); + return false; + } + return true; + } + catch { return false; } + } + #endregion + } } diff --git a/Rectify11Installer/Pages/DebugPage.Designer.cs b/Rectify11Installer/Pages/DebugPage.Designer.cs index 68a8a7850..685f9b35a 100644 --- a/Rectify11Installer/Pages/DebugPage.Designer.cs +++ b/Rectify11Installer/Pages/DebugPage.Designer.cs @@ -29,51 +29,112 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + this.checkBox1 = new Rectify11Installer.Controls.DarkAwareCheckBox(); + this.checkBox2 = new Rectify11Installer.Controls.DarkAwareCheckBox(); + this.darkAwareLabel1 = new Rectify11Installer.Controls.DarkAwareLabel(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.darkAwareLabel2 = new Rectify11Installer.Controls.DarkAwareLabel(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.winUIButton1 = new Rectify11Installer.Controls.WinUIButton(); this.SuspendLayout(); - checkBox1 = new Controls.DarkAwareCheckBox(); - checkBox2 = new Controls.DarkAwareCheckBox(); - // - // checkBox1 - // - this.checkBox1.ForeColor = System.Drawing.Color.Black; + // + // checkBox1 + // + this.checkBox1.ForeColor = System.Drawing.Color.Black; this.checkBox1.Location = new System.Drawing.Point(4, 10); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(288, 19); this.checkBox1.TabIndex = 0; this.checkBox1.Text = "Disable update check"; this.checkBox1.UseVisualStyleBackColor = true; - this.checkBox1.Click += CheckBox1_Click; - // - // checkBox2 - // - this.checkBox2.ForeColor = System.Drawing.Color.Black; - this.checkBox2.Location = new System.Drawing.Point(4, 30); - this.checkBox2.Name = "checkBox2"; - this.checkBox2.Size = new System.Drawing.Size(288, 19); - this.checkBox2.TabIndex = 0; - this.checkBox2.Text = "Disable phase2"; - this.checkBox2.UseVisualStyleBackColor = true; - this.checkBox2.Click += CheckBox2_Click; - // - // DebugPage - // - this.BackColor = System.Drawing.Color.Transparent; + // + // checkBox2 + // + this.checkBox2.ForeColor = System.Drawing.Color.Black; + this.checkBox2.Location = new System.Drawing.Point(4, 30); + this.checkBox2.Name = "checkBox2"; + this.checkBox2.Size = new System.Drawing.Size(288, 19); + this.checkBox2.TabIndex = 0; + this.checkBox2.Text = "Disable phase2"; + this.checkBox2.UseVisualStyleBackColor = true; + // + // darkAwareLabel1 + // + this.darkAwareLabel1.AutoSize = true; + this.darkAwareLabel1.BackColor = System.Drawing.Color.White; + this.darkAwareLabel1.ForeColor = System.Drawing.Color.Black; + this.darkAwareLabel1.Location = new System.Drawing.Point(4, 66); + this.darkAwareLabel1.Name = "darkAwareLabel1"; + this.darkAwareLabel1.Size = new System.Drawing.Size(96, 15); + this.darkAwareLabel1.TabIndex = 1; + this.darkAwareLabel1.Text = "Execute function"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(4, 84); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(105, 23); + this.textBox1.TabIndex = 2; + // + // darkAwareLabel2 + // + this.darkAwareLabel2.AutoSize = true; + this.darkAwareLabel2.BackColor = System.Drawing.Color.White; + this.darkAwareLabel2.ForeColor = System.Drawing.Color.Black; + this.darkAwareLabel2.Location = new System.Drawing.Point(113, 88); + this.darkAwareLabel2.Name = "darkAwareLabel2"; + this.darkAwareLabel2.Size = new System.Drawing.Size(17, 15); + this.darkAwareLabel2.TabIndex = 3; + this.darkAwareLabel2.Text = "in"; + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(134, 84); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(142, 23); + this.textBox2.TabIndex = 4; + // + // winUIButton1 + // + this.winUIButton1.BackColor = System.Drawing.Color.Transparent; + this.winUIButton1.ButtonText = "Execute"; + this.winUIButton1.ForeColor = System.Drawing.Color.Black; + this.winUIButton1.Location = new System.Drawing.Point(280, 85); + this.winUIButton1.Name = "winUIButton1"; + this.winUIButton1.Size = new System.Drawing.Size(64, 23); + this.winUIButton1.TabIndex = 5; + this.winUIButton1.Click += WinUIButton1_Click; + // + // DebugPage + // + this.BackColor = System.Drawing.Color.Transparent; + this.Controls.Add(this.winUIButton1); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.darkAwareLabel2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.darkAwareLabel1); this.Controls.Add(this.checkBox1); this.Controls.Add(this.checkBox2); - this.Name = "DebugPage"; - this.WizardHeader = "Debug"; - this.HeaderVisible = true; this.FooterVisible = true; + this.HeaderVisible = true; + this.Name = "DebugPage"; + this.NextButtonEnabled = false; this.Page = Rectify11Installer.Core.TabPages.debPage; + this.SideImage = global::Rectify11Installer.Properties.Resources.incomplete; this.UpdateFrame = true; this.IsWelcomePage = false; - this.NextButtonEnabled = false; - this.SideImage = global::Rectify11Installer.Properties.Resources.incomplete; + this.WizardHeader = "Debug"; this.ResumeLayout(false); + this.PerformLayout(); } #endregion private Controls.DarkAwareCheckBox checkBox1; private Controls.DarkAwareCheckBox checkBox2; - } + private Controls.DarkAwareLabel darkAwareLabel1; + private System.Windows.Forms.TextBox textBox1; + private Controls.DarkAwareLabel darkAwareLabel2; + private System.Windows.Forms.TextBox textBox2; + private Controls.WinUIButton winUIButton1; + } } diff --git a/Rectify11Installer/Pages/DebugPage.cs b/Rectify11Installer/Pages/DebugPage.cs index c9a589844..13928fc75 100644 --- a/Rectify11Installer/Pages/DebugPage.cs +++ b/Rectify11Installer/Pages/DebugPage.cs @@ -1,4 +1,5 @@ using System; +using System.Reflection; namespace Rectify11Installer.Pages { @@ -16,5 +17,13 @@ private void CheckBox2_Click(object sender, EventArgs e) { Core.Variables.Phase2Skip = checkBox2.Checked; } - } + private void WinUIButton1_Click(object sender, System.EventArgs e) + { + Type type = Type.GetType(textBox2.Text); + object o = Activator.CreateInstance(type); + MethodInfo method = type.GetMethod(textBox1.Text); + method.Invoke(o, null); + } + + } }