mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
WIP Clean Architecture
Windows 8.1 App Uses keepasslib v2.44 (temporarily)
This commit is contained in:
38
ModernKeePass.Infrastructure/UWP/StorageFileClient.cs
Normal file
38
ModernKeePass.Infrastructure/UWP/StorageFileClient.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.AccessCache;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Infrastructure.UWP
|
||||
{
|
||||
public class StorageFileClient: IFileProxy
|
||||
{
|
||||
public async Task<byte[]> OpenBinaryFile(string path)
|
||||
{
|
||||
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(path);
|
||||
var result = await FileIO.ReadBufferAsync(file);
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public async Task<IList<string>> OpenTextFile(string path)
|
||||
{
|
||||
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(path);
|
||||
var result = await FileIO.ReadLinesAsync(file);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void ReleaseFile(string path)
|
||||
{
|
||||
StorageApplicationPermissions.FutureAccessList.Remove(path);
|
||||
}
|
||||
|
||||
public async Task WriteBinaryContentsToFile(string path, byte[] contents)
|
||||
{
|
||||
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(path);
|
||||
await FileIO.WriteBytesAsync(file, contents);
|
||||
}
|
||||
}
|
||||
}
|
63
ModernKeePass.Infrastructure/UWP/UwpRecentFilesClient.cs
Normal file
63
ModernKeePass.Infrastructure/UWP/UwpRecentFilesClient.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage.AccessCache;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
|
||||
namespace ModernKeePass.Infrastructure.UWP
|
||||
{
|
||||
public class UwpRecentFilesClient: IRecentProxy
|
||||
{
|
||||
private readonly StorageItemMostRecentlyUsedList _mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
|
||||
public int EntryCount => _mru.Entries.Count;
|
||||
|
||||
public async Task<FileInfo> Get(string token)
|
||||
{
|
||||
var recentEntry = _mru.Entries.FirstOrDefault(e => e.Token == token);
|
||||
var file = await _mru.GetFileAsync(token);
|
||||
StorageApplicationPermissions.FutureAccessList.AddOrReplace(recentEntry.Metadata, file);
|
||||
return new FileInfo
|
||||
{
|
||||
Name = file.DisplayName,
|
||||
Path = recentEntry.Metadata
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<FileInfo>> GetAll()
|
||||
{
|
||||
var result = new List<FileInfo>();
|
||||
foreach (var entry in _mru.Entries)
|
||||
{
|
||||
try
|
||||
{
|
||||
var recentItem = await Get(entry.Token);
|
||||
result.Add(recentItem);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_mru.Remove(entry.Token);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task Add(FileInfo recentItem)
|
||||
{
|
||||
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(recentItem.Path);
|
||||
_mru.Add(file, recentItem.Path);
|
||||
}
|
||||
|
||||
public void ClearAll()
|
||||
{
|
||||
for (var i = _mru.Entries.Count; i > 0; i--)
|
||||
{
|
||||
var entry = _mru.Entries[i];
|
||||
StorageApplicationPermissions.FutureAccessList.Remove(entry.Metadata);
|
||||
_mru.Remove(entry.Token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
ModernKeePass.Infrastructure/UWP/UwpResourceClient.cs
Normal file
17
ModernKeePass.Infrastructure/UWP/UwpResourceClient.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Windows.ApplicationModel.Resources;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Infrastructure.UWP
|
||||
{
|
||||
public class UwpResourceClient: IResourceProxy
|
||||
{
|
||||
private const string ResourceFileName = "CodeBehind";
|
||||
private readonly ResourceLoader _resourceLoader = ResourceLoader.GetForCurrentView();
|
||||
|
||||
public string GetResourceValue(string key)
|
||||
{
|
||||
var resource = _resourceLoader.GetString($"/{ResourceFileName}/{key}");
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
}
|
31
ModernKeePass.Infrastructure/UWP/UwpSettingsClient.cs
Normal file
31
ModernKeePass.Infrastructure/UWP/UwpSettingsClient.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.Storage;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Infrastructure.UWP
|
||||
{
|
||||
public class UwpSettingsClient : ISettingsProxy
|
||||
{
|
||||
private readonly IPropertySet _values = ApplicationData.Current.LocalSettings.Values;
|
||||
|
||||
public T GetSetting<T>(string property, T defaultValue = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T)Convert.ChangeType(_values[property], typeof(T));
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void PutSetting<T>(string property, T value)
|
||||
{
|
||||
if (_values.ContainsKey(property))
|
||||
_values[property] = value;
|
||||
else _values.Add(property, value);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user