예제 #1
0
 private void EnsurePageant(string remote)
 {
     if (GitSshHelpers.Plink())
     {
         StartPageant(remote);
     }
 }
예제 #2
0
        public static void StartAgent([NotNull] IWin32Window owner, [NotNull] IGitModule module, [NotNull] string remote)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (module == null)
            {
                throw new ArgumentNullException(nameof(module));
            }

            if (remote == null)
            {
                throw new ArgumentNullException(nameof(remote));
            }

            if (GitSshHelpers.Plink())
            {
                if (!File.Exists(AppSettings.Pageant))
                {
                    MessageBoxes.PAgentNotFound(owner);
                }
                else
                {
                    module.StartPageantForRemote(remote);
                }
            }
        }
예제 #3
0
 private void FormCloneLoad(object sender, EventArgs e)
 {
     if (!GitSshHelpers.Plink())
     {
         LoadSSHKey.Visible = false;
     }
 }
        protected override void SettingsToPage()
        {
            PlinkPath.Text           = AppSettings.Plink;
            PuttygenPath.Text        = AppSettings.Puttygen;
            PageantPath.Text         = AppSettings.Pageant;
            AutostartPageant.Checked = AppSettings.AutoStartPageant;

            var sshPath = AppSettings.SshPath;

            if (string.IsNullOrEmpty(sshPath))
            {
                OpenSSH.Checked = true;
            }
            else if (GitSshHelpers.Plink())
            {
                Putty.Checked = true;
            }
            else
            {
                OtherSsh.Text = sshPath;
                Other.Checked = true;
            }

            EnableSshOptions();
        }
예제 #5
0
        private void application_Idle(object sender, EventArgs e)
        {
            // we need this event only once, so unwire
            Application.Idle -= application_Idle;

            // make sure only single load option is given
            if (PreselectRemoteOnLoad is not null && PreselectLocalOnLoad is not null)
            {
                throw new ArgumentException($"Only one option allowed:" +
                                            $" Either {nameof(PreselectRemoteOnLoad)} or {nameof(PreselectLocalOnLoad)}");
            }

            pnlMgtPuttySsh.Visible = GitSshHelpers.Plink();

            // if Putty SSH isn't enabled, reduce the minimum height of the form
            MinimumSize = new Size(MinimumSize.Width, pnlMgtPuttySsh.Visible ? MinimumSize.Height : MinimumSize.Height - pnlMgtPuttySsh.Height);

            // adjust width of the labels if required
            // this may be necessary if the translated labels require more space than English versions
            // the longest label is likely to be label3 (Private key file), so use it as a guide
            var widestLabelMinSize = new Size(label3.Width, 0);

            label1.MinimumSize       = label1.MaximumSize = widestLabelMinSize;       // Name
            label2.MinimumSize       = label2.MaximumSize = widestLabelMinSize;       // Url
            labelPushUrl.MinimumSize = labelPushUrl.MaximumSize = widestLabelMinSize; // Push URL

            _remotesManager = new ConfigFileRemoteSettingsManager(() => Module);

            // load the data for the very first time
            Initialize(PreselectRemoteOnLoad, PreselectLocalOnLoad);
        }
