public static DatabaseConfig GetKPRPCConfig(this PwDatabase db) { if (!db.CustomData.Exists("KeePassRPC.Config")) { // Set custom data and migrate the old config custom data to this // version (but don't save the DB - we can do this again and again until // user decides to save a change for another reason) var newConfig = new DatabaseConfig(); if (db.CustomData.Exists("KeePassRPC.KeeFox.rootUUID")) { newConfig.RootUUID = db.CustomData.Get("KeePassRPC.KeeFox.rootUUID"); } db.SetKPRPCConfig(newConfig); return(newConfig); } else { try { return((DatabaseConfig)Jayrock.Json.Conversion.JsonConvert.Import(typeof(DatabaseConfig), db.CustomData.Get("KeePassRPC.Config"))); } catch (Exception) { // Reset to default config because the current stored config is corrupt var newConfig = new DatabaseConfig(); db.SetKPRPCConfig(newConfig); return(newConfig); } } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (ParentForm != null) { ParentForm.FormClosing += delegate(object aSender, FormClosingEventArgs aEventArgs) { if (ParentForm.DialogResult == DialogResult.OK) { config.DefaultMatchAccuracy = DetermineDefaultMatchAccuracy(); config.MatchedURLAccuracyOverrides = DetermineMatchedURLAccuracyOverrides(); config.DefaultPlaceholderHandling = DetermineDefaultPlaceholderHandling(); database.SetKPRPCConfig(config); } }; } }
/// <summary> /// Called when [file new]. /// </summary> /// <remarks>Review whenever private KeePass.MainForm.OnFileNew method changes. Last reviewed 20180416</remarks> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> internal void CreateNewDatabase() { if (!AppPolicy.Try(AppPolicyId.SaveFile)) { return; } DialogResult dr; string strPath; using (SaveFileDialog sfd = UIUtil.CreateSaveFileDialog(KPRes.CreateNewDatabase, KPRes.NewDatabaseFileName, UIUtil.CreateFileTypeFilter( AppDefs.FileExtension.FileExt, KPRes.KdbxFiles, true), 1, AppDefs.FileExtension.FileExt, false)) { GlobalWindowManager.AddDialog(sfd); dr = sfd.ShowDialog(_host.MainWindow); GlobalWindowManager.RemoveDialog(sfd); strPath = sfd.FileName; } if (dr != DialogResult.OK) { return; } KeePassLib.Keys.CompositeKey key = null; bool showUsualKeePassKeyCreationDialog = false; using (KeyCreationSimpleForm kcsf = new KeyCreationSimpleForm()) { // Don't show the simple key creation form if the user has set // security policies that restrict the allowable composite key sources if (KeePass.Program.Config.UI.KeyCreationFlags == 0) { kcsf.InitEx(KeePassLib.Serialization.IOConnectionInfo.FromPath(strPath), true); dr = kcsf.ShowDialog(_host.MainWindow); if ((dr == DialogResult.Cancel) || (dr == DialogResult.Abort)) { return; } if (dr == DialogResult.No) { showUsualKeePassKeyCreationDialog = true; } else { key = kcsf.CompositeKey; } } else { showUsualKeePassKeyCreationDialog = true; } if (showUsualKeePassKeyCreationDialog) { using (KeyCreationForm kcf = new KeyCreationForm()) { kcf.InitEx(KeePassLib.Serialization.IOConnectionInfo.FromPath(strPath), true); dr = kcf.ShowDialog(_host.MainWindow); if ((dr == DialogResult.Cancel) || (dr == DialogResult.Abort)) { return; } key = kcf.CompositeKey; } } PwDocument dsPrevActive = _host.MainWindow.DocumentManager.ActiveDocument; PwDatabase pd = _host.MainWindow.DocumentManager.CreateNewDocument(true).Database; pd.New(KeePassLib.Serialization.IOConnectionInfo.FromPath(strPath), key); if (!string.IsNullOrEmpty(kcsf.DatabaseName)) { pd.Name = kcsf.DatabaseName; pd.NameChanged = DateTime.Now; } InsertStandardKeePassData(pd); var conf = pd.GetKPRPCConfig(); pd.SetKPRPCConfig(conf); // save the new database & update UI appearance pd.Save(_host.MainWindow.CreateStatusBarLogger()); } _host.MainWindow.UpdateUI(true, null, true, null, true, null, false); }