示例#1
0
        /// <summary>
        /// Asks the user to selecte a database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OpenDatabaseButton_Click(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();

            picker.FileTypeFilter.Add(".kdbx");

            string databaseName = String.Empty;

            try
            {
                var file = await picker.PickSingleFileAsync();

                if (file != null)
                {
                    databaseName = file.Name;
                    // Ask for password
                    PasswordParameter password = await DatabasePasswordProvider.GetDatabasePasswordAsync(databaseName);

                    // Then load the database
                    await ViewModel.LoadDatabaseAsync(file, password);

                    // Once loaded, navigate to the collection page
                    if (SettingsViewModel.Instance.ViewCollectionAsTree)
                    {
                        this.Frame.Navigate(typeof(EntryCollectionTreeViewPage));
                    }
                    else
                    {
                        this.Frame.Navigate(typeof(EntryCollectionPage));
                    }
                }
            }
            catch (WinKeeLib.Keys.InvalidCompositeKeyException)
            {
                DatabasePasswordProvider.ClearSavedPasswordForDatabase(databaseName);
                MessageDialog err = new MessageDialog(
                    ResourceLoader.GetForCurrentView().GetString("MessageDialog_IncorrectKey"));
                await err.ShowAsync();
            }
            catch (TaskCanceledException)
            {
                // User cancelled password entering
            }
            catch (Exception ex)
            {
                // Error opening the database
                MessageDialog err = new MessageDialog(
                    ResourceLoader.GetForCurrentView().GetString("MessageDialog_ErrorOpeningDatabase") + "\n\"" + ex.Message + "\"");
                await err.ShowAsync();
            }
        }
示例#2
0
        private async Task LoadPreviousDatabaseAsync()
        {
            try
            {
                // Ask for password
                PasswordParameter password = await DatabasePasswordProvider.GetDatabasePasswordAsync(ViewModel.LastDatabaseName);

                // Then load the database
                await ViewModel.LoadPreviouslyOpenedDatabase(password);

                // Once loaded, navigate to the collection page
                if (SettingsViewModel.Instance.ViewCollectionAsTree)
                {
                    this.Frame.Navigate(typeof(EntryCollectionTreeViewPage));
                }
                else
                {
                    this.Frame.Navigate(typeof(EntryCollectionPage));
                }
            }
            catch (WinKeeLib.Keys.InvalidCompositeKeyException)
            {
                // Invalid key, ensure it is not saved
                DatabasePasswordProvider.ClearSavedPasswordForDatabase(ViewModel.LastDatabaseName);
                MessageDialog err = new MessageDialog(
                    ResourceLoader.GetForCurrentView().GetString("MessageDialog_IncorrectKey"));
                await err.ShowAsync();
            }
            catch (TaskCanceledException)
            {
                // User cancelled password entering
            }
            catch (Exception ex)
            {
                // Error opening the database
                MessageDialog err = new MessageDialog(
                    ResourceLoader.GetForCurrentView().GetString("MessageDialog_ErrorOpeningDatabase") + "\n\"" + ex.Message + "\"");
                await err.ShowAsync();
            }
        }