fix(bw): tool scripts with long file names not working (#6027)
This commit is contained in:
+2
-2
@@ -685,13 +685,13 @@ union ReusableBuffer
|
|||||||
|
|
||||||
#if defined(NUM_BODY_LINES)
|
#if defined(NUM_BODY_LINES)
|
||||||
#define TOOL_NAME_MAX_LEN (LCD_W / FW)
|
#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{
|
struct scriptInfo{
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
char label[TOOL_NAME_MAX_LEN + 1];
|
char label[TOOL_NAME_MAX_LEN + 1];
|
||||||
uint8_t module;
|
uint8_t module;
|
||||||
void (* tool)(event_t);
|
void (* tool)(event_t);
|
||||||
char path[TOOL_PATH_MAX_LEN + 1];
|
char filename[TOOL_PATH_MAX_LEN + 1];
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
extern uint8_t g_moduleIdx;
|
extern uint8_t g_moduleIdx;
|
||||||
|
|
||||||
struct LuaScript {
|
struct LuaScript {
|
||||||
std::string path;
|
std::string filename;
|
||||||
std::string label;
|
std::string label;
|
||||||
bool operator<(const LuaScript &a) { return label < a.label; }
|
bool operator<(const LuaScript &a) { return label < a.label; }
|
||||||
};
|
};
|
||||||
@@ -47,7 +47,7 @@ static LcdFlags dispTool(uint8_t index)
|
|||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayRadioTool(uint8_t index)
|
static void displayRadioTool(uint8_t index)
|
||||||
{
|
{
|
||||||
auto attr = dispTool(index);
|
auto attr = dispTool(index);
|
||||||
if (attr && s_editMode > 0) {
|
if (attr && s_editMode > 0) {
|
||||||
@@ -57,17 +57,16 @@ void displayRadioTool(uint8_t index)
|
|||||||
g_moduleIdx = reusableBuffer.radioTools.script[index - menuVerticalOffset].module;
|
g_moduleIdx = reusableBuffer.radioTools.script[index - menuVerticalOffset].module;
|
||||||
pushMenu(reusableBuffer.radioTools.script[index - menuVerticalOffset].tool);
|
pushMenu(reusableBuffer.radioTools.script[index - menuVerticalOffset].tool);
|
||||||
}
|
}
|
||||||
else if (reusableBuffer.radioTools.script[index - menuVerticalOffset].path[0]) {
|
else if (reusableBuffer.radioTools.script[index - menuVerticalOffset].filename[0]) {
|
||||||
char toolPath[FF_MAX_LFN];
|
f_chdir(SCRIPTS_TOOLS_PATH);
|
||||||
strcpy(toolPath, reusableBuffer.radioTools.script[index - menuVerticalOffset].path);
|
char path[FF_MAX_LFN + 1] = SCRIPTS_TOOLS_PATH "/";
|
||||||
*((char *)getBasename(toolPath)-1) = '\0';
|
strcat(path, reusableBuffer.radioTools.script[index - menuVerticalOffset].filename);
|
||||||
f_chdir(toolPath);
|
luaExec(path);
|
||||||
luaExec(reusableBuffer.radioTools.script[index - menuVerticalOffset].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);
|
strAppend(reusableBuffer.radioTools.script[index - menuVerticalOffset].label, label, TOOL_NAME_MAX_LEN);
|
||||||
auto attr = dispTool(index);
|
auto attr = dispTool(index);
|
||||||
@@ -88,13 +87,13 @@ void addRadioModuleToolHandler(uint8_t index, const char * label, void (* tool)(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(LUA)
|
#if defined(LUA)
|
||||||
void addRadioScriptToolHandler(std::vector<LuaScript> luaScripts)
|
static void addRadioScriptToolHandler(std::vector<LuaScript> luaScripts)
|
||||||
{
|
{
|
||||||
uint8_t index = 0;
|
uint8_t index = 0;
|
||||||
for (auto luaScript : luaScripts) {
|
for (auto luaScript : luaScripts) {
|
||||||
if (index >= menuVerticalOffset && index < menuVerticalOffset + NUM_BODY_LINES) {
|
if (index >= menuVerticalOffset && index < menuVerticalOffset + NUM_BODY_LINES) {
|
||||||
memclear(&reusableBuffer.radioTools.script[index - menuVerticalOffset], sizeof(reusableBuffer.radioTools.script[0]));
|
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());
|
addRadioTool(index, luaScript.label.c_str());
|
||||||
}
|
}
|
||||||
index += 1;
|
index += 1;
|
||||||
@@ -138,26 +137,25 @@ void menuRadioTools(event_t event)
|
|||||||
std::vector<LuaScript> luaScripts; // gather and sort before adding to menu
|
std::vector<LuaScript> luaScripts; // gather and sort before adding to menu
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
TCHAR path[FF_MAX_LFN + 1] = SCRIPTS_TOOLS_PATH "/";
|
|
||||||
|
|
||||||
res = f_readdir(&dir, &fno); /* Read a directory item */
|
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 (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.fattrib & (AM_DIR|AM_HID|AM_SYS)) continue; // skip subfolders, hidden files and system files
|
||||||
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */
|
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */
|
||||||
|
|
||||||
strcat(path, fno.fname);
|
|
||||||
if (isRadioScriptTool(fno.fname)) {
|
if (isRadioScriptTool(fno.fname)) {
|
||||||
char toolName[RADIO_TOOL_NAME_MAXLEN + 1] = {0};
|
|
||||||
const char *label;
|
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)) {
|
if (readToolName(toolName, path)) {
|
||||||
label = toolName;
|
label = toolName;
|
||||||
} else {
|
} else {
|
||||||
*ext = '\0';
|
label = fno.fname;
|
||||||
label = getBasename(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
luaScripts.emplace_back(LuaScript{path, label});
|
luaScripts.emplace_back(LuaScript{fno.fname, label});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f_closedir(&dir);
|
f_closedir(&dir);
|
||||||
|
|||||||
Reference in New Issue
Block a user