www.pudn.com > notWow.rar > ResLoader.cpp
#include "ResLoader.h" #includevoid* ResLoader::GetFile(const wchar_t* szFile,int &Size,RESOURCE Type) { char mbFile[128]; wcstombs(mbFile,szFile,128); return GetFile(mbFile,Size,Type); } void* ResLoader::GetFile(const char* szFile,int &Size,RESOURCE Type) { char* pFile; FILE* fpRead; char szTempFile[128]; strcpy(szTempFile,m_szPath); strcat(szTempFile,szFile); fpRead = fopen(szTempFile,"rb"); if(fpRead == NULL) { FILE *fp = fopen("Err.txt","w+"); fprintf(fp,"%s:cannot open\n",szFile); fclose(fp); return NULL; } fseek(fpRead,0,SEEK_END); Size = ftell(fpRead); fseek(fpRead,0,SEEK_SET); pFile = new char [Size]; fread(pFile,Size,1,fpRead); fclose(fpRead); return pFile; } void* ResLoader::GetModelFile(ObjectID id,int &Size) { map ::iterator Itr; Size = 0; Itr = m_ObjectMap.find(id); if(Itr == m_ObjectMap.end()) return NULL; string str = Itr->second.Name; str += Itr->second.Format; return GetFile(str.c_str(),Size,RES_MODEL); } string ResLoader::GetObjectName(ObjectID id) { map ::iterator Itr; string str = ""; Itr = m_ObjectMap.find(id); if(Itr == m_ObjectMap.end()) return str; str = Itr->second.Name; return str; } string ResLoader::GetObjectName(ObjectID id,MODELTYPE &Type,bool &M2File) { map ::iterator Itr; string str = ""; Type = MODEL_ERROR; Itr = m_ObjectMap.find(id); if(Itr == m_ObjectMap.end()) return str; str = Itr->second.Name; Type = (MODELTYPE)Itr->second.Type; M2File = (Itr->second.Format == ".m2"); return str; }