diff --git a/src/MSCFixer/Features/UI/DarkMode.cs b/src/MSCFixer/Features/UI/DarkMode.cs index 6e37ae0..cbd3782 100644 --- a/src/MSCFixer/Features/UI/DarkMode.cs +++ b/src/MSCFixer/Features/UI/DarkMode.cs @@ -97,6 +97,7 @@ namespace Settings.Personalization try { Registry.SetValue(keyName, valueName, 0, RegistryValueKind.DWord); + Utils.RestartExplorer(); // Restart Explorer to apply changes return Task.FromResult(true); } catch (Exception ex) @@ -112,6 +113,7 @@ namespace Settings.Personalization try { Registry.SetValue(keyName, valueName, 1, RegistryValueKind.DWord); + Utils.RestartExplorer(); // Restart Explorer to apply changes return true; } catch (Exception ex) diff --git a/src/MSCFixer/Helpers/HelperTool.cs b/src/MSCFixer/Helpers/HelperTool.cs new file mode 100644 index 0000000..318da56 --- /dev/null +++ b/src/MSCFixer/Helpers/HelperTool.cs @@ -0,0 +1,23 @@ +using System.IO; +using System.Windows.Forms; + +namespace HelperTool +{ + internal class Utils + + { + public static class Data + { + public static string DataRootDir = Application.StartupPath + + @"\app\"; + } + + // Create data directory if non present + public static void CreateDataDir() + { + bool dirExists = Directory.Exists(@"app"); + if (!dirExists) + Directory.CreateDirectory(@"app"); + } + } +} \ No newline at end of file diff --git a/src/MSCFixer/Helpers/Logger.cs b/src/MSCFixer/Helpers/Logger.cs new file mode 100644 index 0000000..7c983fc --- /dev/null +++ b/src/MSCFixer/Helpers/Logger.cs @@ -0,0 +1,73 @@ +using System; +using System.Drawing; +using System.Windows.Forms; + +/// +/// A simple logger class to log messages to a RichTextBox. +/// +public static class Logger +{ + public static RichTextBox OutputBox; + + private static readonly Font DefaultFont = new Font("Consolas", 8.25f, FontStyle.Regular); + + public static void Log(string message, LogLevel level = LogLevel.Info) + { + if (OutputBox == null) return; + + if (OutputBox.InvokeRequired) + { + OutputBox.Invoke(new Action(() => LogInternal(message, level))); + } + else + { + LogInternal(message, level); + } + } + + private static void LogInternal(string message, LogLevel level) + { + // string prefix = $"[{DateTime.Now:HH:mm:ss}] [{level}] "; + string fullMessage = message + Environment.NewLine; + + // Set color based on log level + Color color; + switch (level) + { + case LogLevel.Warning: + color = Color.OrangeRed; + break; + + case LogLevel.Error: + color = Color.Red; + break; + + case LogLevel.Custom: + color = Color.Magenta; // for plugins and other custom messages + break; + + default: + color = Color.Black; + break; + } + + // Append text with color + OutputBox.SelectionStart = OutputBox.TextLength; + OutputBox.SelectionLength = 0; + OutputBox.SelectionColor = color; + OutputBox.AppendText(fullMessage); + + // Reset selection to default + OutputBox.SelectionColor = OutputBox.ForeColor; // reset color + OutputBox.SelectionFont = DefaultFont; // reset font + OutputBox.ScrollToCaret(); // scroll to the end + } +} + +public enum LogLevel +{ + Info, + Warning, + Error, + Custom +} \ No newline at end of file diff --git a/src/MSCFixer/Helpers/OSHelper.cs b/src/MSCFixer/Helpers/OSHelper.cs new file mode 100644 index 0000000..bd4e8d7 --- /dev/null +++ b/src/MSCFixer/Helpers/OSHelper.cs @@ -0,0 +1,52 @@ +using System.Collections.ObjectModel; +using System.Management.Automation; +using System.Threading.Tasks; +using Microsoft.Win32; + +// This file is part of MSCFixer. +namespace OSHelper +{ + internal class OSHelper + { + public static async Task GetWindowsVersion() + { + return await Task.Run(() => + { + try + { + using (PowerShell powerShellInstance = PowerShell.Create()) + { + powerShellInstance.AddScript("Get-CimInstance -ClassName Win32_OperatingSystem"); + Collection psOutput = powerShellInstance.Invoke(); + + foreach (PSObject outputItem in psOutput) + { + if (outputItem != null) + { + string productName = outputItem.Properties["Caption"]?.Value?.ToString(); + if (!string.IsNullOrEmpty(productName)) + { + string osVersion = productName.Contains("Windows 10") ? "Windows 10" : "Windows 11"; + + using (RegistryKey displayVersionKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion")) + { + if (displayVersionKey != null) + { + string displayVersion = displayVersionKey.GetValue("DisplayVersion")?.ToString(); + return $"{osVersion} ({displayVersion})"; + } + } + return osVersion; + } + } + } + } + } + catch + { + } + return "OS not supported"; + }); + } + } +} \ No newline at end of file diff --git a/src/MSCFixer/Helpers/Utils.cs b/src/MSCFixer/Helpers/Utils.cs new file mode 100644 index 0000000..ea42a11 --- /dev/null +++ b/src/MSCFixer/Helpers/Utils.cs @@ -0,0 +1,83 @@ +using Microsoft.Win32; +using System.Windows.Forms; +using System; +using System.Diagnostics; + +// This file is part of MSCFixer. +namespace Crapfixer +{ + internal class Utils + { + /// + /// Checks if a registry value is equal to a specified integer. + /// + /// + /// + /// + /// + public static bool IntEquals(string keyName, string valueName, int expectedValue) + { + try + { + var value = Registry.GetValue(keyName, valueName, null); + return (value != null && (int)value == expectedValue); + } + catch (Exception ex) + + { + MessageBox.Show(keyName, ex.Message, MessageBoxButtons.OK); + return false; + } + } + + /// + /// Checks if a registry value is equal to a specified string. + /// + /// + /// + /// + /// + public static bool StringEquals(string keyName, string valueName, string expectedValue) + { + try + { + var value = Registry.GetValue(keyName, valueName, null); + + return (value != null && (string)value == expectedValue); + } + catch (Exception ex) + { + MessageBox.Show(keyName, ex.Message, MessageBoxButtons.OK); + return false; + } + } + + /// + /// Restarts Windows Explorer to apply UI changes. + /// + public static void RestartExplorer() + { + try + { + Logger.Log("Restarting Windows Explorer to apply UI changes...", LogLevel.Info); + + // Kill all explorer instances + foreach (var process in Process.GetProcessesByName("explorer")) + { + process.Kill(); + process.WaitForExit(); + } + + // Restart explorer + Process.Start("explorer.exe"); + + Logger.Log("Explorer restarted successfully. Changes should now be visible.", LogLevel.Info); + } + catch (Exception ex) + { + Logger.Log("Failed to restart Explorer: " + ex.Message, LogLevel.Error); + } + } + + } +} \ No newline at end of file diff --git a/src/MSCFixer/NavigationHandler.cs b/src/MSCFixer/NavigationHandler.cs new file mode 100644 index 0000000..d9d12dc --- /dev/null +++ b/src/MSCFixer/NavigationHandler.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; + +namespace MSCFixer +{ + /// + /// Handles navigation button highlighting for a set of UI buttons. + /// + public class NavigationHandler + { + // List of all buttons managed by the navigation handler + private readonly List