/// <summary> /// Load a list of remote hosts from the registry into the list box /// </summary> private void RefreshRemoteHosts() { listHosts.Items.Clear(); try { string[] keys; using (var reg = Registry.CurrentUser.OpenSubKey(PuTTY_Regkey, false)) { keys = reg.GetValueNames(); } foreach (string key in keys) { ClassUrl.Url url = ClassUrl.Parse(key); // Decipher the registry host format using our URL parse functions, // the fields align in the following way: // Ex. rsa2@22:github.com if (url.Ok) { listHosts.Items.Add(url.Path + " Port: " + url.Host + " Type: " + url.User); } else { listHosts.Items.Add(key); } } listHosts.Tag = keys; // Store list of keys in the listBox tag } catch { } }
/// <summary> /// Test connection to the selected host /// </summary> private void BtTestHostClick(object sender, EventArgs e) { string[] keys = listHosts.Tag as string[]; string key = keys[listHosts.SelectedIndex]; ClassUrl.Url url = ClassUrl.Parse(key); App.Putty.RunPLink(String.Format("-agent git@{0} -P {1}", url.Path, url.Host)); }
/// <summary> /// Text in the input box has changed. Validate it and if it's a valid HTTPS URL, enable the "Add" button /// </summary> private void TextBoxHostTextChanged(object sender, EventArgs e) { // First, a simple test that allows users to paste a clone command textBoxHost.Text = textBoxHost.Text.Replace("git clone ", ""); ClassUrl.Url host = ClassUrl.Parse(textBoxHost.Text); btAddHost.Enabled = host.Type == ClassUrl.UrlType.Https; }
/// <summary> /// Validate entries and return true if they are reasonably valid /// </summary> public bool IsValid() { _fetchUrl = ClassUrl.Parse(textUrlFetch.Text.Trim()); _pushUrl = ClassUrl.Parse(textUrlPush.Text.Trim()); // Consider valid entry if the name is ok and some combination of urls return(textName.Text.Trim().Length > 0 && _fetchUrl.Type != ClassUrl.UrlType.Unknown); }
/// <summary> /// Initializes SSH connection by running the PLINK using the specified /// connection parameters. This function blocks until the PLINK returns. /// </summary> public void ImportRemoteSshKey(ClassUrl.Url url) { // Build the arguments to the PLINK process: port number, user and the host // Use the default SSH values if the url did not provide them string args = " -P " + (url.Port > 0 ? url.Port.ToString() : "22") + " -l " + (string.IsNullOrEmpty(url.User) ? "anonymous" : url.User) + " " + url.Host; // plink does everything through its stderr stream ExecResult result = Exec.Run(pathPlink, args); App.PrintLogMessage(result.stderr, MessageType.Error); }
/// <summary> /// User clicked on the "web" button to the left of the git repo address. /// Find the canonical web site and open it /// </summary> private void BtWwwClick(object sender, EventArgs e) { string key = ((Button)sender).Tag.ToString(); ClassUrl.Url url = key == "Fetch" ? _fetchUrl : _pushUrl; // Find a generic host name string target = "http://" + url.Host; // Detect some special hosts for which we can form a complete path if (url.Host.Contains("github")) { target += "/" + url.Path; } if (url.Host.Contains(".code.sf.net")) { target = "https://sourceforge.net/projects/" + url.Name; } ClassUtils.OpenWebLink(target); }
/// <summary> /// Disable or enable Add Host button based on the validity of the host address /// </summary> private void TextBoxHostTextChanged(object sender, EventArgs e) { remoteUrl = ClassUrl.Parse(textBoxHost.Text); btAddHost.Enabled = textBoxHost.Text.Length > 0 && remoteUrl.Type == ClassUrl.UrlType.Ssh; }
/// <summary> /// Validate entries and return true if they are reasonably valid /// </summary> public bool IsValid() { _fetchUrl = ClassUrl.Parse(textUrlFetch.Text.Trim()); _pushUrl = ClassUrl.Parse(textUrlPush.Text.Trim()); // Consider valid entry if the name is ok and some combination of urls return textName.Text.Trim().Length > 0 && _fetchUrl.Type != ClassUrl.UrlType.Unknown; }
/// <summary> /// User clicked on the Add host button, prompt for user name and password and then add it /// </summary> private void BtAddHostClick(object sender, EventArgs e) { // We assume the URL in the text box is a well formatted HTTPS string since Add button would not be enabled otherwise ClassUrl.Url host = ClassUrl.Parse(textBoxHost.Text.Trim()); AddEdit(host.Host); // Use only the host part of the address }
/// <summary> /// Checks the given web target link and returns true if it is reasonably valid URL /// </summary> private bool isValidUrl(string target) { ClassUrl.Url url = ClassUrl.Parse(target.Trim()); return(url.Ok); }