예제 #1
0
        public override bool CreateFile(string file, string source, DateTime lastModified, string fileMD5, FileAttributes attributes, bool reportProgress = true)
        {
            string dest = Path.Combine(this.Dest, file);

            // It's almost always quicker just to re-copy the file, rather than checking
            // md5 of remote file. With USB, read/write times are the same. With internal
            // HDD, times don't differ by enough to justify md5 computational overhead. Plus other overheads
            // for small files...

            this.withHandling(() => XCopy.Copy(source, dest, true, true, (percent) => {
                if (reportProgress)
                {
                    this.ReportProcess(percent);
                }
                return(this.Cancelled ? XCopy.CopyProgressResult.PROGRESS_CANCEL : XCopy.CopyProgressResult.PROGRESS_CONTINUE);
            }), file);
            if (this.Cancelled)
            {
                return(true);
            }
            FileInfo fileInfo = new FileInfo(dest);

            fileInfo.Attributes = attributes;
            fileInfo.IsReadOnly = false;
            this.withHandling(() => File.SetLastWriteTimeUtc(dest, lastModified), file);
            return(true);
        }
예제 #2
0
        public override void RestoreFile(string file, string dest, DateTime lastModified)
        {
            string fullPath = Path.Combine(this.Dest, file);

            if (!File.Exists(fullPath))
            {
                throw new BackupOperationException(file, "File could not be found on backend, so can't restore");
            }

            this.withHandling(() => XCopy.Copy(fullPath, dest, true, true, (percent) => {
                this.ReportProcess(percent);
                return(this.Cancelled ? XCopy.CopyProgressResult.PROGRESS_CANCEL : XCopy.CopyProgressResult.PROGRESS_CONTINUE);
            }), file);
            if (!this.Cancelled)
            {
                this.withHandling(() => {
                    File.SetLastWriteTimeUtc(dest, lastModified);
                    FileInfo fileInfo   = new FileInfo(dest);
                    fileInfo.Attributes = new FileInfo(fullPath).Attributes;
                }, file);
            }
        }