MCPcopy Create free account
hub / github.com/MCJack123/craftos2 / initializePlugins

Function initializePlugins

src/plugin.cpp:146–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146std::unordered_map<path_t, std::string> initializePlugins() {
147 std::unordered_map<path_t, std::string> failures;
148 std::vector<path_t> remove;
149 for (auto& p : loadedPlugins) {
150 path_t path = p.first;
151 loadingPlugin = p.first.string();
152 const auto plugin_init = (PluginInfo*(*)(const PluginFunctions*, const path_t&))SDL_LoadFunction(p.second.first, "plugin_init");
153 if (plugin_init != NULL) {
154 PluginInfo * info = NULL;
155 try {
156 info = plugin_init(const_cast<const PluginFunctions*>(&function_map), path);
157 } catch (std::exception &e) {
158 failures[path] = e.what();
159 fprintf(stderr, "Failed to load plugin at %s: %s\n", path.string().c_str(), e.what());
160 continue;
161 }
162 if (info->abi_version != PLUGIN_VERSION || info->minimum_structure_version > function_map.structure_version) {
163 failures[path] = "CraftOS-PC version too old";
164 fprintf(stderr, "Failed to load plugin at %s: This plugin requires a newer version of CraftOS-PC\n", path.string().c_str());
165 const auto plugin_deinit = (void(*)(PluginInfo *))SDL_LoadFunction(p.second.first, "plugin_deinit");
166 if (plugin_deinit != NULL) plugin_deinit(info);
167 continue;
168 }
169 if (!info->failureReason.empty()) {
170 failures[path] = info->failureReason;
171 fprintf(stderr, "Failed to load plugin at %s: %s\n", path.string().c_str(), info->failureReason.c_str());
172 const auto plugin_deinit = (void(*)(PluginInfo *))SDL_LoadFunction(p.second.first, "plugin_deinit");
173 if (plugin_deinit != NULL) plugin_deinit(info);
174 continue;
175 }
176 p.second.second = info;
177 } else if (SDL_LoadFunction(p.second.first, "plugin_info") != NULL) {
178 failures[path] = "Plugin version too old";
179 fprintf(stderr, "Failed to load plugin at %s: This plugin needs to be updated for newer versions of CraftOS-PC\n", path.string().c_str());
180 continue;
181 } else p.second.second = &defaultInfo;
182 }
183 loadingPlugin = "";
184 return failures;
185}
186
187void loadPlugins(Computer * comp) {
188 for (const auto& p : loadedPlugins) { if (p.second.second != NULL) {

Callers 1

mainFunction · 0.70

Calls 2

whatMethod · 0.80
plugin_initFunction · 0.50

Tested by

no test coverage detected