diff --git a/.vs/DataOrganizer/v16/.suo b/.vs/DataOrganizer/v16/.suo index 8747cd4..2709873 100644 Binary files a/.vs/DataOrganizer/v16/.suo and b/.vs/DataOrganizer/v16/.suo differ diff --git a/DataOrganizer/FileManager.Designer.cs b/DataOrganizer/FileManager.Designer.cs index 639b5e7..8def445 100644 --- a/DataOrganizer/FileManager.Designer.cs +++ b/DataOrganizer/FileManager.Designer.cs @@ -53,6 +53,10 @@ this.SelectedFolderViewGroupTreeView = new System.Windows.Forms.TreeView(); this.ComparisionFolderViewGroupBox = new System.Windows.Forms.GroupBox(); 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.MainMenuStrip.SuspendLayout(); this.DiffResultsGroupBox.SuspendLayout(); @@ -61,6 +65,7 @@ this.statusStrip1.SuspendLayout(); this.SelectedGroupFolderViewGroupBox.SuspendLayout(); this.ComparisionFolderViewGroupBox.SuspendLayout(); + this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // MainLayoutPanel @@ -78,6 +83,7 @@ this.MainLayoutPanel.Controls.Add(this.statusStrip1, 0, 4); this.MainLayoutPanel.Controls.Add(this.SelectedGroupFolderViewGroupBox, 2, 2); 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.Location = new System.Drawing.Point(0, 0); this.MainLayoutPanel.Name = "MainLayoutPanel"; @@ -326,6 +332,46 @@ this.ComparisionFolderViewTreeView.Size = new System.Drawing.Size(420, 326); 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 // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); @@ -346,6 +392,8 @@ this.statusStrip1.PerformLayout(); this.SelectedGroupFolderViewGroupBox.ResumeLayout(false); this.ComparisionFolderViewGroupBox.ResumeLayout(false); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); this.ResumeLayout(false); } @@ -377,5 +425,9 @@ private System.Windows.Forms.TreeView SelectedFolderViewGroupTreeView; private System.Windows.Forms.GroupBox ComparisionFolderViewGroupBox; 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; } } \ No newline at end of file diff --git a/DataOrganizer/FileManager.cs b/DataOrganizer/FileManager.cs index 89e1d76..ef014e1 100644 --- a/DataOrganizer/FileManager.cs +++ b/DataOrganizer/FileManager.cs @@ -77,17 +77,47 @@ namespace DataOrganizer var db = new DB(); var p = GetProfileToCompare(); var f = GetFolderGroupToCompare(); + var renames = new List(); ComparisionSnapshot = new Snapshot(db.GetFilesForProfileByFolderGroup(p.Id, f.Id), f); var diff = ActiveSnapshot.Diff(ComparisionSnapshot); - foreach(var file in diff.NewFiles) - AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingInsert); + //foreach (var folder in ActiveSnapshot.Directories.Values) + //{ + // if (ComparisionSnapshot.Directories.ContainsKey(folder.FullPath)) + // { + // renames.AddRange(ActiveSnapshot.FindFileRenames(folder, ComparisionSnapshot.Directories[folder.FullPath])); + // } + //} - foreach (var file in diff.ModifiedFiles) - AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingUpdate); + //foreach (var rename in renames) + //{ + // DiffViewTreeView.Nodes.Add($"From: {rename.From.Name}"); + // DiffViewTreeView.Nodes.Add($"To: {rename.To.Name}"); + //} + var dupCount = 0; - foreach (var file in diff.DeletedFiles) - AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingDelete); + foreach(var folder in ActiveSnapshot.TopLevelFolders.Keys) + { + 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) @@ -324,5 +354,21 @@ namespace DataOrganizer StatusLabel.Text = message; 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 + + } } } diff --git a/DataOrganizer/FileManager.resx b/DataOrganizer/FileManager.resx index 57b87f9..0e5bf2c 100644 --- a/DataOrganizer/FileManager.resx +++ b/DataOrganizer/FileManager.resx @@ -123,10 +123,4 @@ 205, 17 - - 17, 17 - - - 205, 17 - \ No newline at end of file diff --git a/DataOrganizer/Snapshot.cs b/DataOrganizer/Snapshot.cs index e009b0a..c3d2ae9 100644 --- a/DataOrganizer/Snapshot.cs +++ b/DataOrganizer/Snapshot.cs @@ -272,9 +272,41 @@ namespace DataOrganizer return renames; } + public List FindDuplicates(Folder topLevelFolder) + { + var duplicates = new Dictionary(); + 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() }); + + 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() }); + + 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 DB.DBFileSnapshot File; + public FileSnapshot File; public List Duplicates; } }