mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-04 08:00:16 -04:00
Changed most services to singletons
Refactor the Database Service (no more enum, ...) Restored the Donate page with Paypal web page Added (but not working) MS App Center integration Corrected tests accordingly WIP AOP to detect database changes
This commit is contained in:
@@ -22,7 +22,7 @@ namespace ModernKeePass.ViewModels
|
||||
Success = 5
|
||||
}
|
||||
|
||||
public IDatabase Database { get; set; }
|
||||
public IDatabaseService Database { get; set; }
|
||||
|
||||
public bool HasPassword
|
||||
{
|
||||
@@ -111,11 +111,11 @@ namespace ModernKeePass.ViewModels
|
||||
private StatusTypes _statusType;
|
||||
private StorageFile _keyFile;
|
||||
private string _keyFileText;
|
||||
private readonly IResource _resource;
|
||||
private readonly IResourceService _resource;
|
||||
|
||||
public CompositeKeyVm() : this((Application.Current as App)?.Database, new ResourcesService()) { }
|
||||
public CompositeKeyVm() : this(DatabaseService.Instance, new ResourcesService()) { }
|
||||
|
||||
public CompositeKeyVm(IDatabase database, IResource resource)
|
||||
public CompositeKeyVm(IDatabaseService database, IResourceService resource)
|
||||
{
|
||||
_resource = resource;
|
||||
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
|
||||
|
@@ -1,44 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.ApplicationModel.Store;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Services;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class DonateVm: NotifyPropertyChangedBase
|
||||
{
|
||||
public ObservableCollection<ProductListing> Donations { get; }
|
||||
|
||||
public ProductListing SelectedItem
|
||||
{
|
||||
get { return _selectedItem; }
|
||||
set { SetProperty(ref _selectedItem, value); }
|
||||
}
|
||||
|
||||
private readonly ILicenseService _license;
|
||||
private ProductListing _selectedItem;
|
||||
|
||||
public DonateVm() : this (new LicenseService()) { }
|
||||
|
||||
public DonateVm(ILicenseService license)
|
||||
{
|
||||
// TODO: find a nice way to order products
|
||||
_license = license;
|
||||
Donations = new ObservableCollection<ProductListing>(
|
||||
_license.Products.Values
|
||||
/*.OrderBy(p => decimal.Parse(p.FormattedPrice.Replace('\u00A0', ' '), NumberStyles.Currency,
|
||||
CultureInfo.CurrentCulture.NumberFormat))*/
|
||||
);
|
||||
}
|
||||
|
||||
public async Task<int> Purchase()
|
||||
{
|
||||
return await _license.Purchase(SelectedItem.ProductId);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Attributes;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Mappings;
|
||||
using ModernKeePass.Services;
|
||||
using ModernKeePassLib;
|
||||
using ModernKeePassLib.Cryptography.PasswordGenerator;
|
||||
using ModernKeePassLib.Security;
|
||||
@@ -67,6 +68,7 @@ namespace ModernKeePass.ViewModels
|
||||
NotifyPropertyChanged("PasswordComplexityIndicator");
|
||||
}
|
||||
}
|
||||
|
||||
public string Url
|
||||
{
|
||||
get { return GetEntryValue(PwDefs.UrlField); }
|
||||
@@ -155,7 +157,7 @@ namespace ModernKeePass.ViewModels
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private readonly PwEntry _pwEntry;
|
||||
private readonly IDatabase _database;
|
||||
private readonly IDatabaseService _database;
|
||||
private bool _isEditMode;
|
||||
private bool _isRevealPassword;
|
||||
private double _passwordLength = 25;
|
||||
@@ -168,9 +170,9 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public EntryVm() { }
|
||||
|
||||
internal EntryVm(PwEntry entry, GroupVm parent) : this(entry, parent, (Application.Current as App)?.Database) { }
|
||||
internal EntryVm(PwEntry entry, GroupVm parent) : this(entry, parent, DatabaseService.Instance) { }
|
||||
|
||||
public EntryVm(PwEntry entry, GroupVm parent, IDatabase database)
|
||||
public EntryVm(PwEntry entry, GroupVm parent, IDatabaseService database)
|
||||
{
|
||||
_database = database;
|
||||
_pwEntry = entry;
|
||||
@@ -211,6 +213,7 @@ namespace ModernKeePass.ViewModels
|
||||
return _pwEntry?.Strings.GetSafe(key).ReadString();
|
||||
}
|
||||
|
||||
[DatabaseChanged]
|
||||
private void SetEntryValue(string key, string newValue)
|
||||
{
|
||||
_pwEntry?.Strings.Set(key, new ProtectedString(true, newValue));
|
||||
|
@@ -3,11 +3,12 @@ using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Attributes;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Mappings;
|
||||
using ModernKeePass.Services;
|
||||
using ModernKeePassLib;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
@@ -54,6 +55,7 @@ namespace ModernKeePass.ViewModels
|
||||
public string Name
|
||||
{
|
||||
get { return _pwGroup == null ? string.Empty : _pwGroup.Name; }
|
||||
[DatabaseChanged]
|
||||
set { _pwGroup.Name = value; }
|
||||
}
|
||||
|
||||
@@ -92,7 +94,7 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
|
||||
private readonly PwGroup _pwGroup;
|
||||
private readonly IDatabase _database;
|
||||
private readonly IDatabaseService _database;
|
||||
private bool _isEditMode;
|
||||
private PwEntry _reorderedEntry;
|
||||
private ObservableCollection<EntryVm> _entries = new ObservableCollection<EntryVm>();
|
||||
@@ -101,10 +103,10 @@ namespace ModernKeePass.ViewModels
|
||||
public GroupVm() {}
|
||||
|
||||
internal GroupVm(PwGroup pwGroup, GroupVm parent, PwUuid recycleBinId = null) : this(pwGroup, parent,
|
||||
(Application.Current as App)?.Database, recycleBinId)
|
||||
DatabaseService.Instance, recycleBinId)
|
||||
{ }
|
||||
|
||||
public GroupVm(PwGroup pwGroup, GroupVm parent, IDatabase database, PwUuid recycleBinId = null)
|
||||
public GroupVm(PwGroup pwGroup, GroupVm parent, IDatabaseService database, PwUuid recycleBinId = null)
|
||||
{
|
||||
_pwGroup = pwGroup;
|
||||
_database = database;
|
||||
@@ -115,7 +117,8 @@ namespace ModernKeePass.ViewModels
|
||||
Entries.CollectionChanged += Entries_CollectionChanged;
|
||||
Groups = new ObservableCollection<GroupVm>(pwGroup.Groups.Select(g => new GroupVm(g, this, recycleBinId)));
|
||||
}
|
||||
|
||||
|
||||
[DatabaseChanged]
|
||||
private void Entries_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
switch (e.Action)
|
||||
@@ -131,7 +134,8 @@ namespace ModernKeePass.ViewModels
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[DatabaseChanged]
|
||||
public GroupVm AddNewGroup(string name = "")
|
||||
{
|
||||
var pwGroup = new PwGroup(true, true, name, PwIcon.Folder);
|
||||
@@ -162,6 +166,8 @@ namespace ModernKeePass.ViewModels
|
||||
Move(PreviousGroup);
|
||||
}
|
||||
|
||||
|
||||
[DatabaseChanged]
|
||||
public void Move(GroupVm destination)
|
||||
{
|
||||
PreviousGroup = ParentGroup;
|
||||
@@ -189,6 +195,8 @@ namespace ModernKeePass.ViewModels
|
||||
_database.Save();
|
||||
}
|
||||
|
||||
|
||||
[DatabaseChanged]
|
||||
public void SortEntries()
|
||||
{
|
||||
var comparer = new PwEntryComparer(PwDefs.TitleField, true, false);
|
||||
@@ -203,6 +211,8 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[DatabaseChanged]
|
||||
public void SortGroups()
|
||||
{
|
||||
try
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using Windows.Storage;
|
||||
using ModernKeePass.Common;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Services;
|
||||
|
||||
@@ -31,20 +30,20 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public void OpenDatabaseFile()
|
||||
{
|
||||
OpenDatabaseFile((Application.Current as App)?.Database);
|
||||
OpenDatabaseFile(DatabaseService.Instance);
|
||||
}
|
||||
|
||||
public void OpenDatabaseFile(IDatabase database)
|
||||
public void OpenDatabaseFile(IDatabaseService database)
|
||||
{
|
||||
database.DatabaseFile = DatabaseFile;
|
||||
}
|
||||
|
||||
public void UpdateAccessTime()
|
||||
{
|
||||
UpdateAccessTime(new RecentService());
|
||||
UpdateAccessTime(RecentService.Instance);
|
||||
}
|
||||
|
||||
public async void UpdateAccessTime(IRecent recent)
|
||||
public async void UpdateAccessTime(IRecentService recent)
|
||||
{
|
||||
await recent.GetFileAsync(Token);
|
||||
}
|
||||
|
@@ -2,9 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Services;
|
||||
using ModernKeePassLib;
|
||||
using ModernKeePassLib.Cryptography.Cipher;
|
||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||
@@ -14,7 +14,7 @@ namespace ModernKeePass.ViewModels
|
||||
// TODO: implement Kdf settings
|
||||
public class SettingsDatabaseVm: NotifyPropertyChangedBase, IHasSelectableObject
|
||||
{
|
||||
private readonly IDatabase _database;
|
||||
private readonly IDatabaseService _database;
|
||||
private GroupVm _selectedItem;
|
||||
|
||||
public bool HasRecycleBin
|
||||
@@ -88,9 +88,9 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsDatabaseVm() : this((Application.Current as App)?.Database) { }
|
||||
public SettingsDatabaseVm() : this(DatabaseService.Instance) { }
|
||||
|
||||
public SettingsDatabaseVm(IDatabase database)
|
||||
public SettingsDatabaseVm(IDatabaseService database)
|
||||
{
|
||||
_database = database;
|
||||
Groups = _database?.RootGroup.Groups;
|
||||
|
@@ -6,12 +6,12 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class SettingsNewVm
|
||||
{
|
||||
private ISettings _settings;
|
||||
private ISettingsService _settings;
|
||||
|
||||
public SettingsNewVm() : this(new SettingsService())
|
||||
public SettingsNewVm() : this(SettingsService.Instance)
|
||||
{ }
|
||||
|
||||
public SettingsNewVm(ISettings settings)
|
||||
public SettingsNewVm(ISettingsService settings)
|
||||
{
|
||||
_settings = settings;
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
@@ -46,10 +45,10 @@ namespace ModernKeePass.ViewModels
|
||||
public MainVm() {}
|
||||
|
||||
internal MainVm(Frame referenceFrame, Frame destinationFrame) : this(referenceFrame, destinationFrame,
|
||||
(Application.Current as App)?.Database, new ResourcesService(), new RecentService())
|
||||
DatabaseService.Instance, new ResourcesService(), RecentService.Instance)
|
||||
{ }
|
||||
|
||||
public MainVm(Frame referenceFrame, Frame destinationFrame, IDatabase database, IResource resource, IRecent recent)
|
||||
public MainVm(Frame referenceFrame, Frame destinationFrame, IDatabaseService database, IResourceService resource, IRecentService recent)
|
||||
{
|
||||
var isDatabaseOpen = database != null && database.IsOpen;
|
||||
|
||||
@@ -62,7 +61,7 @@ namespace ModernKeePass.ViewModels
|
||||
Destination = destinationFrame,
|
||||
Parameter = referenceFrame,
|
||||
SymbolIcon = Symbol.Page2,
|
||||
IsSelected = database != null && database.IsFileOpen
|
||||
IsSelected = database != null && database.IsFileOpen && !database.IsOpen
|
||||
},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
@@ -107,14 +106,14 @@ namespace ModernKeePass.ViewModels
|
||||
PageType = typeof(AboutPage),
|
||||
Destination = destinationFrame,
|
||||
SymbolIcon = Symbol.Help
|
||||
}/*,
|
||||
},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
Title = resource.GetResourceValue("MainMenuItemDonate"),
|
||||
PageType = typeof(DonatePage),
|
||||
Destination = destinationFrame,
|
||||
SymbolIcon = Symbol.Shop
|
||||
}*/
|
||||
}
|
||||
};
|
||||
// Auto-select the Recent Items menu item if the conditions are met
|
||||
SelectedItem = mainMenuItems.FirstOrDefault(m => m.IsSelected);
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Services;
|
||||
@@ -12,11 +11,11 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public string Name => _database?.Name;
|
||||
|
||||
private readonly IDatabase _database;
|
||||
private readonly IDatabaseService _database;
|
||||
|
||||
public OpenVm() : this((Application.Current as App)?.Database) { }
|
||||
public OpenVm() : this(DatabaseService.Instance) { }
|
||||
|
||||
public OpenVm(IDatabase database)
|
||||
public OpenVm(IDatabaseService database)
|
||||
{
|
||||
_database = database;
|
||||
if (database == null || !database.IsFileOpen) return;
|
||||
@@ -25,10 +24,10 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public void OpenFile(StorageFile file)
|
||||
{
|
||||
OpenFile(file, new RecentService());
|
||||
OpenFile(file, RecentService.Instance);
|
||||
}
|
||||
|
||||
public void OpenFile(StorageFile file, IRecent recent)
|
||||
public void OpenFile(StorageFile file, IRecentService recent)
|
||||
{
|
||||
_database.DatabaseFile = file;
|
||||
OnPropertyChanged("Name");
|
||||
@@ -36,7 +35,7 @@ namespace ModernKeePass.ViewModels
|
||||
AddToRecentList(file, recent);
|
||||
}
|
||||
|
||||
private void AddToRecentList(StorageFile file, IRecent recent)
|
||||
private void AddToRecentList(StorageFile file, IRecentService recent)
|
||||
{
|
||||
recent.Add(file, file.DisplayName);
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class RecentVm : NotifyPropertyChangedBase, IHasSelectableObject
|
||||
{
|
||||
private readonly IRecent _recent;
|
||||
private readonly IRecentService _recent;
|
||||
private ISelectableModel _selectedItem;
|
||||
private ObservableCollection<IRecentItem> _recentItems = new ObservableCollection<IRecentItem>();
|
||||
|
||||
@@ -35,10 +35,10 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public RecentVm() : this (new RecentService())
|
||||
public RecentVm() : this (RecentService.Instance)
|
||||
{ }
|
||||
|
||||
public RecentVm(IRecent recent)
|
||||
public RecentVm(IRecentService recent)
|
||||
{
|
||||
_recent = recent;
|
||||
RecentItems = _recent.GetAllFiles();
|
||||
|
@@ -1,16 +1,16 @@
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Services;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class SaveVm
|
||||
{
|
||||
private readonly IDatabase _database;
|
||||
public SaveVm() : this((Application.Current as App)?.Database) { }
|
||||
private readonly IDatabaseService _database;
|
||||
public SaveVm() : this(DatabaseService.Instance) { }
|
||||
|
||||
public SaveVm(IDatabase database)
|
||||
public SaveVm(IDatabaseService database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
@@ -41,9 +40,9 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsVm() : this((Application.Current as App)?.Database, new ResourcesService()) { }
|
||||
public SettingsVm() : this(DatabaseService.Instance, new ResourcesService()) { }
|
||||
|
||||
public SettingsVm(IDatabase database, IResource resource)
|
||||
public SettingsVm(IDatabaseService database, IResourceService resource)
|
||||
{
|
||||
var menuItems = new ObservableCollection<ListMenuItemVm>
|
||||
{
|
||||
|
Reference in New Issue
Block a user