Beispiel #1
0
HRESULT CUpdateCheckEx::ParseInfoFile(BYTE* pbData, UC_COMPONENTS_LIST& vList)
{
	if(pbData == NULL) { ASSERT(FALSE); return E_POINTER; }

	vList.clear();

	TCHAR* lpData = _UTF8ToString(pbData);
	if(lpData == NULL) { ASSERT(FALSE); return E_FAIL; }
	std_string strData = lpData;
	SAFE_DELETE_ARRAY(lpData);

	std::vector<std_string> vItems;
	SU_Split(vItems, strData, _T("\r\n"));

	for(size_t i = 0; i < vItems.size(); ++i)
		CUpdateCheckEx::AddComponent(vItems[i], vList);

	return S_OK;
}
BOOL LoadTranslationTable(LPCTSTR pszTableName)
{
	FreeCurrentTranslationTable();

	if(pszTableName == NULL) { ASSERT(FALSE); return TRUE; }
	if(pszTableName[0] == 0) return TRUE;

	if((_tcsicmp(pszTableName, _T("Standard")) == 0) ||
		(_tcsicmp(pszTableName, _T("English")) == 0))
	{
		m_strTableName = pszTableName;
		return TRUE;
	}

	TCHAR szPath[MAX_PATH * 3];
	ZeroMemory(&szPath[0], MAX_PATH * 3 * sizeof(TCHAR));
	GetModuleFileName(NULL, &szPath[0], MAX_PATH * 3 - 2);

	int iPathPos = static_cast<int>(_tcslen(szPath)) - 1;
	while(iPathPos >= 0)
	{
		if((szPath[iPathPos] == _T('\\')) || (szPath[iPathPos] == _T('/')))
		{
			szPath[iPathPos + 1] = _T('\0');
			break;
		}
		--iPathPos;
	}
	_tcscat_s(szPath, PWM_DIR_LANGUAGES);
	_tcscat_s(szPath, _T("\\"));
	_tcscat_s(szPath, pszTableName);
	_tcscat_s(szPath, _T(".lng"));

	FILE *fp = NULL;
	_tfopen_s(&fp, szPath, _T("rb"));
	if(fp == NULL) return FALSE;

	fseek(fp, 0, SEEK_END);
	const long lFileLength = ftell(fp);
	fseek(fp, 0, SEEK_SET);

	UTF8_BYTE *pTranslation8 = new UTF8_BYTE[lFileLength + 1];
	if(pTranslation8 == NULL) { fclose(fp); fp = NULL; return FALSE; }
	pTranslation8[lFileLength] = 0;

	fread(pTranslation8, 1, static_cast<size_t>(lFileLength), fp);
	fclose(fp); fp = NULL;

	m_lpTranslationData = _UTF8ToString(pTranslation8);
	SAFE_DELETE_ARRAY(pTranslation8);
	if(m_lpTranslationData == NULL) { ASSERT(FALSE); return FALSE; }
	
	const size_t dwLength = _tcslen(m_lpTranslationData);
	BOOL bMode = TRL_MODE_DEF;
	BOOL bScanning = FALSE;

	size_t i = 0;
	if(dwLength > 3)
	{
		if((m_lpTranslationData[0] == 0xEF) && (m_lpTranslationData[1] == 0xBB) &&
			(m_lpTranslationData[2] == 0xBF))
		{
			i += 3; // Skip UTF-8 initialization characters
		}
	}

	for( ; i < dwLength; ++i)
	{
		if(m_lpTranslationData[i] == _T('|'))
		{
			m_lpTranslationData[i] = 0;

			if((bMode == TRL_MODE_DEF) && (bScanning == FALSE))
			{
				m_vDefStrings.push_back(&m_lpTranslationData[i + 1]);
				bScanning = TRUE;
			}
			else if((bMode == TRL_MODE_DEF) && (bScanning == TRUE))
			{
				bMode = TRL_MODE_TRL;
				bScanning = FALSE;
			}
			else if((bMode == TRL_MODE_TRL) && (bScanning == FALSE))
			{
				m_vTrlStrings.push_back(&m_lpTranslationData[i + 1]);
				bScanning = TRUE;
			}
			else // if((bMode == TRL_MODE_TRL) && (bScanning == TRUE))
			{
				bMode = TRL_MODE_DEF;
				bScanning = FALSE;
			}
		}
	}

	ASSERT(bMode == TRL_MODE_DEF);
	ASSERT(bScanning == FALSE);

	ASSERT(m_vDefStrings.size() == m_vTrlStrings.size());
	if(m_vDefStrings.size() != m_vTrlStrings.size())
	{
		FreeCurrentTranslationTable();
		return FALSE;
	}

	for(size_t uZeroScan = 0; uZeroScan < m_vDefStrings.size(); ++uZeroScan)
	{
		if(m_vTrlStrings[uZeroScan][0] == 0)
			m_vTrlStrings[uZeroScan] = m_vDefStrings[uZeroScan];
	}

	_SortTrlTable();

#ifdef _DEBUG
	for(int iDupScan = 0; iDupScan < static_cast<int>(m_vDefStrings.size()) - 1; ++iDupScan)
	{
		LPCTSTR lpTestL = m_vDefStrings[iDupScan];
		LPCTSTR lpTestR = m_vDefStrings[iDupScan + 1];
		ASSERT(_tcscmp(lpTestL, lpTestR) != 0); // Test for duplicate definitions
	}
#endif

	m_strTableName = pszTableName;
	return TRUE;
}
STDMETHODIMP_(LPTSTR) CKpUtilitiesImpl::UTF8ToString(const UTF8_BYTE* pUTF8String)
{
	return _UTF8ToString(pUTF8String);
}
Beispiel #4
0
void CPwImport::_AddStringStreamToDb(const char *pStream, unsigned long uStreamSize, BOOL bUTF8)
{
	DWORD s;
	char *pTitle = NULL, *pUserName = NULL, *pPassword = NULL, *pURL = NULL, *pNotes = NULL;
	char *p = (char *)pStream;
	char *pEnd = (char *)pStream + uStreamSize;
	TCHAR *tszTitle = NULL, *tszUserName = NULL, *tszPassword = NULL, *tszURL = NULL, *tszNotes = NULL;

	ASSERT(pStream != NULL);

	while(true)
	{
		if(p >= pEnd) break;
		pTitle = p;
		s = szlen(p);
		p += s + 1;

		if(p >= pEnd) break;
		pUserName = p;
		s = szlen(p);
		p += s + 1;

		if(p >= pEnd) break;
		pPassword = p;
		s = szlen(p);
		p += s + 1;

		if(p >= pEnd) break;
		pURL = p;
		s = szlen(p);
		p += s + 1;

		if(p >= pEnd) break;
		pNotes = p;
		s = szlen(p);
		p += s + 1;

		if((strcmp(pTitle, "Account") != 0) && (strcmp(pPassword, "Password") != 0))
		{
			PW_ENTRY pwTemplate;
			PW_TIME tNow;

			if(bUTF8 == TRUE)
			{
				tszTitle = _UTF8ToString((UTF8_BYTE *)pTitle);
				tszUserName = _UTF8ToString((UTF8_BYTE *)pUserName);
				tszPassword = _UTF8ToString((UTF8_BYTE *)pPassword);
				tszURL = _UTF8ToString((UTF8_BYTE *)pURL);
				tszNotes = _UTF8ToString((UTF8_BYTE *)pNotes);
			}
			else
			{
				tszTitle = (TCHAR *)pTitle;
				tszUserName = (TCHAR *)pUserName;
				tszPassword = (TCHAR *)pPassword;
				tszURL = (TCHAR *)pURL;
				tszNotes = (TCHAR *)pNotes;
			}

			memset(&pwTemplate, 0, sizeof(PW_ENTRY));
			_GetCurrentPwTime(&tNow);
			pwTemplate.pszAdditional = tszNotes;
			pwTemplate.pszPassword = tszPassword;
			pwTemplate.pszTitle = tszTitle;
			pwTemplate.pszURL = tszURL;
			pwTemplate.pszUserName = tszUserName;
			pwTemplate.tCreation = tNow; CPwManager::GetNeverExpireTime(&pwTemplate.tExpire);
			pwTemplate.tLastAccess = tNow; pwTemplate.tLastMod = tNow;
			pwTemplate.uGroupId = m_dwLastGroupId;
			pwTemplate.uImageId = _GetPreferredIcon(tszTitle);
			pwTemplate.uPasswordLen = static_cast<DWORD>(_tcslen(tszPassword));
			// UUID is zero -> create new UUID

			m_pLastMgr->AddEntry(&pwTemplate);

			if(bUTF8 == TRUE)
			{
				SAFE_DELETE_ARRAY(tszTitle);
				SAFE_DELETE_ARRAY(tszUserName);
				SAFE_DELETE_ARRAY(tszPassword);
				SAFE_DELETE_ARRAY(tszURL);
				SAFE_DELETE_ARRAY(tszNotes);
			}
		}
	}
}