diff --git a/ModernKeePass.Application/Database/Commands/UpdateCredentials/UpdateCredentialsCommand.cs b/ModernKeePass.Application/Database/Commands/UpdateCredentials/UpdateCredentialsCommand.cs
index 7f0ef75..80c6499 100644
--- a/ModernKeePass.Application/Database/Commands/UpdateCredentials/UpdateCredentialsCommand.cs
+++ b/ModernKeePass.Application/Database/Commands/UpdateCredentials/UpdateCredentialsCommand.cs
@@ -27,7 +27,7 @@ namespace ModernKeePass.Application.Database.Commands.UpdateCredentials
if (!_database.IsOpen) throw new DatabaseClosedException();
_database.UpdateCredentials(new Credentials
{
- KeyFileContents = await _file.OpenBinaryFile(message.KeyFilePath),
+ KeyFileContents = !string.IsNullOrEmpty(message.KeyFilePath) ? await _file.OpenBinaryFile(message.KeyFilePath) : null,
Password = message.Password
});
}
diff --git a/ModernKeePass/Views/SettingsPageFrames/SettingsSecurityPage.xaml b/ModernKeePass/Views/SettingsPageFrames/SettingsSecurityPage.xaml
index 17b3d18..32450cb 100644
--- a/ModernKeePass/Views/SettingsPageFrames/SettingsSecurityPage.xaml
+++ b/ModernKeePass/Views/SettingsPageFrames/SettingsSecurityPage.xaml
@@ -5,24 +5,19 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:userControls="using:ModernKeePass.Views.UserControls"
- xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
- xmlns:core="using:Microsoft.Xaml.Interactions.Core"
- xmlns:actions="using:ModernKeePass.Actions"
+ xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
mc:Ignorable="d">
+
+
+
-
+
-
-
-
-
-
-
-
+
diff --git a/ModernKeePass/Views/UserControls/CompositeKeyUserControl.xaml b/ModernKeePass/Views/UserControls/CompositeKeyUserControl.xaml
deleted file mode 100644
index 866582a..0000000
--- a/ModernKeePass/Views/UserControls/CompositeKeyUserControl.xaml
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/ModernKeePass/Views/UserControls/CompositeKeyUserControl.xaml.cs b/ModernKeePass/Views/UserControls/CompositeKeyUserControl.xaml.cs
deleted file mode 100644
index 9065d35..0000000
--- a/ModernKeePass/Views/UserControls/CompositeKeyUserControl.xaml.cs
+++ /dev/null
@@ -1,193 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Windows.Storage.AccessCache;
-using Windows.Storage.Pickers;
-using Windows.System;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Input;
-using MediatR;
-using Microsoft.Extensions.DependencyInjection;
-using ModernKeePass.Application.Common.Interfaces;
-using ModernKeePass.Application.Database.Commands.CloseDatabase;
-using ModernKeePass.Application.Database.Commands.SaveDatabase;
-using ModernKeePass.Application.Database.Queries.GetDatabase;
-using ModernKeePass.Common;
-using ModernKeePass.Domain.Dtos;
-using ModernKeePass.Events;
-using ModernKeePass.Extensions;
-using ModernKeePass.ViewModels;
-
-// Pour en savoir plus sur le modèle d'élément Contrôle utilisateur, consultez la page http://go.microsoft.com/fwlink/?LinkId=234236
-
-namespace ModernKeePass.Views.UserControls
-{
- public sealed partial class CompositeKeyUserControl
- {
- private readonly IMediator _mediator;
- private readonly IResourceProxy _resource;
- public CompositeKeyVm Model => Grid.DataContext as CompositeKeyVm;
-
- public bool CreateNew
- {
- get { return (bool)GetValue(CreateNewProperty); }
- set { SetValue(CreateNewProperty, value); }
- }
- public static readonly DependencyProperty CreateNewProperty =
- DependencyProperty.Register(
- nameof(CreateNew),
- typeof(bool),
- typeof(CompositeKeyUserControl),
- new PropertyMetadata(false, (o, args) => { }));
-
- public bool UpdateKey
- {
- get { return (bool)GetValue(UpdateKeyProperty); }
- set { SetValue(UpdateKeyProperty, value); }
- }
- public static readonly DependencyProperty UpdateKeyProperty =
- DependencyProperty.Register(
- nameof(UpdateKey),
- typeof(bool),
- typeof(CompositeKeyUserControl),
- new PropertyMetadata(false, (o, args) => { }));
-
- public string ButtonLabel
- {
- get { return (string)GetValue(ButtonLabelProperty); }
- set { SetValue(ButtonLabelProperty, value); }
- }
- public static readonly DependencyProperty ButtonLabelProperty =
- DependencyProperty.Register(
- nameof(ButtonLabel),
- typeof(string),
- typeof(CompositeKeyUserControl),
- new PropertyMetadata("OK", (o, args) => { }));
-
- public string DatabaseFilePath
- {
- get { return (string)GetValue(DatabaseFilePathProperty); }
- set { SetValue(DatabaseFilePathProperty, value); }
- }
- public static readonly DependencyProperty DatabaseFilePathProperty =
- DependencyProperty.Register(
- nameof(DatabaseFilePath),
- typeof(string),
- typeof(CompositeKeyUserControl),
- new PropertyMetadata(null, (o, args) => { }));
-
- public bool ShowComplexityIndicator => CreateNew || UpdateKey;
-
- public CompositeKeyUserControl(): this(App.Services.GetRequiredService(), App.Services.GetRequiredService()) { }
-
- public CompositeKeyUserControl(IMediator mediator, IResourceProxy resource)
- {
- _mediator = mediator;
- _resource = resource;
- InitializeComponent();
- }
-
- public event EventHandler ValidationChecking;
- public event EventHandler ValidationChecked;
-
- private async void OpenButton_OnClick(object sender, RoutedEventArgs e)
- {
- ValidationChecking?.Invoke(this, new EventArgs());
-
- if (UpdateKey)
- {
- await Model.UpdateKey();
- ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroupId));
- }
- else
- {
- var database = await _mediator.Send(new GetDatabaseQuery());
- if (database.IsOpen)
- {
- await MessageDialogHelper.ShowActionDialog(_resource.GetResourceValue("MessageDialogDBOpenTitle"),
- string.Format(_resource.GetResourceValue("MessageDialogDBOpenDesc"), database.Name),
- _resource.GetResourceValue("MessageDialogDBOpenButtonSave"),
- _resource.GetResourceValue("MessageDialogDBOpenButtonDiscard"),
- async command =>
- {
- await _mediator.Send(new SaveDatabaseCommand());
- ToastNotificationHelper.ShowGenericToast(
- database.Name,
- _resource.GetResourceValue("ToastSavedMessage"));
- await _mediator.Send(new CloseDatabaseCommand());
- await OpenDatabase();
- },
- async command =>
- {
- await _mediator.Send(new CloseDatabaseCommand());
- await OpenDatabase();
- });
- }
- else
- {
- await OpenDatabase();
- }
- }
- }
-
- private void PasswordBox_KeyDown(object sender, KeyRoutedEventArgs e)
- {
- if (e.Key == VirtualKey.Enter && Model.IsValid)
- {
- OpenButton_OnClick(sender, e);
- // Stop the event from triggering twice
- e.Handled = true;
- }
- }
-
- private async void KeyFileButton_Click(object sender, RoutedEventArgs e)
- {
- var picker = new FileOpenPicker
- {
- ViewMode = PickerViewMode.List,
- SuggestedStartLocation = PickerLocationId.DocumentsLibrary
- };
- picker.FileTypeFilter.Add("*");
-
- // Application now has read/write access to the picked file
- var file = await picker.PickSingleFileAsync();
- if (file == null) return;
-
- var token = StorageApplicationPermissions.FutureAccessList.Add(file);
- Model.KeyFilePath = token;
- }
-
- private async void CreateKeyFileButton_Click(object sender, RoutedEventArgs e)
- {
- var savePicker = new FileSavePicker
- {
- SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
- SuggestedFileName = "Key"
- };
- savePicker.FileTypeChoices.Add("Key file", new List { ".key" });
-
- var file = await savePicker.PickSaveFileAsync();
- if (file == null) return;
-
- var token = StorageApplicationPermissions.FutureAccessList.Add(file);
- await Model.CreateKeyFile(new FileInfo
- {
- Id = token,
- Name = file.DisplayName,
- Path = file.Path
- });
- }
-
- private async Task OpenDatabase()
- {
- var oldLabel = ButtonLabel;
- ButtonLabel = _resource.GetResourceValue("CompositeKeyOpening");
- if (await Dispatcher.RunTaskAsync(async () => await Model.OpenDatabase(DatabaseFilePath, CreateNew)))
- {
- ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroupId));
- }
-
- ButtonLabel = oldLabel;
- }
- }
-}
diff --git a/ModernKeePass/Views/UserControls/OpenDatabaseUserControl.xaml.cs b/ModernKeePass/Views/UserControls/OpenDatabaseUserControl.xaml.cs
index 9dbf192..e984569 100644
--- a/ModernKeePass/Views/UserControls/OpenDatabaseUserControl.xaml.cs
+++ b/ModernKeePass/Views/UserControls/OpenDatabaseUserControl.xaml.cs
@@ -54,6 +54,7 @@ namespace ModernKeePass.Views.UserControls
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
Model.KeyFilePath = token;
+ Model.KeyFileText = file.DisplayName;
}
}
}
diff --git a/ModernKeePass/Views/UserControls/SetCredentialsUserControl.xaml b/ModernKeePass/Views/UserControls/SetCredentialsUserControl.xaml
index ea1b645..5c2875c 100644
--- a/ModernKeePass/Views/UserControls/SetCredentialsUserControl.xaml
+++ b/ModernKeePass/Views/UserControls/SetCredentialsUserControl.xaml
@@ -42,7 +42,7 @@
Value="{Binding PasswordComplexityIndicator, ConverterParameter=0\,128, Converter={StaticResource ProgressBarLegalValuesConverter}}"
Foreground="{Binding PasswordComplexityIndicator, ConverterParameter=128, Converter={StaticResource DoubleToSolidColorBrushConverter}}"/>
-
ColorPickerUserControl.xaml
-
- CompositeKeyUserControl.xaml
-
MainPage.xaml
@@ -222,10 +219,6 @@
Designer
MSBuild:Compile
-
- Designer
- MSBuild:Compile
-
MSBuild:Compile
Designer
diff --git a/ModernKeePass10/Package.StoreAssociation.xml b/ModernKeePass10/Package.StoreAssociation.xml
deleted file mode 100644
index 860d03a..0000000
--- a/ModernKeePass10/Package.StoreAssociation.xml
+++ /dev/null
@@ -1,368 +0,0 @@
-
-
- CN=0719A91A-C322-4EE0-A257-E60733EECF06
- wismna
- http://www.w3.org/2001/04/xmlenc#sha256
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- wismna.ModernKeePass
-
- ModernKeePass
-
-
-
-
-
\ No newline at end of file
diff --git a/ModernKeePass10/ViewModels/AboutViewModel.cs b/ModernKeePass10/ViewModels/AboutViewModel.cs
deleted file mode 100644
index 6b75e02..0000000
--- a/ModernKeePass10/ViewModels/AboutViewModel.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using Windows.ApplicationModel;
-
-namespace ModernKeePass.ViewModels
-{
- public class AboutViewModel
- {
- private readonly Package _package;
-
- public string Name => _package.DisplayName;
-
- public string Version
- {
- get
- {
- var version = _package.Id.Version;
- return $"{version.Major}.{version.Minor}";
- }
- }
-
- public AboutViewModel() : this(Package.Current) { }
-
- public AboutViewModel(Package package)
- {
- _package = package;
- }
- }
-}
\ No newline at end of file
diff --git a/ModernKeePass10/ViewModels/NewViewModel.cs b/ModernKeePass10/ViewModels/NewViewModel.cs
deleted file mode 100644
index 97ba903..0000000
--- a/ModernKeePass10/ViewModels/NewViewModel.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-using System;
-using Windows.Storage;
-using Windows.Storage.AccessCache;
-using ModernKeePass.Converters;
-using ModernKeePass.Domain.Entities;
-using ModernKeePass.Domain.Enums;
-using ModernKeePass.Domain.Interfaces;
-
-namespace ModernKeePass.ViewModels
-{
- public class NewViewModel : OpenViewModel
- {
- private string _importFormatHelp;
- private readonly IDatabaseService _databaseService;
- private readonly IImportService _importService;
- private readonly ISettingsService _settingsService;
-
- public string Password { get; set; }
-
- public bool IsImportChecked { get; set; }
-
- public IStorageFile ImportFile { get; set; }
-
- public string ImportFileExtensionFilter { get; set; } = "*";
-
- public ImportFormat ImportFormat { get; set; }
-
- public string ImportFormatHelp
- {
- get => _importFormatHelp;
- set
- {
- _importFormatHelp = value;
- OnPropertyChanged(nameof(ImportFormatHelp));
- }
- }
-
- public NewViewModel()
- { }
-
- public NewViewModel(IDatabaseService databaseService, IImportService importService, ISettingsService settingsService)
- {
- _databaseService = databaseService;
- _importService = importService;
- _settingsService = settingsService;
- }
-
- public void PopulateInitialData()
- {
- if (_settingsService.GetSetting("Sample") && !IsImportChecked) CreateSampleData(_databaseService.RootGroupEntity);
- else if (IsImportChecked && ImportFile != null)
- {
- var token = StorageApplicationPermissions.FutureAccessList.Add(ImportFile);
- _importService.Import(ImportFormat, token, _databaseService.RootGroupEntity);
- StorageApplicationPermissions.FutureAccessList.Remove(token);
- }
- }
-
- private void CreateSampleData(GroupEntity groupEntity)
- {
- var converter = new IconToSymbolConverter();
-
- groupEntity.SubGroups.Add(new GroupEntity
- {
- Name = "Banking",
- Icon = Icon.Calculator
- });
-
- groupEntity.SubGroups.Add(new GroupEntity
- {
- Name = "Email",
- Icon = Icon.Mail
- });
-
- groupEntity.SubGroups.Add(new GroupEntity
- {
- Name = "Internet",
- Icon = Icon.World
- });
-
- groupEntity.Entries.Add(new EntryEntity
- {
- Name = "Sample Entry",
- UserName = "Username",
- Url = new Uri("https://keepass.info"),
- Password = "Password",
- Notes = "You may safely delete this sample"
- });
-
- groupEntity.Entries.Add(new EntryEntity
- {
- Name = "Sample Entry #2",
- UserName = "Michael321",
- Url = new Uri("https://keepass.info/help/base/kb/testform.html"),
- Password = "12345"
- });
- }
- }
-}
diff --git a/ModernKeePass10/ViewModels/OpenViewModel.cs b/ModernKeePass10/ViewModels/OpenViewModel.cs
deleted file mode 100644
index 87189bc..0000000
--- a/ModernKeePass10/ViewModels/OpenViewModel.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using System.Threading.Tasks;
-using Autofac;
-using ModernKeePass.Domain.AOP;
-using ModernKeePass.Domain.Dtos;
-using ModernKeePass.Domain.Interfaces;
-
-namespace ModernKeePass.ViewModels
-{
- public class OpenViewModel: NotifyPropertyChangedBase
- {
- private readonly IRecentService _recentService;
- private string _name;
- private string _databaseFilePath;
-
- public bool IsFileSelected => !string.IsNullOrEmpty(DatabaseFilePath);
-
- public string Name
- {
- get => _name;
- private set => SetProperty(ref _name, value);
- }
-
- public string DatabaseFilePath
- {
- get => _databaseFilePath;
- private set => SetProperty(ref _databaseFilePath, value);
- }
-
- public OpenViewModel(): this(App.Container.Resolve())
- { }
- public OpenViewModel(IRecentService recentService)
- {
- _recentService = recentService;
- }
-
- public async Task OpenFile(FileInfo fileInfo)
- {
- Name = fileInfo.Name;
- DatabaseFilePath = fileInfo.Path;
- OnPropertyChanged(nameof(IsFileSelected));
- await _recentService.Add(fileInfo);
- }
- }
-}
diff --git a/ModernKeePass10/ViewModels/RecentViewModel.cs b/ModernKeePass10/ViewModels/RecentViewModel.cs
deleted file mode 100644
index bea32a6..0000000
--- a/ModernKeePass10/ViewModels/RecentViewModel.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Windows.Input;
-using Autofac;
-using ModernKeePass.Application.Common.Interfaces;
-using ModernKeePass.Common;
-using ModernKeePass.Domain.AOP;
-using ModernKeePass.Domain.Interfaces;
-using ModernKeePass.ViewModels.ListItems;
-
-namespace ModernKeePass.ViewModels
-{
- public class RecentViewModel : NotifyPropertyChangedBase, IHasSelectableObject
- {
- private readonly IRecentService _recentService;
- private ISelectableModel _selectedItem;
- private ObservableCollection _recentItems = new ObservableCollection();
-
- public ObservableCollection RecentItems
- {
- get => _recentItems;
- set => SetProperty(ref _recentItems, value);
- }
-
- public ISelectableModel SelectedItem
- {
- get => _selectedItem;
- set
- {
- if (_selectedItem == value) return;
- if (_selectedItem != null)
- {
- _selectedItem.IsSelected = false;
- }
-
- SetProperty(ref _selectedItem, value);
-
- if (_selectedItem == null) return;
- _selectedItem.IsSelected = true;
- }
- }
-
- public ICommand ClearAllCommand { get; }
-
- public RecentViewModel() : this (App.Container.Resolve())
- { }
-
- public RecentViewModel(IRecentService recentService)
- {
- _recentService = recentService;
- ClearAllCommand = new RelayCommand(ClearAll);
-
- RecentItems = new ObservableCollection(
- _recentService.GetAll().GetAwaiter().GetResult().Select(r => new RecentItemViewModel
- {
- Name = r.Name,
- Token = r.Path
- })
- );
- if (RecentItems.Count > 0) SelectedItem = RecentItems[0];
- }
-
- private void ClearAll()
- {
- _recentService.ClearAll();
- RecentItems.Clear();
- }
- }
-}
diff --git a/ModernKeePass10/ViewModels/SaveViewModel.cs b/ModernKeePass10/ViewModels/SaveViewModel.cs
deleted file mode 100644
index 21e7cba..0000000
--- a/ModernKeePass10/ViewModels/SaveViewModel.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using Autofac;
-using ModernKeePass.Domain.Dtos;
-using ModernKeePass.Domain.Interfaces;
-
-namespace ModernKeePass.ViewModels
-{
- public class SaveViewModel
- {
- private readonly IDatabaseService _database;
- public SaveViewModel() : this(App.Container.Resolve()) { }
-
- public SaveViewModel(IDatabaseService database)
- {
- _database = database;
- }
-
- public void Save(bool close = true)
- {
- _database.Save();
- if (close) _database.Close();
- }
-
- public void Save(string token)
- {
- _database.SaveAs(new FileInfo
- {
- Path = token
- });
- }
- }
-}
\ No newline at end of file
diff --git a/ModernKeePass10/Win10App.csproj b/ModernKeePass10/Win10App.csproj
index 5876cc4..82a2919 100644
--- a/ModernKeePass10/Win10App.csproj
+++ b/ModernKeePass10/Win10App.csproj
@@ -101,7 +101,6 @@
UpdateCredentialsUserControl.xaml
-
@@ -185,10 +184,6 @@
SaveDatabasePage.xaml
-
-
-
-
HamburgerMenuUserControl.xaml
@@ -208,9 +203,6 @@
-
-
-
MSBuild:Compile
diff --git a/WinAppCommon/ViewModels/Items/SettingsSecurityVm.cs b/WinAppCommon/ViewModels/Items/SettingsSecurityVm.cs
new file mode 100644
index 0000000..c8e6c04
--- /dev/null
+++ b/WinAppCommon/ViewModels/Items/SettingsSecurityVm.cs
@@ -0,0 +1,43 @@
+using System.Threading.Tasks;
+using GalaSoft.MvvmLight.Messaging;
+using GalaSoft.MvvmLight.Views;
+using MediatR;
+using Messages;
+using Microsoft.Extensions.DependencyInjection;
+using ModernKeePass.Application.Common.Interfaces;
+using ModernKeePass.Application.Database.Commands.UpdateCredentials;
+
+namespace ModernKeePass.ViewModels.ListItems
+{
+ public class SettingsSecurityVm
+ {
+ private readonly IMediator _mediator;
+ private readonly ISettingsProxy _settings;
+ private readonly INavigationService _navigation;
+
+ public SettingsSecurityVm(): this(
+ App.Services.GetRequiredService(),
+ App.Services.GetRequiredService(),
+ App.Services.GetRequiredService(),
+ App.Services.GetRequiredService()) { }
+
+ public SettingsSecurityVm(IMediator mediator, ISettingsProxy settings, IMessenger messenger, INavigationService navigation)
+ {
+ _mediator = mediator;
+ _settings = settings;
+ _navigation = navigation;
+
+ messenger.Register(this, async message => await UpdateDatabaseCredentials(message));
+ }
+
+ public async Task UpdateDatabaseCredentials(CredentialsSetMessage message)
+ {
+ await _mediator.Send(new UpdateCredentialsCommand
+ {
+ KeyFilePath = message.KeyFilePath,
+ Password = message.Password
+ });
+ //TODO: Add Toast
+ }
+ }
+}
\ No newline at end of file
diff --git a/WinAppCommon/ViewModels/UserControls/OpenDatabaseControlVm.cs b/WinAppCommon/ViewModels/UserControls/OpenDatabaseControlVm.cs
index d76c57d..000bddd 100644
--- a/WinAppCommon/ViewModels/UserControls/OpenDatabaseControlVm.cs
+++ b/WinAppCommon/ViewModels/UserControls/OpenDatabaseControlVm.cs
@@ -49,7 +49,7 @@ namespace ModernKeePass.ViewModels
}
}
- public bool IsValid => !_isOpening && (HasPassword || HasKeyFile && KeyFilePath != null);
+ public bool IsValid => !_isOpening && (HasPassword || HasKeyFile && !string.IsNullOrEmpty(KeyFilePath));
public string Status
{
@@ -113,7 +113,6 @@ namespace ModernKeePass.ViewModels
private string _keyFileText;
private string _openButtonLabel;
-
public OpenDatabaseControlVm() : this(
App.Services.GetRequiredService(),
App.Services.GetRequiredService(),
diff --git a/WinAppCommon/ViewModels/UserControls/SetCredentialsViewModel.cs b/WinAppCommon/ViewModels/UserControls/SetCredentialsViewModel.cs
index 2a5fd97..8902f46 100644
--- a/WinAppCommon/ViewModels/UserControls/SetCredentialsViewModel.cs
+++ b/WinAppCommon/ViewModels/UserControls/SetCredentialsViewModel.cs
@@ -1,14 +1,18 @@
-using GalaSoft.MvvmLight;
+using System.Threading.Tasks;
+using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
+using MediatR;
using Messages;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
+using ModernKeePass.Application.Security.Commands.GenerateKeyFile;
namespace ModernKeePass.ViewModels
{
public class SetCredentialsViewModel : ObservableObject
{
+ private readonly IMediator _mediator;
private readonly ICredentialsProxy _credentials;
private readonly IMessenger _messenger;
@@ -87,7 +91,7 @@ namespace ModernKeePass.ViewModels
public double PasswordComplexityIndicator => _credentials.EstimatePasswordComplexity(Password);
- public bool IsValid => HasPassword && Password == ConfirmPassword || HasKeyFile && KeyFilePath != string.Empty;
+ public bool IsValid => HasPassword && Password == ConfirmPassword || HasKeyFile && !string.IsNullOrEmpty(KeyFilePath);
public RelayCommand GenerateCredentialsCommand{ get; }
@@ -100,13 +104,25 @@ namespace ModernKeePass.ViewModels
private string _keyFileText;
private string _openButtonLabel;
- public SetCredentialsViewModel(): this(App.Services.GetRequiredService(), App.Services.GetRequiredService()) { }
+ public SetCredentialsViewModel(): this(
+ App.Services.GetRequiredService(),
+ App.Services.GetRequiredService(),
+ App.Services.GetRequiredService(),
+ App.Services.GetRequiredService()) { }
- public SetCredentialsViewModel(ICredentialsProxy credentials, IMessenger messenger)
+ public SetCredentialsViewModel(IMediator mediator, ICredentialsProxy credentials, IMessenger messenger, IResourceProxy resource)
{
+ _mediator = mediator;
_credentials = credentials;
_messenger = messenger;
GenerateCredentialsCommand = new RelayCommand(GenerateCredentials, () => IsValid);
+
+ _keyFileText = resource.GetResourceValue("CompositeKeyDefaultKeyFile");
+ }
+
+ public async Task GenerateKeyFile()
+ {
+ await _mediator.Send(new GenerateKeyFileCommand {KeyFilePath = KeyFilePath});
}
private void GenerateCredentials()
diff --git a/WinAppCommon/WinAppCommon.projitems b/WinAppCommon/WinAppCommon.projitems
index 7916d64..aa661d6 100644
--- a/WinAppCommon/WinAppCommon.projitems
+++ b/WinAppCommon/WinAppCommon.projitems
@@ -52,6 +52,7 @@
+