Skip to content

Commit

Permalink
refactor extras uninstallation
Browse files Browse the repository at this point in the history
  • Loading branch information
rounk-ctrl committed Sep 23, 2023
1 parent 5c35700 commit caa159b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 257 deletions.
55 changes: 50 additions & 5 deletions Rectify11Installer/Core/Backend/Extras.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
/// <summary>
/// installs wallpapers
/// </summary>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions Rectify11Installer/Core/Backend/Icons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"));
Expand Down
7 changes: 3 additions & 4 deletions Rectify11Installer/Core/Backend/Installer.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using Microsoft.Win32;
using Rectify11Installer.Win32;
using System.IO;
using System.Threading.Tasks;
using static Rectify11Installer.Win32.NativeMethods;

namespace Rectify11Installer.Core
{
public class Installer
{
#region Public Methods
public async Task<bool> Install(FrmWizard frm)
public bool Install(FrmWizard frm)
{
frm.InstallerProgress = "Preparing Installation";
Logger.WriteLine("Preparing Installation");
Expand Down Expand Up @@ -110,7 +109,7 @@ public async Task<bool> Install(FrmWizard frm)
{
// create restore point
frm.InstallerProgress = "End creating a restore point";
await Task.Run(() => CreateSystemRestorePoint(true));
CreateSystemRestorePoint(true);
}
catch
{
Expand All @@ -121,7 +120,7 @@ public async Task<bool> 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;
Expand Down
Loading

0 comments on commit caa159b

Please sign in to comment.