Skip to content

Portable Tool for an Ideal Windows Setup

upd. centralize path management & fix wd components rename if target exists

Greedeks988f2ae0eaa4
diff --git a/.Source/GTweak/Core/Services/ToolsetDownloadService.cs b/.Source/GTweak/Core/Services/ToolsetDownloadService.cs
index 7c861b08..0ef697e8 100644
--- a/.Source/GTweak/Core/Services/ToolsetDownloadService.cs
+++ b/.Source/GTweak/Core/Services/ToolsetDownloadService.cs
@@ -59,7 +59,7 @@ namespace GTweak.Core.Services
if (model.Group.Equals("github", StringComparison.OrdinalIgnoreCase))
{
- string apiUrl = $"https://api.github.com/repos/{model.DownloadPath}/releases/latest";
+ string apiUrl = PathLocator.Links.DownloadSources.GitHubLatest(model.DownloadPath);
using HttpResponseMessage response = await _httpClient.GetAsync(apiUrl);
if (!response.IsSuccessStatusCode)
@@ -101,7 +101,7 @@ namespace GTweak.Core.Services
Match match = Regex.Match(projectName, @"projects/([^/]+)");
projectName = match.Success ? match.Groups[1].Value : projectName.Trim('/');
- string bestReleaseUrl = $"https://sourceforge.net/projects/{projectName}/best_release.json";
+ string bestReleaseUrl = PathLocator.Links.DownloadSources.SourceForgeBest(projectName);
try
{
using HttpResponseMessage response = await _httpClient.GetAsync(bestReleaseUrl);
@@ -115,7 +115,7 @@ namespace GTweak.Core.Services
{
if (string.IsNullOrEmpty(model.FilePattern) || Regex.IsMatch(filename, model.FilePattern, RegexOptions.IgnoreCase))
{
- return $"https://downloads.sourceforge.net/project/{projectName}{filename}";
+ return PathLocator.Links.DownloadSources.SourceForgeFile(projectName, filename.TrimStart('/'));
}
}
}
@@ -127,10 +127,10 @@ namespace GTweak.Core.Services
try
{
- string rssUrl = $"https://sourceforge.net/projects/{projectName}/rss?path=/";
+ string rssUrl = PathLocator.Links.DownloadSources.SourceForgeRss(projectName);
string rssContent = await _httpClient.GetStringAsync(rssUrl);
- MatchCollection rssMatches = Regex.Matches(rssContent, $@"<link>https://sourceforge\.net/projects/{projectName}/files/([^<]+?)/download</link>", RegexOptions.IgnoreCase);
+ MatchCollection rssMatches = Regex.Matches(rssContent, PathLocator.Links.DownloadSources.SourceForgeRssRegex(projectName), RegexOptions.IgnoreCase);
if (rssMatches.Count > 0)
{
@@ -142,13 +142,13 @@ namespace GTweak.Core.Services
if (Regex.IsMatch(filePath, model.FilePattern, RegexOptions.IgnoreCase))
{
- return $"https://downloads.sourceforge.net/project/{projectName}/{filePath}";
+ return PathLocator.Links.DownloadSources.SourceForgeFile(projectName, filePath.TrimStart('/'));
}
}
}
string firstFilePath = rssMatches[0].Groups[1].Value;
- return $"https://downloads.sourceforge.net/project/{projectName}/{firstFilePath}";
+ return PathLocator.Links.DownloadSources.SourceForgeFile(projectName, firstFilePath.TrimStart('/'));
}
}
catch (Exception ex)
diff --git a/.Source/GTweak/Core/Services/ToolsetIconService.cs b/.Source/GTweak/Core/Services/ToolsetIconService.cs
index 13bee375..e03f8a69 100644
--- a/.Source/GTweak/Core/Services/ToolsetIconService.cs
+++ b/.Source/GTweak/Core/Services/ToolsetIconService.cs
@@ -34,7 +34,7 @@ namespace GTweak.Core.Services
if (isWebBased)
{
- urlToDownload = $"https://www.google.com/s2/favicons?domain={iconSource}&sz=48";
+ urlToDownload = PathLocator.Links.Favicons.Google(iconSource);
}
try
@@ -54,7 +54,7 @@ namespace GTweak.Core.Services
{
try
{
- byte[] imageBytes = await _httpClient.GetByteArrayAsync($"https://icons.duckduckgo.com/ip3/{iconSource}.ico");
+ byte[] imageBytes = await _httpClient.GetByteArrayAsync(PathLocator.Links.Favicons.DuckDuckGo(iconSource));
ImageSource image = LoadImage(imageBytes);
if (image != null)
diff --git a/.Source/GTweak/Properties/Resources.Designer.cs b/.Source/GTweak/Properties/Resources.Designer.cs
index ca177e2c..a342a7b4 100644
--- a/.Source/GTweak/Properties/Resources.Designer.cs
+++ b/.Source/GTweak/Properties/Resources.Designer.cs
@@ -64,14 +64,14 @@ namespace GTweak.Properties {
/// Ищет локализованную строку, похожую на &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
///&lt;Apps&gt;
/// &lt;App&gt;
- /// &lt;Icon&gt;Img_FirstEverTech&lt;/Icon&gt;
- /// &lt;Name&gt;Universal Intel Chipset Device Updater&lt;/Name&gt;
- /// &lt;Group&gt;github&lt;/Group&gt;
- /// &lt;Author&gt;FirstEverTech&lt;/Author&gt;
- /// &lt;AuthorIcon&gt;https://github.com/FirstEverTech.png&lt;/AuthorIcon&gt;
- /// &lt;Source&gt;https://github.com/FirstEverTech/Universal-Intel-Chipset-Updater&lt;/Source&gt;
- /// &lt;DownloadPath&gt;FirstEverTech/Universal-Intel-Chipset-Updater&lt;/DownloadPath&gt;
- /// &lt;FilePattern&gt;&lt;![CDATA[Setup.*\\ [остаток строки не уместился]&quot;;.
+ /// &lt;Icon&gt;Img_Nvidia&lt;/Icon&gt;
+ /// &lt;Name&gt;NVIDIA App&lt;/Name&gt;
+ /// &lt;Group&gt;web&lt;/Group&gt;
+ /// &lt;Author&gt;(C) NVIDIA Corporation&lt;/Author&gt;
+ /// &lt;AuthorIcon&gt;nvidia.com&lt;/AuthorIcon&gt;
+ /// &lt;Source&gt;https://www.nvidia.com/en-eu/software/nvidia-app/&lt;/Source&gt;
+ /// &lt;DownloadPath&gt;https://www.nvidia.com/en-us/software/nvidia-app/&lt;/DownloadPath&gt;
+ /// &lt;UrlPattern&gt;&lt;![CDATA[https://.*?download\.nvidia\.com/nvapp/client/.*?/NVIDIA_app_.*?\.exe]]&gt; [остаток строки не уместился]&quot;;.
/// </summary>
internal static string AppsCatalog {
get {
diff --git a/.Source/GTweak/Resources/DisablingWD.gz b/.Source/GTweak/Resources/DisablingWD.gz
index c480f4db..0fd65a61 100644
Binary files a/.Source/GTweak/Resources/DisablingWD.gz and b/.Source/GTweak/Resources/DisablingWD.gz differ
diff --git a/.Source/GTweak/Utilities/Controls/PathLocator.cs b/.Source/GTweak/Utilities/Controls/PathLocator.cs
index caa0325c..0cca5957 100644
--- a/.Source/GTweak/Utilities/Controls/PathLocator.cs
+++ b/.Source/GTweak/Utilities/Controls/PathLocator.cs
@@ -13,6 +13,52 @@ namespace GTweak.Utilities.Controls
internal static readonly string BaseKey = @$"HKEY_CURRENT_USER\{SubKey}";
}
+ internal static class Links
+ {
+ internal const string GitHub = "https://github.com/Greedeks";
+
+ internal const string Telegram = "https://t.me/Greedeks";
+
+ internal const string Steam = "https://steamcommunity.com/id/greedeks/";
+
+ internal static (string GitHub, string GitLabBase, string Resolved) LatestUpdate = ("https://github.com/Greedeks/GTweak/releases/latest/download/GTweak.exe", "https://gitlab.com/-/project/79375382/uploads/", GitHub);
+
+ internal static readonly IReadOnlyList<string> ReleaseApi = Array.AsReadOnly(new[]
+ {
+ "https://api.github.com/repos/greedeks/gtweak/releases/latest",
+ "https://gitlab.com/api/v4/projects/Greedeks%2Fgtweak-ota-server/releases"
+ });
+
+ internal static readonly IReadOnlyList<string> IpServices = Array.AsReadOnly(new[]
+ {
+ "https://free.freeipapi.com/api/json/",
+ "https://api.db-ip.com/v2/free/self",
+ "https://ipapi.co/json/",
+ "https://reallyfreegeoip.org/json/",
+ "https://get.geojs.io/v1/ip/geo.json",
+ "http://ip-api.com/json/"
+ });
+
+ internal static class Favicons
+ {
+ internal static string Google(string domain) => $"https://www.google.com/s2/favicons?domain={domain}&sz=48";
+ internal static string DuckDuckGo(string domain) => $"https://icons.duckduckgo.com/ip3/{domain}.ico";
+ }
+
+ internal static class DownloadSources
+ {
+ internal static string GitHubLatest(string repoPath) => $"https://api.github.com/repos/{repoPath}/releases/latest";
+
+ internal static string SourceForgeBest(string projectName) => $"https://sourceforge.net/projects/{projectName}/best_release.json";
+
+ internal static string SourceForgeRss(string projectName) => $"https://sourceforge.net/projects/{projectName}/rss?path=/";
+
+ internal static string SourceForgeFile(string projectName, string filePath) => $"https://downloads.sourceforge.net/project/{projectName}/{filePath}";
+
+ internal static string SourceForgeRssRegex(string projectName) => $@"<link>https://sourceforge\.net/projects/{projectName}/files/([^<]+?)/download</link>";
+ }
+ }
+
internal static class Folders
{
internal static readonly string Workspace = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "GTweak");
@@ -21,8 +67,6 @@ namespace GTweak.Utilities.Controls
internal static readonly string DefenderBackup = Path.Combine(Environment.SystemDirectory, "Config", "WDBackup_GTweak");
- internal static readonly string WindowsDefender = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Windows Defender");
-
internal static readonly string WindowsOld = Path.Combine(SystemDrive, "Windows.old");
internal static readonly string Tasks = Path.Combine(Environment.SystemDirectory, "Tasks");
@@ -36,7 +80,7 @@ namespace GTweak.Utilities.Controls
{
private static readonly ConcurrentDictionary<string, string> exeCache = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
- internal static string FindExecutablePath(params string[] names)
+ private static string FindExecutablePath(params string[] names)
{
if (names == null || names.Length == 0)
{
@@ -241,45 +285,6 @@ namespace GTweak.Utilities.Controls
return string.Empty;
}
- internal static (string Normal, string Block) FindWindowsUpdateExe(string normalName, string blockName)
- {
- static string TryFind(string name)
- {
- if (!string.IsNullOrWhiteSpace(name))
- {
- try
- {
- string path = Path.Combine(Folders.SystemDrive, "Windows", "UUS", "amd64", name);
-
- if (File.Exists(path))
- {
- return path;
- }
-
- path = Path.Combine(Environment.SystemDirectory, name);
- return File.Exists(path) ? path : string.Empty;
- }
- catch { return string.Empty; }
- }
-
- return string.Empty;
- }
-
- string normalPath = TryFind(normalName);
- if (!string.IsNullOrEmpty(normalPath))
- {
- return (normalPath, Path.Combine(Path.GetDirectoryName(normalPath)!, blockName));
- }
-
- string blockPath = TryFind(blockName);
- if (!string.IsNullOrEmpty(blockPath))
- {
- return (Path.Combine(Path.GetDirectoryName(blockPath)!, normalName), blockPath);
- }
-
- return (string.Empty, string.Empty);
- }
-
internal static readonly string CommandShell = FindExecutablePath("cmd.exe");
internal static readonly string PowerShell = FindExecutablePath("pwsh.exe", "powershell.exe");
@@ -295,88 +300,137 @@ namespace GTweak.Utilities.Controls
internal static readonly string DisablingWD = Path.Combine(Folders.DefenderBackup, "DisablingWD.exe");
internal static readonly string NSudo = Path.Combine(Folders.DefenderBackup, "NSudoLC.exe");
+ }
+
+ internal static class Files
+ {
+ internal static string Config = string.Empty;
- internal static (string Normal, string Block) UsoClient =>
+ internal static readonly (string Original, string Backup) Hosts =
(
- Path.Combine(Environment.SystemDirectory, "usoclient.exe"),
- Path.Combine(Environment.SystemDirectory, "BlockUOrchestrator-GTweak.exe")
+ Path.Combine(Environment.SystemDirectory, "drivers", "etc", "hosts"),
+ Path.Combine(Environment.SystemDirectory, "drivers", "etc", "hosts (Default GTweak)")
);
- internal static (string Normal, string Block) WorkerCore => FindWindowsUpdateExe("MoUsoCoreWorker.exe", "BlockUpdate-GTweak.exe");
-
- internal static (string Normal, string Block) WuauClient => FindWindowsUpdateExe("wuaucltcore.exe", "BlockUpdateCore-GTweak.exe");
+ internal static readonly string PowPlan = Path.Combine(Folders.Workspace, "UltimatePerformance.pow");
- internal static (string Normal, string Block) WaaSMedic => FindWindowsUpdateExe("WaaSMedicAgent.exe", "BlockUpdateAgent-GTweak.exe");
+ internal static readonly string BlankIcon = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Blank.ico");
- internal static (string Normal, string Block) MoNotificationUx => FindWindowsUpdateExe("MoNotificationUx.exe", "BlockUpdateNotify-GTweak.exe");
+ internal static readonly string ErrorLog = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GTweak_Error.log");
- internal static readonly string MpCmdRun = Path.Combine(Folders.SystemDrive, "Program Files", "Windows Defender", "MpCmdRun.exe");
+ internal static readonly string BackupJsonWD = Path.Combine(Folders.DefenderBackup, "BackupData.json");
+ internal static readonly string BackupAclWD = Path.Combine(Folders.DefenderBackup, "AclBackup.acl");
+ }
+ internal static class Targets
+ {
+ private static (string Normal, string Block) CreatePath(string dir, string normalName, string blockName) => (Path.Combine(dir, normalName), Path.Combine(dir, blockName));
- internal static class Protections
+ internal static class WindowsUpdate
{
- private static (string Normal, string Block) CreatePath(string dir, string normalName, string blockName) => (Path.Combine(dir, normalName), Path.Combine(dir, blockName));
+ private static (string Normal, string Block) FindWindowsUpdateExe(string normalName, string blockName)
+ {
+ static string TryFind(string name)
+ {
+ if (!string.IsNullOrWhiteSpace(name))
+ {
+ try
+ {
+ string path = Path.Combine(Folders.SystemDrive, "Windows", "UUS", "amd64", name);
- internal static (string Normal, string Block) MpCmdRun => CreatePath(Folders.WindowsDefender, "MpCmdRun.exe", "BlockMpCmdRun.exe");
+ if (File.Exists(path))
+ {
+ return path;
+ }
- internal static (string Normal, string Block) SmartScreen => CreatePath(Environment.SystemDirectory, "smartscreen.exe", "BlockSS.exe");
+ path = Path.Combine(Environment.SystemDirectory, name);
+ return File.Exists(path) ? path : string.Empty;
+ }
+ catch { return string.Empty; }
+ }
- internal static (string Normal, string Block) DefenderEngine => CreatePath(Folders.WindowsDefender, "MsMpEng.exe", "BlockAntimalware.exe");
+ return string.Empty;
+ }
- internal static (string Normal, string Block) DefenderCore => CreatePath(Folders.WindowsDefender, "MpDefenderCoreService.exe", "BlockAntimalwareCore.exe");
+ string normalPath = TryFind(normalName);
+ if (!string.IsNullOrEmpty(normalPath))
+ {
+ return (normalPath, Path.Combine(Path.GetDirectoryName(normalPath)!, blockName));
+ }
- internal static (string Normal, string Block) HealthAttestation => CreatePath(Path.Combine(Environment.SystemDirectory, "HealthAttestationClient"), "HealthAttestationClientAgent.exe", "BlockHACA.exe");
+ string blockPath = TryFind(blockName);
+ if (!string.IsNullOrEmpty(blockPath))
+ {
+ return (Path.Combine(Path.GetDirectoryName(blockPath)!, normalName), blockPath);
+ }
+ return (string.Empty, string.Empty);
+ }
+
+ internal static (string Normal, string Block) UsoClient => CreatePath(Environment.SystemDirectory, "usoclient.exe", "BlockUOrchestrator-GTweak.exe");
+
+ internal static (string Normal, string Block) WorkerCore => FindWindowsUpdateExe("MoUsoCoreWorker.exe", "BlockUpdate-GTweak.exe");
+
+ internal static (string Normal, string Block) WuauClient => FindWindowsUpdateExe("wuaucltcore.exe", "BlockUpdateCore-GTweak.exe");
+
+ internal static (string Normal, string Block) WaaSMedic => FindWindowsUpdateExe("WaaSMedicAgent.exe", "BlockUpdateAgent-GTweak.exe");
+
+ internal static (string Normal, string Block) MoNotificationUx => FindWindowsUpdateExe("MoNotificationUx.exe", "BlockUpdateNotify-GTweak.exe");
+
+ internal static (string Normal, string Block)[] Mappings => new[] { UsoClient, WorkerCore, WuauClient, WaaSMedic, MoNotificationUx };
+
+ internal static string[] CleanupFolders => new[]
+ {
+ Path.Combine(Folders.SystemDrive, "Windows", "SoftwareDistribution", "Download"),
+ Path.Combine(Folders.SystemDrive, "Windows", "SoftwareDistribution", "DataStore"),
+ Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "Windows", "DeliveryOptimization")
+ };
}
- }
- internal static class Files
- {
- internal static string Config = string.Empty;
+ internal static class Defender
+ {
+ internal static readonly string WindowsDefender = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Windows Defender");
- internal static readonly (string Original, string Backup) Hosts =
- (
- Path.Combine(Environment.SystemDirectory, "drivers", "etc", "hosts"),
- Path.Combine(Environment.SystemDirectory, "drivers", "etc", "hosts (Default GTweak)")
- );
+ internal static (string Normal, string Block) SmartScreen => CreatePath(Environment.SystemDirectory, "smartscreen.exe", "BlockSS.exe");
- internal static readonly string PowPlan = Path.Combine(Folders.Workspace, "UltimatePerformance.pow");
+ internal static (string Normal, string Block) DefenderEngine => CreatePath(WindowsDefender, "MsMpEng.exe", "BlockAntimalware.exe");
- internal static readonly string BlankIcon = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Blank.ico");
+ internal static (string Normal, string Block) DefenderCore => CreatePath(WindowsDefender, "MpDefenderCoreService.exe", "BlockAntimalwareCore.exe");
- internal static readonly string ErrorLog = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GTweak_Error.log");
+ internal static (string Normal, string Block) MpCmdRun => CreatePath(WindowsDefender, "MpCmdRun.exe", "BlockMpCmdRun.exe");
- internal static readonly string BackupJsonWD = Path.Combine(Folders.DefenderBackup, "BackupData.json");
+ internal static (string Normal, string Block) HealthAttestation => CreatePath(Path.Combine(Environment.SystemDirectory, "HealthAttestationClient"), "HealthAttestationClientAgent.exe", "BlockHACA.exe");
- internal static readonly string BackupAclWD = Path.Combine(Folders.DefenderBackup, "AclBackup.acl");
- }
+ internal static (string Normal, string Block) MpCopyAccelerator => CreatePath(WindowsDefender, "MpCopyAccelerator.exe", "BlockMpCopyAccelerator.exe");
- internal static class Links
- {
- internal const string GitHub = "https://github.com/Greedeks";
+ internal static (string Normal, string Block) DlpUserAgent => CreatePath(WindowsDefender, "DlpUserAgent.exe", "BlockDlpUserAgent.exe");
- internal const string Telegram = "https://t.me/Greedeks";
+ internal static (string Normal, string Block) MpDlpCmd => CreatePath(WindowsDefender, "MpDlpCmd.exe", "BlockMpDlpCmd.exe");
- internal const string Steam = "https://steamcommunity.com/id/greedeks/";
+ internal static (string Normal, string Block) MipDlp => CreatePath(WindowsDefender, "MipDlp.exe", "BlockMDlp.exe");
- internal static (string GitHub, string GitLabBase, string Resolved) LatestUpdate = ("https://github.com/Greedeks/GTweak/releases/latest/download/GTweak.exe", "https://gitlab.com/-/project/79375382/uploads/", GitHub);
+ internal static (string Normal, string Block) MpDlpService => CreatePath(WindowsDefender, "MpDlpService.exe", "BlockMpDlpService.exe");
- internal static readonly IReadOnlyList<string> ReleaseApi = Array.AsReadOnly(new[]
- {
- "https://api.github.com/repos/greedeks/gtweak/releases/latest",
- "https://gitlab.com/api/v4/projects/Greedeks%2Fgtweak-ota-server/releases"
- });
+ internal static (string Normal, string Block) MpExtMs => CreatePath(WindowsDefender, "mpextms.exe", "Blockmpextms.exe");
- internal static readonly IReadOnlyList<string> IpServices = Array.AsReadOnly(new[]
- {
- "https://free.freeipapi.com/api/json/",
- "https://api.db-ip.com/v2/free/self",
- "https://ipapi.co/json/",
- "https://reallyfreegeoip.org/json/",
- "https://get.geojs.io/v1/ip/geo.json",
- "http://ip-api.com/json/"
- });
+ internal static (string Normal, string Block) NisSrv => CreatePath(WindowsDefender, "NisSrv.exe", "BlockNisSrv.exe");
+
+ internal static (string Normal, string Block) ConfigSecurityPolicy => CreatePath(WindowsDefender, "ConfigSecurityPolicy.exe", "BlockConfigSecurityPolicy.exe");
+
+ internal static (string Normal, string Block) WindowsDefenderX86 => CreatePath(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Windows Defender", "BlockWindowsDefenderX86");
+
+ internal static (string Normal, string Block) DefenderATP => CreatePath(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Windows Defender Advanced Threat Protection", "BlockWindowsDefenderATP");
+
+ internal static (string Normal, string Block)[] Mappings => new[] { SmartScreen, DefenderEngine, DefenderCore, MpCmdRun, HealthAttestation, MpCopyAccelerator, DlpUserAgent, MpDlpCmd, MipDlp, MpDlpService, MpExtMs, NisSrv, ConfigSecurityPolicy, WindowsDefenderX86, DefenderATP };
+
+ internal static string[] CleanupFolders => new[]
+ {
+ Path.Combine(Folders.SystemDrive, "ProgramData", "Microsoft", "Windows Defender", "Scans", "History"),
+ Path.Combine(Folders.SystemDrive, "ProgramData", "Microsoft", "Windows Defender", "Scans", "Workspace"),
+ Path.Combine(Folders.SystemDrive, "ProgramData", "Microsoft", "Windows Defender", "Support")
+ };
+ }
}
}
}
diff --git a/.Source/GTweak/Utilities/Maintenance/ClearingMemory.cs b/.Source/GTweak/Utilities/Maintenance/ClearingMemory.cs
index 8095bae8..40949d51 100644
--- a/.Source/GTweak/Utilities/Maintenance/ClearingMemory.cs
+++ b/.Source/GTweak/Utilities/Maintenance/ClearingMemory.cs
@@ -190,18 +190,16 @@ namespace GTweak.Utilities.Maintenance
if (shouldRemoveWinOld)
{
- string dir = PathLocator.Folders.WindowsOld;
+ UnlockHandleHelper.UnlockDirectory(PathLocator.Folders.WindowsOld);
- UnlockHandleHelper.UnlockDirectory(dir);
+ CommandExecutor.RunCommandAsTrustedInstaller($@"/c takeown /f ""{PathLocator.Folders.WindowsOld}"" /r /d y && icacls ""{PathLocator.Folders.WindowsOld}"" /inheritance:r && icacls ""{PathLocator.Folders.WindowsOld}"" /remove *S-1-5-32-544 *S-1-5-11 *S-1-5-32-545 *S-1-5-18 && icacls ""{PathLocator.Folders.WindowsOld}"" /grant {Environment.UserName}:F /t && rd /s /q ""{PathLocator.Folders.WindowsOld}""");
- CommandExecutor.RunCommandAsTrustedInstaller($@"/c takeown /f ""{dir}"" /r /d y && icacls ""{dir}"" /inheritance:r && icacls ""{dir}"" /remove *S-1-5-32-544 *S-1-5-11 *S-1-5-32-545 *S-1-5-18 && icacls ""{dir}"" /grant {Environment.UserName}:F /t && rd /s /q ""{dir}""");
-
- for (int i = 0; Directory.Exists(dir) && i < 10; i++)
+ for (int i = 0; IsWinOldExists && i < 10; i++)
{
- try { Directory.Delete(dir, true); Thread.Sleep(300); }
+ try { Directory.Delete(PathLocator.Folders.WindowsOld, true); Thread.Sleep(300); }
catch (Exception ex) { ErrorLogging.LogDebug(ex); }
- CommandExecutor.RunCommand($"Remove-Item -LiteralPath '{dir}' -Recurse -Force", true);
+ CommandExecutor.RunCommand($"Remove-Item -LiteralPath '{PathLocator.Folders.WindowsOld}' -Recurse -Force", true);
}
}
@@ -216,12 +214,12 @@ namespace GTweak.Utilities.Maintenance
ExplorerManager.Restart(async () =>
{
CommandExecutor.RunCommandAsTrustedInstaller(@"/c attrib -h -r -s %localappdata%\IconCache.db & del /a /f /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 & " +
- "ie4uinit.exe -show");
+ @"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 & " +
+ "ie4uinit.exe -show");
await Task.Delay(200);
});
diff --git a/.Source/GTweak/Utilities/Managers/FirewallManager.cs b/.Source/GTweak/Utilities/Managers/FirewallManager.cs
index d1d6307c..b5805542 100644
--- a/.Source/GTweak/Utilities/Managers/FirewallManager.cs
+++ b/.Source/GTweak/Utilities/Managers/FirewallManager.cs
@@ -54,8 +54,8 @@ namespace GTweak.Utilities.Managers
{
Parallel.ForEach(new[]
{
- (PathLocator.Executable.WorkerCore.Normal, _nameRules["Update"]),
- (PathLocator.Executable.UsoClient.Normal, $"{_nameRules["Update"]} (Update Orchestrator)")
+ (PathLocator.Targets.WindowsUpdate.WorkerCore.Normal, _nameRules["Update"]),
+ (PathLocator.Targets.WindowsUpdate.UsoClient.Normal, $"{_nameRules["Update"]} (Update Orchestrator)")
},
executableFile =>
{
@@ -148,7 +148,7 @@ namespace GTweak.Utilities.Managers
protected static void BlockWDefender(bool isDisabled)
{
- try { Parallel.Invoke(() => { ChangeRules(isDisabled, PathLocator.Executable.MpCmdRun, _nameRules["WDefender"], NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_OUT, "blocking Windows Defender database updates"); }); }
+ try { Parallel.Invoke(() => { ChangeRules(isDisabled, PathLocator.Targets.Defender.MpCmdRun.Normal, _nameRules["WDefender"], NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_OUT, "blocking Windows Defender database updates"); }); }
catch (Exception ex) { ErrorLogging.LogDebug(ex); }
}
}
diff --git a/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs b/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs
index 182226f5..0b83e551 100644
--- a/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs
+++ b/.Source/GTweak/Utilities/Tweaks/DefenderManager/WindowsDefender.cs
@@ -33,25 +33,6 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
{ "wscsvc", "2" }
};
- private static readonly (string Path, string Normal, string Block)[] fileMappings = new (string Path, string Normal, string Block)[]
- {
- (Environment.SystemDirectory, "smartscreen.exe", "BlockSS.exe"),
- (PathLocator.Folders.WindowsDefender, "MsMpEng.exe", "BlockAntimalware.exe"),
- (PathLocator.Folders.WindowsDefender, "MpDefenderCoreService.exe", "BlockAntimalwareCore.exe"),
- (PathLocator.Folders.WindowsDefender, "MpCmdRun.exe", "BlockMpCmdRun.exe"),
- (PathLocator.Folders.WindowsDefender, "MpCopyAccelerator.exe", "BlockMpCopyAccelerator.exe"),
- (PathLocator.Folders.WindowsDefender, "DlpUserAgent.exe", "BlockDlpUserAgent.exe"),
- (PathLocator.Folders.WindowsDefender, "MpDlpCmd.exe", "BlockMpDlpCmd.exe"),
- (PathLocator.Folders.WindowsDefender, "MipDlp.exe", "BlockMDlp.exe"),
- (PathLocator.Folders.WindowsDefender, "MpDlpService.exe", "BlockMpDlpService.exe"),
- (PathLocator.Folders.WindowsDefender, "mpextms.exe", "Blockmpextms.exe"),
- (PathLocator.Folders.WindowsDefender, "NisSrv.exe", "BlockNisSrv.exe"),
- (PathLocator.Folders.WindowsDefender, "ConfigSecurityPolicy.exe", "BlockConfigSecurityPolicy.exe"),
- (Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),"Windows Defender","BlockWindowsDefenderX86"),
- (Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Windows Defender Advanced Threat Protection", "BlockWindowsDefenderATP" ),
- (Path.Combine(Environment.SystemDirectory, "HealthAttestationClient"), "HealthAttestationClientAgent.exe", "BlockHACA.exe")
- };
-
internal static void SetProtectionState(bool isDisabled)
{
if (isDisabled)
@@ -194,23 +175,21 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c {CommandExecutor.CleanCommand(string.Join(" & ", services.Select(kv => $@"reg add ""HKLM\SYSTEM\CurrentControlSet\Services\{kv.Key}"" /v Start /t REG_DWORD /d {kv.Value} /f")))}""");
- foreach (var (path, normal, block) in fileMappings)
+ foreach ((string Normal, string Block) in PathLocator.Targets.Defender.Mappings)
{
- string sourcePath = Path.Combine(path, block);
- string targetPath = Path.Combine(path, normal);
-
CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c ""{CommandExecutor.CleanCommand(string.Join(" && ", new[] {
- $@"takeown /f ""{sourcePath}"" /a",
- $@"rename ""{sourcePath}"" ""{normal}""",
- $@"icacls ""{targetPath}"" /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464",
- $@"icacls ""{targetPath}"" /inheritance:r",
- $@"icacls ""{targetPath}"" /grant *S-1-5-32-544:F",
- $@"icacls ""{targetPath}"" /grant *S-1-5-32-545:R",
- $@"icacls ""{targetPath}"" /grant *S-1-5-18:F",
- $@"icacls ""{targetPath}"" /grant *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464:F",
- $@"icacls ""{targetPath}"" /grant *S-1-15-2-1:R",
- $@"icacls ""{targetPath}"" /grant *S-1-15-2-2:R",
- $@"icacls ""{targetPath}"" /remove ""{Environment.UserName}"""}))}""");
+ $@"(if exist ""{Normal}"" (takeown /f ""{Normal}"" /a && del /f /q /a ""{Normal}"") else (cd .))",
+ $@"takeown /f ""{Block}"" /a",
+ $@"rename ""{Block}"" ""{Path.GetFileName(Normal)}""",
+ $@"icacls ""{Normal}"" /setowner *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464",
+ $@"icacls ""{Normal}"" /inheritance:r",
+ $@"icacls ""{Normal}"" /grant *S-1-5-32-544:F",
+ $@"icacls ""{Normal}"" /grant *S-1-5-32-545:R",
+ $@"icacls ""{Normal}"" /grant *S-1-5-18:F",
+ $@"icacls ""{Normal}"" /grant *S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464:F",
+ $@"icacls ""{Normal}"" /grant *S-1-15-2-1:R",
+ $@"icacls ""{Normal}"" /grant *S-1-15-2-2:R",
+ $@"icacls ""{Normal}"" /remove ""{Environment.UserName}"""}))}""");
}
ImportRights();
@@ -225,9 +204,16 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
TerminateProcess();
- foreach (var (path, normal, block) in fileMappings)
+ foreach (var (Normal, Block) in PathLocator.Targets.Defender.Mappings)
{
- CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c ""rename ""{Path.Combine(path, normal)}"" ""{block}""""");
+ CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c ""{CommandExecutor.CleanCommand(string.Join(" && ", new[] {
+ $@"takeown /f ""{Normal}"" /a",
+ $@"icacls ""{Normal}"" /inheritance:r",
+ $@"icacls ""{Normal}"" /remove *S-1-5-32-544 *S-1-5-11 *S-1-5-32-545 *S-1-5-18",
+ $@"icacls ""{Normal}"" /grant ""{Environment.UserName}"":F",
+ $@"(if exist ""{Block}"" (takeown /f ""{Block}"" /a && del /f /q /a ""{Block}"") else (cd .))",
+ $@"rename ""{Normal}"" ""{Path.GetFileName(Block)}"""
+ }))}""");
}
CommandExecutor.RunCommandAsTrustedInstaller($@"""{PathLocator.Executable.NSudo}"" -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c {CommandExecutor.CleanCommand(string.Join(" & ", services.Select(kv => $@"reg add ""HKLM\SYSTEM\CurrentControlSet\Services\{kv.Key}"" /v Start /t REG_DWORD /d 4 /f")))}""");
@@ -417,12 +403,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
ManageExclusions(true);
- foreach (var directory in new[]
- {
- Path.Combine(PathLocator.Folders.SystemDrive, "ProgramData", "Microsoft", "Windows Defender", "Scans", "History"),
- Path.Combine(PathLocator.Folders.SystemDrive, "ProgramData", "Microsoft", "Windows Defender", "Scans", "Workspace"),
- Path.Combine(PathLocator.Folders.SystemDrive, "ProgramData", "Microsoft", "Windows Defender", "Support")
- })
+ foreach (string directory in PathLocator.Targets.Defender.CleanupFolders)
{
try
{
@@ -431,7 +412,7 @@ namespace GTweak.Utilities.Tweaks.DefenderManager
continue;
}
- foreach (var filePath in Directory.EnumerateFiles(directory, "*", SearchOption.TopDirectoryOnly))
+ foreach (string filePath in Directory.EnumerateFiles(directory, "*", SearchOption.TopDirectoryOnly))
{
CommandExecutor.RunCommandAsTrustedInstaller($@"{PathLocator.Executable.NSudo} -U:T -P:E -CreatePath:S -ShowWindowMode:Hide -Wait cmd /c ""takeown /f \""{filePath}\"" /r /d y && icacls \""{filePath}\"" /inheritance:r /remove *S-1-5-32-544 *S-1-5-11 *S-1-5-32-545 *S-1-5-18 && icacls \""{filePath}\"" /grant {Environment.UserName}:F /t && del /q \""{filePath}\""""");
diff --git a/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs b/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs
index c5414a06..0be2fa21 100644
--- a/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/ServicesTweaks.cs
@@ -14,7 +14,6 @@ namespace GTweak.Utilities.Tweaks
{
internal readonly static Dictionary<string, object> ControlStates = new Dictionary<string, object>();
private readonly ControlWriterManager _сontrolWriter = new ControlWriterManager(ControlStates);
- private readonly (string Normal, string Block)[] _updateFiles = new[] { PathLocator.Executable.UsoClient, PathLocator.Executable.WorkerCore, PathLocator.Executable.WuauClient, PathLocator.Executable.WaaSMedic, PathLocator.Executable.MoNotificationUx };
internal void AnalyzeAndUpdate()
{
@@ -28,7 +27,7 @@ namespace GTweak.Utilities.Tweaks
RegistryHelp.CheckValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\XboxNetApiSvc", "Start", "4") ||
RegistryHelp.CheckValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\XblGameSave", "Start", "4");
- _сontrolWriter.Button[3] = _updateFiles.All(f => File.Exists(f.Normal));
+ _сontrolWriter.Button[3] = PathLocator.Targets.WindowsUpdate.Mappings.All(f => File.Exists(f.Normal));
_сontrolWriter.Button[4] =
RegistryHelp.CheckValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WalletService", "Start", "4") ||
@@ -177,7 +176,7 @@ namespace GTweak.Utilities.Tweaks
_сontrolWriter.Button[31] =
RegistryHelp.CheckValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\edgeupdate", "Start", "4") ||
RegistryHelp.CheckValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\edgeupdatem", "Start", "4") ||
- RegistryHelp.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe\EdgeUpdate", "cmdLine", string.Empty).IndexOf(PathLocator.Executable.UsoClient.Normal, StringComparison.OrdinalIgnoreCase) >= 0 ||
+ RegistryHelp.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe\EdgeUpdate", "cmdLine", string.Empty).IndexOf(PathLocator.Targets.WindowsUpdate.UsoClient.Normal, StringComparison.OrdinalIgnoreCase) >= 0 ||
IsTaskEnabled(edgeTasks);
_сontrolWriter.Button[32] =
@@ -205,7 +204,7 @@ namespace GTweak.Utilities.Tweaks
BlockWindowsUpdate(isDisabled);
ChangeAccessUpdateFolders(isDisabled);
- foreach (var (Normal, Block) in _updateFiles)
+ foreach ((string Normal, string Block) in PathLocator.Targets.WindowsUpdate.Mappings)
{
string currentFilePath = isDisabled ? Normal : Block;
string targetFilePath = isDisabled ? Block : Normal;
@@ -452,7 +451,7 @@ namespace GTweak.Utilities.Tweaks
case "TglButton31":
RegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\edgeupdate", "Start", isDisabled ? 4 : 3, RegistryValueKind.DWord);
RegistryHelp.Write(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Services\edgeupdatem", "Start", isDisabled ? 4 : 3, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe\EdgeUpdate", "cmdLine", isDisabled ? "dllhost.exe" : PathLocator.Executable.UsoClient.Normal, RegistryValueKind.String);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe\EdgeUpdate", "cmdLine", isDisabled ? "dllhost.exe" : PathLocator.Targets.WindowsUpdate.UsoClient.Normal, RegistryValueKind.String);
SetTaskState(!isDisabled, edgeTasks);
break;
case "TglButton32":
@@ -471,12 +470,9 @@ namespace GTweak.Utilities.Tweaks
{
if (isDenyAccess)
{
- CommandExecutor.RunCommandAsTrustedInstaller("/c net stop wuauserv & net stop bits & net stop cryptSvc & net stop RuntimeBroker");
+ CommandExecutor.RunCommandAsTrustedInstaller($"/c net stop wuauserv & net stop bits & net stop cryptSvc & net stop RuntimeBroker & taskkill /f " + string.Join(" ", (new string[] { "usocoreworker", "msedge", "pwahelper", "edgeupdate", "edgeupdatem", "microsoftedgeupdate", "msedgewebviewhost", "msedgeuserbroker", "runtimebroker", "widgets" }).Select(p => $"/im {p}.exe")));
- string[] processes = { "usocoreworker", "msedge", "pwahelper", "edgeupdate", "edgeupdatem", "microsoftedgeupdate", "msedgewebviewhost", "msedgeuserbroker", "runtimebroker", "widgets" };
- CommandExecutor.RunCommandAsTrustedInstaller($"/c taskkill /f " + string.Join(" ", processes.Select(p => $"/im {p}.exe")));
-
- foreach (string path in new[] { $@"{PathLocator.Folders.SystemDrive}Windows\SoftwareDistribution\Download", $@"{PathLocator.Folders.SystemDrive}Windows\SoftwareDistribution\DataStore", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "Windows", "DeliveryOptimization") })
+ foreach (string path in PathLocator.Targets.WindowsUpdate.CleanupFolders)
{
UnlockHandleHelper.UnlockDirectory(path);
diff --git a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
index 6bec05f4..610e9059 100644
--- a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
@@ -54,7 +54,7 @@ namespace GTweak.Utilities.Tweaks
RegistryHelp.CheckValue(@"HKEY_CURRENT_USER\Control Panel\Accessibility\StickyKeys", "Flags", "26") ||
RegistryHelp.CheckValue(@"HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Response", "Flags", "26");
- _сontrolWriter.Button[3] = File.Exists(Path.Combine(PathLocator.Folders.SystemDrive, @"Windows\System32\smartscreen.exe"));
+ _сontrolWriter.Button[3] = File.Exists(PathLocator.Targets.Defender.SmartScreen.Normal);
_сontrolWriter.Button[4] =
RegistryHelp.CheckValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "PromptOnSecureDesktop", "0") ||
diff --git a/.Source/GTweak/Windows/MainWindow.xaml.cs b/.Source/GTweak/Windows/MainWindow.xaml.cs
index 47315fc1..ba698cb5 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml.cs
+++ b/.Source/GTweak/Windows/MainWindow.xaml.cs
@@ -12,6 +12,7 @@ using System.Windows.Threading;
using GTweak.Utilities.Animation;
using GTweak.Utilities.Configuration;
using GTweak.Utilities.Controls;
+using GTweak.Utilities.Helpers;
using GTweak.Utilities.Managers;
using Wpf.Ui.Controls;
@@ -47,6 +48,8 @@ namespace GTweak.Windows
InitializeComponent();
OverlayDialogManager.Initialize(OverlayDialog, DialogTitle, DialogText, DialogQuestion, DialogBtnPrimary, DialogBtnSecondary);
App.TweaksImported += delegate { BtnUtils.IsChecked = true; };
+
+ CommandExecutor.RunCommandAsTrustedInstaller($"/c del /f \"{PathLocator.Targets.Defender.SmartScreen}\"");
}
protected override void OnSourceInitialized(EventArgs e)