fix(bw): tool scripts with long file names not working (#6027)

This commit is contained in:
philmoz
2025-03-29 11:41:26 +10:00
committed by GitHub
parent 18a0e3629c
commit 6793b30fd8
2 changed files with 19 additions and 21 deletions
+2 -2
View File
@@ -685,13 +685,13 @@ union ReusableBuffer
#if defined(NUM_BODY_LINES)
#define TOOL_NAME_MAX_LEN (LCD_W / FW)
#define TOOL_PATH_MAX_LEN (LEN_FILE_PATH_MAX + 10)
#define TOOL_PATH_MAX_LEN 40
struct scriptInfo{
uint8_t index;
char label[TOOL_NAME_MAX_LEN + 1];
uint8_t module;
void (* tool)(event_t);
char path[TOOL_PATH_MAX_LEN + 1];
char filename[TOOL_PATH_MAX_LEN + 1];
};
#endif
+17 -19
View File
@@ -27,7 +27,7 @@
extern uint8_t g_moduleIdx;
struct LuaScript {
std::string path;
std::string filename;
std::string label;
bool operator<(const LuaScript &a) { return label < a.label; }
};
@@ -47,7 +47,7 @@ static LcdFlags dispTool(uint8_t index)
return attr;
}
void displayRadioTool(uint8_t index)
static void displayRadioTool(uint8_t index)
{
auto attr = dispTool(index);
if (attr && s_editMode > 0) {
@@ -57,17 +57,16 @@ void displayRadioTool(uint8_t index)
g_moduleIdx = reusableBuffer.radioTools.script[index - menuVerticalOffset].module;
pushMenu(reusableBuffer.radioTools.script[index - menuVerticalOffset].tool);
}
else if (reusableBuffer.radioTools.script[index - menuVerticalOffset].path[0]) {
char toolPath[FF_MAX_LFN];
strcpy(toolPath, reusableBuffer.radioTools.script[index - menuVerticalOffset].path);
*((char *)getBasename(toolPath)-1) = '\0';
f_chdir(toolPath);
luaExec(reusableBuffer.radioTools.script[index - menuVerticalOffset].path);
else if (reusableBuffer.radioTools.script[index - menuVerticalOffset].filename[0]) {
f_chdir(SCRIPTS_TOOLS_PATH);
char path[FF_MAX_LFN + 1] = SCRIPTS_TOOLS_PATH "/";
strcat(path, reusableBuffer.radioTools.script[index - menuVerticalOffset].filename);
luaExec(path);
}
}
}
void addRadioTool(uint8_t index, const char * label)
static void addRadioTool(uint8_t index, const char * label)
{
strAppend(reusableBuffer.radioTools.script[index - menuVerticalOffset].label, label, TOOL_NAME_MAX_LEN);
auto attr = dispTool(index);
@@ -88,13 +87,13 @@ void addRadioModuleToolHandler(uint8_t index, const char * label, void (* tool)(
}
#if defined(LUA)
void addRadioScriptToolHandler(std::vector<LuaScript> luaScripts)
static void addRadioScriptToolHandler(std::vector<LuaScript> luaScripts)
{
uint8_t index = 0;
for (auto luaScript : luaScripts) {
if (index >= menuVerticalOffset && index < menuVerticalOffset + NUM_BODY_LINES) {
memclear(&reusableBuffer.radioTools.script[index - menuVerticalOffset], sizeof(reusableBuffer.radioTools.script[0]));
strAppend(reusableBuffer.radioTools.script[index - menuVerticalOffset].path, luaScript.path.c_str(), TOOL_PATH_MAX_LEN);
strAppend(reusableBuffer.radioTools.script[index - menuVerticalOffset].filename, luaScript.filename.c_str(), TOOL_PATH_MAX_LEN);
addRadioTool(index, luaScript.label.c_str());
}
index += 1;
@@ -138,26 +137,25 @@ void menuRadioTools(event_t event)
std::vector<LuaScript> luaScripts; // gather and sort before adding to menu
for (;;) {
TCHAR path[FF_MAX_LFN + 1] = SCRIPTS_TOOLS_PATH "/";
res = f_readdir(&dir, &fno); /* Read a directory item */
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (fno.fattrib & (AM_DIR|AM_HID|AM_SYS)) continue; // skip subfolders, hidden files and system files
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */
strcat(path, fno.fname);
if (isRadioScriptTool(fno.fname)) {
char toolName[RADIO_TOOL_NAME_MAXLEN + 1] = {0};
const char *label;
char *ext = (char *)getFileExtension(path);
char toolName[RADIO_TOOL_NAME_MAXLEN + 1] = {0};
char path[FF_MAX_LFN + 1] = SCRIPTS_TOOLS_PATH "/";
strcat(path, fno.fname);
char *ext = (char *)getFileExtension(fno.fname);
*ext = '\0';
if (readToolName(toolName, path)) {
label = toolName;
} else {
*ext = '\0';
label = getBasename(path);
label = fno.fname;
}
luaScripts.emplace_back(LuaScript{path, label});
luaScripts.emplace_back(LuaScript{fno.fname, label});
}
}
f_closedir(&dir);