2017-10-12 10:36:58 +02:00
|
|
|
|
using System;
|
2017-10-02 10:44:04 +02:00
|
|
|
|
using Windows.System;
|
2017-09-30 09:00:32 -04:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
using Windows.UI.Xaml.Input;
|
2017-10-10 15:00:31 +02:00
|
|
|
|
using ModernKeePass.Common;
|
|
|
|
|
using ModernKeePass.Events;
|
2017-09-30 09:00:32 -04:00
|
|
|
|
|
|
|
|
|
// Pour en savoir plus sur le modèle d'élément Contrôle utilisateur, consultez la page http://go.microsoft.com/fwlink/?LinkId=234236
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Controls
|
|
|
|
|
{
|
2017-10-12 17:45:37 +02:00
|
|
|
|
public sealed partial class OpenDatabaseUserControl
|
2017-09-30 09:00:32 -04:00
|
|
|
|
{
|
2017-10-11 18:43:27 +02:00
|
|
|
|
public bool CreateNew
|
2017-10-11 14:30:07 +02:00
|
|
|
|
{
|
2017-10-11 18:43:27 +02:00
|
|
|
|
get { return (bool)GetValue(CreateNewProperty); }
|
|
|
|
|
set { SetValue(CreateNewProperty, value); }
|
2017-10-11 14:30:07 +02:00
|
|
|
|
}
|
2017-10-11 18:43:27 +02:00
|
|
|
|
public static readonly DependencyProperty CreateNewProperty =
|
2017-10-11 14:30:07 +02:00
|
|
|
|
DependencyProperty.Register(
|
2017-10-11 18:43:27 +02:00
|
|
|
|
"CreateNew",
|
|
|
|
|
typeof(bool),
|
2017-10-11 14:30:07 +02:00
|
|
|
|
typeof(OpenDatabaseUserControl),
|
2017-10-16 16:16:58 +02:00
|
|
|
|
new PropertyMetadata(false, (o, args) => { }));
|
|
|
|
|
|
|
|
|
|
public string Password
|
|
|
|
|
{
|
|
|
|
|
get { return (string)GetValue(PasswordProperty); }
|
|
|
|
|
set { SetValue(PasswordProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty PasswordProperty =
|
|
|
|
|
DependencyProperty.Register(
|
|
|
|
|
"Password",
|
|
|
|
|
typeof(string),
|
|
|
|
|
typeof(OpenDatabaseUserControl),
|
|
|
|
|
new PropertyMetadata(string.Empty, (o, args) => { }));
|
2017-10-11 14:30:07 +02:00
|
|
|
|
|
2017-10-02 10:44:04 +02:00
|
|
|
|
public OpenDatabaseUserControl()
|
2017-09-30 09:00:32 -04:00
|
|
|
|
{
|
2017-10-01 08:48:29 -04:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-12 10:36:58 +02:00
|
|
|
|
public event PasswordCheckingEventHandler ValidationChecking;
|
|
|
|
|
public delegate void PasswordCheckingEventHandler(object sender, EventArgs e);
|
2017-10-02 10:44:04 +02:00
|
|
|
|
public event PasswordCheckedEventHandler ValidationChecked;
|
2017-10-10 15:00:31 +02:00
|
|
|
|
public delegate void PasswordCheckedEventHandler(object sender, PasswordEventArgs e);
|
2017-10-01 08:48:29 -04:00
|
|
|
|
|
|
|
|
|
private void OpenButton_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2017-10-12 10:36:58 +02:00
|
|
|
|
ValidationChecking?.Invoke(this, new EventArgs());
|
2017-10-01 08:48:29 -04:00
|
|
|
|
var app = (App)Application.Current;
|
2017-10-11 18:43:27 +02:00
|
|
|
|
StatusTextBlock.Text = app.Database.Open(PasswordBox.Password, CreateNew);
|
2017-10-10 15:00:31 +02:00
|
|
|
|
if (app.Database.Status == DatabaseHelper.DatabaseStatus.Opened)
|
2017-10-20 20:02:52 +02:00
|
|
|
|
{
|
2017-10-10 15:00:31 +02:00
|
|
|
|
ValidationChecked?.Invoke(this, new PasswordEventArgs(app.Database.RootGroup));
|
2017-10-20 20:02:52 +02:00
|
|
|
|
}
|
2017-10-24 18:43:46 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VisualStateManager.GoToState(PasswordBox, "Error", true);
|
|
|
|
|
}
|
2017-10-01 08:48:29 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PasswordBox_KeyDown(object sender, KeyRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Key == VirtualKey.Enter) OpenButton_OnClick(null, null);
|
2017-10-24 18:43:46 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VisualStateManager.GoToState(PasswordBox, "Normal", true);
|
|
|
|
|
StatusTextBlock.Text = string.Empty;
|
|
|
|
|
}
|
2017-09-30 09:00:32 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|