Exemplo n.º 1
0
void ScrobWrapper::ScrobCallback(int reqId, bool error, std::string msg)
{
	if (error)
		TRACE(_T("@1 ScrobCallback Error reqId: %d msg: %s\n"), reqId, (LPCTSTR)CA2CT(msg.c_str()));
	else
		TRACE(_T("@4 ScrobCallback Msg reqId: %d msg: %s\n"), reqId, (LPCTSTR)CA2CT(msg.c_str()));

}
Exemplo n.º 2
0
/**
 * @param rStackEntry - stack entry information.
 */
void CExpressModeDlg::UpdateStackEntryFromMap(CStackEntry& rStackEntry)
{
	if (! rStackEntry.m_strAddress.IsEmpty() &&
		(
			rStackEntry.m_strFunctionName.IsEmpty() ||
			rStackEntry.m_strSourceFile.IsEmpty() ||
			rStackEntry.m_strLineNumber.IsEmpty()
		))
	{
		int nAddrPos = rStackEntry.m_strAddress.Find(_T(':'));
		if (nAddrPos >= 0)
			++nAddrPos;
		else
			nAddrPos = 0;
		PVOID ptrAddress = (PVOID)_tcstoui64((PCTSTR)rStackEntry.m_strAddress + nAddrPos, NULL, 16);
		if (ptrAddress != NULL)
		{
			boost::shared_ptr<CBaseProcessor> pBaseProcessor(GetModuleInfo(rStackEntry.m_strModule));
			if (pBaseProcessor.get() != NULL)
			{
				boost::shared_ptr<CBaseFnInfo> pFnInfo;
				DWORD64 dwDisplacement64;
				if (pBaseProcessor->FindFunctionInfo(ptrAddress, pFnInfo, dwDisplacement64))
				{
					std::string strFunctionName(pFnInfo->GetName());
					boost::match_results<std::string::const_iterator> what;
					if (boost::regex_search(strFunctionName, what, m_rxFunctionName))
						rStackEntry.m_strFunctionName = CA2CT(what[1].str().c_str());
					else
						rStackEntry.m_strFunctionName = CA2CT(strFunctionName.c_str());
					if (dwDisplacement64 != 0)
						rStackEntry.m_strFunctionOffset.Format(_T("%I64u"), dwDisplacement64);
					else
						rStackEntry.m_strFunctionOffset.Empty();
				}
				boost::shared_ptr<CBaseFileInfo> pFileInfo;
				boost::shared_ptr<CBaseLineInfo> pLineInfo;
				DWORD dwDisplacement32;
				if (pBaseProcessor->FindLineInfo(ptrAddress, pFileInfo, pLineInfo, dwDisplacement32))
				{
					rStackEntry.m_strSourceFile = CA2CT(pFileInfo->GetFileName().c_str());
					rStackEntry.m_strLineNumber.Format(_T("%u"), pLineInfo->GetNumber());
					if (dwDisplacement32 != 0)
						rStackEntry.m_strLineOffset.Format(_T("%I32u"), dwDisplacement32);
					else
						rStackEntry.m_strLineOffset.Empty();
				}
			}
		}
	}
}
Exemplo n.º 3
0
CString CSimpleFile::ReadStringNull()
{
	CStringA str;
	while (char ch = ReadChar())
		str += ch;
	return CString(CA2CT(str));
}
Exemplo n.º 4
0
COutFile::COutFile (const char *lpFileName)
{
	USES_CONVERSION;
	m_nRefCount = 1;
	m_hFile = INVALID_HANDLE_VALUE;
	m_lpFileName = CA2CT(lpFileName);
}
Exemplo n.º 5
0
bool UpkUse7z(LPCTSTR szExeFile, LPCTSTR szExtractPath, Files &files)
{
#if 0 
	static CExeUnpack7z *upk=NULL;
	if(!upk)
	{
		upk = new CExeUnpack7z;
		upk->Initialize(szPath7z, szPathWcx);
	}
	
	strings fs;
	CStringA s1 = CT2CA(szExeFile);
	CStringA s2 = CT2CA(szExtractPath);
	bool bRet = upk->Extract(s1, s2, fs);
	if(bRet)
	{
		for(size_t i=0; i<fs.size(); ++i)
		{
			files.push_back( CString(CA2CT(fs[i].c_str())) );
		}
	}
	return bRet;
#endif
	return false;
}
Exemplo n.º 6
0
CString CSimpleFile::ReadString()
{
	const int Size = ReadInt();
	LPSTR Buf = new char[Size + 1];
	Buf[Size] = '\0';
	return CString(CA2CT(Buf));
}
Exemplo n.º 7
0
BOOL file_get_contents(LPCTSTR lpszFilename, CString &strBuffer)
{
	CStringA strA;
	BOOL bRet = file_get_contents(lpszFilename, strA);

	USES_CONVERSION;
	strBuffer = CA2CT( strA );		
	return bRet;
}
Exemplo n.º 8
0
BOOL DownloadWebPagePostA(std::string& page, HINTERNET hInternet, LPCSTR url, LPCSTR postData)
{
	TRACEST(_T("DownloadWebPagePostA"), CA2CT(url));
	BOOL bRet = FALSE;
	URL_COMPONENTSA comp;
	memset(&comp, 0, sizeof(URL_COMPONENTSA));
	comp.dwStructSize = sizeof(URL_COMPONENTSA);
	CHAR hostName[100], URI[100];
	comp.dwHostNameLength = comp.dwUrlPathLength = 100;
	comp.lpszHostName = hostName;
	comp.lpszUrlPath = URI;
	if (InternetCrackUrlA(url, 0, ICU_ESCAPE, &comp))
	{
		HINTERNET hConnection = InternetConnectA(hInternet, 
			comp.lpszHostName, 
			comp.nPort, 
			NULL, 
			NULL, 
			INTERNET_SERVICE_HTTP, 
			INTERNET_FLAG_KEEP_CONNECTION, 
			0);
		if (hConnection)
		{
			LPCSTR sAcceptTypes[] = {"*/*",NULL};
			HINTERNET hRequest=::HttpOpenRequestA(hConnection,
				"POST", // HTTP Verb
				comp.lpszUrlPath, // Object Name
				HTTP_VERSIONA, // Version
				NULL, // Reference
				sAcceptTypes, // Accept Type
				INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_FORMS_SUBMIT,
				0); // context call-back point
			if(hRequest)
			{
				static LPCSTR sHttpAccept = "Accept: */*\r\n";
				::HttpAddRequestHeadersA(hRequest, sHttpAccept, (DWORD)strlen(sHttpAccept), HTTP_ADDREQ_FLAG_ADD_IF_NEW);

				static LPCSTR szContentType = "Content-Type: application/x-www-form-urlencoded\r\n";
				if(::HttpSendRequestA(hRequest,	szContentType, (DWORD)strlen(szContentType), (LPVOID)postData, (DWORD)strlen(postData)))
					bRet = ReadInternetFile2StringA(hRequest, page);
				else
					HandleInternetError(_T("DownloadWebPagePostA. HttpSendRequestA"));
				InternetCloseHandle(hRequest);

			}
			else
				HandleInternetError(_T("DownloadWebPagePostA. HttpOpenRequestA"));
			InternetCloseHandle(hConnection);

		}
		else
			HandleInternetError(_T("DownloadWebPagePostA. InternetConnectA"));
	}
	else
		HandleInternetError(_T("DownloadWebPagePostA. InternetCrackUrlA"));
	return bRet;
}
Exemplo n.º 9
0
void CSettingGitConfig::OnBnClickedEditglobalgitconfig()
{
	char charBuf[MAX_PATH];
	TCHAR buf[MAX_PATH];
	strcpy_s(charBuf, MAX_PATH, get_windows_home_directory());
	_tcscpy_s(buf, MAX_PATH, CA2CT(charBuf));
	_tcscat_s(buf, MAX_PATH, _T("\\.gitconfig"));
	// use alternative editor because of LineEndings
	CAppUtils::LaunchAlternativeEditor(buf);
}
Exemplo n.º 10
0
/**
 * @param uNotifyCode - notification code if the message is from a control. If the message is from an accelerator, this value is 1. If the message is from a menu, this value is zero.
 * @param nID - specifies the identifier of the menu item, control, or accelerator.
 * @param hWndCtl - handle to the control sending the message if the message is from a control. Otherwise, this parameter is NULL.
 */
