Save error is now handled via Messenger instead of unhandled exception handler (which didn't work)

Save as actually works now
WIP Styles
Code cleanup
This commit is contained in:
Geoffroy BONNEVILLE
2020-05-04 12:48:27 +02:00
parent 97b10baedc
commit 1e7662def7
33 changed files with 268 additions and 268 deletions

View File

@@ -152,15 +152,6 @@ namespace ModernKeePass.Infrastructure.KeePass
});
}
public async Task<byte[]> SaveDatabase(byte[] newFileContents)
{
return await Task.Run(() =>
{
_pwDatabase.SaveAs(IOConnectionInfo.FromByteArray(newFileContents), true, new NullStatusLogger());
return _pwDatabase.IOConnectionInfo.Bytes;
});
}
public void CloseDatabase()
{
_pwDatabase?.Close();

View File

@@ -5,20 +5,69 @@ using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.AccessCache;
using Windows.Storage.Pickers;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Dtos;
namespace ModernKeePass.Infrastructure.UWP
{
public class StorageFileClient: IFileProxy
{
public async Task<byte[]> OpenBinaryFile(string path)
public async Task<FileInfo> OpenFile(string name, string extension, bool addToRecent)
{
var picker = new FileOpenPicker
{
ViewMode = PickerViewMode.List,
SuggestedStartLocation = PickerLocationId.DocumentsLibrary
};
picker.FileTypeFilter.Add(extension);
// Application now has read/write access to the picked file
var file = await picker.PickSingleFileAsync().AsTask();
if (file == null) return null;
var token = addToRecent
? StorageApplicationPermissions.MostRecentlyUsedList.Add(file, file.Path)
: StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
return new FileInfo
{
Id = token,
Name = file.Name,
Path = file.Path
};
}
public async Task<FileInfo> CreateFile(string name, string extension, string description, bool addToRecent)
{
var savePicker = new FileSavePicker
{
SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
SuggestedFileName = name
};
savePicker.FileTypeChoices.Add(description, new List<string> { extension });
var file = await savePicker.PickSaveFileAsync().AsTask();
if (file == null) return null;
var token = addToRecent
? StorageApplicationPermissions.MostRecentlyUsedList.Add(file, file.Path)
: StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
return new FileInfo
{
Id = token,
Name = file.Name,
Path = file.Path
};
}
public async Task<byte[]> ReadBinaryFile(string path)
{
var file = await GetFile(path);
var result = await FileIO.ReadBufferAsync(file).AsTask();
return result.ToArray();
}
public async Task<IList<string>> OpenTextFile(string path)
public async Task<IList<string>> ReadTextFile(string path)
{
var file = await GetFile(path);
var result = await FileIO.ReadLinesAsync(file).AsTask();