예제 #6
0
        private void LoadPuttyKey()
        {
            if (!GitSshHelpers.Plink())
            {
                return;
            }

            if (File.Exists(AppSettings.Pageant))
            {
                var files = new HashSet <string>(new PathEqualityComparer());
                foreach (var remote in GetSelectedRemotes())
                {
                    var sshKeyFile = Module.GetPuttyKeyFileForRemote(remote);
                    if (!string.IsNullOrEmpty(sshKeyFile))
                    {
                        files.Add(sshKeyFile);
                    }
                }

                foreach (var sshKeyFile in files)
                {
                    if (File.Exists(sshKeyFile))
                    {
                        GitModule.StartPageantWithKey(sshKeyFile);
                    }
                }
            }
            else
            {
                MessageBoxes.PAgentNotFound(this);
            }

            return;

            IEnumerable <string> GetSelectedRemotes()
            {
                if (PullFromUrl.Checked)
                {
                    yield break;
                }

                if (IsPullAll())
                {
                    foreach (var remote in (IEnumerable <ConfigFileRemote>)_NO_TRANSLATE_Remotes.DataSource)
                    {
                        if (!string.IsNullOrWhiteSpace(remote.Name) && remote.Name != AllRemotes)
                        {
                            yield return(remote.Name);
                        }
                    }
                }
                else if (!string.IsNullOrWhiteSpace(_NO_TRANSLATE_Remotes.Text))
                {
                    yield return(_NO_TRANSLATE_Remotes.Text);
                }
            }
        }
 private void SshConfig_Click(object sender, EventArgs e)
 {
     if (GitSshHelpers.Plink())
     {
         if (SshSettingsPage.AutoFindPuttyPaths())
         {
             MessageBox.Show(this, _puttyFoundAuto.Text, _putty, MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             PageHost.GotoPage(SshSettingsPage.GetPageReference());
         }
     }
 }
예제 #8
0
 private void EnsurePageant(string remote)
 {
     if (GitSshHelpers.Plink())
     {
         if (!File.Exists(AppSettings.Pageant))
         {
             MessageBoxes.PAgentNotFound(this);
         }
         else
         {
             Module.StartPageantForRemote(remote);
         }
     }
 }
        private bool CheckSSHSettings()
        {
            SshConfig.Visible = true;
            if (GitSshHelpers.Plink())
            {
                return(RenderSettingSetUnset(() => !File.Exists(AppSettings.Plink) || !File.Exists(AppSettings.Puttygen) || !File.Exists(AppSettings.Pageant),
                                             SshConfig, SshConfig_Fix,
                                             _plinkputtyGenpageantNotFound.Text,
                                             _puttyConfigured.Text));
            }

            var ssh = _sshPathLocator.Find(AppSettings.GitBinDir);

            RenderSettingSet(SshConfig, SshConfig_Fix, string.IsNullOrEmpty(ssh) ? _opensshUsed.Text : string.Format(_unknownSshClient.Text, ssh));
            return(true);
        }
        public void Initialize(ITelemetry telemetry)
        {
            string sshClient;
            var    sshPath = _sshPathLocator.Find(AppSettings.GitBinDir);

            if (string.IsNullOrEmpty(sshPath))
            {
                sshClient = "OpenSSH";
            }
            else if (GitSshHelpers.Plink())
            {
                sshClient = "PuTTY";
            }
            else
            {
                sshClient = "Other";
            }

            telemetry.Context.GlobalProperties["Git"]      = GitVersion.Current.ToString();
            telemetry.Context.GlobalProperties["SSH"]      = sshClient;
            telemetry.Context.GlobalProperties["SSH.Path"] = sshPath;
        }
예제 #11
0
        public static async Task <string> RunGerritCommandAsync([NotNull] IWin32Window owner, [NotNull] IGitModule module, [NotNull] string command, [NotNull] Uri fetchUrl, [NotNull] string remote, byte[] stdIn)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (module == null)
            {
                throw new ArgumentNullException(nameof(module));
            }

            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (fetchUrl == null)
            {
                throw new ArgumentNullException(nameof(fetchUrl));
            }

            if (remote == null)
            {
                throw new ArgumentNullException(nameof(remote));
            }

            StartAgent(owner, module, remote);

            var sshCmd = GitSshHelpers.Plink()
                ? AppSettings.Plink
                : SshPathLocatorInstance.Find(AppSettings.GitBinDir);

            if (string.IsNullOrEmpty(sshCmd))
            {
                sshCmd = "ssh.exe";
            }

            string hostname = fetchUrl.Host;
            string username = fetchUrl.UserInfo;
            string portFlag = GitSshHelpers.Plink() ? " -P " : " -p ";
            int    port     = fetchUrl.Port;

            if (port == -1 && fetchUrl.Scheme == "ssh")
            {
                port = 22;
            }

            var sb = new StringBuilder();

            sb.Append('"');

            if (!string.IsNullOrEmpty(username))
            {
                sb.Append(username);
                sb.Append('@');
            }

            sb.Append(hostname);
            sb.Append('"');
            sb.Append(portFlag);
            sb.Append(port);

            sb.Append(" \"");
            sb.Append(command);
            sb.Append("\"");

            return(await new Executable(sshCmd)
                   .GetOutputAsync(sb.ToString(), stdIn).ConfigureAwait(false));
        }
예제 #12
0
 protected override void BeforeProcessStart()
 {
     _restart = false;
     Plink    = GitSshHelpers.Plink();
     base.BeforeProcessStart();
 }