Added code to find any files that have been moved, basic but for the time being it seems to work well enough.
This commit is contained in:
Binary file not shown.
@@ -35,6 +35,7 @@ namespace DataOrganizer
|
|||||||
|
|
||||||
private void DiffViewTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
|
private void DiffViewTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
if (!ActiveSnapshot.TopLevelFolders.ContainsKey(e.Node.Name)) return;
|
if (!ActiveSnapshot.TopLevelFolders.ContainsKey(e.Node.Name)) return;
|
||||||
|
|
||||||
SelectedFolderViewGroupTreeView.Nodes.Clear();
|
SelectedFolderViewGroupTreeView.Nodes.Clear();
|
||||||
@@ -90,22 +91,45 @@ namespace DataOrganizer
|
|||||||
|
|
||||||
if (ComparisionSnapshot.Directories.ContainsKey(w))
|
if (ComparisionSnapshot.Directories.ContainsKey(w))
|
||||||
{
|
{
|
||||||
renames.AddRange(ActiveSnapshot.FindFileRenames(folder, ComparisionSnapshot.Directories[w]));
|
renames.AddRange(Snapshot.FindFileRenames(folder, ComparisionSnapshot.Directories[w]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var compareRoot = ComparisionSnapshot.Directories.Single(x => x.Value.IsRootFolder).Value;
|
var compareRoot = ComparisionSnapshot.Directories.Single(x => x.Value.IsRootFolder).Value;
|
||||||
|
|
||||||
renames.AddRange(ActiveSnapshot.FindFileRenames(folder, compareRoot));
|
renames.AddRange(Snapshot.FindFileRenames(folder, compareRoot));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var renamedNode = new TreeNode("Renamed Files");
|
||||||
|
var movedNode = new TreeNode("Moves");
|
||||||
|
|
||||||
foreach (var rename in renames)
|
foreach (var rename in renames)
|
||||||
{
|
{
|
||||||
DiffViewTreeView.Nodes.Add($"From: {rename.From.Name}");
|
renamedNode.Nodes.Add($"From: {rename.From.Name}");
|
||||||
DiffViewTreeView.Nodes.Add($"To: {rename.To.Name}");
|
renamedNode.Nodes.Add($"To: {rename.To.Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiffViewTreeView.Nodes.Add(renamedNode);
|
||||||
|
|
||||||
|
foreach(var path in ActiveSnapshot.TopLevelFolders.Keys)
|
||||||
|
{
|
||||||
|
if (ComparisionSnapshot.Directories.ContainsKey(path))
|
||||||
|
{
|
||||||
|
var moves = Snapshot.FindFileMoves(ActiveSnapshot.Directories[path], ComparisionSnapshot.Directories[path]);
|
||||||
|
|
||||||
|
foreach(var move in moves)
|
||||||
|
{
|
||||||
|
var one = new TreeNode($"From: {move.From.Name}");
|
||||||
|
one.Nodes.Add($"To: {move.To.Name}");
|
||||||
|
movedNode.Nodes.Add(one);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DiffViewTreeView.Nodes.Add(movedNode);
|
||||||
|
|
||||||
var dupCount = 0;
|
var dupCount = 0;
|
||||||
|
|
||||||
//foreach(var folder in ActiveSnapshot.TopLevelFolders.Keys)
|
//foreach(var folder in ActiveSnapshot.TopLevelFolders.Keys)
|
||||||
@@ -121,15 +145,15 @@ namespace DataOrganizer
|
|||||||
// DiffViewTreeView.Nodes.Add(node);
|
// DiffViewTreeView.Nodes.Add(node);
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
UpdateStatusLabel($"Found {dupCount} duplicate files.");
|
//UpdateStatusLabel($"Found {dupCount} duplicate files.");
|
||||||
//foreach(var file in diff.NewFiles)
|
foreach (var file in diff.NewFiles)
|
||||||
// AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingInsert);
|
AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingInsert);
|
||||||
|
|
||||||
//foreach (var file in diff.ModifiedFiles)
|
foreach (var file in diff.ModifiedFiles)
|
||||||
// AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingUpdate);
|
AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingUpdate);
|
||||||
|
|
||||||
//foreach (var file in diff.DeletedFiles)
|
foreach (var file in diff.DeletedFiles)
|
||||||
// AddFileSnapshotToDiffView(file, GetSelectedFolderGroup(), FileSnapshot.FileStatus.PendingDelete);
|
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)
|
||||||
@@ -154,7 +178,7 @@ namespace DataOrganizer
|
|||||||
}
|
}
|
||||||
|
|
||||||
var node = new TreeNode(file.Name) { Name = file.FullPath };
|
var node = new TreeNode(file.Name) { Name = file.FullPath };
|
||||||
DiffTreeNodes.Add(file.FullPath, node);
|
if(!DiffTreeNodes.ContainsKey(file.FullPath)) DiffTreeNodes.Add(file.FullPath, node);
|
||||||
DiffTreeNodes[file.ParentFolder.FullPath].Nodes.Add(node);
|
DiffTreeNodes[file.ParentFolder.FullPath].Nodes.Add(node);
|
||||||
|
|
||||||
switch (fileStatus)
|
switch (fileStatus)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.IO;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
|
||||||
@@ -256,7 +257,7 @@ namespace DataOrganizer
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SnapshotComparsion.RenamedFile> FindFileRenames(Folder a, Folder b)
|
public static List<SnapshotComparsion.RenamedFile> FindFileRenames(Folder a, Folder b)
|
||||||
{
|
{
|
||||||
var renames = new List<SnapshotComparsion.RenamedFile>();
|
var renames = new List<SnapshotComparsion.RenamedFile>();
|
||||||
|
|
||||||
@@ -275,11 +276,34 @@ namespace DataOrganizer
|
|||||||
return renames;
|
return renames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Duplicate> FindDuplicates(Folder topLevelFolder)
|
public static List<SnapshotComparsion.RenamedFile> FindFileMoves(Folder a, Folder b)
|
||||||
|
{
|
||||||
|
var files = new List<SnapshotComparsion.RenamedFile>();
|
||||||
|
var filesA = a.GetAllFiles();
|
||||||
|
var filesB = b.GetAllFiles();
|
||||||
|
|
||||||
|
foreach(var fileA in filesA)
|
||||||
|
{
|
||||||
|
foreach(var fileB in filesB)
|
||||||
|
{
|
||||||
|
if(fileB.CreatedDate == fileA.CreatedDate && fileA.ModifiedDate == fileB.ModifiedDate && fileA.Size == fileB.Size)
|
||||||
|
{
|
||||||
|
files.Add(new SnapshotComparsion.RenamedFile { From = fileA, To = fileB });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Duplicate> FindDuplicates(Folder topLevelFolder)
|
||||||
{
|
{
|
||||||
var duplicates = new Dictionary<string, Duplicate>();
|
var duplicates = new Dictionary<string, Duplicate>();
|
||||||
var files = topLevelFolder.GetAllFiles();
|
var files = topLevelFolder.GetAllFiles();
|
||||||
var fileCount = 0;
|
var fileCount = 0;
|
||||||
|
var seasonFolderName = new Regex(@"^(?i)season\W+\d+");
|
||||||
|
var extrasFolderName = new Regex(@"^(?i)(?:extras|specials|movies)+$");
|
||||||
|
|
||||||
fileCount = files.Count;
|
fileCount = files.Count;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user