private bool CheckSaveChanges() { if (repository?.Changed == true) { Console.WriteLine("The repository has been changed."); var answer = AskYesNoCancelQuestion("Do you want to save the changes?", Answer.Yes); if (answer == Answer.Yes) { repository.Save(repositoryFileName, keyDirectory, repositoryPassword); return(true); } if (answer == Answer.Cancel) { return(false); } } return(true); }
private void NewRepositoryCommand(List <Shell.ParseResult> result) { if (result.Count < 2) { Console.WriteLine("Missing <file> argument."); return; } if (File.Exists(result[1].Input)) { Console.WriteLine("Password repository file already exists."); return; } if (repository != null) { Console.WriteLine("Repository has not been closed."); return; } repositoryFileName = Path.GetFullPath(result[1].Input); if (result.Count > 2) { keyDirectory = Path.GetFullPath(result[2].Input); if (!Directory.Exists(keyDirectory)) { Console.WriteLine("Key directory does not exist."); return; } } else { keyDirectory = Path.GetDirectoryName(repositoryFileName); } var cr = new ConsoleReader(); cr.Prefix = "Name: "; var name = cr.Read(Path.GetFileNameWithoutExtension(repositoryFileName)); cr.Prefix = "Description: "; var desc = cr.Read(); cr.Prefix = "Master Password: "******"Aborted."); return; } while (true) { cr.Prefix = "Confirm Master Password: "******"Aborted."); return; } if (confirm.IsEqualTo(repositoryPassword)) { break; } Console.WriteLine("Passwords do not match."); } if (AskYesNoQuestion("Do you want to create the repository?") == Answer.Yes) { repository = new PasswordRepository(); repository.Name = name; repository.Description = desc; repository.Save(repositoryFileName, keyDirectory, repositoryPassword); Console.WriteLine("Repository created."); } }