mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
FileInfo overhaul
Opening DB works again
This commit is contained in:
@@ -31,7 +31,7 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
|
||||
await _database.Create(file,
|
||||
new Credentials
|
||||
{
|
||||
KeyFileContents = await _file.OpenBinaryFile(message.KeyFilePath),
|
||||
KeyFileContents = !string.IsNullOrEmpty(message.KeyFilePath) ? await _file.OpenBinaryFile(message.KeyFilePath) : null,
|
||||
Password = message.Password
|
||||
});
|
||||
_database.FileAccessToken = message.FilePath;
|
||||
|
@@ -30,7 +30,7 @@ namespace ModernKeePass.Application.Database.Queries.OpenDatabase
|
||||
var file = await _file.OpenBinaryFile(request.FilePath);
|
||||
await _database.Open(file, new Credentials
|
||||
{
|
||||
KeyFileContents = await _file.OpenBinaryFile(request.KeyFilePath),
|
||||
KeyFileContents = !string.IsNullOrEmpty(request.KeyFilePath) ? await _file.OpenBinaryFile(request.KeyFilePath): null,
|
||||
Password = request.Password
|
||||
});
|
||||
_database.FileAccessToken = request.FilePath;
|
||||
|
@@ -2,6 +2,7 @@
|
||||
{
|
||||
public class FileInfo
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
}
|
||||
|
@@ -18,11 +18,12 @@ namespace ModernKeePass.Infrastructure.UWP
|
||||
{
|
||||
var recentEntry = _mru.Entries.FirstOrDefault(e => e.Token == token);
|
||||
var file = await _mru.GetFileAsync(token);
|
||||
StorageApplicationPermissions.FutureAccessList.AddOrReplace(recentEntry.Metadata, file);
|
||||
StorageApplicationPermissions.FutureAccessList.AddOrReplace(token, file);
|
||||
return new FileInfo
|
||||
{
|
||||
Id = token,
|
||||
Name = file.DisplayName,
|
||||
Path = recentEntry.Metadata
|
||||
Path = file.Path
|
||||
};
|
||||
}
|
||||
|
||||
@@ -46,8 +47,8 @@ namespace ModernKeePass.Infrastructure.UWP
|
||||
|
||||
public async Task Add(FileInfo recentItem)
|
||||
{
|
||||
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(recentItem.Path);
|
||||
_mru.Add(file, recentItem.Path);
|
||||
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(recentItem.Id);
|
||||
_mru.Add(file);
|
||||
}
|
||||
|
||||
public void ClearAll()
|
||||
@@ -55,7 +56,7 @@ namespace ModernKeePass.Infrastructure.UWP
|
||||
for (var i = _mru.Entries.Count; i > 0; i--)
|
||||
{
|
||||
var entry = _mru.Entries[i];
|
||||
StorageApplicationPermissions.FutureAccessList.Remove(entry.Metadata);
|
||||
StorageApplicationPermissions.FutureAccessList.Remove(entry.Token);
|
||||
_mru.Remove(entry.Token);
|
||||
}
|
||||
}
|
||||
|
@@ -239,8 +239,9 @@ namespace ModernKeePass
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var fileInfo = new FileInfo
|
||||
{
|
||||
Path = token,
|
||||
Name = file.DisplayName
|
||||
Id = token,
|
||||
Name = file.DisplayName,
|
||||
Path = file.Path
|
||||
};
|
||||
rootFrame.Navigate(typeof(MainPage), fileInfo);
|
||||
}
|
||||
|
@@ -170,7 +170,7 @@ namespace ModernKeePass.ViewModels
|
||||
public async Task CreateKeyFile(FileInfo file)
|
||||
{
|
||||
// TODO: implement entropy generator
|
||||
await _mediator.Send(new GenerateKeyFileCommand {KeyFilePath = file.Path});
|
||||
await _mediator.Send(new GenerateKeyFileCommand {KeyFilePath = file.Id});
|
||||
KeyFilePath = file.Path;
|
||||
KeyFileText = file.Name;
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.AOP;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
@@ -11,10 +10,27 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
private bool _isSelected;
|
||||
|
||||
public string Token { get; }
|
||||
public string Name { get; }
|
||||
public string Path => string.Empty;
|
||||
private string _name;
|
||||
private string _token;
|
||||
private string _path;
|
||||
|
||||
public string Token
|
||||
{
|
||||
get { return _token; }
|
||||
set { SetProperty(ref _token, value); }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { SetProperty(ref _name, value); }
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get { return _path; }
|
||||
set { SetProperty(ref _path, value); }
|
||||
}
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
@@ -26,13 +42,15 @@ namespace ModernKeePass.ViewModels
|
||||
public RecentItemVm(IRecentProxy recent, FileInfo file)
|
||||
{
|
||||
_recent = recent;
|
||||
Token = file.Path;
|
||||
Token = file.Id;
|
||||
Name = file.Name;
|
||||
Path = file.Path;
|
||||
}
|
||||
|
||||
public async Task UpdateAccessTime()
|
||||
// Called from XAML
|
||||
public void UpdateAccessTime()
|
||||
{
|
||||
await _recent.Get(Token);
|
||||
_recent.Get(Token).Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,10 +9,28 @@ namespace ModernKeePass.ViewModels
|
||||
public class OpenVm: NotifyPropertyChangedBase
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
private string _name;
|
||||
private string _path;
|
||||
private string _token;
|
||||
public bool IsFileSelected => !string.IsNullOrEmpty(Path);
|
||||
|
||||
public string Name { get; private set; }
|
||||
public string Path { get; private set; }
|
||||
public string Token
|
||||
{
|
||||
get { return _token; }
|
||||
set { SetProperty(ref _token, value); }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
private set { SetProperty(ref _name, value); }
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get { return _path; }
|
||||
private set { SetProperty(ref _path, value); }
|
||||
}
|
||||
|
||||
public OpenVm(): this(App.Services.GetService<IRecentProxy>()) { }
|
||||
|
||||
@@ -23,9 +41,9 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public async Task OpenFile(FileInfo file)
|
||||
{
|
||||
Token = file.Id;
|
||||
Name = file.Name;
|
||||
Path = file.Path;
|
||||
OnPropertyChanged(nameof(Name));
|
||||
OnPropertyChanged(nameof(IsFileSelected));
|
||||
await AddToRecentList(file);
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ namespace ModernKeePass.ViewModels
|
||||
RecentItems = new ObservableCollection<RecentItemVm>(_recent.GetAll().GetAwaiter().GetResult()
|
||||
.Select(r => new RecentItemVm(r)));
|
||||
if (RecentItems.Count > 0)
|
||||
SelectedItem = RecentItems[0] as RecentItemVm;
|
||||
SelectedItem = RecentItems[0];
|
||||
}
|
||||
|
||||
private void ClearAll()
|
||||
|
@@ -21,7 +21,7 @@
|
||||
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<StackPanel Margin="25,0,25,0">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyNewButton" CreateNew="True" DatabaseFilePath="{Binding Path}" ValidationChecked="CompositeKeyUserControl_OnValidationChecked" />
|
||||
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyNewButton" CreateNew="True" DatabaseFilePath="{Binding Token}" ValidationChecked="CompositeKeyUserControl_OnValidationChecked" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<CheckBox x:Name="CheckBox" x:Uid="NewImportCheckbox" Margin="15,10,0,0" IsChecked="{Binding IsImportChecked, Mode=TwoWay}" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
|
@@ -50,7 +50,8 @@ namespace ModernKeePass.Views
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var fileInfo = new FileInfo
|
||||
{
|
||||
Path = token,
|
||||
Id = token,
|
||||
Path = file.Path,
|
||||
Name = file.DisplayName
|
||||
};
|
||||
await Model.OpenFile(fileInfo);
|
||||
|
@@ -25,7 +25,7 @@
|
||||
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<StackPanel Margin="25,0,25,0">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyOpenButton" DatabaseFilePath="{Binding Path}">
|
||||
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyOpenButton" DatabaseFilePath="{Binding Token}">
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:EventTriggerBehavior EventName="ValidationChecked">
|
||||
<core:NavigateToPageAction TargetPage="ModernKeePass.Views.GroupDetailPage" />
|
||||
|
@@ -49,8 +49,9 @@ namespace ModernKeePass.Views
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
var fileInfo = new FileInfo
|
||||
{
|
||||
Path = token,
|
||||
Name = file.DisplayName
|
||||
Path = file.Path,
|
||||
Name = file.DisplayName,
|
||||
Id = token
|
||||
};
|
||||
await Model.OpenFile(fileInfo);
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="0" Text="{Binding Name}" Padding="5,0,0,0" />
|
||||
<TextBlock Grid.Row="1" Text="{Binding Path}" Padding="5,0,0,0" FontSize="10" />
|
||||
<userControls:CompositeKeyUserControl Grid.Row="2" x:Name="DatabaseUserControl" x:Uid="CompositeKeyOpenButton" HorizontalAlignment="Stretch" MinWidth="400" Margin="0,10,0,0" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" DatabaseFilePath="{Binding Path}">
|
||||
<userControls:CompositeKeyUserControl Grid.Row="2" x:Name="DatabaseUserControl" x:Uid="CompositeKeyOpenButton" HorizontalAlignment="Stretch" MinWidth="400" Margin="0,10,0,0" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" DatabaseFilePath="{Binding Token}">
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:EventTriggerBehavior EventName="ValidationChecked">
|
||||
<core:CallMethodAction TargetObject="{Binding}" MethodName="UpdateAccessTime" />
|
||||
|
@@ -172,8 +172,9 @@ namespace ModernKeePass.Views.UserControls
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
await Model.CreateKeyFile(new FileInfo
|
||||
{
|
||||
Path = token,
|
||||
Name = file.DisplayName
|
||||
Id = token,
|
||||
Name = file.DisplayName,
|
||||
Path = file.Path
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user