Skip to content

Commit

Permalink
fix themes uninstallation
Browse files Browse the repository at this point in the history
  • Loading branch information
rounk-ctrl committed Sep 22, 2023
1 parent a308c27 commit 5c35700
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 358 deletions.
24 changes: 24 additions & 0 deletions Rectify11Installer/Core/Backend/Icons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,30 @@ public static bool Install(FrmWizard frm)
Variables.RestartRequired = true;
return true;
}

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
{
Registry.LocalMachine.OpenSubKey(@"SOFTWARE", true)
?.CreateSubKey("Rectify11", true)
?.SetValue("UninstallFiles", UninstallOptions.uninstIconsList.ToArray());

if (!Variables.Phase2Skip)
{
Logger.WriteLine("Executed Rectify11.Phase2.exe");
Helper.RunAsTI(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe"), "/uninstall");
}
}
catch { }

Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe"));
Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "aRun.exe"));
return true;
}

/// <summary>
/// fixes 32-bit odbc shortcut icon
/// </summary>
Expand Down
184 changes: 138 additions & 46 deletions Rectify11Installer/Core/Backend/Themes.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Microsoft.VisualBasic;
using Microsoft.Win32;
using Rectify11Installer.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using static Rectify11Installer.Win32.NativeMethods;

namespace Rectify11Installer.Core
{
Expand All @@ -19,11 +22,6 @@ public static bool Install()
}
Logger.WriteLine("WriteFiles() succeeded.");

Helper.KillProcess("micaforeveryone.exe");
Helper.KillProcess("micafix.exe");
Helper.KillProcess("explorerframe.exe");
Helper.DeleteTask("mfe");
Helper.DeleteTask("micafix");

if (Directory.Exists(Path.Combine(Variables.r11Folder, "themes")))
{
Expand All @@ -48,15 +46,7 @@ public static bool Install()
{
if (!InstallOptions.SkipMFE)
{
if (Directory.Exists(Path.Combine(Variables.Windir, "MicaForEveryone")))
{
if (!Helper.SafeDirectoryDeletion(Path.Combine(Variables.Windir, "MicaForEveryone"), false))
{
Logger.WriteLine("Deleting " + Path.Combine(Variables.Windir, "MicaForEveryone") + " failed. ");
return false;
}
}
Directory.Move(Path.Combine(Variables.r11Folder, "Themes", "MicaForEveryone"), Path.Combine(Variables.Windir, "MicaForEveryone"));

InstallMfe();
Logger.WriteLine("InstallMfe() succeeded.");
}
Expand All @@ -79,14 +69,70 @@ public static bool Install()
Logger.WriteLine("══════════════════════════════════════════════");
return true;
}
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;

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);

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"));

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("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);

Logger.WriteLine("Deleted Rectify11 Control Center");
return true;
}

/// <summary>
/// installs themes
/// </summary>
private static bool InstallThemes()
{
var curdir = new DirectoryInfo(Path.Combine(Variables.r11Folder, "themes", "cursors"))
.GetDirectories("*", SearchOption.TopDirectoryOnly);

InstallThemeWallpapers();

// todo: remove r11cp
Expand All @@ -95,7 +141,7 @@ private static bool InstallThemes()
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);

InstallCursors(curdir);
InstallCursors();
InstallMsstyles();
return true;
}
Expand Down Expand Up @@ -135,29 +181,27 @@ private static void Installr11cpl()
/// </summary>
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);
if (Directory.Exists(Path.Combine(Environment.GetEnvironmentVariable("localappdata") ?? string.Empty, "Mica For Everyone")))
{
Directory.Delete(Path.Combine(Environment.GetEnvironmentVariable("localappdata") ?? string.Empty, "Mica For Everyone"), true);
}
string t = "";
if (InstallOptions.TabbedNotMica) t = "T";
if (InstallOptions.ThemeLight)
{
File.Copy(Path.Combine(Variables.Windir, "MicaForEveryone", "CONF", t + "lightrectified.conf"), Path.Combine(Variables.Windir, "MicaForEveryone", "MicaForEveryone.conf"), true);
}
else if (InstallOptions.ThemeDark)

string path = Path.Combine(Environment.GetEnvironmentVariable("localappdata"), "Mica For Everyone");
if (Directory.Exists(path))
{
File.Copy(Path.Combine(Variables.Windir, "MicaForEveryone", "CONF", t + "darkrectified.conf"), Path.Combine(Variables.Windir, "MicaForEveryone", "MicaForEveryone.conf"), true);
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
{
File.Copy(Path.Combine(Variables.Windir, "MicaForEveryone", "CONF", t + "black.conf"), Path.Combine(Variables.Windir, "MicaForEveryone", "MicaForEveryone.conf"), true);
string amdorarm = "AMD";
if (NativeMethods.IsArm64()) amdorarm = "ARM";
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);
}

File.Copy(Path.Combine(Variables.Windir, "MicaForEveryone", "CONF", val),
Path.Combine(Variables.Windir, "MicaForEveryone", "MicaForEveryone.conf"), true);
}

#region Internal
Expand Down Expand Up @@ -196,12 +240,18 @@ private static bool UninstallThemeWallpapers()
"img19.png",
"metal.png"
};
var files = Directory.GetFiles(Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified"));
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)
Expand All @@ -211,9 +261,12 @@ private static bool UninstallThemeWallpapers()
}
return true;
}
private static bool InstallCursors(DirectoryInfo[] curdir)
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
Expand Down Expand Up @@ -248,20 +301,38 @@ private static bool UninstallCursors()
}
private static bool UninstallMsstyles()
{
if (Directory.Exists(Path.Combine(Variables.Windir, "Resources", "Themes", "Rectified")))
// .theme files
List<string> themefiles = new()
{
try
{
Helper.SafeDirectoryDeletion(Path.Combine(Variables.Windir, "Resources", "Themes", "Rectified"), false);
}
catch (Exception ex)
"black.theme",
"darkcolorized.theme",
"darkrectified.theme",
"lightrectified.theme"
};
try
{
for (int i = 0; i < themefiles.Count; i++)
{
Logger.WriteLine("Error deleting " + Path.Combine(Variables.Windir, "Resources", "Themes", "Rectified") + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine);
return false;
Helper.SafeFileDeletion(Path.Combine(Variables.Windir, "Resources", "Themes", themefiles[i]));
}
return true;
Logger.WriteLine("Deleted themes");
}
return false;
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.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine);
return false;
}
return true;
}
private static bool InstallMsstyles()
{
Expand Down Expand Up @@ -293,6 +364,27 @@ private static bool InstallMsstyles()
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 (Directory.Exists(Path.Combine(Variables.Windir, "MicaForEveryone")))
{
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
}
}
Loading

0 comments on commit 5c35700

Please sign in to comment.