// // FromCurr // // Copying files from savepathtemp to savepath // void FromCurr(void) { glob_t *glob; glob = I_StartGlob(savepathtemp, "*", 0); if (glob == NULL) I_Error("FromCurr: Couldn't open dir %s", savepathtemp); for (;;) { byte *filebuffer; int filelen; const char *srcfilename; char *dstfilename; srcfilename = I_NextGlob(glob); if (srcfilename == NULL) { break; } dstfilename = M_SafeFilePath(savepath, M_BaseName(srcfilename)); filelen = M_ReadFile(srcfilename, &filebuffer); M_WriteFile(dstfilename, filebuffer, filelen); Z_Free(filebuffer); Z_Free(dstfilename); } I_EndGlob(glob); }
// // ToCurr // // Copying files from savepath to savepathtemp // void ToCurr(void) { glob_t *glob; ClearTmp(); // BUG: Rogue copypasta'd this error message, which is why we don't know // the real original name of this function. glob = I_StartGlob(savepath, "*", 0); if (glob == NULL) I_Error("ClearSlot: Couldn't open dir %s", savepath); for (;;) { byte *filebuffer; int filelen; const char *srcfilename; char *dstfilename; srcfilename = I_NextGlob(glob); if (srcfilename == NULL) { break; } dstfilename = M_SafeFilePath(savepathtemp, M_BaseName(srcfilename)); filelen = M_ReadFile(srcfilename, &filebuffer); M_WriteFile(dstfilename, filebuffer, filelen); Z_Free(filebuffer); Z_Free(dstfilename); } I_EndGlob(glob); }
wad_file_t *W_AddFile (char *filename) { wadinfo_t header; lumpindex_t i; wad_file_t *wad_file; int length; int startlump; filelump_t *fileinfo; filelump_t *filerover; lumpinfo_t *filelumps; int numfilelumps; // If the filename begins with a ~, it indicates that we should use the // reload hack. if (filename[0] == '~') { if (reloadname != NULL) { I_Error("Prefixing a WAD filename with '~' indicates that the " "WAD should be reloaded\n" "on each level restart, for use by level authors for " "rapid development. You\n" "can only reload one WAD file, and it must be the last " "file in the -file list."); } reloadname = strdup(filename); reloadlump = numlumps; ++filename; } // Open the file and add to directory wad_file = W_OpenFile(filename); if (wad_file == NULL) { printf (" couldn't open %s\n", filename); return NULL; } // [crispy] save the file name wad_file->path = M_BaseName(filename); if (strcasecmp(filename+strlen(filename)-3 , "wad" ) ) { // single lump file // fraggle: Swap the filepos and size here. The WAD directory // parsing code expects a little-endian directory, so will swap // them back. Effectively we're constructing a "fake WAD directory" // here, as it would appear on disk. fileinfo = Z_Malloc(sizeof(filelump_t), PU_STATIC, 0); fileinfo->filepos = LONG(0); fileinfo->size = LONG(wad_file->length); // Name the lump after the base of the filename (without the // extension). M_ExtractFileBase (filename, fileinfo->name); numfilelumps = 1; } else { // WAD file W_Read(wad_file, 0, &header, sizeof(header)); if (strncmp(header.identification,"IWAD",4)) { // Homebrew levels? if (strncmp(header.identification,"PWAD",4)) { I_Error ("Wad file %s doesn't have IWAD " "or PWAD id\n", filename); } // ???modifiedgame = true; } header.numlumps = LONG(header.numlumps); header.infotableofs = LONG(header.infotableofs); length = header.numlumps*sizeof(filelump_t); fileinfo = Z_Malloc(length, PU_STATIC, 0); W_Read(wad_file, header.infotableofs, fileinfo, length); numfilelumps = header.numlumps; } // Increase size of numlumps array to accomodate the new file. filelumps = calloc(numfilelumps, sizeof(lumpinfo_t)); if (filelumps == NULL) { I_Error("Failed to allocate array for lumps from new file."); } startlump = numlumps; numlumps += numfilelumps; lumpinfo = realloc(lumpinfo, numlumps * sizeof(lumpinfo_t *)); if (lumpinfo == NULL) { I_Error("Failed to increase lumpinfo[] array size."); } filerover = fileinfo; for (i = startlump; i < numlumps; ++i) { lumpinfo_t *lump_p = &filelumps[i - startlump]; lump_p->wad_file = wad_file; lump_p->position = LONG(filerover->filepos); lump_p->size = LONG(filerover->size); lump_p->cache = NULL; strncpy(lump_p->name, filerover->name, 8); lumpinfo[i] = lump_p; ++filerover; } Z_Free(fileinfo); if (lumphash != NULL) { Z_Free(lumphash); lumphash = NULL; } // If this is the reload file, we need to save some details about the // file so that we can close it later on when we do a reload. if (reloadname) { reloadhandle = wad_file; reloadlumps = filelumps; } return wad_file; }