private bool RunCreateBazaarBranch(ref string LocalFolderLocation) { // Standard method to create a new branch. This can be called from the link to change the branch location // or from the Source Code drop down option if (LocalFolderLocation == String.Empty) { // we need to find out where to create the branch on the file system... FolderBrowserDialog dlg = new FolderBrowserDialog(); InitialiseFolderBrowserDialog(dlg); DialogResult result = dlg.ShowDialog(); if (result != DialogResult.OK) { return false; } LocalFolderLocation = dlg.SelectedPath; if ((Directory.GetDirectories(LocalFolderLocation).GetLength(0) > 0) || (Directory.GetFiles(LocalFolderLocation).GetLength(0) > 0)) { MessageBox.Show("The folder that you selected is not empty. Please choose an empty folder.", Program.APP_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } } BazaarTask task = new BazaarTask(BazaarTask.TaskItem.qbranch); string cmd = task.GetBazaarCommand(); if (txtLaunchpadUserName.Text == String.Empty) { // We need to know the user's ID on Launchpad DlgLaunchpadUserName dlgLaunchpad = new DlgLaunchpadUserName(); dlgLaunchpad.BranchName = LocalFolderLocation.Substring(LocalFolderLocation.LastIndexOf('\\') + 1); if (dlgLaunchpad.ShowDialog() != DialogResult.OK) { return false; } txtLaunchpadUserName.Text = dlgLaunchpad.txtLaunchpadUserName.Text; } string newLaunchpadUrl = linkLabel_LaunchpadUrl.Text.Substring(0, linkLabel_LaunchpadUrl.Text.LastIndexOf('/') + 1); newLaunchpadUrl += LocalFolderLocation.Substring(LocalFolderLocation.LastIndexOf('\\') + 1); System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(cmd); si.Arguments = task.GetBazaarArgs(LocalFolderLocation, newLaunchpadUrl); si.UseShellExecute = false; try { Process p = Process.Start(si); p.WaitForExit(); if (p.ExitCode != 0) { return false; } } catch (Exception ex) { MessageBox.Show("The Assistant failed to launch the first qbranch command. The system error message was: " + ex.Message, Program.APP_TITLE); return false; } // Now we have to do it again with qbranch2 task = new BazaarTask(BazaarTask.TaskItem.qbranch2); si = new System.Diagnostics.ProcessStartInfo(cmd); si.Arguments = task.GetBazaarArgs(LocalFolderLocation, newLaunchpadUrl); si.UseShellExecute = false; try { Process p = Process.Start(si); p.WaitForExit(); if (p.ExitCode != 0) { return false; } } catch (Exception ex) { MessageBox.Show("The Assistant failed to launch the second qbranch command. The system error message was: " + ex.Message, Program.APP_TITLE); return false; } return true; }
private void btnSourceCode_Click(object sender, EventArgs e) { BazaarTask task = new BazaarTask((BazaarTask.TaskItem)cboSourceCode.SelectedIndex + 1); if ((task.Item != BazaarTask.TaskItem.winexplore) && (txtBazaarPath.Text == String.Empty)) { string msg = "The Assistant cannot find the installed location for Bazaar. It was expected to be in the Program Files (86) folder."; msg += " You can select the 'Options' tab and manually browse to the file bzrw.exe. Then try this action again."; MessageBox.Show(msg, Program.APP_TITLE); return; } if (task.Item == BazaarTask.TaskItem.qbranch) { // Special code to handle qbranch because we need two actions for this string tryPath = String.Empty; if (!RunCreateBazaarBranch(ref tryPath)) { return; } if (ValidateBranchPath(ref tryPath)) { string msg = "The branch was created successfully. Do you want to set this as the current branch?"; if (MessageBox.Show(msg, Program.APP_TITLE, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { ChangeBranchLocation(tryPath); } } else { string msg = "A problem occurred while creating the new branch. There is no source code in the target location."; MessageBox.Show(msg, Program.APP_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { // A standard Bazaar or winexplore command is simple... string cmd = task.GetBazaarCommand(); System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(cmd); si.Arguments = task.GetBazaarArgs(BranchLocation, linkLabel_LaunchpadUrl.Text); si.UseShellExecute = false; // OS needs this because we access environment variables si.WorkingDirectory = BranchLocation; bool waitForExit = (si.Arguments.IndexOf("--ui-mode") > 0); try { Process p = Process.Start(si); if (waitForExit) { p.WaitForExit(); } } catch (Exception ex) { MessageBox.Show("The Assistant failed to launch the specified command. The system error message was: " + ex.Message, Program.APP_TITLE); } } }