/// <summary> /// load the change log and the snapshot and creates them if they dont exist /// </summary> /// <param name="pro"></param> public ModificationRecorder(Project pro) { try { this.pro = pro; logDirectory = new DirectoryInfo(pro.Location + @"\" + SettingsStore.Default.logFolderName); if (!logDirectory.Exists) { logDirectory.Create(); logDirectory.Refresh(); logDirectory.Attributes = logDirectory.Attributes | FileAttributes.Hidden; } root = new RootFolder("", pro.Location, File.GetLastWriteTime(pro.Location)); xmlPath = Path.Combine(logDirectory.FullName, "fileList.xml"); if (File.Exists(xmlPath)) { try { using (XmlReader reader = XmlReader.Create(xmlPath)) { root.load(reader); } System.Diagnostics.Debug.WriteLine(root.print()); } catch { } } log = new changeLog(Path.Combine(logDirectory.FullName, "filelog.list")); pro.LastDate = log.getLastModTime(); } catch { } }
/// <summary> /// remove item at path making entry in log /// </summary> /// <param name="path"></param> /// <param name="pos"></param> /// <returns>success</returns> public override bool removeDeleted(string path, changeLog log) { string currentPath = Uri.UnescapeDataString(Path.Combine(path, Name)); bool res = false; foreach (TrackedFile item in contents.Reverse<TrackedFile>()) { res = item.removeDeleted(currentPath, log); } if (!Directory.Exists(currentPath)) { log.add(getRelative(currentPath), WatcherChangeTypes.Deleted, "", true); if (Parent != null) Parent.removeItem(this); return true; } return res; }
/// <summary> /// remove because file was deleted by adding to log /// </summary> /// <param name="path"></param> /// <param name="log"></param> /// <returns></returns> public virtual bool removeDeleted(string path, changeLog log) { string currentPath = Uri.UnescapeDataString(Path.Combine(path, Name)); //string currentPath = path; if (!File.Exists(currentPath)) { log.add(getRelative(currentPath), WatcherChangeTypes.Deleted, snapshot, false); Parent.removeItem(this); return true; } return false; }
/// <summary> /// use path to remove item in tree storing change in log /// </summary> /// <param name="path"></param> /// <returns>success</returns> public bool removeDeleted(changeLog log) { string currentPath = Uri.UnescapeDataString(rootPath); bool res = false; foreach (TrackedFile item in contents.Reverse<TrackedFile>()) { res = item.removeDeleted(rootPath, log); } return res; }