/// <summary> /// Actually copy a tree; to be called by derived class /// </summary> protected void DoCopyTree(SyncDirectoryInfo from, SyncFileDirName toFullPath) { Actioner.CreateDirectory(toFullPath.FullName); var toCopy = new Stack <string>(); toCopy.Push(""); while (toCopy.Count() > 0) { string path = toCopy.Pop(); string fromPath = Path.Combine(from.FullName, path); string toPath = Path.Combine(toFullPath.FullName, path); foreach (var fileName in Directory.EnumerateFiles(fromPath)) { // fileName contains full path, so need to extract filename! string name = Path.GetFileName(fileName); Actioner.Copy(Path.Combine(fromPath, name), Path.Combine(toPath, name)); } foreach (var dirName in Directory.EnumerateDirectories(fromPath)) { var fullDirName = Path.Combine(path, Path.GetFileName(dirName)); Actioner.CreateDirectory(Path.Combine(toPath, fullDirName)); toCopy.Push(fullDirName); } } }
public override void DeleteTree(SyncDirectoryInfo dir) { if (Responder.SeekYes(String.Format("Delete all of tree {0}", dir.FullName))) { DoDeleteTree(dir); } }
// Useful helper functions /// <summary> /// Unconditionally delete a tree; to be called by derived class after, presumably, some sort /// of checking code. /// </summary> protected void DoDeleteTree(SyncDirectoryInfo dir) { var toDelete = new Stack <string>(); toDelete.Push(dir.FullName); var emptyDirs = new List <string>(); while (toDelete.Count() > 0) { string path = toDelete.Pop(); foreach (var fileName in Directory.EnumerateFiles(path)) { Actioner.DeleteFile(fileName); } foreach (var dirName in Directory.EnumerateDirectories(path)) { toDelete.Push(Path.Combine(path, dirName)); } emptyDirs.Add(path); } foreach (var dirName in emptyDirs) { Actioner.DeleteDirectory(dirName); } }
public override void CopyTree(SyncDirectoryInfo from, SyncFileDirName toFullPath) { DoCopyTree(from, toFullPath); }
public abstract void CopyTree(SyncDirectoryInfo from, SyncFileDirName toFullPath);
public abstract void DeleteTree(SyncDirectoryInfo dir);
public override void CopyTree(SyncDirectoryInfo from, SyncFileDirName toFullPath) { Logger.WriteLine("CopyTree '{0}' -> '{1}'", from, toFullPath); }
/// <summary> /// Take decision about sub-directory when external exists but local does not. /// </summary> public abstract void ProcessDir(SyncFileDirName localDir, SyncDirectoryInfo externalDir);
/// <summary> /// Local directory does not exist, so copy /// </summary> public override void ProcessDir(SyncFileDirName localDir, SyncDirectoryInfo externalDir) { mover.CopyTree(from: externalDir, toFullPath: localDir); }
/// <summary> /// Local directory exists but external does not, so delete local /// </summary> public override void ProcessDir(SyncDirectoryInfo localDir, SyncFileDirName externalDir) { mover.DeleteTree(localDir); }