void MSHLanguageMgr::SelectLanguageByName(const BString& languageTag) { const int32 numLanguages = CountLanguages(); for (int32 langIndex = 0; langIndex < numLanguages; langIndex++) { if (GetLanguageName(langIndex) == languageTag) { fCurrentLanguage = langIndex; } } }
std::vector<std::wstring> plLocalization::StringToLocal(const std::wstring & localizedText) { std::vector<std::wstring> tags; std::vector<int> tagLocs; std::vector<int> sortedTagLocs; std::vector<std::wstring> retVal; int i; for (i=0; i<kNumLanguages; i++) { std::wstring tag = L"$"; std::string temp = GetLanguageName((Language)i); wchar_t *wTemp = hsStringToWString(temp.c_str()); std::wstring langName = wTemp; delete [] wTemp; tag += langName.substr(0,2) + L"$"; tags.push_back(tag); tagLocs.push_back(localizedText.find(tag)); sortedTagLocs.push_back(i); retVal.push_back(L""); } for (i=0; i<kNumLanguages-1; i++) { for (int j=i; j<kNumLanguages; j++) { if (tagLocs[sortedTagLocs[i]] > tagLocs[sortedTagLocs[j]]) sortedTagLocs[i]^=sortedTagLocs[j]^=sortedTagLocs[i]^=sortedTagLocs[j]; // swap the contents (yes, it works) } } // now sortedTagLocs has the indexes of tagLocs sorted from smallest loc to highest loc bool noTags = true; for (i=0; i<kNumLanguages; i++) { int lang = sortedTagLocs[i]; // the language we are extracting if (tagLocs[lang] != -1) { noTags = false; // at least one tag was found in the text int startLoc = tagLocs[lang] + tags[lang].length(); int endLoc; if (i+1 == kNumLanguages) endLoc = localizedText.length(); else endLoc = tagLocs[sortedTagLocs[i+1]]; retVal[lang] = localizedText.substr(startLoc,endLoc-startLoc); } } if (noTags) retVal[0] = localizedText; // if no tags were in the text, we assume it to be English return retVal; }
std::string plLocalization::LocalToString(const std::vector<std::string> & localizedText) { std::string retVal = ""; for (int i=0; i<localizedText.size(); i++) { if (i > kNumLanguages-1) break; std::string langHeader = "$"; std::string langName = GetLanguageName((Language)i); langHeader += langName.substr(0,2) + "$"; retVal += langHeader + localizedText[i]; } return retVal; }
char* CNWNXMessages::OnRequest(char *gameObject, char* Request, char* Parameters){ switch(atoi(Request)){ case 1: sprintf( Parameters, "%i", SendMessageToPlayer( (CNWSObject *)gameObject, Parameters, 1 ) ); break; case 2: sprintf( Parameters, "%i", SendMessageToPlayer( (CNWSObject *)gameObject, Parameters, 2 ) ); break; case 3: sprintf( Parameters, "%i", SendMessageToPlayer( (CNWSObject *)gameObject, Parameters, 3 ) ); break; case 4: sprintf( Parameters, "%i", SendMessageToPlayer( (CNWSObject *)gameObject, Parameters, 4 ) ); break; case 5: sprintf( Parameters, "%i", SendMessageToPlayer( (CNWSObject *)gameObject, Parameters, 5 ) ); break; case 6: sprintf( Parameters, "%i", SendMessageToPlayer( (CNWSObject *)gameObject, Parameters, 6 ) ); break; case 7: ScrambleMessage( Parameters ); break; case 8: GetLanguageID( Parameters ); break; case 9: GetLanguageLevel( Parameters ); break; case 10: GetLanguageName( Parameters ); break; case 11: GetLanguageIDInIndex( Parameters ); break; case 12: Parameters[0]='\"'; Parameters[1]='\0'; break; default:break; } return NULL; }
wxString Localization::GetFullDisplayName(const wxString& canonicalName) { wxString languageCode = GetLanguageCodeOnly(canonicalName); wxString countryCode = GetCountryCodeOnly(canonicalName); wxString output = GetLanguageName(languageCode); wxString extraString; if (countryCode != wxEmptyString) { if (languageCode == _T("zh") && countryCode == _T("CN")) { extraString = _T("简体"); // "Simplified" in "Simplified Chinese" } else { extraString = GetCountryName(countryCode); } } if (languageCode == _T("zh") && countryCode == wxEmptyString) extraString = _T("繁體"); // "Traditional" in "Traditional Chinese" if (extraString != wxEmptyString) output += _T(" (") + extraString + _T(")"); return output; }
HRESULT StackFrame::GetInfo( FRAMEINFO_FLAGS dwFieldSpec, UINT nRadix, FRAMEINFO* pFrameInfo ) { if ( pFrameInfo == NULL ) return E_INVALIDARG; HRESULT hr = S_OK; pFrameInfo->m_dwValidFields = 0; if ( (dwFieldSpec & FIF_FRAME) != 0 ) { hr = QueryInterface( __uuidof( IDebugStackFrame2 ), (void**) &pFrameInfo->m_pFrame ); _ASSERT( hr == S_OK ); pFrameInfo->m_dwValidFields |= FIF_FRAME; } if ( (dwFieldSpec & FIF_DEBUG_MODULEP) != 0 ) { if ( mModule.Get() != NULL ) { hr = mModule->QueryInterface( __uuidof( IDebugModule2 ), (void**) &pFrameInfo->m_pModule ); _ASSERT( hr == S_OK ); pFrameInfo->m_dwValidFields |= FIF_DEBUG_MODULEP; } } if ( (dwFieldSpec & FIF_STACKRANGE) != 0 ) { #if 0 if ( mDiaStackFrame != NULL ) { // TODO: review all this UINT64 base = 0; DWORD size = 0; mDiaStackFrame->get_base( &base ); mDiaStackFrame->get_size( &size ); pFrameInfo->m_addrMax = base; pFrameInfo->m_addrMin = base - size; pFrameInfo->m_dwValidFields |= FIF_STACKRANGE; } #endif } if ( (dwFieldSpec & FIF_DEBUGINFO) != 0 ) { if ( mModule.Get() != NULL ) { RefPtr<MagoST::ISession> session; pFrameInfo->m_fHasDebugInfo = mModule->GetSymbolSession( session ); } else pFrameInfo->m_fHasDebugInfo = FALSE; pFrameInfo->m_dwValidFields |= FIF_DEBUGINFO; } if ( (dwFieldSpec & FIF_FUNCNAME) != 0 ) { hr = GetFunctionName( dwFieldSpec, nRadix, &pFrameInfo->m_bstrFuncName ); if ( SUCCEEDED( hr ) ) pFrameInfo->m_dwValidFields |= FIF_FUNCNAME; } if ( (dwFieldSpec & FIF_RETURNTYPE) != 0 ) { //pFrameInfo->m_bstrReturnType; //pFrameInfo->m_dwValidFields |= FIF_RETURNTYPE; } if ( (dwFieldSpec & FIF_ARGS) != 0 ) { //pFrameInfo->m_bstrArgs; //pFrameInfo->m_dwValidFields |= FIF_ARGS; } if ( (dwFieldSpec & FIF_LANGUAGE) != 0 ) { hr = GetLanguageName( &pFrameInfo->m_bstrLanguage ); if ( SUCCEEDED( hr ) ) pFrameInfo->m_dwValidFields |= FIF_LANGUAGE; } if ( (dwFieldSpec & FIF_MODULE) != 0 ) { if ( mModule != NULL ) { CComBSTR modName; mModule->GetName( modName ); pFrameInfo->m_bstrModule = modName.Detach(); if ( pFrameInfo->m_bstrModule != NULL ) pFrameInfo->m_dwValidFields |= FIF_MODULE; } } //FIF_STALECODE m_fStaleCode //FIF_ANNOTATEDFRAME m_fAnnotatedFrame return S_OK; }
TCHAR *GetLanguageName(LANGID language) { LCID lc = MAKELCID(language, SORT_DEFAULT); return GetLanguageName(lc); }
void DoReport(LPCTSTR lpstrCmdLine, BOOL *pIsHandled) { WSADATA wsaData = {0}; WSAStartup(MAKEWORD(2, 2), &wsaData); //LogFinal(LOG::KBugReport) << L"Bugreport启动命令行: " << lpstrCmdLine; REPORT_CONTEXT report; std::wstring strProductName; const TCHAR * p = _tcsstr(lpstrCmdLine, _T("pid=")); if (p) { *pIsHandled = TRUE; DWORD client_process_id = _tcstoul(p + _tcslen(_T("pid=")), 0, 0); p = _tcsstr(lpstrCmdLine, _T("context=")); if (p) { void *addr = (void*)_tcstoul(p + _tcslen(_T("context=")), 0, 0); //YYBrowser Begin //by ZC. 2013-10-30 11:26. // hClientProcess客户进程,即是启动YGCrashReport的进程,不一定是崩溃的目标进程。 HANDLE client_process_handle = ::OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, client_process_id); // 崩溃目标进程。 HANDLE target_process_handle = NULL; //YYBrowser End if (!client_process_handle) LogFinal(LOG::KBugReport) << L"打开进程句柄失败"; //解释REPORT_PARAMS CRASH_LAUNCH_PARAMS crash_launch_params = {0}; DWORD cbRead = 0; if (addr && ::ReadProcessMemory(client_process_handle, addr, &crash_launch_params, sizeof(crash_launch_params), &cbRead)) { LogFinal(LOG::KBugReport) << L"读取REPORT_PARAMS成功"; std::set<std::wstring> setSuspectModule; std::set<std::wstring> setModule; std::wstring strPathNoExt = GenerateNewFilePath(crash_launch_params.dwPID); report.strZipFilePath = strPathNoExt + _T(".zip"); report.strOSVer = GetOSVer(); AtoW(crash_launch_params.szProductName, -1, strProductName); report.dwReportId = crash_launch_params.dwReportId; report.strUserId = crash_launch_params.szUserId; report.strProductId = crash_launch_params.szProductId; report.strProductVer = crash_launch_params.szProductVer; report.strProductVerDetail = crash_launch_params.szProductVerDetail; //AtoW(crash_launch_params.szRestartExePath, -1, report.wstrRestartExePath); report.strDynaReleaseVer = crash_launch_params.szDynaReleaseVer; WriteBugInfo(report.dwReportId); report.dwCount24Hour = GetBugCount(report.dwReportId); //parse 自定义文件路径 if (crash_launch_params.nFileCount > 0) { char *pPaths = new char[MAX_PATH * crash_launch_params.nFileCount]; if (::ReadProcessMemory(client_process_handle, crash_launch_params.lpszCustomFilePaths, pPaths, MAX_PATH * crash_launch_params.nFileCount, &cbRead)) { for (UINT k = 0; k < cbRead / MAX_PATH; k++) { std::wstring wstrPath; AtoW(pPaths + k * MAX_PATH, -1, wstrPath); report.vecOtherFilePath.push_back(wstrPath); } } delete [] pPaths; pPaths = NULL; } //生成log std::string strLog; char szTemp[1024] = {0}; //Date time_t curTime = 0; time(&curTime); strftime(szTemp, _countof(szTemp)-1, "%Y-%m-%d %H.%M.%S\r\n", localtime(&curTime)); strLog += szTemp; strLog += "\r\n"; //异常信息 strLog += "Exception:\r\n"; const char *pModName = strrchr(crash_launch_params.szExcepModPath, '\\'); if (pModName) pModName++; else pModName = crash_launch_params.szExcepModPath; report.strExcepModuleName = pModName; _snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "Module=%s\r\n", pModName); strLog += szTemp; //YYBrowser Begin //打开目标进程。by ZC. 2013-10-30 11:30. target_process_handle = ::OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, crash_launch_params.dwPID); //YYBrowser End //YYBrowser Begin //从目标进程中读出结构异常。by ZC. 2013-10-30 11:28. if (crash_launch_params.pExceptionInfo) { EXCEPTION_RECORD excep = {0}; CONTEXT ct = {0}; EXCEPTION_POINTERS ptr = {0}; if (::ReadProcessMemory(target_process_handle, crash_launch_params.pExceptionInfo, &ptr, sizeof(ptr), &cbRead) && ::ReadProcessMemory(target_process_handle, ptr.ExceptionRecord, &excep, sizeof(excep), &cbRead) && ::ReadProcessMemory(target_process_handle, ptr.ContextRecord, &ct, sizeof(ct), &cbRead)) { report.dwExcepAddr = (DWORD)excep.ExceptionAddress; report.dwExcepCode = excep.ExceptionCode; report.strExcepDiscription = GetExceptionDescription(excep.ExceptionCode); _snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "ExceptionCode=0x%08x, %s\r\n", excep.ExceptionCode, GetExceptionDescription(excep.ExceptionCode)); strLog += szTemp; _snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "eip=0x%08x, ebp=0x%08x, esp=0x%08x, eax=0x%08x, ebx=0x%08x, ecx=0x%08x, edx=0x%08x, esi=0x%08x, edi=0x%08x\r\n", ct.Eip, ct.Ebp, ct.Esp, ct.Eax, ct.Ebx, ct.Ecx, ct.Edx, ct.Esi, ct.Edi); strLog += szTemp; } strLog += "\r\n"; } //YYBrowser End strLog += "Summary:\r\n"; strLog += GetSummary(client_process_handle); strLog += "UserId(YY)=" + report.strUserId + "\r\n"; strLog += "ProductVer=" + report.strProductVer + "\r\n"; strLog += "DynaReleaseVer=" + report.strDynaReleaseVer + "\r\n"; strLog += "ProductVerDetail=" + report.strProductVerDetail + "\r\n"; _snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "ReportId=%u\r\n", report.dwReportId); strLog += szTemp; strLog += "\r\n"; std::string strLoginHistoryLog; std::string strLoginHistory = ReadLoginHistory(strLoginHistoryLog); //用户自定义信息 strLog += "CustomProperty:\r\n"; char *pCustomProperty = new char[crash_launch_params.cchCustomProperty + 1]; if (::ReadProcessMemory(client_process_handle, crash_launch_params.lpszCustomProperty, pCustomProperty, crash_launch_params.cchCustomProperty, &cbRead)) { pCustomProperty[cbRead/sizeof(char)] = 0; report.strCustomProperty = pCustomProperty; } strLog += report.strCustomProperty; if(strLoginHistory.size()>0) { if(report.strCustomProperty.size()>0) { report.strCustomProperty+="&"; } report.strCustomProperty+=strLoginHistory; } if(strLoginHistoryLog.size()>0) { strLog += "\r\n"; strLog += strLoginHistoryLog; } strLog += "\r\n"; //CallStack strLog += "Call Stack:\r\n"; char *pCallStack = new char[crash_launch_params.cchCallStack + 1]; cbRead = 0; if (::ReadProcessMemory(client_process_handle, crash_launch_params.lpszCallStack, pCallStack, crash_launch_params.cchCallStack, &cbRead)) { pCallStack[cbRead/sizeof(char)] = 0; strLog += pCallStack; } strLog += "\r\n"; //收集进程列表&检测运行环境 std::string strProcListA; std::wstring strProcListW; report.dwRunEnvironment = CheckRunEnvironment(strProcListW); WtoA(strProcListW.c_str(), -1, strProcListA); strLog += "Process List:\r\n"; strLog += strProcListA; strLog += "\r\n"; //收集版本的语言种类,不写入日志 report.strProductLang = GetLanguageName(); //模块列表 strLog += "Module List:\r\n"; strLog += GetModuleList(target_process_handle,&setModule,&setSuspectModule); strLog += "\r\n"; //程序Log strLog += "Log:\r\n"; TCHAR szExePath[MAX_PATH] = {0}; GetModuleFileNameEx(target_process_handle, NULL, szExePath, _countof(szExePath)); TCHAR *p = _tcsrchr(szExePath, _T('.')); if (p) *p = 0; TCHAR* pExeName = _tcsrchr(szExePath, _T('\\')); if (pExeName) pExeName++; else pExeName = szExePath; const DWORD dwMaxLogSize = 1024 * 200; // char *pContent = new char [dwMaxLogSize]; // GetLastLog(pExeName, reportParams.dwPID, 0, pContent, dwMaxLogSize); // strLog += pContent; // delete [] pContent; // pContent = NULL; strLog += "\r\n\r\n"; /************************************************************************/ /*功能:在日志文件中添加安装目录下所有dll和rcc文件的md5*/ /***************************只有yy.exe崩溃时,才会计算相关文件的md5*/ if (StrCmpIA(crash_launch_params.szProductId, "YY") == 0) { strLog += "[List *.dll and *.rcc files MD5:] \r\n\r\n"; TCHAR szCurrentProcesspath[MAX_PATH] = {0}; if ( GetModuleFileName(NULL,szCurrentProcesspath,_countof(szCurrentProcesspath)) > 0) { TCHAR* p_findDir = _tcsrchr(szCurrentProcesspath,_T('\\')); std::wstring rawCurrentProcessPath = szCurrentProcesspath; std::wstring strCurrentProcesspath = rawCurrentProcessPath.substr(0, p_findDir - szCurrentProcesspath); strLog += dwCalculateMD5(strCurrentProcesspath.c_str()); } else { strLog += "Get the files'MD5 failed!"; } } else { strLog += "Hint:\r\nThe crash was caused by the other products except the YY!"; } /************************************************************************/ TCHAR szLogPath[_MAX_PATH] = {0}; _sntprintf_s(szLogPath, _countof(szLogPath), _TRUNCATE, _T("%s.txt"), strPathNoExt.c_str()); report.strLogPath = szLogPath; LogFinal(LOG::KBugReport) << L"写入log文件: " << szLogPath; HANDLE hFile = ::CreateFile(szLogPath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, NULL, NULL); DWORD dwWriten = 0; ::WriteFile(hFile, strLog.c_str(), strLog.size(), &dwWriten, NULL); ::CloseHandle(hFile); //生成dump TCHAR szDumpPath[_MAX_PATH] = {0}; _sntprintf_s(szDumpPath, _countof(szDumpPath), _TRUNCATE, _T("%s.dmp"), strPathNoExt.c_str()); LogFinal(LOG::KBugReport) << L"生成dump文件: " << szDumpPath; int nDumpType = (MiniDumpNormal|MiniDumpWithHandleData|MiniDumpWithIndirectlyReferencedMemory|MiniDumpWithUnloadedModules|MiniDumpWithProcessThreadData); if (!CreateDump(szDumpPath, crash_launch_params.dwPID, crash_launch_params.dwTID, crash_launch_params.pExceptionInfo, nDumpType, MyMiniDumpCallBack, &crash_launch_params)) { crash_launch_params.curCustomDataIdx = 0; CreateDump(szDumpPath, crash_launch_params.dwPID, crash_launch_params.dwTID, crash_launch_params.pExceptionInfo, MiniDumpNormal, MyMiniDumpCallBack, &crash_launch_params); } report.strDumpPath = szDumpPath; //生成fulldump CRegKey key; LONG lResult = key.Open(HKEY_CURRENT_USER, _T("Software\\duowan\\bugreport"), KEY_READ); if (ERROR_SUCCESS == lResult) { TCHAR szFullDump[1024] = {0}; DWORD dwSize = _countof(szFullDump); lResult = key.QueryValue(szFullDump, _T("fulldump"), &dwSize); if (ERROR_SUCCESS == lResult) { szFullDump[dwSize] = 0; if (_tcsicmp(szFullDump, _T("yes")) == 0) { nDumpType = (MiniDumpNormal | MiniDumpWithFullMemory | MiniDumpWithIndirectlyReferencedMemory | MiniDumpWithHandleData | MiniDumpWithUnloadedModules | MiniDumpWithProcessThreadData); TCHAR szFullDumpPath[_MAX_PATH] = {0}; ::GetTempPath(_countof(szFullDumpPath), szFullDumpPath); _tcsncat_s(szFullDumpPath, _countof(szFullDumpPath), _T("duowan\\fulldump.dmp"), _TRUNCATE); LogFinal(LOG::KBugReport) << L"生成fulldump文件: " << szFullDumpPath; CreateDump(szFullDumpPath, crash_launch_params.dwPID, crash_launch_params.dwTID, crash_launch_params.pExceptionInfo, nDumpType, MyMiniDumpCallBack, &crash_launch_params); } } } ::SetEvent(crash_launch_params.evDumpComplete); if (crash_launch_params.bShowReportUI) { LogFinal(LOG::KBugReport) << L"开始弹出崩溃界面"; std::string strRecv; bool bShowModifyStatus = false; //if(GetBugModifyStatus(&report,strRecv)) //{ // const char* p = strstr(strRecv.c_str(),"return=true"); // if(p) // { // bShowModifyStatus = true; // } //} CMessageLoop theLoop; _Module.AddMessageLoop(&theLoop); CDlgReport dlgMain(strProductName.c_str(), &report, crash_launch_params.dwPID, &setModule, &setSuspectModule, bShowModifyStatus, strRecv.c_str()); dlgMain.Create(NULL); dlgMain.ShowWindow(SW_SHOW); theLoop.Run(); _Module.RemoveMessageLoop(); } else { SendReport(&report, &setModule, &setSuspectModule); } } else { LogFinal(LOG::KBugReport) << L"读取崩溃进程REPORT_PARAMS失败"; } ::CloseHandle(target_process_handle); ::CloseHandle(client_process_handle); } } }