コード例 #1
0
ファイル: FileEntry.cs プロジェクト: helixsync/HelixSync
        public static FileEntry FromFile(string fullPath, string root)
        {
            root     = HelixUtil.PathNative(root);
            fullPath = HelixUtil.PathNative(fullPath);

            string    casedFullPath = HelixUtil.GetExactPathName(fullPath);
            FileEntry fileInfo      = new FileEntry
            {
                FileName = HelixUtil.PathUniversal(HelixUtil.RemoveRootFromPath(fullPath, root))
            };

            var fi = new FileInfo(casedFullPath);

            //Check to ensure ends with to address case changes
            if (fi.Exists && fi.FullName.EndsWith(fullPath, StringComparison.Ordinal))
            {
                fileInfo.LastWriteTimeUtc = HelixUtil.TruncateTicks(fi.LastWriteTimeUtc);
                fileInfo.Length           = fi.Length;
                fileInfo.EntryType        = FileEntryType.File;
                return(fileInfo);
            }

            var di = new DirectoryInfo(casedFullPath);

            if (di.Exists && di.FullName.EndsWith(fullPath, StringComparison.Ordinal))
            {
                fileInfo.LastWriteTimeUtc = DateTime.MinValue;
                fileInfo.EntryType        = FileEntryType.Directory;
                return(fileInfo);
            }

            fileInfo.LastWriteTimeUtc = DateTime.MinValue;
            fileInfo.EntryType        = FileEntryType.Removed;
            return(fileInfo);
        }
コード例 #2
0
 private void EncrWatcher_Changed(object sender, FileSystemEventArgs e)
 {
     if (e.ChangeType == WatcherChangeTypes.Deleted)
     {
         Enqueue(new HelixSync.DirectoryChange(PairSide.Encrypted, HelixUtil.RemoveRootFromPath(e.FullPath, DecrDirectory)));
     }
     else if (e.ChangeType == WatcherChangeTypes.Created ||
              e.ChangeType == WatcherChangeTypes.Changed)
     {
         Enqueue(new HelixSync.DirectoryChange(PairSide.Encrypted, HelixUtil.RemoveRootFromPath(e.FullPath, DecrDirectory)));
     }
     else if (e.ChangeType == WatcherChangeTypes.Renamed)
     {
         Enqueue(new HelixSync.DirectoryChange(PairSide.Encrypted, HelixUtil.RemoveRootFromPath((e as RenamedEventArgs).OldFullPath, DecrDirectory)));
         Enqueue(new HelixSync.DirectoryChange(PairSide.Encrypted, HelixUtil.RemoveRootFromPath(e.FullPath, DecrDirectory)));
     }
 }