Merge branch 'AlexVallat/Keepass2AndroidPerfOpt'

Conflicts:
	src/KeePassLib2Android/Serialization/IOConnection.cs
	src/Kp2aBusinessLogic/IKp2aApp.cs
	src/Kp2aBusinessLogic/database/Database.cs
	src/keepass2android/Resources/Resource.designer.cs
	src/keepass2android/app/App.cs
	src/keepass2android/fileselect/FileSelectActivity.cs
This commit is contained in:
Philipp Crocoll
2013-08-10 20:25:10 +02:00
48 changed files with 1002 additions and 729 deletions

View File

@@ -72,25 +72,6 @@ namespace keepass2android
set { _loaded = value; }
}
public bool Open
{
get { return Loaded && (!Locked); }
}
bool _locked;
public bool Locked
{
get
{
return _locked;
}
set
{
Kp2aLog.Log("Locked=" + _locked);
_locked = value;
}
}
public bool DidOpenFileChange()
{
if (Loaded == false)
@@ -102,7 +83,10 @@ namespace keepass2android
}
public void LoadData(IKp2aApp app, IOConnectionInfo iocInfo, String password, String keyfile, ProgressDialogStatusLogger status)
/// <summary>
/// Do not call this method directly. Call App.Kp2a.LoadDatabase instead.
/// </summary>
public void LoadData(IKp2aApp app, IOConnectionInfo iocInfo, MemoryStream databaseData, String password, String keyfile, ProgressDialogStatusLogger status)
{
PwDatabase pwDatabase = new PwDatabase();
@@ -120,12 +104,13 @@ namespace keepass2android
throw new KeyFileException();
}
}
IFileStorage fileStorage = _app.GetFileStorage(iocInfo);
var filename = fileStorage.GetFilenameWithoutPathAndExt(iocInfo);
try
{
IFileStorage fileStorage = _app.GetFileStorage(iocInfo);
var fileVersion = _app.GetFileStorage(iocInfo).GetCurrentFileVersionFast(iocInfo);
pwDatabase.Open(fileStorage.OpenFileForRead(iocInfo), fileStorage.GetFilenameWithoutPathAndExt(iocInfo), iocInfo, compositeKey, status);
pwDatabase.Open(databaseData ?? fileStorage.OpenFileForRead(iocInfo), filename, iocInfo, compositeKey, status);
LastFileVersion = fileVersion;
}
catch (Exception)
@@ -135,8 +120,13 @@ namespace keepass2android
//if we don't get a password, we don't know whether this means "empty password" or "no password"
//retry without password:
compositeKey.RemoveUserKey(compositeKey.GetUserKey(typeof (KcpPassword)));
pwDatabase.Open(iocInfo, compositeKey, status);
}
if (databaseData != null)
{
databaseData.Seek(0, SeekOrigin.Begin);
}
var fileVersion = _app.GetFileStorage(iocInfo).GetCurrentFileVersionFast(iocInfo);
pwDatabase.Open(databaseData ?? fileStorage.OpenFileForRead(iocInfo), filename, iocInfo, compositeKey, status);
LastFileVersion = fileVersion; }
else throw;
}
@@ -151,15 +141,6 @@ namespace keepass2android
SearchHelper = new SearchDbHelper(app);
}
public bool QuickUnlockEnabled { get; set; }
//KeyLength of QuickUnlock at time of loading the database.
//This is important to not allow an attacker to set the length to 1 when QuickUnlock is started already.
public int QuickUnlockKeyLength
{
get;
set;
}
public PwGroup SearchForText(String str) {
PwGroup group = SearchHelper.SearchForText(this, str);
@@ -225,7 +206,6 @@ namespace keepass2android
Root = null;
KpDatabase = null;
_loaded = false;
_locked = false;
_reloadRequested = false;
}

View File

@@ -79,7 +79,7 @@ namespace keepass2android
else
{
// Let's not bother recovering from a failure to save a deleted entry. It is too much work.
App.SetShutdown();
App.LockDatabase();
}
}, OnFinishToRun);
}
@@ -99,7 +99,7 @@ namespace keepass2android
Db.Dirty.Add(pgRecycleBin);
} else {
// Let's not bother recovering from a failure to save a deleted entry. It is too much work.
App.SetShutdown();
App.LockDatabase();
}
}, OnFinishToRun);

View File

@@ -108,7 +108,7 @@ namespace keepass2android
Db.Dirty.Add(pgParent);
} else {
// Let's not bother recovering from a failure to save a deleted group. It is too much work.
App.SetShutdown();
App.LockDatabase();
}
}, OnFinishToRun);
}
@@ -146,7 +146,7 @@ namespace keepass2android
}
} else {
// Let's not bother recovering from a failure to save a deleted group. It is too much work.
_app.SetShutdown();
_app.LockDatabase();
}
base.Run();

View File

@@ -16,21 +16,25 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
*/
using System;
using System.IO;
using System.Threading.Tasks;
using KeePassLib.Serialization;
namespace keepass2android
{
public class LoadDb : RunnableOnFinish {
private readonly IOConnectionInfo _ioc;
private readonly Task<MemoryStream> _databaseData;
private readonly String _pass;
private readonly String _key;
private readonly IKp2aApp _app;
private readonly bool _rememberKeyfile;
public LoadDb(IKp2aApp app, IOConnectionInfo ioc, String pass, String key, OnFinish finish): base(finish)
public LoadDb(IKp2aApp app, IOConnectionInfo ioc, Task<MemoryStream> databaseData, String pass, String key, OnFinish finish): base(finish)
{
_app = app;
_ioc = ioc;
_databaseData = databaseData;
_pass = pass;
_key = key;
@@ -44,7 +48,7 @@ namespace keepass2android
try
{
StatusLogger.UpdateMessage(UiStringKey.loading_database);
_app.GetDb().LoadData (_app, _ioc, _pass, _key, StatusLogger);
_app.LoadDatabase(_ioc, _databaseData == null ? null : _databaseData.Result, _pass, _key, StatusLogger);
SaveFileData (_ioc, _key);
} catch (KeyFileException) {