feat(radio): allow Lua tools to be contained entirely within a folder (#6448)
This commit is contained in:
@@ -114,24 +114,34 @@ static void scanLuaTools(std::list<ToolEntry>& scripts)
|
|||||||
FRESULT res = f_opendir(&dir, SCRIPTS_TOOLS_PATH);
|
FRESULT res = f_opendir(&dir, SCRIPTS_TOOLS_PATH);
|
||||||
if (res == FR_OK) {
|
if (res == FR_OK) {
|
||||||
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)
|
if (res != FR_OK || fno.fname[0] == 0)
|
||||||
break; /* Break on error or end of dir */
|
break; /* Break on error or end of dir */
|
||||||
if (fno.fattrib & (AM_DIR | AM_HID | AM_SYS))
|
if (fno.fattrib & (AM_HID | AM_SYS))
|
||||||
continue; // skip subfolders, hidden files and system files
|
continue; // skip hidden files and system files
|
||||||
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */
|
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */
|
||||||
|
|
||||||
|
bool inFolder = (fno.fattrib & AM_DIR);
|
||||||
|
|
||||||
|
char path[FF_MAX_LFN + 1] = SCRIPTS_TOOLS_PATH "/";
|
||||||
strcat(path, fno.fname);
|
strcat(path, fno.fname);
|
||||||
if (isRadioScriptTool(fno.fname)) {
|
if (inFolder) {
|
||||||
|
strcat(path, "/main.lua");
|
||||||
|
if (f_stat(path, nullptr) != FR_OK)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isRadioScriptTool(path)) {
|
||||||
char toolName[RADIO_TOOL_NAME_MAXLEN + 1] = {0};
|
char toolName[RADIO_TOOL_NAME_MAXLEN + 1] = {0};
|
||||||
const char* label;
|
const char* label;
|
||||||
char* ext = (char*)getFileExtension(path);
|
|
||||||
if (readToolName(toolName, path)) {
|
if (readToolName(toolName, path)) {
|
||||||
label = toolName;
|
label = toolName;
|
||||||
} else {
|
} else {
|
||||||
*ext = '\0';
|
if (!inFolder) {
|
||||||
label = getBasename(path);
|
char* ext = (char*)getFileExtension(fno.fname);
|
||||||
|
if (ext) *ext = '\0';
|
||||||
|
}
|
||||||
|
label = fno.fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
scripts.emplace_back(ToolEntry{label, path, run_lua_tool});
|
scripts.emplace_back(ToolEntry{label, path, run_lua_tool});
|
||||||
|
|||||||
@@ -139,23 +139,33 @@ void menuRadioTools(event_t event)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
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_HID|AM_SYS)) continue; // skip hidden files and system files
|
||||||
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */
|
if (fno.fname[0] == '.') continue; /* Ignore UNIX hidden files */
|
||||||
|
|
||||||
if (isRadioScriptTool(fno.fname)) {
|
bool inFolder = (fno.fattrib & AM_DIR);
|
||||||
|
|
||||||
|
char path[FF_MAX_LFN + 1] = SCRIPTS_TOOLS_PATH "/";
|
||||||
|
strcat(path, fno.fname);
|
||||||
|
if (inFolder) {
|
||||||
|
strcat(path, "/main.lua");
|
||||||
|
if (f_stat(path, nullptr) != FR_OK)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isRadioScriptTool(path)) {
|
||||||
const char *label;
|
const char *label;
|
||||||
char toolName[RADIO_TOOL_NAME_MAXLEN + 1] = {0};
|
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 {
|
||||||
|
if (!inFolder) {
|
||||||
|
char *ext = (char *)getFileExtension(fno.fname);
|
||||||
|
if (ext) *ext = '\0';
|
||||||
|
}
|
||||||
label = fno.fname;
|
label = fno.fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
luaScripts.emplace_back(LuaScript{fno.fname, label});
|
luaScripts.emplace_back(LuaScript{path + DIM(SCRIPTS_TOOLS_PATH "/") - 1, label});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f_closedir(&dir);
|
f_closedir(&dir);
|
||||||
|
|||||||
@@ -1416,7 +1416,7 @@ bool readToolName(char * toolName, const char * filename)
|
|||||||
UINT count;
|
UINT count;
|
||||||
|
|
||||||
if (f_open(&file, filename, FA_READ) != FR_OK) {
|
if (f_open(&file, filename, FA_READ) != FR_OK) {
|
||||||
return "Error opening file";
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FRESULT res = f_read(&file, &buffer, sizeof(buffer), &count);
|
FRESULT res = f_read(&file, &buffer, sizeof(buffer), &count);
|
||||||
|
|||||||
Reference in New Issue
Block a user