@@ -80,6 +80,7 @@ struct Plugin { | |||||
void addModel(Model* model); | void addModel(Model* model); | ||||
Model* getModel(const std::string& slug); | Model* getModel(const std::string& slug); | ||||
void fromJson(json_t* rootJ); | void fromJson(json_t* rootJ); | ||||
void modulesFromJson(json_t* rootJ); | |||||
std::string getBrand(); | std::string getBrand(); | ||||
}; | }; | ||||
@@ -159,6 +159,14 @@ static Plugin* loadPlugin(std::string path) { | |||||
throw Exception("JSON parsing error at %s %d:%d %s", manifestFilename.c_str(), error.line, error.column, error.text); | throw Exception("JSON parsing error at %s %d:%d %s", manifestFilename.c_str(), error.line, error.column, error.text); | ||||
DEFER({json_decref(rootJ);}); | DEFER({json_decref(rootJ);}); | ||||
// Load manifest | |||||
plugin->fromJson(rootJ); | |||||
// Reject plugin if slug already exists | |||||
Plugin* existingPlugin = getPlugin(plugin->slug); | |||||
if (existingPlugin) | |||||
throw Exception("Plugin %s is already loaded, not attempting to load it again", plugin->slug.c_str()); | |||||
// Call init callback | // Call init callback | ||||
InitCallback initCallback; | InitCallback initCallback; | ||||
if (path == "") { | if (path == "") { | ||||
@@ -169,13 +177,9 @@ static Plugin* loadPlugin(std::string path) { | |||||
} | } | ||||
initCallback(plugin); | initCallback(plugin); | ||||
// Load manifest | |||||
plugin->fromJson(rootJ); | |||||
// Reject plugin if slug already exists | |||||
Plugin* existingPlugin = getPlugin(plugin->slug); | |||||
if (existingPlugin) | |||||
throw Exception("Plugin %s is already loaded, not attempting to load it again", plugin->slug.c_str()); | |||||
// Load modules manifest | |||||
json_t* modulesJ = json_object_get(rootJ, "modules"); | |||||
plugin->modulesFromJson(modulesJ); | |||||
// Call settingsFromJson() if exists | // Call settingsFromJson() if exists | ||||
// Returns NULL for Core. | // Returns NULL for Core. | ||||
@@ -107,15 +107,17 @@ void Plugin::fromJson(json_t* rootJ) { | |||||
json_t* changelogUrlJ = json_object_get(rootJ, "changelogUrl"); | json_t* changelogUrlJ = json_object_get(rootJ, "changelogUrl"); | ||||
if (changelogUrlJ) | if (changelogUrlJ) | ||||
changelogUrl = json_string_value(changelogUrlJ); | changelogUrl = json_string_value(changelogUrlJ); | ||||
} | |||||
void Plugin::modulesFromJson(json_t* rootJ) { | |||||
// Reordered models vector | // Reordered models vector | ||||
std::list<Model*> newModels; | std::list<Model*> newModels; | ||||
json_t* modulesJ = json_object_get(rootJ, "modules"); | |||||
if (modulesJ && json_array_size(modulesJ) > 0) { | |||||
if (rootJ && json_array_size(rootJ) > 0) { | |||||
size_t moduleId; | size_t moduleId; | ||||
json_t* moduleJ; | json_t* moduleJ; | ||||
json_array_foreach(modulesJ, moduleId, moduleJ) { | |||||
json_array_foreach(rootJ, moduleId, moduleJ) { | |||||
// Get model slug | // Get model slug | ||||
json_t* modelSlugJ = json_object_get(moduleJ, "slug"); | json_t* modelSlugJ = json_object_get(moduleJ, "slug"); | ||||
if (!modelSlugJ) { | if (!modelSlugJ) { | ||||