private void AddAutoOpenEntryForDatabase(Database db) { PwGroup autoOpenGroup = null; var rootGroup = App.Kp2a.CurrentDb.KpDatabase.RootGroup; foreach (PwGroup pgSub in rootGroup.Groups) { if (pgSub.Name == "AutoOpen") { autoOpenGroup = pgSub; break; } } if (autoOpenGroup == null) { AddGroup addGroupTask = AddGroup.GetInstance(this, App.Kp2a, "AutoOpen", 1, null, rootGroup, null, true); addGroupTask.Run(); autoOpenGroup = addGroupTask.Group; } PwEntry newEntry = new PwEntry(true, true); newEntry.Strings.Set(PwDefs.TitleField, new ProtectedString(false, App.Kp2a.GetFileStorage(db.Ioc).GetDisplayName(db.Ioc))); newEntry.Strings.Set(PwDefs.UrlField, new ProtectedString(false, TryMakeRelativePath(App.Kp2a.CurrentDb, db.Ioc))); var password = db.KpDatabase.MasterKey.GetUserKey <KcpPassword>(); newEntry.Strings.Set(PwDefs.PasswordField, password == null ? new ProtectedString(true, "") : password.Password); var keyfile = db.KpDatabase.MasterKey.GetUserKey <KcpKeyFile>(); if ((keyfile != null) && (keyfile.Ioc != null)) { newEntry.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, TryMakeRelativePath(App.Kp2a.CurrentDb, keyfile.Ioc))); } newEntry.Strings.Set(KeeAutoExecExt._ifDevice, new ProtectedString(false, KeeAutoExecExt.BuildIfDevice(new Dictionary <string, bool>() { { KeeAutoExecExt.ThisDeviceId, true } }))); var addTask = new AddEntry(this, App.Kp2a, newEntry, autoOpenGroup, new ActionOnFinish(this, (success, message, activity) => (activity as ConfigureChildDatabasesActivity)?.Update())); ProgressTask pt = new ProgressTask(App.Kp2a, this, addTask); pt.Run(); }
public override void Run() { StatusLogger.UpdateMessage(UiStringKey.progress_create); Database db = _app.CreateNewDatabase(_makeCurrent); db.KpDatabase = new KeePassLib.PwDatabase(); if (_key == null) { _key = new CompositeKey(); //use a temporary key which should be changed after creation } db.KpDatabase.New(_ioc, _key, _app.GetFileStorage(_ioc).GetFilenameWithoutPathAndExt(_ioc)); db.KpDatabase.KdfParameters = (new AesKdf()).GetDefaultParameters(); db.KpDatabase.Name = "Keepass2Android Password Database"; //re-set the name of the root group because the PwDatabase uses UrlUtil which is not appropriate for all file storages: db.KpDatabase.RootGroup.Name = _app.GetFileStorage(_ioc).GetFilenameWithoutPathAndExt(_ioc); // Set Database state db.Root = db.KpDatabase.RootGroup; db.SearchHelper = new SearchDbHelper(_app); // Add a couple default groups AddGroup internet = AddGroup.GetInstance(_ctx, _app, "Internet", 1, null, db.KpDatabase.RootGroup, null, true); internet.Run(); AddGroup email = AddGroup.GetInstance(_ctx, _app, "eMail", 19, null, db.KpDatabase.RootGroup, null, true); email.Run(); List <PwEntry> addedEntries; AddTemplateEntries addTemplates = new AddTemplateEntries(_ctx, _app, null); addTemplates.AddTemplates(out addedEntries); // Commit changes SaveDb save = new SaveDb(_ctx, _app, db, OnFinishToRun, _dontSave); save.SetStatusLogger(StatusLogger); _onFinishToRun = null; save.Run(); db.UpdateGlobals(); }