Rayburn Davis
2014-09-15 fb4519e5c864e7c153b6bafcf79275ed36a9bda3
....@@ -12,6 +12,7 @@
1212 using System.Threading;
1313 using System.Net.Sockets;
1414 using System.Threading.Tasks;
15
+using DupliDelete.Duplicate_Search_Engine;
1516
1617 namespace DupliDelete
1718 {
....@@ -25,7 +26,7 @@
2526 public double FileChecksumProgress;
2627 public ObjectInfo FileChecksumObject;
2728
28
- public string[] Folders;
29
+ public Folder[] Folders;
2930 public List<string> FileTypeInclusions = new List<string>();
3031 public List<string> ExcludedFolders = new List<string>();
3132 public List<string> ExcludedFiletypes = new List<string>();
....@@ -112,9 +113,83 @@
112113 [DllImport("Kernel32.dll")]
113114 static extern bool GetFileInformationByHandle(IntPtr hFile, out BY_HANDLE_FILE_INFORMATION by1);
114115
115
- public DuplicateFinder(string[] folders)
116
+ public class DuplicateSorter : System.Collections.IComparer
116117 {
117
- Folders = (string[]) folders.Clone();
118
+ DuplicateFinder Finder { get; set; }
119
+
120
+ public DuplicateSorter(DuplicateFinder finder)
121
+ {
122
+ Finder = finder;
123
+ }
124
+
125
+ public int Compare(object x, object y)
126
+ {
127
+ if (Finder.ScanMode == Mode.CompareByActualData)
128
+ {
129
+ string sizeStringX = ((DuplicateGroup)x).GroupName.Substring(0, ((DuplicateGroup)x).GroupName.IndexOf(" "));
130
+ string sizeStringY = ((DuplicateGroup)y).GroupName.Substring(0, ((DuplicateGroup)y).GroupName.IndexOf(" "));
131
+ string metricX = ((DuplicateGroup)x).GroupName.Substring(((DuplicateGroup)x).GroupName.IndexOf(" ") + 1);
132
+ string metricY = ((DuplicateGroup)y).GroupName.Substring(((DuplicateGroup)y).GroupName.IndexOf(" ") + 1);
133
+ double sizeX = Convert.ToDouble(sizeStringX);
134
+ double sizeY = Convert.ToDouble(sizeStringY);
135
+
136
+ if (metricX == "bytes")
137
+ sizeX = shortSizeToLongSize(sizeX, 1);
138
+ if (metricX == "KB")
139
+ sizeX = shortSizeToLongSize(sizeX, 2);
140
+ if (metricX == "MB")
141
+ sizeX = shortSizeToLongSize(sizeX, 3);
142
+ if (metricX == "GB")
143
+ sizeX = shortSizeToLongSize(sizeX, 4);
144
+ if (metricX == "TB")
145
+ sizeX = shortSizeToLongSize(sizeX, 5);
146
+
147
+ if (metricY == "bytes")
148
+ sizeY = shortSizeToLongSize(sizeY, 1);
149
+ if (metricY == "KB")
150
+ sizeY = shortSizeToLongSize(sizeY, 2);
151
+ if (metricY == "MB")
152
+ sizeY = shortSizeToLongSize(sizeY, 3);
153
+ if (metricY == "GB")
154
+ sizeX = shortSizeToLongSize(sizeY, 4);
155
+ if (metricY == "TB")
156
+ sizeY = shortSizeToLongSize(sizeY, 5);
157
+
158
+ if (sizeX < sizeY)
159
+ {
160
+ return -1;
161
+ }
162
+ else if (sizeX == sizeY)
163
+ return 0;
164
+ else
165
+ return 1;
166
+ }
167
+ else
168
+ {
169
+ return 0;
170
+ }
171
+ }
172
+
173
+ public long shortSizeToLongSize(double input, int metric)
174
+ {
175
+ if (metric == 1)
176
+ return (long)input;
177
+ if (metric == 2)
178
+ return (long)input * 1024;
179
+ if (metric == 3)
180
+ return (long)input * 1024 * 1024;
181
+ if (metric == 4)
182
+ return (long)input * 1024 * 1024 * 1024;
183
+ if (metric == 5)
184
+ return (long)input * 1024 * 1024 * 1024 * 1024;
185
+
186
+ return -1;
187
+ }
188
+ }
189
+
190
+ public DuplicateFinder(Folder[] folders)
191
+ {
192
+ Folders = (Folder[]) folders.Clone();
118193
119194 sha_handle = SHA1.Create();
120195 }
....@@ -624,16 +699,16 @@
624699
625700
626701 // Folders to scan
627
- List<string> scanFolders = new List<string>();
702
+ List<Folder> scanFolders = new List<Folder>();
628703 scanFolders.AddRange(Folders);
629704
630705 // Master file list that stores all files and folders that are in the folders that the user selected
631706 DirectoryList masterFolderTable = new DirectoryList();
632707
633708 // Crawl the folders that the user added to the list; add them to the master file table
634
- foreach (string folder in scanFolders)
709
+ foreach (Folder folder in scanFolders)
635710 {
636
- masterFolderTable.Add(new ObjectInfo(folder, 0, ObjectInfo.FileType.Folder));
711
+ masterFolderTable.Add(new ObjectInfo(folder.ClientPath, 0, ObjectInfo.FileType.Folder));
637712 }
638713
639714 foreach (string folder in ExcludedFolders)
....@@ -687,7 +762,7 @@
687762 {
688763 for (j = 0; j < scanFolders.Count; j++)
689764 {
690
- if (scanFolders[j].ToLower().IndexOf(objectInfo.Path.ToLower()) == 0 && scanFolders[j].ToLower() != objectInfo.Path.ToLower())
765
+ if (scanFolders[j].ClientPath.ToLower().IndexOf(objectInfo.Path.ToLower()) == 0 && scanFolders[j].ClientPath.ToLower() != objectInfo.Path.ToLower())
691766 addFolder = false;
692767 }
693768 }
....@@ -1063,6 +1138,8 @@
10631138 }
10641139 }
10651140 }
1141
+
1142
+ GlobalBuffers.Duplicates.Sort(new DuplicateSorter(this));
10661143
10671144
10681145 endTime = DateTime.Now;