void CManualModeDlg::OnChangeMapPdbFile(UINT /*uNotifyCode*/, int /*nID*/, HWND /*hWndCtl*/)
{
	try
	{
		ClearProcessor();
		CString strMapPdbFile;
		m_txtMapPdbFile.GetWindowText(strMapPdbFile);
		if (strMapPdbFile.IsEmpty())
			return;
		if (GetFileAttributes(strMapPdbFile) != INVALID_FILE_ATTRIBUTES)
		{
			CWaitCursor wait;
			CBaseProcessor::PROCESSED_FILE_TYPE eProcessedFileType = CBaseProcessor::GetFileType(strMapPdbFile);
			switch (eProcessedFileType)
			{
			case CBaseProcessor::PFT_MAP:
				{
					CMapProcessor* pMapProcessor = new CMapProcessor();
					m_pProcessor.reset(pMapProcessor);
					m_eProcessedFileType = CBaseProcessor::PFT_MAP;
					pMapProcessor->LoadMapText(strMapPdbFile);
					CNumEdit& txtBaseAddress = m_txtBaseAddress.GetNumEdit();
					PVOID pPreferredBaseAddress = pMapProcessor->GetBaseAddress();
					if (pPreferredBaseAddress)
					{
						CString strPreferredBaseAddress;
						strPreferredBaseAddress.Format(_T("%08X"), pPreferredBaseAddress);
						txtBaseAddress.SetWindowText(strPreferredBaseAddress);
					}
					else
						txtBaseAddress.SetWindowText(NULL);
				}
				break;
			case CBaseProcessor::PFT_PDB:
				{
					m_eProcessedFileType = CBaseProcessor::PFT_PDB;
					CNumEdit& txtModuleSize = m_txtModuleSize.GetNumEdit();
					txtModuleSize.EnableWindow(TRUE);
					CRadixMenu& btnModuleSize = m_txtModuleSize.GetRadixMenu();
					btnModuleSize.EnableWindow(TRUE);
				}
				break;
			default:
				MsgTip::ShowMessage(m_txtMapPdbFile, IDS_INVALIDMAPPDBFILE);
				return;
			}
		}
	}
	catch (std::exception& error)
	{
		CString strProjectTitle;
		strProjectTitle.LoadString(IDS_PROJECTTITLE);
		MessageBox(CA2CT(error.what()), strProjectTitle, MB_OK | MB_ICONERROR);
	}
}
Exemplo n.º 11
0
UINT GetWindowsCodePageA(LPCSTR html)
{
	//Changed to make it work
	//There is a problem for non latin users (like me) when downloading
	//English / french / spanish lyrics..
	//To overcome this problem you must check the page's codepage
	//In HTML's 
	//<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> = Latin1 (28591)
	//<meta http-equiv="Content-Type" content="text/html; charset=windows-1253"> = Greek (1253)
	//<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> = Latin1 (1252)
	//<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> = utf8 (65001)
	//If nothing then use Latin1

	UINT codePage = 0;
	LPCSTR startPos = strstr(html, " charset=");
	if (startPos != NULL)
	{
		startPos += 9;
		LPCSTR endPos = strchr(startPos + 1, '"');
		if (endPos != NULL && endPos - startPos < 30)
		{
			CHAR bf[30];
			strncpy(bf, startPos, endPos - startPos);
			bf[endPos - startPos] = 0;
			_strlwr(bf);
			if (_strnicmp(bf, "windows-", 8) == 0 && endPos - startPos > 8)
			{
				codePage = atol(&bf[8]);
			}
			else if (_strnicmp(bf, "iso-8859-", 9) == 0 && endPos - startPos > 9)
			{
				codePage = 28590 +  atol(&bf[9]);
			}
			else if (_strnicmp(bf, "utf-8", 5) == 0)
				codePage = 65001;
			else if (_strnicmp(bf, "utf-7", 5) == 0)
				codePage = 65000;
			else
			{
				TRACE(_T("@1 GetWindowsCodePageA. Unknown charset: '%s'\r\n"), (LPCTSTR)CA2CT(bf));
			}
		}
		else
			TRACE(_T("@1 GetWindowsCodePageA. Can't find END charset\r\n"));
	}
	else
		TRACE(_T("@1 GetWindowsCodePageA. Can't find charset\r\n"));

	return codePage;
}
Exemplo n.º 12
0
BOOL DownloadWebPageA(std::string& page, HINTERNET hInternet, LPCSTR url)
{
	TRACEST(_T("DownloadWebPageA"), CA2CT(url));
	BOOL bDownloadSuccess = FALSE;
	if (hInternet == NULL)
		return FALSE;
	HINTERNET hFile = InternetOpenUrlA(hInternet, url, NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0);
	if (hFile)
	{   
		bDownloadSuccess = ReadInternetFile2StringA(hFile, page);
		InternetCloseHandle(hFile);
	}
	else
		HandleInternetError(_T("DownloadWebPage. InternetOpenUrlA"));
	return bDownloadSuccess;
}
Exemplo n.º 13
0
bool getStrFromBuffer_ANSI_to_UNICODE(LPTSTR* ptszStr, LPBYTE& pbtCurrentPos, LPBYTE pbtBuffer, DWORD dwBufferSizeSize)
{
	USES_CONVERSION;
	LPSTR pszANSI = nullptr;
	if (!getStrFromBuffer (&pszANSI, pbtCurrentPos, pbtBuffer, dwBufferSizeSize))
		return false;
	if (!pszANSI)
	{
		*ptszStr = nullptr;
		return true;
	}
	tstring unicode = CA2CT (pszANSI);
	delete [] pszANSI;
	*ptszStr = new TCHAR [unicode.length () + 1];
	_tcscpy (*ptszStr, unicode.c_str ());
	return true;
}
Exemplo n.º 14
0
void UpdateEntity::Start(void* h) {
	svy::CHttpClient	http;
	//使用第一个参数连接服务器
	NetConfig::SERVICE netcfg = mNetCfg_.mSvrs[0];
	CString a(netcfg.ip);
	a += _T(":") + svy::strFormat(_T("%d"),netcfg.port);
	a = svy::catUrl(a, netcfg.act);
	a.Replace('\\','/');
	http.AddHeader(_T("SENDER"),_T("SERVYOU001"));
	http.AddHeader(_T("ZCBM"), _T(""));
	http.AddHeader(_T("SWJG_DM"), _T("19901000000"));
	http.AddHeader(_T("JKVERSION"), _T("V1.0.055"));
	http.AddHeader(_T("ACTIONCODE"), _T("5002"));
	http.AddHeader(_T("HAS_BODY"), _T("1"));
	http.AddHeader(_T("IS_CRYPT"), _T("0"));
	http.AddHeader(_T("IS_COMPRESS"), _T("0"));
	http.AddHeader(_T("RESERVE_HEAD"), _T("tdp"));
	http.AddHeader(_T("CREATE_DATE"), CTime::GetCurrentTime().Format(_T("%Y/%m/%d")));
	http.SetAgent(_T("Mozilla/3.0 (compatible; Indy Library)"));

	std::string f = BuildBody(BUILD_XML_FILE);

	http.AddParam("file0", f, svy::CHttpClient::ParamFile);
	http.EnableWriteHeader(true);
	http.PerformParam(a);
	long hCode = svy::CHttpClient::PerformUrl(http.GetCURL());
	//上传结束后删除文件
	::DeleteFileA(f.c_str());

	if (hCode != 200) {
		CString msg = svy::strFormat(_T("%s failed %d"),a, hCode);
		LOG_FILE(svy::Log::L_ERROR,msg);
		return;
	} 
	std::string result = http.GetHeader();
	//留下罪证
	LOG_FILE(svy::Log::L_INFO,(LPCTSTR)CA2CT(result.c_str()) );
	//解析返回的数据
	result = http.GetStream();
	if (!result.size()) {
		LOG_FILE(svy::Log::L_INFO,_T("缺少body数据"));
		return;
	}
	FetchUpdate(result);
}
Exemplo n.º 15
0
bool CScene::LoadTechnique()
{
	HRESULT hr;
	ID3DBlob* pEffectBlob;
	ID3DBlob* pErrors; // This strangely typed variable collects any errors when compiling the effect file
	DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; // These "flags" are used to set the compiler options
	DWORD flags2 = D3DCOMPILE_DEBUG | D3DCOMPILE_WARNINGS_ARE_ERRORS | D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY;

	//Compile Technique file
	hr = D3DX11CompileFromFile(
		L"./Shaders/Technique.fx",
		NULL,
		NULL,
		NULL,
		"fx_5_0",
		dwShaderFlags,
		0,
		NULL,
		&pEffectBlob,
		&pErrors,
		&hr
		);

	if( FAILED( hr ) )
	{
		if( pErrors != 0 )  MessageBox( NULL, CA2CT( reinterpret_cast<char*>(pErrors->GetBufferPointer()) ), L"Error", MB_OK ); // Compiler error: display error message
		else               MessageBox( NULL, L"Error loading Vertex Shader FX file. Ensure your FX file is in the same folder as this executable.", L"Error", MB_OK );  // No error message - probably file not found
		return false;
	}

	uint32_t SHADER_DEBUG = 1;
	uint32_t SHADER_RELEASE = 0;
	LPVOID bufferPointer = pEffectBlob->GetBufferPointer();
	SIZE_T bufferSize = pEffectBlob->GetBufferSize();
	hr = D3DX11CreateEffectFromMemory( bufferPointer, bufferSize, 0, mpd3dDevice, &Effect );

	if( FAILED( hr ) )
	{
		MessageBox( NULL, L"Error creating effects", L"Error", MB_OK );
		return false;
	}

	return true;
}
Exemplo n.º 16
0
bool CInFile::Create ()
{
	HANDLE hFile = CreateFile (
		CA2CT(m_lpFileName.c_str()),
		GENERIC_WRITE,
		FILE_SHARE_READ,
		NULL,
		CREATE_ALWAYS,
		FILE_FLAG_SEQUENTIAL_SCAN,
		NULL
		);

	if ( hFile != INVALID_HANDLE_VALUE )
	{
		m_hFile = hFile;
		return true;
	}

	return false;
}
Exemplo n.º 17
0
BOOL CUdpCast::GetRemoteHost(TCHAR lpszHost[], int& iHostLen, USHORT& usPort)
{
	BOOL isOK = FALSE;

	if(m_strHost.IsEmpty())
		return isOK;

	int iLen = m_strHost.GetLength() + 1;

	if(iHostLen >= iLen)
	{
		memcpy(lpszHost, CA2CT(m_strHost), iLen * sizeof(TCHAR));
		usPort = m_usPort;

		isOK = TRUE;
	}

	iHostLen = iLen;

	return isOK;
}
Exemplo n.º 18
0
bool CInFile::Open ()
{
	USES_CONVERSION;
	HANDLE hFile = CreateFile (
		CA2CT(m_lpFileName.c_str()),

		GENERIC_READ,
		FILE_SHARE_READ|FILE_SHARE_WRITE,
		NULL,
		OPEN_EXISTING,
		FILE_FLAG_SEQUENTIAL_SCAN,
		NULL
		);

	if ( hFile != INVALID_HANDLE_VALUE )
	{
		m_hFile = hFile;
		return true;
	}

	return false;
}
Exemplo n.º 19
0
// Read the bytes of the packet as though they are ASCII characters, placing periods for those that aren't
// Returns a string like "abc..fgh.i"
CString CPacket::ToASCII() const
{
	// Make a string and get direct access to its memory buffer
	CStringA strDump;
	LPSTR pszDump = strDump.GetBuffer( m_nLength + 1 ); 	// We'll write a character for each byte, and 1 more for the null terminator

	// Loop i down each byte in the packet
	for ( DWORD i = 0 ; i < m_nLength ; i++ )
	{
		// Copy the byte at i into an integer called nChar
		int nChar = m_pBuffer[i];

		// If the byte is 32 or greater, read it as an ASCII character and copy that character into the string
		*pszDump++ = CHAR( nChar >= 32 ? nChar : '.' ); 	// If it's 0-31, copy in a period instead
	}

	// Write a null terminator beyond the characters we wrote, close direct memory access to the string, and return it
	*pszDump = 0;
	strDump.ReleaseBuffer();

	return (LPCTSTR)CA2CT( (LPCSTR)strDump );
}
Exemplo n.º 20
0
	// 指定したcodepageのテキストとしてファイルを読み込みます
