Skip to content

Portable Tool for an Ideal Windows Setup

-fixing asynchronous waiting on deletion

Greedeks3fb4bc668ff9
diff --git a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
index a7811f77..5de6ffe3 100644
--- a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
+++ b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
+using System.Threading.Tasks;
namespace GTweak.Utilities.Tweaks
{
@@ -126,109 +127,127 @@ namespace GTweak.Utilities.Tweaks
internal async void ViewInstalledPackages() => InstalledPackages = await CommandExecutor.GetCommandOutput("Get-AppxPackage | Select-Object -ExpandProperty Name");
- internal static void DeletingPackage(string packageName)
+ internal static Task DeletingPackage(string packageName)
{
if (packageName == "OneDrive")
- DeletedOneDrive();
-
+ return DeletedOneDrive();
else
{
- try
+ return Task.Run(() =>
{
- using Process process = new Process();
- process.StartInfo.UseShellExecute = false;
- process.StartInfo.CreateNoWindow = true;
- process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
- process.EnableRaisingEvents = true;
- process.StartInfo.FileName = "powershell.exe";
- process.StartInfo.Arguments = $"Get-AppxProvisionedPackage -online | where-object {{$_.PackageName -like '*{packageName}*'}} | Remove-AppxProvisionedPackage -alluser -online –Verbose";
- process.Start();
-
- foreach (string getPackage in PackageScripts[packageName])
+ try
{
- TrustedInstaller.CreateProcessAsTrustedInstaller(SettingsRepository.PID, $@"cmd.exe /c for /d %i in (""{pathPackage}\*{getPackage}*"") do rd /s /q ""%i""");
- process.StartInfo.Arguments = $"Get-AppxPackage -Name {getPackage} -AllUsers | Remove-AppxPackage";
+ using Process process = new Process();
+ process.StartInfo.UseShellExecute = false;
+ process.StartInfo.CreateNoWindow = true;
+ process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
+ process.EnableRaisingEvents = true;
+ process.StartInfo.FileName = "powershell.exe";
+ process.StartInfo.Arguments = $"Get-AppxProvisionedPackage -online | where-object {{$_.PackageName -like '*{packageName}*'}} | Remove-AppxProvisionedPackage -alluser -online –Verbose";
process.Start();
+ process.WaitForExit();
+
+ foreach (string getPackage in PackageScripts[packageName])
+ {
+ TrustedInstaller.CreateProcessAsTrustedInstaller(SettingsRepository.PID, $@"cmd.exe /c for /d %i in (""{pathPackage}\*{getPackage}*"") do rd /s /q ""%i""");
+ process.StartInfo.Arguments = $"Get-AppxPackage -Name {getPackage} -AllUsers | Remove-AppxPackage";
+ process.Start();
+ process.WaitForExit();
+ }
+
+ if (PackageAliases.ContainsKey(packageName))
+ {
+ process.StartInfo.Arguments = $"Get-AppxProvisionedPackage -online | where-object {{$_.PackageName -like '*{PackageAliases[packageName]}*'}} | Remove-AppxProvisionedPackage -alluser -online –Verbose";
+ process.Start();
+ process.WaitForExit();
+ }
}
+ catch (Exception ex) { Debug.WriteLine(ex); };
- if (PackageAliases.ContainsKey(packageName))
+ switch (packageName)
{
- process.StartInfo.Arguments = $"Get-AppxProvisionedPackage -online | where-object {{$_.PackageName -like '*{PackageAliases[packageName]}*'}} | Remove-AppxProvisionedPackage -alluser -online –Verbose";
- process.Start();
+ case "Widgets":
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Dsh", "AllowNewsAndInterests", 0, RegistryValueKind.DWord);
+ break;
+ case "Cortana":
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\Speech_OneCore\Preferences", "ModelDownloadAllowed", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowCloudSearch", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowCortana", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowSearchToUseLocation", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "ConnectedSearchUseWeb", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "DisableWebSearch", 1, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowNewsAndInterests", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\InputPersonalization", "RestrictImplicitInkCollection", 1, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\InputPersonalization", "RestrictImplicitTextCollection", 1, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\InputPersonalization\TrainedDataStore", "HarvestContacts", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Personalization\Settings", "AcceptedPrivacyPolicy", 0, RegistryValueKind.DWord);
+ RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Windows Search", "CortanaConsent", 0, RegistryValueKind.DWord);
+ break;
}
-
- process.WaitForExit(1000);
- }
- catch (Exception ex) { Debug.WriteLine(ex); };
-
- switch (packageName)
- {
- case "Widgets":
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Dsh", "AllowNewsAndInterests", 0, RegistryValueKind.DWord);
- break;
- case "Cortana":
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Microsoft\Speech_OneCore\Preferences", "ModelDownloadAllowed", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowCloudSearch", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowCortana", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowSearchToUseLocation", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "ConnectedSearchUseWeb", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "DisableWebSearch", 1, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.LocalMachine, @"SOFTWARE\Policies\Microsoft\Windows\Windows Search", "AllowNewsAndInterests", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\InputPersonalization", "RestrictImplicitInkCollection", 1, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\InputPersonalization", "RestrictImplicitTextCollection", 1, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\InputPersonalization\TrainedDataStore", "HarvestContacts", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Personalization\Settings", "AcceptedPrivacyPolicy", 0, RegistryValueKind.DWord);
- RegistryHelp.Write(Registry.CurrentUser, @"Software\Microsoft\Windows\CurrentVersion\Windows Search", "CortanaConsent", 0, RegistryValueKind.DWord);
- break;
- }
+ });
}
}
- internal static void DeletedOneDrive()
+ internal static Task DeletedOneDrive()
{
- using (Process process = new Process())
+ return Task.Run(() =>
{
- process.StartInfo.UseShellExecute = false;
- process.StartInfo.CreateNoWindow = true;
- process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
- process.EnableRaisingEvents = true;
- process.StartInfo.FileName = "cmd.exe";
- process.StartInfo.Arguments = @"/c taskkill /f /im OneDrive.exe & %systemroot%\System32\OneDriveSetup.exe /uninstall & %systemroot%\SysWOW64\OneDriveSetup.exe /uninstall";
+ ProcessStartInfo startInfo = new ProcessStartInfo
+ {
+ FileName = "cmd.exe",
+ Arguments = @"/c taskkill /f /im OneDrive.exe & %systemroot%\System32\OneDriveSetup.exe /uninstall & %systemroot%\SysWOW64\OneDriveSetup.exe /uninstall",
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ UseShellExecute = false,
+ CreateNoWindow = true
+ };
+
+ using Process process = new Process { StartInfo = startInfo };
+
process.Start();
- process.WaitForExit(1000);
+ process.WaitForExit();
- while (!process.HasExited && process.Responding)
+ if (process.ExitCode == 0)
{
RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
RegistryHelp.DeleteFolderTree(Registry.ClassesRoot, @"Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
- }
- }
- string argumentsFolders = $@"/c rd /s /q %userprofile%\AppData\Local\Microsoft\OneDrive & rd /s /q %userprofile%\AppData\Local\OneDrive
- & rd /s /q ""%allusersprofile%\Microsoft OneDrive"" & rd /s /q {StoragePaths.SystemDisk}\OneDriveTemp";
+ string argumentsFolders = $@"/c rd /s /q %userprofile%\AppData\Local\Microsoft\OneDrive & rd /s /q %userprofile%\AppData\Local\OneDrive
+ & rd /s /q ""%allusersprofile%\Microsoft OneDrive"" & rd /s /q {StoragePaths.SystemDisk}\OneDriveTemp";
- if (isLocalAccount)
- argumentsFolders += @" & rd /s /q %userprofile%\OneDrive";
+ if (isLocalAccount)
+ argumentsFolders += @" & rd /s /q %userprofile%\OneDrive";
- CommandExecutor.RunCommand(argumentsFolders);
+ CommandExecutor.RunCommand(argumentsFolders);
+ }
+ });
}
- internal static void ResetOneDrive()
+ internal static Task ResetOneDrive()
{
- using (Process process = new Process())
+ return Task.Run(() =>
{
- process.StartInfo.UseShellExecute = false;
- process.StartInfo.CreateNoWindow = true;
- process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
- process.EnableRaisingEvents = true;
- process.StartInfo.FileName = "cmd.exe";
- process.StartInfo.Arguments = @"/c %systemroot%\System32\OneDriveSetup.exe & %systemroot%\SysWOW64\OneDriveSetup.exe";
+ ProcessStartInfo startInfo = new ProcessStartInfo
+ {
+ FileName = "cmd.exe",
+ Arguments = @"/c %systemroot%\System32\OneDriveSetup.exe & %systemroot%\SysWOW64\OneDriveSetup.exe",
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ UseShellExecute = false,
+ CreateNoWindow = true
+ };
+
+ using Process process = new Process { StartInfo = startInfo };
+
process.Start();
- process.WaitForExit(1000);
- }
+ process.WaitForExit();
- RegistryHelp.CreateFolder(Registry.ClassesRoot, @"CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
- RegistryHelp.CreateFolder(Registry.ClassesRoot, @"Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
+ if (process.ExitCode == 0)
+ {
+ RegistryHelp.CreateFolder(Registry.ClassesRoot, @"CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
+ RegistryHelp.CreateFolder(Registry.ClassesRoot, @"Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}");
+ }
+ });
}
internal async void CheckingForLocalAccount()
diff --git a/.Source/GTweak/View/PakagesView.xaml.cs b/.Source/GTweak/View/PakagesView.xaml.cs
index 8a8be07b..66016042 100644
--- a/.Source/GTweak/View/PakagesView.xaml.cs
+++ b/.Source/GTweak/View/PakagesView.xaml.cs
@@ -15,6 +15,7 @@ namespace GTweak.View
{
public partial class PakagesView : UserControl
{
+ private readonly DispatcherTimer timer;
private TimeSpan time = TimeSpan.FromSeconds(0);
private string applicationName = string.Empty;
@@ -22,7 +23,7 @@ namespace GTweak.View
{
InitializeComponent();
- DispatcherTimer timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
+ timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
{
if (time.TotalSeconds % 4 == 0)
{
@@ -34,6 +35,8 @@ namespace GTweak.View
time = time.Add(TimeSpan.FromSeconds(+1));
}, Application.Current.Dispatcher);
+
+ timer.Start();
}
private void Apps_MouseEnter(object sender, MouseEventArgs e)
@@ -59,31 +62,59 @@ namespace GTweak.View
{
case MouseButtonState.Pressed when appImage.Source == (DrawingImage)FindResource("A_DI_" + applicationName):
{
- UninstallingPakages.IsAppUnavailable[appImage.Name] = true;
- UpdateViewStatePakages();
+ timer.Stop();
BackgroundQueue backgroundQueue = new BackgroundQueue();
await backgroundQueue.QueueTask(delegate { UninstallingPakages.DeletingPackage(applicationName); });
- await Task.Delay(8000);
- UninstallingPakages.IsAppUnavailable[appImage.Name] = false;
- UpdateViewStatePakages();
+ await backgroundQueue.QueueTask(async delegate
+ {
+ await Dispatcher.InvokeAsync(() =>
+ {
+ UninstallingPakages.IsAppUnavailable[appImage.Name] = true;
+ UpdateViewStatePakages();
+ });
+
+ await UninstallingPakages.DeletingPackage(applicationName);
+
+ await Task.Delay(3000);
+
+ await Dispatcher.InvokeAsync(() =>
+ {
+ UninstallingPakages.IsAppUnavailable[appImage.Name] = false;
+ UpdateViewStatePakages();
+ });
+ });
+
+ timer.Start();
break;
}
case MouseButtonState.Pressed when appImage.Source == (DrawingImage)FindResource("DA_DI_" + applicationName) && applicationName == "OneDrive":
{
- new ViewNotification().Show("", "info", (string)FindResource("onedrive_notification"));
+ timer.Stop();
- UninstallingPakages.IsAppUnavailable[appImage.Name] = true;
- UpdateViewStatePakages();
+ new ViewNotification().Show("", "info", (string)FindResource("onedrive_notification"));
BackgroundQueue backgroundQueue = new BackgroundQueue();
- await backgroundQueue.QueueTask(delegate { UninstallingPakages.ResetOneDrive(); });
-
- await Task.Delay(6000);
- UninstallingPakages.IsAppUnavailable[appImage.Name] = false;
- UpdateViewStatePakages();
+ await backgroundQueue.QueueTask(async delegate
+ {
+ await Dispatcher.InvokeAsync(() =>
+ {
+ UninstallingPakages.IsAppUnavailable[appImage.Name] = true;
+ UpdateViewStatePakages();
+ });
+
+ await UninstallingPakages.ResetOneDrive();
+
+ await Dispatcher.InvokeAsync(() =>
+ {
+ UninstallingPakages.IsAppUnavailable[appImage.Name] = false;
+ UpdateViewStatePakages();
+ });
+ });
+
+ timer.Start();
break;
}
}