PwDatabase: Save method now preserves the file format (kdbp vs. kdbx)

SaveDb: fixed bug with catching exceptions
Added kdbp Tests
Changed versionCode for new preview release
This commit is contained in:
Philipp Crocoll 2013-07-13 07:57:34 +02:00
parent f06ce9c58b
commit e887ce1db2
5 changed files with 65 additions and 5 deletions

View File

@ -663,7 +663,7 @@ namespace KeePassLib
Debug.Assert(ValidateUuidUniqueness());
Stream s = streamOfOriginalLocation;
KdbxFile kdb = new KdbxFile(this);
kdb.Save(s, null, KdbxFormat.Default, slLogger);
kdb.Save(s, null, KdbpFile.GetFormatToUse(m_ioSource), slLogger);
m_pbHashOfLastIO = kdb.HashOfFileOnDisk;
m_pbHashOfFileOnDisk = kdb.HashOfFileOnDisk;

View File

@ -136,12 +136,24 @@ namespace keepass2android
{
try
{
_workerThread = new Thread(runHandler);
_workerThread = new Thread(() =>
{
try
{
runHandler();
}
catch (Exception e)
{
Kp2aLog.Log("Error in worker thread of SaveDb: " + e);
Finish(false, e.Message);
}
});
_workerThread.Start();
}
catch (Exception e)
{
Kp2aLog.Log("Error in worker thread of SaveDb: "+e);
Kp2aLog.Log("Error starting worker thread of SaveDb: "+e);
Finish(false, e.Message);
}

View File

@ -91,5 +91,11 @@ namespace Kp2aUnitTests
}
[TestMethod]
public void TestLoadKdbpWithPasswordOnly()
{
RunLoadTest("passwordonly.kdbp", DefaultPassword, "");
}
}
}

View File

@ -263,6 +263,48 @@ namespace Kp2aUnitTests
}
[TestMethod]
public void TestLoadKdbxAndSaveKdbp_TestIdenticalFiles()
{
IKp2aApp app = LoadDatabase(DefaultDirectory + "complexDb.kdbx", "test", null);
//string kdbxXml = DatabaseToXml(app);
newFilename = TestDbDirectory + "tmp_complexDb.kdbp";
if (File.Exists(newFilename))
File.Delete(newFilename);
app.GetDb().KpDatabase.IOConnectionInfo.Path = newFilename;
app.GetDb().SaveData(Application.Context);
IKp2aApp appReloaded = LoadDatabase(newFilename, "test", null);
/*
* Unfortunately we cannot compare the xml because there are slight differences:
* - the order of ProtectedStrings in the xml is different (which is ok)
* - the CustomIconUuids are serialized as Zeros instead of not being serialized (which is ok as well)
string kdbxReloadedXml = DatabaseToXml(appReloaded);
bool areEqual = kdbxXml.Equals(kdbxReloadedXml);
if (!areEqual)
{
using (StreamWriter w1 = File.CreateText(TestDbDirectory + "FromOriginalKdbx.xml"))
{
w1.Write(kdbxXml);
}
using (StreamWriter w2 = File.CreateText(TestDbDirectory + "FromKdbp.xml"))
{
w2.Write(kdbxReloadedXml);
}
}
Assert.IsTrue(areEqual, "reloaded->xml differs from loaded->xml");
*/
AssertDatabasesAreEqual(app.GetDb().KpDatabase, appReloaded.GetDb().KpDatabase);
}
private class OnCloseToStringMemoryStream : MemoryStream

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="15"
android:versionName="0.8.4 preview"
android:versionCode="16"
android:versionName="0.8.4 preview 2"
package="keepass2android.keepass2android"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14" />