diff --git a/EasyLib/Files/TransferManager.cs b/EasyLib/Files/TransferManager.cs index bb1425f..ea6eab4 100644 --- a/EasyLib/Files/TransferManager.cs +++ b/EasyLib/Files/TransferManager.cs @@ -81,8 +81,9 @@ public void ComputeDifference(List> folders) InstructionsFolder = new BackupFolder(folders[1][0]); if (folders[2].Count != 0) { - InstructionsFolder.SubFolders.Add(new BackupFolder(folders[3][0])); + InstructionsFolder.SubFolders.Add(new BackupFolder(folders[1][0])); _compareBackupPath(InstructionsFolder.SubFolders[0], folders[0]); + folders[0].RemoveAt(folders[0].Count - 1); } else { @@ -90,6 +91,39 @@ public void ComputeDifference(List> folders) } } + static void CopyDirectory(string sourceDir, string destinationDir, bool recursive) + { + // Get information about the source directory + var dir = new DirectoryInfo(sourceDir); + + // Check if the source directory exists + if (!dir.Exists) + throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}"); + + // Cache directories before we start copying + DirectoryInfo[] dirs = dir.GetDirectories(); + + // Create the destination directory + Directory.CreateDirectory(destinationDir); + + // Get the files in the source directory and copy to the destination directory + foreach (FileInfo file in dir.GetFiles()) + { + string targetFilePath = Path.Combine(destinationDir, file.Name); + file.CopyTo(targetFilePath); + } + + // If recursive and copying subdirectories, recursively call this method + if (recursive) + { + foreach (DirectoryInfo subDir in dirs) + { + string newDestinationDir = Path.Combine(destinationDir, subDir.Name); + CopyDirectory(subDir.FullName, newDestinationDir, true); + } + } + } + /// /// Compare the source with the existing backup folders if there is any /// The result is stored in the InstructionsFolder property diff --git a/EasyLib/Job/BackupFolderStrategy/DifferentialBackupFolderStrategy.cs b/EasyLib/Job/BackupFolderStrategy/DifferentialBackupFolderStrategy.cs index 91fc06f..dbc7c0e 100644 --- a/EasyLib/Job/BackupFolderStrategy/DifferentialBackupFolderStrategy.cs +++ b/EasyLib/Job/BackupFolderStrategy/DifferentialBackupFolderStrategy.cs @@ -16,13 +16,14 @@ public List> SelectFolders(List> folders, string lastF 1 => [ folders[0], - [finalDestinationPath + Path.DirectorySeparatorChar + Path.GetDirectoryName(finalDestinationPath)], [] + [finalDestinationPath + Path.DirectorySeparatorChar + Path.GetDirectoryName(finalDestinationPath)], + [finalDestinationPath] ], _ => [ Directory.GetDirectories(folders[0][folderCount - 1]).Append(folders[0][0]).ToList(), [finalDestinationPath + Path.DirectorySeparatorChar + Path.GetDirectoryName(finalDestinationPath)], - [folders[0][folderCount - 2]] + [folders[0][folderCount - 2] + Path.DirectorySeparatorChar] ] }; }