예제 #1
0
 private void AskFile1Clicked(object sender, EventArgs e)
 {
     MyResult = moveResult.Overwrite;
     DialogResult = System.Windows.Forms.DialogResult.OK;
     Close();
 }
예제 #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     MyResult = moveResult.Cancel;
     DialogResult = System.Windows.Forms.DialogResult.OK;
     Close();
 }
예제 #3
0
 private void MoveAndKeepClicked(object sender, EventArgs e)
 {
     MyResult = moveResult.Both;
     DialogResult = System.Windows.Forms.DialogResult.OK;
     Close();
 }
예제 #4
0
        private void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
        {
            // Get the subdirectories for the specified directory.
            DirectoryInfo dir = new DirectoryInfo(sourceDirName);

            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException(
                    "Source directory does not exist or could not be found: "
                    + sourceDirName);
            }

            DirectoryInfo[] dirs = dir.GetDirectories();
            // If the destination directory doesn't exist, create it.
            if (!Directory.Exists(destDirName))
            {
                Directory.CreateDirectory(destDirName);
            }

            // Get the files in the directory and copy them to the new location.
            FileInfo[] files = dir.GetFiles();

            foreach (FileInfo file in files)
            {
                string temppath = Path.Combine(destDirName, file.Name);

                try
                {
                    file.CopyTo(temppath, false);
                    Log(file, temppath);
                }
                catch (System.UnauthorizedAccessException)
                {
                    Log(file,  temppath, copyResult.Unhautorized);
                }
                catch (System.IO.IOException e)
                {
                    String newFile = RenameFile(file, temppath);
                    if (MoveResult == moveResult.Undefined)
                    {
                        this.Invoke((MethodInvoker)delegate
                        {
                            var sfd = new ConfirmDialog(file, Path.GetFileName(newFile), temppath);
                            if (sfd.ShowDialog() == DialogResult.OK)
                            {
                                if (sfd.ApplyToAll)
                                {
                                    MoveResult = sfd.ConfirmResult;
                                }

                                if (sfd.ConfirmResult == moveResult.Overwrite)
                                {
                                    try
                                    {
                                        file.CopyTo(temppath, true);
                                        Log(file, temppath);
                                    }
                                    catch (System.UnauthorizedAccessException)
                                    {
                                        Log(file, temppath, copyResult.Unhautorized);
                                    }
                                }
                                else if (sfd.ConfirmResult == moveResult.Both)
                                {
                                    file.CopyTo(newFile, true);
                                    Log(file, newFile, copyResult.Renamed);
                                }
                                else
                                {
                                    Log(file, temppath, copyResult.Exist);
                                }
                            
                            }
                            else
                            {
                                backgroundWorker1.CancelAsync();
                                Canceled = true;
                            }
                                                

                        });
                    }
                    else
                    {
                        if (MoveResult == moveResult.Overwrite)
                        {
                            try
                            {
                                file.CopyTo(temppath, true);
                                Log(file, temppath);
                            }
                            catch (System.UnauthorizedAccessException)
                            {
                                Log(file, temppath, copyResult.Unhautorized);
                            }
                        }
                        else if (MoveResult == moveResult.Both)
                        {
                            file.CopyTo(newFile, true);
                            Log(file,newFile, copyResult.Renamed);
                        }
                        else
                        {
                            Log(file, temppath, copyResult.Exist);
                        }
                    }                

                    if (Canceled) break;
                }
            }
                
            

            if (Canceled) return;


            progressdata data = new progressdata();
            data.type = copyType.file;
            backgroundWorker1.ReportProgress(iFilesOk++, data);

            
        
            progressdata data2 = new progressdata();
            data2.type = copyType.folder;
            backgroundWorker1.ReportProgress(iFoldersOk++, data2);

            // If copying subdirectories, copy them and their contents to new location.
            if (!Canceled && copySubDirs)
            {
                foreach (DirectoryInfo subdir in dirs)
                {
                    string temppath = Path.Combine(destDirName, subdir.Name);
                    DirectoryCopy(subdir.FullName, temppath, copySubDirs);

                }
            }
        }