| 194 | } |
| 195 | |
| 196 | std::vector<Option> getScriptsOptionsList(String currentPath, bool saveStartupScript, int rememberedIndex) { |
| 197 | std::vector<Option> opt = {}; |
| 198 | #if !defined(LITE_VERSION) && !defined(DISABLE_INTERPRETER) |
| 199 | FS *fs; |
| 200 | String folder; |
| 201 | |
| 202 | if (currentPath == "") { |
| 203 | folder = getScriptsFolder(fs); |
| 204 | if (folder == "") return opt; // did not find |
| 205 | } else { |
| 206 | folder = currentPath; |
| 207 | // Determine filesystem based on path |
| 208 | if (currentPath.startsWith("/")) { |
| 209 | fs = &LittleFS; |
| 210 | if (SD.exists(currentPath)) { fs = &SD; } |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | File root = fs->open(folder); |
| 215 | if (!root || !root.isDirectory()) return opt; // not a dir |
| 216 | |
| 217 | while (true) { |
| 218 | bool isDir; |
| 219 | String fullPath = root.getNextFileName(&isDir); |
| 220 | String nameOnly = fullPath.substring(fullPath.lastIndexOf("/") + 1); |
| 221 | if (fullPath == "") { break; } |
| 222 | // Serial.printf("Path: %s (isDir: %d)\n", fullPath.c_str(), isDir); |
| 223 | |
| 224 | if (isDir) { |
| 225 | // Skip hidden folders (starting with .) |
| 226 | if (nameOnly.startsWith(".")) continue; |
| 227 | |
| 228 | // Add folder option |
| 229 | String folderTitle = "[ " + nameOnly + " ]"; |
| 230 | opt.push_back({folderTitle.c_str(), [=]() { |
| 231 | auto subOptions = getScriptsOptionsList(fullPath, saveStartupScript); |
| 232 | if (subOptions.size() > 0) { |
| 233 | String displayPath = fullPath; |
| 234 | int secondSlash = displayPath.indexOf('/', 1); |
| 235 | if (secondSlash >= 0) { |
| 236 | displayPath = displayPath.substring(secondSlash + 1); |
| 237 | } |
| 238 | loopOptions(subOptions, MENU_TYPE_SUBMENU, displayPath.c_str()); |
| 239 | } |
| 240 | }}); |
| 241 | } else { |
| 242 | // Handle files |
| 243 | int dotIndex = nameOnly.lastIndexOf("."); |
| 244 | String ext = dotIndex >= 0 ? nameOnly.substring(dotIndex + 1) : ""; |
| 245 | ext.toUpperCase(); |
| 246 | if (ext != "JS" && ext != "BJS") continue; |
| 247 | |
| 248 | String entry_title = nameOnly.substring(0, nameOnly.lastIndexOf(".")); // remove the extension |
| 249 | opt.push_back({entry_title.c_str(), [=]() { |
| 250 | if (saveStartupScript) { |
| 251 | bruceConfig.startupAppJSInterpreterFile = fullPath; |
| 252 | bruceConfig.saveFile(); |
| 253 | } else { |
no test coverage detected