mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
StorageFile client more intelligent
Save is working again
This commit is contained in:
@@ -12,14 +12,14 @@ namespace ModernKeePass.Infrastructure.UWP
|
||||
{
|
||||
public async Task<byte[]> OpenBinaryFile(string path)
|
||||
{
|
||||
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(path).AsTask();
|
||||
var file = await GetFile(path);
|
||||
var result = await FileIO.ReadBufferAsync(file).AsTask();
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public async Task<IList<string>> OpenTextFile(string path)
|
||||
{
|
||||
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(path).AsTask();
|
||||
var file = await GetFile(path);
|
||||
var result = await FileIO.ReadLinesAsync(file).AsTask();
|
||||
return result;
|
||||
}
|
||||
@@ -31,8 +31,17 @@ namespace ModernKeePass.Infrastructure.UWP
|
||||
|
||||
public async Task WriteBinaryContentsToFile(string path, byte[] contents)
|
||||
{
|
||||
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(path).AsTask();
|
||||
var file = await GetFile(path);
|
||||
await FileIO.WriteBytesAsync(file, contents).AsTask();
|
||||
}
|
||||
|
||||
private async Task<StorageFile> GetFile(string token)
|
||||
{
|
||||
if (StorageApplicationPermissions.MostRecentlyUsedList.ContainsItem(token))
|
||||
return await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(token).AsTask();
|
||||
if (StorageApplicationPermissions.FutureAccessList.ContainsItem(token))
|
||||
return await StorageApplicationPermissions.FutureAccessList.GetFileAsync(token).AsTask();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +1,9 @@
|
||||
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
|
||||
{
|
||||
@@ -15,24 +12,7 @@ namespace ModernKeePass.Infrastructure.UWP
|
||||
private readonly StorageItemMostRecentlyUsedList _mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
|
||||
public int EntryCount => _mru.Entries.Count;
|
||||
|
||||
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);
|
||||
|
||||
var result = await FileIO.ReadBufferAsync(file).AsTask();
|
||||
return result.ToArray();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_mru.Remove(token);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<FileInfo> GetAll()
|
||||
{
|
||||
return _mru.Entries.Select(e => new FileInfo
|
||||
|
Reference in New Issue
Block a user