int PwsafeApp::OnExit() { m_idleTimer->Stop(); recentDatabases().Save(); PWSprefs *prefs = PWSprefs::GetInstance(); if (!m_core.GetCurFile().empty()) prefs->SetPref(PWSprefs::CurrentFile, m_core.GetCurFile()); // Save Application related preferences prefs->SaveApplicationPreferences(); // Save shortcuts, if changed PWSMenuShortcuts::GetShortcutsManager()->SaveUserShortcuts(); PWSMenuShortcuts::DestroyShortcutsManager(); ////@begin PwsafeApp cleanup return wxApp::OnExit(); ////@end PwsafeApp cleanup }
bool PwsafeApp::OnInit() { //Used by help subsystem wxFileSystem::AddHandler(new wxArchiveFSHandler); SetAppName(pwsafeAppName); m_core.SetApplicationNameAndVersion(tostdstring(pwsafeAppName), DWORD((MINORVERSION << 16) | MAJORVERSION)); PWSprefs::SetReporter(&aReporter); PWScore::SetReporter(&aReporter); PWScore::SetAsker(&anAsker); #if wxUSE_XPM wxImage::AddHandler(new wxXPMHandler); #endif #if wxUSE_LIBPNG wxImage::AddHandler(new wxPNGHandler); #endif #if wxUSE_LIBJPEG wxImage::AddHandler(new wxJPEGHandler); #endif #if wxUSE_GIF wxImage::AddHandler(new wxGIFHandler); #endif // Get progname wxString progName(argv[0]); progName = progName.AfterLast(wxChar('/')); // Parse command line wxCmdLineParser cmdParser(cmdLineDesc, argc, argv); int res = cmdParser.Parse(); if (res != 0) return false; // Don't allow ptrace or gdump on release build if (!pws_os::DisableDumpAttach()) return false; // Parse command line options: wxString filename, user, host, cfg_file; bool cmd_ro = cmdParser.Found(wxT("r")); // Next variable currently not referenced bool cmd_encrypt = cmdParser.Found(wxT("e"), &filename); bool cmd_decrypt = cmdParser.Found(wxT("d"), &filename); bool cmd_closed = cmdParser.Found(wxT("c")); bool cmd_silent = cmdParser.Found(wxT("s")); bool cmd_minimized = cmdParser.Found(wxT("m")); bool cmd_user = cmdParser.Found(wxT("u"), &user); bool cmd_host = cmdParser.Found(wxT("h"), &host); bool cmd_cfg = cmdParser.Found(wxT("g"), &cfg_file); bool file_in_cmd = false; size_t count = cmdParser.GetParamCount(); if (count == 1) { filename = cmdParser.GetParam(); file_in_cmd = true; } else if (count > 1) { cmdParser.Usage(); return false; } // check for mutually exclusive options if (((cmd_encrypt + cmd_decrypt) > 1) || ((cmd_closed + cmd_silent + cmd_minimized) > 1)) { cmdParser.Usage(); return false; } if (cmd_user) SysInfo::GetInstance()->SetEffectiveUser(tostdstring(user)); if (cmd_host) SysInfo::GetInstance()->SetEffectiveHost(tostdstring(host)); if (cmd_cfg) PWSprefs::SetConfigFile(tostdstring(cfg_file)); m_core.SetReadOnly(cmd_ro); // OK to load prefs now PWSprefs *prefs = PWSprefs::GetInstance(); // Initialize language only after parsing cmd_cfg and instantiating prefs, // otherwise GetSelectedLanguage()&Co will instantiate prefs singleton and it // will ignore config file parameter wxLanguage selectedLang = GetSelectedLanguage(); m_locale->Init(selectedLang); ActivateLanguage(selectedLang, false); // if filename passed in command line, it takes precedence // over that in preference: if (filename.empty()) { filename = prefs->GetPref(PWSprefs::CurrentFile).c_str(); } else { recentDatabases().AddFileToHistory(filename); } m_core.SetCurFile(tostringx(filename)); m_core.SetApplicationNameAndVersion(tostdstring(progName), MAKEWORD(MINORVERSION, MAJORVERSION)); static wxSingleInstanceChecker appInstance; if (!prefs->GetPref(PWSprefs::MultipleInstances) && (appInstance.Create(wxT("pwsafe.lck"), towxstring(pws_os::getuserprefsdir())) && appInstance.IsAnotherRunning())) { wxMessageBox(_("Another instance of Password Safe is already running"), _("Password Safe"), wxOK|wxICON_INFORMATION); return false; } #if defined(__X__) || defined(__WXGTK__) PWSclipboard::GetInstance()->UsePrimarySelection(prefs->GetPref(PWSprefs::UsePrimarySelectionForClipboard)); #endif // here if we're the child recentDatabases().Load(); if (cmd_closed || cmd_minimized) { m_core.SetCurFile(L""); } if (cmd_silent) { if ( wxTaskBarIcon::IsAvailable() ) { // start silent implies use system tray. // Note that if UseSystemTray is already true, then pwsafe will try to run silently anyway PWSprefs::GetInstance()->SetPref(PWSprefs::UseSystemTray, true); } else { // We don't want to bring up a UI if running silently std::wcerr << L"There appears to be no system tray support in your current environment. pwsafe may not work as expected in silent mode." << std::endl; } } m_appIcons.AddIcon(pwsafe16); m_appIcons.AddIcon(pwsafe32); m_appIcons.AddIcon(pwsafe48); if (!m_helpController) { // helpController (re)created on language activation std::wcerr << L"Could not initialize help subsystem." << std::endl; if (!prefs->GetPref(PWSprefs::IgnoreHelpLoadError) && !cmd_silent) { #if wxCHECK_VERSION(2,9,2) wxRichMessageDialog dlg(NULL, _("Could not initialize help subsystem. Help will not be available."), _("Password Safe: Error initializing help"), wxCENTRE|wxOK|wxICON_EXCLAMATION); dlg.ShowCheckBox(_("Don't show this warning again")); dlg.ShowModal(); if (dlg.IsCheckBoxChecked()) { prefs->SetPref(PWSprefs::IgnoreHelpLoadError, true); prefs->SaveApplicationPreferences(); } #else wxMessageBox(_("Could not initialize help subsystem. Help will not be available."), _("Password Safe: Error initializing help"), wxOK | wxICON_ERROR); #endif } } if (!cmd_closed && !cmd_silent && !cmd_minimized) { // Get the file, r/w mode and password from user // Note that file may be new CSafeCombinationEntry* initWindow = new CSafeCombinationEntry(NULL, m_core); int returnValue = initWindow->ShowModal(); initWindow->Destroy(); if (returnValue != wxID_OK) { return false; } wxASSERT_MSG(!m_frame, wxT("Frame window created unexpectedly")); m_frame = new PasswordSafeFrame(NULL, m_core); m_frame->Load(initWindow->GetPassword()); } else { wxASSERT_MSG(!m_frame, wxT("Frame window created unexpectedly")); m_frame = new PasswordSafeFrame(NULL, m_core); } RestoreFrameCoords(); if (!cmd_silent) m_frame->Show(); if (cmd_minimized) m_frame->Iconize(); else if (cmd_silent) { // Hide UI enumerates top-level windows and its children and hide them, // so we need to set top windows first and only then call hideUI SetTopWindow(m_frame); wxSafeYield(); m_frame->HideUI(false); if (file_in_cmd) { // set locked status if file was passed from command line m_frame->SetTrayStatus(true); } else { m_core.SetCurFile(L""); m_frame->SetTrayClosed(); } } else { SetTopWindow(m_frame); } if (PWSprefs::GetInstance()->GetPref(PWSprefs::UseSystemTray)) m_frame->ShowTrayIcon(); return true; }
void COptions_PropertySheet::UpdateCopyPreferences() { PWSprefs *prefs = PWSprefs::GetInstance(); // Now update the Application preferences. // In PropertyPage alphabetic order // Note: Updating the copy values - especially important for DB preferences!!! // Backup prefs->SetPref(PWSprefs::BackupBeforeEverySave, m_OPTMD.BackupBeforeSave == TRUE, true); prefs->SetPref(PWSprefs::BackupPrefixValue, LPCWSTR(m_OPTMD.UserBackupPrefix), true); prefs->SetPref(PWSprefs::BackupSuffix, (unsigned int)m_OPTMD.BackupSuffix, true); prefs->SetPref(PWSprefs::BackupMaxIncremented, m_OPTMD.MaxNumIncBackups, true); if (!m_OPTMD.UserBackupOtherLocation.IsEmpty()) { // Make sure it ends in a slash! if (m_OPTMD.UserBackupOtherLocation.Right(1) != CSecString(L'\\')) m_OPTMD.UserBackupOtherLocation += L'\\'; } prefs->SetPref(PWSprefs::BackupDir, LPCWSTR(m_OPTMD.UserBackupOtherLocation), true); // Display prefs->SetPref(PWSprefs::AlwaysOnTop, m_OPTMD.AlwaysOnTop == TRUE, true); prefs->SetPref(PWSprefs::ShowNotesAsTooltipsInViews, m_OPTMD.ShowNotesAsTipsInViews == TRUE, true); prefs->SetPref(PWSprefs::ExplorerTypeTree, m_OPTMD.ExplorerTypeTree == TRUE, true); prefs->SetPref(PWSprefs::ListViewGridLines, m_OPTMD.EnableGrid == TRUE, true); prefs->SetPref(PWSprefs::NotesWordWrap, m_OPTMD.WordWrapNotes == TRUE, true); prefs->SetPref(PWSprefs::PreExpiryWarn, m_OPTMD.PreExpiryWarn == TRUE, true); prefs->SetPref(PWSprefs::PreExpiryWarnDays, m_OPTMD.PreExpiryWarnDays, true); prefs->SetPref(PWSprefs::ClosedTrayIconColour, m_OPTMD.TrayIconColour, true); if (m_save_bHighlightChanges != m_OPTMD.HighlightChanges) { prefs->SetPref(PWSprefs::HighlightChanges, m_OPTMD.HighlightChanges == TRUE, true); m_bRefreshViews = true; } // Misc prefs->SetPref(PWSprefs::DeleteQuestion, m_OPTMD.ConfirmDelete == FALSE, true); prefs->SetPref(PWSprefs::EscExits, m_OPTMD.EscExits == TRUE, true); // by strange coincidence, the values of the enums match the indices // of the radio buttons in the following :-) prefs->SetPref(PWSprefs::DoubleClickAction, (unsigned int)m_OPTMD.DoubleClickAction, true); prefs->SetPref(PWSprefs::ShiftDoubleClickAction, (unsigned int)m_OPTMD.ShiftDoubleClickAction, true); prefs->SetPref(PWSprefs::QuerySetDef, m_OPTMD.QuerySetDef == TRUE, true); prefs->SetPref(PWSprefs::AltBrowser, LPCWSTR(m_OPTMD.OtherBrowserLocation), true); prefs->SetPref(PWSprefs::AltBrowserCmdLineParms, LPCWSTR(m_OPTMD.BrowserCmdLineParms), true); prefs->SetPref(PWSprefs::AltNotesEditor, LPCWSTR(m_OPTMD.OtherEditorLocation), true); prefs->SetPref(PWSprefs::MinimizeOnAutotype, m_OPTMD.MinAuto == TRUE, true); prefs->SetPref(PWSprefs::ClearClipboardOnMinimize, m_OPTMD.ClearClipboardOnMinimize == TRUE, true); prefs->SetPref(PWSprefs::ClearClipboardOnExit, m_OPTMD.ClearClipboardOnExit == TRUE, true); prefs->SetPref(PWSprefs::DatabaseClear, m_OPTMD.LockOnMinimize == TRUE, true); prefs->SetPref(PWSprefs::DontAskQuestion, m_OPTMD.ConfirmCopy == FALSE, true); prefs->SetPref(PWSprefs::LockOnWindowLock, m_OPTMD.LockOnWindowLock == TRUE, true); prefs->SetPref(PWSprefs::CopyPasswordWhenBrowseToURL, m_OPTMD.CopyPswdBrowseURL == TRUE, true); prefs->SetPref(PWSprefs::UseSystemTray, m_OPTMD.UseSystemTray == TRUE, true); prefs->SetPref(PWSprefs::HideSystemTray, m_OPTMD.HideSystemTray == TRUE, true); prefs->SetPref(PWSprefs::MaxREItems, m_OPTMD.MaxREItems, true); prefs->SetPref(PWSprefs::MaxMRUItems, m_OPTMD.MaxMRUItems, true); if (m_OPTMD.MaxMRUItems == 0) { // Put them on File menu where they don't take up any room prefs->SetPref(PWSprefs::MRUOnFileMenu, true, true); } else { prefs->SetPref(PWSprefs::MRUOnFileMenu, m_OPTMD.MRUOnFileMenu == TRUE, true); } prefs->SetPref(PWSprefs::DefaultOpenRO, m_OPTMD.DefaultOpenRO == TRUE, true); prefs->SetPref(PWSprefs::MultipleInstances, m_OPTMD.MultipleInstances == TRUE, true); // Now update database preferences // In PropertyPage alphabetic order prefs->SetPref(PWSprefs::SaveImmediately, m_OPTMD.SaveImmediately == TRUE, true); prefs->SetPref(PWSprefs::ShowPWDefault, m_OPTMD.ShowPasswordInEdit == TRUE, true); prefs->SetPref(PWSprefs::ShowUsernameInTree, m_OPTMD.ShowUsernameInTree == TRUE, true); prefs->SetPref(PWSprefs::ShowPasswordInTree, m_OPTMD.ShowPasswordInTree == TRUE, true); prefs->SetPref(PWSprefs::TreeDisplayStatusAtOpen, m_OPTMD.TreeDisplayStatusAtOpen, true); prefs->SetPref(PWSprefs::ShowNotesDefault, m_OPTMD.NotesShowInEdit == TRUE, true); prefs->SetPref(PWSprefs::MaintainDateTimeStamps, m_OPTMD.MaintainDatetimeStamps == TRUE, true); prefs->SetPref(PWSprefs::UseDefaultUser, m_OPTMD.UseDefuser == TRUE, true); prefs->SetPref(PWSprefs::DefaultUsername, LPCWSTR(m_OPTMD.DefUsername), true); if (m_OPTMD.AutotypeText.IsEmpty() || m_OPTMD.AutotypeText == DEFAULT_AUTOTYPE) prefs->SetPref(PWSprefs::DefaultAutotypeString, L"", true); else if (m_OPTMD.AutotypeText != DEFAULT_AUTOTYPE) prefs->SetPref(PWSprefs::DefaultAutotypeString, LPCWSTR(m_OPTMD.AutotypeText), true); prefs->SetPref(PWSprefs::DefaultAutotypeDelay, m_OPTMD.AutotypeDelay, true); prefs->SetPref(PWSprefs::SavePasswordHistory, m_OPTMD.SavePWHistory == TRUE, true); if (m_OPTMD.SavePWHistory == TRUE) prefs->SetPref(PWSprefs::NumPWHistoryDefault, m_OPTMD.PWHistoryNumDefault, true); prefs->SetPref(PWSprefs::LockDBOnIdleTimeout, m_OPTMD.LockOnIdleTimeout == TRUE, true); prefs->SetPref(PWSprefs::IdleTimeout, m_OPTMD.IdleTimeOut, true); GetMainDlg()->SetHashIters(m_OPTMD.HashIters); // Changing ExplorerTypeTree changes order of items, // which DisplayStatus implicitly depends upon if (m_save_bExplorerTypeTree != m_OPTMD.ExplorerTypeTree) m_bSaveGroupDisplayState = m_bRefreshViews = true; // If user has turned on/changed warnings of expired passwords - check now if (m_OPTMD.PreExpiryWarn == TRUE && (m_save_bPreExpiryWarn == FALSE || m_save_iPreExpiryWarnDays != m_OPTMD.PreExpiryWarnDays)) m_bCheckExpired = m_bRefreshViews = true; // Deal with shortcuts prefs->SetPref(PWSprefs::HotKey, m_OPTMD.AppHotKeyValue, true); prefs->SetPref(PWSprefs::HotKeyEnabled, m_OPTMD.AppHotKeyEnabled == TRUE, true); if (m_pp_shortcuts->HaveShortcutsChanged()) m_bUpdateShortcuts = true; // Now copy across application preferences // Any changes via Database preferences done via call to UpdateGUI from Command prefs->UpdateFromCopyPrefs(PWSprefs::ptApplication); // Keep prefs file updated prefs->SaveApplicationPreferences(); }