⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dboxmain.cpp

📁 Password Safe Password Safe is a password database utility. Users can keep their passwords securely
💻 CPP
📖 第 1 页 / 共 4 页
字号:
intDboxMain::BackupSafe(){   int rc;   CMyString tempname;   //SaveAs-type dialog box   while (1)   {      CFileDialog fd(FALSE,                     _T("bak"),                     m_currbackup,                     OFN_PATHMUSTEXIST|OFN_HIDEREADONLY                     | OFN_LONGNAMES|OFN_OVERWRITEPROMPT,                     _T("Password Safe Backups (*.bak)|*.bak||"),                     this);      fd.m_ofn.lpstrTitle = _T("Please Choose a Name for this Backup:");      rc = fd.DoModal();      if (rc == IDOK)      {         tempname = (CMyString)fd.GetPathName();         break;      }      else         return PWScore::USER_CANCEL;   }   rc = m_core.WriteFile(tempname);   if (rc == PWScore::CANT_OPEN_FILE)   {      CMyString temp = tempname + _T("\n\nCould not open file for writing!");      MessageBox(temp, _T("File write error."), MB_OK|MB_ICONWARNING);      return PWScore::CANT_OPEN_FILE;   }   m_currbackup = tempname;   return PWScore::SUCCESS;}voidDboxMain::OnOpen() {   m_LockDisabled = true;   Open();   m_LockDisabled = false;}intDboxMain::Open(){   int rc = PWScore::SUCCESS;   CMyString newfile;   //Open-type dialog box   while (1)   {      CFileDialog fd(TRUE,                     _T("dat"),                     NULL,                     OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_LONGNAMES,                     _T("Password Safe Databases (*.dat)|*.dat|")                     _T("Password Safe Backups (*.bak)|*.bak|")                     _T("All files (*.*)|*.*|")                     _T("|"),                     this);      fd.m_ofn.lpstrTitle = _T("Please Choose a Database to Open:");      rc = fd.DoModal();      if (rc == IDOK)      {         newfile = (CMyString)fd.GetPathName();		 rc = Open( newfile );		 if ( rc == PWScore::SUCCESS )	         break;      }      else         return PWScore::USER_CANCEL;   }   return rc;}intDboxMain::Open( const CMyString &pszFilename ){	int rc;	CMyString passkey, temp;	//Check that this file isn't already open	if (pszFilename == m_core.GetCurFile() && !m_needsreading)	{		//It is the same damn file		MessageBox(_T("That file is already open."),			_T("Oops!"),			MB_OK|MB_ICONWARNING);		return PWScore::ALREADY_OPEN;	}		if (m_core.IsChanged())	{		int rc2;				temp =		  _T("Do you want to save changes to the password database: ")		  + m_core.GetCurFile()			+ _T("?");		rc = MessageBox(temp,			AfxGetAppName(),			MB_ICONQUESTION|MB_YESNOCANCEL);		switch (rc)		{		case IDCANCEL:			return PWScore::USER_CANCEL;		case IDYES:			rc2 = Save();			// Make sure that writting the file was successful			if (rc2 == PWScore::SUCCESS)				break;			else				return PWScore::CANT_OPEN_FILE;		case IDNO:			break;		}	}		rc = GetAndCheckPassword(pszFilename, passkey);	switch (rc)	{	case PWScore::SUCCESS:		app.GetMRU()->Add(pszFilename);		break; // Keep going... 	case PWScore::CANT_OPEN_FILE:		temp = m_core.GetCurFile()		  + "\n\nCan't open file. Please choose another.";		MessageBox(temp, _T("File open error."), MB_OK|MB_ICONWARNING);	case TAR_OPEN:		return Open();	case TAR_NEW:		return New();	case PWScore::WRONG_PASSWORD:	/*	If the user just cancelled out of the password dialog, 	assume they want to return to where they were before... 		*/		return PWScore::USER_CANCEL;	}		rc = m_core.ReadFile(pszFilename, passkey);	if (rc == PWScore::CANT_OPEN_FILE)	{		temp = pszFilename;		temp += _T("\n\nCould not open file for reading!");		MessageBox(temp, _T("File read error."), MB_OK|MB_ICONWARNING);		/*		Everything stays as is... Worst case,		they saved their file....		*/		return PWScore::CANT_OPEN_FILE;	}		m_core.SetCurFile(pszFilename);#if !defined(POCKET_PC)	m_title = _T("Password Safe - ") + m_core.GetCurFile();#endif	ChangeOkUpdate();	RefreshList();		return PWScore::SUCCESS;}voidDboxMain::OnNew(){   m_LockDisabled = true;   New();   m_LockDisabled = false;}intDboxMain::New() {   int rc, rc2;   if (m_core.IsChanged())   {      CMyString temp =	_T("Do you want to save changes to the password database: ")	+ m_core.GetCurFile()         + _T("?");      rc = MessageBox(temp,                      AfxGetAppName(),                      MB_ICONQUESTION|MB_YESNOCANCEL);      switch (rc)      {      case IDCANCEL:         return PWScore::USER_CANCEL;      case IDYES:         rc2 = Save();         /*           Make sure that writing the file was successful         */         if (rc2 == PWScore::SUCCESS)            break;         else            return PWScore::CANT_OPEN_FILE;      case IDNO:         break;      }   }   rc = NewFile();   if (rc == PWScore::USER_CANCEL)      /*        Everything stays as is...         Worst case, they saved their file....       */      return PWScore::USER_CANCEL;   m_core.SetCurFile(""); //Force a save as... #if !defined(POCKET_PC)   m_title = _T("Password Safe - <Untitled>");#endif   ChangeOkUpdate();   return PWScore::SUCCESS;}voidDboxMain::OnRestore(){   m_LockDisabled = true;   Restore();   m_LockDisabled = false;}intDboxMain::Restore() {   int rc;   CMyString newback, passkey, temp;   //Open-type dialog box   while (1)   {      CFileDialog fd(TRUE,                     _T("bak"),                     m_currbackup,                     OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_LONGNAMES,                     _T("Password Safe Backups (*.bak)|*.bak||"),                     this);      fd.m_ofn.lpstrTitle = _T("Please Choose a Backup to Restore:");      rc = fd.DoModal();      if (rc == IDOK)      {         newback = (CMyString)fd.GetPathName();         break;      }      else         return PWScore::USER_CANCEL;   }   rc = GetAndCheckPassword(newback, passkey);   switch (rc)   {   case PWScore::SUCCESS:      break; // Keep going...    case PWScore::CANT_OPEN_FILE:      temp =	m_core.GetCurFile()	+ _T("\n\nCan't open file. Please choose another.");      MessageBox(temp, _T("File open error."), MB_OK|MB_ICONWARNING);   case TAR_OPEN:      return Open();   case TAR_NEW:      return New();   case PWScore::WRONG_PASSWORD:      /*        If the user just cancelled out of the password dialog,         assume they want to return to where they were before...       */      return PWScore::USER_CANCEL;   }   if (m_core.IsChanged())   {      int rc2;	      temp = _T("Do you want to save changes to the password list: ")         + m_core.GetCurFile() + _T("?");      rc = MessageBox(temp,                      AfxGetAppName(),                      MB_ICONQUESTION|MB_YESNOCANCEL);      switch (rc)      {      case IDCANCEL:         return PWScore::USER_CANCEL;      case IDYES:         rc2 = Save();         //Make sure that writting the file was successful         if (rc2 == PWScore::SUCCESS)            break;         else            return PWScore::CANT_OPEN_FILE;      case IDNO:         break;      }   }   rc = m_core.ReadFile(newback, passkey);   if (rc == PWScore::CANT_OPEN_FILE)   {      temp = newback + _T("\n\nCould not open file for reading!");      MessageBox(temp, _T("File read error."), MB_OK|MB_ICONWARNING);      //Everything stays as is... Worst case, they saved their file....      return PWScore::CANT_OPEN_FILE;   }	   m_core.SetCurFile(""); //Force a save as...   m_core.SetChanged(true); //So that the *.dat version of the file will be saved.#if !defined(POCKET_PC)   m_title = _T("Password Safe - <Untitled Restored Backup>");#endif   ChangeOkUpdate();   RefreshList();   return PWScore::SUCCESS;}voidDboxMain::OnSaveAs(){   m_LockDisabled = true;   SaveAs();   m_LockDisabled = false;}intDboxMain::SaveAs() {   int rc;   CMyString newfile;   if (m_core.GetReadFileVersion() == PWSfile::V17) {     CMyString msg = _T("The original database, \"");     msg += m_core.GetCurFile();     msg += _T("\", is in pre-2.0 format. The data will now be written in the new"	       " format, which is unusable by old versions of PasswordSafe."	       " To save the data in the old format, use the \"File->Export To"	       "-> Old (1.x) format\" command.\n\n"	       "Press OK to continue saving, or Cancel to stop.");     if (MessageBox(msg, _T("File version warning"),		    MB_OKCANCEL|MB_ICONWARNING) == IDCANCEL)       return PWScore::USER_CANCEL;   }   //SaveAs-type dialog box   while (1)   {      CFileDialog fd(FALSE,                     _T("dat"),                     m_core.GetCurFile(),                     OFN_PATHMUSTEXIST|OFN_HIDEREADONLY                     |OFN_LONGNAMES|OFN_OVERWRITEPROMPT,                     _T("Password Safe Databases (*.dat)|*.dat|")                     _T("All files (*.*)|*.*|")                     _T("|"),                     this);      if (m_core.GetCurFile().IsEmpty())         fd.m_ofn.lpstrTitle =            _T("Please Choose a Name for the Current (Untitled) Database:");      else         fd.m_ofn.lpstrTitle =            _T("Please Choose a New Name for the Current Database:");      rc = fd.DoModal();      if (rc == IDOK)      {         newfile = (CMyString)fd.GetPathName();         break;      }      else         return PWScore::USER_CANCEL;   }   rc = m_core.WriteFile(newfile);   if (rc == PWScore::CANT_OPEN_FILE)   {      CMyString temp = newfile + _T("\n\nCould not open file for writing!");      MessageBox(temp, _T("File write error."), MB_OK|MB_ICONWARNING);      return PWScore::CANT_OPEN_FILE;   }   m_core.SetCurFile(newfile);#if !defined(POCKET_PC)   m_title = _T("Password Safe - ") + m_core.GetCurFile();#endif   ChangeOkUpdate();   app.GetMRU()->Add( newfile );   return PWScore::SUCCESS;}intDboxMain::GetAndCheckPassword(const CMyString &filename,			      CMyString& passkey,			      bool first){  // Called for an existing database. promt user  // for password, verify against file  int retval;  if (!filename.IsEmpty())    {      bool exists = m_core.FileExists(filename);      if (!exists) {	// Used to display an error message, but this is really the caller's business	return PWScore::CANT_OPEN_FILE;      } // !exists    } // !filename.IsEmpty()  /*   * with my unsightly hacks of PasskeyEntry, it should now accept   * a blank filename, which will disable passkey entry and the OK button   */  CPasskeyEntry dbox_pkentry(this, filename, first);  int rc = dbox_pkentry.DoModal();  if (rc == IDOK)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -