Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
re for class nfts compressor
Greedeks90d518930c58
diff --git a/.Source/GTweak/Utilities/Tweaks/NTFSCompressor.cs b/.Source/GTweak/Utilities/Tweaks/NTFSCompressor.csindex 0559b176..d0806ce4 100644--- a/.Source/GTweak/Utilities/Tweaks/NTFSCompressor.cs+++ b/.Source/GTweak/Utilities/Tweaks/NTFSCompressor.cs@@ -1,6 +1,4 @@-using GTweak.Utilities.Controls;-using GTweak.Utilities.Helpers;-using Microsoft.Win32.SafeHandles;+using Microsoft.Win32.SafeHandles;using System;using System.IO;using System.Runtime.InteropServices;@@ -8,12 +6,12 @@ using System.Text;namespace GTweak.Utilities.Tweaks{- internal class NTFSCompressor+ internal sealed class NTFSCompressor{- const ushort COMPRESSION_FORMAT_NONE = 0x0000;- const ushort COMPRESSION_FORMAT_DEFAULT = 0x0001;- const uint FSCTL_SET_COMPRESSION = 0x9C040;- const FileAttributes BackupSemantics = (FileAttributes)0x02000000;+ private const ushort COMPRESSION_FORMAT_NONE = 0x0000;+ private const ushort COMPRESSION_FORMAT_DEFAULT = 0x0001;+ private const uint FSCTL_SET_COMPRESSION = 0x9C040;+ private const FileAttributes BackupSemantics = (FileAttributes)0x02000000;[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]private static extern SafeFileHandle CreateFile(@@ -47,7 +45,7 @@ namespace GTweak.Utilities.TweaksStringBuilder lpFileSystemNameBuffer,int nFileSystemNameSize);- public static bool IsNtfs(string path)+ internal static bool IsSupportNtfs(string path){string root = Path.GetPathRoot(Path.GetFullPath(path));if (!string.IsNullOrEmpty(root))@@ -59,29 +57,22 @@ namespace GTweak.Utilities.Tweaksreturn false;}- public static void SetCompression(string directoryPath, bool compress)+ internal static void SetCompression(string directoryPath, bool compress){- if (IsNtfs(directoryPath))- {- TakingOwnership.GrantDebugPrivilege();-- UpdateCompressionState(directoryPath, compress);+ UpdateCompressionState(directoryPath, compress);- foreach (string dir in Directory.GetDirectories(directoryPath, "*", SearchOption.AllDirectories))- UpdateCompressionState(dir, compress);+ foreach (string dir in Directory.GetDirectories(directoryPath, "*", SearchOption.AllDirectories))+ UpdateCompressionState(dir, compress);- foreach (string file in Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories))- UpdateCompressionState(file, compress);- }- else- new ViewNotification().Show("", "warn", "notsupport_ntfs_notification");+ foreach (string file in Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories))+ UpdateCompressionState(file, compress);}private static void UpdateCompressionState(string path, bool compress){FileAttributes attributes = File.GetAttributes(path);FileAttributes flags = (attributes & FileAttributes.Directory) == FileAttributes.Directory ? BackupSemantics : FileAttributes.Normal;- using SafeFileHandle handle = CreateFile(path, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, IntPtr.Zero, FileMode.Open, flags,IntPtr.Zero);+ using SafeFileHandle handle = CreateFile(path, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, IntPtr.Zero, FileMode.Open, flags, IntPtr.Zero);ushort compressionFormat = compress ? COMPRESSION_FORMAT_DEFAULT : COMPRESSION_FORMAT_NONE;DeviceIoControl(handle, FSCTL_SET_COMPRESSION, ref compressionFormat, sizeof(ushort), IntPtr.Zero, 0, out int bytesReturned, IntPtr.Zero);}diff --git a/.Source/GTweak/View/MoreView.xaml.cs b/.Source/GTweak/View/MoreView.xaml.csindex a1cb81a6..440eb254 100644--- a/.Source/GTweak/View/MoreView.xaml.cs+++ b/.Source/GTweak/View/MoreView.xaml.cs@@ -63,18 +63,23 @@ namespace GTweak.Viewif (folderDialog.ShowDialog() == true){string selectedPath = folderDialog.SelectedPath;- if ((new DirectoryInfo(selectedPath).Attributes & FileAttributes.Compressed) != FileAttributes.Compressed)+ if (NTFSCompressor.IsSupportNtfs(selectedPath)){- BackgroundQueue backgroundQueue = new BackgroundQueue();- await backgroundQueue.QueueTask(delegate+ if ((new DirectoryInfo(selectedPath).Attributes & FileAttributes.Compressed) != FileAttributes.Compressed){- try { NTFSCompressor.SetCompression(selectedPath, true); }- catch { new ViewNotification().Show("", "warn", "error_compression_notification"); }- });- await backgroundQueue.QueueTask(delegate { new ViewNotification(300).Show("", "info", "succes_compression_notification"); });+ BackgroundQueue backgroundQueue = new BackgroundQueue();+ await backgroundQueue.QueueTask(delegate+ {+ try { NTFSCompressor.SetCompression(selectedPath, true); }+ catch { new ViewNotification().Show("", "warn", "error_compression_notification"); }+ });+ await backgroundQueue.QueueTask(delegate { new ViewNotification(300).Show("", "info", "succes_compression_notification"); });+ }+ else+ new ViewNotification().Show("", "info", "ready_compression_notification");}else- new ViewNotification().Show("", "info", "ready_compression_notification");+ new ViewNotification().Show("", "warn", "notsupport_ntfs_notification");}}@@ -85,19 +90,24 @@ namespace GTweak.Viewif (folderDialog.ShowDialog() == true){string selectedPath = folderDialog.SelectedPath;- if ((new DirectoryInfo(selectedPath).Attributes & FileAttributes.Compressed) == FileAttributes.Compressed)+ if (NTFSCompressor.IsSupportNtfs(selectedPath)){- BackgroundQueue backgroundQueue = new BackgroundQueue();- await backgroundQueue.QueueTask(delegate+ if ((new DirectoryInfo(selectedPath).Attributes & FileAttributes.Compressed) == FileAttributes.Compressed){- try { NTFSCompressor.SetCompression(selectedPath, false); }- catch { new ViewNotification().Show("", "warn", "error_compression_notification"); }+ BackgroundQueue backgroundQueue = new BackgroundQueue();+ await backgroundQueue.QueueTask(delegate+ {+ try { NTFSCompressor.SetCompression(selectedPath, false); }+ catch { new ViewNotification().Show("", "warn", "error_compression_notification"); }- });- await backgroundQueue.QueueTask(delegate { new ViewNotification(300).Show("", "info", "succes_decompression_notification"); });+ });+ await backgroundQueue.QueueTask(delegate { new ViewNotification(300).Show("", "info", "succes_decompression_notification"); });+ }+ else+ new ViewNotification().Show("", "info", "ready_decompression_notification");}else- new ViewNotification().Show("", "info", "ready_decompression_notification");+ new ViewNotification().Show("", "warn", "notsupport_ntfs_notification");}}}diff --git a/.Source/GTweak/Windows/MainWindow.xaml.cs b/.Source/GTweak/Windows/MainWindow.xaml.csindex 58ebc31d..b0290d1e 100644--- a/.Source/GTweak/Windows/MainWindow.xaml.cs+++ b/.Source/GTweak/Windows/MainWindow.xaml.cs@@ -1,7 +1,6 @@using GTweak.Utilities.Configuration;using GTweak.Utilities.Controls;using GTweak.Utilities.Helpers.Animation;-using GTweak.Utilities.Tweaks;using GTweak.Windows;using System;using System.ComponentModel;