mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Re-enabled write mode in KeePassLib
Set database as part of App (so, Singleton) Changed main page view model WIP and testing saving mechanism
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
using Windows.Storage;
|
||||
|
||||
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 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 DatabaseVm()
|
||||
{
|
||||
Visibility = Visibility.Collapsed;
|
||||
}
|
||||
public DatabaseVm(StorageFile databaseFile)
|
||||
{
|
||||
this.databaseFile = databaseFile;
|
||||
Visibility = Visibility.Visible;
|
||||
}
|
||||
public async void Open()
|
||||
{
|
||||
var key = new CompositeKey();
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
ErrorMessage = "Password cannot be empty";
|
||||
NotifyPropertyChanged("ErrorMessage");
|
||||
}
|
||||
catch (InvalidCompositeKeyException)
|
||||
{
|
||||
ErrorMessage = "Wrong password";
|
||||
NotifyPropertyChanged("ErrorMessage");
|
||||
}
|
||||
finally
|
||||
{
|
||||
// TODO: move this when implementing write mode
|
||||
database.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public void NotifyPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,6 +7,8 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class GroupVm : INotifyPropertyChanged
|
||||
{
|
||||
private PwGroup _pwGroup;
|
||||
|
||||
public ObservableCollection<EntryVm> Entries { get; set; }
|
||||
public ObservableCollection<GroupVm> Groups { get; set; }
|
||||
public string Name { get; set; }
|
||||
@@ -35,11 +37,23 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public GroupVm(PwGroup group)
|
||||
{
|
||||
_pwGroup = group;
|
||||
Name = group.Name;
|
||||
Entries = new ObservableCollection<EntryVm>(group.Entries.Select(e => new EntryVm(e)));
|
||||
Groups = new ObservableCollection<GroupVm>(group.Groups.Select(g => new GroupVm(g)));
|
||||
}
|
||||
|
||||
public void AddGroup(string title)
|
||||
{
|
||||
var pwGroup = new PwGroup
|
||||
{
|
||||
Name = title
|
||||
};
|
||||
Groups.Add(new GroupVm(pwGroup));
|
||||
NotifyPropertyChanged("Groups");
|
||||
this._pwGroup.Groups.Add(pwGroup);
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void NotifyPropertyChanged(string propertyName)
|
||||
|
30
ModernKeePass/ViewModels/HomeVm.cs
Normal file
30
ModernKeePass/ViewModels/HomeVm.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.ComponentModel;
|
||||
using Windows.Storage;
|
||||
|
||||
using ModernKeePassLib;
|
||||
using ModernKeePassLib.Keys;
|
||||
using ModernKeePassLib.Serialization;
|
||||
using ModernKeePassLib.Interfaces;
|
||||
using Windows.UI.Xaml;
|
||||
using System;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class HomeVm : INotifyPropertyChanged
|
||||
{
|
||||
public string Password { get; set; }
|
||||
public Visibility Visibility { get; set; }
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
public HomeVm()
|
||||
{
|
||||
Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public void NotifyPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user