CString Util::File::ReadAllText(const CString& path, const UINT codePage)
{
	CString rc;
	CAtlFile file;
	if(file.Create(path, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING) != S_OK){
		rc.Format(_T("ERROR: File Not Found[path=%s]\n"), (LPCTSTR)path);
		return rc;
	}
	ULONGLONG size;
	if(file.GetSize(size) != S_OK){
		rc.Format(_T("ERROR: File GetSize[%s]\n"), (LPCTSTR)path);
		return rc;
	}
	CAtlArray<char> buf;
	buf.SetCount((size_t)size+1);
	if(file.Read(buf.GetData(), (DWORD)size) != S_OK){
		rc.Format(_T("ERROR: File Read[%s]\n"), (LPCTSTR)path);
		return rc;
	}
	buf[(size_t)size] = 0;
	rc = CA2CT(buf.GetData(), codePage);
	return rc;
}
Exemplo n.º 21
0
/**
 * @param uNotifyCode - notification code if the message is from a control. If the message is from an accelerator, this value is 1. If the message is from a menu, this value is zero.
 * @param nID - specifies the identifier of the menu item, control, or accelerator.
 * @param hWndCtl - handle to the control sending the message if the message is from a control. Otherwise, this parameter is NULL.
 */
void CManualModeDlg::OnCalculate(UINT /*uNotifyCode*/, int /*nID*/, HWND /*hWndCtl*/)
{
	try
	{
		CString strMapPdbFile;
		m_txtMapPdbFile.GetWindowText(strMapPdbFile);
		if (strMapPdbFile.IsEmpty())
		{
			MsgTip::ShowMessage(m_txtMapPdbFile, IDS_INVALIDMAPPDBFILE);
			return;
		}

		CNumEdit& txtBaseAddress = m_txtBaseAddress.GetNumEdit();
		DWORD64 dwBaseAddress64;
		txtBaseAddress.GetValue(dwBaseAddress64);
		PVOID ptrBaseAddress = (PVOID)dwBaseAddress64;
		if (! ptrBaseAddress)
		{
			MsgTip::ShowMessage(txtBaseAddress, IDS_INVALIDBASEADDRESS);
			return;
		}

		CNumEdit& txtCrashAddress = m_txtCrashAddress.GetNumEdit();
		DWORD64 dwCrashAddress64;
		txtCrashAddress.GetValue(dwCrashAddress64);
		PVOID ptrCrashAddress = (PVOID)dwCrashAddress64;
		if (! ptrCrashAddress)
		{
			MsgTip::ShowMessage(txtCrashAddress, IDS_INVALIDCRASHADDRESS);
			return;
		}

		CWaitDialog wait(m_hWnd);
		switch (m_eProcessedFileType)
		{
		case CBaseProcessor::PFT_MAP:
			{
				CBaseProcessor* pBaseProcessor = m_pProcessor.get();
				if (! pBaseProcessor || pBaseProcessor->GetRuntimeClass() != RUNTIME_CLASS(CMapProcessor))
				{
					MsgTip::ShowMessage(m_txtMapPdbFile, IDS_INVALIDMAPPDBFILE);
					return;
				}
				CMapProcessor* pMapProcessor = STATIC_DOWNCAST(CMapProcessor, pBaseProcessor);
				pMapProcessor->SetBaseAddress(ptrBaseAddress);
			}
			break;
		case CBaseProcessor::PFT_PDB:
			{
				CNumEdit& txtModuleSize = m_txtModuleSize.GetNumEdit();
				DWORD32 dwModuleSize;
				txtModuleSize.GetValue(dwModuleSize);
				if (! dwModuleSize)
				{
					MsgTip::ShowMessage(txtModuleSize, IDS_INVALIDMODULESIZE);
					return;
				}
				m_pProcessor.reset(); // unload old modules
				CPdbProcessor* pPdbProcessor = new CPdbProcessor();
				m_pProcessor.reset(pPdbProcessor);
				pPdbProcessor->LoadModule(strMapPdbFile, ptrBaseAddress, dwModuleSize);
			}
			break;
		default:
			MsgTip::ShowMessage(m_txtMapPdbFile, IDS_INVALIDMAPPDBFILE);
			return;
		}

		CString strFunctionInfo;
		boost::shared_ptr<CBaseFnInfo> pFnInfo;
		DWORD64 dwDisplacement64;
		if (m_pProcessor->FindFunctionInfo(ptrCrashAddress, pFnInfo, dwDisplacement64))
		{
			CString strFunctionName(CA2CT(pFnInfo->GetName().c_str()));
			if (dwDisplacement64 != 0)
				strFunctionInfo.Format(_T("%s+%I64u bytes"), strFunctionName, dwDisplacement64);
			else
				strFunctionInfo = strFunctionName;
		}
		else
			strFunctionInfo.LoadString(IDS_NOFUNCTIONINFO);
		m_txtFunctionName.SetWindowText(strFunctionInfo);

		CString strSourceFile, strLineInfo;
		boost::shared_ptr<CBaseFileInfo> pFileInfo;
		boost::shared_ptr<CBaseLineInfo> pLineInfo;
		DWORD dwDisplacement32;
		if (m_pProcessor->FindLineInfo(ptrCrashAddress, pFileInfo, pLineInfo, dwDisplacement32))
		{
			strSourceFile = CA2CT(pFileInfo->GetFileName().c_str());
			UINT uLineNumber = pLineInfo->GetNumber();
			if (dwDisplacement32 != 0)
				strLineInfo.Format(_T("line %u+%I32u bytes"), uLineNumber, dwDisplacement32);
			else
				strLineInfo.Format(_T("line %u"), uLineNumber);
		}
		else
		{
			strSourceFile.LoadString(IDS_NOSOURCEFILEINFO);
			strLineInfo.LoadString(IDS_NOLINEINFO);
		}
		m_txtSourceFile.SetWindowText(strSourceFile);
		m_txtLineNumber.SetWindowText(strLineInfo);
	}
	catch (std::exception& error)
	{
		CString strProjectTitle;
		strProjectTitle.LoadString(IDS_PROJECTTITLE);
		MessageBox(CA2CT(error.what()), strProjectTitle, MB_OK | MB_ICONERROR);
	}
}
Exemplo n.º 22
0
//--------------------------------------------------------------------------------------
// Load and compile Effect file (.fx file containing shaders)
//--------------------------------------------------------------------------------------
// An effect file contains a set of "Techniques". A technique is a combination of vertex, geometry and pixel shaders (and some states) used for
// rendering in a particular way. We load the effect file at runtime (it's written in HLSL and has the extension ".fx"). The effect code is compiled
// *at runtime* into low-level GPU language. When rendering a particular model we specify which technique from the effect file that it will use
bool CScene::LoadShaders()
{
	ID3DBlob* pEffectBlob;
	ID3DBlob* pErrors; // This strangely typed variable collects any errors when compiling the effect file
	DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; // These "flags" are used to set the compiler options

	//compile shaders individually
	HRESULT hr; 
	hr = D3DX11CompileFromFile(
		L"VertexShader.hlsl",
		NULL,
		NULL,
		NULL,
		"fx_5_0",
		dwShaderFlags,
		0,
		NULL,
		&pEffectBlob,
		&pErrors,
		&hr
		);

	if( FAILED( hr ) )
	{
		if( pErrors != 0 )  MessageBox( NULL, CA2CT( reinterpret_cast<char*>(pErrors->GetBufferPointer()) ), L"Error", MB_OK ); // Compiler error: display error message
		else               MessageBox( NULL, L"Error loading Vertex Shader FX file. Ensure your FX file is in the same folder as this executable.", L"Error", MB_OK );  // No error message - probably file not found
		return false;
	}

	hr = mpd3dDevice->CreateVertexShader( pEffectBlob->GetBufferPointer(), pEffectBlob->GetBufferSize(), NULL, &mp_VertexShader[0] );

	if( FAILED( hr ) )
	{
		if( pErrors != 0 )  MessageBox( NULL, CA2CT( reinterpret_cast<char*>(pErrors->GetBufferPointer()) ), L"Error", MB_OK ); // Compiler error: display error message
		else               MessageBox( NULL, L"Error creating Vertex Shader.", L"Error", MB_OK );  // No error message - probably file not found
		return false;
	}

	hr = D3DX11CompileFromFile(
		L"PixelShader.hlsl",
		NULL,
		NULL,
		"main",
		"fx_5_0",
		dwShaderFlags,
		0,
		NULL,
		&pEffectBlob,
		&pErrors,
		&hr
		);

	if( FAILED( hr ) )
	{
		if( pErrors != 0 )  MessageBox( NULL, CA2CT( reinterpret_cast<char*>(pErrors->GetBufferPointer()) ), L"Error", MB_OK ); // Compiler error: display error message
		else               MessageBox( NULL, L"Error loading Pixel Shader FX file. Ensure your FX file is in the same folder as this executable.", L"Error", MB_OK );  // No error message - probably file not found
		return false;
	}

	hr = mpd3dDevice->CreatePixelShader( pEffectBlob->GetBufferPointer(), pEffectBlob->GetBufferSize(), NULL, &mp_PixelShader[0] );


	if( FAILED( hr ) )
	{
		if( pErrors != 0 )  MessageBox( NULL, CA2CT( reinterpret_cast<char*>(pErrors->GetBufferPointer()) ), L"Error", MB_OK ); // Compiler error: display error message
		else               MessageBox( NULL, L"Error Creating Pixel Shader", L"Error", MB_OK );  // No error message - probably file not found
		return false;
	}
	return true;
}
Exemplo n.º 23
0
UINT CTeenSpiritDlg::NewVersionCheck()
{
	PrgAPI* pAPI = PRGAPI();
	std::string sysID;
	if (pAPI->GetURLSystemID(sysID))
	{
		m_newVerCheckResult = NewVersionChecker::CheckForNewVersion(pAPI->GetInternetHandle(), sUpdateURL, (LPCTSTR)CA2CT(sysID.c_str()));
		PostMessage(MSG_UPDATECHECKER);
	}
	return 0;
}
Exemplo n.º 24
0
BOOL CUploadTransferDC::OnUpload(const std::string& strType, const std::string& strFilename, QWORD nOffset, QWORD nLength, const std::string& strOptions)
{
	ASSERT( m_pClient );

	if ( m_nState >= upsUploading )
	{
		// Drop unsent data
		CLockedBuffer pOutput( m_pClient->GetOutput() );
		pOutput->Clear();

		m_nState = upsRequest;
	}

	ClearRequest();

	m_sUserAgent = m_pClient->GetUserAgent();
	m_pHost = m_pClient->m_pHost;
	m_sAddress = m_pClient->m_sAddress;
	UpdateCountry();

	m_pClient->m_mInput.pLimit  = &Settings.Bandwidth.Request;
	m_pClient->m_mOutput.pLimit = &m_nBandwidth;

	m_tRequest = GetTickCount();

	BOOL bZip = ( strOptions.find("ZL1") != std::string::npos );

	if ( strType == "tthl" )
	{
		m_bGet = FALSE;

		if ( strFilename.substr( 0, 4 ) == "TTH/" )
		{
			Hashes::TigerHash oTiger;
			if ( oTiger.fromString( CA2W( strFilename.substr( 4 ).c_str() ) ) )
			{
				CSingleLock oLock( &Library.m_pSection );
				if ( oLock.Lock( 1000 ) )
				{
					if ( CLibraryFile* pFile = LibraryMaps.LookupFileByTiger( oTiger, TRUE, TRUE ) )
					{
						if ( RequestTigerTree( pFile, nOffset, nLength ) )
							return TRUE;
					}
				}
			}
		}
	}
	else if ( strType == "file" || strType =="get" )
	{
		m_bGet = ( strType == "get" );

		if ( strFilename == "files.xml" || strFilename == "files.xml.bz2" )
		{
			if ( RequestFileList( TRUE, bZip, strFilename, nOffset, nLength ) )
				return TRUE;
		}
		else if ( strFilename.substr( 0, 4 ) == "TTH/" )
		{
			Hashes::TigerHash oTiger;
			if ( oTiger.fromString( CA2W( strFilename.substr( 4 ).c_str() ) ) )
			{
				CSingleLock oLock( &Library.m_pSection );
				if ( oLock.Lock( 1000 ) )
				{
					if ( CLibraryFile* pFile = LibraryMaps.LookupFileByTiger( oTiger, TRUE, TRUE ) )
					{
						if ( RequestFile( pFile, nOffset, nLength ) )
							return TRUE;
					}
				}
			}
		}
	}
	else if ( strType == "list" )
	{
		m_bGet = FALSE;

		if ( RequestFileList( FALSE, bZip, strFilename, nOffset, nLength ) )
			return TRUE;
	}
	else if ( strType == "send" )
	{
		if ( m_bGet )
		{
			if ( m_pXML.GetCount() )
			{
				// Send cached file list
				m_bGet = FALSE;

				StartSending( upsBrowse );

				m_pClient->Write( &m_pXML );

				m_pXML.Clear();

				return TRUE;
			}
			else if ( SendFile() )
			{
				// Send already requested file
				return TRUE;
			}
		}
		// else $Send without $Get
	}
	else
	{
		// Invalid request type
		theApp.Message( MSG_ERROR, _T("DC++ Invalid request type from %s"), (LPCTSTR)m_sAddress );
		return FALSE;
	}

	theApp.Message( MSG_ERROR, IDS_UPLOAD_FILENOTFOUND, (LPCTSTR)m_sAddress, (LPCTSTR)CA2CT( strFilename.c_str() ) );

	m_pClient->SendCommand( FILE_NOT_AVAILABLE );

	return TRUE;
}
Exemplo n.º 25
0
bool UpdateEntity::FetchUpdate(const std::string& val) {
	{
		//解析xml判断当前动作
		tinyxml2::XMLDocument doc;
		if (tinyxml2::XML_NO_ERROR != doc.Parse(val.c_str())) {
			CString body = svy::strFormat(_T("无法解析 %s"), (LPCTSTR)CA2CT(val.c_str()));
			LOG_FILE(svy::Log::L_INFO, body);
			return false;
		}
		tinyxml2::XMLElement *root = doc.RootElement();
		tinyxml2::XMLElement *ndExt= root->FirstChildElement("EXTEND");	//扩展字段
		tinyxml2::XMLElement *body = root->FirstChildElement("BODY");
		if (!body) {
			CString body = svy::strFormat(_T("不符合规范 %s"), (LPCTSTR)CA2CT(val.c_str()));
			LOG_FILE(svy::Log::L_INFO, body);
			return false;
		}
		tinyxml2::XMLElement *response = body->FirstChildElement("RETURN");
		if (!response) {
			CString body = svy::strFormat(_T("不符合规范 %s"), (LPCTSTR)CA2CT(val.c_str()));
			LOG_FILE(svy::Log::L_INFO, body);
			return false;
		}
		if (0 != strcmp(response->Attribute("CODE"), "0000")) {
			CString body = svy::strFormat(_T("异常 %s"), (LPCTSTR)CA2CT(val.c_str()));
			LOG_FILE(svy::Log::L_INFO, body);
			return false;
		}
		tinyxml2::XMLElement *ndSJXX = body->FirstChildElement("SJXX");		//产品字段
		tinyxml2::XMLElement *product = nullptr;
		if (!ndSJXX) {
			CString body = svy::strFormat(_T("不符合规范 %s"), (LPCTSTR)CA2CT(val.c_str()));
			LOG_FILE(svy::Log::L_INFO, body);
			return false;
		}
		//找到该产品的升级node
		for (tinyxml2::XMLElement *next = ndSJXX->FirstChildElement(); next; next = next->NextSiblingElement()) {
			if (strcmp(next->Name(), "PRODUCT"))
				continue;
			CString a = (LPCTSTR)CA2CT(next->Attribute("CODE"));
			if (a != mExe_.mVer_.mProductCode_)
				continue;
			product = next;
			break;
		}
		if (product==nullptr) {
			CString body = svy::strFormat(_T("缺少对应产品 %s"), (LPCTSTR)CA2CT(val.c_str()));
			LOG_FILE(svy::Log::L_INFO, body);
			return false;
		}
		//存第一个版本升级包
		std::shared_ptr<UP_PACK> info = std::make_shared<UP_PACK>();
		info->url = CA2CT(product->Attribute("UPDATEURL"));
		if (info->url.IsEmpty()) {
			info->url = CA2CT(product->Attribute("OTHERURL"));
			long dot = info->url.Find(',');
			if (dot != -1 && dot > 0)
				info->url = info->url.Mid(0, dot);
		}
		info->ver = CA2CT(product->Attribute("END_VERSION"));
		CString bNeedUp = CA2CT(product->Attribute("HAS_UPDATE"));
		bNeedUp.Trim();
		if (0 == bNeedUp.CompareNoCase(_T("0"))) {
			LOG_FILE(svy::Log::L_INFO,(LPCTSTR)CA2CT(val.c_str()));
			return true;
		}
		if ( !info->ver.IsEmpty() || !info->url.IsEmpty()) {
			mUpData_.push_back(info);
		}
		//存其他版本升级包
		tinyxml2::XMLElement *packs = product->FirstChildElement("GREATERVERSION");
		for (tinyxml2::XMLElement *next = packs; next; next = next->NextSiblingElement()) {
			std::shared_ptr<UP_PACK> info = std::make_shared<UP_PACK>();
			info->url = CA2CT(next->Attribute("UPDATEURL"));
			if (info->url.IsEmpty()) {
				info->url = CA2CT(next->Attribute("OTHERURL"));
				long dot = info->url.Find(',');
				if (dot != -1 && dot > 0)
					info->url = info->url.Mid(0, dot);
			}
			info->ver = CA2CT(next->Attribute("END_VERSION"));
			if (!info->ver.IsEmpty() || !info->url.IsEmpty()) {
				mUpData_.push_back(info);
			}
		}
	}
	std::vector<CString>	badVers;	//异常版本队列,可能是下载错误或写入错误也可能是挂包错误导致
	size_t nCount = mUpData_.count();
	for (size_t nI = 0; nI < nCount; nI++) {
		std::shared_ptr<UP_PACK> info = mUpData_[nI];
		//生成文件
		CString path;
		long	hCode = 0;
		{
			path.Format(_T("%s_%s.zip"),svy::PathGetFileName(mExe_.getPathFile()), info->ver);
			FILE *f = nullptr;
			errno_t err;
			if ((err = fopen_s(&f, CT2CA(path), "wb")) != 0) {
				LOG_FILE(svy::Log::L_ERROR, svy::strFormat(_T("file open filed %d"), err));
				return false;
			}
			//下载数据
			svy::CHttpClient	http;
			http.BodySaveFile(f);
			http.PerformParam(info->url);
			hCode = svy::CHttpClient::PerformUrl(http.GetCURL());
			fclose(f);
			f = nullptr;
		}
		if (hCode != 200) {
			//异常文件
			LOG_FILE(svy::Log::L_ERROR,info->url);
			::DeleteFile(path);
			badVers.push_back(info->ver);
			continue;
		}
		//需要解压缩
		info->step = Step::ExtractFiles;
		info->path = path;
	}
	//移除异常的数据
	nCount = badVers.size();
	for (size_t nI = 0; nI < nCount; nI++) {
		CString key = badVers[nI];
		std::shared_ptr<UP_PACK> pack = mUpData_.getBegin();
		while (pack=mUpData_.getNext()) {
			if (key == pack->ver) {
				mUpData_.erase(pack);
				break;
			}
		}		
	}
	//处理升级包
	HandleUpdatePack();
	return true;
}
Exemplo n.º 26
0
///////////////////////////////////////////////////////////////////////////////
// OnInitDialog
BOOL CCrashReportDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// get our path name - we assume that crashed exe is in same directory
	TCHAR appPath[_MAX_PATH];
	appPath[0]=0;
	::GetModuleFileName(NULL, appPath, _MAX_PATH);
	TCHAR *cp = _tcsrchr(appPath, _T('\\'));
	if (cp != NULL)
	{
		cp++;
		*cp = 0;
	}
	TCHAR crashedAppicationPath[MAX_PATH];
	_sntprintf(crashedAppicationPath, MAX_PATH, _T("%s%s"), appPath, CRASHREPORT_APPEXENAME);
	//=== Initialize the gui with the Crashed Title / icon
	InitializeDisplay(CRASHREPORT_APPTITLE, crashedAppicationPath);
	//=== Create the native report
	m_debugInfo += CollectInformation(crashedAppicationPath);


	//=== Application Monitor Data
