mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Database files are added to the mru instead of the fal
Simplify opening database workflow Corrected opening from recent bug
This commit is contained in:
@@ -7,9 +7,8 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
public interface IRecentProxy
|
||||
{
|
||||
int EntryCount { get; }
|
||||
Task<FileInfo> Get(string token, bool updateAccessTime = false);
|
||||
Task<byte[]> Get(string token, bool updateAccessTime = true);
|
||||
IEnumerable<FileInfo> GetAll();
|
||||
Task Add(FileInfo recentItem);
|
||||
void ClearAll();
|
||||
}
|
||||
}
|
@@ -9,18 +9,15 @@ namespace ModernKeePass.Application.Database.Commands.CloseDatabase
|
||||
public class CloseDatabaseCommandHandler : IRequestHandler<CloseDatabaseCommand>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IFileProxy _file;
|
||||
|
||||
public CloseDatabaseCommandHandler(IDatabaseProxy database, IFileProxy file)
|
||||
public CloseDatabaseCommandHandler(IDatabaseProxy database)
|
||||
{
|
||||
_database = database;
|
||||
_file = file;
|
||||
}
|
||||
public void Handle(CloseDatabaseCommand message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
_database.CloseDatabase();
|
||||
_file.ReleaseFile(_database.FileAccessToken);
|
||||
|
||||
// Cleanup
|
||||
_database.FileAccessToken = null;
|
||||
|
@@ -16,18 +16,20 @@ namespace ModernKeePass.Application.Database.Queries.OpenDatabase
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IFileProxy _file;
|
||||
private readonly IRecentProxy _recent;
|
||||
|
||||
public OpenDatabaseQueryHandler(IDatabaseProxy database, IFileProxy file)
|
||||
public OpenDatabaseQueryHandler(IDatabaseProxy database, IFileProxy file, IRecentProxy recent)
|
||||
{
|
||||
_database = database;
|
||||
_file = file;
|
||||
_recent = recent;
|
||||
}
|
||||
|
||||
public async Task Handle(OpenDatabaseQuery message)
|
||||
{
|
||||
if (_database.IsDirty) throw new DatabaseOpenException();
|
||||
|
||||
var file = await _file.OpenBinaryFile(message.FilePath);
|
||||
|
||||
var file = await _recent.Get(message.FilePath);
|
||||
var hasKeyFile = !string.IsNullOrEmpty(message.KeyFilePath);
|
||||
await _database.Open(file, new Credentials
|
||||
{
|
||||
|
@@ -1,33 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage.AccessCache;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace ModernKeePass.Infrastructure.UWP
|
||||
{
|
||||
public class UwpRecentFilesClient: IRecentProxy
|
||||
{
|
||||
private readonly StorageItemMostRecentlyUsedList _mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
private readonly StorageItemAccessList _fal = StorageApplicationPermissions.FutureAccessList;
|
||||
|
||||
public int EntryCount => _mru.Entries.Count;
|
||||
|
||||
public async Task<FileInfo> Get(string token, bool updateAccessTime = false)
|
||||
public async Task<byte[]> Get(string token, bool updateAccessTime = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var file = await _mru.GetFileAsync(token,
|
||||
updateAccessTime ? AccessCacheOptions.None : AccessCacheOptions.SuppressAccessTimeUpdate).AsTask().ConfigureAwait(false);
|
||||
_fal.AddOrReplace(token, file, file.Name);
|
||||
return new FileInfo
|
||||
{
|
||||
Id = token,
|
||||
Name = file.DisplayName,
|
||||
Path = file.Path
|
||||
};
|
||||
|
||||
var result = await FileIO.ReadBufferAsync(file).AsTask();
|
||||
return result.ToArray();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -45,18 +42,11 @@ namespace ModernKeePass.Infrastructure.UWP
|
||||
Path = e.Metadata
|
||||
});
|
||||
}
|
||||
|
||||
public async Task Add(FileInfo recentItem)
|
||||
{
|
||||
var file = await _fal.GetFileAsync(recentItem.Id).AsTask();
|
||||
_mru.Add(file, file.Path);
|
||||
}
|
||||
|
||||
|
||||
public void ClearAll()
|
||||
{
|
||||
foreach (var entry in _mru.Entries)
|
||||
{
|
||||
if (_fal.ContainsItem(entry.Token)) _fal.Remove(entry.Token);
|
||||
_mru.Remove(entry.Token);
|
||||
}
|
||||
}
|
||||
|
@@ -48,7 +48,7 @@ namespace ModernKeePass.Views
|
||||
Path = file.Path,
|
||||
Name = file.DisplayName
|
||||
};
|
||||
await Model.OpenFile(fileInfo);
|
||||
Model.OpenFile(fileInfo);
|
||||
}
|
||||
|
||||
private void ImportFormatComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
|
@@ -22,13 +22,13 @@ namespace ModernKeePass.Views
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override async void OnNavigatedTo(NavigationEventArgs e)
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
var file = e.Parameter as FileInfo;
|
||||
if (file != null)
|
||||
{
|
||||
await Model.OpenFile(file);
|
||||
Model.OpenFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,14 +45,16 @@ namespace ModernKeePass.Views
|
||||
var file = await picker.PickSingleFileAsync().AsTask();
|
||||
if (file == null) return;
|
||||
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||
//var token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
|
||||
// TODO: use service
|
||||
var token = StorageApplicationPermissions.MostRecentlyUsedList.Add(file, file.Name);
|
||||
var fileInfo = new FileInfo
|
||||
{
|
||||
Path = file.Path,
|
||||
Name = file.DisplayName,
|
||||
Id = token
|
||||
};
|
||||
await Model.OpenFile(fileInfo);
|
||||
Model.OpenFile(fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public NewVm(IMediator mediator, IRecentProxy recent, ISettingsProxy settings, INavigationService navigation) : base(recent)
|
||||
public NewVm(IMediator mediator, IRecentProxy recent, ISettingsProxy settings, INavigationService navigation)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_settings = settings;
|
||||
|
@@ -1,13 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using GalaSoft.MvvmLight;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class OpenVm: ViewModelBase
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
private string _name;
|
||||
private string _path;
|
||||
private string _token;
|
||||
@@ -31,23 +28,12 @@ namespace ModernKeePass.ViewModels
|
||||
private set { Set(() => Path, ref _path, value); }
|
||||
}
|
||||
|
||||
public OpenVm(IRecentProxy recent)
|
||||
{
|
||||
_recent = recent;
|
||||
}
|
||||
|
||||
public async Task OpenFile(FileInfo file)
|
||||
public void OpenFile(FileInfo file)
|
||||
{
|
||||
Token = file.Id;
|
||||
Name = file.Name;
|
||||
Path = file.Path;
|
||||
RaisePropertyChanged(nameof(IsFileSelected));
|
||||
await AddToRecentList(file);
|
||||
}
|
||||
|
||||
private async Task AddToRecentList(FileInfo file)
|
||||
{
|
||||
await _recent.Add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,17 +1,15 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using Messages;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
using ModernKeePass.ViewModels.ListItems;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class RecentVm : ViewModelBase, IHasSelectableObject
|
||||
public class RecentVm : ObservableObject, IHasSelectableObject
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
private ISelectableModel _selectedItem;
|
||||
@@ -52,15 +50,8 @@ namespace ModernKeePass.ViewModels
|
||||
RecentItems = new ObservableCollection<RecentItemVm>(recentItems);
|
||||
if (RecentItems.Count > 0)
|
||||
SelectedItem = RecentItems[0];
|
||||
|
||||
MessengerInstance.Register<DatabaseOpeningMessage>(this, async action => await UpdateAccessTime(action.Token));
|
||||
}
|
||||
|
||||
private async Task UpdateAccessTime(string token)
|
||||
{
|
||||
await _recent.Get(token, true);
|
||||
}
|
||||
|
||||
private void ClearAll()
|
||||
{
|
||||
_recent.ClearAll();
|
||||
|
Reference in New Issue
Block a user