void CMainApp::Banner() { WriteCon(CONOUT, BANNER); #ifdef _DEBUG WriteCon(CONOUT, BUILDSTAMP); #endif }
void NDLocalXmlString::logErr( const string& keyLine, const string& valLine ) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) WriteCon( "@@ NDLocalXmlString::parseLines(), bad lines: \r\n"); WriteCon( " errline: %s\r\n", keyLine.c_str()); WriteCon( " errline: %s\r\n", valLine.c_str()); #endif }
//=========================================================================== void CSMLoginScene::StartEntry() { WriteCon( "@@ CSMLoginScene::StartEntry()\r\n" ); CCLog( "@@login04: StartEntry()\r\n" ); #if 1 if (m_pLabelPromtp) { m_pLabelPromtp->SetText( NDCommonCString2(SZ_SETUP).c_str() ); m_pLabelPromtp->SetVisible( true ); } ShowWaitingAni(); { WriteCon( "@@ NDLocalXmlString::LoadData()...\r\n" ); TIME_SLICE("NDLocalXmlString::LoadData()"); NDLocalXmlString::GetSingleton().LoadData(); } { WriteCon( "@@ ScriptMgrObj.Load()...\r\n" ); TIME_SLICE("ScriptMgrObj.Load()"); ScriptMgrObj.Load(); //加载LUA脚本 } ScriptMgrObj.excuteLuaFunc( "LoadData", "GameSetting" ); CloseUpdateUILayer(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) //if ( m_iAccountID == 0 ) m_iAccountID = ScriptMgrObj.excuteLuaFuncRetN( "GetAccountID", "Login_ServerUI" ); #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) m_iAccountID = NDBeforeGameMgrObj.GetCurrentUser(); #endif ScriptMgrObj.excuteLuaFunc( "ShowUI", "Entry", m_iAccountID ); // ScriptMgrObj.excuteLuaFunc("ProecssLocalNotification", "MsgLoginSuc"); #else //多线程不会有什么好处,反而是崩溃和不稳定, //实际上网络线程和控制台线程都是多余的!单线程足够了! if (m_pLabelPromtp) { m_pLabelPromtp->SetText( NDCommonCString2(SZ_SETUP).c_str() ); m_pLabelPromtp->SetVisible( true ); } ShowWaitingAni(); NDLocalXmlString::GetSingleton(); ScriptMgrObj; pthread_t pid; pthread_create(&pid, NULL, CSMLoginScene::LoadTextAndLua, (void*)this); #endif CCLOG( "@@ CSMLoginScene::StartEntry() -- done.\r\n" ); }
void NDLocalXmlString::dump() { #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) WriteCon( "-------------- NDLocalXmlString -------------- \r\n" ); WriteCon( "@@ has %d key/val\r\n", m_kMapData.size()); for (ITER_MAP_DATA iter = m_kMapData.begin(); iter != m_kMapData.end(); ++iter) { WriteCon( "[%s]=%s\r\n", iter->first.c_str(), iter->second.c_str() ); } WriteCon( "\r\n" ); #endif }
bool StartStage_AutoPatch::sendRequestDownload() { WriteCon("Send Request For Download!\n"); return NDHttpManager::SendRequest("MachineInfo", "Set", 12345, "&item_id=1001"); }
void StartLoading::regLua() { //@reglua: 注册C++类到LUA { WriteCon( "@@ ScriptMgrObj.RegLua_Class()\r\n" ); TIME_SLICE("ScriptMgrObj.RegLua_Class()"); ScriptFramework::RegLua_Class(); ScriptMgrObj.RegLua_Class_Commit(); } //注册C++函数到LUA { WriteCon( "@@ ScriptMgrObj.RegLua_Func()\r\n" ); TIME_SLICE("ScriptMgrObj.RegLua_Func()"); ScriptMgr::RegLua_Func(); } }
int CMainApp::IoDllError(int iError) { CString str = ""; switch (iError) { case 0: break; case ERROR_HANDLE_INVALID: str = "Invalid handle."; break; case ERROR_READING_INI: str = "Error reading WIN.INI file."; break; case ERROR_NEW_FAILED: str = "Running low on memory."; break; case ERROR_FILE_OPEN: str = "Error opening file."; break; case ERROR_FILE_CREATE: str = "Error creating file."; break; case ERROR_FILE_INVALID_OFFSET: str = "File corruption detected."; break; case ERROR_FILE_READ: str = "Error reading file."; break; case ERROR_DLL_LOAD: str = "Error loading R/W DLL."; break; case ERROR_DLL_PROC_ADDRESS: str = "Error loading R/W procedure."; break; case ERROR_RW_LOADIMAGE: str = "Error loading R/W image."; break; case ERROR_RW_PARSEIMAGE: str = "Error parsing R/W image."; break; case ERROR_RW_NOTREADY: str = "Error: R/W not ready?"; break; case ERROR_RW_BUFFER_TOO_SMALL: str = "Running low on memory?"; break; case ERROR_RW_INVALID_FILE: str = "Invalid R/W file."; break; case ERROR_RW_IMAGE_TOO_BIG: str = "Can't load HUGE image."; break; case ERROR_RW_TOO_MANY_LEVELS: str = "Resource directory too deep."; break; case ERROR_RW_NO_RESOURCES: str = "This file contains no resources."; break; case ERROR_IO_INVALIDITEM: str = "Invalid resource item."; break; case ERROR_IO_INVALIDID: str = "Invalid resource ID."; break; case ERROR_IO_INVALID_DLL: str = "Unrecognized file format."; break; case ERROR_IO_TYPE_NOT_SUPPORTED: str = "Type not supported."; break; case ERROR_IO_INVALIDMODULE: str = "Invalid module."; break; case ERROR_IO_RESINFO_NULL: str = "ResInfo is NULL?"; break; case ERROR_IO_UPDATEIMAGE: str = "Error updating image."; break; case ERROR_IO_FILE_NOT_SUPPORTED: str = "File not supported."; break; case ERROR_RW_VXD_MSGPAGE: str = "The specified VxD file contains a message page as its"; str += " last page. This may cause the VxD not to work. Please"; str += " inform the development team of the problem with this file."; break; case ERROR_OUT_OF_DISKSPACE: str = "Out of disk space."; break; default: if(iError-LAST_ERROR>0) { FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, iError-LAST_ERROR, MAKELANGID(LANG_NEUTRAL,LANG_NEUTRAL), str.GetBuffer(1024), 1024, NULL); str.ReleaseBuffer(); } break; } if (!str.IsEmpty()) WriteCon(CONERR, "%s: %s\r\n", (iError < 0) ? "IODLL Warning" : "IODLL Error", str); return iError; }
bool StartLoading::loadInner() { // 加载Xml字符串 { WriteCon( "@@ NDLocalXmlString::LoadData()...\r\n" ); TIME_SLICE("NDLocalXmlString::LoadData()"); NDLocalXmlString::GetSingleton().LoadData(); } // 加载ini格式的字符串 GStr.load(); // 加载所有Lua脚本 { WriteCon( "@@ ScriptMgrObj.LoadEntryLua()\r\n" ); TIME_SLICE("ScriptMgrObj.LoadLua()"); ScriptMgr::LoadEntryLua(); } // 加载地图配置文件 NDTileMapConfigObj.load(); return true; }
//通知地图事件到Lua bool NDTileMapNotify::notifyMapEventToLua(TILEMAP_EVENT_TYPE eventType, int idMap, bool bWorldMap) { LuaObject* obj = getLuaObject(eventType); if (obj && obj->IsFunction()) { WriteCon( "notifyMapEventToLua(), eventType=%d, idMap=%d, bWorldMap=%d\r\n", int(eventType), idMap, (int) bWorldMap); LuaFunction<int> luaFunc(*obj); luaFunc(idMap, bWorldMap); return true; } return false; }
//============================================================================== //注册tileMap地图事件:【路径】点击事件 int RegTileMapCallBack(LuaState* pkLuaState) { WriteCon("[TileMapNotify] RegTileMapCallBack()\r\n"); NDTileMapNotify& kTarget = NDTileMapNotifyObj; LuaStack kArgs(pkLuaState); LuaObject kObjType = kArgs[1]; LuaObject kObjFunction = kArgs[2]; if (kObjType.IsString() && (kObjFunction.IsFunction() || kObjFunction.IsNil())) { const char* pszType = kObjType.GetString(); if (pszType && *pszType) { if (stricmp(pszType, "click_empty") == 0) { kTarget.m_kLuaClickEmpty = kObjFunction; } else if (stricmp(pszType, "click_obj") == 0) { kTarget.m_kLuaClickObj = kObjFunction; } else if (stricmp(pszType, "loadmap_begin") == 0) { kTarget.m_kLuaLoadMapBegin = kObjFunction; } else if (stricmp(pszType, "loadmap_end") == 0) { kTarget.m_kLuaLoadMapEnd = kObjFunction; } else if (stricmp(pszType, "player_jump_done") == 0) { kTarget.m_kLuaPlayerJumpDone = kObjFunction; } pkLuaState->PushBoolean(true); } } else { pkLuaState->PushBoolean(false); } return 1; }
void CMainApp::Help() { WriteCon(CONOUT, strHelp0); WriteCon(CONOUT, strHelp1); }
CMainApp::Error_Codes CMainApp::ParseCommandLine(int argc, char ** argv) { char * pArgument; int count = 0; if(argc==1) m_dwFlags |= HELP; while(++count<argc) { pArgument = argv[count]; if(*pArgument=='/' || *pArgument=='-') { while(*(++pArgument)) { switch(*pArgument) { case 'a': // Append resources case 'A': { //Make sure no other conflicting flags are specified if(IsFlag(REPLACE) | IsFlag(UPDATE) | IsFlag(EXTRACT)) { Banner(); WriteCon(CONERR, "Please use -a without the -r, -u or -t option!"); return ERR_COMMAND_LINE; } // Make sure none of the next item is another option for(int c=1; c<=4; c++) if(argv[count+c]==NULL || *argv[count+c]=='/' || *argv[count+c]=='-') { Banner(); WriteCon(CONERR, "Not enough parameters specified for the -a option\r\n"\ " -a InputExeFile InputUSTokFile InputLOCTokFile OutputExeFile\r\n"); return ERR_COMMAND_LINE; }; m_dwFlags |= APPEND; // Get the input EXE file name m_strInExe = argv[++count]; // Get the source token file name m_strSrcTok = argv[++count]; // Get the target token file name m_strTgtTok = argv[++count]; // Get the output EXE file name m_strOutExe = argv[++count]; } break; case 'b': case 'B': m_dwFlags |= BITMAPS; break; case 'd': case 'D': // Default for unmappable characters m_unmappedChar = argv[++count][0]; break; case 'f': case 'F': m_dwFlags |= FONTS; break; case 'i': // Input language/sublanguage case 'I': m_dwFlags |= INPUT_LANG; m_usIPriLangId = GetLangID(argv[++count]); m_usISubLangId = GetLangID(argv[++count]); break; case '?': // Help case 'h': case 'H': m_dwFlags |= HELP; break; case 'n': case 'N': m_dwFlags |= NOLOGO; break; case 'o': // Output language/sublanguage case 'O': m_dwFlags |= OUTPUT_LANG; m_usOPriLangId = GetLangID(argv[++count]); m_usOSubLangId = GetLangID(argv[++count]); break; case 'p': // Code page case 'P': m_uiCodePage = GetCodePage(argv[++count]); break; case 'r': // Replace resources case 'R': { //Make sure no other conflicting flags are specified if(IsFlag(APPEND) | IsFlag(EXTRACT) | IsFlag(UPDATE)) { Banner(); WriteCon(CONERR, "Please use -r without the -a, -u or -t option!"); return ERR_COMMAND_LINE; } // Make sure none of the next item is another option for(int c=1; c<=3; c++) if(argv[count+c]==NULL || *argv[count+c]=='/' || *argv[count+c]=='-') { Banner(); WriteCon(CONERR, "Not enough parameters specified for the -r option\r\n"\ " -r InputExeFile InputLOCTokFile OutputExeFile\r\n"); return ERR_COMMAND_LINE; }; m_dwFlags |= REPLACE; // Get the input EXE file name m_strInExe = argv[++count]; // Get the target token file name m_strTgtTok = argv[++count]; // Get the output EXE file name m_strOutExe = argv[++count]; } break; case 'u': // Update resources case 'U': { //Make sure no other conflicting flags are specified if(IsFlag(APPEND) | IsFlag(EXTRACT) | IsFlag(REPLACE)) { Banner(); WriteCon(CONERR, "Please use -u without the -a, -r or -t option!"); return ERR_COMMAND_LINE; } // Make sure none of the next item is another option for(int c=1; c<=4; c++) if(argv[count+c]==NULL || *argv[count+c]=='/' || *argv[count+c]=='-') { Banner(); WriteCon(CONERR, "Not enough parameters specified for the -u option\r\n"\ " -u InputExeFile InputUSTokFile InputLOCTokFile OutputExeFile\r\n"); return ERR_COMMAND_LINE; }; m_dwFlags |= UPDATE; // Get the input EXE file name m_strInExe = argv[++count]; // Get the source token file name m_strSrcTok = argv[++count]; // Get the target token file name m_strTgtTok = argv[++count]; // Get the output EXE file name m_strOutExe = argv[++count]; } break; case 's': case 'S': m_dwFlags |= SPLIT; break; case 't': // Create token file case 'T': { //Make sure no other conflicting flags are specified if(IsFlag(APPEND) | IsFlag(REPLACE) | IsFlag(UPDATE)) { Banner(); WriteCon(CONERR, "Please use -t without the -a, -u or -r option!"); return ERR_COMMAND_LINE; } // Make sure none of the next item is another option for(int c=1; c<=2; c++) if(argv[count+c]==NULL || *argv[count+c]=='/' || *argv[count+c]=='-') { Banner(); WriteCon(CONERR, "Not enough parameters specified for the -t option\r\n"\ " -t InputExeFile OutputTokenFile\r\n"); return ERR_COMMAND_LINE; }; m_dwFlags |= EXTRACT; // Get the input EXE file name m_strInExe = argv[++count]; // Get the target token file name m_strTgtTok = argv[++count]; } break; case 'w': // Display warnings case 'W': m_dwFlags |= WARNING; break; default: break; } } } } // Do we want the banner if(!IsFlag(NOLOGO)) Banner(); // Before exiting make sure we display the help screen if requested if(IsFlag(HELP)) { Help(); return ERR_HELP_CHOOSE; } // Check if the code page we have is installed in this system if(!IsValidCodePage(m_uiCodePage)) { // Warn the user and get back the default CP m_uiCodePage = GetACP(); WriteCon(CONERR, "The code page specified is not installed in the system or is invalid! Using system default!\r\n"); } // Make sure the input file is there CFileStatus fs; if(!m_strInExe.IsEmpty()) { if(!CFile::GetStatus(m_strInExe, fs)) { WriteCon(CONERR, "File not found: %s\r\n", m_strInExe); return ERR_FILE_NOTFOUND; } } // Check if the tgt token file or exe are read only if(!m_strOutExe.IsEmpty()) { if(CFile::GetStatus(m_strOutExe, fs)) { if((fs.m_attribute & 0x1)==0x1) { WriteCon(CONERR, "File is read only: %s\r\n", m_strOutExe); return ERR_FILE_CREATE; } } } if(!m_strTgtTok.IsEmpty() && IsFlag(EXTRACT)) { if(CFile::GetStatus(m_strTgtTok, fs)) { if((fs.m_attribute & 0x1)==0x1) { WriteCon(CONERR, "File is read only: %s\r\n", m_strTgtTok); return ERR_FILE_CREATE; } } } // // Check the value specified for the output language. // If none has been specified, warn the user and default to neutral. // if(IsFlag(APPEND) | IsFlag(REPLACE)) { if(m_usOPriLangId==-1) { m_usOPriLangId = LANG_NEUTRAL; // set the PRI language ID to neutral WriteCon(CONERR, "Output language ID not specified, default to neutral(%d)\r\n", m_usOPriLangId); } if(m_usOSubLangId==-1) { m_usOSubLangId = SUBLANG_NEUTRAL; // set the SEC language ID to neutral WriteCon(CONERR, "Output sub-language ID not specified, default to neutral(%d)\r\n", m_usOSubLangId); } } WriteCon(CONWRN, "Code Page : %d\r\n", m_uiCodePage); WriteCon(CONWRN, "In Primary Language : %d (%d)\r\n", m_usIPriLangId, MAKELANGID(m_usIPriLangId,m_usISubLangId)); WriteCon(CONWRN, "In Secondary Language : %d (0x%x)\r\n", m_usISubLangId, MAKELANGID(m_usIPriLangId,m_usISubLangId)); WriteCon(CONWRN, "Out Primary Language : %d (%d)\r\n", m_usOPriLangId, MAKELANGID(m_usOPriLangId,m_usOSubLangId)); WriteCon(CONWRN, "Out Secondary Language : %d (0x%x)\r\n", m_usOSubLangId, MAKELANGID(m_usOPriLangId,m_usOSubLangId)); WriteCon(CONWRN, "Default unmapped char : %c \r\n", m_unmappedChar); return ERR_NOERROR; }
void StartStage_AutoPatch::setDone() { WriteCon("Set done auto patch.\n"); m_pkStageUI->showDone(); StartStageBase::setDone(); }
bool StartStage_AutoPatch::processMessage(unsigned int uiMsgID, void* pParam) { WriteConWarning("Entry Proecess Message For C++\n"); switch (uiMsgID) { case MSG_DOWNLOAD_URL: { NDMsg_DownloadUrl* pkUrl = (NDMsg_DownloadUrl*) pParam; m_bRequestedDownload = true; if (pkUrl->getMsgID() != uiMsgID) { return false; } if (!pkUrl->getNeedDownload()) { setDone(); return true; } m_pkStageUI->showProgress(true); const StringVector& kVec = pkUrl->getUrlVector(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) char szExeFileName[500] = {0}; GetModuleFileNameA(0, szExeFileName, sizeof(szExeFileName)); string strCurrentDir = getPath(szExeFileName); SetCurrentDirectoryA(strCurrentDir.c_str()); strCurrentDir.erase(strCurrentDir.end() - 1); strCurrentDir = getUpFolder(strCurrentDir); #endif WriteConWarning("Will Download Patch From Server!\n"); for (unsigned int uiIndex = 0; uiIndex < kVec.size(); uiIndex++) { const string& strUrl = kVec[uiIndex]; if (0 == strUrl.size()) { continue; } int nPos = strUrl.find_last_of('/'); if (-1 == nPos) { continue; } string strFileName = strUrl.substr(nPos + 1, strUrl.length()); DownloadPackage* pkPackage = new DownloadPackage; pkPackage->FromUrl(strUrl.c_str()); string strPath = ""; char szTempPath[2048] = { 0 }; //SDCARD_GAME_NAME_SLASH #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) strPath = string(SDCARD_GAME_NAME_SLASH) + strFileName; #elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) strPath = strCurrentDir + strFileName; #endif WriteCon( "%d:%s will be download...Add to download task list.\n Save to %s...\n", uiIndex + 1, strUrl.c_str(), strPath.c_str()); pkPackage->ToPath(strPath.c_str()); pkPackage->setDownloadListener(this); m_kDownloadList.push_back(pkPackage); beginDownload(); } } break; default: return false; } return true; }
void StartStageBase::setDone() { WriteCon("Next from auto patch\n"); m_bIsDone = true; GStartStageMgr.nextStage(); }
void StartStageBase::__log( const string& str ) { WriteCon("[%s] %s\r\n", m_strStageName.c_str(), str.c_str()); }
/////////////////////////////////////////////////////////////////////////////// // This function will parse the source file and create the token file CMainApp::Error_Codes CMainApp::TokGen() { Error_Codes ReturnErr = ERR_NOERROR; WriteCon(CONERR, "%s\r\n", CalcTab("", 79, '-')); // Open the iodll.dll using the first file name HANDLE hModule = RSOpenModule(m_strInExe, NULL); if ((int)hModule < 100) { // error or warning WriteCon(CONERR, "%s", CalcTab(m_strInExe, m_strInExe.GetLength()+5, ' ')); IoDllError((int)hModule); return ERR_FILE_NOTSUPP; } else { // before we do anything else we have to check how many languages we have in the file CString strLang; char szLang[8]; BOOL b_multi_lang = FALSE; USHORT usInputLang = MAKELANGID(m_usIPriLangId, m_usISubLangId); if((b_multi_lang = RSLanguages(hModule, strLang.GetBuffer(128))) && !IsFlag(INPUT_LANG)) { // this is a multiple language file but we don't have an input language specified // Fail, but warn the user that he has to set the input language to continue. strLang.ReleaseBuffer(); WriteCon(CONERR, "Multiple language file. Please specify an input language %s.\r\n", strLang); goto exit; } // Convert the language in to the hex value sprintf(szLang,"0x%3.3X", usInputLang); // Check if the input language that we got is a valid one if(IsFlag(INPUT_LANG) && strLang.Find(szLang)==-1) { WriteCon(CONERR, "The language %s in not a valid language for this file.\r\n", szLang); WriteCon(CONERR, "Valid languages are: %s.\r\n", strLang); goto exit; } // Check if the user is extracting the neutral language if(!usInputLang) usInputLang = 0xFFFF; // Open the output file CStdioFile fileOut; if(!fileOut.Open(m_strTgtTok, CFile::modeCreate | CFile::modeReadWrite)) { WriteCon(CONERR, "Cannot create file: %s\r\n", CalcTab(m_strTgtTok, m_strTgtTok.GetLength()+5, ' ')); return ERR_FILE_CREATE; } CString strBmpDir = ""; CString strFileName = m_strInExe; int pos = m_strInExe.ReverseFind('\\'); if(pos!=-1) { strFileName = m_strInExe.Right(m_strInExe.GetLength()-pos-1); } else if((pos = m_strInExe.ReverseFind(':'))!=-1) { strFileName = m_strInExe.Right(m_strInExe.GetLength()-pos-1); } pos = m_strTgtTok.ReverseFind('\\'); if(pos!=-1) { strBmpDir = m_strTgtTok.Left(pos+1); } else if((pos = m_strTgtTok.ReverseFind(':'))!=-1) { strBmpDir = m_strTgtTok.Left(pos+1); } // inform the user ... WriteCon(CONOUT, "Processing\t"); WriteCon(CONBOTH, "%s", CalcTab(strFileName, strFileName.GetLength()+5, ' ')); LPCSTR lpszType = 0L; LPCSTR lpszRes = 0L; DWORD dwLang = 0L; DWORD dwItem = 0L; DWORD dwItemID = 0L; LPRESITEM lpResItem = NULL; CString strToken; CString strResName; CString strCaption; WORD wFlag; BOOL bSkip = FALSE; BOOL bSkipEmpty = FALSE; BOOL bSkipLang = FALSE; WORD wCount = 0; WORD wMsgCount = 0; int iPos = 1; int iBmpIdCount = 0; BOOL bVersionStampOnly = TRUE; while ((lpszType = RSEnumResType(hModule, lpszType))) { // Check if is one of the type we care about if(HIWORD(lpszType)==0) switch(LOWORD(lpszType)) { case 2: case 3: if(theApp.IsFlag(CMainApp::BITMAPS)) bSkip = FALSE; else bSkip = TRUE; break; case 4: case 5: case 6: case 9: case 10: case 11: bVersionStampOnly = FALSE; case 16: bSkip = FALSE; break; default: bSkip = TRUE; } lpszRes = 0L; dwLang = 0L; dwItem = 0L; while ((!bSkip) && (lpszRes = RSEnumResId(hModule, lpszType, lpszRes))) { while ((dwLang = RSEnumResLang(hModule, lpszType, lpszRes, dwLang))) { // Check if we have to skip this language if(b_multi_lang && (LOWORD(dwLang)!=usInputLang)) bSkipLang = TRUE; else bSkipLang = FALSE; while ((!bSkipLang) && (dwItem = RSEnumResItemId(hModule, lpszType, lpszRes, dwLang, dwItem))) { // Now Get the Data DWORD dwImageSize = RSGetResItemData( hModule, lpszType, lpszRes, dwLang, dwItem, m_pBuf, MAX_BUF_SIZE ); lpResItem = (LPRESITEM)m_pBuf; if((wCount++ % 50)==0) WriteCon(CONOUT, "."); // Check if we want or not empty strings switch(lpResItem->dwTypeID) { case 4: case 5: case 16: bSkipEmpty = TRUE; break; default: bSkipEmpty = FALSE; break; } // Version stamp use class name as res id if(lpResItem->lpszResID) strResName = lpResItem->lpszResID; else strResName = ""; dwItemID = lpResItem->dwItemID; // Add font info for dialogs if((theApp.IsFlag(CMainApp::FONTS) && (lpResItem->dwTypeID==5) && (dwItemID==0))) { // Add font information sprintf(strToken.GetBuffer(MAX_STR_SIZE), TEXT("[[%u|%u|%u|%u|%u|\"%s\"]]=%s:%hd\n"), lpResItem->dwTypeID, lpResItem->dwResID, dwItemID, ISDLGFONTNAME | ISDLGFONTSIZE, ST_TRANSLATED, strResName.GetBuffer(0), Format(lpResItem->lpszFaceName), lpResItem->wPointSize); fileOut.WriteString(strToken); } strCaption = lpResItem->lpszCaption; // Set the flag wFlag = 0; if(!(bSkipEmpty && strCaption.IsEmpty())) { switch(lpResItem->dwTypeID) { case 2: case 3: { // create the BMP name CString strBmpName; if(lpResItem->dwTypeID==2) if(lpResItem->dwResID) strBmpName = CreateName(strFileName, ".bmp", lpResItem->dwResID); else strBmpName = CreateName(strFileName, ".bmp", lpResItem->lpszResID); else if(lpResItem->dwResID) strBmpName = CreateName(strFileName, ".ico", lpResItem->dwResID); else strBmpName = CreateName(strFileName, ".ico", lpResItem->lpszResID); // Get the image from the file DWORD dwBufSize = RSGetResImage( hModule, lpszType, lpszRes, dwLang, NULL, 0 ); BYTE * pBuf = (BYTE*)(new BYTE[dwBufSize]); if(pBuf==NULL) { WriteCon(CONERR, "Warning: Failed to allocate buffer for image! (%d, %d, %s, Size: %d)\r\n", lpResItem->dwTypeID, lpResItem->dwResID, lpResItem->lpszResID, dwBufSize); break; } dwBufSize = RSGetResImage( hModule, lpszType, lpszRes, dwLang, pBuf, dwBufSize ); // write the data in to a file CFile BmpFile; if(!BmpFile.Open(strBmpDir+strBmpName, CFile::modeCreate | CFile::modeWrite)) { WriteCon(CONERR, "Cannot create file: %s\r\n", CalcTab(strBmpDir+strBmpName, strBmpName.GetLength()+strBmpDir.GetLength()+5, ' ')); delete pBuf; break; } switch(lpResItem->dwTypeID) { case 2: { BITMAPFILEHEADER bmpFileHeader; BITMAPINFO * pbmpInfo = (BITMAPINFO *)pBuf; DWORD dwNumColor = 0; if(pbmpInfo->bmiHeader.biBitCount!=24) dwNumColor = ( 1L << pbmpInfo->bmiHeader.biBitCount); bmpFileHeader.bfType = 0x4d42; bmpFileHeader.bfSize = (dwBufSize+sizeof(BITMAPFILEHEADER))/4; bmpFileHeader.bfReserved1 = 0; bmpFileHeader.bfReserved2 = 0; bmpFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + pbmpInfo->bmiHeader.biSize + dwNumColor*sizeof(RGBQUAD); BmpFile.Write(&bmpFileHeader, sizeof(BITMAPFILEHEADER)); } break; case 3: { ICONHEADER icoHeader; BITMAPINFOHEADER * pbmpInfoH = (BITMAPINFOHEADER*)pBuf; icoHeader.idReserved = 0; icoHeader.idType = 1; icoHeader.idCount = 1; icoHeader.bWidth = LOBYTE(pbmpInfoH->biWidth); icoHeader.bHeight = LOBYTE(pbmpInfoH->biWidth); icoHeader.bColorCount = 16; icoHeader.bReserved = 0; icoHeader.wPlanes = 0; icoHeader.wBitCount = 0; icoHeader.dwBytesInRes = dwBufSize; icoHeader.dwImageOffset = sizeof(ICONHEADER); BmpFile.Write(&icoHeader, sizeof(ICONHEADER)); } break; default: break; } BmpFile.Write(pBuf, dwBufSize); BmpFile.Close(); delete pBuf; strCaption = strBmpName; } break; case 4: if(lpResItem->dwFlags & MF_POPUP) { wFlag = ISPOPUP; // check if this popup has a valid ID if (LOWORD(dwItemID)==0xffff) wFlag |= OLD_POPUP_ID; dwItemID = (LOWORD(dwItemID)==0xffff ? HIWORD(dwItemID) : dwItemID); } break; case 5: if(dwItemID==0) { wFlag = ISCAP; } // check if this is a duplicated id if (LOWORD(dwItemID)==0xffff) wFlag |= ISDUP; dwItemID = (LOWORD(dwItemID)==0xffff ? HIWORD(dwItemID) : dwItemID); break; case 9: { CAccel accel(lpResItem->dwFlags, lpResItem->dwStyle); strCaption = accel.GetText(); // check if this is a duplicated ID if(HIWORD(dwItemID)) { wFlag |= ISDUP; } } break; case 11: dwItemID = LOWORD(dwItemID); break; case 16: strResName = lpResItem->lpszClassName; break; default: break; } // Create the token file if(lpResItem->dwTypeID==11 && theApp.IsFlag(CMainApp::SPLIT)) { // Search for the \r\n and replace them while((iPos = strCaption.Find("\r\n"))!=-1) { sprintf(strToken.GetBuffer(MAX_STR_SIZE), TEXT("[[%u|%u|%u|%u|%u|\"%s\"]]=%s\\r\\n\n"), lpResItem->dwTypeID, lpResItem->dwResID, dwItemID, wFlag | wMsgCount++, ST_TRANSLATED, strResName.GetBuffer(0), Format(strCaption.Left(iPos))); strCaption = strCaption.Right(strCaption.GetLength()-2-iPos); fileOut.WriteString(strToken); } wMsgCount = 0; } else { sprintf(strToken.GetBuffer(MAX_STR_SIZE), TEXT("[[%u|%u|%u|%u|%u|\"%s\"]]=%s\n"), lpResItem->dwTypeID, lpResItem->dwResID, dwItemID, /*(LOWORD(dwItemID)==0xffff ? HIWORD(dwItemID) : dwItemID),*/ wFlag, ST_TRANSLATED, strResName.GetBuffer(0), Format(strCaption)); fileOut.WriteString(strToken); } // If this is a dialog box add the coordinates if(lpResItem->dwTypeID==5) { sprintf(strToken.GetBuffer(MAX_STR_SIZE), TEXT("[[%u|%u|%u|%u|%u|\"%s\"]]=%hu %hu %hu %hu\n"), lpResItem->dwTypeID, lpResItem->dwResID, (LOWORD(dwItemID)==0xffff ? HIWORD(dwItemID) : dwItemID), wFlag | ISCOR, ST_TRANSLATED, strResName.GetBuffer(0), lpResItem->wX, lpResItem->wY, lpResItem->wcX, lpResItem->wcY); fileOut.WriteString(strToken); } } else { // If this is a dialog box add the coordinates if(lpResItem->dwTypeID==5) { sprintf(strToken.GetBuffer(MAX_STR_SIZE), TEXT("[[%u|%u|%u|%u|%u|\"%s\"]]=%hu %hu %hu %hu\n"), lpResItem->dwTypeID, lpResItem->dwResID, (LOWORD(dwItemID)==0xffff ? HIWORD(dwItemID) : dwItemID), wFlag | ISCOR, ST_TRANSLATED, strResName.GetBuffer(0), lpResItem->wX, lpResItem->wY, lpResItem->wcX, lpResItem->wcY); fileOut.WriteString(strToken); } } } // end while } } } fileOut.Close(); // Check the size of the new file and remove it if empty... CFileStatus fstat; if(CFile::GetStatus(m_strTgtTok, fstat)) if(fstat.m_size==0) CFile::Remove(m_strTgtTok); WriteCon(CONBOTH, " %hu Items\r\n", wCount); if(bVersionStampOnly) { ReturnErr = ERR_FILE_VERSTAMPONLY; WriteCon(CONWRN, "%s : Version Stamping only!\r\n", strFileName); } } exit: RSCloseModule(hModule); return ReturnErr; }
void* StartStage_AutoPatch::unzipPatchThread(void* ptr) { StartStage_AutoPatch* pkThisObj = static_cast<StartStage_AutoPatch*>(ptr); LOGD("[StartStage_AutoPatch] CopyResThread()"); HZIP pZipHandle = 0; //设置zip工作路径 //直接从文件打开zip包 pthread_mutex_lock (&ms_kStringMutex); const string& strZipFile_1 = pkThisObj->getCurrentUnzipFile(); pthread_mutex_unlock(&ms_kStringMutex); struct timespec kDelay = {0}; kDelay.tv_sec = 2; kDelay.tv_nsec = 0; //pthread_delay_np(&kDelay); pZipHandle = OpenZip(strZipFile_1.c_str(), 0); if (!pZipHandle) { WriteConErr("Can't find zip file!\n"); return 0; } //确保zip包会被关闭 struct ZipGuard { ZipGuard() { } ZipGuard(HZIP in_handle) : handle(in_handle) { } ~ZipGuard() { CloseZip(handle); } HZIP handle; } zip_guard(pZipHandle); //查询zip包条目 ZIPENTRY kZipEntry = { 0 }; if (ZR_OK != GetZipItem(pZipHandle, -1, &kZipEntry)) { pkThisObj->__logErr("GetZipItem() to query entry count failed\r\n"); return 0; } char szInfo[200] = ""; int nMaxIndex = kZipEntry.index; sprintf(szInfo, "zip has %d items\r\n", kZipEntry.index); pkThisObj->__log(szInfo); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) string strDestPath = SDCARD_GAME_NAME_SLASH; #elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) string strDestPath = "../"; #endif //逐个解压 int nUnzipCount = 0; for (int nZipIndex = 0; nZipIndex < nMaxIndex; nZipIndex++) { ZIPENTRY kTempZipEntry = { 0 }; GetZipItem(pZipHandle, nZipIndex, &kTempZipEntry); string strDestFileName = strDestPath + string(kTempZipEntry.name); //解压 if (ZR_OK != UnzipItem(pZipHandle, nZipIndex, strDestFileName.c_str())) { char szInfo[500] = ""; sprintf(szInfo, "UnzipItem failed: %s -> %s\r\n", kTempZipEntry.name, strDestFileName.c_str()); WriteConErr(szInfo); CloseZip(pZipHandle); } } CloseZip(pZipHandle); remove(strZipFile_1.c_str()); WriteCon("Unzip %s succeeded!\n", strZipFile_1.c_str()); pkThisObj->beginDownload(); return 0; }