示例#1
0
void CPwSafeApp::ChangeKdbShellAssociation(BOOL bRegister, HWND hParent)
{
	CPwSafeApp::LoadTranslationEx(NULL);

	if(bRegister == TRUE)
	{
		if(CPwSafeApp::RegisterShellAssociation() == TRUE)
		{
			CPwSafeApp::NotifyAssocChanged();

			::MessageBox(hParent, TRL("Successfully associated KeePass with .kdb files! A double-click on a .kdb file will now start KeePass automatically."),
				PWM_PRODUCT_NAME_SHORT, MB_OK | MB_ICONINFORMATION);
		}
		else
		{
			::MessageBox(hParent, TRL("Failed to change the .kdb file association. Make sure you have the rights to write to the registry and change file associations."),
				PWM_PRODUCT_NAME_SHORT, MB_OK | MB_ICONWARNING);
		}
	}
	else // Unregister
	{
		if(CPwSafeApp::UnregisterShellAssociation() == TRUE)
		{
			CPwSafeApp::NotifyAssocChanged();

			::MessageBox(hParent, TRL("Successfully removed association! KeePass won't be started anymore when double-clicking on a .kdb file."),
				PWM_PRODUCT_NAME_SHORT, MB_OK | MB_ICONINFORMATION);
		}
		else
		{
			::MessageBox(hParent, TRL("Failed to change the .kdb file association. Make sure you have the rights to write to the registry and change file associations."),
				PWM_PRODUCT_NAME_SHORT, MB_OK | MB_ICONWARNING);
		}
	}
}
示例#2
0
void NewGUI_ShowQualityMeter(CQualityProgressCtrl *pProgress, CWnd *pStatic,
	LPCTSTR pszPassword)
{
	if(pProgress == NULL) { ASSERT(FALSE); return; }
	if(pStatic == NULL) { ASSERT(FALSE); return; }
	if(pszPassword == NULL) { ASSERT(FALSE); return; }

	const size_t uLength = _tcslen(pszPassword);
	DWORD dwBits = CPwQualityEst::EstimatePasswordBits(pszPassword);
	if(dwBits > 9999) dwBits = 9999; // 4 characters display limit

	CString strQuality;
	strQuality.Format(_T("%u"), dwBits);
	strQuality += _T(" ");
	strQuality += TRL("bits");

	CString strLength;
	strLength.Format(_T("%u"), uLength);
	strLength += _T(" ");
	strLength += TRL("ch.");

	if(dwBits > 128) dwBits = 128;
	pProgress->SetProgressText(strQuality);
	pProgress->SetPos((int)dwBits);

	pStatic->SetWindowText(strLength);
}
示例#3
0
bool CLanguagesDlg::InitEx(HWND hParent) 
{
	bool bRet = true;

	std_string strDir = SU_DriveLetterToUpper(Executable::instance().getPathOnly());
	std_string strFilter = strDir + _T("*.lng");

	CFileFind ff;
	if(ff.FindFile(strFilter.c_str(), 0) != FALSE)
	{
		std_string str = TRL("One or more language files have been found in the KeePass application directory.");
		str += _T("\r\n\r\n");

		std_string strFiles;
		DWORD cFiles = 0;
		const DWORD cMaxFL = 6;
		BOOL bMore = TRUE;
		while(bMore != FALSE)
		{
			bMore = ff.FindNextFile();

			++cFiles;
			if(cFiles <= cMaxFL)
			{
				strFiles += ((cFiles == cMaxFL) ? _T("...") : (LPCTSTR)ff.GetFilePath());
				strFiles += _T("\r\n");
			}
		}
		str += strFiles;
		str += _T("\r\n");

		str += TRL("Loading language files directly from the application directory is not supported. Language files should instead be stored in the 'Languages' folder of the application directory.");
		str += _T("\r\n\r\n");
		str += TRL("Do you want to open the application directory (in order to move or delete language files)?");

		if(::MessageBox(hParent, str.c_str(), PWM_PRODUCT_NAME_SHORT, MB_ICONWARNING |
			MB_YESNO) == IDYES)
		{
			CString strUrl = strDir.c_str();
			if(strDir.size() > 3) strUrl = strUrl.TrimRight(_T('\\'));
			strUrl = CString(_T("cmd://\"")) + strUrl + _T("\"");
			OpenUrlEx(strUrl, hParent);

			bRet = false;
		}
	}

	ff.Close();
	return bRet;
}
示例#4
0
BOOL CUpdateInfoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	NewGUI_TranslateCWnd(this);
	EnumChildWindows(this->m_hWnd, NewGUI_TranslateWindowCb, 0);

	CFontUtil::SetDefaultFontFrom(&m_lblStatus);

	// CFont* pDialogFont = m_lblStatus.GetFont();
	// LOGFONT lf;
	// pDialogFont->GetLogFont(&lf);
	// m_fBold.CreateFont(lf.lfHeight, lf.lfWidth, lf.lfEscapement, lf.lfOrientation,
	//	FW_BOLD, lf.lfItalic, lf.lfUnderline, lf.lfStrikeOut,
	//	lf.lfCharSet, lf.lfOutPrecision, lf.lfClipPrecision, lf.lfQuality,
	//	lf.lfPitchAndFamily, lf.lfFaceName);
	// m_lblStatus.SetFont(&m_fBold);
	CFontUtil::AssignBold(&m_lblStatus, this);

	NewGUI_XPButton(m_btClose, IDB_CANCEL, IDB_CANCEL);

	NewGUI_MakeHyperLink(&m_hlVisitWebsite);
	m_hlVisitWebsite.EnableTooltip(FALSE);
	m_hlVisitWebsite.SetNotifyParent(TRUE);
	m_hlVisitWebsite.EnableURL(FALSE);

	ASSERT(m_pImgList != NULL);
	m_cList.SetImageList(m_pImgList, LVSIL_SMALL);

	// m_cList.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_SI_REPORT |
	//	LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE |
	//	LVS_EX_UNDERLINEHOT | LVS_EX_INFOTIP);
	m_cList.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_SI_REPORT |
		LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_INFOTIP);

	RECT rect;
	m_cList.GetWindowRect(&rect);
	const int nWidth = (rect.right - rect.left - GetSystemMetrics(SM_CXVSCROLL) - 8) / 6;
	m_cList.InsertColumn(0, TRL("Component"), LVCFMT_LEFT, nWidth * 2, 0);
	m_cList.InsertColumn(1, TRL("Status"), LVCFMT_LEFT, nWidth * 2, 1);
	m_cList.InsertColumn(2, TRL("Installed"), LVCFMT_LEFT, nWidth, 2);
	m_cList.InsertColumn(3, TRL("Available"), LVCFMT_LEFT, nWidth, 3);

	FillComponentList();

	UpdateData(FALSE);
	return TRUE;
}
示例#5
0
BOOL CImportOptionsDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	NewGUI_TranslateCWnd(this);
	EnumChildWindows(this->m_hWnd, NewGUI_TranslateWindowCb, 0);

	NewGUI_XPButton(m_btOK, IDB_OK, IDB_OK);
	NewGUI_XPButton(m_btCancel, IDB_CANCEL, IDB_CANCEL);

	NewGUI_ConfigSideBanner(&m_banner, this);
	m_banner.SetIcon(AfxGetApp()->LoadIcon(IDI_ICONPIC),
		KCSB_ICON_LEFT | KCSB_ICON_VCENTER);
	m_banner.SetTitle(TRL("Options"));
	m_banner.SetCaption(_T(" "));

	CFontUtil::SetDefaultFontFrom(GetDlgItem(IDC_RADIO_CREATENEW));

	// m_fBold.CreateFont(-10, 0, 0, 0, FW_BOLD, FALSE, FALSE, 0,
	//	DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
	//	DEFAULT_QUALITY, DEFAULT_PITCH | FF_MODERN, _T("MS Shell Dlg"));

	// GetDlgItem(IDC_RADIO_CREATENEW)->SetFont(&m_fBold);
	// GetDlgItem(IDC_RADIO_OVERWRITE_ALWAYS)->SetFont(&m_fBold);
	// GetDlgItem(IDC_RADIO_OVERWRITE_TIMEBASED)->SetFont(&m_fBold);
	CFontUtil::AssignBold(GetDlgItem(IDC_RADIO_CREATENEW), this);
	CFontUtil::AssignBold(GetDlgItem(IDC_RADIO_OVERWRITE_ALWAYS), this);
	CFontUtil::AssignBold(GetDlgItem(IDC_RADIO_OVERWRITE_TIMEBASED), this);

	return TRUE;
}
示例#6
0
void CUpdateCheckEx::_RunCheck(void* pDlg)
{
	UC_COMPONENTS_LIST vInstalled;
	CUpdateCheckEx::GetInstalledComponents(vInstalled, true);

	BYTE* pb = NULL;
	std_string strError;
	HRESULT hRes = CUpdateCheckEx::DownloadInfoFile(&pb, strError);
	if(FAILED(hRes))
	{
		SAFE_DELETE_ARRAY(pb);

		_FinalReport(vInstalled, strError.c_str(), true, 0, pDlg);
		return;
	}

	UC_COMPONENTS_LIST vAvailable;
	hRes = CUpdateCheckEx::ParseInfoFile(pb, vAvailable);
	SAFE_DELETE_ARRAY(pb);
	if(FAILED(hRes))
	{
		_FinalReport(vInstalled, TRL("Loading error"), true, 0, pDlg);
		return;
	}

	CUpdateCheckEx::CopyAvailableVersions(vAvailable, vInstalled);

	std_string strReport;
	DWORD dwUpdates = 0;
	CUpdateCheckEx::CompareVersions(vInstalled, true, strReport, dwUpdates);
	_FinalReport(vInstalled, strReport.c_str(), false, dwUpdates, pDlg);
}
示例#7
0
BOOL CPwGeneratorAdvDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	ASSERT(m_pOpt != NULL); if(m_pOpt == NULL) return TRUE;

	NewGUI_TranslateCWnd(this);
	EnumChildWindows(this->m_hWnd, NewGUI_TranslateWindowCb, 0);

	NewGUI_XPButton(m_btOK, IDB_OK, IDB_OK);
	NewGUI_XPButton(m_btCancel, IDB_CANCEL, IDB_CANCEL);
	NewGUI_XPButton(m_btHelp, IDB_HELP_SMALL, IDB_HELP_SMALL);

	NewGUI_ConfigSideBanner(&m_banner, this);
	m_banner.SetIcon(AfxGetApp()->LoadIcon(IDI_KEY),
		KCSB_ICON_LEFT | KCSB_ICON_VCENTER);
	m_banner.SetTitle(TRL("Options"));
	m_banner.SetCaption(TRL("Advanced Password Generator Options"));

	CString str;
	GetDlgItem(IDC_CHECK_EXCLUDE_LOOKALIKE)->GetWindowText(str);
	GetDlgItem(IDC_CHECK_EXCLUDE_LOOKALIKE)->SetWindowText(str + _T(" (l|1I, O0) *"));

	GetDlgItem(IDC_CHECK_NO_REPEAT)->GetWindowText(str);
	GetDlgItem(IDC_CHECK_NO_REPEAT)->SetWindowText(str + _T(" *"));

	GetDlgItem(IDC_STATIC_EXCLUDECHARS)->GetWindowText(str);
	GetDlgItem(IDC_STATIC_EXCLUDECHARS)->SetWindowText(str + _T(" *"));

	GetDlgItem(IDC_STATIC_SECREDUCINFO)->GetWindowText(str);
	GetDlgItem(IDC_STATIC_SECREDUCINFO)->SetWindowText(_T("* ") + str);

	m_bNoConfusing = m_pOpt->bNoConfusing;
	m_bNoRepeat = m_pOpt->bNoRepeat;

