Skip to content

Portable Tool for an Ideal Windows Setup

re & getting rid of unnecessary appropriation

Greedeks16de6611ee7c
diff --git a/.Source/GTweak/Assets/UserControl/ToggleButton.xaml.cs b/.Source/GTweak/Assets/UserControl/ToggleButton.xaml.cs
index 4da03726..9123ea1e 100644
--- a/.Source/GTweak/Assets/UserControl/ToggleButton.xaml.cs
+++ b/.Source/GTweak/Assets/UserControl/ToggleButton.xaml.cs
@@ -53,7 +53,6 @@ namespace GTweak.Assets.UserControl
private static readonly DependencyProperty TextProperty =
DependencyProperty.Register(nameof(TextResource), typeof(string), typeof(ToggleButton), new PropertyMetadata("", (s, e) => ((ToggleButton)s).ToggleText.Text = (string)e.NewValue));
-
public ToggleButton()
{
InitializeComponent();
diff --git a/.Source/GTweak/Utilities/Configuration/MonitoringSystem.cs b/.Source/GTweak/Utilities/Configuration/MonitoringSystem.cs
index d032c50c..2a2bdcb3 100644
--- a/.Source/GTweak/Utilities/Configuration/MonitoringSystem.cs
+++ b/.Source/GTweak/Utilities/Configuration/MonitoringSystem.cs
@@ -66,22 +66,28 @@ namespace GTweak.Utilities.Configuration
return (int)((float)(totalMemory - availableMemory) / totalMemory * 100);
}
- internal async Task<int> GetTotalProcessorUsage()
+ internal async void GetTotalProcessorUsageAsync()
{
try
{
static ulong ConvertTimeToTicks(SystemTime systemTime) => ((ulong)systemTime.dwHighDateTime << 32) | systemTime.dwLowDateTime;
if (!GetSystemTimes(out SystemTime idleTime, out SystemTime kernelTime, out SystemTime userTime))
- return 0;
+ {
+ GetProcessorUsage = 1;
+ return;
+ }
ulong idleTicks = ConvertTimeToTicks(idleTime);
ulong totalTicks = ConvertTimeToTicks(kernelTime) + ConvertTimeToTicks(userTime);
- await Task.Delay(500);
+ await Task.Delay(100);
if (!GetSystemTimes(out idleTime, out kernelTime, out userTime))
- return 0;
+ {
+ GetProcessorUsage = 1;
+ return;
+ }
ulong newIdleTicks = ConvertTimeToTicks(idleTime);
ulong newTotalTicks = ConvertTimeToTicks(kernelTime) + ConvertTimeToTicks(userTime);
@@ -89,12 +95,12 @@ namespace GTweak.Utilities.Configuration
ulong totalTicksDiff = newTotalTicks - totalTicks;
GetProcessorUsage = (int)(100.0 * (totalTicksDiff - (newIdleTicks - idleTicks)) / totalTicksDiff);
- return GetProcessorUsage;
+
}
catch (Exception ex)
{
ErrorLogging.LogDebug(ex);
- return 0;
+ GetProcessorUsage = 1;
}
}
}
diff --git a/.Source/GTweak/Utilities/Controls/SettingsRepository.cs b/.Source/GTweak/Utilities/Controls/SettingsRepository.cs
index 780edcac..bad0657f 100644
--- a/.Source/GTweak/Utilities/Controls/SettingsRepository.cs
+++ b/.Source/GTweak/Utilities/Controls/SettingsRepository.cs
@@ -29,8 +29,8 @@ namespace GTweak.Utilities.Controls
[DllImport("winmm.dll")]
internal static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
- internal static string[] AvailableLangs = { "en", "fr", "it", "ko", "ru", "uk" };
- internal static string[] AvailableThemes = { "Dark", "Light", "Cobalt", "Dark amethyst", "Cold Blue", "System" };
+ internal static readonly string[] AvailableLangs = { "en", "fr", "it", "ko", "ru", "uk" };
+ internal static readonly string[] AvailableThemes = { "Dark", "Light", "Cobalt", "Dark amethyst", "Cold Blue", "System" };
internal static int PID = 0;
internal static string currentRelease = (Assembly.GetEntryAssembly() ?? throw new InvalidOperationException()).GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion.Split(' ').Last().Trim();
@@ -66,7 +66,7 @@ namespace GTweak.Utilities.Controls
RegistryHelp.Write(Registry.CurrentUser, @"Software\GTweak", key, value.ToString(), RegistryValueKind.String);
}
- internal void СheckingParameters()
+ internal static void СheckingParameters()
{
bool isRegistryEmpty = false;
diff --git a/.Source/GTweak/Utilities/Helpers/TrustedInstaller.cs b/.Source/GTweak/Utilities/Helpers/TrustedInstaller.cs
index a99bb0f3..c8c62891 100644
--- a/.Source/GTweak/Utilities/Helpers/TrustedInstaller.cs
+++ b/.Source/GTweak/Utilities/Helpers/TrustedInstaller.cs
@@ -1,4 +1,5 @@
-using System;
+using GTweak.Utilities.Controls;
+using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
@@ -178,8 +179,9 @@ namespace GTweak.Utilities.Helpers
return false;
}
- internal static int StartTrustedInstallerService()
+ internal static void StartTrustedInstallerService()
{
+ CommandExecutor.RunCommand("/c sc config TrustedInstaller start= demand && sc start TrustedInstaller");
IntPtr hSCManager = OpenSCManager(null, ServicesActiveDatabase, SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS);
if (hSCManager == IntPtr.Zero)
{
@@ -214,7 +216,8 @@ namespace GTweak.Utilities.Helpers
{
CloseServiceHandle(hService);
CloseServiceHandle(hSCManager);
- return (int)statusBuffer.dwProcessId;
+ SettingsRepository.PID = (int)statusBuffer.dwProcessId;
+ return;
}
}
diff --git a/.Source/GTweak/Utilities/Tweaks/WindowsLicense.cs b/.Source/GTweak/Utilities/Tweaks/WindowsLicense.cs
index 5dfae6c7..dafb7540 100644
--- a/.Source/GTweak/Utilities/Tweaks/WindowsLicense.cs
+++ b/.Source/GTweak/Utilities/Tweaks/WindowsLicense.cs
@@ -21,7 +21,7 @@ namespace GTweak.Utilities.Tweaks
private static bool IsVersionWindows(string pattern, byte words) => new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled).Matches(SystemDiagnostics.HardwareData.OSVersion).Count == words;
- internal void LicenseStatus()
+ internal static void LicenseStatus()
{
Parallel.Invoke(() =>
{
@@ -74,7 +74,7 @@ namespace GTweak.Utilities.Tweaks
RegistryHelp.Write(Registry.CurrentUser, @"Control Panel\International\Geo", "Name", originalGeo, RegistryValueKind.String);
- new WindowsLicense().LicenseStatus();
+ LicenseStatus();
await Task.Delay(2000);
@@ -89,7 +89,7 @@ namespace GTweak.Utilities.Tweaks
await CommandExecutor.InvokeRunCommand("/c slmgr.vbs //b /skms kms.digiboy.ir");
await CommandExecutor.InvokeRunCommand("/c slmgr.vbs //b /ato");
- new WindowsLicense().LicenseStatus();
+ LicenseStatus();
await Task.Delay(2000);
diff --git a/.Source/GTweak/View/DataSystemView.xaml.cs b/.Source/GTweak/View/DataSystemView.xaml.cs
index 01bfa35c..0a1d8653 100644
--- a/.Source/GTweak/View/DataSystemView.xaml.cs
+++ b/.Source/GTweak/View/DataSystemView.xaml.cs
@@ -39,17 +39,17 @@ namespace GTweak.View
_timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, async delegate
{
- if (_time.TotalSeconds % 2 == 0)
+ if ((int)_time.TotalSeconds % 2 == 0)
{
BackgroundQueue backgroundQueue = new BackgroundQueue();
- await backgroundQueue.QueueTask(async delegate
+ await backgroundQueue.QueueTask(delegate
{
new SystemDiagnostics().UpdatingDevicesData();
- await new MonitoringSystem().GetTotalProcessorUsage();
+ new MonitoringSystem().GetTotalProcessorUsageAsync();
});
Application.Current.Dispatcher.Invoke(AnimationProgressBars);
}
- else if (_time.TotalSeconds % 5 == 0)
+ else if ((int)_time.TotalSeconds % 5 == 0)
{
BackgroundQueue backgroundQueue = new BackgroundQueue();
await backgroundQueue.QueueTask(delegate { new SystemDiagnostics().GetUserIpAddress(); });
diff --git a/.Source/GTweak/View/PakagesView.xaml.cs b/.Source/GTweak/View/PakagesView.xaml.cs
index 05c66f8b..d3a61765 100644
--- a/.Source/GTweak/View/PakagesView.xaml.cs
+++ b/.Source/GTweak/View/PakagesView.xaml.cs
@@ -30,7 +30,7 @@ namespace GTweak.View
_timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
{
- if (_time.TotalSeconds % 5 == 0)
+ if ((int)_time.TotalSeconds % 5 == 0)
{
BackgroundWorker backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += delegate { new UninstallingPakages().LoadInstalledPackages(); };
diff --git a/.Source/GTweak/Windows/ImportWindow.xaml b/.Source/GTweak/Windows/ImportWindow.xaml
index 7252635a..41afef9e 100644
--- a/.Source/GTweak/Windows/ImportWindow.xaml
+++ b/.Source/GTweak/Windows/ImportWindow.xaml
@@ -28,7 +28,7 @@
</Style>
</Image.Style>
</Image>
- <TextBlock Text="{DynamicResource title_win_import}" Margin="10,0,0,0" Foreground="{StaticResource Color_Highlighted}" Height="auto" Width="auto" FontFamily="{StaticResource Jura}" FontSize="20px" HorizontalAlignment="Left" TextAlignment="Center"/>
+ <TextBlock Text="{DynamicResource title_win_import}" Margin="10,1,0,0" Foreground="{StaticResource Color_Highlighted}" Height="auto" Width="auto" FontFamily="{StaticResource Jura}" FontSize="19px" HorizontalAlignment="Left" TextAlignment="Center"/>
</StackPanel>
<TextBlock Text="{DynamicResource warning_win_import}" Foreground="{StaticResource Color_TetBlock_Inactivity}" Height="auto" Width="auto" MaxWidth="350" FontFamily="{StaticResource Jura}" FontSize="13px" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,10,0,0"/>
<Border Margin="0,20,0,0" CornerRadius="5" Background="{StaticResource Color_Background_RadialProgressBar}" Height="30" Width="350" HorizontalAlignment="Left">
diff --git a/.Source/GTweak/Windows/LoadingWindow.xaml.cs b/.Source/GTweak/Windows/LoadingWindow.xaml.cs
index aca23e48..1eb4476a 100644
--- a/.Source/GTweak/Windows/LoadingWindow.xaml.cs
+++ b/.Source/GTweak/Windows/LoadingWindow.xaml.cs
@@ -41,18 +41,16 @@ namespace GTweak.Windows
Thread.Sleep(17);
}
-
- static void ExecuteWithLogging(Action action, string methodName)
+ static void ExecuteWithLogging(Action action, string member)
{
try { action(); }
- catch (Exception ex) { ErrorLogging.LogWritingFile(ex, methodName); }
+ catch (Exception ex) { ErrorLogging.LogWritingFile(ex, member); }
}
-
Parallel.Invoke(
- () => ExecuteWithLogging(() => SettingsRepository.PID = TrustedInstaller.StartTrustedInstallerService(), nameof(SettingsRepository.PID)),
- () => ExecuteWithLogging(new SettingsRepository().СheckingParameters, nameof(SettingsRepository.СheckingParameters)),
- () => ExecuteWithLogging(new WindowsLicense().LicenseStatus, nameof(WindowsLicense.LicenseStatus)),
+ () => ExecuteWithLogging(TrustedInstaller.StartTrustedInstallerService, nameof(TrustedInstaller.StartTrustedInstallerService)),
+ () => ExecuteWithLogging(SettingsRepository.СheckingParameters, nameof(SettingsRepository.СheckingParameters)),
+ () => ExecuteWithLogging(WindowsLicense.LicenseStatus, nameof(WindowsLicense.LicenseStatus)),
() => ExecuteWithLogging(new SystemDiagnostics().GetHardwareData, nameof(SystemDiagnostics.GetHardwareData)),
() => ExecuteWithLogging(new SystemDiagnostics().ValidateVersionUpdates, nameof(SystemDiagnostics.ValidateVersionUpdates)),
() => ExecuteWithLogging(new UninstallingPakages().LoadInstalledPackages, nameof(UninstallingPakages.LoadInstalledPackages)),
@@ -61,9 +59,7 @@ namespace GTweak.Windows
() => ExecuteWithLogging(new SystemTweaks().ViewBluetoothStatus, nameof(SystemTweaks.ViewBluetoothStatus))
);
-
- MonitoringSystem monitoringSystem = new MonitoringSystem();
- ExecuteWithLogging(async () => await monitoringSystem.GetTotalProcessorUsage(), nameof(monitoringSystem.GetTotalProcessorUsage));
+ ExecuteWithLogging(new MonitoringSystem().GetTotalProcessorUsageAsync, nameof(MonitoringSystem.GetTotalProcessorUsageAsync));
}
private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
diff --git a/.Source/GTweak/Windows/MessageWindow.xaml b/.Source/GTweak/Windows/MessageWindow.xaml
index 418005dc..0a7f01c0 100644
--- a/.Source/GTweak/Windows/MessageWindow.xaml
+++ b/.Source/GTweak/Windows/MessageWindow.xaml
@@ -27,7 +27,7 @@
</Style>
</Image.Style>
</Image>
- <TextBlock Text="{DynamicResource title_message}" Margin="10,2,0,0" Foreground="{StaticResource Color_Highlighted}" Height="auto" Width="auto" FontFamily="{StaticResource Jura}" FontSize="18px" HorizontalAlignment="Left" TextAlignment="Center"/>
+ <TextBlock Text="{DynamicResource title_message}" Margin="10,1,0,0" Foreground="{StaticResource Color_Highlighted}" Height="auto" Width="auto" FontFamily="{StaticResource Jura}" FontSize="19px" HorizontalAlignment="Left" TextAlignment="Center"/>
</StackPanel>
<TextBlock Foreground="{StaticResource Color_TetBlock_Inactivity}" Height="auto" Width="340" FontFamily="{StaticResource Jura}" FontSize="14px" TextWrapping="Wrap"
HorizontalAlignment="Center" TextAlignment="Left" FontStretch="Medium" Margin="0,10,0,0">
diff --git a/.Source/GTweak/Windows/NotificationWindow.xaml.cs b/.Source/GTweak/Windows/NotificationWindow.xaml.cs
index 42ab205e..fcff03f5 100644
--- a/.Source/GTweak/Windows/NotificationWindow.xaml.cs
+++ b/.Source/GTweak/Windows/NotificationWindow.xaml.cs
@@ -107,8 +107,6 @@ namespace GTweak.Windows
BeginAnimation(Canvas.LeftProperty, doubleAnimKeyFrames);
BeginAnimation(OpacityProperty, FadeAnimation.FadeIn(1, 0.25));
-
-
});
}
diff --git a/.Source/GTweak/Windows/UpdateWindow.xaml b/.Source/GTweak/Windows/UpdateWindow.xaml
index 277a18b1..012993fc 100644
--- a/.Source/GTweak/Windows/UpdateWindow.xaml
+++ b/.Source/GTweak/Windows/UpdateWindow.xaml
@@ -73,7 +73,7 @@
</Style>
</Image.Style>
</Image>
- <TextBlock Text="{DynamicResource title_update}" Foreground="{StaticResource Color_Highlighted}" Height="auto" Width="auto" FontFamily="{StaticResource Jura}" FontSize="18px" HorizontalAlignment="Left" TextAlignment="Center" Margin="10,0,0,0"/>
+ <TextBlock Text="{DynamicResource title_update}" Foreground="{StaticResource Color_Highlighted}" Height="auto" Width="auto" FontFamily="{StaticResource Jura}" FontSize="19px" HorizontalAlignment="Left" TextAlignment="Center" Margin="10,0,0,0"/>
</StackPanel>
<TextBlock Foreground="{StaticResource Color_Highlighted}" Height="auto" Width="auto" FontFamily="{StaticResource Jura}" FontSize="16px" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,3,0,0">
<Run x:Name="CurrentVerison" Text="0.0.0" Foreground="{StaticResource Color_Accent}"/>
@@ -100,7 +100,7 @@
</Style>
</Image.Style>
</Image>
- <TextBlock Foreground="{StaticResource Color_Highlighted}" Height="auto" Width="auto" FontFamily="{StaticResource Jura}" FontSize="20px" HorizontalAlignment="Center" TextAlignment="Center" Margin="10,0,0,0">
+ <TextBlock Foreground="{StaticResource Color_Highlighted}" Height="auto" Width="auto" FontFamily="{StaticResource Jura}" FontSize="19px" HorizontalAlignment="Center" TextAlignment="Center" Margin="10,0,0,0">
<Run Text="{DynamicResource download_update}"/>
<Run Text="“"/><Run Text="GTweak" Foreground="{StaticResource Color_Accent}"/>
<Run x:Name="DownloadVersion" Text="0.0.0" Foreground="{StaticResource Color_Accent}"/><Run Text="”"/>