mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-04 08:00:16 -04:00
Added unit tests (all passing unfortunately)
UI improvements Write mode still doesn't work
This commit is contained in:
@@ -123,9 +123,9 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static async Task<LockFileInfo> Load(IOConnectionInfo iocLockFile)
|
||||
public static LockFileInfo Load(IOConnectionInfo iocLockFile)
|
||||
{
|
||||
using (var s = await IOConnection.OpenRead(iocLockFile))
|
||||
using (var s = IOConnection.OpenRead(iocLockFile))
|
||||
try
|
||||
{
|
||||
if(s == null) return null;
|
||||
@@ -158,7 +158,7 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
}
|
||||
|
||||
// Throws on error
|
||||
public static async Task<LockFileInfo> Create(IOConnectionInfo iocLockFile)
|
||||
public static LockFileInfo Create(IOConnectionInfo iocLockFile)
|
||||
{
|
||||
byte[] pbID = CryptoRandom.Instance.GetRandomBytes(16);
|
||||
string strTime = TimeUtil.SerializeUtc(DateTime.Now);
|
||||
@@ -175,11 +175,11 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
sb.AppendLine(lfi.Machine);
|
||||
sb.AppendLine(lfi.Domain);
|
||||
|
||||
using (var s = await IOConnection.OpenWrite(iocLockFile))
|
||||
using (var s = IOConnection.OpenWrite(iocLockFile))
|
||||
{
|
||||
byte[] pbFile = StrUtil.Utf8.GetBytes(sb.ToString());
|
||||
if (s == null) throw new IOException(iocLockFile.GetDisplayName());
|
||||
await s.WriteAsync(pbFile.AsBuffer());
|
||||
s.WriteAsync(pbFile.AsBuffer()).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
return lfi;
|
||||
@@ -193,7 +193,7 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
m_iocLockFile = iocBaseFile.CloneDeep();
|
||||
m_iocLockFile.Path += LockFileExt;
|
||||
|
||||
LockFileInfo lfiEx = LockFileInfo.Load(m_iocLockFile).Result;
|
||||
LockFileInfo lfiEx = LockFileInfo.Load(m_iocLockFile);
|
||||
if(lfiEx != null)
|
||||
{
|
||||
m_iocLockFile = null; // Otherwise Dispose deletes the existing one
|
||||
|
@@ -79,7 +79,7 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
else m_iocTemp = m_iocBase;
|
||||
}
|
||||
|
||||
public async Task<IRandomAccessStream> OpenWrite()
|
||||
public IRandomAccessStream OpenWrite()
|
||||
{
|
||||
if(!m_bTransacted) m_bMadeUnhidden = UrlUtil.UnhideFile(m_iocTemp.Path);
|
||||
else // m_bTransacted
|
||||
@@ -88,7 +88,7 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
catch(Exception) { }
|
||||
}
|
||||
|
||||
return await IOConnection.OpenWrite(m_iocTemp);
|
||||
return IOConnection.OpenWrite(m_iocTemp);
|
||||
}
|
||||
|
||||
public void CommitWrite()
|
||||
|
@@ -422,17 +422,17 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
new Uri(ioc.Path)));
|
||||
}
|
||||
#else
|
||||
public static async Task<IRandomAccessStream> OpenRead(IOConnectionInfo ioc)
|
||||
public static IRandomAccessStream OpenRead(IOConnectionInfo ioc)
|
||||
{
|
||||
RaiseIOAccessPreEvent(ioc, IOAccessType.Read);
|
||||
|
||||
return await OpenReadLocal(ioc);
|
||||
return OpenReadLocal(ioc);
|
||||
}
|
||||
#endif
|
||||
|
||||
private static async Task<IRandomAccessStream> OpenReadLocal(IOConnectionInfo ioc)
|
||||
private static IRandomAccessStream OpenReadLocal(IOConnectionInfo ioc)
|
||||
{
|
||||
return await ioc.StorageFile.OpenAsync(FileAccessMode.Read);
|
||||
return ioc.StorageFile.OpenAsync(FileAccessMode.Read).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
|
||||
@@ -458,17 +458,17 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
return IocStream.WrapIfRequired(s);
|
||||
}
|
||||
#else
|
||||
public static async Task<IRandomAccessStream> OpenWrite(IOConnectionInfo ioc)
|
||||
public static IRandomAccessStream OpenWrite(IOConnectionInfo ioc)
|
||||
{
|
||||
RaiseIOAccessPreEvent(ioc, IOAccessType.Write);
|
||||
|
||||
return await OpenWriteLocal(ioc);
|
||||
return OpenWriteLocal(ioc);
|
||||
}
|
||||
#endif
|
||||
|
||||
private static async Task<IRandomAccessStream> OpenWriteLocal(IOConnectionInfo ioc)
|
||||
private static IRandomAccessStream OpenWriteLocal(IOConnectionInfo ioc)
|
||||
{
|
||||
return await ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite);
|
||||
return ioc.StorageFile.OpenAsync(FileAccessMode.ReadWrite).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public static bool FileExists(IOConnectionInfo ioc)
|
||||
@@ -486,12 +486,12 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
return ioc.StorageFile.IsAvailable;
|
||||
}
|
||||
|
||||
public static async void DeleteFile(IOConnectionInfo ioc)
|
||||
public static void DeleteFile(IOConnectionInfo ioc)
|
||||
{
|
||||
RaiseIOAccessPreEvent(ioc, IOAccessType.Delete);
|
||||
|
||||
if (!ioc.IsLocalFile()) return;
|
||||
await ioc.StorageFile?.DeleteAsync();
|
||||
ioc.StorageFile?.DeleteAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -503,12 +503,12 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
/// </summary>
|
||||
/// <param name="iocFrom">Source file path.</param>
|
||||
/// <param name="iocTo">Target file path.</param>
|
||||
public static async void RenameFile(IOConnectionInfo iocFrom, IOConnectionInfo iocTo)
|
||||
public static void RenameFile(IOConnectionInfo iocFrom, IOConnectionInfo iocTo)
|
||||
{
|
||||
RaiseIOAccessPreEvent(iocFrom, iocTo, IOAccessType.Move);
|
||||
|
||||
if (!iocFrom.IsLocalFile()) return;
|
||||
await iocFrom.StorageFile?.RenameAsync(iocTo.Path);
|
||||
iocFrom.StorageFile?.RenameAsync(iocTo.Path).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
#if (!ModernKeePassLibPCL && !KeePassLibSD && !KeePassRT)
|
||||
@@ -544,13 +544,13 @@ namespace ModernKeePassLibPCL.Serialization
|
||||
catch(Exception) { Debug.Assert(false); }
|
||||
}
|
||||
#endif
|
||||
public static async Task<byte[]> ReadFile(IOConnectionInfo ioc)
|
||||
public static byte[] ReadFile(IOConnectionInfo ioc)
|
||||
{
|
||||
IRandomAccessStream sIn = null;
|
||||
MemoryStream ms = null;
|
||||
try
|
||||
{
|
||||
sIn = await OpenRead(ioc);
|
||||
sIn = OpenRead(ioc);
|
||||
if(sIn == null) return null;
|
||||
|
||||
ms = new MemoryStream();
|
||||
|
@@ -58,10 +58,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 async void Load(string strFilePath, KdbxFormat kdbFormat, IStatusLogger slLogger)
|
||||
public void Load(string strFilePath, KdbxFormat kdbFormat, IStatusLogger slLogger)
|
||||
{
|
||||
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFilePath);
|
||||
Load(await IOConnection.OpenRead(ioc), kdbFormat, slLogger);
|
||||
Load(IOConnection.OpenRead(ioc), kdbFormat, slLogger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user