Strictly for experimentation. When saving a databse, it will be saved in protocol buffer format. Opening will work for either xml or protocol buffers.

This commit is contained in:
AlexVallat 2013-06-21 18:28:49 +01:00
parent 0b1f372a02
commit 41e9c80456
7 changed files with 4220 additions and 2 deletions

View File

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

View File

@ -127,8 +127,34 @@ namespace KeePassLib.Serialization
}
else m_randomStream = null; // No random stream for plain-text files
ReadXmlStreamed(readerStream, hashedStream);
// ReadXmlDom(readerStream);
// Test: read to memory
var stopWatch = Stopwatch.StartNew();
var memStream = new MemoryStream((int)hashedStream.Length);
CopyStream(readerStream, memStream);
readerStream.Close();
readerStream = memStream;
System.Diagnostics.Debug.WriteLine(String.Format("Copy input stream: {0}ms", stopWatch.ElapsedMilliseconds));
var isXml = memStream.ReadByte() == '<';
memStream.Seek(0, SeekOrigin.Begin);
if (isXml)
{
stopWatch.Restart();
ReadXmlStreamed(readerStream, hashedStream);
System.Diagnostics.Debug.WriteLine(String.Format("ReadXmlStreamed: {0}ms", stopWatch.ElapsedMilliseconds));
}
else
{
stopWatch.Restart();
KdbpFile.ReadDocument(m_pwDatabase, readerStream, m_pbProtectedStreamKey, m_pbHashOfHeader);
System.Diagnostics.Debug.WriteLine(String.Format("KdbpFile.ReadDocument: {0}ms", stopWatch.ElapsedMilliseconds));
}
readerStream.Close();
// GC.KeepAlive(br);
@ -141,6 +167,17 @@ namespace KeePassLib.Serialization
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)
{
hashedStream.Close();

View File

@ -122,11 +122,16 @@ namespace KeePassLib.Serialization
writerStream = hashedStream;
else { Debug.Assert(false); throw new FormatException("KdbFormat"); }
/*
m_xmlWriter = new XmlTextWriter(writerStream, encNoBom);
WriteDocument(pgDataSource);
m_xmlWriter.Flush();
m_xmlWriter.Close();
*/
KdbpFile.WriteDocument(m_pwDatabase, writerStream, m_pbProtectedStreamKey, m_pbHashOfHeader);
writerStream.Close();
}
finally { CommonCleanUpWrite(sSaveTo, hashedStream); }

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