Пример #1
0
        public FileCopy(FileInfo source, FileInfo destination, FileCopyOptions options = FileCopyOptions.None)
        {
            Source      = source;
            Destination = destination;
            Options     = options;

            sourceHash = new List <byte>();
            stopwatch  = new Stopwatch();
        }
Пример #2
0
        /// <summary>
        /// ディレクトリコピー。空のディレクトリはコピーしない。
        /// </summary>
        /// <param name="source"></param>
        /// <param name="dest"></param>
        public static void CopyDirectory(string source, string dest, FileCopyOptions options)
        {
            if (PathUtil.EqualsOrSubPath(source, dest))
            {
                throw new IOException();
            }

            foreach (var item in FileSearcher.EnumerateFileInfos(source))
            {
                CopyFile(item.fi.FullName, PathUtil.CombineToFullPath(dest, item.relativePath), options);
            }
        }
Пример #3
0
        private void cancel_button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Option = FileCopyOptions.Cancel;

                HideOnExternalThread();
            }
            catch (Exception ex)
            {
                MessageBox.Show(Error.GetErrorLog(ex.Message, "NeathCopy", "FileExistWindow", "cancel_button_Click"));
            }
        }
Пример #4
0
        /// <summary>
        /// ファイルをコピーする
        /// </summary>
        /// <param name="srcPath"></param>
        /// <param name="destPath"></param>
        /// <param name="options"></param>
        public static void CopyFile(string srcPath, string destPath, FileCopyOptions options)
        {
            if (PathUtil.EqualsPath(srcPath, destPath))
            {
                throw new IOException();
            }

            var srcFile  = new FileInfo(srcPath);
            var destFile = new FileInfo(destPath);

            if (options.HasFlag(FileCopyOptions.Update) &&
                destFile.Exists &&
                srcFile.Length == destFile.Length &&
                srcFile.LastWriteTimeUtc == destFile.LastWriteTimeUtc)
            {
                return;
            }

            destFile.Directory.Create();
            srcFile.CopyTo(destFile.FullName, true);
        }
Пример #5
0
        private void ok_button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                switch (option_cb.SelectedIndex)
                {
                case 0:
                    Option = FileCopyOptions.OverwriteIfFileExist;
                    break;

                case 1:
                    Option = FileCopyOptions.AllwaysOverride;
                    break;

                case 2:
                    Option = FileCopyOptions.OverrideDifferent;
                    break;

                case 3:
                    Option = FileCopyOptions.AllwaysOverrideDifferent;
                    break;

                case 4:
                    Option = FileCopyOptions.SkipIfFileExist;
                    break;

                case 5:
                    Option = FileCopyOptions.AllwaysSkip;
                    break;
                }

                HideOnExternalThread();
            }
            catch (Exception ex)
            {
                MessageBox.Show(Error.GetErrorLog(ex.Message, "NeathCopy", "FileExistWindow", "cancel_button_Click"));
            }
        }
        protected override async Task <StorageCopyState> DoStartCopyAsync()
        {
            // To copy from source to blob, DataMovement Library should overwrite destination's properties and meta datas.
            // Clear destination's meta data here to avoid using destination's meta data.
            // Please reference to https://docs.microsoft.com/en-us/rest/api/storageservices/copy-file.
            this.destFile.Metadata.Clear();

            OperationContext operationContext = Utils.GenerateOperationContext(this.TransferContext);

            if (null != this.SourceUri)
            {
                await this.destFile.StartCopyAsync(
                    this.SourceUri,
                    null,
                    null,
                    default(FileCopyOptions),
                    Utils.GenerateFileRequestOptions(this.destLocation.FileRequestOptions),
                    operationContext,
                    this.CancellationToken);

                return(new StorageCopyState(this.destFile.CopyState));
            }
            else if (null != this.SourceBlob)
            {
                await this.destFile.StartCopyAsync(
                    this.SourceBlob.GenerateCopySourceUri(),
                    null,
                    null,
                    default(FileCopyOptions),
                    Utils.GenerateFileRequestOptions(this.destLocation.FileRequestOptions),
                    operationContext,
                    this.CancellationToken);

                var copyState = new StorageCopyState(this.destFile.CopyState);

                if (copyState.Status == StorageCopyStatus.Success)
                {
                    copyState.TotalBytes  = this.SourceBlob.Properties.Length;
                    copyState.BytesCopied = this.SourceBlob.Properties.Length;
                }
                return(copyState);
            }
            else
            {
                var             transfer        = this.TransferJob.Transfer;
                FileCopyOptions fileCopyOptions = new FileCopyOptions();

                if (transfer.PreserveSMBAttributes)
                {
                    fileCopyOptions.PreserveCreationTime   = transfer.PreserveSMBAttributes;
                    fileCopyOptions.PreserveLastWriteTime  = transfer.PreserveSMBAttributes;
                    fileCopyOptions.PreserveNtfsAttributes = transfer.PreserveSMBAttributes;
                    fileCopyOptions.SetArchive             = false;
                }

                fileCopyOptions.PreservePermissions = (transfer.PreserveSMBPermissions != PreserveSMBPermissions.None);

                await this.destFile.StartCopyAsync(
                    this.SourceFile.GenerateCopySourceUri(fileCopyOptions.PreservePermissions),
                    null,
                    null,
                    fileCopyOptions,
                    Utils.GenerateFileRequestOptions(this.destLocation.FileRequestOptions),
                    operationContext,
                    this.CancellationToken);

                var copyState = new StorageCopyState(this.destFile.CopyState);

                if (copyState.Status == StorageCopyStatus.Success)
                {
                    copyState.TotalBytes  = this.SourceFile.Properties.Length;
                    copyState.BytesCopied = this.SourceFile.Properties.Length;
                }
                return(copyState);
            }
        }