mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Lib fully migrated to Standard
CryptographicEngine.DeriveKeyMaterial exception...
This commit is contained in:
@@ -122,12 +122,12 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static LockFileInfo Load(IOConnectionInfo iocLockFile)
|
||||
public static async Task<LockFileInfo> Load(IOConnectionInfo iocLockFile)
|
||||
{
|
||||
Stream s = null;
|
||||
try
|
||||
{
|
||||
s = IOConnection.OpenRead(iocLockFile);
|
||||
s = await IOConnection.OpenRead(iocLockFile);
|
||||
if(s == null) return null;
|
||||
StreamReader sr = new StreamReader(s, StrUtil.Utf8);
|
||||
string str = sr.ReadToEnd();
|
||||
@@ -149,7 +149,7 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
}
|
||||
|
||||
// Throws on error
|
||||
public static LockFileInfo Create(IOConnectionInfo iocLockFile)
|
||||
public static async Task<LockFileInfo> Create(IOConnectionInfo iocLockFile)
|
||||
{
|
||||
LockFileInfo lfi;
|
||||
Stream s = null;
|
||||
@@ -186,7 +186,7 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
|
||||
byte[] pbFile = StrUtil.Utf8.GetBytes(sb.ToString());
|
||||
|
||||
s = IOConnection.OpenWrite(iocLockFile);
|
||||
s = await IOConnection.OpenWrite(iocLockFile);
|
||||
if(s == null) throw new IOException(iocLockFile.GetDisplayName());
|
||||
s.Write(pbFile, 0, pbFile.Length);
|
||||
}
|
||||
@@ -203,7 +203,7 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
m_iocLockFile = iocBaseFile.CloneDeep();
|
||||
m_iocLockFile.Path += LockFileExt;
|
||||
|
||||
LockFileInfo lfiEx = LockFileInfo.Load(m_iocLockFile);
|
||||
LockFileInfo lfiEx = LockFileInfo.Load(m_iocLockFile).Result;
|
||||
if(lfiEx != null)
|
||||
{
|
||||
m_iocLockFile = null; // Otherwise Dispose deletes the existing one
|
||||
|
@@ -29,6 +29,7 @@ using System.Security.AccessControl;
|
||||
|
||||
using ModernKeePassLibPCL.Native;
|
||||
using ModernKeePassLibPCL.Utility;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModernKeePassLibPCL.Serialization
|
||||
{
|
||||
@@ -77,7 +78,7 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
else m_iocTemp = m_iocBase;
|
||||
}
|
||||
|
||||
public Stream OpenWrite()
|
||||
public async Task<Stream> OpenWrite()
|
||||
{
|
||||
if(!m_bTransacted) m_bMadeUnhidden = UrlUtil.UnhideFile(m_iocTemp.Path);
|
||||
else // m_bTransacted
|
||||
@@ -86,7 +87,7 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
catch(Exception) { }
|
||||
}
|
||||
|
||||
return IOConnection.OpenWrite(m_iocTemp);
|
||||
return await IOConnection.OpenWrite(m_iocTemp);
|
||||
}
|
||||
|
||||
public void CommitWrite()
|
||||
@@ -98,7 +99,7 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
}
|
||||
}
|
||||
|
||||
private void CommitWriteTransaction()
|
||||
private async void CommitWriteTransaction()
|
||||
{
|
||||
bool bMadeUnhidden = UrlUtil.UnhideFile(m_iocBase.Path);
|
||||
|
||||
@@ -107,7 +108,7 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
bool bEfsEncrypted = false;
|
||||
#endif
|
||||
|
||||
if(IOConnection.FileExists(m_iocBase))
|
||||
if(await IOConnection.FileExists(m_iocBase))
|
||||
{
|
||||
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
|
||||
if(m_iocBase.IsLocalFile())
|
||||
|
@@ -23,6 +23,7 @@ using System.IO;
|
||||
using System.Net;
|
||||
using System.Diagnostics;
|
||||
using Windows.Storage.Streams;
|
||||
using System.Threading.Tasks;
|
||||
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
|
||||
using System.Net.Cache;
|
||||
using System.Net.Security;
|
||||
@@ -421,20 +422,21 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
new Uri(ioc.Path)));
|
||||
}
|
||||
#else
|
||||
public static Stream OpenRead(IOConnectionInfo ioc)
|
||||
public static async Task<Stream> OpenRead(IOConnectionInfo ioc)
|
||||
{
|
||||
RaiseIOAccessPreEvent(ioc, IOAccessType.Read);
|
||||
|
||||
return OpenReadLocal(ioc);
|
||||
return await OpenReadLocal(ioc);
|
||||
}
|
||||
#endif
|
||||
|
||||
private static Stream OpenReadLocal(IOConnectionInfo ioc)
|
||||
private static async Task<Stream> OpenReadLocal(IOConnectionInfo ioc)
|
||||
{
|
||||
#if ModernKeePassLibPCL
|
||||
/*if (ioc.StorageFile != null)
|
||||
/*if (ioc.StorageFile != null)
|
||||
{*/
|
||||
return ioc.StorageFile.OpenAsync(FileAccessMode.Read).GetResults().AsStream();
|
||||
var file = await ioc.StorageFile.OpenAsync(FileAccessMode.Read);
|
||||
return file.AsStream();
|
||||
/*}
|
||||
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
||||
return file.OpenAsync(PCLStorage.FileAccess.Read).Result;*/
|
||||
@@ -467,35 +469,36 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
return IocStream.WrapIfRequired(s);
|
||||
}
|
||||
#else
|
||||
public static Stream OpenWrite(IOConnectionInfo ioc)
|
||||
public static async Task<Stream> OpenWrite(IOConnectionInfo ioc)
|
||||
{
|
||||
RaiseIOAccessPreEvent(ioc, IOAccessType.Write);
|
||||
|
||||
return OpenWriteLocal(ioc);
|
||||
return await OpenWriteLocal(ioc);
|
||||
}
|
||||
#endif
|
||||
|
||||
private static Stream OpenWriteLocal(IOConnectionInfo ioc)
|
||||
private static async Task<Stream> OpenWriteLocal(IOConnectionInfo ioc)
|
||||
{
|
||||
#if ModernKeePassLibPCL
|
||||
/*if (ioc.StorageFile != null)
|
||||
/*if (ioc.StorageFile != null)
|
||||
{*/
|
||||
return ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite).GetResults().AsStream();
|
||||
/*}
|
||||
var file = await ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite);
|
||||
return file.AsStream();
|
||||
/*}
|
||||
var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
||||
return file.OpenAsync(FileAccess.ReadAndWrite).Result;*/
|
||||
#else
|
||||
return new FileStream(ioc.Path, FileMode.Create, FileAccess.Write,
|
||||
FileShare.None);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public static bool FileExists(IOConnectionInfo ioc)
|
||||
public static async Task<bool> FileExists(IOConnectionInfo ioc)
|
||||
{
|
||||
return FileExists(ioc, false);
|
||||
return await FileExists(ioc, false);
|
||||
}
|
||||
|
||||
public static bool FileExists(IOConnectionInfo ioc, bool bThrowErrors)
|
||||
public static async Task<bool> FileExists(IOConnectionInfo ioc, bool bThrowErrors)
|
||||
{
|
||||
if(ioc == null) { Debug.Assert(false); return false; }
|
||||
|
||||
@@ -520,7 +523,7 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
|
||||
try
|
||||
{
|
||||
Stream s = OpenRead(ioc);
|
||||
Stream s = await OpenRead(ioc);
|
||||
if(s == null) throw new FileNotFoundException();
|
||||
|
||||
try { s.ReadByte(); }
|
||||
@@ -540,13 +543,13 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void DeleteFile(IOConnectionInfo ioc)
|
||||
public static async void DeleteFile(IOConnectionInfo ioc)
|
||||
{
|
||||
RaiseIOAccessPreEvent(ioc, IOAccessType.Delete);
|
||||
|
||||
#if ModernKeePassLibPCL
|
||||
if (!ioc.IsLocalFile()) return;
|
||||
ioc.StorageFile?.DeleteAsync().GetResults();
|
||||
await ioc.StorageFile?.DeleteAsync();
|
||||
/*var file = FileSystem.Current.GetFileFromPathAsync(ioc.Path).Result;
|
||||
file.DeleteAsync().RunSynchronously();*/
|
||||
#else
|
||||
@@ -581,13 +584,13 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
/// </summary>
|
||||
/// <param name="iocFrom">Source file path.</param>
|
||||
/// <param name="iocTo">Target file path.</param>
|
||||
public static void RenameFile(IOConnectionInfo iocFrom, IOConnectionInfo iocTo)
|
||||
public static async void RenameFile(IOConnectionInfo iocFrom, IOConnectionInfo iocTo)
|
||||
{
|
||||
RaiseIOAccessPreEvent(iocFrom, iocTo, IOAccessType.Move);
|
||||
|
||||
#if ModernKeePassLibPCL
|
||||
if (!iocFrom.IsLocalFile()) return;
|
||||
iocFrom.StorageFile?.RenameAsync(iocTo.Path).GetResults();
|
||||
await iocFrom.StorageFile?.RenameAsync(iocTo.Path);
|
||||
/*var file = FileSystem.Current.GetFileFromPathAsync(iocFrom.Path).Result;
|
||||
file.MoveAsync(iocTo.Path).RunSynchronously();*/
|
||||
#else
|
||||
@@ -676,13 +679,13 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
}
|
||||
#endif
|
||||
public static byte[] ReadFile(IOConnectionInfo ioc)
|
||||
public static async Task<byte[]> ReadFile(IOConnectionInfo ioc)
|
||||
{
|
||||
Stream sIn = null;
|
||||
MemoryStream ms = null;
|
||||
try
|
||||
{
|
||||
sIn = IOConnection.OpenRead(ioc);
|
||||
sIn = await OpenRead(ioc);
|
||||
if(sIn == null) return null;
|
||||
|
||||
ms = new MemoryStream();
|
||||
|
@@ -32,6 +32,7 @@ using Windows.Storage;
|
||||
|
||||
using ModernKeePassLibPCL.Interfaces;
|
||||
using ModernKeePassLibPCL.Utility;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModernKeePassLibPCL.Serialization
|
||||
{
|
||||
@@ -306,12 +307,15 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
|
||||
public StorageFile StorageFile { get; set; }
|
||||
|
||||
public bool CanProbablyAccess()
|
||||
public async Task<bool> CanProbablyAccess()
|
||||
{
|
||||
#if ModernKeePassLibPCL
|
||||
if(IsLocalFile())
|
||||
//return (FileSystem.Current.GetFileFromPathAsync(m_strUrl).Result != null);
|
||||
return StorageFile.GetFileFromPathAsync(m_strUrl).GetResults() != null;
|
||||
if (IsLocalFile())
|
||||
{
|
||||
//return (FileSystem.Current.GetFileFromPathAsync(m_strUrl).Result != null);
|
||||
var file = await StorageFile.GetFileFromPathAsync(m_strUrl);
|
||||
return file != null;
|
||||
}
|
||||
#else
|
||||
if(IsLocalFile()) return File.Exists(m_strUrl);
|
||||
#endif
|
||||
|
@@ -57,10 +57,10 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
/// <param name="strFilePath">File to load.</param>
|
||||
/// <param name="kdbFormat">Format specifier.</param>
|
||||
/// <param name="slLogger">Status logger (optional).</param>
|
||||
public void Load(string strFilePath, KdbxFormat kdbFormat, IStatusLogger slLogger)
|
||||
public async void Load(string strFilePath, KdbxFormat kdbFormat, IStatusLogger slLogger)
|
||||
{
|
||||
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFilePath);
|
||||
Load(IOConnection.OpenRead(ioc), kdbFormat, slLogger);
|
||||
Load(await IOConnection.OpenRead(ioc), kdbFormat, slLogger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user