Checking whether a file is loaded or not in the menu, and then forbidding multiple load attempts!

Obviously this doesn't work for files you run using exec, but that is the nature of things.
This commit is contained in:
toasterbabe 2017-04-29 16:40:07 +01:00
parent 20fff0ef23
commit da003d61c3
3 changed files with 44 additions and 6 deletions

View File

@ -477,6 +477,8 @@ char exttable[NUM_EXT_TABLE][5] = {
".txt", ".cfg", // exec
".wad", ".soc", ".lua"}; // addfile
char filenamebuf[MAX_WADFILES][MAX_WADPATH];
boolean preparefilemenu(void)
{
DIR *dirhandle;
@ -567,7 +569,7 @@ boolean preparefilemenu(void)
char *temp;
size_t len = strlen(dent->d_name)+1;
UINT8 ext = EXT_FOLDER;
size_t folder;
UINT8 folder;
if (!S_ISDIR(fsstat.st_mode)) // file
{
@ -575,6 +577,25 @@ boolean preparefilemenu(void)
if (!strcasecmp(exttable[ext], dent->d_name+len-5)) break;
if (ext == NUM_EXT_TABLE) continue; // not an addfile-able (or exec-able) file
ext += EXT_START; // moving to be appropriate position
if (ext >= EXT_MD5)
{
size_t i;
for (i = 0; i < numwadfiles; i++)
{
if (!filenamebuf[i][0])
{
strncpy(filenamebuf[i], wadfiles[i]->filename, MAX_WADPATH);
filenamebuf[i][MAX_WADPATH - 1] = '\0';
nameonly(filenamebuf[i]);
}
if (strcasecmp(dent->d_name, filenamebuf[i]))
continue;
if (checkfilemd5(menupath, wadfiles[i]->md5sum))
ext |= EXT_LOADED;
}
}
folder = 0;
}
else

View File

@ -42,11 +42,21 @@ typedef enum
EXT_START,
EXT_TXT = EXT_START,
EXT_CFG,
EXT_WAD,
EXT_MD5,
EXT_WAD = EXT_MD5,
EXT_SOC,
EXT_LUA, // allowed even if not HAVE_BLUA so that we can yell on load attempt
NUM_EXT,
NUM_EXT_TABLE = NUM_EXT-EXT_START
NUM_EXT_TABLE = NUM_EXT-EXT_START,
EXT_LOADED = 0x80
/*
obviously there can only be 0x7F supported extensions in
addons menu because we're cramming this into a char out of
laziness/easy memory allocation (what's the difference?)
and have stolen a bit to show whether it's loaded or not
in practice the size of the data type is probably overkill
toast 02/05/17
*/
} ext_enum;
boolean preparefilemenu(void);

View File

@ -4480,8 +4480,15 @@ static void M_DrawAddons(void)
for (i = dir_on[menudepthleft]; i < sizedirmenu; i++)
{
UINT32 flags = 0;
if (y > BASEVIDHEIGHT) break;
V_DrawString(x, y, ((dirmenu[dir_on[menudepthleft]][0] == EXT_UP) ? 0 : V_ALLOWLOWERCASE), dirmenu[i]+2);
if ((dirmenu[i][0] & ~EXT_LOADED) != EXT_UP)
flags = V_ALLOWLOWERCASE;
if (dirmenu[i][0] & EXT_LOADED)
flags |= V_TRANSLUCENT;
V_DrawString(x, y, flags, dirmenu[i]+2);
y += SMALLLINEHEIGHT;
}
}
@ -4492,7 +4499,7 @@ static void M_AddonExec(INT32 ch)
return;
S_StartSound(NULL, sfx_strpst);
COM_BufAddText(va("exec %s%s", menupath, dirmenu[dir_on[menudepthleft]]+2));
COM_ImmedExecute(va("exec %s%s", menupath, dirmenu[dir_on[menudepthleft]]+2));
}
static void M_HandleAddons(INT32 choice)
@ -4562,7 +4569,7 @@ static void M_HandleAddons(INT32 choice)
case EXT_WAD:
case EXT_SOC:
S_StartSound(NULL, sfx_strpst);
COM_BufAddText(va("addfile %s%s", menupath, dirmenu[dir_on[menudepthleft]]+2));
COM_ImmedExecute(va("addfile %s%s", menupath, dirmenu[dir_on[menudepthleft]]+2));
break;
default:
S_StartSound(NULL, sfx_lose);