Added unit tests (all passing unfortunately)

UI improvements
Write mode still doesn't work
This commit is contained in:
2017-09-25 18:34:27 +02:00
parent 34996da19d
commit 22ea657885
72 changed files with 2563 additions and 63 deletions

View File

@@ -87,9 +87,9 @@ namespace ModernKeePassLibPCL.Keys
Construct(iocKeyFile, bThrowIfDbFile);
}
private async void Construct(IOConnectionInfo iocFile, bool bThrowIfDbFile)
private void Construct(IOConnectionInfo iocFile, bool bThrowIfDbFile)
{
byte[] pbFileData = await IOConnection.ReadFile(iocFile);
byte[] pbFileData = IOConnection.ReadFile(iocFile);
if(pbFileData == null) throw new FileNotFoundException();
if(bThrowIfDbFile && (pbFileData.Length >= 8))
@@ -310,7 +310,7 @@ namespace ModernKeePassLibPCL.Keys
return pbKeyData;
}
private static async void CreateXmlKeyFile(string strFile, byte[] pbKeyData)
private static void CreateXmlKeyFile(string strFile, byte[] pbKeyData)
{
Debug.Assert(strFile != null);
if(strFile == null) throw new ArgumentNullException("strFile");
@@ -318,7 +318,7 @@ namespace ModernKeePassLibPCL.Keys
if(pbKeyData == null) throw new ArgumentNullException("pbKeyData");
IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile);
var sOut = await IOConnection.OpenWrite(ioc);
var sOut = IOConnection.OpenWrite(ioc);
#if ModernKeePassLibPCL
var settings = new XmlWriterSettings() { Encoding = StrUtil.Utf8 };

View File

@@ -566,7 +566,7 @@ namespace ModernKeePassLibPCL
/// <param name="ioSource">IO connection to load the database from.</param>
/// <param name="pwKey">Key used to open the specified database.</param>
/// <param name="slLogger">Logger, which gets all status messages.</param>
public async void Open(IOConnectionInfo ioSource, CompositeKey pwKey,
public void Open(IOConnectionInfo ioSource, CompositeKey pwKey,
IStatusLogger slLogger)
{
Debug.Assert(ioSource != null);
@@ -589,7 +589,7 @@ namespace ModernKeePassLibPCL
KdbxFile kdbx = new KdbxFile(this);
kdbx.DetachBinaries = m_strDetachBins;
var s = await IOConnection.OpenRead(ioSource);
var s = IOConnection.OpenRead(ioSource);
kdbx.Load(s, KdbxFormat.Default, slLogger);
s.Dispose();
@@ -612,7 +612,7 @@ namespace ModernKeePassLibPCL
/// it has been opened from.
/// </summary>
/// <param name="slLogger">Logger that recieves status information.</param>
public async void Save(IStatusLogger slLogger)
public void Save(IStatusLogger slLogger)
{
Debug.Assert(ValidateUuidUniqueness());
@@ -622,7 +622,7 @@ namespace ModernKeePassLibPCL
{
FileTransactionEx ft = new FileTransactionEx(m_ioSource,
m_bUseFileTransactions);
var s = await ft.OpenWrite();
var s = ft.OpenWrite();
KdbxFile kdb = new KdbxFile(this);
kdb.Save(s, null, KdbxFormat.Default, slLogger);

View File

@@ -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

View File

@@ -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()

View File

@@ -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();

View File

@@ -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>