Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }