/// <summary> /// create DirTree /// </summary> /// <param name="info">directory info</param> /// <param name="parent">parent dir | null if root</param> /// <param name="root">this if null</param> public DirTree(MyDirInfo info, DirTree parent, DirTree root) { _info = info; _parent = parent; if (root == null) _root = this; else _root = root; }
public List<DirTree> AddDir(MyDirInfo newDir) { DirTree dt = new DirTree(newDir, this, Root); DirTree parentDir; newDir.DirTreeInfo = dt; newDir.TreePath = GetAbsoluteTreePath(newDir.Path, out parentDir); parentDir._dirs.Add(dt); return newDir.TreePath; }
public List <DirTree> AddDir(MyDirInfo newDir) { DirTree dt = new DirTree(newDir, this, Root); DirTree parentDir; newDir.DirTreeInfo = dt; newDir.TreePath = GetAbsoluteTreePath(newDir.Path, out parentDir); parentDir._dirs.Add(dt); return(newDir.TreePath); }
/// <summary> /// detect files and directories that should be removed for One-Way synchronisation recursively /// </summary> /// <param name="sourceHomePath">absolute source folder path (homepath as defined in link)</param> /// <param name="destHomePath">absolute destination folder path (homepath as defined in link)</param> /// <param name="dir">the directory, in which you want to search</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> /// <returns>true if the operation was canceled</returns> public static void GetRemoveInfosOfDirRecursively_OneWay(string sourceHomePath, string destHomePath, MyDirInfo dir, SyncInfo si, Func <bool> interruptChecker) { interruptChecker(); string sourcePath = sourceHomePath + dir.FullPath; string destPath = destHomePath + dir.FullPath; try { //get directories to remove //detect destination child directories foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(destPath)) { string newDirname = Delimon.Win32.IO.Path.GetFileName(name); MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname); //remove destination directory if source directory doesn't exist (if remove is enabled) if (si.Link.Remove && !new Delimon.Win32.IO.DirectoryInfo(newDir.FullPath).Exists) { new SyncDirInfo(si, newDir, true); new SyncDirExecutionInfo(newDir.SyncDirInfo, si.Link.Direction, true); } GetRemoveInfosOfDirRecursively_OneWay(sourceHomePath, destHomePath, newDir, si, interruptChecker); } //get files to remove //Loop through all files in destination directory foreach (string path in Delimon.Win32.IO.Directory.GetFiles(destPath)) { string name = Delimon.Win32.IO.Path.GetFileName(path); MyFileInfo file = new MyFileInfo(dir.FullPath, name); string sourceFilePath = sourceHomePath + file.FullPath; string destFilePath = destHomePath + file.FullPath; //remove destination file if source file doesn't exist (if remove is enabled) if (!new Delimon.Win32.IO.FileInfo(sourceFilePath).Exists) { new SyncFileInfo(si, file, true); if (si.Link.Remove) { file.Size = new Delimon.Win32.IO.FileInfo(destFilePath).Length; new SyncFileExecutionInfo(file.SyncFileInfo, si.Link.Direction, true); } } } } catch (Exception e) { si.Log(new LogMessage(LogType.ERROR, e.Message, e)); } }
/// <summary> /// create DirTree /// </summary> /// <param name="info">directory info</param> /// <param name="parent">parent dir | null if root</param> /// <param name="root">this if null</param> public DirTree(MyDirInfo info, DirTree parent, DirTree root) { _info = info; _parent = parent; if (root == null) { _root = this; } else { _root = root; } }
/// <summary> /// fetch files and detect subdirectory changes for One-Way synchronisation recursively /// </summary> /// <param name="sourceHomePath">absolute source folder path (homepath as defined in link)</param> /// <param name="destHomePath">absolute destination folder path (homepath as defined in link)</param> /// <param name="dir">the directory, in which you want to search</param> /// <param name="si">sync info</param> /// <param name="onFileFound">is called when a file was found</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> public static void FetchFilesInDirRecursively_OneWay(string sourceHomePath, string destHomePath, MyDirInfo dir, SyncInfo si, Action <SyncFileInfo> onFileFound, Func <bool> interruptChecker) { interruptChecker(); string sourcePath = sourceHomePath + dir.FullPath; string destPath = destHomePath + dir.FullPath; try { //create destination directory if not exists if (dir.SyncDirInfo != null && !new Delimon.Win32.IO.DirectoryInfo(destPath).Exists) { new SyncDirExecutionInfo(dir.SyncDirInfo, si.Link.Direction, false); } //detect source child directories foreach (string dirpath in Delimon.Win32.IO.Directory.GetDirectories(sourcePath)) { string name = Delimon.Win32.IO.Path.GetFileName(dirpath); MyDirInfo newDir = new MyDirInfo(dir.FullPath, name); new SyncDirInfo(si, newDir, true); FetchFilesInDirRecursively_OneWay(sourceHomePath, destHomePath, newDir, si, onFileFound, interruptChecker); } //loop through all files in source directory foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(sourcePath)) { //detect changes of file asynchronously string name = Delimon.Win32.IO.Path.GetFileName(filepath); MyFileInfo file = new MyFileInfo(dir.FullPath, name); new SyncFileInfo(si, file, true); onFileFound(file.SyncFileInfo); } } catch (OperationCanceledException) { } catch (Exception e) { si.Log(new LogMessage(LogType.ERROR, e.Message, e)); } }
/// <summary> /// detect dir change for two way synchronisation. /// </summary> /// <param name="dir"></param> /// <returns></returns> private static TwoWayCompareResult DetectDirChange_TwoWay(MyDirInfo dir) { Delimon.Win32.IO.DirectoryInfo dirInfo1 = new Delimon.Win32.IO.DirectoryInfo(dir.SyncDirInfo.AbsolutePath1); Delimon.Win32.IO.DirectoryInfo dirInfo2 = new Delimon.Win32.IO.DirectoryInfo(dir.SyncDirInfo.AbsolutePath2); Delimon.Win32.IO.DirectoryInfo parent1 = new Delimon.Win32.IO.DirectoryInfo(dir.Parent.SyncDirInfo.AbsolutePath1); Delimon.Win32.IO.DirectoryInfo parent2 = new Delimon.Win32.IO.DirectoryInfo(dir.Parent.SyncDirInfo.AbsolutePath2); bool remove = dir.SyncDirInfo.SyncInfo.Link.Remove; if (!dirInfo1.Exists) { // if parent dir 1 is older than parent dir 2 -> create dir in parent dir 1 if (parent2.LastWriteTime >= parent1.LastWriteTime) { return(new TwoWayCompareResult(SyncDirection.To1, false)); } // otherwise remove dir 2 if remove ist enabled if (remove) { return(new TwoWayCompareResult(SyncDirection.To2, true)); } return(null); } if (!dirInfo2.Exists) { // if parent dir 2 is older than parent dir 1 -> create dir in parent dir 2 if (parent1.LastWriteTime >= parent2.LastWriteTime) { return(new TwoWayCompareResult(SyncDirection.To2, false)); } // otherwise remove dir 1 if remove ist enabled if (remove) { return(new TwoWayCompareResult(SyncDirection.To1, true)); } return(null); } return(null); }
/// <summary> /// create SyncInfo /// </summary> /// <param name="link">link data (will be copied not referenced)</param> public SyncInfo(SyncLink link) { Link = link; Time = new TimeMeasurement(this); Files = new FilesInfo(this); Dirs = new DirsInfo(this); Paused = false; SyncDirExecutionInfos = new List<SyncDirExecutionInfo>(); SyncFileExecutionInfos = new List<SyncFileExecutionInfo>(); ConflictInfos = new List<ElementConflictInfo>(); LogStack = new Stack<LogMessage>(); MyDirInfo rootDir = new MyDirInfo("\\", ""); SyncDirInfo sdi = new SyncDirInfo(this, rootDir, false); DirTree = new DirTree(rootDir, null, null); Status = SyncStatus.DetectingChanges; }
/// <summary> /// create SyncInfo /// </summary> /// <param name="link">link data (will be copied not referenced)</param> public SyncInfo(SyncLink link) { Link = link; Time = new TimeMeasurement(this); Files = new FilesInfo(this); Dirs = new DirsInfo(this); Paused = false; SyncDirExecutionInfos = new List <SyncDirExecutionInfo>(); SyncFileExecutionInfos = new List <SyncFileExecutionInfo>(); ConflictInfos = new List <ElementConflictInfo>(); LogStack = new Stack <LogMessage>(); MyDirInfo rootDir = new MyDirInfo("\\", ""); SyncDirInfo sdi = new SyncDirInfo(this, rootDir, false); DirTree = new DirTree(rootDir, null, null); Status = SyncStatus.DetectingChanges; }
/// <summary> /// fetch files and subdirectories for Two-Way synchronisation recursively /// </summary> /// <param name="dir">the directory, in which you want to search</param> /// <param name="si">sync info</param> /// <param name="onFileFound">is called when a file was found</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> public static void FetchElementsInDirRecursively_TwoWay(MyDirInfo dir, SyncInfo si, Action <SyncFileInfo> onFileFound, Func <bool> interruptChecker) { interruptChecker(); string path1 = si.Link.Path1 + dir.FullPath; string path2 = si.Link.Path2 + dir.FullPath; //directory info Delimon.Win32.IO.DirectoryInfo di1 = new Delimon.Win32.IO.DirectoryInfo(path1); Delimon.Win32.IO.DirectoryInfo di2 = new Delimon.Win32.IO.DirectoryInfo(path2); List <string> dirNames = new List <string>(); List <string> fileNames = new List <string>(); try { #region detect changes of directories if (di1.Exists) { //loop through path1 dir foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(path1)) { string newDirname = Delimon.Win32.IO.Path.GetFileName(name); dirNames.Add(newDirname); MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname); new SyncDirInfo(si, newDir, true); FetchElementsInDirRecursively_TwoWay(newDir, si, onFileFound, interruptChecker); } } if (di2.Exists) { //loop through path2 dir except the dirs, which have already been detected in path1 foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(path2)) { string newDirname = Delimon.Win32.IO.Path.GetFileName(name); if (!dirNames.Contains(newDirname)) { MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname); new SyncDirInfo(si, newDir, true); FetchElementsInDirRecursively_TwoWay(newDir, si, onFileFound, interruptChecker); } } } #endregion #region detect files if (di1.Exists) { //Loop through all files in path1 foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(path1)) { string name = Delimon.Win32.IO.Path.GetFileName(filepath); MyFileInfo file = new MyFileInfo(dir.FullPath, name); new SyncFileInfo(si, file, true); fileNames.Add(name); onFileFound(file.SyncFileInfo); } } if (di2.Exists) { //Loop through all files in path2 except the files, which have already been detected in path1 foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(path2)) { string name = Delimon.Win32.IO.Path.GetFileName(filepath); if (fileNames.Contains(name)) { continue; } MyFileInfo file = new MyFileInfo(dir.FullPath, name); new SyncFileInfo(si, file, true); onFileFound(file.SyncFileInfo); } } #endregion } catch (Exception e) { si.Log(new LogMessage(LogType.ERROR, e.Message, e)); } }
/// <summary> /// fetch files and subdirectories for Two-Way synchronisation recursively /// </summary> /// <param name="dir">the directory, in which you want to search</param> /// <param name="si">sync info</param> /// <param name="onFileFound">is called when a file was found</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> public static void FetchElementsInDirRecursively_TwoWay(MyDirInfo dir, SyncInfo si, Action<SyncFileInfo> onFileFound, Func<bool> interruptChecker) { interruptChecker(); string path1 = si.Link.Path1 + dir.FullPath; string path2 = si.Link.Path2 + dir.FullPath; //directory info Delimon.Win32.IO.DirectoryInfo di1 = new Delimon.Win32.IO.DirectoryInfo(path1); Delimon.Win32.IO.DirectoryInfo di2 = new Delimon.Win32.IO.DirectoryInfo(path2); List<string> dirNames = new List<string>(); List<string> fileNames = new List<string>(); try { #region detect changes of directories if (di1.Exists) { //loop through path1 dir foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(path1)) { string newDirname = Delimon.Win32.IO.Path.GetFileName(name); dirNames.Add(newDirname); MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname); new SyncDirInfo(si, newDir, true); FetchElementsInDirRecursively_TwoWay(newDir, si, onFileFound, interruptChecker); } } if(di2.Exists) { //loop through path2 dir except the dirs, which have already been detected in path1 foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(path2)) { string newDirname = Delimon.Win32.IO.Path.GetFileName(name); if (!dirNames.Contains(newDirname)) { MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname); new SyncDirInfo(si, newDir, true); FetchElementsInDirRecursively_TwoWay(newDir, si, onFileFound, interruptChecker); } } } #endregion #region detect files if (di1.Exists) { //Loop through all files in path1 foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(path1)) { string name = Delimon.Win32.IO.Path.GetFileName(filepath); MyFileInfo file = new MyFileInfo(dir.FullPath, name); new SyncFileInfo(si, file, true); fileNames.Add(name); onFileFound(file.SyncFileInfo); } } if (di2.Exists) { //Loop through all files in path2 except the files, which have already been detected in path1 foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(path2)) { string name = Delimon.Win32.IO.Path.GetFileName(filepath); if (fileNames.Contains(name)) continue; MyFileInfo file = new MyFileInfo(dir.FullPath, name); new SyncFileInfo(si, file, true); onFileFound(file.SyncFileInfo); } } #endregion } catch (Exception e) { si.Log(new LogMessage(LogType.ERROR, e.Message, e)); } }
public SyncDirInfo(SyncInfo syncInfo, MyDirInfo dirInfo, bool initStatus) : base(syncInfo, dirInfo, initStatus) { }
/// <summary> /// reate TreeNode representing a SyncDir /// and update its visual representation /// </summary> /// <param name="dirInfo">directory info</param> public SyncDirTreeViewNode(MyDirInfo dirInfo) : base(dirInfo) { }
/// <summary> /// fetch files and detect subdirectory changes for One-Way synchronisation recursively /// </summary> /// <param name="sourceHomePath">absolute source folder path (homepath as defined in link)</param> /// <param name="destHomePath">absolute destination folder path (homepath as defined in link)</param> /// <param name="dir">the directory, in which you want to search</param> /// <param name="si">sync info</param> /// <param name="onFileFound">is called when a file was found</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> public static void FetchFilesInDirRecursively_OneWay(string sourceHomePath, string destHomePath, MyDirInfo dir, SyncInfo si, Action<SyncFileInfo> onFileFound, Func<bool> interruptChecker) { interruptChecker(); string sourcePath = sourceHomePath + dir.FullPath; string destPath = destHomePath + dir.FullPath; try { //create destination directory if not exists if (dir.SyncDirInfo != null && !new Delimon.Win32.IO.DirectoryInfo(destPath).Exists) { new SyncDirExecutionInfo(dir.SyncDirInfo, si.Link.Direction, false); } //detect source child directories foreach (string dirpath in Delimon.Win32.IO.Directory.GetDirectories(sourcePath)) { string name = Delimon.Win32.IO.Path.GetFileName(dirpath); MyDirInfo newDir = new MyDirInfo(dir.FullPath, name); new SyncDirInfo(si, newDir, true); FetchFilesInDirRecursively_OneWay(sourceHomePath, destHomePath, newDir, si, onFileFound, interruptChecker); } //loop through all files in source directory foreach (string filepath in Delimon.Win32.IO.Directory.GetFiles(sourcePath)) { //detect changes of file asynchronously string name = Delimon.Win32.IO.Path.GetFileName(filepath); MyFileInfo file = new MyFileInfo(dir.FullPath, name); new SyncFileInfo(si, file, true); onFileFound(file.SyncFileInfo); } } catch (OperationCanceledException) { } catch (Exception e) { si.Log(new LogMessage(LogType.ERROR, e.Message, e)); } }
/// <summary> /// detect files and directories that should be removed for One-Way synchronisation recursively /// </summary> /// <param name="sourceHomePath">absolute source folder path (homepath as defined in link)</param> /// <param name="destHomePath">absolute destination folder path (homepath as defined in link)</param> /// <param name="dir">the directory, in which you want to search</param> /// <param name="interruptChecker">is called when the cancellation or pause request should be checked in order to handel them</param> /// <returns>true if the operation was canceled</returns> public static void GetRemoveInfosOfDirRecursively_OneWay(string sourceHomePath, string destHomePath, MyDirInfo dir, SyncInfo si, Func<bool> interruptChecker) { interruptChecker(); string sourcePath = sourceHomePath + dir.FullPath; string destPath = destHomePath + dir.FullPath; try { //get directories to remove //detect destination child directories foreach (string name in Delimon.Win32.IO.Directory.GetDirectories(destPath)) { string newDirname = Delimon.Win32.IO.Path.GetFileName(name); MyDirInfo newDir = new MyDirInfo(dir.FullPath, newDirname); //remove destination directory if source directory doesn't exist (if remove is enabled) if (si.Link.Remove && !new Delimon.Win32.IO.DirectoryInfo(newDir.FullPath).Exists) { new SyncDirInfo(si, newDir, true); new SyncDirExecutionInfo(newDir.SyncDirInfo, si.Link.Direction, true); } GetRemoveInfosOfDirRecursively_OneWay(sourceHomePath, destHomePath, newDir, si, interruptChecker); } //get files to remove //Loop through all files in destination directory foreach (string path in Delimon.Win32.IO.Directory.GetFiles(destPath)) { string name = Delimon.Win32.IO.Path.GetFileName(path); MyFileInfo file = new MyFileInfo(dir.FullPath, name); string sourceFilePath = sourceHomePath + file.FullPath; string destFilePath = destHomePath + file.FullPath; //remove destination file if source file doesn't exist (if remove is enabled) if (!new Delimon.Win32.IO.FileInfo(sourceFilePath).Exists) { new SyncFileInfo(si, file, true); if (si.Link.Remove) { file.Size = new Delimon.Win32.IO.FileInfo(destFilePath).Length; new SyncFileExecutionInfo(file.SyncFileInfo, si.Link.Direction, true); } } } } catch (Exception e) { si.Log(new LogMessage(LogType.ERROR, e.Message, e)); } }
private TreeNode AddDirTreeNode(TreeNodeCollection nodes, MyDirInfo dir) { TreeNode tn = new TreeNode(dir.Name); tn.ImageIndex = 0; tn.SelectedImageIndex = 1; tn.Name = dir.Name; nodes.Add(tn); return tn; }
/// <summary> /// detect dir change for two way synchronisation. /// </summary> /// <param name="dir"></param> /// <returns></returns> private static TwoWayCompareResult DetectDirChange_TwoWay(MyDirInfo dir) { Delimon.Win32.IO.DirectoryInfo dirInfo1 = new Delimon.Win32.IO.DirectoryInfo(dir.SyncDirInfo.AbsolutePath1); Delimon.Win32.IO.DirectoryInfo dirInfo2 = new Delimon.Win32.IO.DirectoryInfo(dir.SyncDirInfo.AbsolutePath2); Delimon.Win32.IO.DirectoryInfo parent1 = new Delimon.Win32.IO.DirectoryInfo(dir.Parent.SyncDirInfo.AbsolutePath1); Delimon.Win32.IO.DirectoryInfo parent2 = new Delimon.Win32.IO.DirectoryInfo(dir.Parent.SyncDirInfo.AbsolutePath2); bool remove = dir.SyncDirInfo.SyncInfo.Link.Remove; if (!dirInfo1.Exists) { // if parent dir 1 is older than parent dir 2 -> create dir in parent dir 1 if (parent2.LastWriteTime >= parent1.LastWriteTime) return new TwoWayCompareResult(SyncDirection.To1, false); // otherwise remove dir 2 if remove ist enabled if (remove) return new TwoWayCompareResult(SyncDirection.To2, true); return null; } if (!dirInfo2.Exists) { // if parent dir 2 is older than parent dir 1 -> create dir in parent dir 2 if (parent1.LastWriteTime >= parent2.LastWriteTime) return new TwoWayCompareResult(SyncDirection.To2, false); // otherwise remove dir 1 if remove ist enabled if (remove) return new TwoWayCompareResult(SyncDirection.To1, true); return null; } return null; }