Skip to content

Commit

Permalink
reboot optional
Browse files Browse the repository at this point in the history
  • Loading branch information
rounk-ctrl committed Oct 13, 2023
1 parent dffe9a1 commit e69a527
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 103 deletions.
38 changes: 34 additions & 4 deletions Rectify11Installer/Core/Backend/Icons.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualBasic;
using KPreisser.UI;
using Microsoft.VisualBasic;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -108,7 +109,9 @@ public static bool Install(FrmWizard frm)
// reg files for various file extensions
Helper.ImportReg(Path.Combine(Variables.r11Files, "icons.reg"));

Variables.RestartRequired = true;
ClearIconCache();

Variables.RestartRequired = true;
Logger.WriteLine("Icons.Install() succeeded.");
Logger.WriteLine("══════════════════════════════════════════════");
return true;
Expand Down Expand Up @@ -329,8 +332,35 @@ private static bool MatchAndApplyRule(PatchesPatch patch)
return true;
}

#region Internal functions
private static void PatchCmd(PatchType type, string filename, string name, string tempfolder, string filepath, string mask)
/// <summary>
/// clears *.db cache files
/// </summary>
private static void ClearIconCache()
{
try
{
DirectoryInfo di = new(Path.Combine(GetFolderPath(SpecialFolder.LocalApplicationData), "microsoft", "windows", "explorer"));
var files = di.GetFiles("*.db");

for (var i = 0; i < files.Length; i++)
{
files[i].Attributes = FileAttributes.Normal;
if (File.Exists(files[i].FullName))
{
Helper.SafeFileDeletion(files[i].FullName);
}
}
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", true);
key?.SetValue("ResetIconCache", Path.Combine(Variables.sys32Folder, "ie4uinit.exe") + " -show", RegistryValueKind.String);
key.Close();
}
catch (Exception ex)
{
Logger.Warn("Clearing icon cache failed", ex);
}
}
#region Internal functions
private static void PatchCmd(PatchType type, string filename, string name, string tempfolder, string filepath, string mask)
{
if (type == PatchType.x86)
{
Expand Down
51 changes: 49 additions & 2 deletions Rectify11Installer/Core/Backend/Themes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public static bool Install()
Helper.SafeFileOperation(Path.Combine(Variables.r11Folder, "mmc.exe.manifest"), Path.Combine(Variables.sys32Folder, "mmc.exe.manifest"), Helper.OperationType.Copy);
File.Delete(Path.Combine(Variables.r11Folder, "mmc.exe.manifest"));

try
{
ApplyScheme();
Logger.WriteLine("ApplyScheme() succeeded.");
}
catch (Exception ex)
{
Logger.Warn("ApplyScheme() failed", ex);
}

Variables.RestartRequired = true;
Logger.WriteLine("Themes.Install() succeeded.");
Logger.WriteLine("══════════════════════════════════════════════");
Expand Down Expand Up @@ -280,6 +290,7 @@ private static void InstallMfe()
string val = "";
if (InstallOptions.ThemeLight) val = t + "lightrectified.conf";
else if (InstallOptions.ThemeDark) val = t + "darkrectified.conf";
else if (InstallOptions.ThemePDark) val = t + "darkrectified.conf";
else if (InstallOptions.ThemeBlack)
{
val = t + "black.conf";
Expand Down Expand Up @@ -394,7 +405,8 @@ private static bool UninstallMsstyles()
"black.theme",
"darkcolorized.theme",
"darkrectified.theme",
"lightrectified.theme"
"lightrectified.theme",
"darkpartial.theme"
};
try
{
Expand Down Expand Up @@ -438,7 +450,7 @@ private static bool InstallMsstyles()
{
try
{
if (Environment.OSVersion.Version.Build >= 22543
if (Environment.OSVersion.Version.Build >= 22543
&& !msstyleDirList[i].Name.Contains("Legacy"))
{
Directory.Move(msstyleDirList[i].FullName, Path.Combine(Variables.Windir, "Resources", "Themes", msstyleDirList[i].Name));
Expand Down Expand Up @@ -476,6 +488,41 @@ private static bool UninstallMfe()
}
catch { return false; }
}

/// <summary>
/// applies the theme just before restart to set the mouse cursor properly
/// </summary>
private static void ApplyScheme()
{
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", true);
string s = "e";
if (key != null)
{
if (InstallOptions.ThemeLight)
{
Process.Start(Path.Combine(Variables.Windir, "Resources", "Themes", "lightrectified.theme"));
s = Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " apply " + '"' + "Rectify11 light theme" + '"';
}
else if (InstallOptions.ThemeDark)
{
Process.Start(Path.Combine(Variables.Windir, "Resources", "Themes", "darkrectified.theme"));
s = Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " apply " + '"' + "Rectify11 dark theme" + '"';
}
else if (InstallOptions.ThemePDark)
{
Process.Start(Path.Combine(Variables.Windir, "Resources", "Themes", "darkpartial.theme"));
s = Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " apply " + '"' + "Rectify11 partial dark theme" + '"';
}
else
{
Process.Start(Path.Combine(Variables.Windir, "Resources", "Themes", "black.theme"));
s = Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " apply " + '"' + "Rectify11 Dark theme with Mica" + '"';
}
}
key.SetValue("ApplyTheme", s, RegistryValueKind.String);
key.SetValue("DeleteJunk", "rmdir /s /q " + Path.Combine(Environment.SpecialFolder.LocalApplicationData.ToString(), "junk"), RegistryValueKind.String);
key.Close();
}
#endregion
}
}
3 changes: 2 additions & 1 deletion Rectify11Installer/Core/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ public class InstallOptions
public static bool ThemeDark { get; set; }
public static bool ThemeBlack { get; set; }
public static bool ThemeLight { get; set; }
public static bool InstallShell { get; set; }
public static bool ThemePDark { get; set; }
public static bool InstallShell { get; set; }
public static bool InstallSounds { get; set; }
public static bool SkipMFE { get; set; }
public static bool TabbedNotMica { get; set; }
Expand Down
1 change: 0 additions & 1 deletion Rectify11Installer/Pages/InstallOptnsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ private static void UpdateListView(PatchesPatch[] patch, TreeNode basicNode, Tre
{
tree.Checked = true;
tree.Ancestors()[0].Checked = true;
tree.Ancestors()[0].Ancestors()[0].Checked = true;
InstallOptions.origList.Add(patch[i].Mui);
}
}
Expand Down
33 changes: 32 additions & 1 deletion Rectify11Installer/Pages/ProgressPage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 14 additions & 93 deletions Rectify11Installer/Pages/ProgressPage.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using KPreisser.UI;
using Microsoft.VisualBasic;
using Microsoft.Win32;
using Rectify11Installer.Core;
using Rectify11Installer.Win32;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -15,8 +12,6 @@ public partial class ProgressPage : WizardPage
{
#region Variables
private FrmWizard frmwiz;
private Timer timer2;
private int duration = 30;
private int CurrentTextIndex = -1;
private static readonly InstallerTexts[] Rectify11InstallerTexts =
{
Expand Down Expand Up @@ -49,11 +44,6 @@ public InstallerTexts(string Title, string Description, Bitmap image)
public ProgressPage(FrmWizard frm)
{
InitializeComponent();
timer2 = new()
{
Interval = 1000
};
timer2.Tick += Timer2_Tick;
frmwiz = frm;
NavigationHelper.OnNavigate += NavigationHelper_OnNavigate;
}
Expand All @@ -64,15 +54,15 @@ public void StartReset()
progressText.Text = "Restarting your PC";
if (Variables.IsUninstall)
{
progressInfo.Text = "Rectify11 has finished uninstalling. Your device needs to restart in order to complete the uninstallation, it will automatically restart in " + duration.ToString() + " seconds";
progressInfo.Text = "Rectify11 has finished uninstalling. Your device needs to restart in order to complete the uninstallation";
}
else
{
progressInfo.Text = "Rectify11 has finished installing. Your device needs to restart in order to complete the installation, it will automatically restart in " + duration.ToString() + " seconds";
progressInfo.Text = "Rectify11 has finished installing. Your device needs to restart in order to complete the installation";
}
frmwiz.InstallerProgress = "Restarting in " + duration.ToString() + " seconds";
frmwiz.InstallerProgress = "";
frmwiz.UpdateSideImage = Properties.Resources.done;
timer2.Start();
r1.Visible = r2.Visible = true;
frmwiz.ShowRebootButton = true;
frmwiz.SetRebootHandler = rebootButton_Click;
}
Expand Down Expand Up @@ -234,71 +224,6 @@ private async void NavigationHelper_OnNavigate(object sender, EventArgs e)
}
}

/// <summary>
/// clears *.db cache files
/// </summary>
private async void ClearIconCache()
{
await Task.Run(() => Interaction.Shell("taskkill.exe /f /im explorer.exe", AppWinStyle.Hide, true));
try
{

DirectoryInfo di = new(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "microsoft", "windows", "explorer"));
var files = di.GetFiles("*.db");

for (var i = 0; i < files.Length; i++)
{
files[i].Attributes = FileAttributes.Normal;
if (File.Exists(files[i].FullName))
{
File.Delete(files[i].FullName);
}
}
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", true);
key?.SetValue("ResetIconCache", Path.Combine(Variables.sys32Folder, "ie4uinit.exe") + " -show", RegistryValueKind.String);
key.Close();
}
catch
{
TaskDialog.Show(text: "deleting icon cache failed",
title: "Rectify11 Setup",
buttons: TaskDialogButtons.OK,
icon: TaskDialogStandardIcon.Information);
}
}

/// <summary>
/// applies the theme just before restart to set the mouse cursor properly
/// </summary>
private async void ApplyScheme()
{
if (InstallOptions.InstallThemes)
{
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", true);
string s = "e";
if (key != null)
{
if (InstallOptions.ThemeLight)
{
await Task.Run(() => Process.Start(Path.Combine(Variables.Windir, "Resources", "Themes", "lightrectified.theme")));
s = Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " apply " + '"' + "Rectify11 light theme" + '"';
}
else if (InstallOptions.ThemeDark)
{
await Task.Run(() => Process.Start(Path.Combine(Variables.Windir, "Resources", "Themes", "darkrectified.theme")));
s = Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " apply " + '"' + "Rectify11 dark theme" + '"';
}
else
{
await Task.Run(() => Process.Start(Path.Combine(Variables.Windir, "Resources", "Themes", "black.theme")));
s = Path.Combine(Variables.r11Folder, "SecureUXHelper.exe") + " apply " + '"' + "Rectify11 Dark theme with Mica" + '"';
}
}
key.SetValue("ApplyTheme", s, RegistryValueKind.String);
key.SetValue("DeleteJunk", "rmdir /s /q " + Path.Combine(Environment.SpecialFolder.LocalApplicationData.ToString(), "junk"), RegistryValueKind.String);
key.Close();
}
}

/// <summary>
/// goes to the next text in the list to be shown
Expand Down Expand Up @@ -332,11 +257,16 @@ private void NextText()
/// </summary>
private void RestartRoutine()
{
timer2.Stop();
frmwiz.InstallerProgress = "Restarting...";
ApplyScheme();
ClearIconCache();
NativeMethods.Reboot();
//ApplyScheme();
//ClearIconCache();
Variables.isInstall = false;
Variables.IsUninstall = true;
if (r1.Checked)
{
NativeMethods.Reboot();
}
else if (r2.Checked)
Application.Exit();
}

private void timer1_Tick(object sender, EventArgs e)
Expand All @@ -349,15 +279,6 @@ private async void rebootButton_Click(object sender, EventArgs e)
await Task.Run(() => RestartRoutine());
}

private async void Timer2_Tick(object sender, EventArgs e)
{
duration -= 1;
frmwiz.InstallerProgress = "Restarting in " + duration.ToString() + " seconds";
if (duration == 0)
{
await Task.Run(() => RestartRoutine());
}
}
#endregion
}
}
1 change: 1 addition & 0 deletions Rectify11Installer/Pages/ThemeChoicePage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e69a527

Please sign in to comment.