예제 #1
0
        private Result GetOverwriteResult(SourceTarget source
                                          , IFileInfo target)
        {
            Result result = Result.Yes;

            if (target.Exists)
            {
                result = Result.No;

                if (Overwrite == OverwriteOptionConstants.Ask)
                {
                    Int64 startTicks = DateTime.Now.Ticks;

                    result = UIServices.ShowMessageBox("Overwrite \"" + target.FullName + "\"\nfrom \"" + source.SourceFile.FullName + "\"?", "Overwrite?", Buttons.YesNoCancel, Icon.Question);

                    Int64 endTicks = DateTime.Now.Ticks;

                    TimeSpan span = new TimeSpan(endTicks - startTicks);

                    CopyPaused?.Invoke(this, new EventArgs <TimeSpan>(span));
                }
                else if (Overwrite == OverwriteOptionConstants.Always)
                {
                    result = Result.Yes;
                }
            }

            return(result);
        }
예제 #2
0
        private Boolean CommenceCopy(List <SourceTarget> fileInfos)
        {
            foreach (SourceTarget fileInfo in fileInfos)
            {
                if (CancellationToken.IsCancellationRequested)
                {
                    UIServices.ShowMessageBox("The Copy process was aborted.", String.Empty, Buttons.OK, Icon.Warning);

                    return(true);
                }

                String path = IOServices.Path.Combine(fileInfo.TargetFolder.FullName, fileInfo.SourceFile.Name);

                IFileInfo targetFileInfo = IOServices.GetFileInfo(path);

                Result result = GetOverwriteResult(fileInfo, targetFileInfo);

                if (result == Result.Cancel)
                {
                    return(true);
                }
                else if (result == Result.No)
                {
                    m_Size -= fileInfo.SourceFile.Length;

                    SizeChanged?.Invoke(this, EventArgs.Empty);

                    continue;
                }
                else if (result == Result.Yes)
                {
                    try
                    {
                        if (IOServices.File.Exists(targetFileInfo.FullName))
                        {
                            IOServices.File.SetAttributes(targetFileInfo.FullName, System.IO.FileAttributes.Normal | System.IO.FileAttributes.Archive);
                        }

                        IOServices.File.Copy(fileInfo.SourceFile.FullName, targetFileInfo.FullName, true);
                    }
                    catch (Exception ex)
                    {
                        Int64 startTicks = DateTime.Now.Ticks;

                        if (UIServices.ShowMessageBox(ex.Message + "\nContinue?", "Continue?", Buttons.YesNo, Icon.Question) == Result.Yes)
                        {
                            Int64 endTicks = DateTime.Now.Ticks;

                            TimeSpan span = new TimeSpan(endTicks - startTicks);

                            CopyPaused?.Invoke(this, new EventArgs <TimeSpan>(span));

                            continue;
                        }
                        else
                        {
                            return(true);
                        }
                    }

                    ProgressValue += fileInfo.SourceFile.Length;

                    ProgressChanged?.Invoke(this, EventArgs.Empty);
                }
            }

            return(false);
        }