Skip to content

Portable Tool for an Ideal Windows Setup

added more info in the log & organization of paths

Greedeks79b27aceaded
diff --git a/.Source/GTweak/App.xaml.cs b/.Source/GTweak/App.xaml.cs
index 19a8e078..8e7db304 100644
--- a/.Source/GTweak/App.xaml.cs
+++ b/.Source/GTweak/App.xaml.cs
@@ -3,6 +3,7 @@ using GTweak.Utilities.Helpers;
using System;
using System.Globalization;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Threading;
@@ -27,7 +28,7 @@ namespace GTweak
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
- ErrorLogging.LogWritingFile(e.Exception);
+ LogError(e.Exception);
e.Handled = true;
Environment.Exit(0);
}
@@ -35,10 +36,12 @@ namespace GTweak
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject is Exception ex)
- ErrorLogging.LogWritingFile(ex);
+ LogError(ex);
Environment.Exit(0);
}
+ private void LogError(Exception ex, [CallerMemberName] string memberName = "") => ErrorLogging.LogWritingFile(ex, memberName);
+
internal static void UpdateImport() => ImportTweaksUpdate?.Invoke(default, EventArgs.Empty);
internal static void ViewingSettings()
diff --git a/.Source/GTweak/Utilities/Controls/ErrorLogging.cs b/.Source/GTweak/Utilities/Controls/ErrorLogging.cs
index b831c5ba..e82b5611 100644
--- a/.Source/GTweak/Utilities/Controls/ErrorLogging.cs
+++ b/.Source/GTweak/Utilities/Controls/ErrorLogging.cs
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
+using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
@@ -10,18 +11,18 @@ namespace GTweak.Utilities.Controls
{
private static readonly string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GTweak_Error.log");
- internal static void LogWritingFile(Exception ex) => Task.Run(() => LogToFile(ex)).Wait();
+ internal static void LogWritingFile(Exception ex, [CallerMemberName] string memberName = "") => Task.Run(() => LogToFile(ex, memberName)).Wait();
- internal static void LogDebug(Exception ex) => Debug.WriteLine($"Debug: {ex.Message}\nStack Trace: {ex.StackTrace}");
+ internal static void LogDebug(Exception ex, [CallerMemberName] string memberName = "") => Debug.WriteLine($"Debug: {ex.Message}\nStack Trace: {ex.StackTrace}\nMember: {memberName}\n");
- internal static async Task LogToFile(Exception ex)
+ internal static async Task LogToFile(Exception ex, string memberName)
{
try
{
- using var stream = new FileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read);
+ using var stream = new FileStream(logFilePath, FileMode.Append, FileAccess.Write, FileShare.Read);
using var writer = new StreamWriter(stream, new UTF8Encoding(false));
- await writer.WriteLineAsync($"[{DateTime.Now}] Error: {ex.Message}\nStack Trace:\n{ex.StackTrace}\n");
-
+ await writer.WriteLineAsync($"[{DateTime.Now}]\nMember: {memberName}\nError: {ex.Message}\nStack Trace:\n{ex.StackTrace}\n");
+ await writer.FlushAsync();
Process.Start(new ProcessStartInfo
{
FileName = logFilePath,
diff --git a/.Source/GTweak/Utilities/Controls/SettingsRepository.cs b/.Source/GTweak/Utilities/Controls/SettingsRepository.cs
index 9a04dc31..8feb3ed6 100644
--- a/.Source/GTweak/Utilities/Controls/SettingsRepository.cs
+++ b/.Source/GTweak/Utilities/Controls/SettingsRepository.cs
@@ -12,13 +12,18 @@ using System.Runtime.InteropServices;
namespace GTweak.Utilities.Controls
{
[StructLayout(LayoutKind.Sequential)]
- internal readonly struct StoragePaths
+ internal struct StoragePaths
{
internal static string Config = string.Empty;
internal static string FolderLocation => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"GTweak");
internal static string SystemDisk => Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));
internal static string HostsFile => Path.Combine(Environment.SystemDirectory, @"drivers\etc\hosts");
- internal static string RegistryLocation = @"HKEY_CURRENT_USER\Software\GTweak";
+
+ internal static string PowFile => Path.Combine(FolderLocation, "UltimatePerformance.pow");
+
+ internal static string IconBlank => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Blank.ico");
+
+ internal static string RegistryLocation => @"HKEY_CURRENT_USER\Software\GTweak";
}
internal sealed class SettingsRepository
diff --git a/.Source/GTweak/Utilities/Helpers/Managers/ExplorerManager.cs b/.Source/GTweak/Utilities/Helpers/Managers/ExplorerManager.cs
index 0a70b570..68f6d836 100644
--- a/.Source/GTweak/Utilities/Helpers/Managers/ExplorerManager.cs
+++ b/.Source/GTweak/Utilities/Helpers/Managers/ExplorerManager.cs
@@ -9,8 +9,8 @@ namespace GTweak.Utilities.Helpers.Managers
{
internal class ExplorerManager
{
- internal static readonly Dictionary<string, bool> InterfBtnMapping = new[]
- {
+ internal static readonly Dictionary<string, bool> InterfBtnMapping = new[]
+ {
new { Button = "TglButton7", NeedRestart = true },
new { Button = "TglButton8", NeedRestart = true },
new { Button = "TglButton17", NeedRestart = true },
diff --git a/.Source/GTweak/Utilities/Helpers/Storage/TaskStorage.cs b/.Source/GTweak/Utilities/Helpers/Storage/TaskStorage.cs
index b3726cda..c88ff015 100644
--- a/.Source/GTweak/Utilities/Helpers/Storage/TaskStorage.cs
+++ b/.Source/GTweak/Utilities/Helpers/Storage/TaskStorage.cs
@@ -3,67 +3,66 @@
internal class TaskStorage
{
internal static readonly string[] dataCollectTasks = {
- @"Microsoft\Windows\Maintenance\WinSAT",
- @"Microsoft\Windows\Autochk\Proxy",
- @"Microsoft\Windows\Application Experience\Microsoft Compatibility Appraiser",
- @"Microsoft\Windows\Application Experience\ProgramDataUpdater",
- @"Microsoft\Windows\Application Experience\StartupAppTask",
- @"Microsoft\Windows\PI\Sqm-Tasks",
- @"Microsoft\Windows\NetTrace\GatherNetworkInfo",
- @"Microsoft\Windows\Customer Experience Improvement Program\Consolidator",
- @"Microsoft\Windows\Customer Experience Improvement Program\KernelCeipTask",
- @"Microsoft\Windows\Customer Experience Improvement Program\UsbCeip",
- @"Microsoft\Windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticResolver",
- @"Microsoft\Windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticDataCollector" };
+ @"\Microsoft\Windows\Maintenance\WinSAT",
+ @"\Microsoft\Windows\Autochk\Proxy",
+ @"\Microsoft\Windows\Application Experience\Microsoft Compatibility Appraiser",
+ @"\Microsoft\Windows\Application Experience\ProgramDataUpdater",
+ @"\Microsoft\Windows\Application Experience\StartupAppTask",
+ @"\Microsoft\Windows\PI\Sqm-Tasks",
+ @"\Microsoft\Windows\NetTrace\GatherNetworkInfo",
+ @"\Microsoft\Windows\Customer Experience Improvement Program\Consolidator",
+ @"\Microsoft\Windows\Customer Experience Improvement Program\KernelCeipTask",
+ @"\Microsoft\Windows\Customer Experience Improvement Program\UsbCeip",
+ @"\Microsoft\Windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticResolver",
+ @"\Microsoft\Windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticDataCollector" };
internal static readonly string[] nvidiaTasks = {
- @"NvTmRepOnLogon_{B2FE1952-0186-46C3-BAEC-A80AA35AC5B8}",
- @"NvTmRep_{B2FE1952-0186-46C3-BAEC-A80AA35AC5B8}",
- @"NvTmMon_{B2FE1952-0186-46C3-BAEC-A80AA35AC5B8}" };
+ @"\NvTmRepOnLogon_{B2FE1952-0186-46C3-BAEC-A80AA35AC5B8}",
+ @"\NvTmRep_{B2FE1952-0186-46C3-BAEC-A80AA35AC5B8}",
+ @"\NvTmMon_{B2FE1952-0186-46C3-BAEC-A80AA35AC5B8}" };
internal static readonly string[] telemetryTasks = {
- @"Microsoft\Office\Office ClickToRun Service Monitor",
- @"Microsoft\Office\OfficeTelemetry\AgentFallBack2016",
- @"Microsoft\Office\OfficeTelemetry\OfficeTelemetryAgentLogOn2016",
- @"Microsoft\Office\OfficeTelemetryAgentFallBack2016",
- @"Microsoft\Office\OfficeTelemetryAgentLogOn2016",
- @"Microsoft\Office\OfficeTelemetryAgentFallBack",
- @"Microsoft\Office\OfficeTelemetryAgentLogOn",
- @"Microsoft\Office\Office 15 Subscription Heartbeat" };
+ @"\Microsoft\Office\Office ClickToRun Service Monitor",
+ @"\Microsoft\Office\OfficeTelemetry\AgentFallBack2016",
+ @"\Microsoft\Office\OfficeTelemetry\OfficeTelemetryAgentLogOn2016",
+ @"\Microsoft\Office\OfficeTelemetryAgentFallBack2016",
+ @"\Microsoft\Office\OfficeTelemetryAgentLogOn2016",
+ @"\Microsoft\Office\OfficeTelemetryAgentFallBack",
+ @"\Microsoft\Office\OfficeTelemetryAgentLogOn",
+ @"\Microsoft\Office\Office 15 Subscription Heartbeat" };
internal static readonly string[] winUpdatesTasks = {
- @"Microsoft\Windows\UpdateOrchestrator\Report policies",
- @"Microsoft\Windows\UpdateOrchestrator\Schedule Scan",
- @"Microsoft\Windows\UpdateOrchestrator\Schedule Scan Static Task",
- @"Microsoft\Windows\UpdateOrchestrator\Schedule Work",
- @"Microsoft\Windows\UpdateOrchestrator\Start Oobe Expedite Work",
- @"Microsoft\Windows\UpdateOrchestrator\StartOobeAppsScanAfterUpdate",
- @"Microsoft\Windows\UpdateOrchestrator\StartOobeAppsScan_LicenseAccepted",
- @"Microsoft\Windows\UpdateOrchestrator\USO_UxBroker",
- @"Microsoft\Windows\UpdateOrchestrator\UUS Failover Task",
- @"Microsoft\Windows\WindowsUpdate\Refresh Group Policy Cache",
- @"Microsoft\Windows\WindowsUpdate\Scheduled Start"};
+ @"\Microsoft\Windows\UpdateOrchestrator\Report policies",
+ @"\Microsoft\Windows\UpdateOrchestrator\Schedule Scan",
+ @"\Microsoft\Windows\UpdateOrchestrator\Schedule Scan Static Task",
+ @"\Microsoft\Windows\UpdateOrchestrator\Schedule Work",
+ @"\Microsoft\Windows\UpdateOrchestrator\Start Oobe Expedite Work",
+ @"\Microsoft\Windows\UpdateOrchestrator\StartOobeAppsScanAfterUpdate",
+ @"\Microsoft\Windows\UpdateOrchestrator\StartOobeAppsScan_LicenseAccepted",
+ @"\Microsoft\Windows\UpdateOrchestrator\USO_UxBroker",
+ @"\Microsoft\Windows\UpdateOrchestrator\UUS Failover Task",
+ @"\Microsoft\Windows\WindowsUpdate\Refresh Group Policy Cache",
+ @"\Microsoft\Windows\WindowsUpdate\Scheduled Start" };
internal static readonly string[] memoryDiagTasks = {
@"Microsoft\Windows\MemoryDiagnostic\ProcessMemoryDiagnosticEvents",
@"Microsoft\Windows\MemoryDiagnostic\RunFullMemoryDiagnostic" };
- internal static readonly string restoreTask = @"Microsoft\Windows\SystemRestore\SR";
- internal static readonly string defragTask = @"Microsoft\Windows\Defrag\ScheduledDefrag";
+ internal static readonly string restoreTask = @"\Microsoft\Windows\SystemRestore\SR";
+ internal static readonly string defragTask = @"\Microsoft\Windows\Defrag\ScheduledDefrag";
internal static readonly string[] edgeTasks = {
- @"MicrosoftEdgeUpdateTaskMachineUA{EA17DF76-AE5F-45F8-8867-FE5E0DD06656}",
- @"MicrosoftEdgeUpdateTaskMachineCore{11EED34D-1A62-4BB7-9A2E-0D83ED6A609F}",
- @"MicrosoftEdgeUpdateTaskMachineCore*",
- @"MicrosoftEdgeUpdateTaskMachineUA*",
- @"MicrosoftEdgeUpdateTaskUser*" };
+ @"\MicrosoftEdgeUpdateTaskMachineUA{EA17DF76-AE5F-45F8-8867-FE5E0DD06656}",
+ @"\MicrosoftEdgeUpdateTaskMachineCore{11EED34D-1A62-4BB7-9A2E-0D83ED6A609F}",
+ @"\MicrosoftEdgeUpdateTaskMachineCore*",
+ @"\MicrosoftEdgeUpdateTaskMachineUA*",
+ @"\MicrosoftEdgeUpdateTaskUser*" };
internal static readonly string[] WinDefenderTasks = {
- @"Microsoft\Windows\ExploitGuard\ExploitGuard MDM policy Refresh",
- @"Microsoft\Windows\Windows Defender\Windows Defender Cache Maintenance",
- @"Microsoft\Windows\Windows Defender\Windows Defender Cleanup",
- @"Microsoft\Windows\Windows Defender\Windows Defender Scheduled Scan",
- @"Microsoft\Windows\Windows Defender\Windows Defender Verification",
- };
+ @"\Microsoft\Windows\ExploitGuard\ExploitGuard MDM policy Refresh",
+ @"\Microsoft\Windows\Windows Defender\Windows Defender Cache Maintenance",
+ @"\Microsoft\Windows\Windows Defender\Windows Defender Cleanup",
+ @"\Microsoft\Windows\Windows Defender\Windows Defender Scheduled Scan",
+ @"\Microsoft\Windows\Windows Defender\Windows Defender Verification", };
}
}
diff --git a/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs b/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs
index 3452b82c..627a7dcd 100644
--- a/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/InterfaceTweaks.cs
@@ -218,12 +218,12 @@ namespace GTweak.Utilities.Tweaks
{
if (isChoose)
{
- new UnarchiveManager($@"{Environment.GetFolderPath(Environment.SpecialFolder.Windows)}\Blank.ico", Properties.Resources.Blank);
+ new UnarchiveManager(StoragePaths.IconBlank, Properties.Resources.Blank);
RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons", "29", @"%systemroot%\\Blank.ico,0", RegistryValueKind.String);
}
else
{
- File.Delete($@"{Environment.GetFolderPath(Environment.SpecialFolder.Windows)}\Blank.ico");
+ File.Delete(StoragePaths.IconBlank);
RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons");
}
});
diff --git a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
index af4c8370..ebe1a3b9 100644
--- a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
@@ -409,9 +409,7 @@ namespace GTweak.Utilities.Tweaks
},
};
- string searchScheme = default,
- unlockFrequency = @"-attributes SUB_PROCESSOR 75b0ae3f-bce0-45a7-8c89-c9611c25e100 -ATTRIB_HIDE",
- pathTempFile = StoragePaths.FolderLocation + @"\UltimatePerformance.pow";
+ string searchScheme = default, unlockFrequency = @"-attributes SUB_PROCESSOR 75b0ae3f-bce0-45a7-8c89-c9611c25e100 -ATTRIB_HIDE";
try
{
@@ -438,13 +436,13 @@ namespace GTweak.Utilities.Tweaks
if (string.IsNullOrEmpty(searchScheme))
{
- new UnarchiveManager(pathTempFile, Properties.Resources.Ultimate_Performance_pow);
+ new UnarchiveManager(StoragePaths.PowFile, Properties.Resources.Ultimate_Performance_pow);
string _guid = Guid.NewGuid().ToString("D");
using (_powercfg)
{
- _powercfg.StartInfo.Arguments = $@"-import ""{pathTempFile}"" {_guid}";
+ _powercfg.StartInfo.Arguments = $@"-import ""{StoragePaths.PowFile}"" {_guid}";
_powercfg.Start();
await Task.Delay(5);
diff --git a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
index 1275d83b..b04f53c1 100644
--- a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
+++ b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
@@ -114,7 +114,7 @@ namespace GTweak.Utilities.Tweaks
await RunPowerShell($"{argument} \"Get-AppxProvisionedPackage -online | where-object {{$_.PackageName -like '*{packageName}*'}} | Remove-AppxProvisionedPackage -alluser -online –Verbose\"");
- foreach (string getScript in Scripts)
+ foreach (string getScript in Scripts ?? Enumerable.Empty<string>())
{
TrustedInstaller.CreateProcessAsTrustedInstaller(SettingsRepository.PID, $@"cmd.exe /c for /d %i in (""{pathPackage}\*{getScript}*"") do rd /s /q ""%i""");
await RunPowerShell($"{argument} \"Get-AppxPackage -Name {getScript} -AllUsers | Remove-AppxPackage\"");