2017-10-12 10:36:58 +02:00
|
|
|
|
using System;
|
2017-11-03 15:48:55 +01:00
|
|
|
|
using Windows.Storage.Pickers;
|
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-11-07 18:45:35 +01:00
|
|
|
|
using ModernKeePass.ViewModels;
|
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-11-07 18:50:36 +01:00
|
|
|
|
public sealed partial class CompositeKeyUserControl
|
2017-09-30 09:00:32 -04:00
|
|
|
|
{
|
2017-11-07 18:45:35 +01:00
|
|
|
|
public CompositeKeyVm Model => Grid.DataContext as CompositeKeyVm;
|
2017-11-07 11:45:02 +01: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-11-07 18:50:36 +01:00
|
|
|
|
typeof(CompositeKeyUserControl),
|
2017-10-16 16:16:58 +02:00
|
|
|
|
new PropertyMetadata(false, (o, args) => { }));
|
|
|
|
|
|
2017-11-07 18:45:35 +01:00
|
|
|
|
public bool UpdateKey
|
2017-10-16 16:16:58 +02:00
|
|
|
|
{
|
2017-11-07 18:45:35 +01:00
|
|
|
|
get { return (bool)GetValue(UpdateKeyProperty); }
|
|
|
|
|
set { SetValue(UpdateKeyProperty, value); }
|
2017-10-16 16:16:58 +02:00
|
|
|
|
}
|
2017-11-07 18:45:35 +01:00
|
|
|
|
public static readonly DependencyProperty UpdateKeyProperty =
|
2017-10-16 16:16:58 +02:00
|
|
|
|
DependencyProperty.Register(
|
2017-11-07 18:45:35 +01:00
|
|
|
|
"UpdateKey",
|
|
|
|
|
typeof(bool),
|
2017-11-07 18:50:36 +01:00
|
|
|
|
typeof(CompositeKeyUserControl),
|
2017-11-07 18:45:35 +01:00
|
|
|
|
new PropertyMetadata(false, (o, args) => { }));
|
2017-11-07 11:45:02 +01:00
|
|
|
|
|
2017-11-07 18:45:35 +01:00
|
|
|
|
public bool ShowComplexityIndicator => CreateNew || UpdateKey;
|
2017-11-07 11:45:02 +01:00
|
|
|
|
|
2017-11-07 18:50:36 +01:00
|
|
|
|
public CompositeKeyUserControl()
|
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-11-07 18:45:35 +01:00
|
|
|
|
|
|
|
|
|
if (UpdateKey) Model.UpdateKey();
|
|
|
|
|
else if (Model.OpenDatabase(CreateNew) == DatabaseHelper.DatabaseStatus.Opened)
|
2017-10-24 18:43:46 +02:00
|
|
|
|
{
|
2017-11-07 18:45:35 +01:00
|
|
|
|
ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroup));
|
2017-10-24 18:43:46 +02:00
|
|
|
|
}
|
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-09-30 09:00:32 -04:00
|
|
|
|
}
|
2017-11-03 15:48:55 +01:00
|
|
|
|
|
|
|
|
|
private async void KeyFileButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var picker =
|
|
|
|
|
new FileOpenPicker
|
|
|
|
|
{
|
|
|
|
|
ViewMode = PickerViewMode.List,
|
|
|
|
|
SuggestedStartLocation = PickerLocationId.DocumentsLibrary
|
|
|
|
|
};
|
|
|
|
|
picker.FileTypeFilter.Add(".key");
|
|
|
|
|
|
|
|
|
|
// Application now has read/write access to the picked file
|
2017-11-07 18:45:35 +01:00
|
|
|
|
Model.KeyFile = await picker.PickSingleFileAsync();
|
2017-11-07 11:45:02 +01:00
|
|
|
|
}
|
2017-09-30 09:00:32 -04:00
|
|
|
|
}
|
|
|
|
|
}
|