Merge branch 'ProtocolBuffers' of https://git01.codeplex.com/forks/alexvallat/keepass2androidperfopt into AlexVallat/ProtocolBuffers

Conflicts:
	src/KeePassLib2Android/PwDatabase.cs
	src/KeePassLib2Android/Serialization/KdbxFile.Read.cs
This commit is contained in:
Philipp Crocoll 2013-07-09 11:03:31 +02:00
commit 16c08cbe8a
10 changed files with 4238 additions and 13 deletions

View File

@ -47,6 +47,9 @@
<AndroidLinkMode>SdkOnly</AndroidLinkMode> <AndroidLinkMode>SdkOnly</AndroidLinkMode>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="protobuf-net">
<HintPath>..\ProtoBuf\protobuf-net.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@ -127,6 +130,7 @@
<Compile Include="Serialization\KdbxFile.Write.cs" /> <Compile Include="Serialization\KdbxFile.Write.cs" />
<Compile Include="Serialization\IOConnectionInfo.cs" /> <Compile Include="Serialization\IOConnectionInfo.cs" />
<Compile Include="Serialization\OldFormatException.cs" /> <Compile Include="Serialization\OldFormatException.cs" />
<Compile Include="Serialization\ProtoBuf\KdbpFile.cs" />
<Compile Include="Translation\KPControlCustomization.cs" /> <Compile Include="Translation\KPControlCustomization.cs" />
<Compile Include="Translation\KPFormCustomization.cs" /> <Compile Include="Translation\KPFormCustomization.cs" />
<Compile Include="Translation\KPStringTable.cs" /> <Compile Include="Translation\KPStringTable.cs" />

View File

@ -605,8 +605,7 @@ namespace KeePassLib
KdbxFile kdbx = new KdbxFile(this); KdbxFile kdbx = new KdbxFile(this);
kdbx.DetachBinaries = m_strDetachBins; kdbx.DetachBinaries = m_strDetachBins;
kdbx.Load(s, KdbxFormat.Default, slLogger); kdbx.Load(s, KdbpFile.GetFormatToUse(ioSource), slLogger);
s.Close(); s.Close();
m_pbHashOfLastIO = kdbx.HashOfFileOnDisk; m_pbHashOfLastIO = kdbx.HashOfFileOnDisk;
@ -642,7 +641,7 @@ namespace KeePassLib
Stream s = ft.OpenWrite(); Stream s = ft.OpenWrite();
KdbxFile kdb = new KdbxFile(this); KdbxFile kdb = new KdbxFile(this);
kdb.Save(s, null, KdbxFormat.Default, slLogger); kdb.Save(s, null, KdbpFile.GetFormatToUse(m_ioSource), slLogger);
ft.CommitWrite(); ft.CommitWrite();

View File

