private void WriteNoteToPath(FilesystemNote note, string path) { Directory.CreateDirectory(Path.GetDirectoryName(path)); FileInfo fileBefore = new FileInfo(path); if (fileBefore.Exists && fileBefore.IsReadOnly) { fileBefore.IsReadOnly = false; } File.WriteAllText(path, note.Text); new FileInfo(path).IsReadOnly = note.IsLocked; note.SetModificationDate(new FileInfo(path).LastWriteTime); }
private FilesystemNote ReadNoteFromPath(string path) { var info = new FileInfo(path); var note = new FilesystemNote(Guid.NewGuid(), _config); using (note.SuppressDirtyChanges()) { note.Title = Path.GetFileNameWithoutExtension(info.FullName); note.Path = ANFileSystemUtil.GetDirectoryPath(_config.Folder, info.DirectoryName); note.Text = File.ReadAllText(info.FullName, _config.Encoding); note.CreationDate = info.CreationTime; note.SetModificationDate(info.LastWriteTime); note.PathRemote = info.FullName; note.IsLocked = info.IsReadOnly; } return(note); }
public override RemoteDownloadResult UpdateNoteFromRemote(INote inote) { FilesystemNote note = (FilesystemNote)inote; var path = note.GetPath(_config); var fi = new FileInfo(path); if (!fi.Exists) { return(RemoteDownloadResult.DeletedOnRemote); } using (note.SuppressDirtyChanges()) { note.Title = Path.GetFileNameWithoutExtension(path); note.Text = File.ReadAllText(path, _config.Encoding); note.PathRemote = path; note.SetModificationDate(fi.LastWriteTime); note.IsLocked = fi.IsReadOnly; } return(RemoteDownloadResult.Updated); }