From da003d61c343f625126e8b67569c0a95fb2e3643 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Sat, 29 Apr 2017 16:40:07 +0100 Subject: [PATCH] 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. --- src/filesrch.c | 23 ++++++++++++++++++++++- src/filesrch.h | 14 ++++++++++++-- src/m_menu.c | 13 ++++++++++--- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/filesrch.c b/src/filesrch.c index 2985e8373..d3e5e5ec3 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -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 diff --git a/src/filesrch.h b/src/filesrch.h index 84932fd60..6bbabb9be 100644 --- a/src/filesrch.h +++ b/src/filesrch.h @@ -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); diff --git a/src/m_menu.c b/src/m_menu.c index 4cee61221..deda69616 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -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);