public override void PrepareForSaving(PwEntry entry) { entry.Strings.Set(PwDefs.UrlField, new ProtectedString(false, entry.Strings.ReadSafe(strUiDatabaseFile))); entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, entry.Strings.ReadSafe(strUiKeyFile))); entry.Strings.Remove(strUiDatabaseFile); entry.Strings.Remove(strUiKeyFile); Dictionary <string, bool> devices = new Dictionary <string, bool>(); foreach (string key in entry.Strings.GetKeys()) { if (key.StartsWith(strUiIfDevice)) { string device = key.Substring(strUiIfDevice.Length); devices[device] = entry.Strings.ReadSafe(key).Equals("true", StringComparison.OrdinalIgnoreCase); } } entry.Strings.Set(KeeAutoExecExt._ifDevice, new ProtectedString(false, KeeAutoExecExt.BuildIfDevice(devices))); foreach (string device in devices.Keys) { entry.Strings.Remove(strUiIfDevice + device); } base.PrepareForSaving(entry); }
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(); }