| 88 | } |
| 89 | |
| 90 | void ModuleFactory::addCustomModulesInFolder(File folder, bool isLocal, bool log) |
| 91 | { |
| 92 | Array<File> modulesList; |
| 93 | folder.findChildFiles(modulesList, File::findDirectories, false); |
| 94 | for (auto& m : modulesList) |
| 95 | { |
| 96 | File moduleFile = m.getChildFile("module.json"); |
| 97 | if (!moduleFile.existsAsFile()) |
| 98 | { |
| 99 | LOGWARNING("Folder " << m.getFileName() << "does not contain a module.json file, skipping"); |
| 100 | continue; |
| 101 | } |
| 102 | |
| 103 | var moduleData = JSON::parse(moduleFile); |
| 104 | |
| 105 | if (!moduleData.isObject()) |
| 106 | { |
| 107 | LOGWARNING("Module " << m.getFileName() << " has an invalid module.json file, skipping"); |
| 108 | continue; |
| 109 | } |
| 110 | |
| 111 | moduleData.getDynamicObject()->setProperty("modulePath", m.getFullPathName()); |
| 112 | |
| 113 | String moduleName = moduleData.getProperty("name", ""); |
| 114 | String moduleType = moduleData.getProperty("type", ""); |
| 115 | String moduleMenuPath = moduleData.getProperty("path", ""); |
| 116 | |
| 117 | if (customModulesDefMap.contains(moduleName)) |
| 118 | { |
| 119 | LOGWARNING("Custom Module with name " << moduleName << " already found, skipping"); |
| 120 | continue; |
| 121 | } |
| 122 | |
| 123 | if (moduleName.isNotEmpty() && moduleType.isNotEmpty()) |
| 124 | { |
| 125 | |
| 126 | if (ModuleDefinition* sourceDef = getDefinitionForType(moduleType)) |
| 127 | { |
| 128 | if (log) LOG("Found custom module : " << moduleMenuPath << ":" << moduleName << (isLocal ? " (local)" : "")); |
| 129 | |
| 130 | ModuleDefinition* def = new ModuleDefinition(moduleMenuPath, moduleName, sourceDef->createFunc); |
| 131 | defs.add(def); |
| 132 | customModulesDefMap.set(moduleName, def); |
| 133 | def->customModuleData = moduleData; |
| 134 | def->moduleFolder = m; |
| 135 | def->isCustomModule = true; |
| 136 | def->isLocalModule = isLocal; |
| 137 | |
| 138 | if (!isLocal) |
| 139 | { |
| 140 | if (CommunityModuleInfo* info = CommunityModuleManager::getInstance()->getModuleInfoForFolder(m)) |
| 141 | { |
| 142 | info->updateLocalData(); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | Image img = ImageCache::getFromFile(m.getChildFile("icon.png")); |
| 147 | if (img.isValid()) def->addIcon(img); |
nothing calls this directly
no test coverage detected