public override RemoteDownloadResult UpdateNoteFromRemote(INote inote) { FilesystemNote note = (FilesystemNote)inote; var path = note.GetPath(_config); if (!File.Exists(path)) { return(RemoteDownloadResult.DeletedOnRemote); } note.Title = Path.GetFileNameWithoutExtension(path); note.Text = File.ReadAllText(path, _config.Encoding); note.PathRemote = path; return(RemoteDownloadResult.Updated); }
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.ModificationDate = fi.LastWriteTime; note.IsLocked = fi.IsReadOnly; } return(RemoteDownloadResult.Updated); }
public override RemoteUploadResult UploadNoteToRemote(ref INote inote, out INote conflict, ConflictResolutionStrategy strategy) { FilesystemNote note = (FilesystemNote)inote; var path = note.GetPath(_config); if (File.Exists(note.PathRemote) && path != note.PathRemote && !File.Exists(path)) { _logger.Debug(FilesystemPlugin.Name, "Upload note to changed remote path"); // path changed and new path does not exist WriteNoteToPath(note, path); conflict = null; ANFileSystemUtil.DeleteFileAndFolderIfEmpty(FilesystemPlugin.Name, _logger, _config.Folder, note.PathRemote); note.PathRemote = path; return(RemoteUploadResult.Uploaded); } else if (File.Exists(note.PathRemote) && path != note.PathRemote && File.Exists(path)) { _logger.Debug(FilesystemPlugin.Name, "Upload note to changed remote path"); // path changed and new path does exist var conf = ReadNoteFromPath(note.PathRemote); if (conf.ModificationDate > note.ModificationDate) { conflict = conf; if (strategy == ConflictResolutionStrategy.UseClientCreateConflictFile || strategy == ConflictResolutionStrategy.UseClientVersion || strategy == ConflictResolutionStrategy.ManualMerge) { WriteNoteToPath(note, path); ANFileSystemUtil.DeleteFileAndFolderIfEmpty(FilesystemPlugin.Name, _logger, _config.Folder, note.PathRemote); note.PathRemote = path; return(RemoteUploadResult.Conflict); } else { note.PathRemote = path; return(RemoteUploadResult.Conflict); } } else { WriteNoteToPath(note, path); conflict = null; ANFileSystemUtil.DeleteFileAndFolderIfEmpty(FilesystemPlugin.Name, _logger, _config.Folder, note.PathRemote); note.PathRemote = path; return(RemoteUploadResult.Uploaded); } } else if (File.Exists(path)) // normal update { var conf = ReadNoteFromPath(path); if (conf.ModificationDate > note.ModificationDate) { conflict = conf; if (strategy == ConflictResolutionStrategy.UseClientCreateConflictFile || strategy == ConflictResolutionStrategy.UseClientVersion) { WriteNoteToPath(note, path); if (note.PathRemote != "") { ANFileSystemUtil.DeleteFileAndFolderIfEmpty(FilesystemPlugin.Name, _logger, _config.Folder, note.PathRemote); } note.PathRemote = path; return(RemoteUploadResult.Conflict); } else { note.PathRemote = path; return(RemoteUploadResult.Conflict); } } else { WriteNoteToPath(note, path); conflict = null; note.PathRemote = path; return(RemoteUploadResult.Uploaded); } } else // new file { WriteNoteToPath(note, path); conflict = null; note.PathRemote = path; return(RemoteUploadResult.Uploaded); } }