Ejemplo n.º 1
0
 public void MakeCopy(string source)
 {
     try
     {
         source = NtPath(source);
         long sizeOverflow = RepoSize + new FileInfo(source).Length - RepoMaxSize;
         if (sizeOverflow > 0)
         {
             Trim(null, sizeOverflow);
         }
         string newPath = NameDoc2Repo(source, new FileInfo(source).LastWriteTimeUtc);
         WriteDebugLog("INFO", $"Copy {source} => {newPath}");
         Directory.CreateDirectory(Win32Path(Path.GetDirectoryName(newPath)));
         if (File.Exists(Win32Path(newPath)))
         {
             WriteDebugLog("WARNING", $"Overwriting {newPath}");
             var ovwAttr = new FileInfo(Win32Path(newPath));
             ovwAttr.Attributes = ovwAttr.Attributes & ~FileAttributes.ReadOnly;
         }
         File.Copy(Win32Path(source), Win32Path(newPath), true);
         var srcAttr = new FileInfo(Win32Path(source));
         srcAttr.Attributes = srcAttr.Attributes & ~FileAttributes.Archive;
         var attr = new FileInfo(Win32Path(newPath));
         attr.Attributes = attr.Attributes & ~FileAttributes.Archive | FileAttributes.ReadOnly;
         CopyMade?.Invoke(this, source);
     }
     catch (Exception ex)
     {
         WriteDebugLog("ERROR", ex);
         //DoUnhandledException(ex);
     }
 }
Ejemplo n.º 2
0
        public void MakeCopy(string source)
        {
            if (source.StartsWith(Win32PathPrefix))
            {
                source = source.Substring(4);
            }
            string dir;

            if (source[1] == ':')
            {
                dir = Path.Combine(RepoPath, source[0] + Path.GetDirectoryName(source).Substring(2));
            }
            // else if (source.StartsWith(Path.DirectorySeparatorChar.ToString())) dir = Path.Combine(RepoPath, '_' + Path.GetDirectoryName(source).Substring(1));
            else
            {
                throw new ArgumentException("不支持的路径格式", nameof(source));
            }
            long sizeOverflow = RepoSize + new FileInfo(source).Length - RepoMaxSize;

            if (sizeOverflow > 0)
            {
                Trim(sizeOverflow);
            }
            Directory.CreateDirectory(Win32PathPrefix + dir);
            string newPath = Path.Combine(dir, Path.GetFileNameWithoutExtension(source) + "_" + new FileInfo(source).LastWriteTimeUtc.ToFileTimeUtc().ToString("X") + Path.GetExtension(source));

            try
            {
                File.Copy(Win32PathPrefix + source, Win32PathPrefix + newPath, true);
                AddRepoFile(new RepoFile(new FileInfo(newPath), RepoPath.Length));
                CopyMade?.Invoke(this, source);
            }
            catch (IOException ex)
            {
                Debug.Print(ex.Message);
            }
        }