2020-04-20 20:02:43 +02:00
|
|
|
|
using System;
|
|
|
|
|
using Windows.Storage.AccessCache;
|
|
|
|
|
using Windows.Storage.Pickers;
|
|
|
|
|
using Windows.System;
|
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
using Windows.UI.Xaml.Input;
|
2020-04-21 17:13:39 +02:00
|
|
|
|
using GalaSoft.MvvmLight.Messaging;
|
|
|
|
|
using Messages;
|
2020-04-20 20:02:43 +02:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using ModernKeePass.ViewModels;
|
|
|
|
|
|
|
|
|
|
// 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.Views.UserControls
|
|
|
|
|
{
|
|
|
|
|
public sealed partial class OpenDatabaseUserControl
|
|
|
|
|
{
|
|
|
|
|
public OpenDatabaseControlVm Model => Grid.DataContext as OpenDatabaseControlVm;
|
|
|
|
|
|
|
|
|
|
public string DatabaseFilePath
|
|
|
|
|
{
|
|
|
|
|
get { return (string)GetValue(DatabaseFilePathProperty); }
|
|
|
|
|
set { SetValue(DatabaseFilePathProperty, value); }
|
|
|
|
|
}
|
|
|
|
|
public static readonly DependencyProperty DatabaseFilePathProperty =
|
|
|
|
|
DependencyProperty.Register(
|
|
|
|
|
nameof(DatabaseFilePath),
|
|
|
|
|
typeof(string),
|
|
|
|
|
typeof(OpenDatabaseUserControl),
|
|
|
|
|
new PropertyMetadata(null, (o, args) => { }));
|
|
|
|
|
|
2020-04-21 17:13:39 +02:00
|
|
|
|
public OpenDatabaseUserControl() : this(App.Services.GetRequiredService<IMessenger>()) { }
|
2020-04-20 20:02:43 +02:00
|
|
|
|
|
2020-04-21 17:13:39 +02:00
|
|
|
|
public OpenDatabaseUserControl(IMessenger messenger)
|
2020-04-20 20:02:43 +02:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2020-04-21 17:13:39 +02:00
|
|
|
|
messenger.Register<DatabaseClosedMessage>(this, async action => await Model.OpenDatabase(DatabaseFilePath));
|
2020-04-20 20:02:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-21 17:13:39 +02:00
|
|
|
|
private async void PasswordBox_KeyDown(object sender, KeyRoutedEventArgs e)
|
2020-04-20 20:02:43 +02:00
|
|
|
|
{
|
|
|
|
|
if (e.Key != VirtualKey.Enter || !Model.IsValid) return;
|
2020-04-21 17:13:39 +02:00
|
|
|
|
await Model.TryOpenDatabase(DatabaseFilePath);
|
2020-04-20 20:02:43 +02:00
|
|
|
|
// Stop the event from triggering twice
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void KeyFileButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var picker = new FileOpenPicker
|
|
|
|
|
{
|
|
|
|
|
ViewMode = PickerViewMode.List,
|
|
|
|
|
SuggestedStartLocation = PickerLocationId.DocumentsLibrary
|
|
|
|
|
};
|
|
|
|
|
picker.FileTypeFilter.Add("*");
|
|
|
|
|
|
|
|
|
|
// Application now has read/write access to the picked file
|
|
|
|
|
var file = await picker.PickSingleFileAsync();
|
|
|
|
|
if (file == null) return;
|
|
|
|
|
|
|
|
|
|
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
|
|
|
|
Model.KeyFilePath = token;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|