// For reading the face-data chunk static bool ReadFaceData(OpenedFile& OFile, int32 ParentChunkEnd) { uint8 NFBuffer[2]; uint16 NumFaces; if (!OFile.Read(2,NFBuffer)) { logError1("ERROR reading number of faces in %s",Path); return false; } uint8 *S = NFBuffer; StreamToValue(S,NumFaces); int32 DataSize = 4*sizeof(uint16)*int(NumFaces); SetChunkBufferSize(DataSize); if (!OFile.Read(DataSize,ChunkBufferBase())) { logError1("ERROR reading face-chunk contents in %s",Path); return false; } S = ChunkBufferBase(); ModelPtr->VertIndices.resize(3*NumFaces); for (int k=0; k<NumFaces; k++) { uint16 *CurrPoly = ModelPtr->VIBase() + 3*k; uint16 Flags; StreamToList(S,CurrPoly,3); StreamToValue(S,Flags); } int32 Location = 0; OFile.GetPosition(Location); while(Location < ParentChunkEnd) { ChunkHeaderData ChunkHeader; if (!ReadChunkHeader(OFile,ChunkHeader)) return false; switch(ChunkHeader.ID) { /* case OBJECT: if (!ReadContainer(OFile,ChunkHeader,ReadObject)) return false; break; */ default: if (!SkipChunk(OFile,ChunkHeader)) return false; } // Where are we now? OFile.GetPosition(Location); } if (Location > ParentChunkEnd) { logError3("ERROR: Overran parent chunk: %d > %d in %s",Location,ParentChunkEnd,Path); return false; } return true; }
bool PluginLoader::ParsePlugin(FileSpecifier& file_name) { OpenedFile file; if (file_name.Open(file)) { int32 data_size; file.GetLength(data_size); m_data.resize(data_size); if (file.Read(data_size, &m_data[0])) { file_name.ToDirectory(current_plugin_directory); char name[256]; current_plugin_directory.GetName(name); m_name = name; if (!DoParse()) { logError1("There were parsing errors in %s Plugin.xml\n", m_name.c_str()); } } m_data.clear(); return true; } return false; }
BOOL fileSaveEx(PSTR szName,...) { FILE *fp; PSTR pData; DWORD dwData; va_list vp; __API_ENTER("fileSaveEx",BOOL,FALSE); va_start(vp,szName); if (NULL == (fp=fopen(szName,"wb"))){ #ifdef _DEBUG logError1("!fopen(%s)",szName); #endif //_DEBUG __API_FINISH(); } for(;;){ if (NULL == (pData=va_arg(vp,PSTR))) break; dwData = va_arg(vp,DWORD); if (-1 == dwData) dwData = strlen(pData); fwrite(pData,dwData,1,fp); } fclose(fp); retCode = TRUE; __API_END_POINT: va_end(vp); __API_LEAVE("fileSaveEx"); }
BOOL fileDeleteDirectory(PSTR szPath) { char szName[_MAX_PATH]; HANDLE hFind; WIN32_FIND_DATA nData; fileAdjustPathSplit(szPath); PathAddBackslash(szPath); strcpyV(szName,sizeof(szName),"%s*.*",szPath); if (INVALID_HANDLE_VALUE == (hFind=FindFirstFile(szName,&nData))){ #ifdef _DEBUG logError1("!FindFirstFile(%s)",szName); #endif //_DEBUG return FALSE; } for(;;){ if (0 == strcmp(nData.cFileName,".")) goto NEXT_SEARCH; if (0 == strcmp(nData.cFileName,"..")) goto NEXT_SEARCH; strcpyV(szName,sizeof(szName),"%s%s",szPath,nData.cFileName); if (FLAGON(nData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY)){ if (!fileDeleteDirectory(szName)) return FALSE; if (!RemoveDirectory(szName)){ #ifdef _DEBUG logError1("!RemoveDirectory(%s)",szPath); #endif //_DEBUG return FALSE; } } else{ if (!DeleteFile(szName)){ #ifdef _DEBUG logError1("!DeleteFile(%s)",szName); #endif //_DEBUG return FALSE; } } NEXT_SEARCH: if (!FindNextFile(hFind,&nData)) break; } FindClose(hFind); return TRUE; }
bool LoadChunk(OpenedFile& OFile, ChunkHeaderData& ChunkHeader) { logTrace2("Loading chunk 0x%04hx size %u",ChunkHeader.ID,ChunkHeader.Size); int32 DataSize = ChunkHeader.Size - SIZEOF_ChunkHeaderData; SetChunkBufferSize(DataSize); if (!OFile.Read(DataSize,ChunkBufferBase())) { logError1("ERROR reading chunk contents in %s",Path); return false; } return true; }
bool ReadChunkHeader(OpenedFile& OFile, ChunkHeaderData& ChunkHeader) { uint8 Buffer[SIZEOF_ChunkHeaderData]; if (!OFile.Read(SIZEOF_ChunkHeaderData,Buffer)) { logError1("ERROR reading chunk header in %s",Path); return false; } uint8 *S = Buffer; StreamToValue(S,ChunkHeader.ID); StreamToValue(S,ChunkHeader.Size); return true; }
bool LoadModel_Studio(FileSpecifier& Spec, Model3D& Model) { ModelPtr = &Model; Model.Clear(); Path = Spec.GetPath(); logNote1("Loading 3D Studio Max model file %s",Path); OpenedFile OFile; if (!Spec.Open(OFile)) { logError1("ERROR opening %s",Path); return false; } ChunkHeaderData ChunkHeader; if (!ReadChunkHeader(OFile,ChunkHeader)) return false; if (ChunkHeader.ID != MASTER) { logError1("ERROR: not a 3DS Max model file: %s",Path); return false; } if (!ReadContainer(OFile,ChunkHeader,ReadMaster)) return false; if (Model.Positions.empty()) { logError1("ERROR: no vertices found in %s",Path); return false; } if (Model.VertIndices.empty()) { logError1("ERROR: no faces found in %s",Path); return false; } return true; }
BOOL fileSave(PSTR szName,PVOID pData,DWORD dwData) { FILE *fp; if (NULL == (fp=fopen(szName,"wb"))){ #ifdef _DEBUG logError1("!fopen(%s)",szName); #endif //_DEBUG return FALSE; } if (-1 == dwData) dwData = strlen(pData); fwrite(pData,dwData,1,fp); fclose(fp); return TRUE; }
// For reading the object-data chunk static bool ReadObject(OpenedFile& OFile, int32 ParentChunkEnd) { // Read the name char c; do { if (!OFile.Read(1,&c)) { logError1("ERROR when reading name in %s",Path); return false; } } while(c != 0); int32 Location = 0; OFile.GetPosition(Location); while(Location < ParentChunkEnd) { ChunkHeaderData ChunkHeader; if (!ReadChunkHeader(OFile,ChunkHeader)) return false; switch(ChunkHeader.ID) { case TRIMESH: if (!ReadContainer(OFile,ChunkHeader,ReadTrimesh)) return false; break; default: if (!SkipChunk(OFile,ChunkHeader)) return false; } // Where are we now? OFile.GetPosition(Location); } if (Location > ParentChunkEnd) { logError3("ERROR: Overran parent chunk: %d > %d in %s",Location,ParentChunkEnd,Path); return false; } return true; }
void PluginLoader::ReportReadError() { logError1("Error reading %s plugin resources", m_name.c_str()); }