mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
W_VerifyNMUSlumps: Clean up
- Bake W_VerifyFile in, since it was a stub never called anywhere else
- Make it operate off file handles, since the following locations quickly filesearch'd more than once in quick succession.
- W_InitFile
- Command_Addfile
- Remove spurious call from W_InitMultipleFiles for `-file` startup param
This commit is contained in:
parent
b119341948
commit
4d6fe8f233
4 changed files with 77 additions and 80 deletions
|
|
@ -1433,21 +1433,29 @@ static void IdentifyVersion(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MUSICTEST(str) \
|
#define MUSICTEST(str) \
|
||||||
{\
|
musicpath = va(spandf,srb2waddir,"data",str);\
|
||||||
const char *musicpath = va(spandf,srb2waddir,"data",str);\
|
handle = W_OpenWadFile(&musicpath, false); \
|
||||||
int ms = W_VerifyNMUSlumps(musicpath, false); \
|
if (handle) \
|
||||||
if (ms == 1) \
|
|
||||||
{ \
|
{ \
|
||||||
D_AddFile(startupiwads, num_startupiwads++, musicpath, NULL); \
|
int ms = W_VerifyNMUSlumps(musicpath, handle, false); \
|
||||||
musicwads++; \
|
fclose(handle); \
|
||||||
} \
|
if (ms == 0) \
|
||||||
else if (ms == 0) \
|
I_Error("File " str " has been modified with non-music/sound lumps"); \
|
||||||
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")
|
const char *musicpath;
|
||||||
MUSICTEST("altmusic.pk3")
|
FILE *handle;
|
||||||
|
|
||||||
|
MUSICTEST("sounds.pk3")
|
||||||
|
MUSICTEST("music.pk3")
|
||||||
|
MUSICTEST("altmusic.pk3")
|
||||||
|
}
|
||||||
|
|
||||||
#undef MUSICTEST
|
#undef MUSICTEST
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4352,6 +4352,8 @@ static void Command_Addfile(void)
|
||||||
const char **addedfiles = Z_Calloc(sizeof(const char*) * argc, PU_STATIC, NULL);
|
const char **addedfiles = Z_Calloc(sizeof(const char*) * argc, PU_STATIC, NULL);
|
||||||
size_t numfilesadded = 0; // the amount of filenames processed
|
size_t numfilesadded = 0; // the amount of filenames processed
|
||||||
|
|
||||||
|
FILE *fhandle = NULL;
|
||||||
|
|
||||||
// start at one to skip command name
|
// start at one to skip command name
|
||||||
for (curarg = 1; curarg < argc; curarg++)
|
for (curarg = 1; curarg < argc; curarg++)
|
||||||
{
|
{
|
||||||
|
|
@ -4360,24 +4362,22 @@ static void Command_Addfile(void)
|
||||||
char *buf_p = buf;
|
char *buf_p = buf;
|
||||||
INT32 i;
|
INT32 i;
|
||||||
size_t ii;
|
size_t ii;
|
||||||
int musiconly; // W_VerifyNMUSlumps isn't boolean
|
int musiconly = -1; // W_VerifyNMUSlumps isn't boolean
|
||||||
boolean fileadded = false;
|
|
||||||
|
|
||||||
fn = COM_Argv(curarg);
|
fn = COM_Argv(curarg);
|
||||||
|
|
||||||
// For the amount of filenames previously processed...
|
// For the amount of filenames previously processed...
|
||||||
for (ii = 0; ii < numfilesadded; ii++)
|
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 this is one of them, don't try to add it.
|
||||||
if (!strcmp(fn, addedfiles[ii]))
|
break;
|
||||||
{
|
|
||||||
fileadded = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we've added this one, skip to the next one.
|
// 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);
|
CONS_Alert(CONS_WARNING, M_GetText("Already processed %s, skipping\n"), fn);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -4385,13 +4385,22 @@ static void Command_Addfile(void)
|
||||||
|
|
||||||
// Disallow non-printing characters and semicolons.
|
// Disallow non-printing characters and semicolons.
|
||||||
for (i = 0; fn[i] != '\0'; i++)
|
for (i = 0; fn[i] != '\0'; i++)
|
||||||
if (!isprint(fn[i]) || fn[i] == ';')
|
{
|
||||||
{
|
if (isprint(fn[i]) && fn[i] != ';')
|
||||||
Z_Free(addedfiles);
|
continue;
|
||||||
return;
|
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)
|
if (musiconly == -1)
|
||||||
{
|
{
|
||||||
|
|
@ -4429,47 +4438,40 @@ static void Command_Addfile(void)
|
||||||
if (numwadfiles >= MAX_WADFILES)
|
if (numwadfiles >= MAX_WADFILES)
|
||||||
{
|
{
|
||||||
CONS_Alert(CONS_ERROR, M_GetText("Too many files loaded to add %s\n"), fn);
|
CONS_Alert(CONS_ERROR, M_GetText("Too many files loaded to add %s\n"), fn);
|
||||||
Z_Free(addedfiles);
|
goto addfile_finally;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITESTRINGN(buf_p,p,240);
|
|
||||||
|
|
||||||
// calculate and check md5
|
// calculate and check md5
|
||||||
{
|
{
|
||||||
UINT8 md5sum[16];
|
UINT8 md5sum[16];
|
||||||
#ifdef NOMD5
|
#ifdef NOMD5
|
||||||
memset(md5sum,0,16);
|
memset(md5sum,0,16);
|
||||||
#else
|
#else
|
||||||
FILE *fhandle;
|
|
||||||
boolean valid = true;
|
|
||||||
|
|
||||||
if ((fhandle = W_OpenWadFile(&fn, true)) != NULL)
|
|
||||||
{
|
{
|
||||||
tic_t t = I_GetTime();
|
tic_t t = I_GetTime();
|
||||||
CONS_Debug(DBG_SETUP, "Making MD5 for %s\n",fn);
|
CONS_Debug(DBG_SETUP, "Making MD5 for %s\n",fn);
|
||||||
md5_stream(fhandle, md5sum);
|
md5_stream(fhandle, md5sum);
|
||||||
CONS_Debug(DBG_SETUP, "MD5 calc for %s took %f second\n", fn, (float)(I_GetTime() - t)/TICRATE);
|
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++)
|
for (i = 0; i < numwadfiles; i++)
|
||||||
{
|
{
|
||||||
if (!memcmp(wadfiles[i]->md5sum, md5sum, 16))
|
if (memcmp(wadfiles[i]->md5sum, md5sum, 16))
|
||||||
{
|
continue;
|
||||||
CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), fn);
|
|
||||||
valid = false;
|
CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), fn);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid == false)
|
if (i < numwadfiles)
|
||||||
{
|
{
|
||||||
|
// Already loaded, try next
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Finally okay to write this important data
|
||||||
|
WRITESTRINGN(buf_p,p,240);
|
||||||
WRITEMEM(buf_p, md5sum, 16);
|
WRITEMEM(buf_p, md5sum, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4481,6 +4483,10 @@ static void Command_Addfile(void)
|
||||||
SendNetXCmd(XD_ADDFILE, buf, buf_p - buf);
|
SendNetXCmd(XD_ADDFILE, buf, buf_p - buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addfile_finally:
|
||||||
|
|
||||||
|
if (fhandle)
|
||||||
|
fclose(fhandle);
|
||||||
Z_Free(addedfiles);
|
Z_Free(addedfiles);
|
||||||
#endif/*TESTERS*/
|
#endif/*TESTERS*/
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -848,7 +848,7 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup, const
|
||||||
if ((handle = W_OpenWadFile(&filename, true)) == NULL)
|
if ((handle = W_OpenWadFile(&filename, true)) == NULL)
|
||||||
return W_InitFileError(filename, startup);
|
return W_InitFileError(filename, startup);
|
||||||
|
|
||||||
important = W_VerifyNMUSlumps(filename, startup);
|
important = W_VerifyNMUSlumps(filename, handle, startup);
|
||||||
|
|
||||||
if (important == -1)
|
if (important == -1)
|
||||||
{
|
{
|
||||||
|
|
@ -1071,8 +1071,8 @@ INT32 W_InitMultipleFiles(const initmultiplefilesentry_t *entries, INT32 count,
|
||||||
{
|
{
|
||||||
const initmultiplefilesentry_t *entry = &entries[i];
|
const initmultiplefilesentry_t *entry = &entries[i];
|
||||||
|
|
||||||
if (addons && !W_VerifyNMUSlumps(entry->filename, !addons))
|
// Previously, W_VerifyNMUSlumps was called to mark game modified
|
||||||
G_SetGameModified(true, false);
|
// for addons... but W_InitFile already does exactly that!
|
||||||
|
|
||||||
//CONS_Debug(DBG_SETUP, "Loading %s\n", *filenames);
|
//CONS_Debug(DBG_SETUP, "Loading %s\n", *filenames);
|
||||||
rc = W_InitFile(entry->filename, !addons, true, entry->md5sum);
|
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.
|
/** 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
|
* 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
|
* file exists with that filename
|
||||||
* \author Alam Arias
|
* \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[] =
|
lumpchecklist_t NMUSlist[] =
|
||||||
{
|
{
|
||||||
|
|
@ -2463,7 +2434,19 @@ int W_VerifyNMUSlumps(const char *filename, boolean exit_on_error)
|
||||||
{NULL, 0},
|
{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)
|
if (status == -1)
|
||||||
W_InitFileError(filename, exit_on_error);
|
W_InitFileError(filename, exit_on_error);
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ void *W_CacheSoftwarePatchNum(lumpnum_t lumpnum, INT32 tag);
|
||||||
|
|
||||||
void W_UnlockCachedPatch(void *patch);
|
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.
|
/// Initialize non-legacy GL shader lookup, which lives outside the lump management system.
|
||||||
void W_InitShaderLookup(const char *filename);
|
void W_InitShaderLookup(const char *filename);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue