2017-09-27 18:01:21 +02:00
|
|
|
|
using System;
|
|
|
|
|
using Windows.Storage.Pickers;
|
2017-09-29 18:08:20 +02:00
|
|
|
|
using Windows.System;
|
2017-09-27 18:01:21 +02:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
2017-09-29 18:08:20 +02:00
|
|
|
|
using Windows.UI.Xaml.Input;
|
2017-09-27 18:01:21 +02:00
|
|
|
|
using Windows.UI.Xaml.Navigation;
|
|
|
|
|
using ModernKeePass.Common;
|
|
|
|
|
using ModernKeePass.ViewModels;
|
2017-09-29 17:23:35 -04:00
|
|
|
|
using Windows.Storage.AccessCache;
|
|
|
|
|
using Windows.Storage;
|
2017-09-27 18:01:21 +02:00
|
|
|
|
|
|
|
|
|
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Pages
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// An empty page that can be used on its own or navigated to within a Frame.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed partial class OpenDatabasePage : Page
|
|
|
|
|
{
|
|
|
|
|
private Frame _mainFrame;
|
|
|
|
|
|
|
|
|
|
public OpenDatabasePage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnNavigatedTo(NavigationEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnNavigatedTo(e);
|
|
|
|
|
_mainFrame = e.Parameter as Frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var picker =
|
|
|
|
|
new FileOpenPicker
|
|
|
|
|
{
|
|
|
|
|
ViewMode = PickerViewMode.List,
|
|
|
|
|
SuggestedStartLocation = PickerLocationId.DocumentsLibrary
|
|
|
|
|
};
|
|
|
|
|
picker.FileTypeFilter.Add(".kdbx");
|
|
|
|
|
|
|
|
|
|
var file = await picker.PickSingleFileAsync();
|
|
|
|
|
// Application now has read/write access to the picked file
|
2017-09-29 17:23:35 -04:00
|
|
|
|
if (file == null) return;
|
|
|
|
|
// Initialize KDBX database
|
2017-09-27 18:01:21 +02:00
|
|
|
|
((App)Application.Current).Database = new DatabaseHelper(file);
|
2017-09-29 17:23:35 -04:00
|
|
|
|
AddToRecentFiles(file);
|
|
|
|
|
ShowPassword(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddToRecentFiles(StorageFile file)
|
|
|
|
|
{
|
|
|
|
|
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
|
|
|
|
var mruToken = mru.Add(file, file.DisplayName);
|
|
|
|
|
|
|
|
|
|
/*var localSettings = ApplicationData.Current.LocalSettings;
|
|
|
|
|
if (!localSettings.Containers.ContainsKey("Recent"))
|
|
|
|
|
localSettings.CreateContainer("Recent", ApplicationDataCreateDisposition.Always);
|
|
|
|
|
|
|
|
|
|
localSettings.Containers["Recent"].Values[file.DisplayName] = mruToken;*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowPassword(StorageFile file)
|
|
|
|
|
{
|
2017-09-27 18:01:21 +02:00
|
|
|
|
var databaseVm = DataContext as DatabaseVm;
|
|
|
|
|
if (databaseVm == null) return;
|
|
|
|
|
databaseVm.SelectedVisibility = Visibility.Visible;
|
|
|
|
|
databaseVm.Name = file.Name;
|
|
|
|
|
databaseVm.NotifyPropertyChanged("SelectedVisibility");
|
|
|
|
|
databaseVm.NotifyPropertyChanged("Name");
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-01 08:48:29 -04:00
|
|
|
|
private void PasswordUserControl_PasswordChecked(object sender, Events.DatabaseEventArgs e)
|
2017-09-27 18:01:21 +02:00
|
|
|
|
{
|
|
|
|
|
var app = (App)Application.Current;
|
2017-10-01 08:48:29 -04:00
|
|
|
|
if (e.IsOpen) _mainFrame.Navigate(typeof(GroupDetailPage), app.Database.RootGroup);
|
2017-09-29 18:08:20 +02:00
|
|
|
|
}
|
2017-09-27 18:01:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|