HRESULT KG3DTerrainRoadMgr::LoadByHandle(UINT uHandle,KG3DTerrainRoad** ppOutRoad) { KG3DTerrainRoad* pRoad = NULL; pRoad = static_cast<KG3DTerrainRoad*>(GetSerpentineByHandle(uHandle)); if(pRoad) { *ppOutRoad = pRoad; return S_OK; } map<UINT,std::string>::iterator iFind = m_mapNames.find(uHandle); if(iFind == m_mapNames.end()) return E_FAIL; std::string strRoadName = iFind->second; CHAR szFileName[MAX_PATH]; wsprintf(szFileName,"%s%s.Road",m_strFilePath.c_str(),strRoadName.c_str()); if(!g_IsFileExist(szFileName)) return E_FAIL; pRoad = new KG3DTerrainRoad; if(FAILED(pRoad->LoadFromFile(szFileName))) { SAFE_RELEASE(pRoad); return E_FAIL; } m_listSerpentines.push_back(pRoad); pRoad->m_uHandle = uHandle; *ppOutRoad = pRoad; return S_OK; }
void KGSFXModelViewPage::OnNMDblclkTree(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR); HTREEITEM hTreeItem = m_tree.GetSelectedItem(); CString strPath = TEXT(""); KG_PROCESS_ERROR(hTreeItem); while (hTreeItem) { strPath = TEXT("\\") + m_tree.GetItemText(hTreeItem) + strPath; hTreeItem = m_tree.GetParentItem(hTreeItem); } m_strSelPath = m_strStartPath + strPath; char* fileName = m_strSelPath.GetBuffer(); if (g_IsFileExist(fileName)) { char fullPath[MAX_PATH]; g_GetFullPath(fullPath, fileName); AfxGetApp()->OpenDocumentFile(fullPath); } m_strSelPath.ReleaseBuffer(); Exit0: *pResult = 0; }
void KG3DFontTexture::LoadAlphaAdjustTable(LPCSTR szFontName, INT nFontSize) { BOOL bAdjust = FALSE; char szFileName[MAX_PATH]; LPSTR szSep = NULL; int nLen = _countof(szFileName) - 16; strncpy(szFileName, szFontName, nLen); szFileName[nLen - 1] = '\0'; szSep = strrchr(szFileName, '.'); if (szSep) { sprintf(szSep, "%d.prf", nFontSize); if (g_IsFileExist(szFileName)) { IFile* pFile = g_OpenFile(szFileName); if (pFile) { unsigned int nCount = pFile->Read(m_uchAdjustBuffer, sizeof(m_uchAdjustBuffer)); if (nCount == sizeof(m_uchAdjustBuffer)) bAdjust = TRUE; KG_COM_RELEASE(pFile); } } } if (!bAdjust) { for (size_t nIndex = 0; nIndex < _countof(m_uchAdjustBuffer); ++nIndex) { m_uchAdjustBuffer[nIndex] = (UCHAR)nIndex; } } }
DWORD KRLSceneMgr::GetRegionDataByMapID(DWORD dwMapID, D3DXVECTOR3 vPosition) { int nRetCode = false; HRESULT hr = E_FAIL; DWORD dwData = 0; IKG3DRegionInfoManager* p3DRegionInfoMgr = NULL; K3DRegionMgrMap::iterator it; IKGSO3WorldClient* pSO3WorldClient = NULL; pSO3WorldClient = g_pRL->m_pSO3WorldClient; KGLOG_PROCESS_ERROR(pSO3WorldClient); it = m_a3DRegionMgr.find(dwMapID); if (it == m_a3DRegionMgr.end()) { TCHAR szFilePath[MAX_PATH]; KMapParams* pParams = NULL; size_t nFilePathLength = 0; LPTSTR pszLastPoint = NULL; pParams = pSO3WorldClient->GetMapParams(dwMapID); KGLOG_PROCESS_ERROR(pParams); _tcscpy(szFilePath, pParams->szResourceFilePath); pszLastPoint = _tcsrchr(szFilePath, '.'); if (pszLastPoint) { *pszLastPoint = _T('\0'); _tcscat_s(szFilePath, _T("RegionInfo\\RLSplit.bmp")); if (g_IsFileExist(szFilePath)) { if (g_pRL->m_p3DEngineManager) { g_pRL->m_p3DEngineManager->GetRegionInfoManager(szFilePath, 0, 0, &p3DRegionInfoMgr); } } m_a3DRegionMgr.insert(std::make_pair(dwMapID, p3DRegionInfoMgr)); } } else { p3DRegionInfoMgr = it->second; } if (p3DRegionInfoMgr) { hr = p3DRegionInfoMgr->GetRegionInfoData(vPosition, &dwData); KGLOG_COM_PROCESS_ERROR(hr); } return dwData; Exit0: return 0; }
//--------------------------------------------------------------------------- // 功能: 打开一个文件,准备读取写 // 参数: FileName 文件名 // 返回: 成功返回TRUE,失败返回FALSE。 //--------------------------------------------------------------------------- QAloneFile* QAloneFile::Open(const char* FileName, int WriteSupport /*= false*/) { FILE* pFile = NULL; char PathName[MAX_PATH]; g_GetFullPath(PathName, FileName); #ifdef unix { char *ptr = PathName; while(*ptr) { if (*ptr == '\\') *ptr = '/'; ptr++; } } #endif // #ifdef unix const char* pMode = "rb"; if (WriteSupport) { if (g_IsFileExist(PathName)) pMode = "r+b"; else pMode = "a+b"; } pFile = fopen(PathName, pMode); #ifdef unix { if (pFile == NULL) { QStrLower(PathName); pFile = fopen(PathName, pMode); } } #endif // #ifdef unix if (pFile) { QAloneFile* pAloneFile = new QAloneFile(pFile); if (pAloneFile && WriteSupport) pAloneFile->m_nContentBufferSize = -1; return pAloneFile; } else { return NULL; } }
int IsBipFileExist(const char cszBipName[]) { int nResult = false; int nRetCode = false; ASSERT(cszBipName); nRetCode = g_IsFileExist(cszBipName); KG_PROCESS_ERROR(nRetCode); nResult = true; Exit0: if (!nResult) { KGLogPrintf(KGLOG_INFO, "can't find bip file!! \"%s\"", cszBipName); } return nResult; }
int TestLoadAllBSP() { int nResult = false; int nRetCode = false; HRESULT hrRetCode = E_FAIL; unsigned uTotalCount = 0; unsigned uFailedCount = 0; unsigned uFailedCountSave = 0; BYTE *pbyTestFileData = NULL; BYTE *pbySourceFileData = NULL; IIniFile *pFile = NULL; IFile *piTestFile = NULL; IKG3DModel *piModel = NULL; IKG3DResourceManager *piModelTable = NULL; char szMessage[MAX_PATH] = ""; char szDirPath[MAX_PATH] = ""; TCHAR strBSPPathName[MAX_PATH] = ""; //vector<string> vecModelList; //vector<string> vecMeshList; MSG msg; nRetCode = GetCurrentDirectory(MAX_PATH, szDirPath); KG_PROCESS_ERROR(nRetCode > 0 && nRetCode < MAX_PATH + 1); strcat(szDirPath, "\\data\\source\\*.*"); szDirPath[MAX_PATH - 1] = '\0'; //strcpy(szDirPath, "D:\\Kingsoft\\Game\\sword3-products\\trunk\\client\\data\\source\\NPC_source\\*.*"); piModelTable = g_cEngineManager.Get3DModelTable(); KGLOG_PROCESS_ERROR(piModelTable); pFile = g_OpenIniFile(g_cszErrorFileName[EXT_MESH],false,true); KGLOG_PROCESS_ERROR(pFile); nRetCode = GetFileList(szDirPath, &g_vecSourceList/*vecMeshList*/, EXT_MESH); KGLOG_PROCESS_ERROR(nRetCode); //g_vecSourceList.push_back("D:\\Kingsoft\\Game\\trunk\\data\\source\\maps_source\\亭塔\\T_erg风车塔001A.Mesh"); uTotalCount = (unsigned)/*vecMeshList*/g_vecSourceList.size(); for (unsigned i = 0; i < uTotalCount; ++i) { char szKeyName[32] = ""; snprintf( szMessage, sizeof(szMessage), "Mesh模型的BSP文件检查:%s", /*vecMeshList*/g_vecSourceList[i].c_str() ); szMessage[sizeof(szMessage) - 1] = '\0'; SetWindowText(g_hWnd, szMessage); TCHAR strDriver[MAX_PATH]; TCHAR strPath[MAX_PATH]; TCHAR strFile[MAX_PATH]; _splitpath_s(g_vecSourceList[i].c_str(), strDriver, MAX_PATH, strPath, MAX_PATH, strFile, MAX_PATH, NULL, 0); //sprintf_s(strBSPPathName, // MAX_PATH, // "%s%s%s.bsp", // strDriver, // strPath, // strFile); //nRetCode = g_IsFileExist(strBSPPathName); //if (!nRetCode) //{ // /*itoa(uFailedCount, szKeyName, 10); // pFile->WriteString("BSP_NotExited",szKeyName, g_vecSourceList[i].c_str()); // ++uFailedCount;*/ // continue; //} try { g_bForceGenerateBspForMesh = /*FALSE*/TRUE; hrRetCode = piModelTable->LoadResourceFromFile(/*vecMeshList*/g_vecSourceList[i].c_str(), 0, 0, (IKG3DResourceBase**)&piModel); if (FAILED(hrRetCode)) { itoa(uFailedCount, szKeyName, 10); pFile->WriteString("ErrorMesh",szKeyName, /*vecMeshList*/g_vecSourceList[i].c_str()); ++uFailedCount; } KG_COM_RELEASE(piModel); g_cEngineManager.FrameMove(); g_bForceGenerateBspForMesh = FALSE; if (FAILED(hrRetCode)) { continue; } //cmp unsigned uTestFileDataSize = 0; unsigned uSourceFileDataSize = 0; unsigned uSizeRead = 0; sprintf_s(strBSPPathName, MAX_PATH, "%s%s%s.bsp", strDriver, strPath, strFile); nRetCode = g_IsFileExist(strBSPPathName); if (!nRetCode) { sprintf_s(strBSPPathName, MAX_PATH, "%s%s%s_test.bsp", strDriver, strPath, strFile); nRetCode = g_IsFileExist(strBSPPathName); if (nRetCode) { itoa(uFailedCount, szKeyName, 10); pFile->WriteString("BSP_NotGenerate",szKeyName, g_vecSourceList[i].c_str()); ++uFailedCount; DeleteFile(strBSPPathName); } continue; } piTestFile = g_OpenFile(strBSPPathName); KGLOG_PROCESS_ERROR(piTestFile); uSourceFileDataSize = piTestFile->Size(); KGLOG_PROCESS_ERROR(uSourceFileDataSize > sizeof(DWORD)); pbySourceFileData = new BYTE[uSourceFileDataSize]; KGLOG_PROCESS_ERROR(pbySourceFileData); uSizeRead = piTestFile->Read(pbySourceFileData, uSourceFileDataSize); KGLOG_PROCESS_ERROR(uSizeRead == uSourceFileDataSize); KG_COM_RELEASE(piTestFile); sprintf_s(strBSPPathName, MAX_PATH, "%s%s%s_test.bsp", strDriver, strPath, strFile); piTestFile = g_OpenFile(strBSPPathName); if (!piTestFile) { itoa(uFailedCount, szKeyName, 10); pFile->WriteString("BSP_Don't Exited",szKeyName, g_vecSourceList[i].c_str()); ++uFailedCount; SAFE_DELETE_ARRAY(pbySourceFileData); continue; } uTestFileDataSize = piTestFile->Size(); KGLOG_PROCESS_ERROR(uTestFileDataSize > sizeof(DWORD)); pbyTestFileData = new BYTE[uTestFileDataSize]; KGLOG_PROCESS_ERROR(pbyTestFileData); uSizeRead = piTestFile->Read(pbyTestFileData, uTestFileDataSize); KGLOG_PROCESS_ERROR(uSizeRead == uTestFileDataSize); KG_COM_RELEASE(piTestFile); if (uTestFileDataSize != uSourceFileDataSize) { itoa(uFailedCount, szKeyName, 10); pFile->WriteString("BSP_NotMatchedSize",szKeyName, g_vecSourceList[i].c_str()); ++uFailedCount; DeleteFile(strBSPPathName); SAFE_DELETE_ARRAY(pbyTestFileData); SAFE_DELETE_ARRAY(pbySourceFileData); continue; } nRetCode = memcmp(pbyTestFileData, pbySourceFileData, uSourceFileDataSize); if (nRetCode) { itoa(uFailedCount, szKeyName, 10); pFile->WriteString("BSP_NotMatched",szKeyName, g_vecSourceList[i].c_str()); ++uFailedCount; DeleteFile(strBSPPathName); SAFE_DELETE_ARRAY(pbyTestFileData); SAFE_DELETE_ARRAY(pbySourceFileData); continue; } DeleteFile(strBSPPathName); SAFE_DELETE_ARRAY(pbyTestFileData); SAFE_DELETE_ARRAY(pbySourceFileData); } catch (...) { itoa(uFailedCount, szKeyName, 10); pFile->WriteString("Mesh_Exception",szKeyName, /*vecMeshList*/g_vecSourceList[i].c_str()); ++uFailedCount; } while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { switch (msg.message) { case WM_QUIT: break; default: TranslateMessage(&msg); DispatchMessage(&msg); } } if (msg.message == WM_QUIT) break; } //uFailedCount += uFailedCountSave; //uTotalCount = (unsigned)(vecModelList.size() + vecMeshList.size()); // snprintf( // szMessage, sizeof(szMessage), // "模型加载检查完成:共检查模型 %u 个 已发现错误 %u 个,请检查文件%s", // uTotalCount, uFailedCount, g_cszErrorFileName[TYPE_MDL] //); //szMessage[sizeof(szMessage) - 1] = '\0'; //::MessageBox(g_hWnd, szMessage, "检查报告", MB_OK); nResult = true; Exit0: if (pFile) { pFile->WriteInteger("ErrorMesh", "ErrorNum", uFailedCount); pFile->Save(g_cszErrorFileName[EXT_MESH]); } SAFE_DELETE_ARRAY(pbyTestFileData); SAFE_DELETE_ARRAY(pbySourceFileData); if (strstr(strBSPPathName, "_test.bsp")) { DeleteFile(strBSPPathName); } KG_COM_RELEASE(piModel); KG_COM_RELEASE(pFile); KG_COM_RELEASE(piTestFile); g_bForceGenerateBspForMesh = FALSE; g_vecSourceList.clear(); return nResult; }
//创建/打开的一个打包文件,返回打包文件索引,返回0值表示操作失败。 int KPackFileManager::CreatePack(const char* pszFile, int bOpenExist, int bExcludeOfCheckId) { int nPakIndex; for (nPakIndex = 0; nPakIndex < PACK_FILE_SHELL_MAX_SUPPORT_PAK_NUM; nPakIndex++) { if (m_PackItemList[nPakIndex].pIOFile == NULL) break; } if (nPakIndex == PACK_FILE_SHELL_MAX_SUPPORT_PAK_NUM) return -1; PACK_ITEM& item = m_PackItemList[nPakIndex]; bool bOk = false; g_GetFullPath(item.PackFileName, pszFile); while(true) { item.pIndexList = (XPackIndexInfo*)malloc(sizeof(XPackIndexInfo) * PACK_FILE_SHELL_MAX_SUPPORT_ELEM_FILE_NUM); if (item.pIndexList == NULL) break; memset(item.pIndexList, 0, sizeof(XPackIndexInfo) * PACK_FILE_SHELL_MAX_SUPPORT_ELEM_FILE_NUM); if (bOpenExist) { if (!g_IsFileExist(pszFile)) //FilePath.cpp:426 --> pszFile = 路径名+文件名 break; item.pIOFile = g_OpenFile(pszFile, true, true); if (item.pIOFile == NULL) break; if (item.pIOFile->Read(&item.Header, sizeof(item.Header)) != sizeof(item.Header) || (*(int*)(&(item.Header.cSignature)) != IPACK_FILE_SIGNATURE_FLAG)) { break; } item.pIOFile->Seek(item.Header.uIndexTableOffset, SEEK_SET); if (item.pIOFile->Read(item.pIndexList, sizeof(XPackIndexInfo) * item.Header.uCount) != sizeof(XPackIndexInfo) * item.Header.uCount)//读入文件尾部,插入新的文件数据之后再插回来 break; item.nDataEndOffset = item.Header.uIndexTableOffset; item.pIOFile->Seek(item.nDataEndOffset, SEEK_SET); LoadPackPartner(nPakIndex); } else { item.pIOFile = g_CreateFile(pszFile); if (item.pIOFile == NULL) break; memset(&item.Header, 0, sizeof(item.Header)); *(int*)(&(item.Header.cSignature)) = IPACK_FILE_SIGNATURE_FLAG; /* 前提条件为:Little-Endian */ if (item.pIOFile->Write(&item.Header, sizeof(item.Header)) != sizeof(item.Header)) break; item.Header.uDataOffset = sizeof(item.Header); item.nDataEndOffset = sizeof(item.Header); item.bModified = true; CreatePackPartner(nPakIndex); } item.bExcludeOfCheckId = (bExcludeOfCheckId != false); bOk = true; break; } if (!bOk) { SAFE_FREE(item.pIndexList); SAFE_RELEASE(item.pIOFile); item.PackFileName[0] = 0; return -1; } return nPakIndex; }