/// <summary> /// Called when [file new]. /// </summary> /// <remarks>Review whenever private KeePass.MainForm.OnFileNew method changes. Last reviewed 20150523</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; SaveFileDialog sfd = UIUtil.CreateSaveFileDialog(KPRes.CreateNewDatabase, KPRes.NewDatabaseFileName, UIUtil.CreateFileTypeFilter( AppDefs.FileExtension.FileExt, KPRes.KdbxFiles, true), 1, AppDefs.FileExtension.FileExt, false); GlobalWindowManager.AddDialog(sfd); DialogResult dr = sfd.ShowDialog(_host.MainWindow); GlobalWindowManager.RemoveDialog(sfd); string strPath = sfd.FileName; if (dr != DialogResult.OK) return; KeePassLib.Keys.CompositeKey key = null; KeyCreationSimpleForm kcsf = new KeyCreationSimpleForm(); bool showUsualKeePassKeyCreationDialog = false; // 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) { 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); InstallKeeFoxSampleEntries(pd, false); pd.CustomData.Set("KeePassRPC.KeeFox.configVersion", CurrentConfigVersion); // save the new database & update UI appearance pd.Save(_host.MainWindow.CreateStatusBarLogger()); _host.MainWindow.UpdateUI(true, null, true, null, true, null, false); }
/// <summary> /// Called when [file new]. /// </summary> /// <remarks>Review whenever private KeePass.MainForm.OnFileNew method changes.</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; SaveFileDialog sfd = UIUtil.CreateSaveFileDialog(KPRes.CreateNewDatabase, KPRes.NewDatabaseFileName, UIUtil.CreateFileTypeFilter( AppDefs.FileExtension.FileExt, KPRes.KdbxFiles, true), 1, AppDefs.FileExtension.FileExt, false); GlobalWindowManager.AddDialog(sfd); DialogResult dr = sfd.ShowDialog(_host.MainWindow); GlobalWindowManager.RemoveDialog(sfd); string strPath = sfd.FileName; if (dr != DialogResult.OK) return; KeePassLib.Keys.CompositeKey key; KeyCreationSimpleForm kcsf = new KeyCreationSimpleForm(); 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) { 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; } else { key = kcsf.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); InstallKeeFoxSampleEntries(pd); // save the new database & update UI appearance pd.Save(_host.MainWindow.CreateStatusBarLogger()); _host.MainWindow.UpdateUI(true, null, true, null, true, null, false); }