mirror of
https://github.com/moparisthebest/keepass2android
synced 2025-01-31 07:00:27 -05:00
add template entries when creating a new database
This commit is contained in:
parent
0f46f18ca5
commit
311316ea50
@ -292,6 +292,22 @@ namespace keepass2android
|
|||||||
public override void Run() {
|
public override void Run() {
|
||||||
StatusLogger.UpdateMessage(UiStringKey.AddingEntry);
|
StatusLogger.UpdateMessage(UiStringKey.AddingEntry);
|
||||||
|
|
||||||
|
List<PwEntry> 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<PwEntry> addedEntries)
|
||||||
|
{
|
||||||
if (TemplateEntries.GroupBy(e => e.Uuid).Any(g => g.Count() > 1))
|
if (TemplateEntries.GroupBy(e => e.Uuid).Any(g => g.Count() > 1))
|
||||||
{
|
{
|
||||||
throw new Exception("invalid UUIDs in template list!");
|
throw new Exception("invalid UUIDs in template list!");
|
||||||
@ -308,7 +324,7 @@ namespace keepass2android
|
|||||||
_app.GetDb().Dirty.Add(_app.GetDb().KpDatabase.RootGroup);
|
_app.GetDb().Dirty.Add(_app.GetDb().KpDatabase.RootGroup);
|
||||||
_app.GetDb().Groups[templateGroup.Uuid] = templateGroup;
|
_app.GetDb().Groups[templateGroup.Uuid] = templateGroup;
|
||||||
}
|
}
|
||||||
List<PwEntry> addedEntries = new List<PwEntry>();
|
addedEntries = new List<PwEntry>();
|
||||||
|
|
||||||
foreach (var template in TemplateEntries)
|
foreach (var template in TemplateEntries)
|
||||||
{
|
{
|
||||||
@ -319,16 +335,7 @@ namespace keepass2android
|
|||||||
addedEntries.Add(entry);
|
addedEntries.Add(entry);
|
||||||
_app.GetDb().Entries[entry.Uuid] = entry;
|
_app.GetDb().Entries[entry.Uuid] = entry;
|
||||||
}
|
}
|
||||||
|
return templateGroup;
|
||||||
if (addedEntries.Any())
|
|
||||||
{
|
|
||||||
_app.GetDb().Dirty.Add(templateGroup);
|
|
||||||
|
|
||||||
// Commit to disk
|
|
||||||
SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun);
|
|
||||||
save.SetStatusLogger(StatusLogger);
|
|
||||||
save.Run();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PwEntry CreateEntry(TemplateEntry template)
|
private PwEntry CreateEntry(TemplateEntry template)
|
||||||
|
@ -15,6 +15,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file
|
|||||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
using KeePassLib.Serialization;
|
using KeePassLib.Serialization;
|
||||||
@ -80,6 +81,10 @@ namespace keepass2android
|
|||||||
AddGroup email = AddGroup.GetInstance(_ctx, _app, "eMail", 19, null, db.KpDatabase.RootGroup, null, true);
|
AddGroup email = AddGroup.GetInstance(_ctx, _app, "eMail", 19, null, db.KpDatabase.RootGroup, null, true);
|
||||||
email.Run();
|
email.Run();
|
||||||
|
|
||||||
|
List<PwEntry> addedEntries;
|
||||||
|
AddTemplateEntries addTemplates = new AddTemplateEntries(_ctx, _app, null);
|
||||||
|
addTemplates.AddTemplates(out addedEntries);
|
||||||
|
|
||||||
// Commit changes
|
// Commit changes
|
||||||
SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun, _dontSave);
|
SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun, _dontSave);
|
||||||
save.SetStatusLogger(StatusLogger);
|
save.SetStatusLogger(StatusLogger);
|
||||||
|
Loading…
Reference in New Issue
Block a user