Skip to content

Portable Tool for an Ideal Windows Setup

-refact the method and improving the firewall rules change

Greedeksc808fac152e6
diff --git a/.Source/GTweak/GTweak.csproj b/.Source/GTweak/GTweak.csproj
index 112f678c..07e5dade 100644
--- a/.Source/GTweak/GTweak.csproj
+++ b/.Source/GTweak/GTweak.csproj
@@ -276,7 +276,7 @@
<Compile Include="Utilities\Helpers\Storage\NotifActionsStorage.cs" />
<Compile Include="Utilities\Tweaks\ClearingMemory.cs" />
<Compile Include="Utilities\Helpers\INIManager.cs" />
- <Compile Include="Utilities\Control\QueryUpdates.cs" />
+ <Compile Include="Utilities\Configuration\QueryUpdates.cs" />
<Compile Include="Utilities\Configuration\MonitoringSystem.cs" />
<Compile Include="Utilities\Configuration\SystemDiagnostics.cs" />
<Compile Include="Utilities\Control\ViewNotification.cs" />
diff --git a/.Source/GTweak/Utilities/Control/QueryUpdates.cs b/.Source/GTweak/Utilities/Configuration/QueryUpdates.cs
similarity index 91%
rename from .Source/GTweak/Utilities/Control/QueryUpdates.cs
rename to .Source/GTweak/Utilities/Configuration/QueryUpdates.cs
index 35172d7b..605350f0 100644
--- a/.Source/GTweak/Utilities/Control/QueryUpdates.cs
+++ b/.Source/GTweak/Utilities/Configuration/QueryUpdates.cs
@@ -1,8 +1,9 @@
-using Newtonsoft.Json;
+using GTweak.Utilities.Control;
+using Newtonsoft.Json;
using System.IO;
using System.Net;
-namespace GTweak.Utilities.Control
+namespace GTweak.Utilities.Configuration
{
internal sealed class QueryUpdates
{
@@ -26,6 +27,7 @@ namespace GTweak.Utilities.Control
webRequest.ContentType = "application/json";
webRequest.UserAgent = "Nothing";
+ webRequest.Timeout = 5000;
using HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
using StreamReader sreader = new StreamReader(response.GetResponseStream());
diff --git a/.Source/GTweak/Utilities/Tweaks/Firewall.cs b/.Source/GTweak/Utilities/Tweaks/Firewall.cs
index cb72e711..d0684943 100644
--- a/.Source/GTweak/Utilities/Tweaks/Firewall.cs
+++ b/.Source/GTweak/Utilities/Tweaks/Firewall.cs
@@ -21,8 +21,8 @@ namespace GTweak.Utilities.Tweaks
private static readonly SortedList<string, string> PathsForPrograms = new SortedList<string, string>
{
- ["MoUso_New"] = string.Concat(StoragePaths.SystemDisk, @"Windows\UUS\amd64\MoUsoCoreWorker.exe"),
- ["MoUso_Old"] = string.Concat(StoragePaths.SystemDisk, @"Windows\System32\MoUsoCoreWorker.exe"),
+ ["MoUso"] = File.Exists($@"{StoragePaths.SystemDisk}Windows\UUS\amd64\MoUsoCoreWorker.exe")
+ ? $@"{StoragePaths.SystemDisk}Windows\UUS\amd64\MoUsoCoreWorker.exe" : $@"{StoragePaths.SystemDisk}Windows\System32\MoUsoCoreWorker.exe",
["Uso"] = string.Concat(StoragePaths.SystemDisk, @"Windows\System32\usoclient.exe"),
["WD"] = string.Concat(StoragePaths.SystemDisk, @"Program Files\Windows Defender\MpCmdRun.exe"),
};
@@ -43,65 +43,39 @@ namespace GTweak.Utilities.Tweaks
{
try
{
- Parallel.Invoke(() =>
+ Parallel.ForEach(new[]
{
- ChangeRulesIn(isChoose, File.Exists(PathsForPrograms["MoUso_New"]) ? PathsForPrograms["MoUso_New"] : PathsForPrograms["MoUso_Old"], NameRules["Update"]);
- ChangeRulesIn(isChoose, PathsForPrograms["Uso"], string.Concat(NameRules["Update"], " (Update Orchestrator)"));
- });
- }
- catch { new ViewNotification().Show("", "warn", (string)Application.Current.Resources["firewalloff_notification"]); }
-
- try
- {
- Parallel.Invoke(() =>
+ (PathsForPrograms["MoUso"], NameRules["Update"]),
+ (PathsForPrograms["Uso"], $"{NameRules["Update"]} (Update Orchestrator)")
+ },
+ executableFiles =>
{
- ChangeRulesOut(isChoose, File.Exists(PathsForPrograms["MoUso_New"]) ? PathsForPrograms["MoUso_New"] : PathsForPrograms["MoUso_Old"], NameRules["Update"]);
- ChangeRulesOut(isChoose, PathsForPrograms["Uso"], string.Concat(NameRules["Update"], " (Update Orchestrator)"));
+ ChangeRules(isChoose, executableFiles.Item1, executableFiles.Item2, NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN);
+ ChangeRules(isChoose, executableFiles.Item1, executableFiles.Item2, NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_OUT);
});
}
catch { new ViewNotification().Show("", "warn", (string)Application.Current.Resources["firewalloff_notification"]); }
}
- private static void ChangeRulesIn(in bool isChoose, in string pathProgram, in string nameRule, in string description = "Windows update blocking")
+
+ private static void ChangeRules(bool isChoose, string pathProgram, string nameRule, NET_FW_RULE_DIRECTION_ direction, string description = "Windows update blocking")
{
- INetFwRule firewallRule = (INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule"));
INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
- firewallRule.ApplicationName = pathProgram;
- firewallRule.Action = NET_FW_ACTION_.NET_FW_ACTION_BLOCK;
- firewallRule.Direction = NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN;
- firewallRule.Description = description;
- firewallRule.Enabled = true;
- firewallRule.InterfaceTypes = "All";
- firewallRule.Name = nameRule;
-
if (isChoose)
{
if (CheckRulesWindows(nameRule))
firewallPolicy.Rules.Remove(nameRule);
- firewallPolicy.Rules.Add(firewallRule);
- }
- else
- firewallPolicy.Rules.Remove(nameRule);
- }
- private static void ChangeRulesOut(in bool isChoose, in string pathProgram, in string nameRule, in string description = "Windows update blocking")
- {
- INetFwRule firewallRule = (INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule"));
- INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
-
- firewallRule.ApplicationName = pathProgram;
- firewallRule.Action = NET_FW_ACTION_.NET_FW_ACTION_BLOCK;
- firewallRule.Direction = NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_OUT;
- firewallRule.Description = description;
- firewallRule.Enabled = true;
- firewallRule.InterfaceTypes = "All";
- firewallRule.Name = nameRule;
+ INetFwRule firewallRule = (INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule"));
+ firewallRule.ApplicationName = pathProgram;
+ firewallRule.Action = NET_FW_ACTION_.NET_FW_ACTION_BLOCK;
+ firewallRule.Direction = direction;
+ firewallRule.Description = description;
+ firewallRule.Enabled = true;
+ firewallRule.InterfaceTypes = "All";
+ firewallRule.Name = nameRule;
- if (isChoose)
- {
- if (CheckRulesWindows(nameRule))
- firewallPolicy.Rules.Remove(nameRule);
firewallPolicy.Rules.Add(firewallRule);
}
else
@@ -155,7 +129,7 @@ namespace GTweak.Utilities.Tweaks
protected static void BlockWDefender(bool isChoose)
{
- try { Parallel.Invoke(() => { ChangeRulesOut(isChoose, PathsForPrograms["WD"], NameRules["WDefender"], "blocking Windows Defender database updates"); }); }
+ try { Parallel.Invoke(() => { ChangeRules(isChoose, PathsForPrograms["WD"], NameRules["WDefender"], NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_OUT, "blocking Windows Defender database updates"); }); }
catch (Exception ex) { Debug.Write(ex.Message); };
}
}
diff --git a/.Source/GTweak/Windows/MainWindow.xaml.cs b/.Source/GTweak/Windows/MainWindow.xaml.cs
index 7fe9523d..c5fa85f4 100644
--- a/.Source/GTweak/Windows/MainWindow.xaml.cs
+++ b/.Source/GTweak/Windows/MainWindow.xaml.cs
@@ -1,4 +1,5 @@
-using GTweak.Utilities.Control;
+using GTweak.Utilities.Configuration;
+using GTweak.Utilities.Control;
using GTweak.Utilities.Helpers.Animation;
using GTweak.Utilities.Tweaks;
using GTweak.Windows;
diff --git a/.Source/GTweak/Windows/UpdateWindow.xaml.cs b/.Source/GTweak/Windows/UpdateWindow.xaml.cs
index 151286be..867d119e 100644
--- a/.Source/GTweak/Windows/UpdateWindow.xaml.cs
+++ b/.Source/GTweak/Windows/UpdateWindow.xaml.cs
@@ -1,4 +1,5 @@
-using GTweak.Utilities.Control;
+using GTweak.Utilities.Configuration;
+using GTweak.Utilities.Control;
using GTweak.Utilities.Helpers;
using System;
using System.ComponentModel;