private SelectionCheck Check() { SelectionCheck check = new SelectionCheck(); if (!symlink.IsCompleted() || String.Equals(symlink.Source, symlink.Target)) { return(check); } check.IsSelectionReady = true; check.IsFile = SymlinkOption.FILE_SYMBOLIC == symlink.SymlinkOption || SymlinkOption.FILE_HARD == symlink.SymlinkOption; if (check.IsFile) { check.SourceExists = File.Exists(symlink.Source); check.TargetExists = File.Exists(symlink.Target); } else { check.SourceExists = Directory.Exists(symlink.Source); check.TargetExists = Directory.Exists(symlink.Target); } return(check); }
private void bLink_Click(object sender, EventArgs e) { /* Check */ SelectionCheck checkResult = Check(); /* Prepare */ Boolean isPreparationOk = Prepare(checkResult); /* Execute it! */ Execute(); }
private bool Prepare(SelectionCheck checkResult) { if (!checkResult.IsSelectionReady) { return(false); } /* Directory */ if (!checkResult.IsFile) { if (!checkResult.TargetExists) { DialogResult result = MessageBox.Show("The Target doesn't exists. Do you want to create it?", "Target doesn't exists", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { Directory.CreateDirectory(symlink.Target); } else if (result == DialogResult.No) { return(false); } } if (checkResult.SourceExists) { DialogResult result = MessageBox.Show("The Source exists. Do you want to: copy the content to target (Yes), replace it (No) or nothing (Cancel)?", "Source exists", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { Copy(checkResult.IsFile); } else if (result == DialogResult.No) { File.Delete(symlink.Source); } else { return(false); } } } return(true); }