Skip to content

Portable Tool for an Ideal Windows Setup

-fixed images change

Greedeksa6fbdc92041e
diff --git a/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs b/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs
index b679657c..24dc8a06 100644
--- a/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs
+++ b/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs
@@ -4,7 +4,7 @@ using System.Threading.Tasks;
namespace GTweak.Utilities.Helpers
{
- internal sealed class CommandExecutor
+ internal static class CommandExecutor
{
internal static async Task<string> GetCommandOutput(string arguments, bool isPowerShell = true)
{
@@ -26,7 +26,7 @@ namespace GTweak.Utilities.Helpers
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
- process.WaitForExit();
+ process.WaitForExitAsync();
if (process.ExitCode == 0)
return string.Join(Environment.NewLine, output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
@@ -51,5 +51,16 @@ namespace GTweak.Utilities.Helpers
});
});
}
+
+ internal static Task WaitForExitAsync(this Process process)
+ {
+ if (process.HasExited)
+ return Task.CompletedTask;
+
+ var tcs = new TaskCompletionSource<object>();
+ process.EnableRaisingEvents = true;
+ process.Exited += (sender, args) => tcs.TrySetResult(null);
+ return tcs.Task;
+ }
}
}
diff --git a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
index cf7bab3d..5cc154ef 100644
--- a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
+++ b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
@@ -91,38 +91,36 @@ namespace GTweak.Utilities.Tweaks
{
try
{
- var (Alias, IsUnavailable, Scripts) = PackagesDetails[packageName];
- string argument = "-NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -Command";
-
- using Process process = new Process
+ static async Task RunPowerShell(string arguments)
{
- StartInfo =
+ ProcessStartInfo startInfo = new ProcessStartInfo
{
+ FileName = "powershell.exe",
+ Arguments = arguments,
UseShellExecute = false,
CreateNoWindow = true,
- WindowStyle = ProcessWindowStyle.Minimized,
- FileName = "powershell.exe"
- },
- EnableRaisingEvents = true
- };
+ RedirectStandardOutput = true,
+ RedirectStandardError = true
+ };
+
+ using var process = new Process { StartInfo = startInfo };
+ process.Start();
+ await process.WaitForExitAsync();
+ }
- process.StartInfo.Arguments = $"{argument} \"Get-AppxProvisionedPackage -online | where-object {{$_.PackageName -like '*{packageName}*'}} | Remove-AppxProvisionedPackage -alluser -online –Verbose\"";
- process.Start();
- process.WaitForExit();
+ var (Alias, IsUnavailable, Scripts) = PackagesDetails[packageName];
+ string argument = "-NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -Command";
+
+ await RunPowerShell($"{argument} \"Get-AppxProvisionedPackage -online | where-object {{$_.PackageName -like '*{packageName}*'}} | Remove-AppxProvisionedPackage -alluser -online –Verbose\"");
foreach (string getScript in Scripts)
{
TrustedInstaller.CreateProcessAsTrustedInstaller(SettingsRepository.PID, $@"cmd.exe /c for /d %i in (""{pathPackage}\*{getScript}*"") do rd /s /q ""%i""");
- process.StartInfo.Arguments = $"{argument} \"Get-AppxPackage -Name {getScript} -AllUsers | Remove-AppxPackage\"";
- process.Start();
- process.WaitForExit();
+ await RunPowerShell($"{argument} \"Get-AppxPackage -Name {getScript} -AllUsers | Remove-AppxPackage\"");
}
if (!string.IsNullOrEmpty(Alias))
- {
- process.StartInfo.Arguments = $"{argument} \"Get-AppxProvisionedPackage -online | where-object {{$_.PackageName -like '*{Alias}*'}} | Remove-AppxProvisionedPackage -alluser -online –Verbose\"";
- process.WaitForExit();
- }
+ await RunPowerShell($"{argument} \"Get-AppxProvisionedPackage -online | where-object {{$_.PackageName -like '*{Alias}*'}} | Remove-AppxProvisionedPackage -alluser -online –Verbose\"");
}
catch (Exception ex) { Debug.WriteLine(ex); }
@@ -297,7 +295,7 @@ namespace GTweak.Utilities.Tweaks
internal static Task DeletedOneDrive()
{
- return Task.Run(() =>
+ return Task.Run(async () =>
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
@@ -312,7 +310,7 @@ namespace GTweak.Utilities.Tweaks
using Process process = new Process { StartInfo = startInfo };
process.Start();
- process.WaitForExit();
+ await process.WaitForExitAsync();
if (process.ExitCode == 0)
{
@@ -327,7 +325,7 @@ namespace GTweak.Utilities.Tweaks
internal static Task ResetOneDrive()
{
- return Task.Run(() =>
+ return Task.Run(async () =>
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
@@ -342,7 +340,7 @@ namespace GTweak.Utilities.Tweaks
using Process process = new Process { StartInfo = startInfo };
process.Start();
- process.WaitForExit();
+ await process.WaitForExitAsync();
if (process.ExitCode == 0)
{
diff --git a/.Source/GTweak/View/PakagesView.xaml.cs b/.Source/GTweak/View/PakagesView.xaml.cs
index 863924b7..e5ee289b 100644
--- a/.Source/GTweak/View/PakagesView.xaml.cs
+++ b/.Source/GTweak/View/PakagesView.xaml.cs
@@ -18,7 +18,6 @@ namespace GTweak.View
{
private readonly DispatcherTimer timer;
private TimeSpan time = TimeSpan.FromSeconds(0);
- private string packageName = string.Empty;
public PakagesView()
{
@@ -56,28 +55,29 @@ namespace GTweak.View
private async void ClickApp_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
- Image pakageImage = (Image)sender;
- packageName = pakageImage.Name;
+ Image packageImage = (Image)sender;
+ string packageName = packageImage.Name;
switch (e.LeftButton)
{
- case MouseButtonState.Pressed when Equals(pakageImage.Source, FindResource("A_DI_" + packageName)):
+ case MouseButtonState.Pressed when Equals(packageImage.Source, FindResource("A_DI_" + packageName)):
{
- UninstallingPakages.HandleAvailabilityStatus(packageName, true);
- UpdateViewStatePakages();
-
- timer.Stop();
-
BackgroundQueue backgroundQueue = new BackgroundQueue();
await backgroundQueue.QueueTask(async delegate
{
try
{
+ Dispatcher.Invoke(() =>
+ {
+ UninstallingPakages.HandleAvailabilityStatus(packageName, true);
+ UpdateViewStatePakages();
+ });
+
await UninstallingPakages.DeletingPackage(packageName);
await Task.Delay(3000);
- await Dispatcher.InvokeAsync(() =>
+ Dispatcher.Invoke(() =>
{
UninstallingPakages.HandleAvailabilityStatus(packageName, false);
UpdateViewStatePakages();
@@ -88,18 +88,11 @@ namespace GTweak.View
}
catch (Exception ex) { Debug.WriteLine(ex.Message); }
});
-
- timer.Start();
break;
}
- case MouseButtonState.Pressed when Equals(pakageImage.Source, FindResource("DA_DI_" + packageName)) && packageName == "OneDrive":
+ case MouseButtonState.Pressed when Equals(packageImage.Source, FindResource("DA_DI_" + packageName)) && packageName == "OneDrive":
{
- UninstallingPakages.HandleAvailabilityStatus(packageName, true);
- UpdateViewStatePakages();
-
- timer.Stop();
-
new ViewNotification().Show("", "info", "onedrive_notification");
BackgroundQueue backgroundQueue = new BackgroundQueue();
@@ -107,9 +100,17 @@ namespace GTweak.View
{
try
{
+ Dispatcher.Invoke(() =>
+ {
+ UninstallingPakages.HandleAvailabilityStatus(packageName, true);
+ UpdateViewStatePakages();
+ });
+
await UninstallingPakages.ResetOneDrive();
- await Dispatcher.InvokeAsync(() =>
+ await Task.Delay(3000);
+
+ Dispatcher.Invoke(() =>
{
UninstallingPakages.HandleAvailabilityStatus(packageName, false);
UpdateViewStatePakages();
@@ -117,8 +118,6 @@ namespace GTweak.View
}
catch (Exception ex) { Debug.WriteLine(ex.Message); }
});
-
- timer.Start();
break;
}
}