public List <DirTree> AddFile(MyFileInfo file) { DirTree parentDir; file.TreePath = GetAbsoluteTreePath(file.Path, out parentDir); parentDir._files.Add(file); return(file.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> /// 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> /// 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 SyncFileInfo(SyncInfo syncInfo, MyFileInfo fileInfo, bool initStatus) : base(syncInfo, fileInfo, initStatus) { }
public List<DirTree> AddFile(MyFileInfo file) { DirTree parentDir; file.TreePath = GetAbsoluteTreePath(file.Path, out parentDir); parentDir._files.Add(file); return file.TreePath; }
/// <summary> /// create TreeNode representing a SyncFile /// and update its visual representation /// </summary> /// <param name="fileInfo">file info</param> public SyncFileTreeViewNode(MyFileInfo fileInfo) : base(fileInfo) { }
private TreeNode AddFileTreeNode(TreeNodeCollection nodes, MyFileInfo file) { TreeNode tn = new TreeNode(file.Name); tn.ImageIndex = 2; tn.SelectedImageIndex = 2; tn.Name = file.Name; nodes.Add(tn); return tn; }
/// <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> /// 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> /// 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)); } }