#ifdef USE_APPLICATIONMONITOR
	TCHAR bf[MAX_PATH];
	GetModuleFileName(NULL, bf, MAX_PATH);
	LPTSTR pos = _tcsrchr(bf, '\\');
	pos[1] = 0;
	_tcscat(bf, CRASHREPORT_APPEXENAME);
	pos = _tcsrchr(bf, '.');
	pos[1] = 0;
	_tcscat(bf, _T("ini"));

	IniAppSettings settings;
	settings.Load(bf);
	std::basic_string<TCHAR> stateString;
	if (settings.Read(CRASHREPORT_INIMONITORSECTION, CRASHREPORT_INIMONITORVALUE, stateString, _T("")))
	{
		AppMonitor appMon;
		if (appMon.Load(stateString.c_str()))
		{
			const AppMonitor::State& state = appMon.GetState();
			m_appID = state.AppUniqueID;
			CString line;
			line.Format(_T("AppUniqueID: %u\r\n"), state.AppUniqueID);
			m_debugInfo += line;
			line.Format(_T("IsAfterCrashStatus: %d\r\n"), appMon.IsAfterCrash());
			m_debugInfo += line;
			line.Format(_T("Statistics: %d/%d - %d/%d\r\n"), 
				state.Crashes, 
				state.Runs, 
				state.TotalCrashes, 
				state.TotalRuns
				);
			m_debugInfo += line;
		}

	}

