void CSafeCombinationEntry::OnNewDbClick( wxCommandEvent& /* evt */ ) { // 1. Get a filename from a file dialog box // 2. Get a password // 3. Set m_filespec && m_passkey to returned value! wxString newfile; wxString cs_msg, cs_title, cs_temp; wxString cf(wxT("pwsafe")); // reasonable default for first time user stringT v3FileName = PWSUtil::GetNewFileName(tostdstring(cf), wxT("psafe3")); stringT dir = PWSdirs::GetSafeDir(); while (1) { wxFileDialog fd(this, _("Please choose a name for the new database"), dir.c_str(), v3FileName.c_str(), _("Password Safe Databases (*.psafe3; *.dat)|*.psafe3;*.dat| All files (*.*; *)|*.*;*"), (wxFD_SAVE | wxFD_OVERWRITE_PROMPT| wxFD_CHANGE_DIR)); int rc = fd.ShowModal(); if (rc == wxID_OK) { wxFileName wxfn(fd.GetPath()); if (wxfn.GetExt().empty()) { wxfn.SetExt(DEFAULT_SUFFIX); } newfile = wxfn.GetFullPath(); break; } else return; } // 2. Get a password CSafeCombinationSetup pksetup(this); int rc = pksetup.ShowModal(); if (rc != wxID_OK) return; //User cancelled password entry // 3. Set m_filespec && m_passkey to returned value! m_core.SetCurFile(tostringx(newfile)); // Now lock the new file std::wstring locker(L""); // null init is important here m_core.LockFile(tostdstring(newfile), locker); m_core.SetReadOnly(false); // new file can't be read-only... m_core.NewFile(tostringx(pksetup.GetPassword())); if ((rc = m_core.WriteCurFile()) == PWSfile::SUCCESS) { wxGetApp().recentDatabases().AddFileToHistory(newfile); EndModal(wxID_OK); } else { wxMessageBox(wxString()<< newfile << wxT("\n\n") << _("Could not open file for writing!"), _("Write Error"), wxOK | wxICON_ERROR, this); } }
void CPasskeyEntry::OnCreateDb() { // 1. Get a filename from a file dialog box // 2. Get a password // 3. Set m_filespec && m_passkey to returned value! INT_PTR rc; CString newfile; CString cs_msg, cs_title, cs_temp; CString cs_text(MAKEINTRESOURCE(IDS_CREATENAME)); CString cf(MAKEINTRESOURCE(IDS_DEFDBNAME)); // reasonable default for first time user std::wstring v3FileName = PWSUtil::GetNewFileName(LPCWSTR(cf), DEFAULT_SUFFIX); std::wstring dir; DboxMain *pDbx = (DboxMain*)GetParent(); if (pDbx->GetCurFile().empty()) dir = PWSdirs::GetSafeDir(); else { std::wstring cdrive, cdir, dontCare; pws_os::splitpath(pDbx->GetCurFile().c_str(), cdrive, cdir, dontCare, dontCare); dir = cdrive + cdir; } while (1) { CPWFileDialog fd(FALSE, DEFAULT_SUFFIX, v3FileName.c_str(), OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_LONGNAMES | OFN_OVERWRITEPROMPT, CString(MAKEINTRESOURCE(IDS_FDF_V3_ALL)), this); fd.m_ofn.lpstrTitle = cs_text; if (!dir.empty()) fd.m_ofn.lpstrInitialDir = dir.c_str(); rc = fd.DoModal(); if (((DboxMain*)GetParent())->ExitRequested()) { // If U3ExitNow called while in CPWFileDialog, // PostQuitMessage makes us return here instead // of exiting the app. Try resignalling PostQuitMessage(0); return; } if (rc == IDOK) { newfile = fd.GetPathName(); break; } else return; } // 2. Get a password CPasskeySetup pksetup(this, *app.GetCore()); rc = pksetup.DoModal(); if (rc == IDOK) m_passkey = pksetup.GetPassKey(); else return; //User cancelled password entry // 3. Set m_filespec && m_passkey to returned value! m_filespec = newfile; ((CEdit*)GetDlgItem(IDC_PASSKEY))->SetWindowText(m_passkey); m_status = TAR_NEW; CPWDialog::OnOK(); }