Updated the FileManager to reflect more where I think I want to go when comparing snapshots. Added a first try at detecting file renames in the Snapshot object.
This commit is contained in:
+52
-17
@@ -17,7 +17,7 @@ namespace DataOrganizer
|
||||
//Contains files associated with particular, first level folders.
|
||||
//So if the root folder group is X:\Anime and we have a folder path of x:\Anime\Death Note, then indexing this dictonary
|
||||
//with the text "Death Note" would return all files in that folder.
|
||||
public Dictionary<string, List<FileSnapshot>> OrganizationFolders { get; private set; } = new Dictionary<string, List<FileSnapshot>>();
|
||||
public Dictionary<string, List<FileSnapshot>> TopLevelFolders { get; private set; } = new Dictionary<string, List<FileSnapshot>>();
|
||||
|
||||
public Snapshot(List<DB.DBFileSnapshot> fileRecords, DB.FolderGroup folderGroup)
|
||||
{
|
||||
@@ -53,7 +53,7 @@ namespace DataOrganizer
|
||||
{
|
||||
firstLevelFolder = new Folder(folders[0], Path.Combine(folderGroup.Path, folders[0]), Root);
|
||||
Directories.Add(orgFolder, firstLevelFolder);
|
||||
OrganizationFolders.Add(orgFolder, new List<FileSnapshot>());
|
||||
TopLevelFolders.Add(orgFolder, new List<FileSnapshot>());
|
||||
Root.AddDirectory(firstLevelFolder);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace DataOrganizer
|
||||
//}
|
||||
var snap = new FileSnapshot(file, firstLevelFolder, Directories[currentPath], folderGroup.Path);
|
||||
|
||||
OrganizationFolders[orgFolder].Add(snap);
|
||||
TopLevelFolders[orgFolder].Add(snap);
|
||||
Directories[currentPath].AddFile(snap);
|
||||
Files.Add(Path.Combine(folderGroup.Path, file.PathNoRoot), snap);
|
||||
}
|
||||
@@ -103,7 +103,7 @@ namespace DataOrganizer
|
||||
{
|
||||
firstLevelFolder = new Folder(folders[0], Path.Combine(folderGroup.Path, folders[0]), Root);
|
||||
Directories.Add(orgFolder, firstLevelFolder);
|
||||
OrganizationFolders.Add(orgFolder, new List<FileSnapshot>());
|
||||
TopLevelFolders.Add(orgFolder, new List<FileSnapshot>());
|
||||
Root.AddDirectory(firstLevelFolder);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace DataOrganizer
|
||||
//}
|
||||
var snap = new FileSnapshot(file, firstLevelFolder, Directories[currentPath], folderGroup.Path);
|
||||
|
||||
OrganizationFolders[orgFolder].Add(snap);
|
||||
TopLevelFolders[orgFolder].Add(snap);
|
||||
Directories[currentPath].AddFile(snap);
|
||||
Files.Add(snap.FullPath, snap);
|
||||
}
|
||||
@@ -157,7 +157,7 @@ namespace DataOrganizer
|
||||
private void ClearSubFolders(Folder folder)
|
||||
{
|
||||
if (Directories.ContainsKey(folder.FullPath)) Directories.Remove(folder.FullPath);
|
||||
if (OrganizationFolders.ContainsKey(folder.FullPath)) OrganizationFolders.Remove(folder.FullPath);
|
||||
if (TopLevelFolders.ContainsKey(folder.FullPath)) TopLevelFolders.Remove(folder.FullPath);
|
||||
Root.DeleteFolder(folder);
|
||||
folder.Parent.DeleteFolder(folder);
|
||||
|
||||
@@ -173,12 +173,12 @@ namespace DataOrganizer
|
||||
foreach(var file in snapshot.Files)
|
||||
if (!Files.ContainsKey(file.Key)) newFiles.Add(file.Value);
|
||||
|
||||
foreach (var folder in snapshot.OrganizationFolders)
|
||||
foreach (var folder in snapshot.TopLevelFolders)
|
||||
{
|
||||
if (!OrganizationFolders.ContainsKey(folder.Key) && folder.Key != Root.FullPath)
|
||||
if (!TopLevelFolders.ContainsKey(folder.Key) && folder.Key != Root.FullPath)
|
||||
{
|
||||
Root.AddDirectory(snapshot.Directories[folder.Key]);
|
||||
OrganizationFolders.Add(folder.Key, new List<FileSnapshot>());
|
||||
TopLevelFolders.Add(folder.Key, new List<FileSnapshot>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace DataOrganizer
|
||||
folder = folder.Parent;
|
||||
}
|
||||
|
||||
OrganizationFolders[newFile.OrganizationalFolder.FullPath].Add(newFile);
|
||||
TopLevelFolders[newFile.TopLevelFolder.FullPath].Add(newFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,9 +227,9 @@ namespace DataOrganizer
|
||||
foreach (var file in b.Files)
|
||||
if (!a.Files.ContainsKey(file.Key)) newFiles.Add(file.Value);
|
||||
|
||||
foreach (var folder in b.OrganizationFolders)
|
||||
foreach (var folder in b.TopLevelFolders)
|
||||
{
|
||||
if (!a.OrganizationFolders.ContainsKey(folder.Key) && folder.Key != a.Root.FullPath)
|
||||
if (!a.TopLevelFolders.ContainsKey(folder.Key) && folder.Key != a.Root.FullPath)
|
||||
{
|
||||
newOrgFolders.Add(b.Directories[folder.Key]);
|
||||
}
|
||||
@@ -252,10 +252,26 @@ namespace DataOrganizer
|
||||
NewFiles = newFiles,
|
||||
ModifiedFiles = modifiedFiles,
|
||||
DeletedFiles = deletedFiles,
|
||||
NewOrganizationalFolders = newOrgFolders
|
||||
NewTopLevelFolders = newOrgFolders
|
||||
};
|
||||
}
|
||||
|
||||
public List<SnapshotComparsion.RenamedFile> FindFileRenames(Folder a, Folder b)
|
||||
{
|
||||
var renames = new List<SnapshotComparsion.RenamedFile>();
|
||||
|
||||
foreach(var file in a.Files.Values)
|
||||
{
|
||||
foreach(var f in b.Files.Values)
|
||||
{
|
||||
if (file.Size == f.Size && file.CreatedDate == f.CreatedDate && file.ModifiedDate == f.ModifiedDate)
|
||||
renames.Add(new SnapshotComparsion.RenamedFile() { From = file, To = f });
|
||||
}
|
||||
}
|
||||
|
||||
return renames;
|
||||
}
|
||||
|
||||
public struct Duplicate
|
||||
{
|
||||
public DB.DBFileSnapshot File;
|
||||
@@ -319,11 +335,23 @@ namespace DataOrganizer
|
||||
{
|
||||
if (Folders.ContainsKey(folder.FullPath)) Folders.Remove(folder.FullPath);
|
||||
}
|
||||
|
||||
public List<FileSnapshot> GetAllFiles()
|
||||
{
|
||||
var files = new List<FileSnapshot>();
|
||||
|
||||
files.AddRange(Files.Values);
|
||||
|
||||
foreach (var dir in Folders.Values)
|
||||
files.AddRange(dir.GetAllFiles());
|
||||
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
||||
public class FileSnapshot
|
||||
{
|
||||
public Folder OrganizationalFolder { get; }
|
||||
public Folder TopLevelFolder { get; }
|
||||
public Folder ParentFolder { get; }
|
||||
public string PathNoRoot { get; }
|
||||
private string Root { get; }
|
||||
@@ -373,7 +401,7 @@ namespace DataOrganizer
|
||||
|
||||
public FileSnapshot(DB.DBFileSnapshot file, Folder organizationalFolder, Folder parentFolder, string rootPath)
|
||||
{
|
||||
OrganizationalFolder = organizationalFolder;
|
||||
TopLevelFolder = organizationalFolder;
|
||||
ParentFolder = parentFolder;
|
||||
|
||||
var db = new DB();
|
||||
@@ -392,7 +420,7 @@ namespace DataOrganizer
|
||||
|
||||
public FileSnapshot(FileInfo file, Folder organizationalFolder, Folder parentFolder, string rootPath)
|
||||
{
|
||||
OrganizationalFolder = organizationalFolder;
|
||||
TopLevelFolder = organizationalFolder;
|
||||
ParentFolder = parentFolder;
|
||||
|
||||
_Name = file.Name;
|
||||
@@ -442,6 +470,13 @@ namespace DataOrganizer
|
||||
public List<FileSnapshot> NewFiles { get; set; }
|
||||
public List<FileSnapshot> ModifiedFiles { get; set; }
|
||||
public List<FileSnapshot> DeletedFiles { get; set; }
|
||||
public List<Folder> NewOrganizationalFolders { get; set; }
|
||||
public List<Folder> NewTopLevelFolders { get; set; }
|
||||
public List<RenamedFile> RenamedFiles { get; set; }
|
||||
|
||||
public struct RenamedFile
|
||||
{
|
||||
public FileSnapshot From;
|
||||
public FileSnapshot To;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user