From 26659d7906e31741199a93fc370eef4d42a171f7 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 16 Apr 2022 07:04:18 -0400 Subject: [PATCH] Load plugin manifest before loading plugin library. --- include/plugin/Plugin.hpp | 1 + src/plugin.cpp | 18 +++++++++++------- src/plugin/Plugin.cpp | 8 +++++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/plugin/Plugin.hpp b/include/plugin/Plugin.hpp index c0702f5c..745fcded 100644 --- a/include/plugin/Plugin.hpp +++ b/include/plugin/Plugin.hpp @@ -80,6 +80,7 @@ struct Plugin { void addModel(Model* model); Model* getModel(const std::string& slug); void fromJson(json_t* rootJ); + void modulesFromJson(json_t* rootJ); std::string getBrand(); }; diff --git a/src/plugin.cpp b/src/plugin.cpp index 3b61b215..404451fe 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -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); 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 InitCallback initCallback; if (path == "") { @@ -169,13 +177,9 @@ static Plugin* loadPlugin(std::string path) { } 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 // Returns NULL for Core. diff --git a/src/plugin/Plugin.cpp b/src/plugin/Plugin.cpp index 698e67fe..2f5a98ea 100644 --- a/src/plugin/Plugin.cpp +++ b/src/plugin/Plugin.cpp @@ -107,15 +107,17 @@ void Plugin::fromJson(json_t* rootJ) { json_t* changelogUrlJ = json_object_get(rootJ, "changelogUrl"); if (changelogUrlJ) changelogUrl = json_string_value(changelogUrlJ); +} + +void Plugin::modulesFromJson(json_t* rootJ) { // Reordered models vector std::list 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; json_t* moduleJ; - json_array_foreach(modulesJ, moduleId, moduleJ) { + json_array_foreach(rootJ, moduleId, moduleJ) { // Get model slug json_t* modelSlugJ = json_object_get(moduleJ, "slug"); if (!modelSlugJ) {