bug fixes and improvements after adding multi-database support

This commit is contained in:
Philipp Crocoll
2018-10-25 06:03:08 +02:00
parent a2dab72b25
commit 4f3f18a0ad
25 changed files with 501 additions and 291 deletions

View File

@@ -88,8 +88,10 @@ namespace keepass2android
save.SetStatusLogger(StatusLogger);
_onFinishToRun = null;
save.Run();
db.UpdateGlobals();
}
}

View File

@@ -21,6 +21,7 @@ namespace keepass2android
//determine once. The property is queried for each delete operation, but might return false
//after one entry/group is deleted (and thus in recycle bin and thus can't be recycled anymore)
_canRecycle = DetermineCanRecycle();
ShowDatabaseIocInStatus = true;
}
private bool DetermineCanRecycle()

View File

@@ -121,25 +121,27 @@ namespace keepass2android
public void Start()
{
if (CanRecycle)
string messageSuffix = ShowDatabaseIocInStatus ? "(" + App.GetFileStorage(Db.Ioc).GetDisplayName(Db.Ioc) + ")" : "";
if (CanRecycle)
{
App.AskYesNoCancel(UiStringKey.AskDeletePermanently_title,
QuestionRecycleResourceId,
(dlgSender, dlgEvt) =>
{
DeletePermanently = true;
ProgressTask pt = new ProgressTask(App, Ctx, this);
pt.Run();
DeletePermanently = true;
ProgressTask pt = new ProgressTask(App, Ctx, this);
pt.Run();
},
(dlgSender, dlgEvt) =>
{
DeletePermanently = false;
ProgressTask pt = new ProgressTask(App, Ctx, this);
pt.Run();
DeletePermanently = false;
ProgressTask pt = new ProgressTask(App, Ctx, this);
pt.Run();
},
(dlgSender, dlgEvt) => { },
Ctx);
Ctx, messageSuffix);
@@ -150,12 +152,12 @@ namespace keepass2android
QuestionNoRecycleResourceId,
(dlgSender, dlgEvt) =>
{
ProgressTask pt = new ProgressTask(App, Ctx, this);
pt.Run();
ProgressTask pt = new ProgressTask(App, Ctx, this);
pt.Run();
},
null,
(dlgSender, dlgEvt) => { },
Ctx);
Ctx, messageSuffix);
}
@@ -234,13 +236,21 @@ namespace keepass2android
// Commit database
SaveDb save = new SaveDb(Ctx, App, Db, OnFinishToRun, false);
save.SetStatusLogger(StatusLogger);
save.ShowDatabaseIocInStatus = ShowDatabaseIocInStatus;
save.SetStatusLogger(StatusLogger);
save.Run();
}
protected abstract void PerformDelete(List<PwGroup> touchedGroups, List<PwGroup> permanentlyDeletedGroups);
public bool ShowDatabaseIocInStatus
{
get;
set;
}
protected abstract void PerformDelete(List<PwGroup> touchedGroups, List<PwGroup> permanentlyDeletedGroups);
public abstract UiStringKey StatusMessage { get; }

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Android.App;
@@ -50,11 +51,20 @@ namespace keepass2android.database.edit
}
HashSet<Database> removeDatabases = new HashSet<Database>();
Database addDatabase = _app.FindDatabaseForGroupId(_targetGroup.Uuid);
if (addDatabase == null)
{
Finish(false, "Did not find target database. Did you lock it?");
return;
}
foreach (var elementToMove in _elementsToMove)
{
_app.DirtyGroups.Add(elementToMove.ParentGroup);
//TODO is this safe when transferring between databases?
PwGroup pgParent = elementToMove.ParentGroup;
if (pgParent != _targetGroup)
{
@@ -63,8 +73,12 @@ namespace keepass2android.database.edit
PwEntry entry = elementToMove as PwEntry;
if (entry != null)
{
var dbRem = _app.FindDatabaseForEntryId(entry.Uuid);
removeDatabases.Add(dbRem);
dbRem.Entries.Remove(entry.Uuid);
pgParent.Entries.Remove(entry);
_targetGroup.AddEntry(entry, true, true);
addDatabase.Entries.Add(entry.Uuid, entry);
}
else
{
@@ -74,30 +88,58 @@ namespace keepass2android.database.edit
Finish(false, _app.GetResourceString(UiStringKey.CannotMoveGroupHere));
return;
}
var dbRem = _app.FindDatabaseForEntryId(@group.Uuid);
if (dbRem == null)
{
Finish(false, "Did not find source database. Did you lock it?");
return;
}
dbRem.Groups.Remove(group.Uuid);
removeDatabases.Add(dbRem);
pgParent.Groups.Remove(group);
_targetGroup.AddGroup(group, true, true);
addDatabase.Groups.Add(group.Uuid, group);
}
}
}
}
_onFinishToRun = new ActionOnFinish(ActiveActivity, (success, message, activity) =>
{
if (!success)
{ // Let's not bother recovering from a failure.
_app.Lock(false);
}
}, OnFinishToRun);
//Unchecked
//TODO save the right database
//first save the database where we added the elements
var allDatabasesToSave = new List<Database> {addDatabase};
//then all databases where we removed elements:
removeDatabases.RemoveWhere(db => db == addDatabase);
allDatabasesToSave.AddRange(removeDatabases);
// Save
SaveDb save = new SaveDb(_ctx, _app, _app.CurrentDb, OnFinishToRun, false);
save.SetStatusLogger(StatusLogger);
save.Run();
int indexToSave = 0;
bool allSavesSuccess = true;
void ContinueSave(bool success, string message, Activity activeActivity)
{
allSavesSuccess &= success;
indexToSave++;
if (indexToSave == allDatabasesToSave.Count)
{
OnFinishToRun.SetResult(allSavesSuccess);
OnFinishToRun.Run();
return;
}
SaveDb saveDb = new SaveDb(_ctx, _app, allDatabasesToSave[indexToSave], new ActionOnFinish(activeActivity, ContinueSave), false);
saveDb.SetStatusLogger(StatusLogger);
saveDb.ShowDatabaseIocInStatus = allDatabasesToSave.Count > 1;
saveDb.Run();
}
SaveDb save = new SaveDb(_ctx, _app, allDatabasesToSave[0], new ActionOnFinish(ActiveActivity, ContinueSave), false);
save.SetStatusLogger(StatusLogger);
save.ShowDatabaseIocInStatus = allDatabasesToSave.Count > 1;
save.Run();
}
}
}

View File

@@ -79,9 +79,10 @@ namespace keepass2android
_db = db;
_dontSave = false;
}
public override void Run ()
public bool ShowDatabaseIocInStatus { get; set; }
public override void Run ()
{
if (!_dontSave)
@@ -95,7 +96,13 @@ namespace keepass2android
return;
}
StatusLogger.UpdateMessage(UiStringKey.saving_database);
string message = _app.GetResourceString(UiStringKey.saving_database);
if (ShowDatabaseIocInStatus)
message += " (" + _app.GetFileStorage(_db.Ioc).GetDisplayName(_db.Ioc) + ")";
StatusLogger.UpdateMessage(message);
IOConnectionInfo ioc = _db.Ioc;
IFileStorage fileStorage = _app.GetFileStorage(ioc);