| 67 | } |
| 68 | |
| 69 | bool AddFile(const std::string &filename, size_t basepath_length, const std::string &) override |
| 70 | { |
| 71 | std::string basepath = filename.substr(basepath_length); |
| 72 | Debug(misc, 1, "[Social Integration: {}] Loading ...", basepath); |
| 73 | |
| 74 | auto &plugin = _plugins.emplace_back(std::make_unique<InternalSocialIntegrationPlugin>(filename, basepath)); |
| 75 | |
| 76 | /* Validation failed, so no library was loaded. */ |
| 77 | if (plugin->library == nullptr) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | if (plugin->library->HasError()) { |
| 82 | plugin->external.state = SocialIntegrationPlugin::FAILED; |
| 83 | |
| 84 | Debug(misc, 0, "[Social Integration: {}] Failed to load library: {}", basepath, plugin->library->GetLastError()); |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | OpenTTD_SocialIntegration_v1_GetInfo getinfo_func = plugin->library->GetFunction("SocialIntegration_v1_GetInfo"); |
| 89 | if (plugin->library->HasError()) { |
| 90 | plugin->external.state = SocialIntegrationPlugin::UNSUPPORTED_API; |
| 91 | |
| 92 | Debug(misc, 0, "[Social Integration: {}] Failed to find symbol SocialPlugin_v1_GetInfo: {}", basepath, plugin->library->GetLastError()); |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | OpenTTD_SocialIntegration_v1_Init init_func = plugin->library->GetFunction("SocialIntegration_v1_Init"); |
| 97 | if (plugin->library->HasError()) { |
| 98 | plugin->external.state = SocialIntegrationPlugin::UNSUPPORTED_API; |
| 99 | |
| 100 | Debug(misc, 0, "[Social Integration: {}] Failed to find symbol SocialPlugin_v1_Init: {}", basepath, plugin->library->GetLastError()); |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | getinfo_func(&plugin->plugin_info); |
| 105 | /* Setup the information for the outside world to see. */ |
| 106 | plugin->external.social_platform = plugin->plugin_info.social_platform; |
| 107 | plugin->external.name = plugin->plugin_info.name; |
| 108 | plugin->external.version = plugin->plugin_info.version; |
| 109 | |
| 110 | /* Lowercase the string for comparison. */ |
| 111 | std::string lc_social_platform = plugin->plugin_info.social_platform; |
| 112 | strtolower(lc_social_platform); |
| 113 | |
| 114 | /* Prevent more than one plugin for a certain Social Platform to be loaded, as that never ends well. */ |
| 115 | if (_loaded_social_platform.find(lc_social_platform) != _loaded_social_platform.end()) { |
| 116 | plugin->external.state = SocialIntegrationPlugin::DUPLICATE; |
| 117 | |
| 118 | Debug(misc, 0, "[Social Integration: {}] Another plugin for {} is already loaded", basepath, plugin->plugin_info.social_platform); |
| 119 | return false; |
| 120 | } |
| 121 | _loaded_social_platform.insert(std::move(lc_social_platform)); |
| 122 | |
| 123 | auto state = init_func(&plugin->plugin_api, &plugin->openttd_info); |
| 124 | switch (state) { |
| 125 | case OTTD_SOCIAL_INTEGRATION_V1_INIT_SUCCESS: |
| 126 | plugin->external.state = SocialIntegrationPlugin::RUNNING; |
nothing calls this directly
no test coverage detected