Main page now allows password input

Group nesting works
This commit is contained in:
2017-09-15 15:58:51 +02:00
parent e97344011d
commit b54fff2502
7 changed files with 103 additions and 29 deletions

View File

@@ -5,33 +5,65 @@ using ModernKeePassLib;
using ModernKeePassLib.Keys;
using ModernKeePassLib.Serialization;
using ModernKeePassLib.Interfaces;
using Windows.UI.Xaml;
using System;
namespace ModernKeePass.ViewModels
{
public class DatabaseVm : INotifyPropertyChanged
{
private PwDatabase _database = new PwDatabase();
private PwDatabase database = new PwDatabase();
private StorageFile databaseFile;
public string Password { get; set; }
public bool IsOpen { get; set; }
public Visibility Visibility { get; private set; }
public string ErrorMessage { get; set; }
public string Name { get; set; }
public GroupVm RootGroup { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public async void Open(StorageFile databaseFile, string password)
public DatabaseVm()
{
Visibility = Visibility.Collapsed;
}
public DatabaseVm(StorageFile databaseFile)
{
this.databaseFile = databaseFile;
Visibility = Visibility.Visible;
}
public async void Open()
{
var key = new CompositeKey();
key.AddUserKey(new KcpPassword(password));
try
{
await _database.Open(IOConnectionInfo.FromFile(databaseFile), key, new NullStatusLogger());
if (!_database.IsOpen) return;
key.AddUserKey(new KcpPassword(Password));
await database.Open(IOConnectionInfo.FromFile(databaseFile), key, new NullStatusLogger());
IsOpen = database.IsOpen;
Name = databaseFile.DisplayName;
RootGroup = new GroupVm (_database.RootGroup);
RootGroup = new GroupVm (database.RootGroup);
}
catch (ArgumentNullException)
{
ErrorMessage = "Password cannot be empty";
NotifyPropertyChanged("ErrorMessage");
}
catch (InvalidCompositeKeyException)
{
ErrorMessage = "Wrong password";
NotifyPropertyChanged("ErrorMessage");
}
finally
{
_database.Close();
// TODO: move this when implementing write mode
database.Close();
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}