예제 #1
0
int main(int argc, char **argv)
{
  testing::InitGoogleTest(&argc, argv);
  int rc = RUN_ALL_TESTS();

#ifdef WIN32
  system("pause");
#endif

  // Need to find these in order to delete them
  PWSLog *pwslog = PWSLog::GetLog();
  PWSprefs *pwsprefs = PWSprefs::GetInstance();
  PWSrand *pwsrand = PWSrand::GetInstance();

  pwsprefs->DeleteInstance();
  pwslog->DeleteLog();
  pwsrand->DeleteInstance();

  // To stop Compiler warning C4189
  pwsprefs = NULL;
  pwslog = NULL;
  pwsrand = NULL;

  return rc;
}
예제 #2
0
파일: mainManage.cpp 프로젝트: Sp1l/pwsafe
void PasswordSafeFrame::OnPreferencesClick( wxCommandEvent& /* evt */ )
{
  PWSprefs* prefs = PWSprefs::GetInstance();
  const StringX sxOldDBPrefsString(prefs->Store());
  COptions *window = new COptions(this);
  if (window->ShowModal() == wxID_OK) {
    StringX sxNewDBPrefsString(prefs->Store(true));
    // Update system tray icon if visible so changes show up immediately
    if (m_sysTray && prefs->GetPref(PWSprefs::UseSystemTray))
        m_sysTray->ShowIcon();

    if (!m_core.GetCurFile().empty() && !m_core.IsReadOnly() &&
        m_core.GetReadFileVersion() == PWSfile::VCURRENT) {
      if (sxOldDBPrefsString != sxNewDBPrefsString) {
        Command *pcmd = DBPrefsCommand::Create(&m_core, sxNewDBPrefsString);
        if (pcmd) {
            //I don't know why notifications should ever be suspended, but that's how
            //things were before I messed with them, so I want to limit the damage by
            //enabling notifications only as long as required and no more
            m_core.ResumeOnDBNotification();
            Execute(pcmd);  //deleted automatically
            m_core.SuspendOnDBNotification();
        }
      }
    }
  }
  window->Destroy();
}
예제 #3
0
TEST_F(ItemDataTest, PasswordHistory)
{
  size_t pwh_max, num_err;
  PWHistList pwhl;

  const StringX pw1(L"banana-0rchid");
  const StringX pw2(L"banana-1rchid");
  const StringX pw3(L"banana-2rchid");
  const StringX pw4(L"banana-5rchid");

  PWSprefs *prefs = PWSprefs::GetInstance();
  prefs->SetPref(PWSprefs::SavePasswordHistory, true);
  prefs->SetPref(PWSprefs::NumPWHistoryDefault, 3);

  CItemData di;
  di.SetCTime();
  di.SetPassword(pw1); // first time must be Set, not Update!
  di.UpdatePassword(pw2);
  EXPECT_FALSE(di.GetPWHistory().empty());

  EXPECT_TRUE(CreatePWHistoryList(di.GetPWHistory(), pwh_max, num_err,
                                  pwhl, PWSUtil::TMC_ASC_UNKNOWN));
  EXPECT_EQ(0, num_err);
  EXPECT_EQ(3, pwh_max);
  EXPECT_EQ(1, pwhl.size());
  EXPECT_EQ(pw1, pwhl[0].password);

  di.UpdatePassword(pw3);

  EXPECT_TRUE(CreatePWHistoryList(di.GetPWHistory(), pwh_max, num_err,
                                  pwhl, PWSUtil::TMC_ASC_UNKNOWN));
  EXPECT_EQ(0, num_err);
  EXPECT_EQ(3, pwh_max);
  EXPECT_EQ(2, pwhl.size());
  EXPECT_EQ(pw1, pwhl[0].password);
  EXPECT_EQ(pw2, pwhl[1].password);

  di.UpdatePassword(pw4);

  EXPECT_TRUE(CreatePWHistoryList(di.GetPWHistory(), pwh_max, num_err,
                                  pwhl, PWSUtil::TMC_ASC_UNKNOWN));
  EXPECT_EQ(0, num_err);
  EXPECT_EQ(3, pwh_max);
  EXPECT_EQ(3, pwhl.size());
  EXPECT_EQ(pw1, pwhl[0].password);
  EXPECT_EQ(pw2, pwhl[1].password);
  EXPECT_EQ(pw3, pwhl[2].password);

  di.UpdatePassword(L"Last1");

  EXPECT_TRUE(CreatePWHistoryList(di.GetPWHistory(), pwh_max, num_err,
                                  pwhl, PWSUtil::TMC_ASC_UNKNOWN));
  EXPECT_EQ(0, num_err);
  EXPECT_EQ(3, pwh_max);
  EXPECT_EQ(3, pwhl.size());
  EXPECT_EQ(pw2, pwhl[0].password);
  EXPECT_EQ(pw3, pwhl[1].password);
  EXPECT_EQ(pw4, pwhl[2].password);
}
예제 #4
0
CAddEdit_Basic::CAddEdit_Basic(CWnd *pParent, st_AE_master_data *pAEMD)
    : CAddEdit_PropertyPage(pParent,
                            CAddEdit_Basic::IDD, CAddEdit_Basic::IDD_SHORT,
                            pAEMD),
      m_bInitdone(false), m_thread(NULL), m_isNotesHidden(false)
{
    if (CS_SHOW.IsEmpty()) { // one-time initializations
        HIDDEN_NOTES.LoadString(IDS_HIDDENNOTES);
        CS_SHOW.LoadString(IDS_SHOWPASSWORDTXT);
        CS_HIDE.LoadString(IDS_HIDEPASSWORDTXT);
    }

    PWSprefs *prefs = PWSprefs::GetInstance();

    // Setup
    m_bWordWrap = prefs->GetPref(PWSprefs::NotesWordWrap);

    m_password = m_password2 = M_realpassword();
    m_notes = M_realnotes().Left(MAXTEXTCHARS);

    // Set up right-click Notes context menu additions
    std::vector<st_context_menu> vmenu_items;

    st_context_menu st_cm;
    std::wstring cs_menu_string;

    LoadAString(cs_menu_string, IDS_WORD_WRAP);
    st_cm.menu_string = cs_menu_string;
    st_cm.message_number = PWS_MSG_EDIT_WORDWRAP;
    st_cm.flags = m_bWordWrap ? MF_CHECKED : MF_UNCHECKED;
    vmenu_items.push_back(st_cm);

    st_cm.Empty();
    LoadAString(cs_menu_string, IDS_NOTESZOOMIN);
    st_cm.menu_string = cs_menu_string;
    st_cm.message_number = PWS_MSG_CALL_NOTESZOOMIN;
    st_cm.flags = 0;
    st_cm.lParam = 1;
    vmenu_items.push_back(st_cm);

    st_cm.Empty();
    LoadAString(cs_menu_string, IDS_NOTESZOOMOUT);
    st_cm.menu_string = cs_menu_string;
    st_cm.message_number = PWS_MSG_CALL_NOTESZOOMOUT;
    st_cm.flags = 0;
    st_cm.lParam = -1;
    vmenu_items.push_back(st_cm);

    st_cm.Empty();
    LoadAString(cs_menu_string, IDS_EDITEXTERNALLY);
    st_cm.menu_string = cs_menu_string;
    st_cm.message_number = PWS_MSG_CALL_EXTERNAL_EDITOR;
    st_cm.flags = 0;
    vmenu_items.push_back(st_cm);

    m_ex_notes.SetContextMenu(vmenu_items);
}
예제 #5
0
파일: mainManage.cpp 프로젝트: Sp1l/pwsafe
//////////////////////////////////////////
// Backup and Restore
//
void PasswordSafeFrame::OnBackupSafe(wxCommandEvent& /*evt*/)
{
  PWSprefs *prefs = PWSprefs::GetInstance();
  const wxFileName currbackup(towxstring(prefs->GetPref(PWSprefs::CurrentBackup)));

  const wxString title(_("Please Choose a Name for this Backup:"));

  wxString dir;
  if (m_core.GetCurFile().empty())
    dir = towxstring(PWSdirs::GetSafeDir());
  else {
    wxFileName::SplitPath(towxstring(m_core.GetCurFile()), &dir, NULL, NULL);
    wxCHECK_RET(!dir.IsEmpty(), _("Could not parse current file path"));
  }

  //returns empty string if user cancels
  wxString wxbf = wxFileSelector(title,
                                 dir,
                                 currbackup.GetFullName(),
                                 wxT("bak"),
                                 _("Password Safe Backups (*.bak)|*.bak"),
                                 wxFD_SAVE|wxFD_OVERWRITE_PROMPT,
                                 this);
  /*
  The wxFileSelector code says it appends the default extension if user
  doesn't type one, but it actually doesn't and I don't see the purported
  code in 2.8.10.  And doing it ourselves after the dialog has returned is
  risky because we might silently overwrite an existing file
  */

  //create a copy to avoid multiple conversions to StringX
  const StringX backupfile(tostringx(wxbf));

#ifdef NOT_YET
  if (m_inExit) {
    // If U3ExitNow called while in CPWFileDialog,
    // PostQuitMessage makes us return here instead
    // of exiting the app. Try resignalling
    PostQuitMessage(0);
    return PWScore::USER_CANCEL;
  }
#endif

  if (!backupfile.empty()) {  //i.e. if user didn't cancel
    if (m_core.WriteFile(backupfile, m_core.GetReadFileVersion(),
                         false) == PWScore::CANT_OPEN_FILE) {
      wxMessageBox( wxbf << wxT("\n\n") << _("Could not open file for writing!"),
                    _("Write Error"), wxOK|wxICON_ERROR, this);
    }

    prefs->SetPref(PWSprefs::CurrentBackup, backupfile);
  }
}
예제 #6
0
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
}
//Just update the item's text, don't move it into its sorted position
void PWSTreeCtrl::UpdateItemField(const CItemData &item, CItemData::FieldType ft)
{
  PWSprefs* prefs = PWSprefs::GetInstance();
  if (ft == CItemData::GROUP) {
    //remove & add again
    UpdateItem(item);
  }
  //these are the only items ever shown in the tree
  else if (ft == CItemData::TITLE || ft == CItemData::START ||
       (ft == CItemData::USER && prefs->GetPref(PWSprefs::ShowUsernameInTree)) ||
       (ft == CItemData::PASSWORD && prefs->GetPref(PWSprefs::ShowPasswordInTree))) {
    wxRect rc;
    wxTreeItemId ti = Find(item);
    if (ti.IsOk()) {
      SetItemText(ti, ItemDisplayString(item));
    }
  }
}
예제 #8
0
void CPWSRecentFileList::ReadList()
{
  PWSprefs *pref = PWSprefs::GetInstance();
  // reads from registry or config file
  if (pref->IsUsingRegistry()) {
    CRecentFileList::ReadList();
  } else {
    const int nMRUItems = pref->GetPref(PWSprefs::MaxMRUItems);
    ASSERT(nMRUItems == m_nSize);
    std::wstring *arrNames = new std::wstring[nMRUItems];
    pref->GetMRUList(arrNames);
    for (int i = 0; i < nMRUItems; i++) {
      std::wstring path = arrNames[i].c_str();
      pws_os::AddDrive(path);
      m_arrNames[i] = path.c_str();
    }
    delete[] arrNames;
  }
}
wxString PWSTreeCtrl::ItemDisplayString(const CItemData &item) const
{
  PWSprefs *prefs = PWSprefs::GetInstance();
  const wxString title = item.GetTitle().c_str();
  wxString disp = title;

  if (prefs->GetPref(PWSprefs::ShowUsernameInTree)) {
    const wxString user = item.GetUser().c_str();
    if (!user.empty())
      disp += wxT(" [") + user + wxT("]");
  }

  if (prefs->GetPref(PWSprefs::ShowPasswordInTree)) {
    const wxString passwd = item.GetPassword().c_str();
    if (!passwd.empty())
      disp += wxT(" {") + passwd + wxT("}");
  }

  return disp;
}
예제 #10
0
void CPWSRecentFileList::WriteList()
{
  extern void RelativizePath(stringT &);
  PWSprefs *pref = PWSprefs::GetInstance();
  // writes to registry or config file
  if (pref->IsUsingRegistry()) {
    CRecentFileList::WriteList();
  } else {
    const int num_MRU = GetSize();
    const int max_MRU = ID_FILE_MRU_ENTRYMAX - ID_FILE_MRU_ENTRY1;
    std::wstring *csMRUFiles = new std::wstring[num_MRU];

    for (int i = 0; i < num_MRU; i++) {
      csMRUFiles[i] = (*this)[i];
      if (!csMRUFiles[i].empty()) {
        Trim(csMRUFiles[i]);
        RelativizePath(csMRUFiles[i]);
      }
    }

    pref->SetMRUList(csMRUFiles, num_MRU, max_MRU);
    delete[] csMRUFiles;
  }
}
예제 #11
0
BOOL COptionsSystem::OnInitDialog() 
{
  COptions_PropertyPage::OnInitDialog();

  PWSprefs *prefs = PWSprefs::GetInstance();

  PWSprefs::ConfigOption configoption;
  StringX sx_CF = prefs->GetConfigFile(configoption).c_str();
  std::wstring  wsCO(L"");
  switch (configoption) {
    case PWSprefs::CF_NONE:
      LoadAString(sx_CF, IDS_NONE);
      break;
    case PWSprefs::CF_REGISTRY:
      LoadAString(sx_CF, IDS_REGISTRY);
      break;
    case PWSprefs::CF_FILE_RO:
      LoadAString(wsCO, IDS_READ_ONLY);
      break;
    case PWSprefs::CF_FILE_RW:
    case PWSprefs::CF_FILE_RW_NEW:
      LoadAString(wsCO, IDS_READ_WRITE);
      break;
    default:
      ASSERT(0);
  }

  CString cs_text;

  // R/W status
  GetDlgItem(IDC_STATIC_RWSTATUS)->SetWindowText(wsCO.c_str());

  // Config file name & location
  cs_text = PWSUtil::NormalizeTTT(sx_CF, 60).c_str();
  GetDlgItem(IDC_CONFIGFILE)->SetWindowText(cs_text);

  // Effective host & user used in config file
  if (configoption == PWSprefs::CF_FILE_RO || 
      configoption == PWSprefs::CF_FILE_RW ||
      configoption == PWSprefs::CF_FILE_RW_NEW) {
    stringT hn = SysInfo::GetInstance()->GetEffectiveHost();
    PWSprefs::XMLify(charT('H'), hn);
    stringT un = SysInfo::GetInstance()->GetEffectiveUser();
    PWSprefs::XMLify(charT('u'), un);

    cs_text.Format(IDS_HOSTUSER, static_cast<LPCWSTR>(hn.c_str()), static_cast<LPCWSTR>(un.c_str()));
    GetDlgItem(IDC_STATIC_HOSTUSER)->SetWindowText(cs_text);
  }

  bool bofferdeleteregistry = prefs->OfferDeleteRegistry();

  bool boffermigrate2appdata = OfferConfigMigration();

  if (!bofferdeleteregistry) {
    GetDlgItem(IDC_REGDEL)->ShowWindow(SW_HIDE);
    GetDlgItem(IDC_REGDEL)->EnableWindow(FALSE);
  }

  if (!boffermigrate2appdata) {
    GetDlgItem(IDC_MIGRATETOAPPDATA)->ShowWindow(SW_HIDE);
    GetDlgItem(IDC_MIGRATETOAPPDATA)->EnableWindow(FALSE);
  }

  if (!bofferdeleteregistry && !boffermigrate2appdata) {
    GetDlgItem(IDC_CONFIG_GRP)->ShowWindow(SW_HIDE);
    GetDlgItem(IDC_APPLYCONFIGCHANGES)->ShowWindow(SW_HIDE);
  } else {
    GetDlgItem(IDC_APPLYCONFIGCHANGES)->ShowWindow(SW_SHOW);
  }

  GetDlgItem(IDC_APPLYCONFIGCHANGES)->EnableWindow(FALSE);

  CSpinButtonCtrl *pspin = (CSpinButtonCtrl *)GetDlgItem(IDC_RESPIN);
  pspin->SetBuddy(GetDlgItem(IDC_MAXREITEMS));
  pspin->SetRange(M_prefminREItems(), M_prefmaxREItems());
  pspin->SetBase(10);
  pspin->SetPos(m_MaxREItems);

  pspin = (CSpinButtonCtrl *)GetDlgItem(IDC_MRUSPIN);
  pspin->SetBuddy(GetDlgItem(IDC_MAXMRUITEMS));
  pspin->SetRange(M_prefminMRU(), M_prefmaxMRU());
  pspin->SetBase(10);
  pspin->SetPos(m_MaxMRUItems);

  OnUseSystemTray();

  if (InitToolTip(TTS_BALLOON | TTS_NOPREFIX, 0)) {
    m_Help1.Init(IDB_QUESTIONMARK);
    m_Help2.Init(IDB_QUESTIONMARK);

    // Note naming convention: string IDS_xxx corresponds to control IDC_xxx_HELP
    AddTool(IDC_REGDELHELP, IDS_REGDEL);
    AddTool(IDC_MIGRATETOAPPDATAHELP, IDS_MIGRATETOAPPDATA);
    ActivateToolTip();
  } else {
    m_Help1.EnableWindow(FALSE);
    m_Help1.ShowWindow(SW_HIDE);
    m_Help2.EnableWindow(FALSE);
    m_Help2.ShowWindow(SW_HIDE);
  }

  if (!bofferdeleteregistry) {
    m_Help1.EnableWindow(FALSE);
    m_Help1.ShowWindow(SW_HIDE);
  }

  if (!boffermigrate2appdata) {
    m_Help2.EnableWindow(FALSE);
    m_Help2.ShowWindow(SW_HIDE);
  }

  return TRUE;  // return TRUE unless you set the focus to a control
}
예제 #12
0
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;
}
예제 #13
0
BOOL COptionsSystem::OnInitDialog() 
{
  COptions_PropertyPage::OnInitDialog();

  PWSprefs *prefs = PWSprefs::GetInstance();
  if (!m_bShowConfigFile) {
    GetDlgItem(IDC_STATIC_CONFIGFILE)->ShowWindow(SW_HIDE);
    GetDlgItem(IDC_STATIC_RWSTATUS)->ShowWindow(SW_HIDE);
    GetDlgItem(IDC_CONFIGFILE)->ShowWindow(SW_HIDE);
  } else {
    PWSprefs::ConfigOption configoption;
    std::wstring wsCF = prefs->GetConfigFile(configoption);
    std::wstring wsCO(L"");
    switch (configoption) {
      case PWSprefs::CF_NONE:
        LoadAString(wsCF, IDS_NONE);
        break;
      case PWSprefs::CF_REGISTRY:
        LoadAString(wsCF, IDS_REGISTRY);
        break;
      case PWSprefs::CF_FILE_RO:
        LoadAString(wsCO, IDS_READ_ONLY);
        break;
      case PWSprefs::CF_FILE_RW:
      case PWSprefs::CF_FILE_RW_NEW:
        LoadAString(wsCO, IDS_READ_WRITE);
        break;
      default:
        ASSERT(0);
    }
    GetDlgItem(IDC_CONFIGFILE)->SetWindowText(wsCF.c_str());
    GetDlgItem(IDC_STATIC_RWSTATUS)->SetWindowText(wsCO.c_str());
  }

  bool bofferdeleteregistry = prefs->OfferDeleteRegistry();

  bool boffermigrate2appdata = OfferConfigMigration();

  if (!bofferdeleteregistry) {
    GetDlgItem(IDC_REGDEL)->ShowWindow(SW_HIDE);
    GetDlgItem(IDC_REGDEL)->EnableWindow(FALSE);
  }

  if (!boffermigrate2appdata) {
    GetDlgItem(IDC_MIGRATETOAPPDATA)->ShowWindow(SW_HIDE);
    GetDlgItem(IDC_MIGRATETOAPPDATA)->EnableWindow(FALSE);
  }

  if (!bofferdeleteregistry && !boffermigrate2appdata) {
    GetDlgItem(IDC_CONFIG_GRP)->ShowWindow(SW_HIDE);
    GetDlgItem(IDC_APPLYCONFIGCHANGES)->ShowWindow(SW_HIDE);
  } else {
    GetDlgItem(IDC_APPLYCONFIGCHANGES)->ShowWindow(SW_SHOW);
  }

  GetDlgItem(IDC_APPLYCONFIGCHANGES)->EnableWindow(FALSE);

  CSpinButtonCtrl *pspin = (CSpinButtonCtrl *)GetDlgItem(IDC_RESPIN);

  pspin->SetBuddy(GetDlgItem(IDC_MAXREITEMS));
  pspin->SetRange(0, ID_TRAYRECENT_ENTRYMAX - ID_TRAYRECENT_ENTRY1 + 1);
  pspin->SetBase(10);
  pspin->SetPos(m_MaxREItems);

  pspin = (CSpinButtonCtrl *)GetDlgItem(IDC_MRUSPIN);

  pspin->SetBuddy(GetDlgItem(IDC_MAXMRUITEMS));
  pspin->SetRange(0, ID_FILE_MRU_ENTRYMAX - ID_FILE_MRU_ENTRY1 + 1);
  pspin->SetBase(10);
  pspin->SetPos(m_MaxMRUItems);

  OnUseSystemTray();

  InitToolTip(TTS_BALLOON | TTS_NOPREFIX, 2);
  AddTool(IDC_REGDEL,           IDS_REGDEL);
  AddTool(IDC_MIGRATETOAPPDATA, IDS_MIGRATETOAPPDATA);
  ActivateToolTip();

  return TRUE;  // return TRUE unless you set the focus to a control
  // EXCEPTION: OCX Property Pages should return FALSE
}
예제 #14
0
BOOL CAddEdit_Basic::OnInitDialog()
{
    CAddEdit_PropertyPage::OnInitDialog();

    ModifyStyleEx(0, WS_EX_CONTROLPARENT);

    Fonts *pFonts = Fonts::GetInstance();
    pFonts->ApplyPasswordFont(GetDlgItem(IDC_PASSWORD));
    pFonts->ApplyPasswordFont(GetDlgItem(IDC_PASSWORD2));

    // Need to get change notifcations
    m_ex_notes.SetEventMask(ENM_CHANGE | m_ex_notes.GetEventMask());

    // Set plain text - not that it seems to do much!
    m_ex_notes.SetTextMode(TM_PLAINTEXT);

    PWSprefs *prefs = PWSprefs::GetInstance();

    // Set Notes font!
    if (prefs->GetPref(PWSprefs::NotesFont).empty()) {
        m_ex_notes.SetFont(pFonts->GetCurrentFont());
    } else {
        m_ex_notes.SetFont(pFonts->GetNotesFont());
    }

    if (M_uicaller() == IDS_EDITENTRY && M_protected() != 0) {
        GetDlgItem(IDC_STATIC_PROTECTED)->ShowWindow(SW_SHOW);
        m_stc_protected.SetColour(RGB(255,0,0));
    }

    if (M_uicaller() != IDS_ADDENTRY) {
        InitToolTip();

        AddTool(IDC_STATIC_GROUP,    IDS_CLICKTOCOPY);
        AddTool(IDC_STATIC_TITLE,    IDS_CLICKTOCOPY);
        AddTool(IDC_STATIC_USERNAME, IDS_CLICKTOCOPY);
        AddTool(IDC_STATIC_PASSWORD, IDS_CLICKTOCOPY);
        AddTool(IDC_STATIC_NOTES,    IDS_CLICKTOCOPY);
        AddTool(IDC_STATIC_URL,      IDS_CLICKTOCOPY);
        AddTool(IDC_STATIC_EMAIL,    IDS_CLICKTOCOPYPLUS1);
        AddTool(IDC_LAUNCH,          IDS_CLICKTOGOPLUS);
        AddTool(IDC_SENDEMAIL,       IDS_CLICKTOSEND);

        if (M_uicaller() == IDS_EDITENTRY && M_protected() != 0) {
            AddTool(IDC_STATIC_PROTECTED, IDS_UNPROTECT);
        }

        ActivateToolTip();

        m_stc_group.SetHighlight(true, CAddEdit_PropertyPage::crefWhite);
        m_stc_title.SetHighlight(true, CAddEdit_PropertyPage::crefWhite);
        m_stc_username.SetHighlight(true, CAddEdit_PropertyPage::crefWhite);
        m_stc_password.SetHighlight(true, CAddEdit_PropertyPage::crefWhite);
        m_stc_notes.SetHighlight(true, CAddEdit_PropertyPage::crefWhite);
        m_stc_URL.SetHighlight(true, CAddEdit_PropertyPage::crefWhite);
        m_stc_email.SetHighlight(true, CAddEdit_PropertyPage::crefWhite);
    }

    m_ex_group.ChangeColour();
    GetDlgItem(IDC_LAUNCH)->EnableWindow(M_URL().IsEmpty() ? FALSE : TRUE);
    GetDlgItem(IDC_SENDEMAIL)->EnableWindow(M_email().IsEmpty() ? FALSE : TRUE);

    if (M_uicaller() == IDS_VIEWENTRY ||
            (M_uicaller() == IDS_EDITENTRY && M_protected() != 0)) {
        // Change 'OK' to 'Close' and disable 'Cancel'
        // "CancelToClose" disables the System Command SC_CLOSE
        // from clicking X on PropertySheet so have implemented
        // CAddEdit_PropertySheet::OnSysCommand to deal with it.
        CancelToClose();

        // Disable Group Combo
        GetDlgItem(IDC_GROUP)->EnableWindow(FALSE);

        // Disable normal Edit controls
        GetDlgItem(IDC_TITLE)->SendMessage(EM_SETREADONLY, TRUE, 0);
        GetDlgItem(IDC_USERNAME)->SendMessage(EM_SETREADONLY, TRUE, 0);
        GetDlgItem(IDC_PASSWORD)->SendMessage(EM_SETREADONLY, TRUE, 0);
        GetDlgItem(IDC_PASSWORD2)->SendMessage(EM_SETREADONLY, TRUE, 0);
        GetDlgItem(IDC_NOTES)->SendMessage(EM_SETREADONLY, TRUE, 0);
        GetDlgItem(IDC_URL)->SendMessage(EM_SETREADONLY, TRUE, 0);
        GetDlgItem(IDC_EMAIL)->SendMessage(EM_SETREADONLY, TRUE, 0);

        // Disable Button
        GetDlgItem(IDC_GENERATEPASSWORD)->EnableWindow(FALSE);
    }

    // Populate the combo box
    m_ex_group.ResetContent(); // groups might be from a previous DB (BR 3062758)

    // The core function "GetUniqueGroups(vGroups)" returns the group list by
    // going through the entries in the database. This will not include empty
    // groups.  However, we already maintain this list in the UI to save the
    // display status, so use this instead.
    std::vector<std::wstring> vGroups;
    GetMainDlg()->GetAllGroups(vGroups);

    for (std::vector<std::wstring>::iterator iter = vGroups.begin();
            iter != vGroups.end(); ++iter) {
        m_ex_group.AddString(iter->c_str());
    }

    size_t num_unkwn(0);
    if (M_uicaller() != IDS_ADDENTRY)
        num_unkwn = M_pci()->NumberUnknownFields();

    if (num_unkwn > 0) {
        CString cs_text;
        cs_text.Format(IDS_RECORDUNKNOWNFIELDS, num_unkwn);
        GetDlgItem(IDC_RECORDUNKNOWNFIELDS)->SetWindowText(cs_text);
        GetDlgItem(IDC_RECORDUNKNOWNFIELDS)->ShowWindow(SW_SHOW);
        GetDlgItem(IDC_STATIC_RECORDUNKNOWNFIELDS)->ShowWindow(SW_SHOW);
        GetDlgItem(IDC_STATICGROUPRUNKNFLDS)->ShowWindow(SW_SHOW);
    } else {
        GetDlgItem(IDC_RECORDUNKNOWNFIELDS)->ShowWindow(SW_HIDE);
        GetDlgItem(IDC_STATIC_RECORDUNKNOWNFIELDS)->ShowWindow(SW_HIDE);
        GetDlgItem(IDC_STATICGROUPRUNKNFLDS)->ShowWindow(SW_HIDE);
    }

    // Note shortcuts have their own dialog for edit.
    CString cs_text;
    if (M_original_entrytype() == CItemData::ET_ALIASBASE ||
            M_original_entrytype() == CItemData::ET_SHORTCUTBASE) {
        // Show button to allow users to view dependents
        cs_text.LoadString(M_original_entrytype() == CItemData::ET_ALIASBASE ?
                           IDS_VIEWALIASESBTN : IDS_VIEWSHORTCUTSBTN);
        GetDlgItem(IDC_VIEWDEPENDENTS)->SetWindowText(cs_text);
        GetDlgItem(IDC_VIEWDEPENDENTS)->ShowWindow(SW_SHOW);

        cs_text.LoadString(M_original_entrytype() == CItemData::ET_ALIASBASE ?
                           IDS_ISANALIASBASE : IDS_ISASHORTCUTBASE);
        GetDlgItem(IDC_STATIC_ISANALIAS)->SetWindowText(cs_text);
        GetDlgItem(IDC_STATIC_ISANALIAS)->ShowWindow(SW_SHOW);
    } else if (M_original_entrytype() == CItemData::ET_ALIAS) {
        // Update password to alias form
        // Show text stating that it is an alias
        M_realpassword() = M_oldRealPassword() = m_password = m_password2 = M_base();
        GetDlgItem(IDC_VIEWDEPENDENTS)->ShowWindow(SW_HIDE);

        cs_text.Format(IDS_ISANALIAS, M_base());
        GetDlgItem(IDC_STATIC_ISANALIAS)->SetWindowText(cs_text);
        GetDlgItem(IDC_STATIC_ISANALIAS)->ShowWindow(SW_SHOW);
    } else if (M_original_entrytype() == CItemData::ET_NORMAL) {
        // Normal - do none of the above
        GetDlgItem(IDC_VIEWDEPENDENTS)->ShowWindow(SW_HIDE);
        GetDlgItem(IDC_STATIC_ISANALIAS)->ShowWindow(SW_HIDE);
    }

    if (prefs->GetPref(PWSprefs::ShowPWDefault)) {
        ShowPassword();
    } else {
        HidePassword();
    }

    if (prefs->GetPref(PWSprefs::ShowNotesDefault)) {
        ShowNotes();
    } else {
        HideNotes();
        m_ex_notes.EnableMenuItem(PWS_MSG_CALL_NOTESZOOMIN, false);
        m_ex_notes.EnableMenuItem(PWS_MSG_CALL_NOTESZOOMOUT, false);
    }

    CHARFORMAT cf = {0};
    cf.cbSize = sizeof(cf);

    m_ex_notes.SetSel(0, -1);
    m_ex_notes.SendMessage(EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
    m_iPointSize = cf.yHeight / 20;

    // Set initial Word Wrap
    m_ex_notes.SetTargetDevice(NULL, m_bWordWrap ? 0 : 1);
    m_ex_notes.UpdateState(PWS_MSG_EDIT_WORDWRAP, m_bWordWrap);

    UpdateData(FALSE);
    m_bInitdone = true;
    return TRUE;
}
예제 #15
0
CAddEdit_PropertySheet::CAddEdit_PropertySheet(UINT nID, CWnd* pParent,
                                               PWScore *pcore,
                                               CItemData *pci_original, CItemData *pci,
                                               const bool bLongPPs,
                                               const StringX currentDB)
  : CPWPropertySheet(nID, pParent, bLongPPs), m_bIsModified(false), m_bChanged(false),
  m_bNotesChanged(false), m_bSymbolsChanged(false)
{
  m_AEMD.bLongPPs = bLongPPs;
  m_AEMD.uicaller = nID;

  ASSERT(pParent != NULL);
  ASSERT(pcore != NULL);
  ASSERT(pci != NULL);

  m_AEMD.pcore = pcore;
  m_AEMD.pci_original = pci_original;
  m_AEMD.pci = pci;

  m_AEMD.currentDB = currentDB;

  PWSprefs *prefs = PWSprefs::GetInstance();

  m_AEMD.default_pwp = prefs->GetDefaultPolicy();
  m_AEMD.default_symbols = prefs->GetPref(PWSprefs::DefaultSymbols);

  // Set up data used by all Property Pages, as appropriate
  if (m_AEMD.uicaller == IDS_ADDENTRY) {
    // Basic initialisation
    m_AEMD.group = L"";
    m_AEMD.title = L"";
    m_AEMD.username = L"";
    m_AEMD.realpassword = L"";
    m_AEMD.realnotes = m_AEMD.originalrealnotesTRC = L"";
    m_AEMD.URL = L"";
    m_AEMD.email = L"";
    m_AEMD.symbols = m_AEMD.oldsymbols = L"";
    m_AEMD.num_dependents = 0;

    // Entry type initialisation
    m_AEMD.original_entrytype = CItemData::ET_NORMAL;

    // Additional initialisation
    m_AEMD.autotype = L"";
    m_AEMD.runcommand = L"";
    m_AEMD.oldDCA = m_AEMD.DCA = m_AEMD.oldShiftDCA = m_AEMD.ShiftDCA = -1;

    // Date & Time initialisation
    m_AEMD.locCTime.LoadString(IDS_NA);
    m_AEMD.locXTime = m_AEMD.locATime = m_AEMD.locRMTime = m_AEMD.locPMTime =
          m_AEMD.oldlocXTime = m_AEMD.locCTime;
    m_AEMD.tttXTime = m_AEMD.tttCPMTime = (time_t)0;
    m_AEMD.oldXTimeInt = m_AEMD.XTimeInt = 0;

    // PWHistory initialisation
    m_AEMD.SavePWHistory = m_AEMD.oldSavePWHistory =
            PWSprefs::GetInstance()->GetPref(PWSprefs::SavePasswordHistory) ? TRUE : FALSE;
    m_AEMD.MaxPWHistory = m_AEMD.oldMaxPWHistory =
            PWSprefs::GetInstance()->GetPref(PWSprefs::NumPWHistoryDefault);
    m_AEMD.NumPWHistory = m_AEMD.oldNumPWHistory = 0;

    // PWPolicy fields
    m_AEMD.pwp = m_AEMD.oldpwp = m_AEMD.default_pwp;
    m_AEMD.ipolicy = m_AEMD.oldipolicy = DEFAULT_POLICY;
    m_AEMD.iownsymbols = m_AEMD.ioldownsymbols = DEFAULT_SYMBOLS;
    m_AEMD.symbols = L"";
    m_AEMD.policyname = m_AEMD.oldpolicyname = L"";

    // Protected
    m_AEMD.ucprotected = 0;
    
    // Entry Keyboard shortcut
    m_AEMD.oldKBShortcut = m_AEMD.KBShortcut = 0;
  } else {
    SetupInitialValues();
  }
  // Only now allocate the PropertyPages - after all data there
  // to be used by their c'tors
  m_pp_basic      = new CAddEdit_Basic(this, &m_AEMD);
  m_pp_additional = new CAddEdit_Additional(this, &m_AEMD);
  m_pp_datetimes  = new CAddEdit_DateTimes(this, &m_AEMD);
  m_pp_pwpolicy   = new CAddEdit_PasswordPolicy(this, &m_AEMD);
  if (pcore->GetReadFileVersion() == PWSfile::V40)
    m_pp_attachment = new CAddEdit_Attachment(this, &m_AEMD);
  else
    m_pp_attachment = NULL;

  AddPage(m_pp_basic);
  AddPage(m_pp_additional);
  AddPage(m_pp_datetimes);
  AddPage(m_pp_pwpolicy);
  if (pcore->GetReadFileVersion() == PWSfile::V40)
    AddPage(m_pp_attachment);
}
예제 #16
0
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();
}
예제 #17
0
void COptions_PropertySheet::SetupInitialValues()
{
    PWSprefs *prefs = PWSprefs::GetInstance();

    // Set up a copy of the preferences
    prefs->SetupCopyPrefs();

    // Backup Data
    CString cs_backupPrefix, cs_backupDir;
    m_OPTMD.CurrentFile = GetMainDlg()->GetCurFile().c_str();
    m_OPTMD.SaveImmediately =
        prefs->GetPref(PWSprefs::SaveImmediately) ? TRUE : FALSE;
    m_OPTMD.BackupBeforeSave =
        prefs->GetPref(PWSprefs::BackupBeforeEverySave) ? TRUE : FALSE;
    cs_backupPrefix =
        prefs->GetPref(PWSprefs::BackupPrefixValue).c_str();
    m_OPTMD.BackupPrefix = cs_backupPrefix.IsEmpty() ? 0 : 1;
    m_OPTMD.UserBackupPrefix = (LPCWSTR)cs_backupPrefix;
    m_OPTMD.BackupSuffix =
        prefs->GetPref(PWSprefs::BackupSuffix);
    m_OPTMD.MaxNumIncBackups =
        prefs->GetPref(PWSprefs::BackupMaxIncremented);
    cs_backupDir =
        prefs->GetPref(PWSprefs::BackupDir).c_str();
    m_OPTMD.BackupLocation = cs_backupDir.IsEmpty() ? 0 : 1;
    m_OPTMD.UserBackupOtherLocation = (LPCWSTR)cs_backupDir;

    // Display Data
    m_OPTMD.AlwaysOnTop =
        prefs->GetPref(PWSprefs::AlwaysOnTop) ? TRUE : FALSE;
    m_OPTMD.ShowPasswordInEdit =
        prefs->GetPref(PWSprefs::ShowPWDefault) ? TRUE : FALSE;
    m_OPTMD.ShowUsernameInTree = m_save_bShowUsernameInTree =
                                     prefs->GetPref(PWSprefs::ShowUsernameInTree) ? TRUE : FALSE;
    m_OPTMD.ShowPasswordInTree = m_save_bShowPasswordInTree =
                                     prefs->GetPref(PWSprefs::ShowPasswordInTree) ? TRUE : FALSE;
    m_OPTMD.ShowNotesAsTipsInViews =
        prefs->GetPref(PWSprefs::ShowNotesAsTooltipsInViews) ? TRUE : FALSE;
    m_OPTMD.ExplorerTypeTree = m_save_bExplorerTypeTree =
                                   prefs->GetPref(PWSprefs::ExplorerTypeTree) ? TRUE : FALSE;
    m_OPTMD.EnableGrid =
        prefs->GetPref(PWSprefs::ListViewGridLines) ? TRUE : FALSE;
    m_OPTMD.NotesShowInEdit =
        prefs->GetPref(PWSprefs::ShowNotesDefault) ? TRUE : FALSE;
    m_OPTMD.WordWrapNotes =
        prefs->GetPref(PWSprefs::NotesWordWrap) ? TRUE : FALSE;
    m_OPTMD.PreExpiryWarn = m_save_bPreExpiryWarn =
                                prefs->GetPref(PWSprefs::PreExpiryWarn) ? TRUE : FALSE;
    m_OPTMD.PreExpiryWarnDays = m_save_iPreExpiryWarnDays =
                                    prefs->GetPref(PWSprefs::PreExpiryWarnDays);
    m_OPTMD.TreeDisplayStatusAtOpen =
        prefs->GetPref(PWSprefs::TreeDisplayStatusAtOpen);
    m_OPTMD.TrayIconColour =
        prefs->GetPref(PWSprefs::ClosedTrayIconColour);
    m_OPTMD.HighlightChanges = m_save_bHighlightChanges =
                                   prefs->GetPref(PWSprefs::HighlightChanges);

    // Misc Data
    m_OPTMD.ConfirmDelete =
        prefs->GetPref(PWSprefs::DeleteQuestion) ? FALSE : TRUE;
    m_OPTMD.MaintainDatetimeStamps =
        prefs->GetPref(PWSprefs::MaintainDateTimeStamps) ? TRUE : FALSE;
    m_OPTMD.EscExits =
        prefs->GetPref(PWSprefs::EscExits) ? TRUE : FALSE;
    m_OPTMD.DoubleClickAction =
        prefs->GetPref(PWSprefs::DoubleClickAction);
    m_OPTMD.ShiftDoubleClickAction =
        prefs->GetPref(PWSprefs::ShiftDoubleClickAction);

    m_OPTMD.UseDefuser =
        prefs->GetPref(PWSprefs::UseDefaultUser) ? TRUE : FALSE;
    m_OPTMD.DefUsername =
        prefs->GetPref(PWSprefs::DefaultUsername).c_str();
    m_OPTMD.QuerySetDef =
        prefs->GetPref(PWSprefs::QuerySetDef) ? TRUE : FALSE;
    m_OPTMD.OtherBrowserLocation =
        prefs->GetPref(PWSprefs::AltBrowser).c_str();
    m_OPTMD.BrowserCmdLineParms =
        prefs->GetPref(PWSprefs::AltBrowserCmdLineParms).c_str();
    m_OPTMD.OtherEditorLocation =
        prefs->GetPref(PWSprefs::AltNotesEditor).c_str();
    CString cs_dats =
        prefs->GetPref(PWSprefs::DefaultAutotypeString).c_str();
    if (cs_dats.IsEmpty())
        cs_dats = DEFAULT_AUTOTYPE;
    m_OPTMD.AutotypeText = (LPCWSTR)cs_dats;
    m_OPTMD.AutotypeDelay =
        prefs->GetPref(PWSprefs::DefaultAutotypeDelay);
    m_OPTMD.MinAuto =
        prefs->GetPref(PWSprefs::MinimizeOnAutotype) ? TRUE : FALSE;

    // Password History Data
    m_OPTMD.SavePWHistory =
        prefs->GetPref(PWSprefs::SavePasswordHistory) ? TRUE : FALSE;
    m_OPTMD.PWHistoryNumDefault =
        prefs->GetPref(PWSprefs::NumPWHistoryDefault);
    m_OPTMD.PWHAction = 0;

    // Security Data
    m_OPTMD.ClearClipboardOnMinimize =
        prefs->GetPref(PWSprefs::ClearClipboardOnMinimize) ? TRUE : FALSE;
    m_OPTMD.ClearClipboardOnExit =
        prefs->GetPref(PWSprefs::ClearClipboardOnExit) ? TRUE : FALSE;
    m_OPTMD.LockOnMinimize =
        prefs->GetPref(PWSprefs::DatabaseClear) ? TRUE : FALSE;
    m_OPTMD.ConfirmCopy =
        prefs->GetPref(PWSprefs::DontAskQuestion) ? FALSE : TRUE;
    m_OPTMD.LockOnWindowLock = m_save_bLockOnWindowLock =
                                   prefs->GetPref(PWSprefs::LockOnWindowLock) ? TRUE : FALSE;
    m_OPTMD.LockOnIdleTimeout =
        prefs->GetPref(PWSprefs::LockDBOnIdleTimeout) ? TRUE : FALSE;
    m_OPTMD.IdleTimeOut =
        prefs->GetPref(PWSprefs::IdleTimeout);
    m_OPTMD.HashIters = GetMainDlg()->GetHashIters();
    m_OPTMD.CopyPswdBrowseURL =
        prefs->GetPref(PWSprefs::CopyPasswordWhenBrowseToURL) ? TRUE : FALSE;

    // Shortcut Data
    m_OPTMD.AppHotKeyValue = int32(prefs->GetPref(PWSprefs::HotKey));
    // Can't be enabled if not set!
    if (m_OPTMD.AppHotKeyValue == 0)
        m_OPTMD.AppHotKeyEnabled = FALSE;
    else
        m_OPTMD.AppHotKeyEnabled =
            prefs->GetPref(PWSprefs::HotKeyEnabled) ? TRUE : FALSE;

    m_OPTMD.ColWidth =
        prefs->GetPref(PWSprefs::OptShortcutColumnWidth);
    m_OPTMD.DefColWidth =
        prefs->GetPrefDefVal(PWSprefs::OptShortcutColumnWidth);

    // System Data
    CShortcut pws_shortcut;
    m_OPTMD.MaxREItems =
        prefs->GetPref(PWSprefs::MaxREItems);
    m_OPTMD.UseSystemTray =
        prefs->GetPref(PWSprefs::UseSystemTray) ? TRUE : FALSE;
    m_OPTMD.HideSystemTray =
        prefs->GetPref(PWSprefs::HideSystemTray) ? TRUE : FALSE;
    m_OPTMD.MaxMRUItems =
        prefs->GetPref(PWSprefs::MaxMRUItems);
    m_OPTMD.MRUOnFileMenu =
        prefs->GetPref(PWSprefs::MRUOnFileMenu);
    const CString PWSLnkName(L"Password Safe"); // for startup shortcut
    m_OPTMD.Startup = m_bStartupShortcutExists =
                          pws_shortcut.isLinkExist(PWSLnkName, CSIDL_STARTUP);
    m_OPTMD.DefaultOpenRO = prefs->GetPref(PWSprefs::DefaultOpenRO) ? TRUE : FALSE;
    m_OPTMD.MultipleInstances =
        prefs->GetPref(PWSprefs::MultipleInstances) ? TRUE : FALSE;
}