diff --git a/src/d_main.cpp b/src/d_main.cpp index 98190cacf..2eba82a6d 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1433,21 +1433,29 @@ static void IdentifyVersion(void) #endif #define MUSICTEST(str) \ - {\ - const char *musicpath = va(spandf,srb2waddir,"data",str);\ - int ms = W_VerifyNMUSlumps(musicpath, false); \ - if (ms == 1) \ + musicpath = va(spandf,srb2waddir,"data",str);\ + handle = W_OpenWadFile(&musicpath, false); \ + if (handle) \ { \ - D_AddFile(startupiwads, num_startupiwads++, musicpath, NULL); \ - musicwads++; \ - } \ - else if (ms == 0) \ - I_Error("File " str " has been modified with non-music/sound lumps"); \ - } + int ms = W_VerifyNMUSlumps(musicpath, handle, false); \ + fclose(handle); \ + if (ms == 0) \ + I_Error("File " str " has been modified with non-music/sound lumps"); \ + if (ms == 1) \ + { \ + D_AddFile(startupiwads, num_startupiwads++, musicpath, NULL); \ + musicwads++; \ + } \ + } - MUSICTEST("sounds.pk3") - MUSICTEST("music.pk3") - MUSICTEST("altmusic.pk3") + { + const char *musicpath; + FILE *handle; + + MUSICTEST("sounds.pk3") + MUSICTEST("music.pk3") + MUSICTEST("altmusic.pk3") + } #undef MUSICTEST } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 026189ad9..58bee1b6a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4352,6 +4352,8 @@ static void Command_Addfile(void) const char **addedfiles = Z_Calloc(sizeof(const char*) * argc, PU_STATIC, NULL); size_t numfilesadded = 0; // the amount of filenames processed + FILE *fhandle = NULL; + // start at one to skip command name for (curarg = 1; curarg < argc; curarg++) { @@ -4360,24 +4362,22 @@ static void Command_Addfile(void) char *buf_p = buf; INT32 i; size_t ii; - int musiconly; // W_VerifyNMUSlumps isn't boolean - boolean fileadded = false; + int musiconly = -1; // W_VerifyNMUSlumps isn't boolean fn = COM_Argv(curarg); // For the amount of filenames previously processed... for (ii = 0; ii < numfilesadded; ii++) { + if (strcmp(fn, addedfiles[ii])) + continue; + // If this is one of them, don't try to add it. - if (!strcmp(fn, addedfiles[ii])) - { - fileadded = true; - break; - } + break; } // If we've added this one, skip to the next one. - if (fileadded) + if (ii < numfilesadded) { CONS_Alert(CONS_WARNING, M_GetText("Already processed %s, skipping\n"), fn); continue; @@ -4385,13 +4385,22 @@ static void Command_Addfile(void) // Disallow non-printing characters and semicolons. for (i = 0; fn[i] != '\0'; i++) - if (!isprint(fn[i]) || fn[i] == ';') - { - Z_Free(addedfiles); - return; - } + { + if (isprint(fn[i]) && fn[i] != ';') + continue; + goto addfile_finally; + } - musiconly = W_VerifyNMUSlumps(fn, false); + if (fhandle) + { + fclose(fhandle); + fhandle = NULL; + } + + if ((fhandle = W_OpenWadFile(&fn, true)) != NULL) + { + musiconly = W_VerifyNMUSlumps(fn, fhandle, false); + } if (musiconly == -1) { @@ -4429,47 +4438,40 @@ static void Command_Addfile(void) if (numwadfiles >= MAX_WADFILES) { CONS_Alert(CONS_ERROR, M_GetText("Too many files loaded to add %s\n"), fn); - Z_Free(addedfiles); - return; + goto addfile_finally; } - WRITESTRINGN(buf_p,p,240); - // calculate and check md5 { UINT8 md5sum[16]; #ifdef NOMD5 memset(md5sum,0,16); #else - FILE *fhandle; - boolean valid = true; - - if ((fhandle = W_OpenWadFile(&fn, true)) != NULL) { tic_t t = I_GetTime(); CONS_Debug(DBG_SETUP, "Making MD5 for %s\n",fn); md5_stream(fhandle, md5sum); CONS_Debug(DBG_SETUP, "MD5 calc for %s took %f second\n", fn, (float)(I_GetTime() - t)/TICRATE); - fclose(fhandle); } - else // file not found - continue; for (i = 0; i < numwadfiles; i++) { - if (!memcmp(wadfiles[i]->md5sum, md5sum, 16)) - { - CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), fn); - valid = false; - break; - } + if (memcmp(wadfiles[i]->md5sum, md5sum, 16)) + continue; + + CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), fn); + break; } - if (valid == false) + if (i < numwadfiles) { + // Already loaded, try next continue; } #endif + + // Finally okay to write this important data + WRITESTRINGN(buf_p,p,240); WRITEMEM(buf_p, md5sum, 16); } @@ -4481,6 +4483,10 @@ static void Command_Addfile(void) SendNetXCmd(XD_ADDFILE, buf, buf_p - buf); } +addfile_finally: + + if (fhandle) + fclose(fhandle); Z_Free(addedfiles); #endif/*TESTERS*/ } diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 293c1e3f3..857be69ab 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -848,7 +848,7 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup, const if ((handle = W_OpenWadFile(&filename, true)) == NULL) return W_InitFileError(filename, startup); - important = W_VerifyNMUSlumps(filename, startup); + important = W_VerifyNMUSlumps(filename, handle, startup); if (important == -1) { @@ -1071,8 +1071,8 @@ INT32 W_InitMultipleFiles(const initmultiplefilesentry_t *entries, INT32 count, { const initmultiplefilesentry_t *entry = &entries[i]; - if (addons && !W_VerifyNMUSlumps(entry->filename, !addons)) - G_SetGameModified(true, false); + // Previously, W_VerifyNMUSlumps was called to mark game modified + // for addons... but W_InitFile already does exactly that! //CONS_Debug(DBG_SETUP, "Loading %s\n", *filenames); rc = W_InitFile(entry->filename, !addons, true, entry->md5sum); @@ -2368,35 +2368,6 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) } } -// Note: This never opens lumps themselves and therefore doesn't have to -// deal with compressed lumps. -static int W_VerifyFile(const char *filename, lumpchecklist_t *checklist, - boolean status) -{ - FILE *handle; - int goodfile = false; - - if (!checklist) - I_Error("No checklist for %s\n", filename); - // open wad file - if ((handle = W_OpenWadFile(&filename, false)) == NULL) - return -1; - - if (stricmp(&filename[strlen(filename) - 4], ".pk3") == 0) - goodfile = W_VerifyPK3(handle, checklist, status); - else - { - // detect wad file by the absence of the other supported extensions - if (stricmp(&filename[strlen(filename) - 4], ".soc") - && stricmp(&filename[strlen(filename) - 4], ".lua")) - { - goodfile = W_VerifyWAD(handle, checklist, status); - } - } - fclose(handle); - return goodfile; -} - /** Checks a wad for lumps other than music and sound. * Used during game load to verify music.dta is a good file and during a @@ -2410,7 +2381,7 @@ static int W_VerifyFile(const char *filename, lumpchecklist_t *checklist, * file exists with that filename * \author Alam Arias */ -int W_VerifyNMUSlumps(const char *filename, boolean exit_on_error) +int W_VerifyNMUSlumps(const char *filename, FILE *handle, boolean exit_on_error) { lumpchecklist_t NMUSlist[] = { @@ -2463,7 +2434,19 @@ int W_VerifyNMUSlumps(const char *filename, boolean exit_on_error) {NULL, 0}, }; - int status = W_VerifyFile(filename, NMUSlist, false); + int status = 0; + + if (stricmp(&filename[strlen(filename) - 4], ".pk3") == 0) + status = W_VerifyPK3(handle, NMUSlist, false); + else + { + // detect wad file by the absence of the other supported extensions + if (stricmp(&filename[strlen(filename) - 4], ".soc") + && stricmp(&filename[strlen(filename) - 4], ".lua")) + { + status = W_VerifyWAD(handle, NMUSlist, false); + } + } if (status == -1) W_InitFileError(filename, exit_on_error); diff --git a/src/w_wad.h b/src/w_wad.h index b56e05248..6c479aae5 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -226,7 +226,7 @@ void *W_CacheSoftwarePatchNum(lumpnum_t lumpnum, INT32 tag); void W_UnlockCachedPatch(void *patch); -int W_VerifyNMUSlumps(const char *filename, boolean exit_on_error); +int W_VerifyNMUSlumps(const char *filename, FILE *handle, boolean exit_on_error); /// Initialize non-legacy GL shader lookup, which lives outside the lump management system. void W_InitShaderLookup(const char *filename);