@ -38,6 +38,7 @@ using KeePassLib.Interfaces;
using KeePassLib.Keys; using KeePassLib.Keys;
using KeePassLib.Resources; using KeePassLib.Resources;
using KeePassLib.Utility; using KeePassLib.Utility;
using keepass2android;
namespace KeePassLib.Serialization namespace KeePassLib.Serialization
{ {
@ -82,7 +83,7 @@ namespace KeePassLib.Serialization
BinaryReaderEx brDecrypted = null; BinaryReaderEx brDecrypted = null;
Stream readerStream = null; Stream readerStream = null;
if(kdbFormat == KdbxFormat.Default) if(kdbFormat == KdbxFormat.Default || kdbFormat == KdbxFormat.ProtocolBuffers)
{ {
br = new BinaryReaderEx(hashedStream, encNoBom, KLRes.FileCorrupted); br = new BinaryReaderEx(hashedStream, encNoBom, KLRes.FileCorrupted);
ReadHeader(br); ReadHeader(br);
@ -134,8 +135,21 @@ namespace KeePassLib.Serialization
else m_randomStream = null; // No random stream for plain-text files else m_randomStream = null; // No random stream for plain-text files
if (m_slLogger != null) if (m_slLogger != null)
m_slLogger.SetText("KP2AKEY_ParsingDatabase", LogStatusType.AdditionalInfo); m_slLogger.SetText("KP2AKEY_ParsingDatabase", LogStatusType.AdditionalInfo);
var stopWatch = Stopwatch.StartNew();
if (kdbFormat == KdbxFormat.ProtocolBuffers)
{
KdbpFile.ReadDocument(m_pwDatabase, readerStream, m_pbProtectedStreamKey, m_pbHashOfHeader);
Kp2aLog.Log(String.Format("KdbpFile.ReadDocument: {0}ms", stopWatch.ElapsedMilliseconds));
}
else
{
ReadXmlStreamed(readerStream, hashedStream); ReadXmlStreamed(readerStream, hashedStream);
// ReadXmlDom(readerStream);
Kp2aLog.Log(String.Format("ReadXmlStreamed: {0}ms", stopWatch.ElapsedMilliseconds));
}
readerStream.Close(); readerStream.Close();
// GC.KeepAlive(br); // GC.KeepAlive(br);
@ -148,6 +162,17 @@ namespace KeePassLib.Serialization
finally { CommonCleanUpRead(sSource, hashedStream); } finally { CommonCleanUpRead(sSource, hashedStream); }
} }
public static void CopyStream(Stream input, Stream output)
{
byte[] buffer = new byte[4096];
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
}
output.Seek(0, SeekOrigin.Begin);
}
private void CommonCleanUpRead(Stream sSource, HashingStreamEx hashedStream) private void CommonCleanUpRead(Stream sSource, HashingStreamEx hashedStream)
{ {
hashedStream.Close(); hashedStream.Close();

View File

@ -45,6 +45,7 @@ using KeePassLib.Keys;
using KeePassLib.Resources; using KeePassLib.Resources;
using KeePassLib.Security; using KeePassLib.Security;
using KeePassLib.Utility; using KeePassLib.Utility;
using keepass2android;
namespace KeePassLib.Serialization namespace KeePassLib.Serialization
{ {
@ -101,7 +102,7 @@ namespace KeePassLib.Serialization
m_pbStreamStartBytes = cr.GetRandomBytes(32); m_pbStreamStartBytes = cr.GetRandomBytes(32);
Stream writerStream; Stream writerStream;
if(m_format == KdbxFormat.Default) if(m_format == KdbxFormat.Default || m_format == KdbxFormat.ProtocolBuffers)
{ {
WriteHeader(hashedStream); // Also flushes the stream WriteHeader(hashedStream); // Also flushes the stream
@ -122,12 +123,24 @@ namespace KeePassLib.Serialization
writerStream = hashedStream; writerStream = hashedStream;
else { Debug.Assert(false); throw new FormatException("KdbFormat"); } else { Debug.Assert(false); throw new FormatException("KdbFormat"); }
var stopWatch = Stopwatch.StartNew();
if (m_format == KdbxFormat.ProtocolBuffers)
{
KdbpFile.WriteDocument(m_pwDatabase, writerStream, m_pbProtectedStreamKey, m_pbHashOfHeader);
}
else
{
m_xmlWriter = new XmlTextWriter(writerStream, encNoBom); m_xmlWriter = new XmlTextWriter(writerStream, encNoBom);
WriteDocument(pgDataSource); WriteDocument(pgDataSource);
m_xmlWriter.Flush(); m_xmlWriter.Flush();
m_xmlWriter.Close(); m_xmlWriter.Close();
}
writerStream.Close(); writerStream.Close();
Kp2aLog.Log(String.Format("{1}: {0}ms", stopWatch.ElapsedMilliseconds, m_format == KdbxFormat.ProtocolBuffers ? "KdbpFile.WriteDocument" : "Xml WriteDocument"));
} }
finally { CommonCleanUpWrite(sSaveTo, hashedStream); } finally { CommonCleanUpWrite(sSaveTo, hashedStream); }
} }

View File

@ -52,7 +52,8 @@ namespace KeePassLib.Serialization
/// <summary> /// <summary>
/// Use this flag when exporting data to a plain-text XML file. /// Use this flag when exporting data to a plain-text XML file.
/// </summary> /// </summary>
PlainXml PlainXml,
ProtocolBuffers
} }
/// <summary> /// <summary>

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -86,7 +86,7 @@ namespace keepass2android.search
} }
catch (Exception e) catch (Exception e)
{ {
System.Diagnostics.Debug.WriteLine("Failed to search for suggestions: " + e.Message); Kp2aLog.Log("Failed to search for suggestions: " + e.Message);
} }
} }
break; break;