diff --git a/src/KeyKeeper/Views/CreateVaultDialog.axaml b/src/KeyKeeper/Views/CreateVaultDialog.axaml
index dd8dea5..4d00fa8 100644
--- a/src/KeyKeeper/Views/CreateVaultDialog.axaml
+++ b/src/KeyKeeper/Views/CreateVaultDialog.axaml
@@ -1,22 +1,19 @@
-
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/src/KeyKeeper/Views/CreateVaultDialog.axaml.cs b/src/KeyKeeper/Views/CreateVaultDialog.axaml.cs
index fdc9d53..d56b0b4 100644
--- a/src/KeyKeeper/Views/CreateVaultDialog.axaml.cs
+++ b/src/KeyKeeper/Views/CreateVaultDialog.axaml.cs
@@ -3,13 +3,13 @@ using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using System;
-using System.IO;
namespace KeyKeeper.Views
{
public partial class CreateVaultFileWindow : Window
{
public string FilePath { get; private set; } = string.Empty;
+ public string Password { get; private set; } = string.Empty;
public bool Success { get; private set; }
public CreateVaultFileWindow()
@@ -19,20 +19,22 @@ namespace KeyKeeper.Views
this.AttachDevTools();
#endif
FilePathTextBox.TextChanged += OnTextChanged;
+ PasswordBox.TextChanged += OnPasswordTextChanged;
+ ConfirmPasswordBox.TextChanged += OnPasswordTextChanged;
}
- private async void OnTextChanged(object? sender, TextChangedEventArgs e)
+ private void OnTextChanged(object? sender, TextChangedEventArgs e)
{
- string path = FilePathTextBox.Text ?? "";
- CreateButton.IsEnabled = !string.IsNullOrWhiteSpace(path);
+ UpdateCreateButtonState();
PathWarning.Text = "";
+ string path = FilePathTextBox.Text ?? "";
if (string.IsNullOrWhiteSpace(path))
return;
try
{
- var storageFile = await StorageProvider.TryGetFileFromPathAsync(path);
+ var storageFile = StorageProvider.TryGetFileFromPathAsync(path).GetAwaiter().GetResult();
if (storageFile != null)
{
PathWarning.Text = "File already exists. It will be overwritten.";
@@ -43,6 +45,20 @@ namespace KeyKeeper.Views
}
}
+ private void OnPasswordTextChanged(object? sender, TextChangedEventArgs e)
+ {
+ UpdateCreateButtonState();
+ PasswordErrorText.IsVisible = false;
+ }
+
+ private void UpdateCreateButtonState()
+ {
+ bool pathValid = !string.IsNullOrWhiteSpace(FilePathTextBox.Text);
+ bool passwordsEntered = !string.IsNullOrWhiteSpace(PasswordBox.Text) &&
+ !string.IsNullOrWhiteSpace(ConfirmPasswordBox.Text);
+ CreateButton.IsEnabled = pathValid && passwordsEntered;
+ }
+
private async void BrowseButton_Click(object? sender, RoutedEventArgs e)
{
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
@@ -59,7 +75,7 @@ namespace KeyKeeper.Views
}
});
- if (file != null && file.TryGetLocalPath() is string path)
+ if (file?.TryGetLocalPath() is string path)
{
FilePathTextBox.Text = path;
}
@@ -67,13 +83,37 @@ namespace KeyKeeper.Views
private void CreateButton_Click(object? sender, RoutedEventArgs e)
{
- FilePath = FilePathTextBox.Text ?? "";
- if (string.IsNullOrWhiteSpace(FilePath)) return;
+ string path = FilePathTextBox.Text ?? "";
+ if (string.IsNullOrWhiteSpace(path))
+ return;
+ string password = PasswordBox.Text ?? "";
+ string confirm = ConfirmPasswordBox.Text ?? "";
+
+ if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(confirm))
+ {
+ ShowPasswordError("Password cannot be empty");
+ return;
+ }
+
+ if (password != confirm)
+ {
+ ShowPasswordError("Passwords don't match");
+ return;
+ }
+
+ FilePath = path;
+ Password = password;
Success = true;
Close();
}
+ private void ShowPasswordError(string message)
+ {
+ PasswordErrorText.Text = message;
+ PasswordErrorText.IsVisible = true;
+ }
+
private void CancelButton_Click(object? sender, RoutedEventArgs e)
{
Success = false;
diff --git a/src/KeyKeeper/Views/MainWindow.axaml.cs b/src/KeyKeeper/Views/MainWindow.axaml.cs
index e6d8872..ee8549a 100644
--- a/src/KeyKeeper/Views/MainWindow.axaml.cs
+++ b/src/KeyKeeper/Views/MainWindow.axaml.cs
@@ -22,28 +22,26 @@ namespace KeyKeeper.Views
private async void CreateNewVault_Click(object sender, RoutedEventArgs e)
{
- var fileDialog = new CreateVaultFileWindow();
- await fileDialog.ShowDialog(this);
+ var createVaultDialog = new CreateVaultFileWindow();
+ await createVaultDialog.ShowDialog(this);
- if (fileDialog.Success && !string.IsNullOrEmpty(fileDialog.FilePath))
+ if (createVaultDialog.Success &&
+ !string.IsNullOrEmpty(createVaultDialog.FilePath) &&
+ !string.IsNullOrEmpty(createVaultDialog.Password))
{
- var path = fileDialog.FilePath;
- var passwordDialog = new PasswordDialog();
- await passwordDialog.ShowDialog(this);
- if (passwordDialog.Created && !string.IsNullOrEmpty(passwordDialog.Password))
- {
- var compositeKey = new CompositeKey(passwordDialog.Password, null);
- var passStoreAccessor = new PassStoreFileAccessor(
- filename: path,
- create: true,
- createOptions: new StoreCreationOptions()
- {
- Key = compositeKey,
- LockTimeoutSeconds = 800
- });
- IPassStore passStore = passStoreAccessor;
- OpenRepositoryWindow(passStore);
- }
+ var path = createVaultDialog.FilePath;
+ var password = createVaultDialog.Password;
+ var compositeKey = new CompositeKey(password, null);
+ var passStoreAccessor = new PassStoreFileAccessor(
+ filename: path,
+ create: true,
+ createOptions: new StoreCreationOptions()
+ {
+ Key = compositeKey,
+ LockTimeoutSeconds = 800
+ });
+ IPassStore passStore = passStoreAccessor;
+ OpenRepositoryWindow(passStore);
}
}
diff --git a/src/KeyKeeper/Views/PasswordDialog.axaml b/src/KeyKeeper/Views/PasswordDialog.axaml
deleted file mode 100644
index 27b58c2..0000000
--- a/src/KeyKeeper/Views/PasswordDialog.axaml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/KeyKeeper/Views/PasswordDialog.axaml.cs b/src/KeyKeeper/Views/PasswordDialog.axaml.cs
deleted file mode 100644
index 7e15c00..0000000
--- a/src/KeyKeeper/Views/PasswordDialog.axaml.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Markup.Xaml;
-using Avalonia.Interactivity;
-
-namespace KeyKeeper.Views
-{
- public partial class PasswordDialog : Window
- {
- public string Password { get; private set; } = "";
- public bool Created { get; private set; } = false;
-
- public PasswordDialog()
- {
- InitializeComponent();
- }
-
- private void InitializeComponent()
- {
- AvaloniaXamlLoader.Load(this);
- }
-
- private void CreateButton_Click(object sender, RoutedEventArgs e)
- {
- var passwordBox = this.FindControl("PasswordBox");
- var confirmBox = this.FindControl("ConfirmPasswordBox");
- var errorText = this.FindControl("ErrorText");
-
- string password = passwordBox?.Text ?? "";
- string confirmPassword = confirmBox?.Text ?? "";
-
- if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(confirmPassword))
- {
- ShowError("Password cannot be empty");
- return;
- }
-
- if (password != confirmPassword)
- {
- ShowError("Passwords don't match");
- return;
- }
-
- Password = password;
- Created = true;
- Close();
- }
-
- private void ShowError(string message)
- {
- var errorText = this.FindControl("ErrorText");
- if (errorText != null)
- {
- errorText.Text = message;
- errorText.IsVisible = true;
- }
- }
-
- private void CancelButton_Click(object sender, RoutedEventArgs e)
- {
- Created = false;
- Close();
- }
- }
-}