From 1de70724b0ee27c573f8b28efa1c766048b9fed1 Mon Sep 17 00:00:00 2001 From: Jordan Wages Date: Thu, 28 Feb 2019 01:17:38 -0600 Subject: [PATCH] Ugly Safety Checkin Everything works. Mostly. It is kinda of flimsy so it needs to be cleaned up. --- mdfinder/App.config | 3 + mdfinder/DBHelper.cs | 11 +- mdfinder/DuplicateFileGroup.cs | 77 ++++++ mdfinder/FileRecord.cs | 132 +++++++++- mdfinder/Icons.xaml | 45 ++++ .../Localization/Localization.Designer.cs | 125 ++++++++-- mdfinder/Localization/Localization.resx | 45 +++- mdfinder/MainWindow.xaml | 229 +++++++++++------ mdfinder/MainWindow.xaml.cs | 234 +++++++++++++++--- mdfinder/OptionsWindow.xaml | 19 +- mdfinder/OptionsWindow.xaml.cs | 13 + mdfinder/Properties/Settings.Designer.cs | 12 + mdfinder/Properties/Settings.settings | 3 + mdfinder/ScanResults.cs | 65 +++++ mdfinder/Scanner.cs | 9 + mdfinder/mdfinder.csproj | 7 + mdfinder/packages.config | 1 + 17 files changed, 885 insertions(+), 145 deletions(-) create mode 100644 mdfinder/DuplicateFileGroup.cs create mode 100644 mdfinder/ScanResults.cs diff --git a/mdfinder/App.config b/mdfinder/App.config index 86c251c..004b9b3 100644 --- a/mdfinder/App.config +++ b/mdfinder/App.config @@ -36,6 +36,9 @@ en-US + + + \ No newline at end of file diff --git a/mdfinder/DBHelper.cs b/mdfinder/DBHelper.cs index f25c5a0..685db31 100644 --- a/mdfinder/DBHelper.cs +++ b/mdfinder/DBHelper.cs @@ -63,8 +63,15 @@ namespace mdfinder /// The hash provider. public void InsertFileRecord(string path, long size, string hash, string hashProvider) { - var fileRecord = new FileRecord() { Path = new Uri(path), Size = size, Hash = hash, HashProvider = hashProvider }; - this.FileRecordCollection.Insert(fileRecord); + var fileRecord = new FileRecord(path, size, hash, hashProvider); + this.FileRecordCollection.Upsert(fileRecord); + } + + /// Removes the file record described by ID. + /// The identifier. + public void RemoveFileRecord(string path) + { + this.FileRecordCollection.Delete(fr => fr.Id == path); } /// Gets the file records in this collection. diff --git a/mdfinder/DuplicateFileGroup.cs b/mdfinder/DuplicateFileGroup.cs new file mode 100644 index 0000000..d30ee9b --- /dev/null +++ b/mdfinder/DuplicateFileGroup.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mdfinder +{ + public class DuplicateFileGroup : PropertyChangedAlerter + { + #region Properties + + /// Gets the hash. + /// The hash. + public string Hash { get; } + + /// Gets the number of. + /// The count. + public int Count { get; } + + /// Gets the total size of the file group. + /// The total number of size. + public long TotalSize { get; } + + /// Gets the potential size saving. + /// The potential size saving. + public long PotentialSizeSaving { get; } + + /// Gets or sets the file records. + /// The file records. + public List FileRecords { get; set; } + + #endregion + + /// Constructor. + /// The file records. + /// (Optional) Type of the size savings to calculate. + public DuplicateFileGroup(IEnumerable fileRecords, SavingsType savingsType = SavingsType.SaveBiggest) + { + this.FileRecords = new List(fileRecords); + + //Precalculate stats. + this.Hash = this.FileRecords.Select(fr => fr.Hash).FirstOrDefault(); + this.Count = this.FileRecords.Count(); + + this.TotalSize = this.FileRecords.Sum(fr => fr.Size); + + switch (savingsType) + { + case SavingsType.SaveBiggest: + this.PotentialSizeSaving = this.FileRecords.OrderByDescending(fr => fr.Size).Skip(1).Sum(fr => fr.Size); + break; + case SavingsType.SaveSmallest: + this.PotentialSizeSaving = this.FileRecords.OrderBy(fr => fr.Size).Skip(1).Sum(fr => fr.Size); + break; + case SavingsType.SaveMedian: + //This is kind of hacky, but good enough for our purposes here. CLOSE ENOUGH + var medianFileRecord = this.FileRecords.OrderBy(fr => fr.Size).ElementAt(this.Count / 2); + this.PotentialSizeSaving = this.FileRecords.Except(new[] { medianFileRecord }).Sum(fr => fr.Size); + break; + default: + break; + } + } + + /// Values that represent the ways of saving space. + public enum SavingsType + { + /// Saves the biggest, and presumably highest quality, file. + SaveBiggest, + /// Saves the smallest file. + SaveSmallest, + /// . + SaveMedian + } + } +} diff --git a/mdfinder/FileRecord.cs b/mdfinder/FileRecord.cs index dcd14e8..645c7f4 100644 --- a/mdfinder/FileRecord.cs +++ b/mdfinder/FileRecord.cs @@ -6,29 +6,149 @@ using System.Threading.Tasks; namespace mdfinder { - public class FileRecord + public class FileRecord : PropertyChangedAlerter { + #region Members + + /// The identifier. + private string id; + + /// Full pathname of the file. + private Uri path; + + /// The size. + private long size; + + /// The hash. + private string hash; + + /// The hash provider. + private string hashProvider; + + /// True to keep. + private bool keep; + + #endregion + #region Properties /// Gets or sets the identifier. /// The identifier. - public Int64 Id { get; set; } + public string Id + { + get + { + return this.id; + } + set + { + this.id = value; + OnPropertyChanged(); + } + } /// Gets or sets the full pathname of the file. /// The full pathname of the file. - public Uri Path { get; set; } + public Uri Path + { + get + { + return this.path; + } + set + { + this.path = value; + OnPropertyChanged(); + } + } /// Gets or sets the size. /// The size. - public long Size { get; set; } + public long Size + { + get + { + return this.size; + } + set + { + this.size = value; + OnPropertyChanged(); + } + } /// Gets or sets the hash. /// The hash. - public string Hash { get; set; } + public string Hash + { + get + { + return this.hash; + } + set + { + this.hash = value; + OnPropertyChanged(); + } + } /// Gets or sets the hash provider. /// The hash provider. - public string HashProvider { get; set; } + public string HashProvider + { + get + { + return this.hashProvider; + } + set + { + this.hashProvider = value; + OnPropertyChanged(); + } + } + + /// Gets or sets a value indicating whether to keep the file when processing duplicates. + /// True if keep, false if not. + public bool Keep + { + get + { + return this.keep; + } + set + { + this.keep = value; + OnPropertyChanged(); + } + } + + #endregion + + #region Constructors + + public FileRecord() + { + this.Id = string.Empty; + this.Path = default(Uri); + this.Size = 0; + this.Hash = string.Empty; + this.HashProvider = string.Empty; + } + + /// Constructor. + /// Full pathname of the file. + /// The size. + /// The hash. + /// The hash provider. + public FileRecord(string path, long size, string hash, string hashProvider) + { + this.Id = path; + this.Path = new Uri(path); + this.Size = size; + this.Hash = hash; + this.HashProvider = hashProvider; + + } #endregion } diff --git a/mdfinder/Icons.xaml b/mdfinder/Icons.xaml index 184dd6d..96877c5 100644 --- a/mdfinder/Icons.xaml +++ b/mdfinder/Icons.xaml @@ -170,4 +170,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mdfinder/Localization/Localization.Designer.cs b/mdfinder/Localization/Localization.Designer.cs index def609d..a1a3e77 100644 --- a/mdfinder/Localization/Localization.Designer.cs +++ b/mdfinder/Localization/Localization.Designer.cs @@ -106,7 +106,16 @@ namespace mdfinder.Localization { } /// - /// Looks up a localized string similar to Actions. + /// Looks up a localized string similar to Archive Remaining Files. + /// + public static string ActionArchiveLabel { + get { + return ResourceManager.GetString("ActionArchiveLabel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Duplicate Actions. /// public static string ActionBarLabel { get { @@ -114,6 +123,42 @@ namespace mdfinder.Localization { } } + /// + /// Looks up a localized string similar to Keep Largest. + /// + public static string ActionLargestLabel { + get { + return ResourceManager.GetString("ActionLargestLabel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to KeepSelected. + /// + public static string ActionSelectedLabel { + get { + return ResourceManager.GetString("ActionSelectedLabel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Keep Smallest. + /// + public static string ActionSmallestLabel { + get { + return ResourceManager.GetString("ActionSmallestLabel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Archive Folder. + /// + public static string ArchiveFolderLabel { + get { + return ResourceManager.GetString("ArchiveFolderLabel", resourceCulture); + } + } + /// /// Looks up a localized string similar to Would you like to visit mdfinder to update to the latest version?. /// @@ -159,6 +204,15 @@ namespace mdfinder.Localization { } } + /// + /// Looks up a localized string similar to Keep File. + /// + public static string ColumnHeaderKeep { + get { + return ResourceManager.GetString("ColumnHeaderKeep", resourceCulture); + } + } + /// /// Looks up a localized string similar to Hash. /// @@ -268,29 +322,11 @@ namespace mdfinder.Localization { } /// - /// Looks up a localized string similar to Filters. + /// Looks up a localized string similar to Files. /// - public static string FilterBarLabel { + public static string FilesLabel { get { - return ResourceManager.GetString("FilterBarLabel", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Duplicates. - /// - public static string FilterDuplicatesLabel { - get { - return ResourceManager.GetString("FilterDuplicatesLabel", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Show All. - /// - public static string FilterShowAllLabel { - get { - return ResourceManager.GetString("FilterShowAllLabel", resourceCulture); + return ResourceManager.GetString("FilesLabel", resourceCulture); } } @@ -330,6 +366,15 @@ namespace mdfinder.Localization { } } + /// + /// Looks up a localized string similar to No Preview Available. + /// + public static string NoPreviewLabel { + get { + return ResourceManager.GetString("NoPreviewLabel", resourceCulture); + } + } + /// /// Looks up a localized string similar to OK. /// @@ -384,6 +429,15 @@ namespace mdfinder.Localization { } } + /// + /// Looks up a localized string similar to Potential Space Savings. + /// + public static string PotentialSpaceSavingsLabel { + get { + return ResourceManager.GetString("PotentialSpaceSavingsLabel", resourceCulture); + } + } + /// /// Looks up a localized string similar to Provider Location. /// @@ -429,6 +483,15 @@ namespace mdfinder.Localization { } } + /// + /// Looks up a localized string similar to Scan Location. + /// + public static string ScanningLabel { + get { + return ResourceManager.GetString("ScanningLabel", resourceCulture); + } + } + /// /// Looks up a localized string similar to Scan the selected path. /// @@ -438,6 +501,24 @@ namespace mdfinder.Localization { } } + /// + /// Looks up a localized string similar to Size:. + /// + public static string SizeLabel { + get { + return ResourceManager.GetString("SizeLabel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Size On Disk:. + /// + public static string SizeOnDiskLabel { + get { + return ResourceManager.GetString("SizeOnDiskLabel", resourceCulture); + } + } + /// /// Looks up a localized string similar to Skip Empty Files. /// diff --git a/mdfinder/Localization/Localization.resx b/mdfinder/Localization/Localization.resx index 89b00bc..950bca9 100644 --- a/mdfinder/Localization/Localization.resx +++ b/mdfinder/Localization/Localization.resx @@ -132,8 +132,17 @@ About mdfinder + + Archive Remaining Files + - Actions + Duplicate Actions + + + Keep Largest + + + Keep Smallest Would you like to visit mdfinder to update to the latest version? @@ -186,14 +195,8 @@ File - - Filters - - - Duplicates - - - Show All + + Files Help @@ -240,9 +243,15 @@ Location to Scan + + Scan Location + Scan the selected path + + Size: + Skip Empty Files @@ -255,4 +264,22 @@ Version + + KeepSelected + + + Archive Folder + + + Keep File + + + No Preview Available + + + Potential Space Savings + + + Size On Disk: + \ No newline at end of file diff --git a/mdfinder/MainWindow.xaml b/mdfinder/MainWindow.xaml index ceeacac..13ec573 100644 --- a/mdfinder/MainWindow.xaml +++ b/mdfinder/MainWindow.xaml @@ -3,10 +3,11 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:gu="https://github.com/JohanLarsson/Gu.Wpf.Media" xmlns:mdfinder="clr-namespace:mdfinder" xmlns:loc="clr-namespace:mdfinder.Localization" mc:Ignorable="d" - Title="{x:Static loc:Localization.Title}" Height="450" Width="800"> + Title="{x:Static loc:Localization.Title}" Height="520.293" Width="814.505"> @@ -33,7 +34,7 @@ - + @@ -62,7 +63,7 @@ - + @@ -85,80 +86,168 @@ - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +