Beispiel #1
0
        public CopyForm(Options.Direction direction, FolderItem leftFolder, FolderItem rightFolder)
        {
            InitializeComponent();

            this.leftFolder  = leftFolder;
            this.rightFolder = rightFolder;

            this.leftFolderTextBox.Text  = this.leftFolder.FullName();
            this.rightFolderTextBox.Text = this.rightFolder.FullName();

            switch (direction)
            {
            case Options.Direction.LeftToRight:
                this.leftToRightRadioButton.Checked = true;
                break;

            case Options.Direction.RightToLeft:
                this.rightToLeftRadioButton.Checked = true;
                break;

            case Options.Direction.Synchronize:
                this.syncRadioButton.Checked = true;
                break;

            default:
                Debug.Assert(false);
                break;
            }
            Application.Idle += new EventHandler(Application_Idle);
        }
Beispiel #2
0
        private void PerformCopy(Options.Direction direction)
        {
            // Show the synchronization options form
            using (CopyForm copyForm = new CopyForm(direction, this.folderTree1.RootFolder, this.folderTree2.RootFolder))
            {
                if (copyForm.ShowDialog(this) == DialogResult.OK)
                {
                    // Build up a list of files to copy
                    List <string> fromList = new List <string>();
                    List <string> toList   = new List <string>();
                    // Also build a list of files to delete
                    List <string> deleteList = new List <string>();

                    Options options = copyForm.GetOptions();

                    // Add the files to the list:
                    AddFilesToList(this.folderTree1.RootFolder, this.folderTree2.RootFolder, options, fromList, toList, deleteList);

                    if (fromList.Count == 0 && deleteList.Count == 0)
                    {
                        MessageBox.Show(this, "There are no files to copy or delete!", "Nothing to do", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        string[] from = fromList.ToArray();
                        string[] to   = toList.ToArray();

                        if (copyForm.IsPreview())
                        {
                            StringBuilder fromStringBuilder = new StringBuilder();
                            int           n = 0;
                            foreach (string s in from)
                            {
                                fromStringBuilder.AppendLine(s + " --> " + to[n]);
                                n++;
                            }
                            foreach (string s in deleteList)
                            {
                                fromStringBuilder.AppendLine("Delete: " + s);
                            }

                            ShowPreview(fromStringBuilder.ToString());

                            //string filename = Path.GetTempFileName(); //Path.Combine(Environment.CurrentDirectory, "test.txt");
                            //File.WriteAllText(filename, fromStringBuilder.ToString());
                            //Process p = Process.Start("Notepad", filename);
                            //File.Delete(filename);
                        }
                        else
                        {
                            bool AnyOperationsAborted = false;

                            if (from.Length > 0 && !FileOperation.CopyFiles(this.Handle, from, to, "Synchronizing...", out AnyOperationsAborted))
                            {
                                MessageBox.Show(this, "An error occurred while copying files." + Environment.NewLine + Environment.NewLine + "Not all files were copied. Please repeat the operation.", "Error during synchronization", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else if (AnyOperationsAborted)
                            {
                                MessageBox.Show(this, "The operation was cancelled while copying files." + Environment.NewLine + Environment.NewLine + "Not all files were copied. Please repeat the operation.", "Error during synchronization", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else if (deleteList.Count > 0)
                            {
                                string[] delete = deleteList.ToArray();
                                if (!FileOperation.DeleteFiles(this.Handle, delete, "Synchronizing...", out AnyOperationsAborted))
                                {
                                    MessageBox.Show(this, "An error occurred while deleting files." + Environment.NewLine + Environment.NewLine + "Not all necessary files were deleted. Please repeat the operation.", "Error during synchronization", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                                else if (AnyOperationsAborted)
                                {
                                    MessageBox.Show(this, "The operation was cancelled while deleting files." + Environment.NewLine + Environment.NewLine + "Not all necessary files were deleted. Please repeat the operation.", "Error during synchronization", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                            // TODO: refresh here
                        }
                    }
                }
            }
        }