/// <summary> /// Adds a new password to the password store. /// </summary> private void AddPassword() { if (InvokeRequired) { Invoke((MethodInvoker)AddPassword); return; } var passwordFileName = ShowFileSelectionWindow(); // passwordFileName will be null if no file was selected if (passwordFileName == null) { return; } // Display the password generation window. string password; string extraContent; using (var passwordWindow = new PasswordWindow(Path.GetFileName(passwordFileName))) { passwordWindow.ShowDialog(); if (!passwordWindow.DialogResult.GetValueOrDefault()) { return; } password = passwordWindow.Password.Text; extraContent = passwordWindow.ExtraContent.Text.Replace(Environment.NewLine, "\n"); } try { passwordManager.EncryptPassword(new PasswordFileContent(password, extraContent), passwordFileName + passwordManager.EncryptedFileExtension); } catch (GpgException e) { ShowErrorWindow("Unable to encrypt your password: "******"Unable to encrypt your password: "******"The new password has been copied to your clipboard.\nIt will be cleared in {ConfigManager.Config.ClipboardTimeout:0.##} seconds.", ToolTipIcon.Info); } // Add the password to Git git?.AddPassword(passwordFileName + passwordManager.EncryptedFileExtension); }