mirror of
https://github.com/moparisthebest/keepass2android
synced 2025-01-10 21:18:18 -05:00
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:
commit
16c08cbe8a
@ -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" />
|
||||
@ -127,6 +130,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" />
|
||||
|
@ -605,8 +605,7 @@ namespace KeePassLib
|
||||
KdbxFile kdbx = new KdbxFile(this);
|
||||
kdbx.DetachBinaries = m_strDetachBins;
|
||||
|
||||
kdbx.Load(s, KdbxFormat.Default, slLogger);
|
||||
|
||||
kdbx.Load(s, KdbpFile.GetFormatToUse(ioSource), slLogger);
|
||||
s.Close();
|
||||
|
||||
m_pbHashOfLastIO = kdbx.HashOfFileOnDisk;
|
||||
@ -642,7 +641,7 @@ namespace KeePassLib
|
||||
Stream s = ft.OpenWrite();
|
||||
|
||||
KdbxFile kdb = new KdbxFile(this);
|
||||
kdb.Save(s, null, KdbxFormat.Default, slLogger);
|
||||
kdb.Save(s, null, KdbpFile.GetFormatToUse(m_ioSource), slLogger);
|
||||
|
||||
ft.CommitWrite();
|
||||
|
||||
|
@ -38,6 +38,7 @@ using KeePassLib.Interfaces;
|
||||
using KeePassLib.Keys;
|
||||
using KeePassLib.Resources;
|
||||
using KeePassLib.Utility;
|
||||
using keepass2android;
|
||||
|
||||
namespace KeePassLib.Serialization
|
||||
{
|
||||
@ -82,7 +83,7 @@ namespace KeePassLib.Serialization
|
||||
BinaryReaderEx brDecrypted = null;
|
||||
Stream readerStream = null;
|
||||
|
||||
if(kdbFormat == KdbxFormat.Default)
|
||||
if(kdbFormat == KdbxFormat.Default || kdbFormat == KdbxFormat.ProtocolBuffers)
|
||||
{
|
||||
br = new BinaryReaderEx(hashedStream, encNoBom, KLRes.FileCorrupted);
|
||||
ReadHeader(br);
|
||||
@ -134,8 +135,21 @@ namespace KeePassLib.Serialization
|
||||
else m_randomStream = null; // No random stream for plain-text files
|
||||
if (m_slLogger != null)
|
||||
m_slLogger.SetText("KP2AKEY_ParsingDatabase", LogStatusType.AdditionalInfo);
|
||||
ReadXmlStreamed(readerStream, hashedStream);
|
||||
// ReadXmlDom(readerStream);
|
||||
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);
|
||||
|
||||
Kp2aLog.Log(String.Format("ReadXmlStreamed: {0}ms", stopWatch.ElapsedMilliseconds));
|
||||
}
|
||||
|
||||
readerStream.Close();
|
||||
// GC.KeepAlive(br);
|
||||
@ -148,6 +162,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();
|
||||
|
@ -45,6 +45,7 @@ using KeePassLib.Keys;
|
||||
using KeePassLib.Resources;
|
||||
using KeePassLib.Security;
|
||||
using KeePassLib.Utility;
|
||||
using keepass2android;
|
||||
|
||||
namespace KeePassLib.Serialization
|
||||
{
|
||||
@ -101,7 +102,7 @@ namespace KeePassLib.Serialization
|
||||
m_pbStreamStartBytes = cr.GetRandomBytes(32);
|
||||
|
||||
Stream writerStream;
|
||||
if(m_format == KdbxFormat.Default)
|
||||
if(m_format == KdbxFormat.Default || m_format == KdbxFormat.ProtocolBuffers)
|
||||
{
|
||||
WriteHeader(hashedStream); // Also flushes the stream
|
||||
|
||||
@ -122,12 +123,24 @@ namespace KeePassLib.Serialization
|
||||
writerStream = hashedStream;
|
||||
else { Debug.Assert(false); throw new FormatException("KdbFormat"); }
|
||||
|
||||
m_xmlWriter = new XmlTextWriter(writerStream, encNoBom);
|
||||
WriteDocument(pgDataSource);
|
||||
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);
|
||||
WriteDocument(pgDataSource);
|
||||
|
||||
m_xmlWriter.Flush();
|
||||
m_xmlWriter.Close();
|
||||
}
|
||||
|
||||
m_xmlWriter.Flush();
|
||||
m_xmlWriter.Close();
|
||||
writerStream.Close();
|
||||
|
||||
Kp2aLog.Log(String.Format("{1}: {0}ms", stopWatch.ElapsedMilliseconds, m_format == KdbxFormat.ProtocolBuffers ? "KdbpFile.WriteDocument" : "Xml WriteDocument"));
|
||||
}
|
||||
finally { CommonCleanUpWrite(sSaveTo, hashedStream); }
|
||||
}
|
||||
|
@ -52,7 +52,8 @@ namespace KeePassLib.Serialization
|
||||
/// <summary>
|
||||
/// Use this flag when exporting data to a plain-text XML file.
|
||||
/// </summary>
|
||||
PlainXml
|
||||
PlainXml,
|
||||
ProtocolBuffers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
1436
src/KeePassLib2Android/Serialization/ProtoBuf/KdbpFile.cs
Normal file
1436
src/KeePassLib2Android/Serialization/ProtoBuf/KdbpFile.cs
Normal file
File diff suppressed because it is too large
Load Diff
BIN
src/ProtoBuf/protobuf-net.dll
Normal file
BIN
src/ProtoBuf/protobuf-net.dll
Normal file
Binary file not shown.
BIN
src/ProtoBuf/protobuf-net.pdb
Normal file
BIN
src/ProtoBuf/protobuf-net.pdb
Normal file
Binary file not shown.
2747
src/ProtoBuf/protobuf-net.xml
Normal file
2747
src/ProtoBuf/protobuf-net.xml
Normal file
File diff suppressed because it is too large
Load Diff
@ -86,7 +86,7 @@ namespace keepass2android.search
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Failed to search for suggestions: " + e.Message);
|
||||
Kp2aLog.Log("Failed to search for suggestions: " + e.Message);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user