//------------------------------------------------------------------------------ //copies a pigfile from the CD to the current dir //retuns file handle of new pig int CopyPigFileFromCD (CFile& cf, char *filename) { return cf.Open (filename, gameFolders.szDataDir, "rb", 0); #if 0 char name [80]; FFS ffs; int ret; messageBox.Show ("Copying bitmap data from CD..."); paletteManager.LoadEffect (); //I don't think this line is really needed //First, delete all PIG files currently in the directory if (!FFF ("*.pig", &ffs, 0)) { do { cf.Delete (ffs.name, ""); } while (!FFN (&ffs, 0)); FFC (&ffs); } //Now, copy over new pig redbook.Stop (); //so we can read off the cd //new code to unarj file strcpy (name, CDROM_dir); strcat (name, "descent2.sow"); do { // ret = unarj_specific_file (name,filename,filename); // DPH:FIXME ret = !EXIT_SUCCESS; if (ret != EXIT_SUCCESS) { //delete file, so we don't leave partial file cf.Delete (filename, ""); if (RequestCD () == -1) //NOTE LINK TO ABOVE IF Error ("Cannot load file <%s> from CD", filename); } } while (ret != EXIT_SUCCESS); mb.Clear (); return cfPiggy [gameStates.app.bD1Data].Open (filename, gameFolders.szDataDir, "rb", 0); #endif }
void Save() const { CFile *pFile = new CFile(GetConfigPath()); if (!pFile->Open(O_WRONLY | O_CREAT | O_TRUNC, 0600)) { DEBUG("ignore: Failed to save `" + GetConfigPath() + "` `" + CString(strerror(errno)) + "`"); delete pFile; return; } for (vector<CIgnore>::const_iterator it = m_vIgnores.begin(); it != m_vIgnores.end(); ++it) { CIgnore Ignore = *it; pFile->Write(Ignore.ToString()); } pFile->Sync(); if (pFile->HadError()) { DEBUG("ignore: Failed to save `" + GetConfigPath() + "` `" + CString(strerror(errno)) + "`"); pFile->Delete(); } delete pFile; }
bool CTriMeshBuilder::Load (int nLevel, bool bForce) { CFile cf; tMeshDataHeader mdh; int nSize; bool bOk; char szFilename [FILENAME_LEN]; char *ioBuffer = NULL, *bufP; if (!(gameStates.render.bTriangleMesh && (gameStates.app.bCacheMeshes || bForce))) return false; if (!cf.Open (DataFilename (szFilename, nLevel), gameFolders.szCacheDir, "rb", 0)) return false; bOk = (cf.Read (&mdh, sizeof (mdh), 1) == 1); if (bOk) bOk = (mdh.nVersion == MESH_DATA_VERSION) && (mdh.nSegments == gameData.segs.nSegments) && (mdh.nFaces == gameData.segs.nFaces); uint nTriVerts = mdh.nTris * 3; if (bOk) nSize = (sizeof (gameData.segs.vertices [0]) + sizeof (gameData.segs.fVertices [0])) * mdh.nVertices + sizeof (FACES.faces [0]) * mdh.nFaces + sizeof (FACES.tris [0]) * mdh.nTris + (sizeof (FACES.vertices [0]) + sizeof (FACES.normals [0]) + sizeof (FACES.texCoord [0]) + sizeof (FACES.ovlTexCoord [0]) + sizeof (FACES.color [0]) + sizeof (FACES.lMapTexCoord [0])) * nTriVerts + sizeof (FACES.faceVerts [0]) * mdh.nFaceVerts; if (bOk) bOk = ((ioBuffer = new char [nSize]) != NULL); if (bOk) bOk = cf.Read (ioBuffer, nSize, 1) == 1; if (bOk) { bufP = ioBuffer; FACES.Destroy (); gameData.segs.vertices.Create (mdh.nVertices); memcpy (gameData.segs.vertices.Buffer (), bufP, nSize = sizeof (gameData.segs.vertices [0]) * mdh.nVertices); bufP += nSize; gameData.segs.fVertices.Create (mdh.nVertices); memcpy (gameData.segs.fVertices.Buffer (), bufP, nSize = sizeof (gameData.segs.fVertices [0]) * mdh.nVertices); bufP += nSize; FACES.faces.Create (mdh.nFaces); memcpy (FACES.faces.Buffer (), bufP, nSize = sizeof (FACES.faces [0]) * mdh.nFaces); bufP += nSize; FACES.tris.Create (mdh.nTris); memcpy (FACES.tris.Buffer (), bufP, nSize = sizeof (FACES.tris [0]) * mdh.nTris); bufP += nSize; FACES.vertices.Create (nTriVerts); memcpy (FACES.vertices.Buffer (), bufP, nSize = sizeof (FACES.vertices [0]) * nTriVerts); bufP += nSize; FACES.normals.Create (nTriVerts); memcpy (FACES.normals.Buffer (), bufP, nSize = sizeof (FACES.normals [0]) * nTriVerts); bufP += nSize; FACES.texCoord.Create (nTriVerts); memcpy (FACES.texCoord.Buffer (), bufP, nSize = sizeof (FACES.texCoord [0]) * nTriVerts); bufP += nSize; FACES.ovlTexCoord.Create (nTriVerts); memcpy (FACES.ovlTexCoord.Buffer (), bufP, nSize = sizeof (FACES.ovlTexCoord [0]) * nTriVerts); bufP += nSize; FACES.color.Create (nTriVerts); memcpy (FACES.color.Buffer (), bufP, nSize = sizeof (FACES.color [0]) * nTriVerts); bufP += nSize; FACES.lMapTexCoord.Create (nTriVerts); memcpy (FACES.lMapTexCoord.Buffer (), bufP, nSize = sizeof (FACES.lMapTexCoord [0]) * nTriVerts); bufP += nSize; FACES.faceVerts.Create (mdh.nFaceVerts); memcpy (FACES.faceVerts.Buffer (), bufP, nSize = sizeof (FACES.faceVerts [0]) * mdh.nFaceVerts); gameData.segs.points.Resize (mdh.nVertices); } if (ioBuffer) { delete[] ioBuffer; ioBuffer = NULL; } if (bOk) { gameData.segs.nVertices = mdh.nVertices; gameData.segs.nTris = mdh.nTris; SetupVertexNormals (); } cf.Close (); if (!gameStates.app.bCacheMeshes) cf.Delete (DataFilename (szFilename, nLevel), gameFolders.szCacheDir); CreateSegFaceList (); CreateFaceVertLists (); return bOk; }