From d758e42afbac9792a946dc417d1ba6adee81e198 Mon Sep 17 00:00:00 2001 From: Admin Date: Sat, 5 Dec 2020 17:00:08 -0600 Subject: [PATCH] Added a function to allow a snapshot object to handle dealing with the diff on its own. --- .vs/DataOrganizer/v16/.suo | Bin 145920 -> 145920 bytes DataOrganizer/FileViewer.cs | 32 +++++++---------------------- DataOrganizer/Snapshot.cs | 39 ++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/.vs/DataOrganizer/v16/.suo b/.vs/DataOrganizer/v16/.suo index c7570bdfef3e97373dc1ac17c74c1e65be237a98..0880bae859efc0e38d0c90983b61ad47c7bc9e6c 100644 GIT binary patch delta 445 zcmZqp!qM=BV}gMu0}Kc-Fz_-kFfcJNF#P-f|365Wk%56hf`NfSl7WFiYqBD%_{M@i zjI0Jpj-pYU3z>d1vj!Z<{~x)zkgZ*Xaq{M$TEa3sr!4*A>TfHQap!A0P3Ccz*lgf_ zf}3&D=AS{rPFN(TUf9AlS%85-n1O+TjbS>YFJssA3qg#=(;K20_fJ3R#du`9*AGS) zCWOp(Uw_6!%#1FR7y8Ig*AHe?VbXGjv!_oFW^`6x3vxRcD;_w_z`(GYfq}tgE2E2* zft7((wXv&_p`)?6vF@TCw(X2jjMB`4OTmgkgwlZr3=9l{({||WV#KbaPz@O1>xxTE9yMs0tGW}*|b@*)29K5-ZtzCt2%I2S1!ZJz=+tjriOZ8+g*lIid+c@*7>ULWm z4;yW#Ql^|uwuxbrvbxu4<&DGw5M5<^ywq(o`zy)E2R1Q-~E85kJY81_y#jAh(6 zz0I5P$aF?u#;)n-f*6e%w}M1Fr&mNV>TYNBW$a~Sgs9u@{hP6uMXev?129%Tu#$m+ zL5YEZ!DTC>it*i0Dmro ABLDyZ diff --git a/DataOrganizer/FileViewer.cs b/DataOrganizer/FileViewer.cs index cc0591a..5639f24 100644 --- a/DataOrganizer/FileViewer.cs +++ b/DataOrganizer/FileViewer.cs @@ -164,37 +164,19 @@ namespace DataOrganizer var folderGroup = GetActiveFolderGroup(); var files = new List(); var rootFolder = new DirectoryInfo(folderGroup.Path); - var pendingChanges = 0; foreach (var dir in rootFolder.EnumerateDirectories()) files.AddRange(ScanDirectory(dir)); var snapShot = new Snapshot(files, folderGroup); + ActiveSnapshotForPrimaryTree.MergeSnapshot(snapShot); var newFiles = snapShot.Files.Values.Except(ActiveSnapshotForPrimaryTree.Files.Values); var existingFiles = ActiveSnapshotForPrimaryTree.Files.Values.Except(snapShot.Files.Values); - var deletedFiles = new List(); - var modifiedFiles = new List(); var newFilesCount = 0; var modifiedFilesCount = 0; var deletedFilesCount = 0; - foreach(var existingFile in existingFiles) - { - if (!snapShot.Files.ContainsKey(existingFile.FullPath)) - { - existingFile.Status = FileSnapshot.FileStatus.PendingDelete; - deletedFiles.Add(existingFile); - pendingChanges++; - } - else if (existingFile.ModifiedDate != snapShot.Files[existingFile.FullPath].ModifiedDate) - { - existingFile.ModifiedDate = snapShot.Files[existingFile.FullPath].ModifiedDate; - modifiedFiles.Add(snapShot.Files[existingFile.FullPath]); - pendingChanges++; - } - } - foreach(var f in newFiles) { var newNode = new TreeNode(f.Name) { Name = f.FullPath, BackColor = Color.LightBlue, ToolTipText = "New File Found!" }; @@ -224,17 +206,17 @@ namespace DataOrganizer } } - foreach(var f in deletedFiles) + foreach(var f in ActiveSnapshotForPrimaryTree.Files.Where(x => x.Value.Status == FileSnapshot.FileStatus.PendingDelete)) { - PrimaryTreeNodes[f.FullPath].BackColor = Color.Red; - PrimaryTreeNodes[f.FullPath].ToolTipText = "This file has been deleted."; + PrimaryTreeNodes[f.Key].BackColor = Color.Red; + PrimaryTreeNodes[f.Key].ToolTipText = "This file has been deleted."; deletedFilesCount++; } - foreach(var f in modifiedFiles) + foreach(var f in ActiveSnapshotForPrimaryTree.Files.Where(x => x.Value.Status == FileSnapshot.FileStatus.PendingUpdate)) { - PrimaryTreeNodes[f.FullPath].BackColor = Color.DarkBlue; - PrimaryTreeNodes[f.FullPath].ToolTipText = "This file has been modified."; + PrimaryTreeNodes[f.Key].BackColor = Color.DarkBlue; + PrimaryTreeNodes[f.Key].ToolTipText = "This file has been modified."; modifiedFilesCount++; } diff --git a/DataOrganizer/Snapshot.cs b/DataOrganizer/Snapshot.cs index f1699b3..0d501ae 100644 --- a/DataOrganizer/Snapshot.cs +++ b/DataOrganizer/Snapshot.cs @@ -168,6 +168,44 @@ namespace DataOrganizer public void MergeSnapshot(Snapshot snapshot) { //TODO: build this out + var newFiles = Files.Values.Except(snapshot.Files.Values); + var newFolders = Directories.Values.Except(snapshot.Directories.Values); + var newOrgFolders = OrganizationFolders.Values.Except(snapshot.OrganizationFolders.Values); + var existingFiles = Files.Values.Except(snapshot.Files.Values); + + foreach (var existingFile in existingFiles) + { + if (!snapshot.Files.ContainsKey(existingFile.FullPath)) + { + existingFile.Status = FileSnapshot.FileStatus.PendingDelete; + //deletedFiles.Add(existingFile); + //pendingChanges++; + } + else if (existingFile.ModifiedDate != snapshot.Files[existingFile.FullPath].ModifiedDate) + { + existingFile.ModifiedDate = snapshot.Files[existingFile.FullPath].ModifiedDate; + //modifiedFiles.Add(snapShot.Files[existingFile.FullPath]); + //pendingChanges++; + } + } + + foreach(var newFile in newFiles) + { + if(!Files.ContainsKey(newFile.FullPath)) Files.Add(newFile.FullPath, newFile); + Folder folder = newFile.ParentFolder; + + while(folder != null) + { + if (!Directories.ContainsKey(folder.FullPath)) + { + Directories.Add(folder.FullPath, folder); + } + + if (folder.Parent == null && !OrganizationFolders.ContainsKey(folder.FullPath)) OrganizationFolders.Add(folder.FullPath, folder.Files.Values.ToList()); + + folder = folder.Parent; + } + } } public struct Duplicate @@ -344,6 +382,7 @@ namespace DataOrganizer PendingInsert, PendingUpdate, PendingDelete, + Deleted, None } }