예제 #1
0
        public static bool Rename(string path1, string path2)
        {
            if (string.Equals(path1, path2, StringComparison.InvariantCultureIgnoreCase))
            {
                return(true);
            }

            if (File.Exists(path2))
            {
                using (CopyDialog dialog = new CopyDialog(path2, path1)
                {
                    Text = "Move"
                })
                {
                    DialogResult r = dialog.ShowDialog();
                    if (r == DialogResult.Yes)
                    {
                        File.Delete(path2);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            File.Move(path1, path2);
            return(true);
        }
예제 #2
0
        public static bool Copy(string path1, string path2, bool deleteFirst = false, bool confirmOverwrite = true)
        {
            if (File.Exists(path2) && confirmOverwrite)
            {
                using (CopyDialog dialog = new CopyDialog(path2, path1)
                {
                    Text = "Copy"
                })
                {
                    DialogResult r = dialog.ShowDialog();
                    if (r != DialogResult.Yes)
                    {
                        return(false);
                    }
                }
            }

            string dir = Path.GetDirectoryName(path2);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            if (deleteFirst)
            {
                File.Delete(path2);
            }

            File.Copy(path1, path2, true);
            return(true);
        }
예제 #3
0
        public CopyDialog(string pacNew, string pacExisting)
        {
            InitializeComponent();

            CopyDialog dialog = this;

            dialog.lblPacNewName.Text      = Path.GetFileName(pacNew);
            dialog.lblPacNewMD5.Text       = ByteUtilities.MD5Sum(pacNew);
            dialog.lblPacExistingName.Text = Path.GetFileName(pacExisting);
            dialog.lblPacExistingMD5.Text  = ByteUtilities.MD5Sum(pacExisting);

            if (dialog.lblPacNewMD5.Text == dialog.lblPacExistingMD5.Text)
            {
                dialog.lblPacExistingMD5.ForeColor = dialog.lblPacNewMD5.ForeColor = Color.Green;
            }
        }