First attempt at finding duplicate files. For now, and possible ever, this process will be a 'best effort' approach, so there will be false positives but this will most likely remain the case for the life of this program.
This commit is contained in:
Binary file not shown.
Generated
+52
@@ -53,6 +53,10 @@
|
|||||||
this.SelectedFolderViewGroupTreeView = new System.Windows.Forms.TreeView();
|
this.SelectedFolderViewGroupTreeView = new System.Windows.Forms.TreeView();
|
||||||
this.ComparisionFolderViewGroupBox = new System.Windows.Forms.GroupBox();
|
this.ComparisionFolderViewGroupBox = new System.Windows.Forms.GroupBox();
|
||||||
this.ComparisionFolderViewTreeView = new System.Windows.Forms.TreeView();
|
this.ComparisionFolderViewTreeView = new System.Windows.Forms.TreeView();
|
||||||
|
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||||
|
this.textBox1 = new System.Windows.Forms.TextBox();
|
||||||
|
this.button1 = new System.Windows.Forms.Button();
|
||||||
|
this.button2 = new System.Windows.Forms.Button();
|
||||||
this.MainLayoutPanel.SuspendLayout();
|
this.MainLayoutPanel.SuspendLayout();
|
||||||
this.MainMenuStrip.SuspendLayout();
|
this.MainMenuStrip.SuspendLayout();
|
||||||
this.DiffResultsGroupBox.SuspendLayout();
|
this.DiffResultsGroupBox.SuspendLayout();
|
||||||
@@ -61,6 +65,7 @@
|
|||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
this.SelectedGroupFolderViewGroupBox.SuspendLayout();
|
this.SelectedGroupFolderViewGroupBox.SuspendLayout();
|
||||||
this.ComparisionFolderViewGroupBox.SuspendLayout();
|
this.ComparisionFolderViewGroupBox.SuspendLayout();
|
||||||
|
this.groupBox1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// MainLayoutPanel
|
// MainLayoutPanel
|
||||||
@@ -78,6 +83,7 @@
|
|||||||
this.MainLayoutPanel.Controls.Add(this.statusStrip1, 0, 4);
|
this.MainLayoutPanel.Controls.Add(this.statusStrip1, 0, 4);
|
||||||
this.MainLayoutPanel.Controls.Add(this.SelectedGroupFolderViewGroupBox, 2, 2);
|
this.MainLayoutPanel.Controls.Add(this.SelectedGroupFolderViewGroupBox, 2, 2);
|
||||||
this.MainLayoutPanel.Controls.Add(this.ComparisionFolderViewGroupBox, 2, 3);
|
this.MainLayoutPanel.Controls.Add(this.ComparisionFolderViewGroupBox, 2, 3);
|
||||||
|
this.MainLayoutPanel.Controls.Add(this.groupBox1, 2, 1);
|
||||||
this.MainLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.MainLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.MainLayoutPanel.Location = new System.Drawing.Point(0, 0);
|
this.MainLayoutPanel.Location = new System.Drawing.Point(0, 0);
|
||||||
this.MainLayoutPanel.Name = "MainLayoutPanel";
|
this.MainLayoutPanel.Name = "MainLayoutPanel";
|
||||||
@@ -326,6 +332,46 @@
|
|||||||
this.ComparisionFolderViewTreeView.Size = new System.Drawing.Size(420, 326);
|
this.ComparisionFolderViewTreeView.Size = new System.Drawing.Size(420, 326);
|
||||||
this.ComparisionFolderViewTreeView.TabIndex = 0;
|
this.ComparisionFolderViewTreeView.TabIndex = 0;
|
||||||
//
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
this.groupBox1.Controls.Add(this.button2);
|
||||||
|
this.groupBox1.Controls.Add(this.button1);
|
||||||
|
this.groupBox1.Controls.Add(this.textBox1);
|
||||||
|
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.groupBox1.Location = new System.Drawing.Point(877, 43);
|
||||||
|
this.groupBox1.Name = "groupBox1";
|
||||||
|
this.groupBox1.Size = new System.Drawing.Size(426, 172);
|
||||||
|
this.groupBox1.TabIndex = 12;
|
||||||
|
this.groupBox1.TabStop = false;
|
||||||
|
this.groupBox1.Text = "groupBox1";
|
||||||
|
//
|
||||||
|
// textBox1
|
||||||
|
//
|
||||||
|
this.textBox1.Location = new System.Drawing.Point(29, 34);
|
||||||
|
this.textBox1.Name = "textBox1";
|
||||||
|
this.textBox1.Size = new System.Drawing.Size(239, 26);
|
||||||
|
this.textBox1.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// button1
|
||||||
|
//
|
||||||
|
this.button1.Location = new System.Drawing.Point(296, 38);
|
||||||
|
this.button1.Name = "button1";
|
||||||
|
this.button1.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.button1.TabIndex = 1;
|
||||||
|
this.button1.Text = "button1";
|
||||||
|
this.button1.UseVisualStyleBackColor = true;
|
||||||
|
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||||
|
//
|
||||||
|
// button2
|
||||||
|
//
|
||||||
|
this.button2.Location = new System.Drawing.Point(16, 120);
|
||||||
|
this.button2.Name = "button2";
|
||||||
|
this.button2.Size = new System.Drawing.Size(112, 46);
|
||||||
|
this.button2.TabIndex = 2;
|
||||||
|
this.button2.Text = "button2";
|
||||||
|
this.button2.UseVisualStyleBackColor = true;
|
||||||
|
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||||
|
//
|
||||||
// FileManager
|
// FileManager
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
|
||||||
@@ -346,6 +392,8 @@
|
|||||||
this.statusStrip1.PerformLayout();
|
this.statusStrip1.PerformLayout();
|
||||||
this.SelectedGroupFolderViewGroupBox.ResumeLayout(false);
|
this.SelectedGroupFolderViewGroupBox.ResumeLayout(false);
|
||||||
this.ComparisionFolderViewGroupBox.ResumeLayout(false);
|
this.ComparisionFolderViewGroupBox.ResumeLayout(false);
|
||||||
|
this.groupBox1.ResumeLayout(false);
|
||||||
|
this.groupBox1.PerformLayout();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -377,5 +425,9 @@
|
|||||||
private System.Windows.Forms.TreeView SelectedFolderViewGroupTreeView;
|
private System.Windows.Forms.TreeView SelectedFolderViewGroupTreeView;
|
||||||
private System.Windows.Forms.GroupBox ComparisionFolderViewGroupBox;
|
private System.Windows.Forms.GroupBox ComparisionFolderViewGroupBox;
|
||||||
private System.Windows.Forms.TreeView ComparisionFolderViewTreeView;
|
private System.Windows.Forms.TreeView ComparisionFolderViewTreeView;
|
||||||
|
private System.Windows.Forms.GroupBox groupBox1;
|
||||||
|
private System.Windows.Forms.Button button1;
|
||||||
|
private System.Windows.Forms.TextBox textBox1;
|
||||||
|
private System.Windows.Forms.Button button2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,17 +77,47 @@ namespace DataOrganizer
|
|||||||
var db = new DB();
|
var db = new DB();
|
||||||
var p = GetProfileToCompare();
|
var p = GetProfileToCompare();
|
||||||
var f = GetFolderGroupToCompare();
|
var f = GetFolderGroupToCompare();
|
||||||
|
var renames = new List<SnapshotComparsion.RenamedFile>();
|
||||||
ComparisionSnapshot = new Snapshot(db.GetFilesForProfileByFolderGroup(p.Id, f.Id), f);
|
ComparisionSnapshot = new Snapshot(db.GetFilesForProfileByFolderGroup(p.Id, f.Id), f);
|
||||||
var diff = ActiveSnapshot.Diff(ComparisionSnapshot);
|
var diff = ActiveSnapshot.Diff(ComparisionSnapshot);
|
||||||
|
|
||||||
foreach(var file in diff.NewFiles)
|
//foreach (var folder in ActiveSnapshot.Directories.Values)
|
||||||
AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingInsert);
|
//{
|
||||||
|
// if (ComparisionSnapshot.Directories.ContainsKey(folder.FullPath))
|
||||||
|
// {
|
||||||
|
// renames.AddRange(ActiveSnapshot.FindFileRenames(folder, ComparisionSnapshot.Directories[folder.FullPath]));
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
foreach (var file in diff.ModifiedFiles)
|
//foreach (var rename in renames)
|
||||||
AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingUpdate);
|
//{
|
||||||
|
// DiffViewTreeView.Nodes.Add($"From: {rename.From.Name}");
|
||||||
|
// DiffViewTreeView.Nodes.Add($"To: {rename.To.Name}");
|
||||||
|
//}
|
||||||
|
var dupCount = 0;
|
||||||
|
|
||||||
foreach (var file in diff.DeletedFiles)
|
foreach(var folder in ActiveSnapshot.TopLevelFolders.Keys)
|
||||||
AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingDelete);
|
{
|
||||||
|
foreach(var dup in ActiveSnapshot.FindDuplicates(ActiveSnapshot.Directories[folder]))
|
||||||
|
{
|
||||||
|
var node = new TreeNode($"{dup.File.Name} ({dup.Duplicates.Count})") { ToolTipText = dup.File.FullPath };
|
||||||
|
foreach(var d in dup.Duplicates)
|
||||||
|
{
|
||||||
|
node.Nodes.Add(new TreeNode(d.Name) { ToolTipText = d.FullPath });
|
||||||
|
dupCount++;
|
||||||
|
}
|
||||||
|
DiffViewTreeView.Nodes.Add(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UpdateStatusLabel($"Found {dupCount} duplicate files.");
|
||||||
|
//foreach(var file in diff.NewFiles)
|
||||||
|
// AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingInsert);
|
||||||
|
|
||||||
|
//foreach (var file in diff.ModifiedFiles)
|
||||||
|
// AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingUpdate);
|
||||||
|
|
||||||
|
//foreach (var file in diff.DeletedFiles)
|
||||||
|
// AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddFileSnapshotToDiffView(FileSnapshot file, DB.FolderGroup folderGroup, FileSnapshot.FileStatus fileStatus = FileSnapshot.FileStatus.None)
|
private void AddFileSnapshotToDiffView(FileSnapshot file, DB.FolderGroup folderGroup, FileSnapshot.FileStatus fileStatus = FileSnapshot.FileStatus.None)
|
||||||
@@ -324,5 +354,21 @@ namespace DataOrganizer
|
|||||||
StatusLabel.Text = message;
|
StatusLabel.Text = message;
|
||||||
statusStrip1.Refresh();
|
statusStrip1.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void button1_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var form = new FolderBrowserDialog();
|
||||||
|
|
||||||
|
if(form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
textBox1.Text = form.SelectedPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void button2_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
//Compare
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,10 +123,4 @@
|
|||||||
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>205, 17</value>
|
<value>205, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="MainMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
|
||||||
<value>17, 17</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
|
||||||
<value>205, 17</value>
|
|
||||||
</metadata>
|
|
||||||
</root>
|
</root>
|
||||||
@@ -272,9 +272,41 @@ namespace DataOrganizer
|
|||||||
return renames;
|
return renames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Duplicate> FindDuplicates(Folder topLevelFolder)
|
||||||
|
{
|
||||||
|
var duplicates = new Dictionary<string, Duplicate>();
|
||||||
|
var files = topLevelFolder.GetAllFiles();
|
||||||
|
var fileCount = 0;
|
||||||
|
|
||||||
|
fileCount = files.Count;
|
||||||
|
|
||||||
|
for(var i = 0; i < fileCount; i++)
|
||||||
|
{
|
||||||
|
var file = files[i];
|
||||||
|
|
||||||
|
//if (!duplicates.ContainsKey(file.FullPath)) duplicates.Add(file.FullPath, new Duplicate() { File = file, Duplicates = new List<FileSnapshot>() });
|
||||||
|
|
||||||
|
var dups = files.Where(x => x.Size == file.Size && x.FileId != file.FileId).ToList();
|
||||||
|
var dupCount = dups.Count;
|
||||||
|
|
||||||
|
if(dupCount > 0)
|
||||||
|
if (!duplicates.ContainsKey(file.FullPath)) duplicates.Add(file.FullPath, new Duplicate() { File = file, Duplicates = new List<FileSnapshot>() });
|
||||||
|
|
||||||
|
for (var j = 0; j < dupCount; j++)
|
||||||
|
{
|
||||||
|
var dup = dups[j];
|
||||||
|
files.Remove(dup);
|
||||||
|
duplicates[file.FullPath].Duplicates.Add(dup);
|
||||||
|
fileCount--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return duplicates.Values.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
public struct Duplicate
|
public struct Duplicate
|
||||||
{
|
{
|
||||||
public DB.DBFileSnapshot File;
|
public FileSnapshot File;
|
||||||
public List<FileSnapshot> Duplicates;
|
public List<FileSnapshot> Duplicates;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user