Skip to content

Portable Tool for an Ideal Windows Setup

-changed & re

Greedeks34e7abcc4515
diff --git a/.Source/GTweak/Utilities/Control/ErrorLogging.cs b/.Source/GTweak/Utilities/Control/ErrorLogging.cs
index 6e7b84ad..2e188b46 100644
--- a/.Source/GTweak/Utilities/Control/ErrorLogging.cs
+++ b/.Source/GTweak/Utilities/Control/ErrorLogging.cs
@@ -10,7 +10,7 @@ namespace GTweak.Utilities.Control
{
private static readonly string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GTweak_Error.log");
- internal static void LogWritingFile(Exception ex) => Task.Run(() => LogToFile(ex));
+ internal static void LogWritingFile(Exception ex) => Task.Run(() => LogToFile(ex)).Wait();
internal static void LogDebug(Exception ex) => Debug.WriteLine($"Debug: {ex.Message}\nStack Trace: {ex.StackTrace}");
diff --git a/.Source/GTweak/Utilities/Tweaks/ConfidentialityTweaks.cs b/.Source/GTweak/Utilities/Tweaks/ConfidentialityTweaks.cs
index db7895cf..ca8b11bb 100644
--- a/.Source/GTweak/Utilities/Tweaks/ConfidentialityTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/ConfidentialityTweaks.cs
@@ -90,23 +90,8 @@ namespace GTweak.Utilities.Tweaks
{
try
{
- byte numberHostsRules = 0;
-
- using (StreamReader streamReader = new StreamReader(StoragePaths.HostsFile))
- {
- string hosts = streamReader.ReadToEnd();
- numberHostsRules += (byte)(new string[] {
- @"0.0.0.0 hk2sch130021829.wns.windows.com",
- @"0.0.0.0 v10-win.vortex.data.microsoft.com.akadns.net",
- @"0.0.0.0 watson.live.com",
- @"0.0.0.0 cds843.lon.llnw.net",
- @"0.0.0.0 db6sch102091602.wns.windows.com",
- @"0.0.0.0 telemetry.microsoft.com",
- @"0.0.0.0 bn3sch020010635.wns.windows.com",
- @"0.0.0.0 api.cortana.ai"
- }).Where(rule => hosts.Contains(rule)).Count();
- }
- return numberHostsRules == 0;
+ int numberRows = File.ReadAllText(StoragePaths.HostsFile).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Count(line => line.StartsWith("0.0.0.0"));
+ return numberRows < 673;
}
catch { return false; }
}
@@ -194,6 +179,7 @@ namespace GTweak.Utilities.Tweaks
RegistryHelp.DeleteFolderTree(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\SQMClient");
break;
case "TglButton9":
+ BlockSpyDomain(isChoose);
Task.Run(delegate
{
string backupFile = StoragePaths.HostsFile + @" (Default GTweak)";
@@ -213,14 +199,12 @@ namespace GTweak.Utilities.Tweaks
if (File.Exists(backupFile))
File.Delete(backupFile);
+ else
+ File.WriteAllText(StoragePaths.HostsFile, string.Empty);
}
-
}
catch (Exception ex) { ErrorLogging.LogDebug(ex); }
-
- BlockSpyDomain(isChoose);
-
- });
+ }).Wait();
break;
case "TglButton10":
if (isChoose)
diff --git a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
index 7eaf0b0b..d6fb7e02 100644
--- a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
@@ -333,7 +333,21 @@ namespace GTweak.Utilities.Tweaks
SetPowercfg(isChoose);
break;
case "TglButton19":
- BluetoothStatusSet(isChoose ? "'off'" : "'on'");
+ CommandExecutor.RunCommand(@"Add-Type -AssemblyName System.Runtime.WindowsRuntime
+ $asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
+ Function Await($WinRtTask, $ResultType) {
+ $asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
+ $netTask = $asTask.Invoke($null, @($WinRtTask))
+ $netTask.Wait(-1) | Out-Null
+ $netTask.Result
+ }
+ [Windows.Devices.Radios.Radio,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
+ [Windows.Devices.Radios.RadioAccessStatus,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
+ Await ([Windows.Devices.Radios.Radio]::RequestAccessAsync()) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null
+ $radios = Await ([Windows.Devices.Radios.Radio]::GetRadiosAsync()) ([System.Collections.Generic.IReadOnlyList[Windows.Devices.Radios.Radio]])
+ $bluetooth = $radios | ? { $_.Kind -eq 'Bluetooth' }
+ [Windows.Devices.Radios.RadioState,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
+ Await ($bluetooth.SetStateAsync(" + (isChoose ? "'off'" : "'on'") + ")) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null", true);
isBluetoothStatus = !isChoose;
break;
case "TglButton20":
@@ -381,26 +395,6 @@ namespace GTweak.Utilities.Tweaks
}
}
- private static void BluetoothStatusSet(string status)
- {
- CommandExecutor.RunCommand(@"Add-Type -AssemblyName System.Runtime.WindowsRuntime
- $asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
- Function Await($WinRtTask, $ResultType) {
- $asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
- $netTask = $asTask.Invoke($null, @($WinRtTask))
- $netTask.Wait(-1) | Out-Null
- $netTask.Result
- }
- [Windows.Devices.Radios.Radio,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
- [Windows.Devices.Radios.RadioAccessStatus,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
- Await ([Windows.Devices.Radios.Radio]::RequestAccessAsync()) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null
- $radios = Await ([Windows.Devices.Radios.Radio]::GetRadiosAsync()) ([System.Collections.Generic.IReadOnlyList[Windows.Devices.Radios.Radio]])
- $bluetooth = $radios | ? { $_.Kind -eq 'Bluetooth' }
- [Windows.Devices.Radios.RadioState,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
- Await ($bluetooth.SetStateAsync(" + status + ")) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null", true);
- }
-
-
private static void SetPowercfg(bool isChoose)
{
Task.Run(async () =>