#include "manifest_util.h" #include #include #ifdef _WIN32 #pragma push_macro("interface") #undef interface #pragma push_macro("GetObject") #undef GetObject #ifndef NOMINMAX #define NOMINMAX #endif #include #include #elif defined __unix__ #else #error OS is not supported! #endif sdv::u8string CManifestUtil::ReadModuleManifest(/*in*/ const sdv::u8string& ssModule) { sdv::u8string ssManifest; std::filesystem::path pathModule(static_cast(ssModule)); if (!std::filesystem::exists(pathModule)) return ssManifest; // Load the module #ifdef _WIN32 sdv::core::TModuleID tModuleID = reinterpret_cast(LoadLibrary(pathModule.native().c_str())); #elif defined __unix__ sdv::core::TModuleID tModuleID = reinterpret_cast(dlopen(pathModule.native().c_str(), RTLD_LAZY)); #else #error OS not supported! #endif if (!tModuleID) return ssManifest; // Check whether the module exposes the necessary functions using TFNHasActiveObjects = bool(); using TFNGetModuleFactory = sdv::IInterfaceAccess*(uint32_t); using TFNGetManifest = const char*(); #ifdef _WIN32 std::function fnGetFactory = reinterpret_cast(GetProcAddress(reinterpret_cast(tModuleID), "GetModuleFactory")); std::function fnActiveObjects = reinterpret_cast(GetProcAddress(reinterpret_cast(tModuleID), "HasActiveObjects")); std::function fnGetManifest = reinterpret_cast(GetProcAddress(reinterpret_cast(tModuleID), "GetManifest")); #elif defined __unix__ std::function fnGetFactory = reinterpret_cast(dlsym(reinterpret_cast(tModuleID), "GetModuleFactory")); std::function fnActiveObjects = reinterpret_cast(dlsym(reinterpret_cast(tModuleID), "HasActiveObjects")); std::function fnGetManifest = reinterpret_cast(dlsym(reinterpret_cast(tModuleID), "GetManifest")); #else #error OS not supported! #endif // Check for functions and the correct version if (fnGetFactory && fnActiveObjects && fnGetManifest && fnGetManifest()) ssManifest = fnGetManifest(); // Release the library #ifdef _WIN32 FreeLibrary(reinterpret_cast(tModuleID)); #elif defined __unix__ dlclose(reinterpret_cast(tModuleID)); #else #error OS not supported! #endif // Return the manifest return ssManifest; }