From 311316ea5017cb7d4c2dfaa5d5d27d33e0269c68 Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Mon, 18 Jan 2016 04:40:07 +0100 Subject: [PATCH] add template entries when creating a new database --- .../database/edit/AddTemplateEntries.cs | 29 ++++++++++++------- .../database/edit/CreateDB.cs | 5 ++++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/Kp2aBusinessLogic/database/edit/AddTemplateEntries.cs b/src/Kp2aBusinessLogic/database/edit/AddTemplateEntries.cs index 46effba3..f79b7a83 100644 --- a/src/Kp2aBusinessLogic/database/edit/AddTemplateEntries.cs +++ b/src/Kp2aBusinessLogic/database/edit/AddTemplateEntries.cs @@ -292,6 +292,22 @@ namespace keepass2android public override void Run() { StatusLogger.UpdateMessage(UiStringKey.AddingEntry); + List addedEntries; + var templateGroup = AddTemplates(out addedEntries); + + if (addedEntries.Any()) + { + _app.GetDb().Dirty.Add(templateGroup); + + // Commit to disk + SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun); + save.SetStatusLogger(StatusLogger); + save.Run(); + } + } + + public PwGroup AddTemplates(out List addedEntries) + { if (TemplateEntries.GroupBy(e => e.Uuid).Any(g => g.Count() > 1)) { throw new Exception("invalid UUIDs in template list!"); @@ -308,7 +324,7 @@ namespace keepass2android _app.GetDb().Dirty.Add(_app.GetDb().KpDatabase.RootGroup); _app.GetDb().Groups[templateGroup.Uuid] = templateGroup; } - List addedEntries = new List(); + addedEntries = new List(); foreach (var template in TemplateEntries) { @@ -319,16 +335,7 @@ namespace keepass2android addedEntries.Add(entry); _app.GetDb().Entries[entry.Uuid] = entry; } - - if (addedEntries.Any()) - { - _app.GetDb().Dirty.Add(templateGroup); - - // Commit to disk - SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun); - save.SetStatusLogger(StatusLogger); - save.Run(); - } + return templateGroup; } private PwEntry CreateEntry(TemplateEntry template) diff --git a/src/Kp2aBusinessLogic/database/edit/CreateDB.cs b/src/Kp2aBusinessLogic/database/edit/CreateDB.cs index f6ed5e28..f599c7d0 100644 --- a/src/Kp2aBusinessLogic/database/edit/CreateDB.cs +++ b/src/Kp2aBusinessLogic/database/edit/CreateDB.cs @@ -15,6 +15,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file along with Keepass2Android. If not, see . */ +using System.Collections.Generic; using Android.Content; using KeePassLib; using KeePassLib.Serialization; @@ -79,6 +80,10 @@ namespace keepass2android internet.Run(); AddGroup email = AddGroup.GetInstance(_ctx, _app, "eMail", 19, null, db.KpDatabase.RootGroup, null, true); email.Run(); + + List addedEntries; + AddTemplateEntries addTemplates = new AddTemplateEntries(_ctx, _app, null); + addTemplates.AddTemplates(out addedEntries); // Commit changes SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun, _dontSave);