From cada64d86ec2ea7549921b11403f2a3cfd6869a3 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 25 Apr 2024 12:07:03 +0200 Subject: [PATCH] API: Add WUPSGetPluginMetaInformationByPathEx and WUPSGetPluginMetaInformationByBufferEx --- source/utils/exports.cpp | 47 +++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/source/utils/exports.cpp b/source/utils/exports.cpp index 6b30541..1f95ce6 100644 --- a/source/utils/exports.cpp +++ b/source/utils/exports.cpp @@ -92,7 +92,7 @@ extern "C" PluginBackendApiErrorType WUPSLoadPluginAsDataByBuffer(wups_backend_p return WUPSLoadPluginAsData(PLUGIN_INFORMATION_INPUT_TYPE_BUFFER, nullptr, buffer, size, output); } -extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformation(WUPSBackendGetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, wups_backend_plugin_information *output) { +extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformationEx(WUPSBackendGetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, wups_backend_plugin_information *output, PluginBackendPluginParseError *errOut) { if (output == nullptr) { DEBUG_FUNCTION_LINE_ERR("PLUGIN_BACKEND_API_ERROR_INVALID_ARG"); return PLUGIN_BACKEND_API_ERROR_INVALID_ARG; @@ -105,10 +105,31 @@ extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformation(WUPSBackendGet } else if (inputType == PLUGIN_INFORMATION_INPUT_TYPE_BUFFER && buffer != nullptr && size > 0) { pluginInfo = PluginMetaInformationFactory::loadPlugin(std::span((uint8_t *) buffer, size), error); } else { + if (errOut) { + *errOut = PLUGIN_BACKEND_PLUGIN_PARSE_ERROR_UNKNOWN; + } + DEBUG_FUNCTION_LINE_ERR("PLUGIN_BACKEND_API_ERROR_INVALID_ARG"); return PLUGIN_BACKEND_API_ERROR_INVALID_ARG; } + if (errOut) { + switch (error) { + case PLUGIN_PARSE_ERROR_NONE: + *errOut = PLUGIN_BACKEND_PLUGIN_PARSE_ERROR_NONE; + break; + case PLUGIN_PARSE_ERROR_INCOMPATIBLE_VERSION: + *errOut = PLUGIN_BACKEND_PLUGIN_PARSE_ERROR_INCOMPATIBLE_VERSION; + break; + case PLUGIN_PARSE_ERROR_UNKNOWN: + case PLUGIN_PARSE_ERROR_BUFFER_EMPTY: + case PLUGIN_PARSE_ERROR_ELFIO_PARSE_FAILED: + case PLUGIN_PARSE_ERROR_IO_ERROR: + *errOut = PLUGIN_BACKEND_PLUGIN_PARSE_ERROR_UNKNOWN; + break; + } + } + if (!pluginInfo) { DEBUG_FUNCTION_LINE_ERR("PLUGIN_BACKEND_API_ERROR_FILE_NOT_FOUND"); return PLUGIN_BACKEND_API_ERROR_FILE_NOT_FOUND; @@ -118,12 +139,16 @@ extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformation(WUPSBackendGet return PLUGIN_BACKEND_API_ERROR_NONE; } +extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformation(WUPSBackendGetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, wups_backend_plugin_information *output) { + return WUPSGetPluginMetaInformationEx(inputType, path, buffer, size, output, nullptr); +} + extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformationByPath(wups_backend_plugin_information *output, const char *path) { - return WUPSGetPluginMetaInformation(PLUGIN_INFORMATION_INPUT_TYPE_PATH, path, nullptr, 0, output); + return WUPSGetPluginMetaInformationEx(PLUGIN_INFORMATION_INPUT_TYPE_PATH, path, nullptr, 0, output, nullptr); } extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformationByBuffer(wups_backend_plugin_information *output, char *buffer, size_t size) { - return WUPSGetPluginMetaInformation(PLUGIN_INFORMATION_INPUT_TYPE_BUFFER, nullptr, buffer, size, output); + return WUPSGetPluginMetaInformationEx(PLUGIN_INFORMATION_INPUT_TYPE_BUFFER, nullptr, buffer, size, output, nullptr); } extern "C" PluginBackendApiErrorType WUPSGetPluginDataForContainerHandles(const wups_backend_plugin_container_handle *plugin_container_handle_list, wups_backend_plugin_data_handle *plugin_data_list, uint32_t buffer_size) { @@ -226,7 +251,7 @@ extern "C" PluginBackendApiErrorType WUPSGetAPIVersion(WUPSBackendAPIVersion *ou if (outVersion == nullptr) { return PLUGIN_BACKEND_API_ERROR_INVALID_ARG; } - *outVersion = 2; + *outVersion = 3; return PLUGIN_BACKEND_API_ERROR_NONE; } @@ -303,4 +328,16 @@ WUMS_EXPORT_FUNCTION(WUPSGetAPIVersion); WUMS_EXPORT_FUNCTION(WUPSGetNumberOfLoadedPlugins); WUMS_EXPORT_FUNCTION(WUPSGetSectionInformationForPlugin); WUMS_EXPORT_FUNCTION(WUPSWillReloadPluginsOnNextLaunch); -WUMS_EXPORT_FUNCTION(WUPSGetSectionMemoryAddresses); \ No newline at end of file +WUMS_EXPORT_FUNCTION(WUPSGetSectionMemoryAddresses); + +// API 3.0 +extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformationByPathEx(wups_backend_plugin_information *output, const char *path, PluginBackendPluginParseError *err) { + return WUPSGetPluginMetaInformationEx(PLUGIN_INFORMATION_INPUT_TYPE_PATH, path, nullptr, 0, output, err); +} + +extern "C" PluginBackendApiErrorType WUPSGetPluginMetaInformationByBufferEx(wups_backend_plugin_information *output, char *buffer, size_t size, PluginBackendPluginParseError *err) { + return WUPSGetPluginMetaInformationEx(PLUGIN_INFORMATION_INPUT_TYPE_BUFFER, nullptr, buffer, size, output, err); +} + +WUMS_EXPORT_FUNCTION(WUPSGetPluginMetaInformationByPathEx); +WUMS_EXPORT_FUNCTION(WUPSGetPluginMetaInformationByBufferEx);