#endif


	//=== Add the rest of the files to the report
	INT fileNum = 0;
	LPCTSTR files[] = CRASHREPORT_FILES;
	while (files[fileNum] != 0)
	{
		TCHAR bf[MAX_PATH];
		_sntprintf(bf, MAX_PATH, _T("%s%s"), appPath, files[fileNum]);
		CStringA fileContents;
		if (ReadFileContents(bf, fileContents))
		{
			m_debugInfo += _T("\r\n@===");
			m_debugInfo += files[fileNum];
			m_debugInfo += _T("\r\n");
			m_debugInfo += CA2CT(fileContents);
		}
		fileNum++;
	}
	LoadHandCursor();
	SetTimer(1, 80, NULL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}
Exemplo n.º 27
0
///////////////////////////////////////////////////////////////////////////////
// OnSend
void CCrashReportDlg::OnSend() 
{
	CString userComments;
	m_What.GetWindowText(userComments);
	if (userComments.IsEmpty() == FALSE)
	{
		m_debugInfo += _T("\r\n@===User Comments\r\n");
		m_debugInfo += userComments;
	}

	CHAR bf[500];

	const INT cMaxString = 30000;
	CHAR utf8bf[cMaxString];
	INT len = WideCharToMultiByte(CP_UTF8, 0, m_debugInfo, -1, utf8bf, cMaxString, 0, 0);
	if (len == 0)
	{
		TRACE(_T("CCrashReportDlg::OnSend WideCharToMultiByte Failed\r\n"));
		return;
	}
	utf8bf[len] = 0;
	std::string xmlstring = utf8bf;
	replace(xmlstring, "&", "&amp;");
	replace(xmlstring, "<", "&lt;");
	replace(xmlstring, ">", "&gt;");
	replace(xmlstring, "'", "&apos;");
	replace(xmlstring, "\"", "&quot;");

	std::string request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
	request += "<request>";
	request += "<info uid=\"";
	_snprintf_s(bf, 500, "CR1:%u:%u:%u", m_appID, GetVersion(), CRASHREPORT_BUILDVERSION);
	request += bf;
	request += "\" />";

	request += "<operation name=\"senddebuglog\"><log>";
	request += xmlstring;
	request += "</log></operation>";
	request += "</request>";


	//static LPCTSTR const sWebServiceURL = _T("http://localhost/services/tsservice.php");



	INT dataSize = request.size();
	LPSTR encData = URLEncDecHelper::EncodeData((LPBYTE)request.c_str(), dataSize, TRUE, TRUE);

	std::string params;
	params += CRASHREPORT_REPORTURLPARAM;
	params += encData;
	delete[] encData;


	HINTERNET hNet = InternetOpen(CRASHREPORT_APPTITLE, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	std::string page;
	if (DownloadWebPagePost(page, hNet, CRASHREPORT_REPORTURL, params.c_str()))
	{
		LPCSTR pos = page.c_str();
		if (strncmp(pos, "OK", 2) == 0)
		{
			if (page.size() > 2)
			{
				MessageBox(CA2CT(&page[2]), _T("Thank you"));
			}
			else
				MessageBox(_T("Your report has been sent."), _T("Thank you"));
		}

	}
	InternetCloseHandle(hNet);
	RestartIfNeeded();
	CDialog::OnOK();
}
Exemplo n.º 28
0
BOOL GoogleLyricsProvider::GetNextResult(Result& result)
{
	m_result.clear();
	m_resultAdditionalInfo.clear();
	ASSERT(m_curResult > -1);//Should be Initialized
	ASSERT(!m_Artist.empty() && !m_Track.empty());
	if (m_Artist.empty() || m_Track.empty())
		return FALSE;

	if (m_curResult == 0)
	{
		TRACE(_T("@3 GoogleLyricsProvider::GetResult(). Dowloading Google Page\r\n"));
		//std::tstring query = _T("http://www.google.com/search?q=");
		std::tstring query = _T("allintitle:\"");
		query += m_Artist;
		query += _T("\" \"");
		query += m_Track;
		switch (m_request.service)
		{
		case SRV_TrackLyrics:
			query += _T("\" lyrics");
			break;
		case SRV_TrackTablatures:
			query += _T("\" chords");
			break;
		default:
			ASSERT(0);
			return FALSE;
		}
		std::tstring fixString;
		URLEncode(fixString, query.c_str());
		query = _T("http://www.google.com/search?q=");
		query += fixString;




		//URLEncode(fixString, m_Artist.c_str());
		//query += fixString;
		//query += _T("\"+\"");
		//URLEncode(fixString, m_Track.c_str();
		//query += fixString;
		//switch (m_request.service)
		//{
		//case SRV_TrackLyrics:
		//	query += _T("\"+lyrics");
		//	break;
		//case SRV_TrackTablatures:
		//	query += _T("\"+chords");
		//	break;
		//default:
		//	ASSERT(0);
		//	return FALSE;
		//}

		
		//fixString.clear();
		//URLEncode(fixString, query.c_str());
		

		//CHAR bf[1000];
		//WideCharToMultiByte(CP_ACP, 0, query.c_str(), -1, bf, 1000, 0, 0);

		//CHAR url[1000];
		//DWORD bfLen = 1000;
		//BOOL ret = InternetCanonicalizeUrlA(bf, url, &bfLen, 0);
		//query = bf;

		//query = _T("http://www.google.com/search?q=allintitle%3A%22%CE%98%CE%B1%CE%BD%CE%AC%CF%83%CE%B7%CF%82%2B%CE%A0%CE%B1%CF%80%CE%B1%CE%BA%CF%89%CE%BD%CF%83%CF%84%CE%B1%CE%BD%CF%84%CE%AF%CE%BD%CE%BF%CF%85%22%2B%22%CE%89%CE%BC%CE%B5%CF%81%CE%BF%CF%82%2B%CE%8E%CF%80%CE%BD%CE%BF%CF%82%22%2Blyrics");
		std::string page;
		if (DownloadWebPage(page, m_hNet, query.c_str()))
		{
			const INT cLinkLen = 1000;
			CHAR linkBuffer[cLinkLen];
			LPCSTR startPos = page.c_str(); 
			while (startPos != NULL)
			{
				startPos = strstr(startPos, "h3 class=\"r\">");
				if (startPos)
				{
					startPos = strstr(startPos, "http:");
					if (startPos)
					{
						LPCSTR endPos = NULL;
						if (startPos[-1] == '"')
							endPos = strchr(startPos + 1, '"');
						else
							endPos = strchr(startPos + 1, '&');
						if (endPos)
						{
							if (endPos - startPos < (INT)cLinkLen)
							{
								strncpy(linkBuffer, startPos, endPos - startPos);
								linkBuffer[endPos - startPos] = 0;
								if (IsBlackListed(linkBuffer) == FALSE)
									m_googleLinks.push_back(linkBuffer);
							}
							else
								TRACE(_T("@1 GoogleLyricsProvider::NextResult. link bigger than expected (FAILED)\r\n"));
						}
						else
							TRACE(_T("@1 GoogleLyricsProvider::NextResult. Can't find endPos '%0.150s'\r\n"), CA2CT(&startPos[-1]));
						startPos = endPos;
					}
					else
						TRACE(_T("@1 GoogleLyricsProvider::NextResult. Can't find startPos (2) (FAILED)\r\n"));
				}
				else
					TRACE(_T("@1 GoogleLyricsProvider::NextResult. Can't find startPos (1) (FAILED)\r\n"));
			}
			if (m_googleLinks.empty())
			{
				startPos = page.c_str(); 
				//=== This happens on iGoogle
				while (startPos != NULL)
				{
					startPos = strstr(startPos, " class=r>");
					if (startPos)
					{
						startPos = strstr(startPos, "http:");
						if (startPos)
						{
							LPCSTR endPos = NULL;
							if (startPos[-1] == '"')
								endPos = strchr(startPos + 1, '"');
							else
								endPos = strchr(startPos + 1, '&');
							if (endPos)
							{
								if (endPos - startPos < (INT)cLinkLen)
								{
									strncpy(linkBuffer, startPos, endPos - startPos);
									linkBuffer[endPos - startPos] = 0;
									if (IsBlackListed(linkBuffer) == FALSE)
										m_googleLinks.push_back(linkBuffer);
								}
								else
									TRACE(_T("@1 GoogleLyricsProvider::NextResult. (r) link bigger than expected (FAILED)\r\n"));
							}
							else
								TRACE(_T("@1 GoogleLyricsProvider::NextResult. (r) Can't find endPos '%0.150s'\r\n"), CA2CT(&startPos[-1]));
							startPos = endPos;
						}
						else
							TRACE(_T("@1 GoogleLyricsProvider::NextResult. (r) Can't find startPos (2) (FAILED)\r\n"));
					}
					else
						TRACE(_T("@1 GoogleLyricsProvider::NextResult. (r) Can't find startPos (1) (FAILED)\r\n"));
				}

			}

		}
		else
			TRACE(_T("@1 GoogleLyricsProvider::NextResult(). Dowloading Google Page (FAILED)\r\n"));

	}

	std::wstring page;
	while (m_curResult < (INT)m_googleLinks.size())
	{
		BOOL bResultFound = FALSE;
		if (DownloadWebPageUnicode(page, m_hNet, (LPCTSTR)CA2CT(m_googleLinks[m_curResult].c_str())))
		{
			RemoveEnclosedString(page, _T("<!--"), _T("-->"));
			RemoveEnclosedString(page, _T("<head"), _T("/head>"));
			RemoveEnclosedString(page, _T("<script"), _T("/script>"));
			RemoveEnclosedString(page, _T("<a href="), _T("/a>"));
			ReplaceHtmlEntities(page);
			if (ExtractLyrics(page))
			{

				//InlineHTML2Text(pResult.get());
				//m_result = pResult.get();
				m_result = page;
				LPCTSTR delims = _T(" \t\n\r");
				m_result.erase(0, m_result.find_first_not_of(delims));		//Trim Left
				m_result.erase(m_result.find_last_not_of(delims) + 1);		//Trim Right
				if (m_result.size() > 40)
				{
					//Keep Additional Info (The Web Site Provider)
					LPCSTR pLink = m_googleLinks[m_curResult].c_str();
					LPCSTR sp = &pLink[7];
					LPCSTR ep = strchr(&pLink[8], '/');
					if (ep != 0)
					{
						CHAR SourceSiteU[MAX_PATH];
						strncpy(SourceSiteU, sp, INT(ep - sp) > 99 ? 99 : INT(ep - sp));
						SourceSiteU[INT(ep - sp) > 99 ? 99 : INT(ep - sp)] = 0;
						m_resultAdditionalInfo = (LPCTSTR)CA2CT(SourceSiteU);
					}
					else
						m_resultAdditionalInfo.clear();
					bResultFound = TRUE;
				}
			}
			else
				TRACE(_T("@1 GoogleLyricsProvider::GetResult(). ExtractLyrics (FAILED)\r\n"));
		}		
		else
			TRACE(_T("@1 GoogleLyricsProvider::GetResult(). Dowloading Lyrics Page (FAILED) '%s'\r\n"), (LPCTSTR)CA2CT(m_googleLinks[m_curResult].c_str()));

		m_curResult++;
		if (bResultFound)
			break;
	}
	if (m_result.empty())
		return FALSE;
	result.main = m_result.c_str();
	result.additionalInfo = m_resultAdditionalInfo.c_str();
	result.service = m_request.service;
	return TRUE;
}
Exemplo n.º 29
0
BOOL CLoginDlg::dataParser(char* readBuffer)
{
	BOOL bRtn = TRUE;
	CComm func;
	char* char_str;

	char_str = func.ConvertBuffer(readBuffer);

	std::string config_doc = char_str;
	Json::Value root;
	Json::Reader reader;
	bool parsingSuccessful = reader.parse(config_doc, root);
	if (!parsingSuccessful)
	{
		TRACE(L"\r\n!!!!!!!!!!!!!!!!!! Parser Error !!!!!!!!!!!!!!!!!!!!!!!!\r\n");
		std::cout << "Failed to parse configuration\n"
			<< reader.getFormatedErrorMessages();
		bRtn = FALSE;
		return bRtn;
	}

	Json::Value array = root["data"];
	CString strValue = L"";
	std::string item;
	for (unsigned int i = 0; i < array.size(); ++i)
	{
		item = array[i].get("profileImage", "default").asString();
		if (item != "default"){
			strValue = CA2CT(item.c_str());   //ANSI => UNICODE 
			WritePrivateProfileString(L"MYINFO", L"profileImage", strValue, func.m_strINI);
		}

		item = array[i].get("searchID", "default").asString();
		if (item != "default"){
			strValue = CA2CT(item.c_str());   //ANSI => UNICODE 
			WritePrivateProfileString(L"MYINFO", L"searchID", strValue, func.m_strINI);
		}

		Json::Value trans = array[i]["translationLanguage"];
		for (unsigned int j = 0; j < trans.size(); ++j){
			item = trans[j].asString();
			strValue = CA2CT(item.c_str());   //ANSI => UNICODE 
			CString strField = L"";
			strField.Format(L"translationLanguage[%d]",j);
			WritePrivateProfileString(L"MYINFO", strField, strValue, func.m_strINI);
		}
		
		item = array[i].get("name", "default").asString();
		if (item != "default"){
			strValue = CA2CT(item.c_str());   //ANSI => UNICODE 
			WritePrivateProfileString(L"MYINFO", L"name", strValue, func.m_strINI);
		}

		item = array[i].get("memberUID",L"default").asString();
		if (item != "default"){
			strValue = CA2CT(item.c_str());   //ANSI => UNICODE 
			WritePrivateProfileString(L"MYINFO", L"memberUID", strValue, func.m_strINI);
		}

		item = array[i].get("language", L"default").asString();
		if (item != "default"){
			strValue = CA2CT(item.c_str());   //ANSI => UNICODE 
			WritePrivateProfileString(L"MYINFO", L"language", strValue, func.m_strINI);
		}

		item = array[i]["contact"].get("phoneNumber", "default").asString();
		if (item != "default"){
			strValue = CA2CT(item.c_str());   //ANSI => UNICODE 
			WritePrivateProfileString(L"MYINFO", L"phoneNumber", strValue, func.m_strINI);
		}

		item = array[i]["contact"].get("countryCode", "default").asString();
		if (item != "default"){
			strValue = CA2CT(item.c_str());   //ANSI => UNICODE 
			WritePrivateProfileString(L"MYINFO", L"countryCode", strValue, func.m_strINI);
		}
		
		item = array[i].get("email", L"default").asString();
		if (item != "default"){
			strValue = CA2CT(item.c_str());   //ANSI => UNICODE 
			WritePrivateProfileString(L"MYINFO", L"email", strValue, func.m_strINI);
		}
		
		item = array[i].get("description", L"default").asString();
		if (item != "default"){
			strValue = CA2CT(item.c_str());   //ANSI => UNICODE 
			WritePrivateProfileString(L"MYINFO", L"description", strValue, func.m_strINI);
		}
	}

	return bRtn;
}
Exemplo n.º 30
0
BOOL CreateDirEx (const char *lpFullPath, DWORD dwFileAttributes)
{
	USES_CONVERSION;
	return CreateDirectoryNested( CA2CT(lpFullPath) );
}