using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DataOrganizer { class Snapshot { public Folder Root { get; private set; } public Dictionary Files { get; private set; } = new Dictionary(); public Dictionary Directories { get; private set; } = new Dictionary(); public Snapshot(List fileRecords, DB.Profile profile, DB.FolderGroup folderGroup) { Root = new Folder(folderGroup.Name, folderGroup.Path); Directories.Add(Root.FullPath, Root); var rootDepth = folderGroup.Path.Split(new char[] { Path.DirectorySeparatorChar }).Length; foreach (var file in fileRecords) { var folders = file.FullPath.Split(new char[] { Path.DirectorySeparatorChar }); var currentPath = folderGroup.Path; if (folders.Length == rootDepth + 1) { Root.AddFile(file); Files.Add(file.FullPath, file); continue; } for (var i = rootDepth; i < folders.Length - 1; i++) { string previousPath = currentPath; currentPath = Path.Combine(currentPath, folders[i]); if (!Directories.ContainsKey(currentPath)) { var newFolder = new Folder(folders[i], currentPath); Directories[previousPath].AddDirectory(newFolder); Directories.Add(currentPath, newFolder); } } Directories[currentPath].AddFile(file); } } } public class Folder { public string Name { get; private set; } public string FullPath { get; private set; } public Dictionary Files { get; private set; } = new Dictionary(); public Dictionary Folders { get; private set; } = new Dictionary(); public List Duplicates { get; private set; } public Folder(string name, string fullPath) { Name = name; FullPath = fullPath; } public void AddFile(DB.FileSnapshot file) { Files.Add(file.FullPath, file); } public void AddDirectory(Folder folder) { Folders.Add(folder.FullPath, folder); } public struct Duplicate { DB.FileSnapshot FileA; DB.FileSnapshot FileB; } } }