#ifdef _UNICODE
	m_strExcludeChars = m_pOpt->strExcludeChars.c_str();
#else
	char *pExcl = _StringToAnsi(m_pOpt->strExcludeChars.c_str());
	m_strExcludeChars = pExcl;
	SAFE_DELETE_ARRAY(pExcl);
#endif

	UpdateData(FALSE);
	return TRUE;
}
示例#8
0
void CUpdateCheckEx::GetInstalledComponents(UC_COMPONENTS_LIST& vList,
	bool bDefaultToUnknownStatus)
{
	vList.clear();

	UC_COMPONENT_INFO kp;
	kp.strName = PWM_PRODUCT_NAME_SHORT;
	kp.qwVerInstalled = PWM_VERSION_QW;
	vList.push_back(kp);

	const CPluginManager& pm = CPluginManager::Instance();

	typedef std::vector<KP_PLUGIN_INSTANCE>::const_iterator PlgIter;
	for(PlgIter it = pm.m_plugins.begin(); it != pm.m_plugins.end(); ++it)
	{
		if((it->hinstDLL == NULL) || (it->pInterface == NULL))
		{
			ASSERT(FALSE);
			continue;
		}

		UC_COMPONENT_INFO c;
		c.strName = it->strName;
		c.qwVerInstalled = it->qwVersion;

		vList.push_back(c);
	}

	for(size_t i = 0; i < vList.size(); ++i)
	{
		if(bDefaultToUnknownStatus)
		{
			if(i > 0) vList[i].strStatus = TRL("Plugin unknown.");
			else { vList[i].strStatus = TRL("Unknown"); vList[i].strStatus += _T("."); }

			vList[i].iStatusImage = 44;
		}

		vList[i].qwVerAvailable = 0;
	}

	SortComponentsList(vList);
}
示例#9
0
void CUpdateCheckEx::EnsureConfigured(BOOL* pCheck, BOOL* pConfig,
	HWND hParent, HINSTANCE hInstance)
{
	if((pCheck == NULL) || (pConfig == NULL)) { ASSERT(FALSE); return; }
	if((*pConfig) != FALSE) return;

#ifdef PWM_DEVSNAPSHOT
	UNREFERENCED_PARAMETER(hParent);
	UNREFERENCED_PARAMETER(hInstance);
#else
	// If the user has manually enabled the automatic update check
	// before, there's no need to ask him again
	if((*pCheck) == FALSE)
	{
		CString strHdr = TRL("KeePass can automatically check for updates on each program start.");
		
		CString strSub = TRL("Automatic update checks are performed unintrusively in the background. A notification is only displayed when an update is available. Updates are not downloaded or installed automatically.");
		strSub += _T("\r\n\r\n");
		strSub += TRL("No personal information is sent to the KeePass web server. KeePass just downloads a small version information file and compares the available version with the installed version.");

		CString strEnable = TRL("&Enable");
		strEnable += _T(" (");
		strEnable += TRL("recommended");
		strEnable += _T(")");

		CString strQ = TRL("Enable automatic update check?");

		CVistaTaskDialog dlg(hParent, hInstance, true);
		dlg.SetContent(strHdr);
		dlg.SetMainInstruction(strQ);
		dlg.SetWindowTitle(PWM_PRODUCT_NAME_SHORT);
		dlg.AddButton(strEnable, NULL, IDYES);
		dlg.AddButton(TRL("&Disable"), NULL, IDNO);
		dlg.SetIcon(MTDI_QUESTION);
		dlg.SetFooterText(strSub);
		dlg.SetFooterIcon(TD_INFORMATION_ICON);

		int dr = dlg.ShowDialog(NULL);
		if(dr < 0)
		{
			CString strMain = strHdr;
			strMain += _T("\r\n\r\n");
			strMain += strSub;
			strMain += _T("\r\n\r\n");
			strMain += strQ;

			dr = MessageBox(hParent, strMain, PWM_PRODUCT_NAME_SHORT,
				MB_YESNO | MB_ICONQUESTION);
		}

		*pCheck = (((dr == IDOK) || (dr == IDYES)) ? TRUE : FALSE);
	}
#endif

	*pConfig = TRUE;
}
示例#10
0
void CLanguagesDlg::_LoadLanguage(LPCTSTR szLang)
{
	CPrivateConfigEx cConfig(TRUE);

	if(_tcscmp(szLang, _T("English")) != 0)
	{
		std_string strFile =  SU_DriveLetterToUpper(Executable::instance().getPathOnly());
		strFile += PWM_DIR_LANGUAGES;
		strFile += _T("\\");
		strFile += szLang;
		strFile += _T(".lng");

		FILE* fp = NULL;
		_tfopen_s(&fp, strFile.c_str(), _T("rb"));
		ASSERT(fp != NULL);
		if(fp == NULL)
		{
			MessageBox(TRL("Language file cannot be opened!"), TRL("Loading error"), MB_OK | MB_ICONWARNING);
			return;
		}
		fclose(fp);

		if(cConfig.Set(PWMKEY_LANG, szLang) == FALSE)
		{
			MessageBox(TRL("Language file cannot be activated!"), TRL("Loading error"), MB_OK | MB_ICONWARNING);
			return;
		}
	}
	else cConfig.Set(PWMKEY_LANG, _T("Standard"));

	CString str = TRL("The selected language has been activated. KeePass must be restarted in order to load the language.");
	str += _T("\r\n\r\n");
	str += TRL("Do you wish to restart KeePass now?");

	int iResult = CVistaTaskDialog::ShowMessageBox(this->m_hWnd, TRL("Restart KeePass?"),
		str, MTDI_QUESTION, TRL("&Yes"), IDOK, TRL("&No"), IDCANCEL);
	if(iResult < 0)
		iResult = MessageBox(str, TRL("Restart KeePass?"), MB_YESNO | MB_ICONQUESTION);
	if((iResult == IDOK) || (iResult == IDYES)) CDialog::OnOK();
}
示例#11
0
void CLanguagesDlg::_LoadLanguage(LPCTSTR szLang)
{
	FILE *fp = NULL;
	CPrivateConfigEx cConfig(TRUE);

	// GetModuleFileName(NULL, szFile, MAX_PATH * 2);
	// for(i = _tcslen(szFile)-1; i > 1; i--) // Extract dir
	// {
	//	if(szFile[i] == _T('\\')) { szFile[i] = 0; break; }
	// }
	// _tcscat_s(szFile, _countof(szFile), _T("\\"));
	// _tcscat_s(szFile, _countof(szFile), szLang);
	std_string strFile =  Executable::instance().getPathOnly();
	strFile += szLang;

	if(_tcscmp(szLang, _T("English")) != 0)
	{
		// _tcscat_s(szFile, _countof(szFile), _T(".lng"));
		strFile += _T(".lng");

		_tfopen_s(&fp, strFile.c_str(), _T("rb"));
		ASSERT(fp != NULL);
		if(fp == NULL)
		{
			MessageBox(TRL("Language file cannot be opened!"), TRL("Loading error"), MB_OK | MB_ICONWARNING);
			return;
		}
		fclose(fp);

		if(cConfig.Set(PWMKEY_LANG, szLang) == FALSE)
		{
			MessageBox(TRL("Language file cannot be registered!"), TRL("Loading error"), MB_OK | MB_ICONWARNING);
			return;
		}
	}
	else cConfig.Set(PWMKEY_LANG, _T("Standard"));

	CString str = TRL("The language file has been installed.");
	str += _T("\r\n\r\n");
	str += TRL("You must restart KeePass in order to use the new language.");
	str += _T("\r\n\r\n");
	str += TRL("Do you wish to restart KeePass now?");

	const int i = MessageBox(str, TRL("Restart KeePass?"), MB_YESNO |
		MB_ICONQUESTION);
	if(i == IDYES)
	{
		CDialog::OnOK();
	}
}
BOOL CHelpSourceDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	NewGUI_TranslateCWnd(this);
	EnumChildWindows(this->m_hWnd, NewGUI_TranslateWindowCb, 0);

	NewGUI_XPButton(m_btnOK, IDB_OK, IDB_OK);
	NewGUI_XPButton(m_btnCancel, IDB_CANCEL, IDB_CANCEL);

	NewGUI_ConfigSideBanner(&m_banner, this);
	m_banner.SetIcon(AfxGetApp()->LoadIcon(IDI_OPTIONS),
		KCSB_ICON_LEFT | KCSB_ICON_VCENTER);
	m_banner.SetTitle(TRL("Help Source"));
	m_banner.SetCaption(TRL("Choose between local help and online help center."));

	if(WU_GetAppHelpSource() == APPHS_LOCAL)
		m_rbLocalHelp.SetCheck(BST_CHECKED);
	else
		m_rbOnlineHelp.SetCheck(BST_CHECKED);

	CFontUtil::SetDefaultFontFrom(&m_rbLocalHelp);

	// CFont* pFont = m_rbLocalHelp.GetFont();
	// if(pFont != NULL)
	// {
	//	LOGFONT lf;
	//	pFont->GetLogFont(&lf);
	//	lf.lfWeight = FW_BOLD;
	//	m_pBoldFont = new CFont();
	//	VERIFY(m_pBoldFont->CreateFontIndirect(&lf));
	//	m_rbLocalHelp.SetFont(m_pBoldFont);
	//	m_rbOnlineHelp.SetFont(m_pBoldFont);
	// }
	CFontUtil::AssignBold(&m_rbLocalHelp, this);
	CFontUtil::AssignBold(&m_rbOnlineHelp, this);

	return TRUE;
}
示例#13
0
BOOL CTanWizardDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	NewGUI_TranslateCWnd(this);
	EnumChildWindows(this->m_hWnd, NewGUI_TranslateWindowCb, 0);

	NewGUI_XPButton(m_btOK, IDB_OK, IDB_OK);
	NewGUI_XPButton(m_btCancel, IDB_CANCEL, IDB_CANCEL);
	NewGUI_XPButton(m_btHelp, IDB_HELP_SMALL, IDB_HELP_SMALL);

	NewGUI_ConfigSideBanner(&m_banner, this);
	m_banner.SetIcon(AfxGetApp()->LoadIcon(IDI_OPTIONS),
		KCSB_ICON_LEFT | KCSB_ICON_VCENTER);
	m_banner.SetTitle(TRL("TAN Wizard"));
	m_banner.SetCaption(TRL("Using this wizard you can easily add TAN entries."));

	GetDlgItem(IDC_EDIT_NUMBERING_START)->EnableWindow(FALSE);

	CString strToGroup;
	GetDlgItem(IDC_STATIC_TOGROUP)->GetWindowText(strToGroup);
	if(m_strGroupName.GetLength() > 0)
	{
		strToGroup += _T(": ");
		strToGroup += m_strGroupName;
	}
	strToGroup += _T(".");
	GetDlgItem(IDC_STATIC_TOGROUP)->SetWindowText(strToGroup);

	TCHAR lpTANChars[SI_REGSIZE + 1];
	CPrivateConfigEx cfg(FALSE);
	if(cfg.Get(PWMKEY_TANCHARS, lpTANChars) == TRUE) m_strTANChars = lpTANChars;
	else m_strTANChars = TW_DEFAULTCHARS;

	UpdateData(FALSE);

	GetDlgItem(IDC_EDIT_TANS)->SetFocus();
	return FALSE;
}
示例#14
0
void COptionsList::InitOptionListEx(CImageList *pImages, BOOL bTwoColumns)
{
	ASSERT(pImages != NULL); if(pImages == NULL) return;
	m_pImages = pImages;

	m_bTwoColumns = bTwoColumns;

	PostMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_SI_MENU |
		LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);

	SetImageList(m_pImages, LVSIL_SMALL);

	DeleteAllItems();
	RECT rect;
	GetClientRect(&rect);
	int nWidth = rect.right - rect.left - GetSystemMetrics(SM_CXVSCROLL) - 8;
	if(m_bTwoColumns == TRUE) nWidth /= 2;
	InsertColumn(0, TRL("Options"), LVCFMT_LEFT, nWidth, 0);

	if(m_bTwoColumns == TRUE)
		InsertColumn(1, TRL("Value"), LVCFMT_LEFT, nWidth, 1);
}
示例#15
0
void CAddGroupDlg::OnOK() 
{
	UpdateData(TRUE);

	if(m_strGroupName.GetLength() == 0)
	{
		MessageBox(TRL("Enter a group name!"), PWM_PRODUCT_NAME_SHORT, MB_ICONWARNING | MB_OK);
		return;
	}

	CString strId = m_strGroupName;
	strId = strId.MakeLower();

	CString strSearch = PWS_SEARCHGROUP; // PWS_SEARCHGROUP is translated
	strSearch = strSearch.MakeLower();
	CString strBackup1 = PWS_BACKUPGROUP;
	strBackup1 = strBackup1.MakeLower();
	CString strBackup2 = PWS_BACKUPGROUP_SRC;
	strBackup2 = strBackup2.MakeLower();

	if(m_strGroupName == m_strInitialName) { } // Always allow unchanged
	else if(strId == strSearch)
	{
		MessageBox(TRL("The group you selected cannot store entries. Please select a different group."),
			PWM_PRODUCT_NAME_SHORT, MB_ICONWARNING | MB_OK);
		return;
	}
	else if((strId == strBackup1) || (strId == strBackup2))
	{
		CString strResMsg = TRL("The specified name is reserved.");
		strResMsg += _T("\r\n\r\n");
		strResMsg += TRL("Please choose a different name.");
		MessageBox(strResMsg, PWM_PRODUCT_NAME_SHORT, MB_ICONWARNING | MB_OK);
		return;
	}

	CDialog::OnOK();
}
示例#16
0
std::basic_string<TCHAR> CEntryUtil::CreateSummaryList(CPwManager* pMgr,
	const std::vector<DWORD>& vEntryIndices)
{
	std::basic_string<TCHAR> strEmpty;
	if(pMgr == NULL) { ASSERT(FALSE); return strEmpty; }
	if(vEntryIndices.size() == 0) return strEmpty;

	const size_t uMaxEntries = 10;
	size_t uSummaryShow = min(uMaxEntries, vEntryIndices.size());
	if(uSummaryShow == (vEntryIndices.size() - 1)) --uSummaryShow; // Plural msg

	CStringBuilderEx sb;
	for(size_t i = 0; i < uSummaryShow; ++i)
	{
		PW_ENTRY* pe = pMgr->GetEntry(vEntryIndices[i]);
		if(pe == NULL) { ASSERT(FALSE); continue; }

		if(sb.GetLength() > 0) sb.Append(_T("\r\n"));

		sb.Append(_T("- "));
		std::basic_string<TCHAR> strItem = SU_CompactWith3Dots(pe->pszTitle, 39);
		sb.Append(strItem.c_str());

		if(CPwUtil::IsTANEntry(pe) != FALSE)
		{
			std::basic_string<TCHAR> strTanID = SU_CompactWith3Dots(pe->pszUserName, 39);
			if(strTanID.size() > 0)
			{
				sb.Append(_T(" (#"));
				sb.Append(strTanID.c_str());
				sb.Append(_T(")"));
			}
		}
	}

	if(uSummaryShow != vEntryIndices.size())
	{
		const std::basic_string<TCHAR> strCount =
			boost::lexical_cast<std::basic_string<TCHAR> >(static_cast<int>(
			vEntryIndices.size() - uSummaryShow));

		CString strMore = TRL("{PARAM} more entries");
		VERIFY(strMore.Replace(_T("{PARAM}"), strCount.c_str()) == 1);

		sb.Append(_T("\r\n- "));
		sb.Append(strMore);
	}

	return sb.ToString();
}
示例#17
0
BOOL CIconPickerDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	ASSERT(m_pImageList != NULL);
	ASSERT(m_uNumIcons != 0);

	NewGUI_TranslateCWnd(this);
	EnumChildWindows(this->m_hWnd, NewGUI_TranslateWindowCb, 0);

	m_cList.SetImageList(m_pImageList, LVSIL_SMALL);

	ASSERT(LVM_SETEXTENDEDLISTVIEWSTYLE == (0x1000 + 54));
	// m_cList.PostMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_SI_REPORT |
	//	LVS_EX_ONECLICKACTIVATE | LVS_EX_UNDERLINEHOT);

	for(UINT i = 0; i < m_uNumIcons; ++i)
	{
		CString str;
		str.Format(_T("%u"), i);
		m_cList.InsertItem(LVIF_IMAGE | LVIF_TEXT, static_cast<int>(i), str, 0, 0, i, 0);
	}

	if((m_nSelectedIcon >= 0) && (m_nSelectedIcon < m_cList.GetItemCount()))
		m_cList.SetItemState(m_nSelectedIcon, LVIS_SELECTED, LVIS_SELECTED);

	NewGUI_XPButton(m_btOK, IDB_OK, IDB_OK);
	NewGUI_XPButton(m_btCancel, IDB_CANCEL, IDB_CANCEL);

	NewGUI_ConfigSideBanner(&m_banner, this);
	m_banner.SetIcon(AfxGetApp()->LoadIcon(IDI_ICONPIC),
		KCSB_ICON_LEFT | KCSB_ICON_VCENTER);
	m_banner.SetTitle(TRL("Pick an Icon"));
	m_banner.SetCaption(TRL("Choose an icon from the list of available entry and group icons."));

	return TRUE; // Return TRUE unless you set the focus to a control
}
示例#18
0
BOOL CPluginsDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	NewGUI_TranslateCWnd(this);
	EnumChildWindows(this->m_hWnd, NewGUI_TranslateWindowCb, 0);

	ASSERT(m_pPiMgr != NULL);
	ASSERT(m_pImgList != NULL);

	NewGUI_XPButton(m_btClose, IDB_OK, IDB_OK);
	NewGUI_XPButton(m_btHelp, IDB_HELP_SMALL, IDB_HELP_SMALL);

	NewGUI_ConfigSideBanner(&m_banner, this);
	m_banner.SetIcon(AfxGetApp()->LoadIcon(IDI_PLUGINS),
		KCSB_ICON_LEFT | KCSB_ICON_VCENTER);
	m_banner.SetTitle(TRL("Plugins"));
	m_banner.SetCaption(TRL("Here you can configure all installed KeePass plugins."));

	NewGUI_MakeHyperLink(&m_hlGetPlugins);
	m_hlGetPlugins.EnableTooltip(FALSE);
	m_hlGetPlugins.SetNotifyParent(TRUE);
	m_hlGetPlugins.EnableURL(FALSE);

	m_cList.SetImageList(m_pImgList, LVSIL_SMALL);

	// m_cList.PostMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_SI_REPORT |
	//	LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE |
	//	LVS_EX_UNDERLINEHOT | LVS_EX_INFOTIP);
	m_cList.PostMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_SI_REPORT |
		LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_INFOTIP);

	RECT rect;
	m_cList.GetWindowRect(&rect);
	const int nWidth = (rect.right - rect.left - GetSystemMetrics(SM_CXVSCROLL) - 8) / 7;
	m_cList.InsertColumn(0, TRL("Plugin"), LVCFMT_LEFT, nWidth * 3, 0);
	m_cList.InsertColumn(1, TRL("Version"), LVCFMT_LEFT, nWidth, 1);
	m_cList.InsertColumn(2, TRL("Author"), LVCFMT_LEFT, nWidth * 3, 2);
	m_cList.InsertColumn(3, TRL("ID"), LVCFMT_LEFT, 0, 3);

	// TCHAR tszBase[MAX_PATH]; tszBase[0] = 0; tszBase[1] = 0;
	// GetModuleFileName(NULL, tszBase, MAX_PATH - 2);
	// int jj;
	// for(jj = (int)_tcslen(tszBase) - 1; jj > 0; jj--)
	//	if(tszBase[jj] == _T('\\'))
	//	{
	//		tszBase[jj + 1] = 0;
	//		break;
	//	}
	// std_string strBase = Executable::instance().getPathOnly();
	// VERIFY(m_pPiMgr->AddAllPlugins(strBase.c_str(), _T("*.dll"), FALSE)); // Updates existing list

	UpdateGUI();

	return TRUE;
}
示例#19
0
void CUpdateCheckEx::CompareVersions(UC_COMPONENTS_LIST& v, bool bSetStatus,
	std_string& strReport, DWORD& dwUpdates)
{
	DWORD dwAvUpdates = 0;
	for(size_t i = 0; i < v.size(); ++i)
	{
		const UINT64 dwIn = v[i].qwVerInstalled;
		const UINT64 dwAv = v[i].qwVerAvailable;

		if(dwIn == dwAv)
		{
			if(bSetStatus)
			{
				v[i].strStatus = TRL("Up to date.");
				v[i].iStatusImage = 53;
			}
		}
		else if(dwIn < dwAv)
		{
			if(bSetStatus)
			{
				v[i].strStatus = TRL("New version available.");
				v[i].iStatusImage = 61;
			}

			++dwAvUpdates;
		}
		else if((dwIn > dwAv) && (dwAv != 0))
		{
			if(bSetStatus)
			{
				v[i].strStatus = TRL("Pre-release version.");
				v[i].iStatusImage = 39;
			}
		}
	}

	dwUpdates = dwAvUpdates;
	if(dwAvUpdates == 0) strReport = TRL("No updates available.");
	else if(dwAvUpdates == 1) strReport = TRL("1 update is available!");
	else
	{
		CString strFmt;
		strFmt.Format(TRL("%u updates are available!"), dwAvUpdates);
		strReport = (LPCTSTR)strFmt;
	}
}
示例#20
0
BOOL CAddGroupDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	ASSERT(m_pParentImageList != NULL);

	EnumChildWindows(this->m_hWnd, NewGUI_TranslateWindowCb, 0);

	NewGUI_XPButton(m_btSetIcon, -1, -1);
	NewGUI_XPButton(m_btOK, IDB_OK, IDB_OK);
	NewGUI_XPButton(m_btCancel, IDB_CANCEL, IDB_CANCEL);

	m_btSetIcon.SetTooltipText(TRL("Choose an icon."), TRUE);
	if((m_nIconId >= 0) && (m_pParentImageList != NULL))
		m_btSetIcon.SetIcon(m_pParentImageList->ExtractIcon(m_nIconId));

	NewGUI_ConfigSideBanner(&m_banner, this);
	m_banner.SetIcon(AfxGetApp()->LoadIcon(IDI_KEY),
		KCSB_ICON_LEFT | KCSB_ICON_VCENTER);

	if(m_bEditMode == FALSE)
	{
		m_banner.SetTitle(TRL("Add Group"));
		m_banner.SetCaption(TRL("Create a new password group."));
		SetWindowText(TRL("Add Group"));
	}
	else
	{
		m_banner.SetTitle(TRL("Edit Group"));
		m_banner.SetCaption(TRL("Modify existing password group."));
		SetWindowText(TRL("Edit Group"));
	}

	m_strInitialName = m_strGroupName;

	UpdateData(FALSE);
	GetDlgItem(IDC_EDIT_GROUPNAME)->SetFocus();
	return FALSE; // Return TRUE unless you set the focus to a control
}
示例#21
0
BOOL CPwImport::ImportPwSafeToDb(const TCHAR *pszFile, CPwManager *pMgr)
{
	char *pData;
	unsigned long uFileSize, i;
	int nField, j;
	CString strGroup, strTitle, strUserName, strPassword, strNotes;
	DWORD dwGroupId;
	BOOL bInNotes = FALSE;
	CString str3, str4, str5, str6;

	ASSERT(pszFile != NULL); if(pszFile == NULL) return FALSE;
	ASSERT(pMgr != NULL); if(pMgr == NULL) return FALSE;

	pData = CPwImport::FileToMemory(pszFile, &uFileSize);
	if(pData == NULL) return FALSE;

	nField = 0;
	i = 0; j = 0;
	strGroup.Empty(); strTitle.Empty(); strUserName.Empty(); strPassword.Empty(); strNotes.Empty();

	if(uFileSize > 3)
		if((static_cast<unsigned char>(pData[0]) == 0xEF) &&
			(static_cast<unsigned char>(pData[1]) == 0xBB) &&
			(static_cast<unsigned char>(pData[2]) == 0xBF))
			i += 3; // Skip UTF-8 initialization characters

	while(true)
	{
		if((pData[i] == '\t') && (bInNotes == FALSE))
		{
			nField++;

			if(nField == 1)
			{
				j = strGroup.ReverseFind(_T('.'));

				// Thanks to Andrew D. Bond for the following improvement
				// Slightly enhanced by D. Reichl to detect some more URLs

				// -- Andrew D. Bond
				// Introduction: The Password Safe export format is rather flawed,
				// since it uses the '.' character as the group / title separator.
				// However, '.' is not likely to appear in the context of titles
				// that include 'com', 'org', 'edu', etc, (domain names) or even
				// 'zip' (password protected zip files)

				// Slightly-smarter import: if the '.' we just found is followed
				// by 'com', 'org', 'edu', etc, (domain names) or even
				// 'zip' (password protected zip files) then figure this is part
				// of the title and try the group / title splitting again.
				// Example:
				//  strGroup = "websites.someSite.com" // j == 17 // <- INCORRECT
				//
				// Overall, these fixes do make things much better.
				// However, they will still not be able to handle entries where
				// the title has _other_ "."'s in it.
				// For example, when the title is:
				//  subdomain.domain.com
				//  mySoftware version 8.5
				//	domain.tv (replace .tv with any domain suffix not included below)

				if((strGroup.GetLength() >= 4) && (j != -1))
					str3 = strGroup.Right(3);
				else
					str3 = _T("   ");
				if((strGroup.GetLength() >= 5) && (j != -1))
					str4 = strGroup.Right(4);
				else
					str4 = _T("    ");
				if((strGroup.GetLength() >= 6) && (j != -1))
					str5 = strGroup.Right(5);
				else
					str5 = _T("     ");
				if((strGroup.GetLength() >= 7) && (j != -1))
					str6 = strGroup.Right(6);
				else
					str6 = _T("      ");

				str3 = str3.MakeLower();
				str4 = str4.MakeLower();
				str5 = str5.MakeLower();
				str6 = str6.MakeLower();

				if((str4 == _T(".com")) || (str4 == _T(".org")) || (str4 == _T(".edu"))
					|| (str4 == _T(".net")) || (str4 == _T(".zip"))
					|| (str3 == _T(".uk")) || (str3 == _T(".de")) || (str3 == _T(".ch"))
					|| (str3 == _T(".at")) || (str3 == _T(".it")))
				{
					// Fix for double-point URLs like .co.uk
					if(str6 == _T(".co.uk")) j -= 3;

					strTitle = strGroup.Right(strGroup.GetLength() - j);
					strGroup = strGroup.Left(j);
					j = strGroup.ReverseFind(_T('.'));
				}

				if(j != -1)
				{
					strTitle = strGroup.Right(strGroup.GetLength() - j - 1) + strTitle;
					strGroup = strGroup.Left(j);
				}
				else
				{
					// No '.' was found, or it is part of a ".com" in the title.
					// Since Password Safe
					// **requires** a title but not a group name, this means
					// that a group name was not specified (a common
					// occurrence). We should assign a logical group name
					// and store the title we just identified. 
					strTitle = strGroup + strTitle;
					strGroup = TRL("Imported from Password Safe");
				}
			}
		}
		else if((pData[i] == '\"') && (bInNotes == FALSE) && (nField == 3))
		{
			bInNotes = TRUE;
		}
		else if((pData[i] == '\"') && (bInNotes == TRUE) && (nField == 3))
		{
			bInNotes = FALSE;

			if(strNotes.GetLength() != 0)
			{
				if(strNotes.GetAt(0) == _T('\"')) strNotes = strNotes.Right(strNotes.GetLength() - 1);
				if(strNotes.Right(1) == _T("\"")) strNotes = strNotes.Left(strNotes.GetLength() - 1);
			}
		}
		else if((pData[i] == '\r') && (bInNotes == FALSE))
		{
			// Ignore all \r
		}
		else if((pData[i] == '\n') && (bInNotes == FALSE))
		{
			dwGroupId = pMgr->GetGroupId((LPCTSTR)strGroup);
			if(dwGroupId == DWORD_MAX)
			{
				PW_GROUP pwT;
				PW_TIME tNow;
				_GetCurrentPwTime(&tNow);
				memset(&pwT, 0, sizeof(PW_GROUP));
				pwT.pszGroupName = (TCHAR *)(LPCTSTR)strGroup;
				pwT.tCreation = tNow; CPwManager::GetNeverExpireTime(&pwT.tExpire);
				pwT.tLastAccess = tNow; pwT.tLastMod = tNow;
				pwT.uGroupId = 0; // 0 = create new group ID
				pwT.uImageId = _GetPreferredIcon((LPCTSTR)strGroup);
				pMgr->AddGroup(&pwT);
				dwGroupId = pMgr->GetGroupId((LPCTSTR)strGroup);
			}
			ASSERT(dwGroupId != DWORD_MAX);

			PW_ENTRY pwTemplate;
			PW_TIME tNow;

			memset(&pwTemplate, 0, sizeof(PW_ENTRY));
			_GetCurrentPwTime(&tNow);
			pwTemplate.pszAdditional = const_cast<LPTSTR>((LPCTSTR)strNotes);
			pwTemplate.pszPassword = const_cast<LPTSTR>((LPCTSTR)strPassword);
			pwTemplate.pszTitle = const_cast<LPTSTR>((LPCTSTR)strTitle);
			pwTemplate.pszURL = g_pNullString;
			pwTemplate.pszUserName = const_cast<LPTSTR>((LPCTSTR)strUserName);
			pwTemplate.tCreation = tNow; CPwManager::GetNeverExpireTime(&pwTemplate.tExpire);
			pwTemplate.tLastAccess = tNow; pwTemplate.tLastMod = tNow;
			pwTemplate.uImageId = _GetPreferredIcon((LPCTSTR)strTitle);
			pwTemplate.uPasswordLen = strPassword.GetLength();
			pwTemplate.uGroupId = dwGroupId;
			// UUID is zero -> create new UUID

			pMgr->AddEntry(&pwTemplate);

			strGroup.Empty(); strTitle.Empty(); strUserName.Empty();
			strPassword.Empty(); strNotes.Empty();
			nField = 0;
		}
		else
		{
			if(nField == 0) strGroup += pData[i];
			else if(nField == 1) strUserName += pData[i];
			else if(nField == 2) strPassword += pData[i];
			else if(nField == 3) strNotes += pData[i];
		}

		i++;
		if(i >= uFileSize) break;
	}

	EraseCString(&strGroup); EraseCString(&strTitle); EraseCString(&strUserName);
	EraseCString(&strPassword); EraseCString(&strNotes);

	SAFE_DELETE_ARRAY(pData);
	return TRUE;
}
示例#22
0
BOOL CPwSafeApp::RegisterShellAssociation()
{
	HKEY hBase, hShell, hTemp, hTemp2;
	// TCHAR tszTemp[MAX_PATH * 2];
	// TCHAR tszMe[MAX_PATH * 2];

	// VERIFY(GetModuleFileName(NULL, tszMe, MAX_PATH * 2 - 2) != 0);
	std_string strMe = Executable::instance().getFullPathName();

	// HKEY_CLASSES_ROOT/.kdb

	LONG l = RegCreateKey(HKEY_CLASSES_ROOT, _T(".kdb"), &hBase);
	if(l != ERROR_SUCCESS) return FALSE;

	std_string strTemp = _T("kdbfile");
	DWORD dw = static_cast<DWORD>((strTemp.length() + 1) * sizeof(TCHAR));
	l = RegSetValueEx(hBase, _T(""), 0, REG_SZ, (CONST BYTE *)strTemp.c_str(), dw);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) { RegCloseKey(hBase); return FALSE; }

	RegCloseKey(hBase);

	// HKEY_CLASSES_ROOT/kdbfile

	l = RegCreateKey(HKEY_CLASSES_ROOT, _T("kdbfile"), &hBase);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) return FALSE;

	// _tcscpy_s(tszTemp, _countof(tszTemp), TRL("KeePass Password Database"));
	strTemp = TRL("KeePass Password Database");

	dw = static_cast<DWORD>((strTemp.length() + 1) * sizeof(TCHAR));
	l = RegSetValueEx(hBase, _T(""), 0, REG_SZ, (CONST BYTE *)strTemp.c_str(), dw);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) { RegCloseKey(hBase); return FALSE; }

	// _tcscpy_s(tszTemp, _countof(tszTemp), _T(""));
	strTemp = _T("");

	dw = static_cast<DWORD>((strTemp.length() + 1) * sizeof(TCHAR));
	l = RegSetValueEx(hBase, _T("AlwaysShowExt"), 0, REG_SZ, (CONST BYTE *)strTemp.c_str(), dw);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) { RegCloseKey(hBase); return FALSE; }

	l = RegCreateKey(hBase, _T("DefaultIcon"), &hTemp);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) return FALSE;

	// _tcscpy_s(tszTemp, _countof(tszTemp), tszMe);
	strTemp = strMe;
	// _tcscat_s(tszTemp, _countof(tszTemp), _T(",0"));
	strTemp += _T(",0");
	dw = static_cast<DWORD>((strTemp.length() + 1) * sizeof(TCHAR));
	l = RegSetValueEx(hTemp, _T(""), 0, REG_SZ, (CONST BYTE *)strTemp.c_str(), dw);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) { RegCloseKey(hTemp); RegCloseKey(hBase); return FALSE; }

	RegCloseKey(hTemp);

	// HKEY_CLASSES_ROOT/kdbfile/shell

	l = RegCreateKey(hBase, _T("shell"), &hShell);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) return FALSE;

	// HKEY_CLASSES_ROOT/kdbfile/shell/open

	l = RegCreateKey(hShell, _T("open"), &hTemp);

	// _tcscpy_s(tszTemp, _countof(tszTemp), TRL("&Open with KeePass"));
	strTemp = TRL("&Open with KeePass");
	dw = static_cast<DWORD>((strTemp.length() + 1) * sizeof(TCHAR));
	l = RegSetValueEx(hTemp, _T(""), 0, REG_SZ, (CONST BYTE *)strTemp.c_str(), dw);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) { RegCloseKey(hTemp); RegCloseKey(hShell); RegCloseKey(hBase); return FALSE; }

	l = RegCreateKey(hTemp, _T("command"), &hTemp2);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) return FALSE;

	// _tcscpy_s(tszTemp, _countof(tszTemp), _T("\""));
	strTemp = _T("\"");
	// _tcscat_s(tszTemp, _countof(tszTemp), tszMe);
	strTemp += strMe;
	// _tcscat_s(tszTemp, _countof(tszTemp), _T("\" \"%1\""));
	strTemp += _T("\" \"%1\"");
	dw = static_cast<DWORD>((strTemp.length() + 1) * sizeof(TCHAR));
	l = RegSetValueEx(hTemp2, _T(""), 0, REG_SZ, (CONST BYTE *)strTemp.c_str(), dw);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) { RegCloseKey(hTemp); RegCloseKey(hShell); RegCloseKey(hBase); return FALSE; }

	VERIFY(RegCloseKey(hTemp2) == ERROR_SUCCESS);
	VERIFY(RegCloseKey(hTemp) == ERROR_SUCCESS);

	VERIFY(RegCloseKey(hShell) == ERROR_SUCCESS);

	VERIFY(RegCloseKey(hBase) == ERROR_SUCCESS);

	return TRUE;
}
示例#23
0
CString CPwUtil::FormatError(int nErrorCode, DWORD dwFlags)
{
	CString str;

	if(nErrorCode != PWE_SUCCESS)
	{
		TCHAR tszTemp[24];
		_stprintf_s(tszTemp, _countof(tszTemp), _T("%08X"),
			static_cast<unsigned int>(nErrorCode));

		if((dwFlags & PWFF_NO_INTRO) == 0)
		{
			str = TRL("An error occurred"); str += _T("!\r\n");
		}

		str += TRL("Error code"); str += _T(": 0x");
		str += tszTemp;
		str += _T(".");

		if((dwFlags & PWFF_NO_INTRO) == 0) str += _T("\r\n\r\n");
		else str += _T("\r\n");
	}

	if(((nErrorCode == PWE_INVALID_KEY) && ((dwFlags & PWFF_INVKEY_WITH_CODE) == 0)) ||
		(nErrorCode == PWE_UNSUPPORTED_KDBX) || ((dwFlags & PWFF_MAIN_TEXT_ONLY) != 0) ||
		(nErrorCode == PWE_GETLASTERROR))
		str.Empty();

	switch(nErrorCode)
	{
	case PWE_UNKNOWN:
		str += TRL("Unknown error");
		break;
	case PWE_SUCCESS:
		str += TRL("Success");
		break;
	case PWE_INVALID_PARAM:
		str += TRL("Invalid parameter");
		break;
	case PWE_NO_MEM:
		str += TRL("Too little memory (RAM) available");
		break;
	case PWE_INVALID_KEY:
		str += TRL("Invalid/wrong key");
		break;
	case PWE_NOFILEACCESS_READ:
		str += TRL("File access error: failed to open file in read mode");
		break;
	case PWE_NOFILEACCESS_WRITE:
		str += TRL("File access error: failed to open file in write mode");
		break;
	case PWE_FILEERROR_READ:
		str += TRL("File error: error while reading from the file");
		break;
	case PWE_FILEERROR_WRITE:
		str += TRL("File error: error while writing to the file");
		break;
	case PWE_INVALID_RANDOMSOURCE:
		str += TRL("Internal error"); str += _T(": ");
		str += TRL("Invalid random source");
		break;
	case PWE_INVALID_FILESTRUCTURE:
		str += TRL("Invalid/corrupted file structure");
		break;
	case PWE_CRYPT_ERROR:
		str += TRL("Encryption/decryption error");
		break;
	case PWE_INVALID_FILESIZE:
		str += TRL("Invalid/corrupted file structure");
		break;
	case PWE_INVALID_FILESIGNATURE:
		str += TRL("Invalid/corrupted file structure");
		break;
	case PWE_INVALID_FILEHEADER:
		str += TRL("Invalid/corrupted file structure");
		break;
	case PWE_NOFILEACCESS_READ_KEY:
		str += TRL("File access error: failed to open file in read mode");
		break;
	case PWE_KEYPROV_INVALID_KEY:
		str += TRL("The key provider plugin did not supply a valid key");
		break;
	case PWE_FILEERROR_VERIFY:
		str += TRL("File error: error while writing to the file"); // Same as write
		break;
	case PWE_UNSUPPORTED_KDBX:
		str += TRL("KeePass 1.x cannot open KDBX files.");
		str += _T("\r\n\r\n");
		str += TRL("Use the KeePass 2.x 'Export' feature to migrate this file");
		break;
	case PWE_GETLASTERROR:
		str += CPwUtil::FormatSystemMessage(GetLastError()).c_str();
		str = str.TrimRight(_T(".!\r\n"));
		break;
	default:
		ASSERT(FALSE);
		str += TRL("Unknown error");
		break;
	}
	str += _T(".");

	if(nErrorCode == PWE_NOFILEACCESS_READ_KEY)
	{
		str += _T("\r\n\r\n");
		str += TRL("Make sure the media that contains the key file is inserted and that KeePass has the rights to access it (check file access rights, ensure that no other application is blocking the file, ...).");
	}

	if((dwFlags & PWFF_DATALOSS_WITHOUT_SAVE) != 0)
	{
		str += _T("\r\n\r\n");
		str += TRL("The target file might be in a corrupted state. Please try saving again, and if that fails, save the database to a different location.");
	}

	return str;
}
示例#24
0
BOOL CPwImport::ImportCWalletToDb(const TCHAR *pszFile, CPwManager *pMgr)
{
	char *pData;
	CString strTitle, strURL, strUserName, strPassword, strNotes;
	DWORD uFileSize, i = DWORD_MAX, b;
	CString str;
	CString strLastCategory = _T("General");
	DWORD dwLastGroupId = 0;
	BOOL bInNotes = FALSE;

	ASSERT(pMgr != NULL);

	pData = CPwImport::FileToMemory(pszFile, &uFileSize);
	if(pData == NULL) return FALSE;

	strTitle.Empty(); strURL.Empty(); strUserName.Empty();
	strPassword.Empty(); strNotes.Empty();

	if((uFileSize > 3) && (static_cast<unsigned char>(pData[0]) == 0xEF) &&
		(static_cast<unsigned char>(pData[1]) == 0xBB) &&
		(static_cast<unsigned char>(pData[2]) == 0xBF))
		i += 3; // Skip UTF-8 initialization characters

	bool bUnicodeMode = false;
	if((uFileSize > 2) && (static_cast<unsigned char>(pData[0]) == 0xFF) &&
		(static_cast<unsigned char>(pData[1]) == 0xFE))
	{
		i += 2; // Skip Unicode initialization characters
		bUnicodeMode = true;
	}

	while(true) // Processing the file
	{
		str.Empty();

		while(true) // Loading one line to CString
		{
			++i;
			if(i >= uFileSize) break;

			const char chReadCx = pData[i];

			if(bUnicodeMode) ++i;

			if(chReadCx == '\n') break;
			if(chReadCx != '\r') str += chReadCx;
		}

		// Add the entry
		if(((str.Left(1) == _T("[")) && (str.Right(1) == _T("]"))) ||
			(str == DEF_CW_CATEGORY) || (str == DEF_CW_CATEGORY_NEW) || (i >= uFileSize))
		{
			CString strTrimmedNotes = strNotes;
			strTrimmedNotes = strTrimmedNotes.Trim();

			if((strTitle.IsEmpty() == FALSE) || (strUserName.IsEmpty() == FALSE) ||
				(strURL.IsEmpty() == FALSE) || (strPassword.IsEmpty() == FALSE) ||
				(strTrimmedNotes.IsEmpty() == FALSE))
			{
				strTitle = strTitle.Trim();
				strURL = strURL.Trim();
				strUserName = strUserName.Trim();
				strPassword = strPassword.Trim();
				strNotes = strNotes.Trim();

				PW_TIME tNow;
				_GetCurrentPwTime(&tNow);

				PW_ENTRY pwTemplate;
				memset(&pwTemplate, 0, sizeof(PW_ENTRY));
				pwTemplate.pszAdditional = const_cast<LPTSTR>((LPCTSTR)strNotes);
				pwTemplate.pszPassword = const_cast<LPTSTR>((LPCTSTR)strPassword);
				pwTemplate.pszTitle = const_cast<LPTSTR>((LPCTSTR)strTitle);
				pwTemplate.pszURL = const_cast<LPTSTR>((LPCTSTR)strURL);
				pwTemplate.pszUserName = const_cast<LPTSTR>((LPCTSTR)strUserName);
				pwTemplate.tCreation = tNow; CPwManager::GetNeverExpireTime(&pwTemplate.tExpire);
				pwTemplate.tLastAccess = tNow; pwTemplate.tLastMod = tNow;
				pwTemplate.uGroupId = dwLastGroupId;
				pwTemplate.uImageId = _GetPreferredIcon(strTitle);
				pwTemplate.uPasswordLen = strPassword.GetLength();

				if(pwTemplate.uGroupId != 0) pMgr->AddEntry(&pwTemplate);
			}

			strTitle.Empty(); strURL.Empty(); strUserName.Empty();
			strPassword.Empty(); strNotes.Empty();
			bInNotes = FALSE;
		}

		if(i >= uFileSize) break;

		if((str.Left(1) == _T("[")) && (str.Right(1) == _T("]")))
		{
			strTitle = str;
			strTitle = strTitle.Left(strTitle.GetLength() - 1);
			strTitle = strTitle.Right(strTitle.GetLength() - 1);
			continue;
		}

		if(bInNotes == TRUE)
		{
			if(strNotes.GetLength() != 0) strNotes += _T("\r\n");

			if((str != DEF_CW_CATEGORY) && (str != DEF_CW_CATEGORY_NEW))
				strNotes += str;
		}

		const std::basic_string<TCHAR> strFxCategory = _T("Category: ");
		const std::basic_string<TCHAR> strFxFolder = _T("Folder: ");
		const bool bStartsCat = (str.Left(static_cast<int>(strFxCategory.size())) ==
			strFxCategory.c_str());
		const bool bStartsFld = (str.Left(static_cast<int>(strFxFolder.size())) ==
			strFxFolder.c_str());

		if(bStartsCat || bStartsFld)
		{
			strLastCategory = str.Right(str.GetLength() - static_cast<int>(bStartsCat ?
				strFxCategory.size() : strFxFolder.size()));
			strLastCategory = strLastCategory.Trim();

			while(true)
			{
				strLastCategory = strLastCategory.Left(strLastCategory.GetLength() - 1);
				if(strLastCategory.GetLength() == 0) break;
				if(strLastCategory.Right(1) == _T("("))
				{
					strLastCategory = strLastCategory.Left(strLastCategory.GetLength() - 2);
					break;
				}
				if(strLastCategory.GetLength() == 0) break;
			}

			if(strLastCategory.GetLength() == 0)
				strLastCategory = TRL("General");
			dwLastGroupId = pMgr->GetGroupId((LPCTSTR)strLastCategory);
			if(dwLastGroupId == DWORD_MAX)
			{
				PW_GROUP pwT;
				PW_TIME tNow;
				_GetCurrentPwTime(&tNow);
				memset(&pwT, 0, sizeof(PW_GROUP));
				pwT.pszGroupName = (TCHAR *)(LPCTSTR)strLastCategory;
				pwT.tCreation = tNow; CPwManager::GetNeverExpireTime(&pwT.tExpire);
				pwT.tLastAccess = tNow; pwT.tLastMod = tNow;
				pwT.uGroupId = 0; // 0 = create new group ID
				pwT.uImageId = _GetPreferredIcon((LPCTSTR)strLastCategory);
				pMgr->AddGroup(&pwT);
				dwLastGroupId = pMgr->GetGroupId((LPCTSTR)strLastCategory);
			}
			ASSERT(dwLastGroupId != DWORD_MAX);
		}

		if((str.Left(6) == _T("Notes:")) && (bInNotes == FALSE))
		{
			bInNotes = TRUE;
			str = str.Right(str.GetLength() - 6);
			if(str.GetLength() != 0) strNotes = str;
			continue;
		}

		b=0;
		if(str.Left(9) == _T("User ID: ")) {strUserName = str.Right(str.GetLength() - 9); b=1;}
		if(str.Left(7) == _T("Login: "******"Access #: ")) {strUserName = str.Right(str.GetLength() - 10); b=1;}
		if(str.Left(8) == _T("System: ")) {strUserName = str.Right(str.GetLength() - 8); b=1;}
		if(str.Left(9) == _T("Content: ")) {strUserName = str.Right(str.GetLength() - 9); b=1;}
		if(strUserName.GetLength() == 0)
		{
			if(str.Left(6) == _T("Date: ")) {strUserName = str.Right(str.GetLength() - 6); b=1;}
			if(str.Left(8) == _T("Issuer: ")) {strUserName = str.Right(str.GetLength() - 8); b=1;}
			if(str.Left(8) == _T("Number: ")) {strUserName = str.Right(str.GetLength() - 8); b=1;}
			if(str.Left(9) == _T("Network: ")) {strUserName = str.Right(str.GetLength() - 9); b=1;}
			if(str.Left(11) == _T("Ftp login: "******"URL: ")) {strURL = str.Right(str.GetLength() - 5); b=1;}
		if(str.Left(10) == _T("Web site: ")) {strURL = str.Right(str.GetLength() - 10); b=1;}
		if(strURL.GetLength() == 0)
		{
			if(str.Left(19) == _T("Registered e-mail: ")) {strURL = str.Right(str.GetLength() - 19); b=1;}
		}

		if(str.Left(10) == _T("Password: "******"PIN: ")) {strPassword = str.Right(str.GetLength() - 5); b=1;}
		}

		if((b == 0) && (bInNotes == FALSE))
		{
			if(strNotes.GetLength() != 0) strNotes += _T("\r\n");

			if((str != DEF_CW_CATEGORY) && (str != DEF_CW_CATEGORY_NEW))
				strNotes += str;
		}
	}

	SAFE_DELETE_ARRAY(pData);
	return TRUE;
}
示例#25
0
BOOL CPwImport::ImportPVaultToDb(const TCHAR *pszFile, CPwManager *pMgr)
{
	char *pData;
	CString strTitle, strURL, strUserName, strPassword, strNotes;
	DWORD uFileSize, i, b;
	CString str;
	CString strLastCategory = _T("General");
	DWORD dwLastGroupId = 0;
	BOOL bInNotes = FALSE;

	ASSERT(pMgr != NULL);

	pData = CPwImport::FileToMemory(pszFile, &uFileSize);
	if(pData == NULL) return FALSE;

	strTitle.Empty(); strURL.Empty(); strUserName.Empty();
	strPassword.Empty(); strNotes.Empty();

	i = DWORD_MAX;

	if(uFileSize > 3)
		if((static_cast<unsigned char>(pData[0]) == 0xEF) &&
			(static_cast<unsigned char>(pData[1]) == 0xBB) &&
			(static_cast<unsigned char>(pData[2]) == 0xBF))
			i += 3; // Skip UTF-8 initialization characters

	while(true) // Processing the file
	{
		str.Empty();

		while(true) // Loading one line to CString
		{
			++i;
			if(i >= uFileSize) break;

			if(pData[i] == '\n') break;
			if(pData[i] != '\r') str += pData[i];
		}

		// Add the entry
		if((str == DEF_PV_SEPENTRY) || (i >= uFileSize) || (str.Left(12) == DEF_PV_CATEGORY))
		{
			if((strTitle.IsEmpty() == FALSE) || (strUserName.IsEmpty() == FALSE) ||
				(strURL.IsEmpty() == FALSE) || (strPassword.IsEmpty() == FALSE))
			{
				strTitle = strTitle.Trim();
				strURL = strURL.Trim();
				strUserName = strUserName.Trim();
				strPassword = strPassword.Trim();
				strNotes = strNotes.Trim();

				PW_ENTRY pwTemplate;
				PW_TIME tNow;

				_GetCurrentPwTime(&tNow);
				memset(&pwTemplate, 0, sizeof(PW_ENTRY));
				pwTemplate.pszAdditional = const_cast<LPTSTR>((LPCTSTR)strNotes);
				pwTemplate.pszPassword = const_cast<LPTSTR>((LPCTSTR)strPassword);
				pwTemplate.pszTitle = const_cast<LPTSTR>((LPCTSTR)strTitle);
				pwTemplate.pszURL = const_cast<LPTSTR>((LPCTSTR)strURL);
				pwTemplate.pszUserName = const_cast<LPTSTR>((LPCTSTR)strUserName);
				pwTemplate.tCreation = tNow; CPwManager::GetNeverExpireTime(&pwTemplate.tExpire);
				pwTemplate.tLastAccess = tNow; pwTemplate.tLastMod = tNow;
				pwTemplate.uGroupId = dwLastGroupId;
				pwTemplate.uImageId = _GetPreferredIcon(strTitle);
				pwTemplate.uPasswordLen = strPassword.GetLength();

				pMgr->AddEntry(&pwTemplate);
			}

			strTitle.Empty(); strURL.Empty(); strUserName.Empty();
			strPassword.Empty(); strNotes.Empty();
			bInNotes = FALSE;
		}

		if(i >= uFileSize) break;

		if(bInNotes == TRUE)
		{
			if(strNotes.GetLength() != 0) strNotes += _T("\r\n");
			strNotes += str.Right(str.GetLength() - 14);
		}

		if((str.Left(12) == DEF_PV_CATEGORY) && (str.Right(12) == DEF_PV_CATEGORY))
		{
			strLastCategory = str.Right(str.GetLength() - 12);
			strLastCategory = strLastCategory.Left(strLastCategory.GetLength() - 12);
			strLastCategory = strLastCategory.Trim();

			if(strLastCategory.GetLength() == 0)
				strLastCategory = TRL("General");
			dwLastGroupId = pMgr->GetGroupId((LPCTSTR)strLastCategory);
			if(dwLastGroupId == DWORD_MAX)
			{
				PW_GROUP pwT;
				PW_TIME tNow;
				_GetCurrentPwTime(&tNow);
				memset(&pwT, 0, sizeof(PW_GROUP));
				pwT.pszGroupName = (TCHAR *)(LPCTSTR)strLastCategory;
				pwT.tCreation = tNow; CPwManager::GetNeverExpireTime(&pwT.tExpire);
				pwT.tLastAccess = tNow; pwT.tLastMod = tNow;
				pwT.uGroupId = 0; // 0 = create new group ID
				pwT.uImageId = _GetPreferredIcon((LPCTSTR)strLastCategory);
				pMgr->AddGroup(&pwT);
				dwLastGroupId = pMgr->GetGroupId((LPCTSTR)strLastCategory);
			}
			ASSERT(dwLastGroupId != DWORD_MAX);
		}

		if((str.Left(9) == _T("Comments:")) && (bInNotes == FALSE))
		{
			bInNotes = TRUE;
			str = str.Right(str.GetLength() - 9);
			if(str.GetLength() != 0) strNotes = str;
			continue;
		}

		if(str.Left(9) == _T("Account: ")) {strTitle = str.Right(str.GetLength() - 9); b=1;}

		b=0;
		if(str.Left(11) == _T("User Name: ")) {strUserName = str.Right(str.GetLength() - 11); b=1;}

		if(str.Left(11) == _T("Hyperlink: ")) {strURL = str.Right(str.GetLength() - 11); b=1;}

		if(str.Left(10) == _T("Password: "******"\r\n");
			strNotes += str;
		}
	}

	SAFE_DELETE_ARRAY(pData);

	return TRUE;
}
示例#26
0
BOOL CLanguagesDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	NewGUI_TranslateCWnd(this);
	EnumChildWindows(this->m_hWnd, NewGUI_TranslateWindowCb, 0);
	
	NewGUI_XPButton(m_btClose, IDB_CANCEL, IDB_CANCEL);
	NewGUI_XPButton(m_btGetLang, IDB_LANGUAGE, IDB_LANGUAGE);
	NewGUI_XPButton(m_btOpenFolder, IDB_TB_OPEN, IDB_TB_OPEN);

	NewGUI_ConfigSideBanner(&m_banner, this);
	m_banner.SetIcon(AfxGetApp()->LoadIcon(IDI_WORLD),
		KCSB_ICON_LEFT | KCSB_ICON_VCENTER);
	m_banner.SetTitle(TRL("Select Language"));
	m_banner.SetCaption(TRL("Here you can change the user interface language."));

	RECT rcList;
	m_listLang.GetClientRect(&rcList);
	const int wList = rcList.right - rcList.left - GetSystemMetrics(SM_CXVSCROLL);
	const int w2 = (wList * 2) / 20;
	const int w3 = (wList * 3) / 20;
	const int w5 = (wList * 5) / 20;
	m_listLang.InsertColumn(0, TRL("Installed Languages"), LVCFMT_LEFT, w5, 0);
	m_listLang.InsertColumn(1, TRL("Version"), LVCFMT_LEFT, w2, 1);
	m_listLang.InsertColumn(2, TRL("Author"), LVCFMT_LEFT, w5, 2);
	m_listLang.InsertColumn(3, TRL("Contact"), LVCFMT_LEFT, w5, 3);
	m_listLang.InsertColumn(4, TRL("File"), LVCFMT_LEFT, w3, 4);

	// m_ilIcons.Create(CPwSafeApp::GetClientIconsResourceID(), 16, 1, RGB(255,0,255));
	CPwSafeApp::CreateHiColorImageList(&m_ilIcons, IDB_CLIENTICONS_EX, 16);
	m_listLang.SetImageList(&m_ilIcons, LVSIL_SMALL);

	m_listLang.PostMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_SI_REPORT |
		LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE |
		LVS_EX_UNDERLINEHOT | LVS_EX_INFOTIP);

	m_listLang.DeleteAllItems();

	LV_ITEM lvi;
	ZeroMemory(&lvi, sizeof(LV_ITEM));
	lvi.iItem = m_listLang.InsertItem(LVIF_TEXT | LVIF_IMAGE, m_listLang.GetItemCount(),
		_T("English"), 0, 0, 1, NULL);

	CString strTemp;
	
	strTemp = PWM_VERSION_STR;
	lvi.iSubItem = 1; lvi.mask = LVIF_TEXT;
	lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
	m_listLang.SetItem(&lvi);

	strTemp = PWMX_ENGLISH_AUTHOR;
	lvi.iSubItem = 2; lvi.mask = LVIF_TEXT;
	lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
	m_listLang.SetItem(&lvi);

	strTemp = PWMX_ENGLISH_CONTACT;
	lvi.iSubItem = 3; lvi.mask = LVIF_TEXT;
	lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
	m_listLang.SetItem(&lvi);

	strTemp = TRL("Built-in");
	lvi.iSubItem = 4; lvi.mask = LVIF_TEXT;
	lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
	m_listLang.SetItem(&lvi);

	const std_string strActive = GetCurrentTranslationTable();

	std_string strFilter = SU_DriveLetterToUpper(Executable::instance().getPathOnly());
	strFilter += PWM_DIR_LANGUAGES;
	strFilter += _T("\\*.lng");

	CFileFind ff;
	BOOL bMore = ff.FindFile(strFilter.c_str(), 0);
	while(bMore != FALSE)
	{
		bMore = ff.FindNextFile();

		// Ignore KeePass 2.x LNGX files (these are found even though
		// "*.lng" is specified as file mask)
		CString strFileName = ff.GetFileName();
		strFileName = strFileName.MakeLower();
		if((strFileName.GetLength() >= 5) && (strFileName.Right(5) == _T(".lngx")))
			continue;

		CString strID = ff.GetFileTitle();
		strID = strID.MakeLower();
		if((strID != _T("standard")) && (strID != _T("english")))
		{
			VERIFY(LoadTranslationTable((LPCTSTR)ff.GetFileTitle()));

			strTemp = (LPCTSTR)ff.GetFileTitle();
			// strTemp += _T(" - "); // Name is used as identifier
			// strTemp += TRL("~LANGUAGENAME");

			lvi.iItem = m_listLang.InsertItem(LVIF_TEXT | LVIF_IMAGE,
				m_listLang.GetItemCount(), strTemp, 0, 0, 1, NULL);

			strTemp = TRL("~LANGUAGEVERSION");
			if(strTemp == _T("~LANGUAGEVERSION")) strTemp.Empty();
			lvi.iSubItem = 1; lvi.mask = LVIF_TEXT;
			lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
			m_listLang.SetItem(&lvi);

			strTemp = TRL("~LANGUAGEAUTHOR");
			if(strTemp == _T("~LANGUAGEAUTHOR")) strTemp.Empty();
			lvi.iSubItem = 2; lvi.mask = LVIF_TEXT;
			lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
			m_listLang.SetItem(&lvi);

			strTemp = TRL("~LANGUAGEAUTHOREMAIL");
			if(strTemp == _T("~LANGUAGEAUTHOREMAIL")) strTemp.Empty();
			lvi.iSubItem = 3; lvi.mask = LVIF_TEXT;
			lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
			m_listLang.SetItem(&lvi);

			strTemp = ff.GetFilePath();
			lvi.iSubItem = 4; lvi.mask = LVIF_TEXT;
			lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
			m_listLang.SetItem(&lvi);
		}
	}

	ff.Close();

	VERIFY(LoadTranslationTable(strActive.c_str()));
	return TRUE;
}
示例#27
0
HRESULT CUpdateCheckEx::DownloadInfoFile(BYTE** ppbData, std_string& strError)
{
	if(ppbData == NULL) { ASSERT(FALSE); return E_POINTER; }
	*ppbData = NULL;

	/* TCHAR tszFile[MAX_PATH + 34];
	ZeroMemory(tszFile, sizeof(TCHAR) * (MAX_PATH + 34));

	URLDownloadToCacheFile(NULL, PWM_URL_VERSION, tszFile, URLOSTRM_GETNEWESTVERSION,
		0, NULL);

	if(_tcslen(tszFile) != 0)
	{
		FILE* fp = NULL;
		_tfopen_s(&fp, tszFile, _T("rb"));

		if(fp != NULL)
		{
			fseek(fp, 0, SEEK_END);
			const DWORD uFileSize = static_cast<DWORD>(ftell(fp));
			fseek(fp, 0, SEEK_SET);

			if(uFileSize != 0)
			{
				BYTE* pDataBuf = new BYTE[uFileSize + 2];

				fread(pDataBuf, 1, uFileSize, fp);
				fclose(fp);

				pDataBuf[uFileSize] = 0;
				pDataBuf[uFileSize + 1] = 0;

				*ppbData = pDataBuf;
			}
			else
			{
				strError = TRL("Cache error (cannot open cached file).");
				return E_ACCESSDENIED;
			}
		}
		else
		{
			strError = TRL("Cache error (cannot open cached file).");
			return E_ACCESSDENIED;
		}
	}
	else
	{
		strError = TRL("Connect failed, cannot check for updates.");
		return E_ACCESSDENIED;
	} */

	CKpInternetStream s(PWM_URL_VERSION, false);
	s.SetConnectOptions(5000, 1);
	s.SetTransferOptions(5000);

	std::vector<BYTE> vData;
	HRESULT r = s.ReadToEnd(vData);
	s.Close();
	if(FAILED(r) || (vData.size() == 0))
	{
		strError = TRL("Connect failed, cannot check for updates.");
		return r;
	}

	*ppbData = new BYTE[vData.size() + 2];
	(*ppbData)[vData.size()] = 0;
	(*ppbData)[vData.size() + 1] = 0;
	memcpy(*ppbData, &vData[0], vData.size());

	strError.clear();
	return S_OK;
}
示例#28
0
BOOL CLanguagesDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	NewGUI_TranslateCWnd(this);
	EnumChildWindows(this->m_hWnd, NewGUI_TranslateWindowCb, 0);
	
	NewGUI_XPButton(m_btClose, IDB_CANCEL, IDB_CANCEL);
	NewGUI_XPButton(m_btGetLang, IDB_LANGUAGE, IDB_LANGUAGE);

	NewGUI_ConfigSideBanner(&m_banner, this);
	m_banner.SetIcon(AfxGetApp()->LoadIcon(IDI_WORLD),
		KCSB_ICON_LEFT | KCSB_ICON_VCENTER);
	m_banner.SetTitle(TRL("Load a Language File"));
	m_banner.SetCaption(TRL("Select one of the languages in the list below."));

	RECT rcList;
	m_listLang.GetWindowRect(&rcList);
	const int nColSize = (rcList.right - rcList.left - GetSystemMetrics(SM_CXVSCROLL) - 8) / 4;
	m_listLang.InsertColumn(0, TRL("Available Languages"), LVCFMT_LEFT, nColSize, 0);
	m_listLang.InsertColumn(1, TRL("Language File Version"), LVCFMT_LEFT, nColSize, 1);
	m_listLang.InsertColumn(2, TRL("Author"), LVCFMT_LEFT, nColSize, 2);
	m_listLang.InsertColumn(3, TRL("Translation Author Contact"), LVCFMT_LEFT, nColSize, 3);

	// m_ilIcons.Create(CPwSafeApp::GetClientIconsResourceID(), 16, 1, RGB(255,0,255));
	CPwSafeApp::CreateHiColorImageList(&m_ilIcons, IDB_CLIENTICONS_EX, 16);
	m_listLang.SetImageList(&m_ilIcons, LVSIL_SMALL);

	m_listLang.PostMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_SI_REPORT |
		LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE |
		LVS_EX_UNDERLINEHOT | LVS_EX_INFOTIP);

	m_listLang.DeleteAllItems();

	LV_ITEM lvi;
	ZeroMemory(&lvi, sizeof(LV_ITEM));
	lvi.iItem = m_listLang.InsertItem(LVIF_TEXT | LVIF_IMAGE, m_listLang.GetItemCount(),
		_T("English"), 0, 0, 1, NULL);

	CString strTemp;
	
	strTemp = PWM_VERSION_STR;
	lvi.iSubItem = 1; lvi.mask = LVIF_TEXT;
	lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
	m_listLang.SetItem(&lvi);

	strTemp = PWMX_ENGLISH_AUTHOR;
	lvi.iSubItem = 2; lvi.mask = LVIF_TEXT;
	lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
	m_listLang.SetItem(&lvi);

	strTemp = PWMX_ENGLISH_CONTACT;
	lvi.iSubItem = 3; lvi.mask = LVIF_TEXT;
	lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
	m_listLang.SetItem(&lvi);

	CFileFind ff;
	CString csTmp;
	BOOL chk_w = FALSE;
	TCHAR szCurrentlyLoaded[MAX_PATH * 2];

	_tcscpy_s(szCurrentlyLoaded, _countof(szCurrentlyLoaded), GetCurrentTranslationTable());

	std_string strFilter = Executable::instance().getPathOnly();
	strFilter += _T("*.lng");

	chk_w = ff.FindFile(strFilter.c_str(), 0);
	while(chk_w == TRUE)
	{
		chk_w = ff.FindNextFile();

		csTmp = ff.GetFileTitle();
		csTmp = csTmp.MakeLower();
		if((csTmp != _T("standard")) && (csTmp != _T("english")))
		{
			VERIFY(LoadTranslationTable((LPCTSTR)ff.GetFileTitle()));

			strTemp = (LPCTSTR)ff.GetFileTitle();
			// strTemp += _T(" - ");
			// strTemp += TRL("~LANGUAGENAME");

			lvi.iItem = m_listLang.InsertItem(LVIF_TEXT | LVIF_IMAGE,
				m_listLang.GetItemCount(), strTemp, 0, 0, 1, NULL);

			strTemp = TRL("~LANGUAGEVERSION");
			if(strTemp == _T("~LANGUAGEVERSION")) strTemp.Empty();
			lvi.iSubItem = 1; lvi.mask = LVIF_TEXT;
			lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
			m_listLang.SetItem(&lvi);

			strTemp = TRL("~LANGUAGEAUTHOR");
			if(strTemp == _T("~LANGUAGEAUTHOR")) strTemp.Empty();
			lvi.iSubItem = 2; lvi.mask = LVIF_TEXT;
			lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
			m_listLang.SetItem(&lvi);

			strTemp = TRL("~LANGUAGEAUTHOREMAIL");
			if(strTemp == _T("~LANGUAGEAUTHOREMAIL")) strTemp.Empty();
			lvi.iSubItem = 3; lvi.mask = LVIF_TEXT;
			lvi.pszText = (LPTSTR)(LPCTSTR)strTemp;
			m_listLang.SetItem(&lvi);
		}
	}

	ff.Close();

	VERIFY(LoadTranslationTable(szCurrentlyLoaded));
	return TRUE;
}
示例#29
-1
BOOL CFindInDbDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	NewGUI_TranslateCWnd(this);
	EnumChildWindows(this->m_hWnd, NewGUI_TranslateWindowCb, 0);

	NewGUI_XPButton(m_btOK, IDB_OK, IDB_OK);
	NewGUI_XPButton(m_btCancel, IDB_CANCEL, IDB_CANCEL);

	NewGUI_ConfigSideBanner(&m_banner, this);
	m_banner.SetIcon(AfxGetApp()->LoadIcon(IDI_SEARCH),
		KCSB_ICON_LEFT | KCSB_ICON_VCENTER);
	m_banner.SetTitle(TRL("Find"));
	m_banner.SetCaption(TRL("Find a string in the entry list."));

	if(m_lpGroupName != NULL)
	{
		CString str;

		str = TRL("Find"); str += _T(" - "); str += TRL("Group:");
		str += _T(" "); str += m_lpGroupName;
		m_banner.SetTitle(str);

		GetDlgItem(IDC_CHECK_GROUPNAME)->EnableWindow(FALSE);
		GetDlgItem(IDC_CHECK_EXCLUDEBACKUPS)->EnableWindow(FALSE);
	}

	GetDlgItem(IDC_EDIT_FINDTEXT)->SetFocus();
	return FALSE; // Return TRUE unless you set the focus to a control
}