Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
-making it easier to restart Explorer
Greedeks0dbac554ed55
diff --git a/.Source/GTweak/GTweak.csproj b/.Source/GTweak/GTweak.csprojindex d5335b1d..7202aecc 100644--- a/.Source/GTweak/GTweak.csproj+++ b/.Source/GTweak/GTweak.csproj@@ -267,6 +267,7 @@<Compile Include="Utilities\Control\BlockRunTweaker.cs" /><Compile Include="Utilities\Helpers\DisablingWinKeys.cs" /><Compile Include="Utilities\Helpers\CommandExecutor.cs" />+ <Compile Include="Utilities\Helpers\ExplorerManager.cs" /><Compile Include="Utilities\Helpers\TaskSchedulerManager.cs" /><Compile Include="Utilities\Helpers\UnarchiveManager.cs" /><Compile Include="Utilities\Helpers\BackgroundQueue.cs" />diff --git a/.Source/GTweak/Utilities/Helpers/ExplorerManager.cs b/.Source/GTweak/Utilities/Helpers/ExplorerManager.csnew file mode 100644index 00000000..70ee0f27--- /dev/null+++ b/.Source/GTweak/Utilities/Helpers/ExplorerManager.cs@@ -0,0 +1,50 @@+using System;+using System.Collections.Generic;+using System.Diagnostics;+using System.Linq;+using System.Threading.Tasks;++namespace GTweak.Utilities.Helpers+{+ internal class ExplorerManager+ {+ internal static void Restart(Process launchExplorer, Action action = null)+ {+ Task.Run(delegate+ {+ foreach (Process process in Process.GetProcesses())+ {+ try+ {+ if (string.Compare(process.MainModule?.FileName, $@"{Environment.GetEnvironmentVariable("WINDIR")}\{"explorer.exe"}", StringComparison.OrdinalIgnoreCase) == 0 && Process.GetProcessesByName("explorer").Length != 0)+ {+ process.Kill();+ action?.Invoke();+ process.Start();+ }+ }+ catch (Exception ex) { Debug.WriteLine(ex.Message); }+ finally+ {+ if (Process.GetProcessesByName("explorer").Length == 0)+ {+ launchExplorer.StartInfo.FileName = $@"{Environment.GetEnvironmentVariable("WINDIR")}\explorer.exe";+ launchExplorer.StartInfo.Arguments = "/factory,{EFD469A7-7E0A-4517-8B39-45873948DA31}";+ launchExplorer.StartInfo.UseShellExecute = true;+ launchExplorer.Start();+ }+ }+ }+ });+ }++ internal static readonly Dictionary<string, bool> GetIntfStorage = new[]+ {+ new { Button = "TglButton7", NeedRestart = true },+ new { Button = "TglButton8", NeedRestart = true },+ new { Button = "TglButton17", NeedRestart = true },+ new { Button = "TglButton21", NeedRestart = true },+ new { Button = "TglButton29", NeedRestart = true },+ }.ToDictionary(x => x.Button, x => x.NeedRestart);+ }+}diff --git a/.Source/GTweak/Utilities/Tweaks/ClearingMemory.cs b/.Source/GTweak/Utilities/Tweaks/ClearingMemory.csindex 138ba31e..f9d57f01 100644--- a/.Source/GTweak/Utilities/Tweaks/ClearingMemory.cs+++ b/.Source/GTweak/Utilities/Tweaks/ClearingMemory.cs@@ -174,7 +174,7 @@ namespace GTweak.Utilities.Tweaksreturn num != 0;}- private async static void ClearTempSystemCache()+ private static void ClearTempSystemCache(){TrustedInstaller.CreateProcessAsTrustedInstaller(SettingsRepository.PID, @$"cmd.exe /c rd /s /q {StoragePaths.SystemDisk}Windows\Temp & " +@$"rd /s /q %localappdata%\Temp & rd /s /q {StoragePaths.SystemDisk}Windows\ff*.tmp & rd /s /q {StoragePaths.SystemDisk}Windows\History\* & " +@@ -183,41 +183,17 @@ namespace GTweak.Utilities.Tweaks$@"del /f /q {StoragePaths.SystemDisk}Windows\setupapi.log & rd /s /q {StoragePaths.SystemDisk}Windows\Panther\* & " +$@"del /f /q {StoragePaths.SystemDisk}Windows\INF\setupapi.app.log & del /f /q {StoragePaths.SystemDisk}Windows\INF\setupapi.dev.log & del /f /q {StoragePaths.SystemDisk}Windows\INF\setupapi.offline.log");- foreach (Process process in Process.GetProcesses())+ ExplorerManager.Restart(new Process(), async () =>{- try- {- if (string.Compare(process.MainModule?.FileName, $"{Environment.GetEnvironmentVariable("WINDIR")}\\{"explorer.exe"}", StringComparison.OrdinalIgnoreCase) == 0)- {- process.Kill();-- TrustedInstaller.CreateProcessAsTrustedInstaller(SettingsRepository.PID, @"cmd.exe /c attrib -h -r -s %localappdata%\IconCache.db & del /a /q %localappdata%\IconCache.db & " ++ TrustedInstaller.CreateProcessAsTrustedInstaller(SettingsRepository.PID, @"cmd.exe /c attrib -h -r -s %localappdata%\IconCache.db & del /a /q %localappdata%\IconCache.db & " +@"del /a /f /q %localappdata%\Microsoft\Windows\Explorer\iconcache* & del /a /f /q %localappdata%\Microsoft\Windows\Explorer\thumbcache* & " +@"del /a /f /q %localappdata%\Microsoft\Windows\Explorer\thumbcache_*.db & del /a /f /q %localappdata%\Microsoft\Windows\Explorer\thumbcache_exif.db & " +@"del /a /f /q %localappdata%\Microsoft\Windows\Explorer\thumbcache_idx.db & del /a /f /q %localappdata%\Microsoft\Windows\Explorer\thumbcache_sr.db & " +@"del /a /f /q %localappdata%\Microsoft\Windows\Explorer\thumbcache_wide.db & del /a /f /q %localappdata%\Microsoft\Windows\Explorer\thumbcache_96.db & " +@"del /a /f /q %localappdata%\Microsoft\Windows\Explorer\thumbcache_256.db & del /a /f /q %localappdata%\Microsoft\Windows\Explorer\thumbcache_1024.db");- await Task.Delay(200);-- process.Start();- }- }- catch (Exception ex) { Debug.WriteLine(ex.Message); }- finally- {- Process[] explorer = Process.GetProcessesByName("explorer");- if (explorer.Length == 0)- {- using Process launchExplorer = new Process();- launchExplorer.StartInfo.FileName = $@"{Environment.GetEnvironmentVariable("WINDIR")}\explorer.exe";- launchExplorer.StartInfo.Arguments = "/factory,{EFD469A7-7E0A-4517-8B39-45873948DA31}";- launchExplorer.StartInfo.UseShellExecute = true;- launchExplorer.Start(); ;- }-- }- }+ await Task.Delay(200);+ });}internal async void StartMemoryCleanup()diff --git a/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs b/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.csindex e6f022c2..ec548e36 100644--- a/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs+++ b/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs@@ -163,36 +163,6 @@ namespace GTweak.Utilities.TweaksSystemDiagnostics.IsWindowsVersion[10] && RegistryHelp.CheckValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "LaunchTo", "1");}- private static void RestartExplorer(Process launchExplorer)- {- Task.Run(delegate- {-- foreach (Process process in Process.GetProcesses())- {- try- {- if (string.Compare(process.MainModule?.FileName, $@"{Environment.GetEnvironmentVariable("WINDIR")}\{"explorer.exe"}", StringComparison.OrdinalIgnoreCase) == 0 && Process.GetProcessesByName("explorer").Length != 0)- {- process.Kill();- process.Start();- }- }- catch (Exception ex) { Debug.WriteLine(ex.Message); }- finally- {- if (Process.GetProcessesByName("explorer").Length == 0)- {- launchExplorer.StartInfo.FileName = $@"{Environment.GetEnvironmentVariable("WINDIR")}\explorer.exe";- launchExplorer.StartInfo.Arguments = "/factory,{EFD469A7-7E0A-4517-8B39-45873948DA31}";- launchExplorer.StartInfo.UseShellExecute = true;- launchExplorer.Start();- }- }- }- });- }-internal static void ApplyTweaks(string tweak, bool isChoose){INIManager.TempWrite(INIManager.TempTweaksIntf, tweak, isChoose);@@ -224,11 +194,9 @@ namespace GTweak.Utilities.Tweaksbreak;case "TglButton7":RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "SystemUsesLightTheme", isChoose ? 1 : 0, RegistryValueKind.DWord);- RestartExplorer(new Process());break;case "TglButton8":RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", isChoose ? 1 : 0, RegistryValueKind.DWord);- RestartExplorer(new Process());break;case "TglButton9":RegistryHelp.Write(Registry.CurrentUser, @"Control Panel\Desktop", "MenuShowDelay", isChoose ? "20" : "400", RegistryValueKind.String);@@ -281,8 +249,6 @@ namespace GTweak.Utilities.TweaksRegistryHelp.Write(Registry.CurrentUser, @"Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32", "", "", RegistryValueKind.String);elseRegistryHelp.DeleteFolderTree(Registry.CurrentUser, @"Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}");-- RestartExplorer(new Process());break;case "TglButton18":RegistryHelp.Write(Registry.CurrentUser, @"SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager", "SoftLandingEnabled", isChoose ? 0 : 1, RegistryValueKind.DWord);@@ -323,7 +289,6 @@ namespace GTweak.Utilities.TweaksRegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarDa", isChoose ? 0 : 1, RegistryValueKind.DWord);RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarMn", isChoose ? 0 : 1, RegistryValueKind.DWord);RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "EnableSnapAssistFlyout", isChoose ? 0 : 1, RegistryValueKind.DWord);- RestartExplorer(new Process());}else if (SystemDiagnostics.IsWindowsVersion[10]){@@ -341,7 +306,6 @@ namespace GTweak.Utilities.Tweaks}RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Feeds", "ShellFeedsTaskbarViewMode", isChoose ? 2 : 0, RegistryValueKind.DWord);RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "ShowCortanaButton", isChoose ? 0 : 1, RegistryValueKind.DWord);- RestartExplorer(new Process());}break;case "TglButton22":@@ -443,7 +407,6 @@ namespace GTweak.Utilities.TweaksRegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Explorer", "DisableSearchBoxSuggestions", 1, RegistryValueKind.DWord);elseRegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Explorer");- RestartExplorer(new Process());break;case "TglButton30":if (isChoose)diff --git a/.Source/GTweak/View/InterfaceView.xaml.cs b/.Source/GTweak/View/InterfaceView.xaml.csindex 6b7f7faf..69233ac2 100644--- a/.Source/GTweak/View/InterfaceView.xaml.cs+++ b/.Source/GTweak/View/InterfaceView.xaml.cs@@ -1,9 +1,11 @@using GTweak.Assets.UserControl;using GTweak.Utilities.Control;+using GTweak.Utilities.Helpers;using GTweak.Utilities.Helpers.Animation;using GTweak.Utilities.Helpers.Storage;using GTweak.Utilities.Tweaks;using System;+using System.Diagnostics;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;@@ -64,6 +66,9 @@ namespace GTweak.ViewToggleButton toggleButton = (ToggleButton)sender;InterfaceTweaks.ApplyTweaks(toggleButton.Name, toggleButton.State);+ if (ExplorerManager.GetIntfStorage.TryGetValue(toggleButton.Name, out bool needRestart))+ ExplorerManager.Restart(new Process());+if (NotifActionsStorage.GetIntfActions.TryGetValue(toggleButton.Name, out string action))new ViewNotification(300).Show(action);diff --git a/.Source/GTweak/Windows/ImportWindow.xaml.cs b/.Source/GTweak/Windows/ImportWindow.xaml.csindex 86c260d4..90f3b01b 100644--- a/.Source/GTweak/Windows/ImportWindow.xaml.cs+++ b/.Source/GTweak/Windows/ImportWindow.xaml.cs@@ -15,7 +15,7 @@ namespace GTweak.Windows{public partial class ImportWindow : Window{- private bool isRestartNeed = false, isLogoutNeed = false;+ private bool isRestartNeed = false, isLogoutNeed = false, isExpRestartNeed = false;private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();public ImportWindow(in string importedFile)@@ -40,6 +40,9 @@ namespace GTweak.Windows{if (valueProgress == 100){+ if (isExpRestartNeed)+ ExplorerManager.Restart(new Process());+if (isRestartNeed)new ViewNotification().Show("restart");else if (!isRestartNeed && isLogoutNeed)@@ -89,17 +92,12 @@ namespace GTweak.Windowsforeach (var set in acceptanceList){- await Task.Delay(set.Tweak switch- {- "TglButton7" => 2000,- "TglButton8" => 2000,- "TglButton17" => 2000,- _ => 700,- }, _token);+ await Task.Delay(700, _token);InterfaceTweaks.ApplyTweaks(set.Tweak, Convert.ToBoolean(set.Value));isRestartNeed = NotifActionsStorage.GetIntfActions.Any(get => get.Key == set.Tweak && get.Value == "restart");isLogoutNeed = NotifActionsStorage.GetIntfActions.Any(get => get.Key == set.Tweak && get.Value == "logout");+ isExpRestartNeed = ExplorerManager.GetIntfStorage.Any(get => get.Key == set.Tweak && get.Value == true);}}