From caa159b22062320447d6f8abb4ec61d53b370495 Mon Sep 17 00:00:00 2001
From: rounk-ctrl <70931017+rounk-ctrl@users.noreply.github.com>
Date: Sat, 23 Sep 2023 10:02:15 +0400
Subject: [PATCH] refactor extras uninstallation
---
Rectify11Installer/Core/Backend/Extras.cs | 55 +++-
Rectify11Installer/Core/Backend/Icons.cs | 10 +-
Rectify11Installer/Core/Backend/Installer.cs | 7 +-
.../Core/Backend/Uninstaller.cs | 254 +-----------------
4 files changed, 69 insertions(+), 257 deletions(-)
diff --git a/Rectify11Installer/Core/Backend/Extras.cs b/Rectify11Installer/Core/Backend/Extras.cs
index 6565ec6a2..608ba1ce5 100644
--- a/Rectify11Installer/Core/Backend/Extras.cs
+++ b/Rectify11Installer/Core/Backend/Extras.cs
@@ -74,7 +74,38 @@ public static bool Install(FrmWizard frm)
Logger.WriteLine("══════════════════════════════════════════════");
return true;
}
-
+ public static bool Uninstall()
+ {
+ for (int i = 0; i < UninstallOptions.uninstExtrasList.Count; i++)
+ {
+ if (UninstallOptions.uninstExtrasList[i] == "wallpapersNode")
+ {
+ UninstallWallpapers();
+ Logger.WriteLine("Uninstalled wallpapers");
+ }
+ if (UninstallOptions.uninstExtrasList[i] == "asdfNode")
+ {
+ 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");
+ }
+ }
+ return true;
+ }
///
/// installs wallpapers
///
@@ -326,6 +357,13 @@ private static bool UninstallAsdf()
Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "extras", "AccentColorizer"), false);
}
catch { return false; }
+
+ string epath = Path.Combine(Variables.r11Folder, "extras");
+ if (Directory.GetDirectories(epath).Length == 0
+ && Directory.GetFiles(epath).Length == 0)
+ {
+ Helper.SafeDirectoryDeletion(epath, false);
+ }
return true;
}
return true;
@@ -380,8 +418,18 @@ private static bool UninstallShell()
if (!Helper.SafeFileDeletion(path))
return false;
+ // restore win11 menus
+ Process.Start(Path.Combine(Variables.sys32Folder, "reg.exe"), " delete \"HKCU\\Software\\Classes\\CLSID\\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\" /f");
+
if (!Helper.SafeDirectoryDeletion(Path.Combine(Variables.Windir, "nilesoft"), false))
return false;
+
+ if (!Variables.RestartRequired && Variables.IsUninstall)
+ {
+ Interaction.Shell(Path.Combine(Variables.sys32Folder, "taskkill.exe") + " /f /im explorer.exe", AppWinStyle.Hide, true);
+ Interaction.Shell(Path.Combine(Variables.Windir, "explorer.exe"), AppWinStyle.NormalFocus);
+ Thread.Sleep(3000);
+ }
}
return true;
}
@@ -395,10 +443,7 @@ private static bool UninstallUserAv()
{
try
{
- if (Directory.Exists(Path.Combine(Variables.progdata, "Microsoft", "User Account Pictures", "Default Pictures")))
- {
- Directory.Delete(Path.Combine(Variables.progdata, "Microsoft", "User Account Pictures", "Default Pictures"), true);
- }
+ Helper.SafeDirectoryDeletion(Path.Combine(Variables.progdata, "Microsoft", "User Account Pictures", "Default Pictures"), false);
return true;
}
catch (Exception ex)
diff --git a/Rectify11Installer/Core/Backend/Icons.cs b/Rectify11Installer/Core/Backend/Icons.cs
index f2d469ca1..a66216f36 100644
--- a/Rectify11Installer/Core/Backend/Icons.cs
+++ b/Rectify11Installer/Core/Backend/Icons.cs
@@ -133,10 +133,7 @@ public static bool Install(FrmWizard frm)
}
}
// phase 2
- Interaction.Shell(Path.Combine(Variables.r11Folder, "aRun.exe")
- + " /EXEFilename " + '"' + Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe") + '"'
- + " /CommandLine " + "\'" + "/install" + "\'"
- + " /WaitProcess 1 /RunAs 8 /Run", AppWinStyle.NormalFocus, true);
+ 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);
@@ -162,7 +159,10 @@ public static bool Uninstall()
Helper.RunAsTI(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe"), "/uninstall");
}
}
- catch { }
+ catch
+ {
+ return false;
+ }
Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "Rectify11.Phase2.exe"));
Helper.SafeFileDeletion(Path.Combine(Variables.r11Folder, "aRun.exe"));
diff --git a/Rectify11Installer/Core/Backend/Installer.cs b/Rectify11Installer/Core/Backend/Installer.cs
index a99f8e1fe..6e1d2ab53 100644
--- a/Rectify11Installer/Core/Backend/Installer.cs
+++ b/Rectify11Installer/Core/Backend/Installer.cs
@@ -1,7 +1,6 @@
using Microsoft.Win32;
using Rectify11Installer.Win32;
using System.IO;
-using System.Threading.Tasks;
using static Rectify11Installer.Win32.NativeMethods;
namespace Rectify11Installer.Core
@@ -9,7 +8,7 @@ namespace Rectify11Installer.Core
public class Installer
{
#region Public Methods
- public async Task Install(FrmWizard frm)
+ public bool Install(FrmWizard frm)
{
frm.InstallerProgress = "Preparing Installation";
Logger.WriteLine("Preparing Installation");
@@ -110,7 +109,7 @@ public async Task Install(FrmWizard frm)
{
// create restore point
frm.InstallerProgress = "End creating a restore point";
- await Task.Run(() => CreateSystemRestorePoint(true));
+ CreateSystemRestorePoint(true);
}
catch
{
@@ -121,7 +120,7 @@ public async Task Install(FrmWizard frm)
frm.InstallerProgress = "Cleaning up...";
Logger.WriteLine("Cleaning up");
Logger.WriteLine("───────────");
- if (!await Task.Run(() => Common.Cleanup()))
+ if (!Common.Cleanup())
{
Logger.WriteLine("Cleanup() failed");
return false;
diff --git a/Rectify11Installer/Core/Backend/Uninstaller.cs b/Rectify11Installer/Core/Backend/Uninstaller.cs
index 7cfd45915..a019321f2 100644
--- a/Rectify11Installer/Core/Backend/Uninstaller.cs
+++ b/Rectify11Installer/Core/Backend/Uninstaller.cs
@@ -1,26 +1,19 @@
-using Microsoft.VisualBasic;
-using Microsoft.Win32;
-using Rectify11Installer.Win32;
+using Microsoft.Win32;
using System;
-using System.Collections.Generic;
-using System.Diagnostics;
using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-using static Rectify11Installer.Win32.NativeMethods;
namespace Rectify11Installer.Core
{
public class Uninstaller
{
- public async Task Uninstall(FrmWizard frm)
+ public bool Uninstall(FrmWizard frm)
{
if (UninstallOptions.uninstIconsList.Count > 0)
{
Logger.WriteLine("Uninstalling icons");
Logger.WriteLine("──────────────────");
frm.InstallerProgress = "Uninstalling icons";
- await Task.Run(() => Icons.Uninstall());
+ Icons.Uninstall();
Variables.RestartRequired = true;
Console.WriteLine("══════════════════════════════════════════════");
}
@@ -29,7 +22,7 @@ public async Task Uninstall(FrmWizard frm)
Logger.WriteLine("Uninstalling themes");
Logger.WriteLine("───────────────────");
frm.InstallerProgress = "Uninstalling themes";
- await Task.Run(() => Themes.Uninstall());
+ Themes.Uninstall();
Variables.RestartRequired = true;
Console.WriteLine("══════════════════════════════════════════════");
}
@@ -38,28 +31,17 @@ public async Task Uninstall(FrmWizard frm)
Logger.WriteLine("Uninstalling extras");
Logger.WriteLine("───────────────────");
frm.InstallerProgress = "Uninstalling Extras";
- await Task.Run(() => UninstallExtras());
+ Extras.Uninstall();
Console.WriteLine("══════════════════════════════════════════════");
}
// cleanup
- if (Directory.Exists(Path.Combine(Variables.r11Folder, "Tmp")))
- {
- try
- {
- Directory.Delete(Path.Combine(Variables.r11Folder, "Tmp"), true);
- }
- catch { }
- }
+ Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "Tmp"), false);
if (Directory.Exists(Path.Combine(Variables.r11Folder, "Backup")))
{
if (Directory.GetFiles(Path.Combine(Variables.r11Folder, "Backup")).Length == 0
&& Directory.GetDirectories(Path.Combine(Variables.r11Folder, "Backup")).Length == 0)
{
- try
- {
- Directory.Delete(Path.Combine(Variables.r11Folder, "Backup"), true);
- }
- catch { }
+ Helper.SafeDirectoryDeletion(Path.Combine(Variables.r11Folder, "Backup"), false);
}
}
Logger.CommitLog();
@@ -69,20 +51,12 @@ public async Task Uninstall(FrmWizard frm)
var files = Directory.GetFiles(Variables.r11Folder);
for (int j = 0; j < files.Length; j++)
{
- try
- {
- File.Delete(files[j]);
- }
- catch
- {
- string name = Path.GetRandomFileName();
- File.Move(files[j], Path.Combine(Path.GetTempPath(), name));
- MoveFileEx(Path.Combine(Path.GetTempPath(), name), null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
- }
+ Helper.SafeFileDeletion(files[j]);
}
- if (Directory.GetFiles(Variables.r11Folder).Length == 0 && Directory.GetDirectories(Variables.r11Folder).Length == 0)
+ if (Directory.GetFiles(Variables.r11Folder).Length == 0
+ && Directory.GetDirectories(Variables.r11Folder).Length == 0)
{
- Directory.Delete(Variables.r11Folder, true);
+ Helper.SafeDirectoryDeletion(Variables.r11Folder, false);
}
using var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE", true);
reg.DeleteSubKey("Rectify11", false);
@@ -92,211 +66,5 @@ public async Task Uninstall(FrmWizard frm)
if (!Variables.RestartRequired) frm.InstallerProgress = "Done, you can close this window";
return true;
}
-
- private async Task UninstallExtras()
- {
- for (int i = 0; i < UninstallOptions.uninstExtrasList.Count; i++)
- {
- if (UninstallOptions.uninstExtrasList[i] == "wallpapersNode")
- {
- if (Directory.Exists(Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified")))
- {
- List wallpapers = new List
- {
- "cosmic.png",
- "img0.png",
- "img19.png",
- "metal.png"
- };
- var files = Directory.GetFiles(Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified"));
- for (int j = 0; j < files.Length; j++)
- {
- if (!wallpapers.Contains(Path.GetFileName(files[j])))
- {
- try
- {
- File.Delete(files[j]);
- }
- catch
- {
- MoveFileEx(files[j], null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
- }
- }
- }
- if (Directory.GetFiles(Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified")).Length == 0)
- {
- try
- {
- Directory.Delete(Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified"), true);
- }
- catch
- {
- string name = Path.GetRandomFileName();
- Directory.Move(Path.Combine(Variables.Windir, "web", "wallpaper", "Rectified"), Path.Combine(Path.GetTempPath(), name));
- MoveFileEx(Path.Combine(Path.GetTempPath(), name), null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
- }
- }
- }
- Logger.WriteLine("Uninstalled wallpapers");
- }
- if (UninstallOptions.uninstExtrasList[i] == "asdfNode")
- {
- await Task.Run(() => Interaction.Shell(Path.Combine(Variables.sys32Folder, "taskkill.exe") + " /f /im AccentColorizer.exe", AppWinStyle.Hide, true));
- await Task.Run(() => Interaction.Shell(Path.Combine(Variables.sys32Folder, "taskkill.exe") + " /f /im AccentColorizerEleven.exe", AppWinStyle.Hide, true));
- await Task.Run(() => Interaction.Shell(Path.Combine(Variables.sys32Folder, "schtasks.exe") + " /delete /f /tn asdf", AppWinStyle.Hide));
- if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "asdf.lnk")))
- {
- try
- {
- File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "asdf.lnk"));
- }
- catch
- {
- File.Move(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "asdf.lnk"), Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
- }
- }
- if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "asdf11.lnk")))
- {
- try
- {
- File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "asdf11.lnk"));
- }
- catch
- {
- File.Move(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "asdf11.lnk"), Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
- }
- }
- if (Directory.Exists(Path.Combine(Variables.r11Folder, "extras", "AccentColorizer")))
- {
- try
- {
- Directory.Delete(Path.Combine(Variables.r11Folder, "extras", "AccentColorizer"), true);
- }
- catch
- {
- string name = Path.GetRandomFileName();
- Directory.Move(Path.Combine(Variables.r11Folder, "extras", "AccentColorizer"), Path.Combine(Path.GetTempPath(), name));
- var files = Directory.GetFiles(Path.Combine(Path.GetTempPath(), name));
- for (int j = 0; j < files.Length; j++)
- {
- MoveFileEx(files[j], null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
- }
- MoveFileEx(Path.Combine(Path.GetTempPath(), name), null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
- }
- }
- // will fail anyways if the folder isnt empty
- Directory.Delete(Path.Combine(Variables.r11Folder, "extras"), true);
- Logger.WriteLine("Uninstalled asdf");
- }
- if (UninstallOptions.uninstExtrasList[i] == "useravNode")
- {
- if (Directory.Exists(Path.Combine(Variables.progdata, "Microsoft", "User Account Pictures", "Default Pictures")))
- {
- try
- {
- Directory.Delete(Path.Combine(Variables.progdata, "Microsoft", "User Account Pictures", "Default Pictures"), true);
- }
- catch
- {
- string name = Path.GetRandomFileName();
- Directory.Move(Path.Combine(Variables.progdata, "Microsoft", "User Account Pictures", "Default Pictures"), Path.Combine(Path.GetTempPath(), name));
- var fil = Directory.GetFiles(Path.Combine(Path.GetTempPath(), name));
- for (int j = 0; j < fil.Length; j++)
- {
- MoveFileEx(fil[j], null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
- }
- MoveFileEx(Path.Combine(Path.GetTempPath(), name), null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
- }
- }
- Logger.WriteLine("Uninstalled user avatars");
- }
- if (UninstallOptions.uninstExtrasList[i] == "shellNode")
- {
- if (Directory.Exists(Path.Combine(Variables.Windir, "nilesoft")))
- {
- await Task.Run(() => Interaction.Shell(Path.Combine(Variables.sys32Folder, "taskkill.exe") + " /f /im AcrylicMenusLoader.exe", AppWinStyle.Hide, true));
- if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "acrylmenu.lnk")))
- {
- File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "programs", "startup", "acrylmenu.lnk"));
- }
- ProcessStartInfo shlinfo2 = new()
- {
- FileName = Path.Combine(Variables.Windir, "nilesoft", "shell.exe"),
- WindowStyle = ProcessWindowStyle.Hidden,
- Arguments = " -u"
- };
- try
- {
- if (File.Exists(Path.Combine(Variables.Windir, "nilesoft", "shell.dll")))
- {
- var shlInstproc2 = Process.Start(shlinfo2);
- shlInstproc2.WaitForExit();
- }
- }
- catch { }
- await Task.Run(() => Process.Start(Path.Combine(Variables.sys32Folder, "reg.exe"), " delete \"HKCU\\Software\\Classes\\CLSID\\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\" /f"));
- string name = Path.GetRandomFileName();
- Directory.Move(Path.Combine(Variables.Windir, "nilesoft"), Path.Combine(Path.GetTempPath(), name));
- var files = Directory.GetFiles(Path.Combine(Path.GetTempPath(), name));
- for (int j = 0; j < files.Length; j++)
- {
- try
- {
- File.Delete(files[j]);
- }
- catch
- {
- MoveFileEx(files[j], null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
- }
- }
- var dir = Directory.GetDirectories(Path.Combine(Path.GetTempPath(), name));
- for (int j = 0; j < dir.Length; j++)
- {
- var fil = Directory.GetFiles(dir[j]);
- for (int k = 0; k < fil.Length; k++)
- {
- try
- {
- File.Delete(fil[k]);
- }
- catch
- {
- MoveFileEx(fil[k], null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
- }
- }
- try
- {
- Directory.Delete(dir[j], true);
- }
- catch
- {
- MoveFileEx(dir[j], null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
- }
- }
- MoveFileEx(Path.Combine(Path.GetTempPath(), name), null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
- if (!Variables.RestartRequired)
- {
- await Task.Run(() => Interaction.Shell(Path.Combine(Variables.sys32Folder, "taskkill.exe") + " /f /im explorer.exe", AppWinStyle.Hide, true));
- await Task.Run(() => Interaction.Shell(Path.Combine(Variables.Windir, "explorer.exe"), AppWinStyle.NormalFocus));
- Thread.Sleep(3000);
- }
- Logger.WriteLine("Uninstalled shell");
- }
- }
- if (UninstallOptions.uninstExtrasList[i] == "gadgetsNode")
- {
- ProcessStartInfo gad = new()
- {
- FileName = Path.Combine(Variables.sys32Folder, "msiexec.exe"),
- WindowStyle = ProcessWindowStyle.Normal,
- Arguments = "/X{A84C39EA-54FE-4CED-B464-97DA9201EB33} /qn"
- };
- var vcproc = Process.Start(gad);
- vcproc.WaitForExit();
- Logger.WriteLine("Uninstalled shell");
- }
- }
- return true;
- }
}
}