├── .gitignore ├── LICENSE ├── README.md ├── Screenshot.png └── SharpDiskSweeper ├── DiskSweeper.sln └── DiskSweeper ├── App.config ├── App.xaml ├── App.xaml.cs ├── ConfigurationHelper.cs ├── DiskItem.cs ├── DiskSweeper.csproj ├── DiskSweeper.ico ├── FileInfoExtensions.cs ├── GridViewSort.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── Resources ├── File.png └── Folder.png ├── ShellExtensionAdder.cs └── SweepEngine.cs /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Yang Wang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sharp Disk Sweeper 2 | 3 | Sharp Disk Sweeper is a very useful tool that helps reveal outstanding huge files/folders that are eating up your disk space the most. The idea is inspired by the popular macOS app [OmniDiskSweeper](https://www.omnigroup.com/more/). 4 | 5 | ![Screenshot](https://github.com/luanshixia/SharpDiskSweeper/raw/master/Screenshot.png) 6 | 7 | You can [download it](https://github.com/luanshixia/SharpDiskSweeper/releases) to try it out. 8 | 9 | Sharp Disk Sweeper is written in C# and WPF. The project is a great example for developers who want to learn WPF and XAML, especially on how to customize the look and feel of standard controls using styles and templates. The project also demonstrates how to effectively start/cancel background tasks with `async` and `await` with the UI still responsive. 10 | 11 | Star us, tell your friends, and give us feedback! 12 | -------------------------------------------------------------------------------- /Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luanshixia/SharpDiskSweeper/1fbce43ce2306cd2dd1ab21cdde01e3eaac4fbf4/Screenshot.png -------------------------------------------------------------------------------- /SharpDiskSweeper/DiskSweeper.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2035 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiskSweeper", "DiskSweeper\DiskSweeper.csproj", "{ACED01E7-FC11-4B41-BEA2-7CEA6720C4A8}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {ACED01E7-FC11-4B41-BEA2-7CEA6720C4A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {ACED01E7-FC11-4B41-BEA2-7CEA6720C4A8}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {ACED01E7-FC11-4B41-BEA2-7CEA6720C4A8}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {ACED01E7-FC11-4B41-BEA2-7CEA6720C4A8}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {7C8702F7-7F71-4D6C-A8CC-608C72632DD8} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /SharpDiskSweeper/DiskSweeper/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /SharpDiskSweeper/DiskSweeper/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /SharpDiskSweeper/DiskSweeper/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Linq; 3 | using System.Windows; 4 | 5 | namespace DiskSweeper 6 | { 7 | /// 8 | /// Interaction logic for App.xaml 9 | /// 10 | public partial class App : Application 11 | { 12 | public static string StartupPath; 13 | 14 | public void Application_Startup(object sender, StartupEventArgs e) 15 | { 16 | if (e.Args.Length > 0 && Directory.Exists(e.Args[0])) 17 | { 18 | App.StartupPath = e.Args[0]; 19 | } 20 | 21 | //ShellExtensionAdder.AddRegEntries(ShellExtensionAdder.GetRegEntriesToAdd( 22 | // shellObject: "Directory", 23 | // appName: "SharpDiskSweeper", 24 | // caption: "Open with SharpDiskSweeper", 25 | // command: $"\"{typeof(App).Assembly.Location}\" \"%1\"")); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /SharpDiskSweeper/DiskSweeper/ConfigurationHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Media; 8 | 9 | namespace DiskSweeper 10 | { 11 | public static class ConfigurationHelper 12 | { 13 | public static string GetConfiguration(string settingName, string defaultValue = null) 14 | { 15 | return ConfigurationManager.AppSettings.AllKeys.Contains(settingName) 16 | ? ConfigurationManager.AppSettings[settingName] 17 | : defaultValue; 18 | } 19 | 20 | public static long GetConfigurationInt64(string settingName, long defaultValue) 21 | { 22 | return ConfigurationManager.AppSettings.AllKeys.Contains(settingName) 23 | && long.TryParse(ConfigurationManager.AppSettings[settingName], out long result) 24 | ? result 25 | : defaultValue; 26 | } 27 | 28 | public static int GetConfigurationInt32(string settingName, int defaultValue) 29 | { 30 | return ConfigurationManager.AppSettings.AllKeys.Contains(settingName) 31 | && int.TryParse(ConfigurationManager.AppSettings[settingName], out int result) 32 | ? result 33 | : defaultValue; 34 | } 35 | 36 | public static double GetConfigurationDouble(string settingName, double defaultValue) 37 | { 38 | return ConfigurationManager.AppSettings.AllKeys.Contains(settingName) 39 | && double.TryParse(ConfigurationManager.AppSettings[settingName], out double result) 40 | ? result 41 | : defaultValue; 42 | } 43 | 44 | public static TimeSpan GetConfigurationTimeSpan(string settingName, TimeSpan defaultValue) 45 | { 46 | return ConfigurationManager.AppSettings.AllKeys.Contains(settingName) 47 | && TimeSpan.TryParse(ConfigurationManager.AppSettings[settingName], out TimeSpan result) 48 | ? result 49 | : defaultValue; 50 | } 51 | 52 | public static bool GetConfigurationBoolean(string settingName, bool defaultValue) 53 | { 54 | return ConfigurationManager.AppSettings.AllKeys.Contains(settingName) 55 | && bool.TryParse(ConfigurationManager.AppSettings[settingName], out bool result) 56 | ? result 57 | : defaultValue; 58 | } 59 | 60 | public static Guid GetConfigurationGuid(string settingName, Guid defaultValue) 61 | { 62 | return ConfigurationManager.AppSettings.AllKeys.Contains(settingName) 63 | && Guid.TryParse(ConfigurationManager.AppSettings[settingName], out Guid result) 64 | ? result 65 | : defaultValue; 66 | } 67 | 68 | public static Color GetConfigurationColor(string settingName, Color defaultValue) 69 | { 70 | return ConfigurationManager.AppSettings.AllKeys.Contains(settingName) 71 | ? (Color)ColorConverter.ConvertFromString(ConfigurationManager.AppSettings[settingName]) 72 | : defaultValue; 73 | } 74 | 75 | public static T GetConfigurationEnum(string settingName, T defaultValue) where T: struct 76 | { 77 | return ConfigurationManager.AppSettings.AllKeys.Contains(settingName) 78 | && Enum.TryParse(ConfigurationManager.AppSettings[settingName], out T result) 79 | ? result 80 | : defaultValue; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /SharpDiskSweeper/DiskSweeper/DiskItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace DiskSweeper 11 | { 12 | public class DiskItem : INotifyPropertyChanged 13 | { 14 | public DiskItemType Type { get; set; } 15 | public string Name { get; set; } 16 | public long Size { get; set; } 17 | public long SizeOnDisk { get; set; } 18 | public long FilesCount { get; set; } 19 | public long FoldersCount { get; set; } 20 | public DateTime Created { get; set; } 21 | public DateTime Modified { get; set; } 22 | 23 | public string Highlight => this.Size > SweepEngine.P0SizeFloor 24 | ? "P0" 25 | : this.Size > SweepEngine.P1SizeFloor 26 | ? "P1" 27 | : null; 28 | 29 | public string SizeString => this.IsCalculationDone 30 | ? DiskItem.FormatSize(this.Size) 31 | : "..." + DiskItem.FormatSize(this.Size); 32 | 33 | public string SizeOnDiskString => this.IsCalculationDone 34 | ? DiskItem.FormatSize(this.SizeOnDisk) 35 | : "..." + DiskItem.FormatSize(this.SizeOnDisk); 36 | 37 | public event PropertyChangedEventHandler PropertyChanged; 38 | 39 | private bool IsCalculationDone = false; 40 | private readonly DirectoryInfo DirInfo; 41 | 42 | public DiskItem(FileSystemInfo info) 43 | { 44 | if (info is FileInfo fileInfo) 45 | { 46 | this.Type = DiskItemType.File; 47 | this.Name = fileInfo.Name; 48 | this.Size = fileInfo.Length; 49 | this.SizeOnDisk = fileInfo.GetSizeOnDisk(); 50 | this.FilesCount = 1; 51 | this.FoldersCount = 0; 52 | this.Created = fileInfo.CreationTime; 53 | this.Modified = fileInfo.LastWriteTime; 54 | this.IsCalculationDone = true; 55 | } 56 | else if (info is DirectoryInfo directoryInfo) 57 | { 58 | this.Type = DiskItemType.Directory; 59 | this.Name = directoryInfo.Name; 60 | this.Size = 0; 61 | this.SizeOnDisk = 0; 62 | this.FilesCount = 0; 63 | this.FoldersCount = 0; 64 | this.Created = directoryInfo.CreationTime; 65 | this.Modified = directoryInfo.LastWriteTime; 66 | this.DirInfo = directoryInfo; 67 | } 68 | } 69 | 70 | public async Task Start(CancellationToken cancellationToken) 71 | { 72 | if (this.Type == DiskItemType.File) 73 | { 74 | return; 75 | } 76 | 77 | var engine = new SweepEngine(this.DirInfo); 78 | engine.ReportProgress += (sender, e) => this.ReportChanges(engine); 79 | 80 | await Task.Run(() => engine 81 | .CalculateDirectorySizeRecursivelyWithUpdateAsync(this.DirInfo, cancellationToken)); 82 | 83 | this.IsCalculationDone = true; 84 | this.ReportChanges(engine); 85 | } 86 | 87 | private void ReportChanges(SweepEngine engine) 88 | { 89 | (this.Size, this.SizeOnDisk, this.FilesCount, this.FoldersCount) = engine.Result; 90 | 91 | this.NotifyPropertyChanged(nameof(this.Size)); 92 | this.NotifyPropertyChanged(nameof(this.SizeString)); 93 | this.NotifyPropertyChanged(nameof(this.SizeOnDisk)); 94 | this.NotifyPropertyChanged(nameof(this.SizeOnDiskString)); 95 | this.NotifyPropertyChanged(nameof(this.FilesCount)); 96 | this.NotifyPropertyChanged(nameof(this.FoldersCount)); 97 | this.NotifyPropertyChanged(nameof(this.Highlight)); 98 | } 99 | 100 | private void NotifyPropertyChanged(string propertyName) 101 | { 102 | this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 103 | } 104 | 105 | private static string FormatSize(long size) 106 | { 107 | if (size < 1024) 108 | { 109 | return size + " Byte"; 110 | } 111 | else if (size < 1024 * 1024) 112 | { 113 | return (size / 1024) + " KB"; 114 | } 115 | else 116 | { 117 | return (size / 1024 / 1024) + " MB"; 118 | } 119 | } 120 | } 121 | 122 | public enum DiskItemType 123 | { 124 | File, 125 | Directory 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /SharpDiskSweeper/DiskSweeper/DiskSweeper.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {ACED01E7-FC11-4B41-BEA2-7CEA6720C4A8} 8 | WinExe 9 | DiskSweeper 10 | DiskSweeper 11 | v4.8 12 | 512 13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 4 15 | true 16 | 17 | 18 | 19 | AnyCPU 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | AnyCPU 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | DiskSweeper.ico 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 4.0 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | MSBuild:Compile 61 | Designer 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | MSBuild:Compile 71 | Designer 72 | 73 | 74 | App.xaml 75 | Code 76 | 77 | 78 | MainWindow.xaml 79 | Code 80 | 81 | 82 | 83 | 84 | Code 85 | 86 | 87 | True 88 | True 89 | Resources.resx 90 | 91 | 92 | True 93 | Settings.settings 94 | True 95 | 96 | 97 | ResXFileCodeGenerator 98 | Resources.Designer.cs 99 | 100 | 101 | SettingsSingleFileGenerator 102 | Settings.Designer.cs 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /SharpDiskSweeper/DiskSweeper/DiskSweeper.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luanshixia/SharpDiskSweeper/1fbce43ce2306cd2dd1ab21cdde01e3eaac4fbf4/SharpDiskSweeper/DiskSweeper/DiskSweeper.ico -------------------------------------------------------------------------------- /SharpDiskSweeper/DiskSweeper/FileInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace DiskSweeper 11 | { 12 | /// 13 | /// https://stackoverflow.com/questions/3750590/get-size-of-file-on-disk 14 | /// 15 | public static class FileInfoExtensions 16 | { 17 | public static long GetSizeOnDisk(this FileInfo info) 18 | { 19 | int result = GetDiskFreeSpaceW( 20 | info.Directory.Root.FullName, 21 | out uint sectorsPerCluster, 22 | out uint bytesPerSector, 23 | out uint dummy, 24 | out dummy); 25 | 26 | if (result == 0) 27 | { 28 | throw new Win32Exception(); 29 | } 30 | 31 | uint losize = GetCompressedFileSizeW( 32 | info.FullName, 33 | out uint hosize); 34 | 35 | long size = (long)hosize << 32 | losize; 36 | uint clusterSize = sectorsPerCluster * bytesPerSector; 37 | return ((size + clusterSize - 1) / clusterSize) * clusterSize; 38 | } 39 | 40 | [DllImport("kernel32.dll")] 41 | private static extern uint GetCompressedFileSizeW( 42 | [In, MarshalAs(UnmanagedType.LPWStr)] string lpFileName, 43 | [Out, MarshalAs(UnmanagedType.U4)] out uint lpFileSizeHigh); 44 | 45 | [DllImport("kernel32.dll", SetLastError = true, PreserveSig = true)] 46 | private static extern int GetDiskFreeSpaceW( 47 | [In, MarshalAs(UnmanagedType.LPWStr)] string lpRootPathName, 48 | out uint lpSectorsPerCluster, 49 | out uint lpBytesPerSector, 50 | out uint lpNumberOfFreeClusters, 51 | out uint lpTotalNumberOfClusters); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /SharpDiskSweeper/DiskSweeper/GridViewSort.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Input; 5 | using System.Windows.Media; 6 | 7 | namespace DiskSweeper 8 | { 9 | /// 10 | /// http://www.thomaslevesque.com/2009/03/27/wpf-automatically-sort-a-gridview-when-a-column-header-is-clicked/ 11 | /// 12 | public static class GridViewSort 13 | { 14 | #region Attached properties 15 | 16 | public static ICommand GetCommand(DependencyObject obj) 17 | { 18 | return (ICommand)obj.GetValue(CommandProperty); 19 | } 20 | 21 | public static void SetCommand(DependencyObject obj, ICommand value) 22 | { 23 | obj.SetValue(CommandProperty, value); 24 | } 25 | 26 | // Using a DependencyProperty as the backing store for Command. This enables animation, styling, binding, etc... 27 | public static readonly DependencyProperty CommandProperty = 28 | DependencyProperty.RegisterAttached( 29 | "Command", 30 | typeof(ICommand), 31 | typeof(GridViewSort), 32 | new UIPropertyMetadata( 33 | null, 34 | (d, e) => 35 | { 36 | if (d is ItemsControl listView) 37 | { 38 | if (!GetAutoSort(listView)) // Don't change click handler if AutoSort enabled 39 | { 40 | if (e.OldValue != null && e.NewValue == null) 41 | { 42 | listView.RemoveHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(ColumnHeader_Click)); 43 | } 44 | if (e.OldValue == null && e.NewValue != null) 45 | { 46 | listView.AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(ColumnHeader_Click)); 47 | } 48 | } 49 | } 50 | } 51 | ) 52 | ); 53 | 54 | public static bool GetAutoSort(DependencyObject obj) 55 | { 56 | return (bool)obj.GetValue(AutoSortProperty); 57 | } 58 | 59 | public static void SetAutoSort(DependencyObject obj, bool value) 60 | { 61 | obj.SetValue(AutoSortProperty, value); 62 | } 63 | 64 | // Using a DependencyProperty as the backing store for AutoSort. This enables animation, styling, binding, etc... 65 | public static readonly DependencyProperty AutoSortProperty = 66 | DependencyProperty.RegisterAttached( 67 | "AutoSort", 68 | typeof(bool), 69 | typeof(GridViewSort), 70 | new UIPropertyMetadata( 71 | false, 72 | (d, e) => 73 | { 74 | if (d is ListView listView) 75 | { 76 | if (GetCommand(listView) == null) // Don't change click handler if a command is set 77 | { 78 | bool oldValue = (bool)e.OldValue; 79 | bool newValue = (bool)e.NewValue; 80 | if (oldValue && !newValue) 81 | { 82 | listView.RemoveHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(ColumnHeader_Click)); 83 | } 84 | if (!oldValue && newValue) 85 | { 86 | listView.AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(ColumnHeader_Click)); 87 | } 88 | } 89 | } 90 | } 91 | ) 92 | ); 93 | 94 | public static string GetPropertyName(DependencyObject obj) 95 | { 96 | return (string)obj.GetValue(PropertyNameProperty); 97 | } 98 | 99 | public static void SetPropertyName(DependencyObject obj, string value) 100 | { 101 | obj.SetValue(PropertyNameProperty, value); 102 | } 103 | 104 | // Using a DependencyProperty as the backing store for PropertyName. This enables animation, styling, binding, etc... 105 | public static readonly DependencyProperty PropertyNameProperty = 106 | DependencyProperty.RegisterAttached( 107 | "PropertyName", 108 | typeof(string), 109 | typeof(GridViewSort), 110 | new UIPropertyMetadata(null) 111 | ); 112 | 113 | #endregion 114 | 115 | #region Column header click event handler 116 | 117 | private static void ColumnHeader_Click(object sender, RoutedEventArgs e) 118 | { 119 | if (e.OriginalSource is GridViewColumnHeader headerClicked) 120 | { 121 | string propertyName = GetPropertyName(headerClicked.Column); 122 | if (!string.IsNullOrEmpty(propertyName)) 123 | { 124 | ListView listView = GetAncestor(headerClicked); 125 | if (listView != null) 126 | { 127 | ICommand command = GetCommand(listView); 128 | if (command != null) 129 | { 130 | if (command.CanExecute(propertyName)) 131 | { 132 | command.Execute(propertyName); 133 | } 134 | } 135 | else if (GetAutoSort(listView)) 136 | { 137 | ApplySort(listView.Items, propertyName); 138 | } 139 | } 140 | } 141 | } 142 | } 143 | 144 | #endregion 145 | 146 | #region Helper methods 147 | 148 | public static T GetAncestor(DependencyObject reference) where T : DependencyObject 149 | { 150 | DependencyObject parent = VisualTreeHelper.GetParent(reference); 151 | while (!(parent is T)) 152 | { 153 | parent = VisualTreeHelper.GetParent(parent); 154 | } 155 | 156 | return parent as T; 157 | } 158 | 159 | public static void ApplySort(ICollectionView view, string propertyName) 160 | { 161 | ListSortDirection direction = ListSortDirection.Ascending; 162 | if (view.SortDescriptions.Count > 0) 163 | { 164 | SortDescription currentSort = view.SortDescriptions[0]; 165 | if (currentSort.PropertyName == propertyName) 166 | { 167 | if (currentSort.Direction == ListSortDirection.Ascending) 168 | { 169 | direction = ListSortDirection.Descending; 170 | } 171 | else 172 | { 173 | direction = ListSortDirection.Ascending; 174 | } 175 | } 176 | 177 | view.SortDescriptions.Clear(); 178 | } 179 | 180 | if (!string.IsNullOrEmpty(propertyName)) 181 | { 182 | view.SortDescriptions.Add(new SortDescription(propertyName, direction)); 183 | } 184 | } 185 | 186 | #endregion 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /SharpDiskSweeper/DiskSweeper/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 53 | 54 | 55 | 56 |