Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
deleting Windows.old (#32)
Greedeks5225e54009b1
diff --git a/.Source/GTweak/Languages/en/Localize.xaml b/.Source/GTweak/Languages/en/Localize.xamlindex 68c4877b..6d635858 100644--- a/.Source/GTweak/Languages/en/Localize.xaml+++ b/.Source/GTweak/Languages/en/Localize.xaml@@ -463,6 +463,12 @@<v:String x:Key="title_decompression_more">NTFS Decompression</v:String><v:String x:Key="text_decompression_more">Disables compression by restoring files to their original size and accelerating access to them.</v:String><v:String x:Key="btntext_overview_more">Overview</v:String>++ <v:String x:Key="title_over_more">Disk Cleanup Confirmation</v:String>+ <v:String x:Key="text_over_more">Your disk contains a Windows.old folder holding files from a previous version of Windows that are taking up a significant amount of space. Please note: once this folder is deleted, its contents cannot be restored, so be sure you’ve saved any files you need.</v:String>+ <v:String x:Key="question_over_more">Do you want to proceed with the cleanup and delete the Windows.old folder?</v:String>+ <v:String x:Key="btn_agree_more">Agree</v:String>+ <v:String x:Key="btn_decline_more">Decline</v:String><!--#endregion--></ResourceDictionary>\ No newline at end of filediff --git a/.Source/GTweak/Languages/ko/Localize.xaml b/.Source/GTweak/Languages/ko/Localize.xamlindex 74914f93..2c246ee9 100644--- a/.Source/GTweak/Languages/ko/Localize.xaml+++ b/.Source/GTweak/Languages/ko/Localize.xaml@@ -463,6 +463,12 @@<v:String x:Key="title_decompression_more">NTFS 압축 해제</v:String><v:String x:Key="text_decompression_more">압축을 해제하여 파일을 원래 크기로 복원하고 접근 속도를 높입니다.</v:String><v:String x:Key="btntext_overview_more">개요</v:String>++ <v:String x:Key="title_over_more">Disk Cleanup Confirmation</v:String>+ <v:String x:Key="text_over_more">Your disk contains a Windows.old folder holding files from a previous version of Windows that are taking up a significant amount of space. Please note: once this folder is deleted, its contents cannot be restored, so be sure you’ve saved any files you need.</v:String>+ <v:String x:Key="question_over_more">Do you want to proceed with the cleanup and delete the Windows.old folder?</v:String>+ <v:String x:Key="btn_agree_more">Agree</v:String>+ <v:String x:Key="btn_decline_more">Decline</v:String><!--#endregion--></ResourceDictionary>\ No newline at end of filediff --git a/.Source/GTweak/Languages/ru/Localize.xaml b/.Source/GTweak/Languages/ru/Localize.xamlindex 12030d0c..3c2f1153 100644--- a/.Source/GTweak/Languages/ru/Localize.xaml+++ b/.Source/GTweak/Languages/ru/Localize.xaml@@ -463,6 +463,12 @@<v:String x:Key="title_decompression_more">Декомпрессия NTFS</v:String><v:String x:Key="text_decompression_more">Отключает сжатие, восстанавливая файлы до их исходного объёма и ускоряя доступ к ним.</v:String><v:String x:Key="btntext_overview_more">Обзор</v:String>++ <v:String x:Key="title_over_more">Подтверждение очистки диска</v:String>+ <v:String x:Key="text_over_more">На вашем диске найденая папка Windows.old, содержащая файлы предыдущей версии Windows, активно занимающая значительное пространство. Обратите внимание: после удаления папки восстановить её содержимое будет невозможно, поэтому убедитесь, что все необходимые файлы сохранены.</v:String>+ <v:String x:Key="question_over_more">Вы хотите продолжить очистку с удалением папки Windows.old?</v:String>+ <v:String x:Key="btn_agree_more">Согласиться</v:String>+ <v:String x:Key="btn_decline_more">Отказаться</v:String><!--#endregion--></ResourceDictionary>\ No newline at end of filediff --git a/.Source/GTweak/Languages/uk/Localize.xaml b/.Source/GTweak/Languages/uk/Localize.xamlindex 328090f8..832d116e 100644--- a/.Source/GTweak/Languages/uk/Localize.xaml+++ b/.Source/GTweak/Languages/uk/Localize.xaml@@ -463,6 +463,12 @@<v:String x:Key="title_decompression_more">Декомпресія NTFS</v:String><v:String x:Key="text_decompression_more">Відключає стиснення, відновлюючи файли до їх початкового обсягу та прискорюючи доступ до них.</v:String><v:String x:Key="btntext_overview_more">Огляд</v:String>++ <v:String x:Key="title_over_more">Підтвердження очищення диска</v:String>+ <v:String x:Key="text_over_more">На вашому диску знайдено папку Windows.old, яка містить файли попередньої версії Windows і займає значний обсяг пам’яті. Зверніть увагу: після видалення вміст папки не можна буде відновити, тому переконайтеся, що ви зберегли всі необхідні файли.</v:String>+ <v:String x:Key="question_over_more">Бажаєте продовжити очищення та видалити папку Windows.old?</v:String>+ <v:String x:Key="btn_agree_more">Погодитись</v:String>+ <v:String x:Key="btn_decline_more">Відхилити</v:String><!--#endregion--></ResourceDictionary>diff --git a/.Source/GTweak/Utilities/Tweaks/ClearingMemory.cs b/.Source/GTweak/Utilities/Tweaks/ClearingMemory.csindex f7136f57..70b4dadd 100644--- a/.Source/GTweak/Utilities/Tweaks/ClearingMemory.cs+++ b/.Source/GTweak/Utilities/Tweaks/ClearingMemory.cs@@ -5,6 +5,7 @@ using System;using System.Collections.Generic;using System.ComponentModel;using System.Diagnostics;+using System.IO;using System.Runtime.InteropServices;using System.Security.Principal;using System.Threading.Tasks;@@ -49,6 +50,8 @@ namespace GTweak.Utilities.Tweaksinternal class ClearingMemory{+ internal static bool IsWinOldExists => Directory.Exists(Path.Combine(StoragePaths.SystemDisk, "Windows.old"));+private const int SE_PRIVILEGE_ENABLED = 2;private const string SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege";private const string SE_PROFILE_SINGLE_PROCESS_NAME = "SeProfileSingleProcessPrivilege";@@ -175,8 +178,17 @@ namespace GTweak.Utilities.Tweaksreturn num != 0;}- private static void ClearTempSystemCache()+ private static void ClearTempSystemCache(bool shouldRemoveWinOld = false){+ if (shouldRemoveWinOld)+ {+ string filePath = Path.Combine(StoragePaths.SystemDisk, "Windows.old");+ TrustedInstaller.CreateProcessAsTrustedInstaller(SettingsRepository.PID, $"сmd.exe /c takeown /f \"{filePath}\"");+ TrustedInstaller.CreateProcessAsTrustedInstaller(SettingsRepository.PID, $"cmd.exe /c icacls \"{filePath}\" /inheritance:r /remove S-1-5-32-544 S-1-5-11 S-1-5-32-545 S-1-5-18");+ TrustedInstaller.CreateProcessAsTrustedInstaller(SettingsRepository.PID, $"cmd.exe /c icacls \"{filePath}\" /grant %username%:F");+ TrustedInstaller.CreateProcessAsTrustedInstaller(SettingsRepository.PID, $"cmd.exe /c rd /s /q \"{filePath}\"");+ }+TrustedInstaller.CreateProcessAsTrustedInstaller(SettingsRepository.PID, @$"cmd.exe /c rd /s /q {StoragePaths.SystemDisk}Windows\Temp & " +@$"rd /s /q %localappdata%\Temp & rd /s /q {StoragePaths.SystemDisk}Windows\ff*.tmp & rd /s /q {StoragePaths.SystemDisk}Windows\History\* & " +$@"rd /s /q {StoragePaths.SystemDisk}Windows\CbsTemp\* & rd /s /q {StoragePaths.SystemDisk}Windows\System32\SleepStudy\* & " +@@ -198,10 +210,10 @@ namespace GTweak.Utilities.Tweaks});}- internal async void StartMemoryCleanup()+ internal async void StartMemoryCleanup(bool removeWinOldFlag = false){BackgroundQueue backgroundQueue = new BackgroundQueue();- await backgroundQueue.QueueTask(delegate { ClearFileSystemCache(true); EmptyWorkingSetFunction(); ClearTempSystemCache(); });+ await backgroundQueue.QueueTask(delegate { ClearFileSystemCache(true); EmptyWorkingSetFunction(); ClearTempSystemCache(removeWinOldFlag); });new ViewNotification(500).Show("", "info", "clear_ram_notification");}}diff --git a/.Source/GTweak/View/MoreView.xaml b/.Source/GTweak/View/MoreView.xamlindex 3cb23b35..58478736 100644--- a/.Source/GTweak/View/MoreView.xaml+++ b/.Source/GTweak/View/MoreView.xaml@@ -7,43 +7,70 @@xmlns:UserControl="clr-namespace:GTweak.Assets.UserControl"mc:Ignorable="d" d:DesignHeight="550" d:DesignWidth="1100" Style="{StaticResource LaunchPage}"><Grid>- <Grid.RowDefinitions>- <RowDefinition/>- <RowDefinition Height="10*"/>- </Grid.RowDefinitions>+ <Grid x:Name="Overlay" Panel.ZIndex="1" Visibility="Collapsed">+ <Grid Background="{StaticResource Color_Background_Dark}" Opacity="0.9"/>+ <Grid HorizontalAlignment="Center" VerticalAlignment="Center" Height="auto" Width="auto">+ <StackPanel Orientation="Vertical">+ <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">+ <Image Width="25">+ <Image.Style>+ <Style TargetType="Image">+ <Setter Property="Source" Value="{StaticResource DI_Warning}"/>+ </Style>+ </Image.Style>+ </Image>+ <TextBlock Text="{DynamicResource title_over_more}" Foreground="{StaticResource Color_Highlighted}" Height="auto" Width="auto" FontFamily="{StaticResource Jura}" FontSize="20px" HorizontalAlignment="Left" TextAlignment="Center" Margin="10,0,0,0"/>+ </StackPanel>+ <TextBlock Margin="0,10,0,0" Text="{DynamicResource text_over_more}" Foreground="{StaticResource Color_TetBlock_Inactivity}" Height="auto" Width="583" FontFamily="{StaticResource Jura}" FontSize="16px" TextAlignment="Justify" FontStretch="Medium" TextWrapping="Wrap"/>++ <TextBlock Margin="0,20,0,0" Text="{DynamicResource question_over_more}" Foreground="{StaticResource Color_Accent}" Height="auto" Width="512" FontFamily="{StaticResource Jura}" FontSize="16px" TextAlignment="Center" FontStretch="Medium" TextWrapping="Wrap"/>+ <Grid Margin="0,20,0,0" HorizontalAlignment="Center" Width="345">+ <Button x:Name="BtnAgree" Content="{DynamicResource btn_agree_more}" Style="{StaticResource BtnDefaultM}" FontSize="15px" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Height="30" Cursor="Hand"/>+ <Button x:Name="BtnDecline" Content="{DynamicResource btn_decline_more}" Style="{StaticResource BtnDefault}" FontSize="15px" HorizontalAlignment="Right" VerticalAlignment="Top" Width="120" Height="30" Cursor="Hand"/>+ </Grid>+ </StackPanel>+ </Grid>+ </Grid>++ <Grid>+ <Grid.RowDefinitions>+ <RowDefinition/>+ <RowDefinition Height="10*"/>+ </Grid.RowDefinitions>- <Grid Grid.Row="0">- <TextBlock x:Name="test" Width="Auto" Height="auto" FontFamily="{StaticResource Jura}" FontSize="13pt" Foreground="{StaticResource Color_TetBlock_Inactivity}" HorizontalAlignment="Center" VerticalAlignment="Top" KeyboardNavigation.IsTabStop="False" Margin="0,10,0,0">+ <Grid Grid.Row="0">+ <TextBlock x:Name="test" Width="Auto" Height="auto" FontFamily="{StaticResource Jura}" FontSize="13pt" Foreground="{StaticResource Color_TetBlock_Inactivity}" HorizontalAlignment="Center" VerticalAlignment="Top" KeyboardNavigation.IsTabStop="False" Margin="0,10,0,0"><Run Text="{DynamicResource text0_more}"/><Run Text="{DynamicResource text1_more}" Foreground="{StaticResource Color_Accent}"/><Run Text="{DynamicResource text2_more}"/>- </TextBlock>- </Grid>+ </TextBlock>+ </Grid>- <Grid Grid.Row="1">- <ScrollViewer Style="{StaticResource ScrollPage}">- <StackPanel>- <UniformGrid Rows="1" Columns="3">- <UserControl:Card ImageSource ="{StaticResource DI_LicenseWindows}" Title="{DynamicResource title_licens_more}" Description="{DynamicResource text_licens_more}" BtnContent="{DynamicResource btntext_licens_more}" ClickButton="BtnLicenseWindows_ClickButton"/>- <UserControl:Card ImageSource="{StaticResource DI_BackupSystem}" Title="{DynamicResource title_createpoint_more}" Description="{DynamicResource text_createpoint_more}" BtnContent="{DynamicResource btntext_createpoint_more}" ClickButton="BtnRestorePoint_ClickButton"/>- <UserControl:Card ImageSource="{StaticResource DI_RecoverySystem}" Title="{DynamicResource title_recovery_more}" Description="{DynamicResource text_recovery_more}" BtnContent="{DynamicResource btntext_recovery_more}" ClickButton="BtnRecoveyLaunch_ClickButton"/>- </UniformGrid>+ <Grid Grid.Row="1">+ <ScrollViewer Style="{StaticResource ScrollPage}">+ <StackPanel>+ <UniformGrid Rows="1" Columns="3">+ <UserControl:Card ImageSource ="{StaticResource DI_LicenseWindows}" Title="{DynamicResource title_licens_more}" Description="{DynamicResource text_licens_more}" BtnContent="{DynamicResource btntext_licens_more}" ClickButton="BtnLicenseWindows_ClickButton"/>+ <UserControl:Card ImageSource="{StaticResource DI_BackupSystem}" Title="{DynamicResource title_createpoint_more}" Description="{DynamicResource text_createpoint_more}" BtnContent="{DynamicResource btntext_createpoint_more}" ClickButton="BtnRestorePoint_ClickButton"/>+ <UserControl:Card ImageSource="{StaticResource DI_RecoverySystem}" Title="{DynamicResource title_recovery_more}" Description="{DynamicResource text_recovery_more}" BtnContent="{DynamicResource btntext_recovery_more}" ClickButton="BtnRecoveyLaunch_ClickButton"/>+ </UniformGrid>- <UniformGrid Rows="1" Columns="3" Margin="0,20,0,0">- <UserControl:Card ImageSource="{StaticResource DI_Trash}" Title="{DynamicResource title_clear_more}" Description="{DynamicResource text_clear_more}" BtnContent="{DynamicResource btntext_clear_more}" ClickButton="BtnClear_ClickButton"/>- <UserControl:Card ImageSource="{StaticResource DI_DefragDisable}" Title="{DynamicResource title_defrag_off_more}" Description="{DynamicResource text_defrag_off_more}" BtnContent="{DynamicResource btntext_disable_more}" ClickButton="BtnDisableDefrag_ClickButton"/>- <UserControl:Card ImageSource="{StaticResource DI_DisableRecovery}" Title="{DynamicResource title_disablepoint_more}" Description="{DynamicResource text_disablepoint_more}" BtnContent="{DynamicResource btntext_disable_more}" ClickButton="BtnDisableRecovery_ClickButton"/>- </UniformGrid>+ <UniformGrid Rows="1" Columns="3" Margin="0,20,0,0">+ <UserControl:Card ImageSource="{StaticResource DI_Trash}" Title="{DynamicResource title_clear_more}" Description="{DynamicResource text_clear_more}" BtnContent="{DynamicResource btntext_clear_more}" ClickButton="BtnClear_ClickButton"/>+ <UserControl:Card ImageSource="{StaticResource DI_DefragDisable}" Title="{DynamicResource title_defrag_off_more}" Description="{DynamicResource text_defrag_off_more}" BtnContent="{DynamicResource btntext_disable_more}" ClickButton="BtnDisableDefrag_ClickButton"/>+ <UserControl:Card ImageSource="{StaticResource DI_DisableRecovery}" Title="{DynamicResource title_disablepoint_more}" Description="{DynamicResource text_disablepoint_more}" BtnContent="{DynamicResource btntext_disable_more}" ClickButton="BtnDisableRecovery_ClickButton"/>+ </UniformGrid>- <UniformGrid Rows="1" Columns="3" Margin="0,20,0,20">- <UserControl:Card ImageSource="{StaticResource DI_DefragEnable}" Title="{DynamicResource title_defrag_on_more}" Description="{DynamicResource text_defrag_on_more}" BtnContent="{DynamicResource btntext_enable_more}" ClickButton="BtnEnableDefrag_ClickButton"/>- <UserControl:Card ImageSource="{StaticResource DI_Compression}" Title="{DynamicResource title_compression_more}" Description="{DynamicResource text_compression_more}" BtnContent="{DynamicResource btntext_overview_more}" ClickButton="BtnCompression_ClickButton"/>- <UserControl:Card ImageSource="{StaticResource DI_Decompression}" Title="{DynamicResource title_decompression_more}" Description="{DynamicResource text_decompression_more}" BtnContent="{DynamicResource btntext_overview_more}" ClickButton="BtnDecompression_ClickButton"/>- </UniformGrid>+ <UniformGrid Rows="1" Columns="3" Margin="0,20,0,20">+ <UserControl:Card ImageSource="{StaticResource DI_DefragEnable}" Title="{DynamicResource title_defrag_on_more}" Description="{DynamicResource text_defrag_on_more}" BtnContent="{DynamicResource btntext_enable_more}" ClickButton="BtnEnableDefrag_ClickButton"/>+ <UserControl:Card ImageSource="{StaticResource DI_Compression}" Title="{DynamicResource title_compression_more}" Description="{DynamicResource text_compression_more}" BtnContent="{DynamicResource btntext_overview_more}" ClickButton="BtnCompression_ClickButton"/>+ <UserControl:Card ImageSource="{StaticResource DI_Decompression}" Title="{DynamicResource title_decompression_more}" Description="{DynamicResource text_decompression_more}" BtnContent="{DynamicResource btntext_overview_more}" ClickButton="BtnDecompression_ClickButton"/>+ </UniformGrid></StackPanel>- </ScrollViewer>+ </ScrollViewer>+ </Grid>+</Grid>-</Grid></UserControl>diff --git a/.Source/GTweak/View/MoreView.xaml.cs b/.Source/GTweak/View/MoreView.xaml.csindex d1608a99..fbb4b55e 100644--- a/.Source/GTweak/View/MoreView.xaml.cs+++ b/.Source/GTweak/View/MoreView.xaml.cs@@ -6,16 +6,36 @@ using GTweak.Windows;using Ookii.Dialogs.Wpf;using System;using System.IO;+using System.Threading.Tasks;+using System.Windows;+using System.Windows.Media.Animation;namespace GTweak.View{public partial class MoreView{+ private bool _isWinOldRemoval = false;+ private static bool _hasDeclined = false;+public MoreView(){InitializeComponent();}+ private void OverlayAnimation(double from, double to, double duration, EventHandler onComplete = null)+ {+ DoubleAnimation doubleAnim = new DoubleAnimation+ {+ From = from,+ To = to,+ Duration = TimeSpan.FromSeconds(duration),+ EasingFunction = new QuadraticEase()+ };+ if (onComplete != null) { doubleAnim.Completed += onComplete; }+ Timeline.SetDesiredFrameRate(doubleAnim, 400);+ Overlay.BeginAnimation(OpacityProperty, doubleAnim);+ }+private async void BtnLicenseWindows_ClickButton(object sender, EventArgs e){if (WindowsLicense.IsWindowsActivated)@@ -41,7 +61,42 @@ namespace GTweak.Viewprivate void BtnRecoveyLaunch_ClickButton(object sender, EventArgs e) => SystemMaintenance.StartRecovery();- private void BtnClear_ClickButton(object sender, EventArgs e) => new ClearingMemory().StartMemoryCleanup();+ private async void BtnClear_ClickButton(object sender, EventArgs e)+ {+ if (ClearingMemory.IsWinOldExists && !_hasDeclined)+ {+ Overlay.Visibility = Visibility.Visible;++ OverlayAnimation(0, 1, 0.3);++ TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();++ void AgreeHandler(object sender, RoutedEventArgs args)+ {+ tcs.TrySetResult(true);+ BtnAgree.PreviewMouseLeftButtonDown -= AgreeHandler;+ BtnDecline.PreviewMouseLeftButtonDown -= DeclineHandler;+ }++ void DeclineHandler(object sender, RoutedEventArgs args)+ {+ tcs.TrySetResult(false);+ BtnAgree.PreviewMouseLeftButtonDown -= AgreeHandler;+ BtnDecline.PreviewMouseLeftButtonDown -= DeclineHandler;+ _hasDeclined = true;+ }++ BtnAgree.PreviewMouseLeftButtonDown += AgreeHandler;+ BtnDecline.PreviewMouseLeftButtonDown += DeclineHandler;++ try { _isWinOldRemoval = await tcs.Task; }+ catch (TaskCanceledException) { _isWinOldRemoval = false; }++ OverlayAnimation(1, 0, 0.25, (s, e) => Overlay.Visibility = Visibility.Collapsed);+ }++ new ClearingMemory().StartMemoryCleanup(_isWinOldRemoval);+ }private void BtnDisableDefrag_ClickButton(object sender, EventArgs e) => SystemMaintenance.SetDefragState(false);diff --git a/.Source/GTweak/View/PakagesView.xaml.cs b/.Source/GTweak/View/PakagesView.xaml.csindex 228a8d2d..83c6f245 100644--- a/.Source/GTweak/View/PakagesView.xaml.cs+++ b/.Source/GTweak/View/PakagesView.xaml.cs@@ -44,6 +44,20 @@ namespace GTweak.View_timer.Start();}+ private void OverlayAnimation(double from, double to, double duration, EventHandler onComplete = null)+ {+ DoubleAnimation doubleAnim = new DoubleAnimation+ {+ From = from,+ To = to,+ Duration = TimeSpan.FromSeconds(duration),+ EasingFunction = new QuadraticEase()+ };+ if (onComplete != null) { doubleAnim.Completed += onComplete; }+ Timeline.SetDesiredFrameRate(doubleAnim, 400);+ Overlay.BeginAnimation(OpacityProperty, doubleAnim);+ }+private void Apps_MouseEnter(object sender, MouseEventArgs e){string descriptionApp = (string)FindResource(((Image)sender).Name + "_applications");@@ -94,7 +108,8 @@ namespace GTweak.ViewBtnDelete.PreviewMouseLeftButtonDown += DeleteHandler;BtnCancel.PreviewMouseLeftButtonDown += CancelHandler;- _isWebViewRemoval = await tcs.Task;+ try { _isWebViewRemoval = await tcs.Task; }+ catch (TaskCanceledException) { _isWebViewRemoval = false; }OverlayAnimation(1, 0, 0.25, (s, e) => Overlay.Visibility = Visibility.Collapsed);}@@ -230,20 +245,5 @@ namespace GTweak.Viewimage.Source = AvailabilityInstalledPackage(packageName, packageName == "OneDrive");}}--- private void OverlayAnimation(double from, double to, double duration, EventHandler onComplete = null)- {- DoubleAnimation doubleAnim = new DoubleAnimation- {- From = from,- To = to,- Duration = TimeSpan.FromSeconds(duration),- EasingFunction = new QuadraticEase()- };- if (onComplete != null) { doubleAnim.Completed += onComplete; }- Timeline.SetDesiredFrameRate(doubleAnim, 400);- Overlay.BeginAnimation(OpacityProperty, doubleAnim);- }}}