From 699e3f044941ef84227a97e6da5251a38390a0ef Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 22 Mar 2024 10:14:19 +0100 Subject: [PATCH 1/9] Remove unused and obsolete legacy api function --- include/wups_backend/api.h | 4 ---- source/api.cpp | 8 -------- source/imports.h | 4 ---- 3 files changed, 16 deletions(-) diff --git a/include/wups_backend/api.h b/include/wups_backend/api.h index 863f5ab..a5602d0 100644 --- a/include/wups_backend/api.h +++ b/include/wups_backend/api.h @@ -26,14 +26,10 @@ PluginBackendApiErrorType WUPSBackend_LoadAndLinkByDataHandle(const plugin_data_ PluginBackendApiErrorType WUPSBackend_DeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); -PluginBackendApiErrorType WUPSBackend_LoadPluginAsData(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_data_handle *out); - PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByPath(plugin_data_handle *output, const char *path); PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size); -PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformation(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_information *output); - PluginBackendApiErrorType WUPSBackend_WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path); PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size); diff --git a/source/api.cpp b/source/api.cpp index 391b42d..2b8cd48 100644 --- a/source/api.cpp +++ b/source/api.cpp @@ -186,10 +186,6 @@ PluginBackendApiErrorType WUPSBackend_DeletePluginData(const plugin_data_handle return WUPSDeletePluginData(plugin_data_handle_list, plugin_data_handle_list_size); } -PluginBackendApiErrorType WUPSBackend_LoadPluginAsData(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_data_handle *out) { - return WUPSLoadPluginAsData(inputType, path, buffer, size, out); -} - PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByPath(plugin_data_handle *output, const char *path) { return WUPSLoadPluginAsDataByPath(output, path); } @@ -198,10 +194,6 @@ PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByBuffer(plugin_data_handl return WUPSLoadPluginAsDataByBuffer(output, buffer, size); } -PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformation(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_information *output) { - return WUPSGetPluginMetaInformation(inputType, path, buffer, size, output); -} - PluginBackendApiErrorType WUPSBackend_WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path) { return WUPSGetPluginMetaInformationByPath(output, path); } diff --git a/source/imports.h b/source/imports.h index 98199c7..5c094a7 100644 --- a/source/imports.h +++ b/source/imports.h @@ -27,14 +27,10 @@ extern PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_data_h extern PluginBackendApiErrorType WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); -extern PluginBackendApiErrorType WUPSLoadPluginAsData(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_data_handle *out); - extern PluginBackendApiErrorType WUPSLoadPluginAsDataByPath(plugin_data_handle *output, const char *path); extern PluginBackendApiErrorType WUPSLoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size); -extern PluginBackendApiErrorType WUPSGetPluginMetaInformation(GetPluginInformationInputType inputType, const char *path, char *buffer, size_t size, plugin_information *output); - extern PluginBackendApiErrorType WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path); extern PluginBackendApiErrorType WUPSGetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size); From e835e66c7b23b78cd3008642f9bffcb7dd83b5c1 Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 22 Mar 2024 10:15:09 +0100 Subject: [PATCH 2/9] Fix typo in function declaration (WUPSBackend_GetPluginMetaInformationByPath) --- include/wups_backend/api.h | 2 +- source/api.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/wups_backend/api.h b/include/wups_backend/api.h index a5602d0..ac037a4 100644 --- a/include/wups_backend/api.h +++ b/include/wups_backend/api.h @@ -30,7 +30,7 @@ PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByPath(plugin_data_handle PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size); -PluginBackendApiErrorType WUPSBackend_WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path); +PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByPath(plugin_information *output, const char *path); PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size); diff --git a/source/api.cpp b/source/api.cpp index 2b8cd48..46ec767 100644 --- a/source/api.cpp +++ b/source/api.cpp @@ -194,7 +194,7 @@ PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByBuffer(plugin_data_handl return WUPSLoadPluginAsDataByBuffer(output, buffer, size); } -PluginBackendApiErrorType WUPSBackend_WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path) { +PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByPath(plugin_information *output, const char *path) { return WUPSGetPluginMetaInformationByPath(output, path); } From 786c5a7a3bd4fa6820ac1c00b22d665de31e1e61 Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 22 Mar 2024 10:17:29 +0100 Subject: [PATCH 3/9] Add warning when using legacy api function without calling WUPSBackend_InitLibrary --- source/api.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/api.cpp b/source/api.cpp index 46ec767..a1b2ce0 100644 --- a/source/api.cpp +++ b/source/api.cpp @@ -178,38 +178,53 @@ PluginBackendApiErrorType WUPSBackend_GetSectionMemoryAddresses(plugin_container return reinterpret_cast(sWUPSGetSectionMemoryAddresses)(handle, textAddress, dataAddress); } +#define PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED() \ + do { \ + if (sWUPSAPIVersion == WUPS_BACKEND_MODULE_API_VERSION_ERROR) { DEBUG_FUNCTION_LINE_WARN("libwupsbackend is not initialized, please make sure to call WUPSBackend_InitLibrary"); } \ + } while (0) + + PluginBackendApiErrorType WUPSBackend_LoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) { + PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSLoadAndLinkByDataHandle(plugin_data_handle_list, plugin_data_handle_list_size); } PluginBackendApiErrorType WUPSBackend_DeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) { + PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSDeletePluginData(plugin_data_handle_list, plugin_data_handle_list_size); } PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByPath(plugin_data_handle *output, const char *path) { + PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSLoadPluginAsDataByPath(output, path); } PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size) { + PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSLoadPluginAsDataByBuffer(output, buffer, size); } PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByPath(plugin_information *output, const char *path) { + PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSGetPluginMetaInformationByPath(output, path); } PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size) { + PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSGetPluginMetaInformationByBuffer(output, buffer, size); } PluginBackendApiErrorType WUPSBackend_GetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, const plugin_data_handle *plugin_data_list, uint32_t buffer_size) { + PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSGetPluginDataForContainerHandles(plugin_container_handle_list, plugin_data_list, buffer_size); } PluginBackendApiErrorType WUPSBackend_GetMetaInformation(const plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size) { + PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSGetMetaInformation(plugin_container_handle_list, plugin_information_list, buffer_size); } PluginBackendApiErrorType WUPSBackend_GetLoadedPlugins(const plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize, uint32_t *plugin_information_version) { + PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSGetLoadedPlugins(io_handles, buffer_size, outSize, plugin_information_version); } From 53f2ef0525a743ac0aae72cf097bff751b7b5b99 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 23 Mar 2024 08:11:02 +0100 Subject: [PATCH 4/9] Rename structs to add wups_backend --- include/wups_backend/api.h | 22 ++++++++++----------- include/wups_backend/import_defines.h | 24 +++++++++++------------ source/PluginUtils.cpp | 26 ++++++++++++------------- source/api.cpp | 28 +++++++++++++-------------- source/imports.h | 18 ++++++++--------- 5 files changed, 59 insertions(+), 59 deletions(-) diff --git a/include/wups_backend/api.h b/include/wups_backend/api.h index ac037a4..8bda107 100644 --- a/include/wups_backend/api.h +++ b/include/wups_backend/api.h @@ -12,7 +12,7 @@ PluginBackendApiErrorType WUPSBackend_DeInitLibrary(); const char *WUPSBackend_GetStatusStr(PluginBackendApiErrorType status); -PluginBackendApiErrorType WUPSBackend_GetSectionInformationForPlugin(plugin_container_handle handle, plugin_section_info *plugin_section_list, uint32_t buffer_size, uint32_t *out_count); +PluginBackendApiErrorType WUPSBackend_GetSectionInformationForPlugin(wups_backend_plugin_container_handle handle, wups_backend_plugin_section_info *plugin_section_list, uint32_t buffer_size, uint32_t *out_count); PluginBackendApiErrorType WUPSBackend_GetApiVersion(WUPSBackendAPIVersion *outVersion); @@ -20,25 +20,25 @@ PluginBackendApiErrorType WUPSBackend_GetNumberOfLoadedPlugins(uint32_t *out_cou PluginBackendApiErrorType WUPSBackend_WillReloadPluginsOnNextLaunch(bool *out); -PluginBackendApiErrorType WUPSBackend_GetSectionMemoryAddresses(plugin_container_handle handle, void **textAddress, void **dataAddress); +PluginBackendApiErrorType WUPSBackend_GetSectionMemoryAddresses(wups_backend_plugin_container_handle handle, void **textAddress, void **dataAddress); -PluginBackendApiErrorType WUPSBackend_LoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); +PluginBackendApiErrorType WUPSBackend_LoadAndLinkByDataHandle(const wups_backend_plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); -PluginBackendApiErrorType WUPSBackend_DeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); +PluginBackendApiErrorType WUPSBackend_DeletePluginData(const wups_backend_plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); -PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByPath(plugin_data_handle *output, const char *path); +PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByPath(wups_backend_plugin_data_handle *output, const char *path); -PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size); +PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByBuffer(wups_backend_plugin_data_handle *output, char *buffer, size_t size); -PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByPath(plugin_information *output, const char *path); +PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByPath(wups_backend_plugin_information *output, const char *path); -PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size); +PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByBuffer(wups_backend_plugin_information *output, char *buffer, size_t size); -PluginBackendApiErrorType WUPSBackend_GetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, const plugin_data_handle *plugin_data_list, uint32_t buffer_size); +PluginBackendApiErrorType WUPSBackend_GetPluginDataForContainerHandles(const wups_backend_plugin_container_handle *plugin_container_handle_list, const wups_backend_plugin_data_handle *plugin_data_list, uint32_t buffer_size); -PluginBackendApiErrorType WUPSBackend_GetMetaInformation(const plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size); +PluginBackendApiErrorType WUPSBackend_GetMetaInformation(const wups_backend_plugin_container_handle *plugin_container_handle_list, wups_backend_plugin_information *plugin_information_list, uint32_t buffer_size); -PluginBackendApiErrorType WUPSBackend_GetLoadedPlugins(const plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize, uint32_t *plugin_information_version); +PluginBackendApiErrorType WUPSBackend_GetLoadedPlugins(const wups_backend_plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize, uint32_t *plugin_information_version); #ifdef __cplusplus } diff --git a/include/wups_backend/import_defines.h b/include/wups_backend/import_defines.h index dc0445b..c6b6785 100644 --- a/include/wups_backend/import_defines.h +++ b/include/wups_backend/import_defines.h @@ -20,22 +20,22 @@ #include #include -typedef enum GetPluginInformationInputType { +typedef enum WUPSBackendGetPluginInformationInputType { PLUGIN_INFORMATION_INPUT_TYPE_PATH = 0, PLUGIN_INFORMATION_INPUT_TYPE_BUFFER = 1, -} GetPluginInformationInputType; +} WUPSBackendGetPluginInformationInputType; -typedef uint32_t plugin_container_handle; -typedef uint32_t plugin_data_handle; +typedef uint32_t wups_backend_plugin_container_handle; +typedef uint32_t wups_backend_plugin_data_handle; typedef uint32_t WUPSBackendAPIVersion; -#define WUPS_BACKEND_MODULE_API_VERSION 0x00000002 -#define WUPS_BACKEND_MODULE_API_VERSION_ERROR 0xFFFFFFFF +#define WUPS_BACKEND_MODULE_API_VERSION 0x00000002 +#define WUPS_BACKEND_MODULE_API_VERSION_ERROR 0xFFFFFFFF -#define PLUGIN_INFORMATION_VERSION 0x00000002 +#define WUPS_BACKEND_PLUGIN_INFORMATION_VERSION 0x00000002 /* plugin_information message */ -typedef struct plugin_information { +typedef struct wups_backend_plugin_information { uint32_t plugin_information_version; char name[256]; char author[256]; @@ -45,16 +45,16 @@ typedef struct plugin_information { char version[256]; char storageId[256]; size_t size; -} plugin_information; +} wups_backend_plugin_information; -#define PLUGIN_SECTION_INFORMATION_VERSION 0x00000001 +#define WUPS_BACKEND_PLUGIN_SECTION_INFORMATION_VERSION 0x00000001 -typedef struct plugin_section_info { +typedef struct wups_backend_plugin_section_info { uint32_t plugin_section_info_version; char name[32]; void *address; uint32_t size; -} plugin_section_info; +} wups_backend_plugin_section_info; typedef enum PluginBackendApiErrorType { PLUGIN_BACKEND_API_ERROR_NONE = 0, diff --git a/source/PluginUtils.cpp b/source/PluginUtils.cpp index dd5a480..5c4323f 100644 --- a/source/PluginUtils.cpp +++ b/source/PluginUtils.cpp @@ -24,8 +24,8 @@ using namespace WUPSBackend; -std::optional> getMetaInformation(const plugin_information &info) { - if (info.plugin_information_version != PLUGIN_INFORMATION_VERSION) { +std::optional> getMetaInformation(const wups_backend_plugin_information &info) { + if (info.plugin_information_version != WUPS_BACKEND_PLUGIN_INFORMATION_VERSION) { DEBUG_FUNCTION_LINE_ERR("Version mismatch"); return {}; } @@ -45,7 +45,7 @@ std::optional> getMetaInformation(const p } std::optional> PluginUtils::getMetaInformationForBuffer(char *buffer, size_t size) { - plugin_information info = {}; + wups_backend_plugin_information info; if (WUPSGetPluginMetaInformationByBuffer(&info, buffer, size) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to load meta infos for buffer %08X with size %08X", buffer, size); return {}; @@ -55,7 +55,7 @@ std::optional> PluginUtils::getMetaInform } std::optional> PluginUtils::getMetaInformationForPath(const std::string &path) { - plugin_information info = {}; + wups_backend_plugin_information info = {}; if (WUPSGetPluginMetaInformationByPath(&info, path.c_str()) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to load meta infos for %s", path.c_str()); return {}; @@ -71,7 +71,7 @@ std::optional> PluginUtils::getPluginForPath(co return {}; } - plugin_data_handle dataHandle; + wups_backend_plugin_data_handle dataHandle; if (WUPSLoadPluginAsDataByPath(&dataHandle, path.c_str()) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("WUPSLoadPluginAsDataByPath failed for path %s", path.c_str()); return {}; @@ -99,7 +99,7 @@ std::optional> PluginUtils::getPluginForBuffer( return {}; } - plugin_data_handle dataHandle; + wups_backend_plugin_data_handle dataHandle; if (WUPSLoadPluginAsDataByBuffer(&dataHandle, buffer, size) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("WUPSLoadPluginAsDataByBuffer failed for buffer %08X (%d bytes)", buffer, size); return {}; @@ -124,7 +124,7 @@ std::optional> PluginUtils::getPluginForBuffer( std::vector> PluginUtils::getLoadedPlugins(uint32_t maxSize) { std::vector> result; - auto handles = make_unique_nothrow(maxSize); + auto handles = make_unique_nothrow(maxSize); if (!handles) { DEBUG_FUNCTION_LINE_ERR("Not enough memory"); return result; @@ -141,12 +141,12 @@ std::vector> PluginUtils::getLoadedPlugins(uint DEBUG_FUNCTION_LINE_ERR("WUPSGetLoadedPlugins: Failed"); return result; } - if (realSize == 0 || plugin_information_version != PLUGIN_INFORMATION_VERSION) { + if (realSize == 0 || plugin_information_version != WUPS_BACKEND_PLUGIN_INFORMATION_VERSION) { DEBUG_FUNCTION_LINE_ERR("realSize is 0 or version mismatch"); return result; } - auto dataHandles = make_unique_nothrow(realSize); + auto dataHandles = make_unique_nothrow(realSize); if (!dataHandles) { DEBUG_FUNCTION_LINE_ERR("Not enough memory"); return result; @@ -157,7 +157,7 @@ std::vector> PluginUtils::getLoadedPlugins(uint return result; } - auto information = make_unique_nothrow(realSize); + auto information = make_unique_nothrow(realSize); if (!information) { DEBUG_FUNCTION_LINE_ERR("Not enough memory"); return result; @@ -168,7 +168,7 @@ std::vector> PluginUtils::getLoadedPlugins(uint } for (uint32_t i = 0; i < realSize; i++) { - if (information[i].plugin_information_version != PLUGIN_INFORMATION_VERSION) { + if (information[i].plugin_information_version != WUPS_BACKEND_PLUGIN_INFORMATION_VERSION) { DEBUG_FUNCTION_LINE_ERR("Skip, wrong struct version."); continue; } @@ -206,10 +206,10 @@ std::vector> PluginUtils::getLoadedPlugins(uint int32_t PluginUtils::LoadAndLinkOnRestart(const std::vector> &plugins) { uint32_t dataSize = plugins.size(); - plugin_data_handle handles[dataSize]; + wups_backend_plugin_data_handle handles[dataSize]; int i = 0; for (auto &plugin : plugins) { - plugin_data_handle handle = plugin->getPluginData()->getHandle(); + const wups_backend_plugin_data_handle &handle = plugin->getPluginData()->getHandle(); if (handle == 0) { dataSize--; } else { diff --git a/source/api.cpp b/source/api.cpp index a1b2ce0..45da567 100644 --- a/source/api.cpp +++ b/source/api.cpp @@ -9,14 +9,14 @@ static OSDynLoad_Module sModuleHandle = nullptr; static PluginBackendApiErrorType (*sWUPSGetAPIVersion)(WUPSBackendAPIVersion *) = nullptr; static PluginBackendApiErrorType (*sWUPSGetSectionInformationForPlugin)( - plugin_container_handle handle, - plugin_section_info *plugin_section_list, + wups_backend_plugin_container_handle handle, + wups_backend_plugin_section_info *plugin_section_list, uint32_t buffer_size, uint32_t *out_count) = nullptr; static PluginBackendApiErrorType (*sWUPSGetNumberOfLoadedPlugins)(uint32_t *out) = nullptr; static PluginBackendApiErrorType (*sWUPSWillReloadPluginsOnNextLaunch)(bool *out) = nullptr; -static PluginBackendApiErrorType (*sWUPSGetSectionMemoryAddresses)(plugin_container_handle handle, +static PluginBackendApiErrorType (*sWUPSGetSectionMemoryAddresses)(wups_backend_plugin_container_handle handle, void **textAddress, void **dataAddress) = nullptr; @@ -118,7 +118,7 @@ PluginBackendApiErrorType WUPSBackend_GetApiVersion(WUPSBackendAPIVersion *outVe return reinterpret_cast(sWUPSGetAPIVersion)(outVersion); } -PluginBackendApiErrorType WUPSBackend_GetSectionInformationForPlugin(plugin_container_handle handle, plugin_section_info *plugin_section_list, uint32_t buffer_size, uint32_t *out_count) { +PluginBackendApiErrorType WUPSBackend_GetSectionInformationForPlugin(wups_backend_plugin_container_handle handle, wups_backend_plugin_section_info *plugin_section_list, uint32_t buffer_size, uint32_t *out_count) { if (sWUPSAPIVersion == WUPS_BACKEND_MODULE_API_VERSION_ERROR) { return PLUGIN_BACKEND_API_ERROR_LIB_UNINITIALIZED; } @@ -163,7 +163,7 @@ PluginBackendApiErrorType WUPSBackend_WillReloadPluginsOnNextLaunch(bool *out) { return reinterpret_cast(sWUPSWillReloadPluginsOnNextLaunch)(out); } -PluginBackendApiErrorType WUPSBackend_GetSectionMemoryAddresses(plugin_container_handle handle, void **textAddress, void **dataAddress) { +PluginBackendApiErrorType WUPSBackend_GetSectionMemoryAddresses(wups_backend_plugin_container_handle handle, void **textAddress, void **dataAddress) { if (sWUPSAPIVersion == WUPS_BACKEND_MODULE_API_VERSION_ERROR) { return PLUGIN_BACKEND_API_ERROR_LIB_UNINITIALIZED; } @@ -184,47 +184,47 @@ PluginBackendApiErrorType WUPSBackend_GetSectionMemoryAddresses(plugin_container } while (0) -PluginBackendApiErrorType WUPSBackend_LoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) { +PluginBackendApiErrorType WUPSBackend_LoadAndLinkByDataHandle(const wups_backend_plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) { PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSLoadAndLinkByDataHandle(plugin_data_handle_list, plugin_data_handle_list_size); } -PluginBackendApiErrorType WUPSBackend_DeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) { +PluginBackendApiErrorType WUPSBackend_DeletePluginData(const wups_backend_plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size) { PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSDeletePluginData(plugin_data_handle_list, plugin_data_handle_list_size); } -PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByPath(plugin_data_handle *output, const char *path) { +PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByPath(wups_backend_plugin_data_handle *output, const char *path) { PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSLoadPluginAsDataByPath(output, path); } -PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size) { +PluginBackendApiErrorType WUPSBackend_LoadPluginAsDataByBuffer(wups_backend_plugin_data_handle *output, char *buffer, size_t size) { PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSLoadPluginAsDataByBuffer(output, buffer, size); } -PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByPath(plugin_information *output, const char *path) { +PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByPath(wups_backend_plugin_information *output, const char *path) { PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSGetPluginMetaInformationByPath(output, path); } -PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size) { +PluginBackendApiErrorType WUPSBackend_GetPluginMetaInformationByBuffer(wups_backend_plugin_information *output, char *buffer, size_t size) { PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSGetPluginMetaInformationByBuffer(output, buffer, size); } -PluginBackendApiErrorType WUPSBackend_GetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, const plugin_data_handle *plugin_data_list, uint32_t buffer_size) { +PluginBackendApiErrorType WUPSBackend_GetPluginDataForContainerHandles(const wups_backend_plugin_container_handle *plugin_container_handle_list, const wups_backend_plugin_data_handle *plugin_data_list, uint32_t buffer_size) { PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSGetPluginDataForContainerHandles(plugin_container_handle_list, plugin_data_list, buffer_size); } -PluginBackendApiErrorType WUPSBackend_GetMetaInformation(const plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size) { +PluginBackendApiErrorType WUPSBackend_GetMetaInformation(const wups_backend_plugin_container_handle *plugin_container_handle_list, wups_backend_plugin_information *plugin_information_list, uint32_t buffer_size) { PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSGetMetaInformation(plugin_container_handle_list, plugin_information_list, buffer_size); } -PluginBackendApiErrorType WUPSBackend_GetLoadedPlugins(const plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize, uint32_t *plugin_information_version) { +PluginBackendApiErrorType WUPSBackend_GetLoadedPlugins(const wups_backend_plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize, uint32_t *plugin_information_version) { PRINT_WARNING_FOR_LEGACY_FUNCTION_WHEN_NOT_INITIALIZED(); return WUPSGetLoadedPlugins(io_handles, buffer_size, outSize, plugin_information_version); } diff --git a/source/imports.h b/source/imports.h index 5c094a7..8edf469 100644 --- a/source/imports.h +++ b/source/imports.h @@ -23,23 +23,23 @@ extern "C" { #endif -extern PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); +extern PluginBackendApiErrorType WUPSLoadAndLinkByDataHandle(const wups_backend_plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); -extern PluginBackendApiErrorType WUPSDeletePluginData(const plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); +extern PluginBackendApiErrorType WUPSDeletePluginData(const wups_backend_plugin_data_handle *plugin_data_handle_list, uint32_t plugin_data_handle_list_size); -extern PluginBackendApiErrorType WUPSLoadPluginAsDataByPath(plugin_data_handle *output, const char *path); +extern PluginBackendApiErrorType WUPSLoadPluginAsDataByPath(wups_backend_plugin_data_handle *output, const char *path); -extern PluginBackendApiErrorType WUPSLoadPluginAsDataByBuffer(plugin_data_handle *output, char *buffer, size_t size); +extern PluginBackendApiErrorType WUPSLoadPluginAsDataByBuffer(wups_backend_plugin_data_handle *output, char *buffer, size_t size); -extern PluginBackendApiErrorType WUPSGetPluginMetaInformationByPath(plugin_information *output, const char *path); +extern PluginBackendApiErrorType WUPSGetPluginMetaInformationByPath(wups_backend_plugin_information *output, const char *path); -extern PluginBackendApiErrorType WUPSGetPluginMetaInformationByBuffer(plugin_information *output, char *buffer, size_t size); +extern PluginBackendApiErrorType WUPSGetPluginMetaInformationByBuffer(wups_backend_plugin_information *output, char *buffer, size_t size); -extern PluginBackendApiErrorType WUPSGetPluginDataForContainerHandles(const plugin_container_handle *plugin_container_handle_list, const plugin_data_handle *plugin_data_list, uint32_t buffer_size); +extern PluginBackendApiErrorType WUPSGetPluginDataForContainerHandles(const wups_backend_plugin_container_handle *plugin_container_handle_list, const wups_backend_plugin_data_handle *plugin_data_list, uint32_t buffer_size); -extern PluginBackendApiErrorType WUPSGetMetaInformation(const plugin_container_handle *plugin_container_handle_list, plugin_information *plugin_information_list, uint32_t buffer_size); +extern PluginBackendApiErrorType WUPSGetMetaInformation(const wups_backend_plugin_container_handle *plugin_container_handle_list, wups_backend_plugin_information *plugin_information_list, uint32_t buffer_size); -extern PluginBackendApiErrorType WUPSGetLoadedPlugins(const plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize, uint32_t *plugin_information_version); +extern PluginBackendApiErrorType WUPSGetLoadedPlugins(const wups_backend_plugin_container_handle *io_handles, uint32_t buffer_size, uint32_t *outSize, uint32_t *plugin_information_version); #ifdef __cplusplus } From 20116104f5bcd0c296d919d5bb2d27196564601a Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 23 Mar 2024 08:12:10 +0100 Subject: [PATCH 5/9] Using api functions in PluginUtils --- source/PluginUtils.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/PluginUtils.cpp b/source/PluginUtils.cpp index 5c4323f..39f5841 100644 --- a/source/PluginUtils.cpp +++ b/source/PluginUtils.cpp @@ -16,9 +16,9 @@ ****************************************************************************/ #include "wups_backend/PluginUtils.h" -#include "imports.h" #include "logger.h" #include "utils.h" +#include "wups_backend/api.h" #include #include @@ -46,7 +46,7 @@ std::optional> getMetaInformation(const w std::optional> PluginUtils::getMetaInformationForBuffer(char *buffer, size_t size) { wups_backend_plugin_information info; - if (WUPSGetPluginMetaInformationByBuffer(&info, buffer, size) != PLUGIN_BACKEND_API_ERROR_NONE) { + if (WUPSBackend_GetPluginMetaInformationByBuffer(&info, buffer, size) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to load meta infos for buffer %08X with size %08X", buffer, size); return {}; } @@ -56,7 +56,7 @@ std::optional> PluginUtils::getMetaInform std::optional> PluginUtils::getMetaInformationForPath(const std::string &path) { wups_backend_plugin_information info = {}; - if (WUPSGetPluginMetaInformationByPath(&info, path.c_str()) != PLUGIN_BACKEND_API_ERROR_NONE) { + if (WUPSBackend_GetPluginMetaInformationByPath(&info, path.c_str()) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to load meta infos for %s", path.c_str()); return {}; } @@ -72,7 +72,7 @@ std::optional> PluginUtils::getPluginForPath(co } wups_backend_plugin_data_handle dataHandle; - if (WUPSLoadPluginAsDataByPath(&dataHandle, path.c_str()) != PLUGIN_BACKEND_API_ERROR_NONE) { + if (WUPSBackend_LoadPluginAsDataByPath(&dataHandle, path.c_str()) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("WUPSLoadPluginAsDataByPath failed for path %s", path.c_str()); return {}; } @@ -100,7 +100,7 @@ std::optional> PluginUtils::getPluginForBuffer( } wups_backend_plugin_data_handle dataHandle; - if (WUPSLoadPluginAsDataByBuffer(&dataHandle, buffer, size) != PLUGIN_BACKEND_API_ERROR_NONE) { + if (WUPSBackend_LoadPluginAsDataByBuffer(&dataHandle, buffer, size) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("WUPSLoadPluginAsDataByBuffer failed for buffer %08X (%d bytes)", buffer, size); return {}; } @@ -137,7 +137,7 @@ std::vector> PluginUtils::getLoadedPlugins(uint uint32_t plugin_information_version = 0; - if (WUPSGetLoadedPlugins(handles.get(), maxSize, &realSize, &plugin_information_version) != PLUGIN_BACKEND_API_ERROR_NONE) { + if (WUPSBackend_GetLoadedPlugins(handles.get(), maxSize, &realSize, &plugin_information_version) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("WUPSGetLoadedPlugins: Failed"); return result; } @@ -152,7 +152,7 @@ std::vector> PluginUtils::getLoadedPlugins(uint return result; } - if (WUPSGetPluginDataForContainerHandles(handles.get(), dataHandles.get(), realSize) != PLUGIN_BACKEND_API_ERROR_NONE) { + if (WUPSBackend_GetPluginDataForContainerHandles(handles.get(), dataHandles.get(), realSize) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to get plugin data"); return result; } @@ -162,7 +162,7 @@ std::vector> PluginUtils::getLoadedPlugins(uint DEBUG_FUNCTION_LINE_ERR("Not enough memory"); return result; } - if (WUPSGetMetaInformation(handles.get(), information.get(), realSize) != PLUGIN_BACKEND_API_ERROR_NONE) { + if (WUPSBackend_GetMetaInformation(handles.get(), information.get(), realSize) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to get meta information for handles"); return result; } @@ -218,5 +218,5 @@ int32_t PluginUtils::LoadAndLinkOnRestart(const std::vector Date: Sat, 23 Mar 2024 19:12:11 +0100 Subject: [PATCH 6/9] Use api.h in PluginData destructor --- source/PluginData.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/PluginData.cpp b/source/PluginData.cpp index 6c0acfa..fc965cc 100644 --- a/source/PluginData.cpp +++ b/source/PluginData.cpp @@ -16,8 +16,8 @@ ****************************************************************************/ #include "wups_backend/PluginData.h" -#include "imports.h" #include "logger.h" +#include "wups_backend/api.h" #include using namespace WUPSBackend; @@ -28,7 +28,7 @@ PluginData::PluginData(uint32_t handle) { PluginData::~PluginData() { if (handle != 0) { - if (WUPSDeletePluginData(&handle, 1) != PLUGIN_BACKEND_API_ERROR_NONE) { + if (WUPSBackend_DeletePluginData(&handle, 1) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to delete plugin data"); } } From d4bddb48107d9b7d420850803af37e89dbc482c9 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 23 Mar 2024 19:15:29 +0100 Subject: [PATCH 7/9] Refactor PluginUtils to not return shared_ptr anymore --- .clang-format | 2 +- include/wups_backend/PluginContainer.h | 18 +- include/wups_backend/PluginData.h | 24 ++- include/wups_backend/PluginMetaInformation.h | 142 +++++++--------- include/wups_backend/PluginUtils.h | 22 ++- source/PluginContainer.cpp | 9 +- source/PluginData.cpp | 22 ++- source/PluginMetaInformation.cpp | 28 ++-- source/PluginUtils.cpp | 163 ++++++++----------- 9 files changed, 197 insertions(+), 233 deletions(-) diff --git a/.clang-format b/.clang-format index 56cc685..34c35a0 100644 --- a/.clang-format +++ b/.clang-format @@ -42,7 +42,7 @@ IndentPPDirectives: None IndentWidth: 4 KeepEmptyLinesAtTheStartOfBlocks: true MaxEmptyLinesToKeep: 2 -NamespaceIndentation: All +NamespaceIndentation: None ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true PointerAlignment: Right diff --git a/include/wups_backend/PluginContainer.h b/include/wups_backend/PluginContainer.h index 3c440a1..62b2beb 100644 --- a/include/wups_backend/PluginContainer.h +++ b/include/wups_backend/PluginContainer.h @@ -25,17 +25,17 @@ #include "PluginMetaInformation.h" namespace WUPSBackend { - class PluginContainer { +class PluginContainer { - public: - PluginContainer(std::shared_ptr data, std::shared_ptr metaInfo); +public: + PluginContainer(PluginData data, PluginMetaInformation metaInfo); - [[nodiscard]] const std::shared_ptr &getMetaInformation() const; + [[nodiscard]] const PluginMetaInformation &getMetaInformation() const; - [[nodiscard]] const std::shared_ptr &getPluginData() const; + [[nodiscard]] const PluginData &getPluginData() const; - private: - const std::shared_ptr pluginData; - const std::shared_ptr metaInformation; - }; +private: + PluginData pluginData; + PluginMetaInformation metaInformation; +}; } // namespace WUPSBackend \ No newline at end of file diff --git a/include/wups_backend/PluginData.h b/include/wups_backend/PluginData.h index 7941bd7..0e59690 100644 --- a/include/wups_backend/PluginData.h +++ b/include/wups_backend/PluginData.h @@ -20,16 +20,22 @@ #include namespace WUPSBackend { - class PluginData { +class PluginData { - public: - explicit PluginData(uint32_t handle); - ~PluginData(); +public: + explicit PluginData(uint32_t handle); - [[nodiscard]] uint32_t getHandle() const { - return handle; - } + PluginData(const PluginData &) = delete; - uint32_t handle; - }; + PluginData(PluginData &&src) noexcept; + + ~PluginData(); + + PluginData &operator=(PluginData &&src) noexcept; + + [[nodiscard]] uint32_t getHandle() const; + +private: + uint32_t mHandle; +}; } // namespace WUPSBackend \ No newline at end of file diff --git a/include/wups_backend/PluginMetaInformation.h b/include/wups_backend/PluginMetaInformation.h index 37fec76..95cbb5e 100644 --- a/include/wups_backend/PluginMetaInformation.h +++ b/include/wups_backend/PluginMetaInformation.h @@ -22,91 +22,59 @@ #include namespace WUPSBackend { - class PluginMetaInformation { - public: - [[nodiscard]] const std::string &getName() const { - return name; - } - - [[nodiscard]] const std::string &getAuthor() const { - return this->author; - } - - [[nodiscard]] const std::string &getVersion() const { - return this->version; - } - - [[nodiscard]] const std::string &getLicense() const { - return this->license; - } - - [[nodiscard]] const std::string &getBuildTimestamp() const { - return this->buildtimestamp; - } - - [[nodiscard]] const std::string &getDescription() const { - return this->description; - } - - [[nodiscard]] const std::string &getStorageId() const { - return this->storageId; - } - - [[nodiscard]] size_t getSize() const { - return this->size; - } - - PluginMetaInformation(std::string name, - std::string author, - std::string version, - std::string license, - std::string buildtimestamp, - std::string description, - std::string storageId, - size_t size); - - private: - PluginMetaInformation() = default; - - void setName(std::string name_) { - this->name = std::move(name_); - } - - void setAuthor(std::string author_) { - this->author = std::move(author_); - } - - void setVersion(std::string version_) { - this->version = std::move(version_); - } - - void setLicense(std::string license_) { - this->license = std::move(license_); - } - - void setBuildTimestamp(std::string buildtimestamp_) { - this->buildtimestamp = std::move(buildtimestamp_); - } - - void setDescription(std::string description_) { - this->description = std::move(description_); - } - - void setStorageId(std::string storageId_) { - this->storageId = std::move(storageId_); - } - - void setSize(size_t size_) { - this->size = size_; - } - - std::string name; - std::string author; - std::string version; - std::string license; - std::string buildtimestamp; - std::string description; - std::string storageId; - size_t size{}; - }; +class PluginMetaInformation { +public: + [[nodiscard]] const std::string &getName() const { + return name; + } + + [[nodiscard]] const std::string &getAuthor() const { + return this->author; + } + + [[nodiscard]] const std::string &getVersion() const { + return this->version; + } + + [[nodiscard]] const std::string &getLicense() const { + return this->license; + } + + [[nodiscard]] const std::string &getBuildTimestamp() const { + return this->buildtimestamp; + } + + [[nodiscard]] const std::string &getDescription() const { + return this->description; + } + + [[nodiscard]] const std::string &getStorageId() const { + return this->storageId; + } + + [[nodiscard]] size_t getSize() const { + return this->size; + } + + PluginMetaInformation(std::string_view name, + std::string_view author, + std::string_view version, + std::string_view license, + std::string_view buildtimestamp, + std::string_view description, + std::string_view storageId, + size_t size); + +private: + PluginMetaInformation() = default; + + std::string name; + std::string author; + std::string version; + std::string license; + std::string buildtimestamp; + std::string description; + std::string storageId; + size_t size{}; +}; } // namespace WUPSBackend \ No newline at end of file diff --git a/include/wups_backend/PluginUtils.h b/include/wups_backend/PluginUtils.h index b48f47d..364c734 100644 --- a/include/wups_backend/PluginUtils.h +++ b/include/wups_backend/PluginUtils.h @@ -21,18 +21,22 @@ #include namespace WUPSBackend { - class PluginUtils { - public: - static std::optional> getMetaInformationForBuffer(char *buffer, size_t size); - static std::optional> getMetaInformationForPath(const std::string &path); +const char *GetStatusStr(PluginBackendApiErrorType err); - static std::vector> getLoadedPlugins(uint32_t maxSize); +namespace PluginUtils { - static std::optional> getPluginForPath(const std::string &path); +std::optional getMetaInformationForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err); - static std::optional> getPluginForBuffer(char *buffer, size_t size); +std::optional getMetaInformationForPath(const std::string &path, PluginBackendApiErrorType &err); - static int32_t LoadAndLinkOnRestart(const std::vector> &plugins); - }; +std::vector getLoadedPlugins(PluginBackendApiErrorType &err); + +std::optional getPluginForPath(const std::string &path, PluginBackendApiErrorType &err); + +std::optional getPluginForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err); + +PluginBackendApiErrorType LoadAndLinkOnRestart(const std::vector &plugins); + +} // namespace PluginUtils } // namespace WUPSBackend \ No newline at end of file diff --git a/source/PluginContainer.cpp b/source/PluginContainer.cpp index 6fc99a3..6e26225 100644 --- a/source/PluginContainer.cpp +++ b/source/PluginContainer.cpp @@ -3,15 +3,14 @@ using namespace WUPSBackend; - -PluginContainer::PluginContainer(std::shared_ptr data, std::shared_ptr metaInfo) : pluginData(std::move(data)), - metaInformation(std::move(metaInfo)) { +PluginContainer::PluginContainer(PluginData data, PluginMetaInformation metaInfo) : pluginData(std::move(data)), + metaInformation(std::move(metaInfo)) { } -[[nodiscard]] const std::shared_ptr &PluginContainer::getMetaInformation() const { +[[nodiscard]] const PluginMetaInformation &PluginContainer::getMetaInformation() const { return this->metaInformation; } -[[nodiscard]] const std::shared_ptr &PluginContainer::getPluginData() const { +[[nodiscard]] const PluginData &PluginContainer::getPluginData() const { return pluginData; } diff --git a/source/PluginData.cpp b/source/PluginData.cpp index fc965cc..ed1470a 100644 --- a/source/PluginData.cpp +++ b/source/PluginData.cpp @@ -23,13 +23,29 @@ using namespace WUPSBackend; PluginData::PluginData(uint32_t handle) { - this->handle = handle; + this->mHandle = handle; +} + +PluginData::PluginData(PluginData &&src) noexcept : mHandle(src.mHandle) { + src.mHandle = {}; } PluginData::~PluginData() { - if (handle != 0) { - if (WUPSBackend_DeletePluginData(&handle, 1) != PLUGIN_BACKEND_API_ERROR_NONE) { + if (mHandle != 0) { + if (WUPSBackend_DeletePluginData(&mHandle, 1) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to delete plugin data"); } } } + +PluginData &PluginData::operator=(PluginData &&src) noexcept { + if (this != &src) { + this->mHandle = src.mHandle; + src.mHandle = {}; + } + return *this; +} + +uint32_t PluginData::getHandle() const { + return mHandle; +} diff --git a/source/PluginMetaInformation.cpp b/source/PluginMetaInformation.cpp index 97fb90a..492f9db 100644 --- a/source/PluginMetaInformation.cpp +++ b/source/PluginMetaInformation.cpp @@ -22,20 +22,20 @@ using namespace WUPSBackend; -PluginMetaInformation::PluginMetaInformation(std::string name, - std::string author, - std::string version, - std::string license, - std::string buildtimestamp, - std::string description, - std::string storageId, +PluginMetaInformation::PluginMetaInformation(std::string_view name, + std::string_view author, + std::string_view version, + std::string_view license, + std::string_view buildtimestamp, + std::string_view description, + std::string_view storageId, size_t size) { - this->name = std::move(name); - this->author = std::move(author); + this->name = name; + this->author = author; this->size = size; - this->buildtimestamp = std::move(buildtimestamp); - this->description = std::move(description); - this->license = std::move(license); - this->version = std::move(version); - this->storageId = std::move(storageId); + this->buildtimestamp = buildtimestamp; + this->description = description; + this->license = license; + this->version = version; + this->storageId = storageId; } diff --git a/source/PluginUtils.cpp b/source/PluginUtils.cpp index 39f5841..43aa571 100644 --- a/source/PluginUtils.cpp +++ b/source/PluginUtils.cpp @@ -22,110 +22,92 @@ #include #include -using namespace WUPSBackend; +namespace WUPSBackend { -std::optional> getMetaInformation(const wups_backend_plugin_information &info) { +const char *GetStatusStr(PluginBackendApiErrorType status) { + return WUPSBackend_GetStatusStr(status); +} + +namespace PluginUtils { +static std::optional getMetaInformation(const wups_backend_plugin_information &info, PluginBackendApiErrorType &err) { if (info.plugin_information_version != WUPS_BACKEND_PLUGIN_INFORMATION_VERSION) { + err = PLUGIN_BACKEND_API_ERROR_UNSUPPORTED_VERSION; DEBUG_FUNCTION_LINE_ERR("Version mismatch"); return {}; } - auto res = make_unique_nothrow(info.name, - info.author, - info.version, - info.license, - info.buildTimestamp, - info.description, - info.storageId, - info.size); - if (!res) { - DEBUG_FUNCTION_LINE_ERR("Not enough memory"); - return {}; - } - return res; + return PluginMetaInformation(info.name, + info.author, + info.version, + info.license, + info.buildTimestamp, + info.description, + info.storageId, + info.size); } -std::optional> PluginUtils::getMetaInformationForBuffer(char *buffer, size_t size) { - wups_backend_plugin_information info; - if (WUPSBackend_GetPluginMetaInformationByBuffer(&info, buffer, size) != PLUGIN_BACKEND_API_ERROR_NONE) { +std::optional getMetaInformationForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err) { + wups_backend_plugin_information info = {}; + if ((err = WUPSBackend_GetPluginMetaInformationByBuffer(&info, buffer, size)) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to load meta infos for buffer %08X with size %08X", buffer, size); return {}; } - - return getMetaInformation(info); + return getMetaInformation(info, err); } -std::optional> PluginUtils::getMetaInformationForPath(const std::string &path) { +std::optional getMetaInformationForPath(const std::string &path, PluginBackendApiErrorType &err) { wups_backend_plugin_information info = {}; - if (WUPSBackend_GetPluginMetaInformationByPath(&info, path.c_str()) != PLUGIN_BACKEND_API_ERROR_NONE) { + if ((err = WUPSBackend_GetPluginMetaInformationByPath(&info, path.c_str())) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to load meta infos for %s", path.c_str()); return {}; } - - return getMetaInformation(info); + return getMetaInformation(info, err); } -std::optional> PluginUtils::getPluginForPath(const std::string &path) { - auto metaInfoOpt = PluginUtils::getMetaInformationForPath(path); +std::optional getPluginForPath(const std::string &path, PluginBackendApiErrorType &err) { + auto metaInfoOpt = getMetaInformationForPath(path, err); if (!metaInfoOpt) { DEBUG_FUNCTION_LINE_ERR("Failed to get MetaInformation for path %s", path.c_str()); return {}; } wups_backend_plugin_data_handle dataHandle; - if (WUPSBackend_LoadPluginAsDataByPath(&dataHandle, path.c_str()) != PLUGIN_BACKEND_API_ERROR_NONE) { + if ((err = WUPSBackend_LoadPluginAsDataByPath(&dataHandle, path.c_str())) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("WUPSLoadPluginAsDataByPath failed for path %s", path.c_str()); return {}; } - auto pluginData = make_shared_nothrow(dataHandle); - if (!pluginData) { - DEBUG_FUNCTION_LINE_ERR("Failed to allocate PluginData"); - return {}; - } - - auto pluginContainer = make_unique_nothrow(std::move(pluginData), std::move(metaInfoOpt.value())); - if (!pluginContainer) { - DEBUG_FUNCTION_LINE_ERR("Failed to allocate PluginContainer"); - return {}; - } - - return pluginContainer; + return PluginContainer(PluginData(dataHandle), std::move(metaInfoOpt.value())); } -std::optional> PluginUtils::getPluginForBuffer(char *buffer, size_t size) { - auto metaInfoOpt = PluginUtils::getMetaInformationForBuffer(buffer, size); +std::optional getPluginForBuffer(char *buffer, size_t size, PluginBackendApiErrorType &err) { + auto metaInfoOpt = getMetaInformationForBuffer(buffer, size, err); if (!metaInfoOpt) { DEBUG_FUNCTION_LINE_ERR("Failed to get MetaInformation for buffer %08X (%d bytes)", buffer, size); return {}; } wups_backend_plugin_data_handle dataHandle; - if (WUPSBackend_LoadPluginAsDataByBuffer(&dataHandle, buffer, size) != PLUGIN_BACKEND_API_ERROR_NONE) { + if ((err = WUPSBackend_LoadPluginAsDataByBuffer(&dataHandle, buffer, size)) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("WUPSLoadPluginAsDataByBuffer failed for buffer %08X (%d bytes)", buffer, size); return {}; } - auto pluginData = make_shared_nothrow(dataHandle); - if (!pluginData) { - DEBUG_FUNCTION_LINE_ERR("Failed to allocate PluginData"); - return {}; - } - - auto pluginContainer = make_unique_nothrow(std::move(pluginData), std::move(metaInfoOpt.value())); - if (!pluginContainer) { - DEBUG_FUNCTION_LINE_ERR("Failed to allocate PluginContainer"); - return {}; - } - - return pluginContainer; + return PluginContainer(PluginData(dataHandle), std::move(metaInfoOpt.value())); } +std::vector getLoadedPlugins(PluginBackendApiErrorType &err) { + std::vector result; -std::vector> PluginUtils::getLoadedPlugins(uint32_t maxSize) { - std::vector> result; + PluginBackendApiErrorType err2; + uint32_t maxSize; + if ((err2 = WUPSBackend_GetNumberOfLoadedPlugins(&maxSize)) != PLUGIN_BACKEND_API_ERROR_NONE) { + DEBUG_FUNCTION_LINE_WARN("Failed to get number of loaded plugins: %s", WUPSBackend_GetStatusStr(err2)); + maxSize = 120; + } auto handles = make_unique_nothrow(maxSize); if (!handles) { + err = PLUGIN_BACKEND_API_ERROR_FAILED_ALLOC; DEBUG_FUNCTION_LINE_ERR("Not enough memory"); return result; } @@ -136,87 +118,76 @@ std::vector> PluginUtils::getLoadedPlugins(uint } uint32_t plugin_information_version = 0; - - if (WUPSBackend_GetLoadedPlugins(handles.get(), maxSize, &realSize, &plugin_information_version) != PLUGIN_BACKEND_API_ERROR_NONE) { + if ((err = WUPSBackend_GetLoadedPlugins(handles.get(), maxSize, &realSize, &plugin_information_version)) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("WUPSGetLoadedPlugins: Failed"); return result; } if (realSize == 0 || plugin_information_version != WUPS_BACKEND_PLUGIN_INFORMATION_VERSION) { + err = PLUGIN_BACKEND_API_ERROR_UNSUPPORTED_VERSION; DEBUG_FUNCTION_LINE_ERR("realSize is 0 or version mismatch"); return result; } auto dataHandles = make_unique_nothrow(realSize); if (!dataHandles) { + err = PLUGIN_BACKEND_API_ERROR_FAILED_ALLOC; DEBUG_FUNCTION_LINE_ERR("Not enough memory"); return result; } - if (WUPSBackend_GetPluginDataForContainerHandles(handles.get(), dataHandles.get(), realSize) != PLUGIN_BACKEND_API_ERROR_NONE) { + if ((err = WUPSBackend_GetPluginDataForContainerHandles(handles.get(), dataHandles.get(), realSize)) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to get plugin data"); return result; } auto information = make_unique_nothrow(realSize); if (!information) { + err = PLUGIN_BACKEND_API_ERROR_FAILED_ALLOC; DEBUG_FUNCTION_LINE_ERR("Not enough memory"); return result; } - if (WUPSBackend_GetMetaInformation(handles.get(), information.get(), realSize) != PLUGIN_BACKEND_API_ERROR_NONE) { + if ((err = WUPSBackend_GetMetaInformation(handles.get(), information.get(), realSize)) != PLUGIN_BACKEND_API_ERROR_NONE) { DEBUG_FUNCTION_LINE_ERR("Failed to get meta information for handles"); return result; } for (uint32_t i = 0; i < realSize; i++) { if (information[i].plugin_information_version != WUPS_BACKEND_PLUGIN_INFORMATION_VERSION) { + err = PLUGIN_BACKEND_API_ERROR_UNSUPPORTED_VERSION; DEBUG_FUNCTION_LINE_ERR("Skip, wrong struct version."); - continue; - } - auto metaInfo = make_shared_nothrow(information[i].name, - information[i].author, - information[i].version, - information[i].license, - information[i].buildTimestamp, - information[i].description, - information[i].storageId, - information[i].size); - - if (!metaInfo) { - DEBUG_FUNCTION_LINE_ERR("Skip, failed to allocate MetaInformation"); - continue; + return {}; } - - auto pluginData = std::make_shared((uint32_t) dataHandles[i]); - if (!pluginData) { - DEBUG_FUNCTION_LINE_ERR("Skip, failed to allocate PluginData"); - continue; - } - - auto pluginContainer = make_unique_nothrow(std::move(pluginData), std::move(metaInfo)); - if (!pluginContainer) { - DEBUG_FUNCTION_LINE_ERR("Skip, failed to allocate PluginContainer"); - continue; - } - - result.push_back(std::move(pluginContainer)); + result.emplace_back(PluginData(dataHandles[i]), PluginMetaInformation(information[i].name, + information[i].author, + information[i].version, + information[i].license, + information[i].buildTimestamp, + information[i].description, + information[i].storageId, + information[i].size)); } return result; } -int32_t PluginUtils::LoadAndLinkOnRestart(const std::vector> &plugins) { +PluginBackendApiErrorType LoadAndLinkOnRestart(const std::vector &plugins) { uint32_t dataSize = plugins.size(); - wups_backend_plugin_data_handle handles[dataSize]; + auto handles = make_unique_nothrow(dataSize); + if (!handles) { + return PLUGIN_BACKEND_API_ERROR_FAILED_ALLOC; + } int i = 0; - for (auto &plugin : plugins) { - const wups_backend_plugin_data_handle &handle = plugin->getPluginData()->getHandle(); + for (const auto &plugin : plugins) { + const auto &handle = plugin.getPluginData().getHandle(); if (handle == 0) { - dataSize--; + return PLUGIN_BACKEND_API_INVALID_HANDLE; } else { handles[i] = handle; i++; } } - return WUPSBackend_LoadAndLinkByDataHandle(handles, dataSize); + return WUPSBackend_LoadAndLinkByDataHandle(handles.get(), dataSize); } +} // namespace PluginUtils +} // namespace WUPSBackend \ No newline at end of file From 96a4d2613549e57d7ec9181da283fa68c70555ce Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 23 Mar 2024 19:20:01 +0100 Subject: [PATCH 8/9] Update Dockerfiles --- Dockerfile | 4 ++-- Dockerfile.buildlocal | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index db4755e..edaa45e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM ghcr.io/wiiu-env/devkitppc:20230621 +FROM ghcr.io/wiiu-env/devkitppc:20231112 -COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20230621 /artifacts $DEVKITPRO +COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:0.8.0-dev-20240302-3b5cc2f /artifacts $DEVKITPRO WORKDIR tmp_build COPY . . diff --git a/Dockerfile.buildlocal b/Dockerfile.buildlocal index 2c69585..1b1e606 100644 --- a/Dockerfile.buildlocal +++ b/Dockerfile.buildlocal @@ -1,3 +1,3 @@ -FROM ghcr.io/wiiu-env/devkitppc:20230621 +FROM ghcr.io/wiiu-env/devkitppc:20231112 WORKDIR project \ No newline at end of file From d19e43f32c019ca3584db3617201f461212f5dd9 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 23 Mar 2024 19:21:08 +0100 Subject: [PATCH 9/9] Update push-image workflow to publish dev images --- .github/workflows/push_image.yml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/push_image.yml b/.github/workflows/push_image.yml index 8976048..30dc9a6 100644 --- a/.github/workflows/push_image.yml +++ b/.github/workflows/push_image.yml @@ -3,14 +3,32 @@ on: push: branches: - main + - '*-dev' env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: + clang-format-lib: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./include ./source + build-lib: + runs-on: ubuntu-22.04 + needs: clang-format-lib + steps: + - uses: actions/checkout@v3 + - name: build binary + run: | + docker build . -f Dockerfile.buildlocal -t builder + docker run --rm -v ${PWD}:/project builder make build-and-push-image: runs-on: ubuntu-latest + needs: [build-lib] permissions: contents: read packages: write @@ -24,9 +42,10 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=raw,value={{date 'YYYYMMDD'}}-{{sha}} - type=raw,value={{date 'YYYYMMDD'}} - type=raw,value=latest + type=raw,value={{branch}}-{{date 'YYYYMMDD'}}-{{sha}},enable=${{ github.ref != format('refs/heads/{0}', 'main') }} + type=raw,value={{date 'YYYYMMDD'}}-{{sha}},enable={{is_default_branch}} + type=raw,value={{date 'YYYYMMDD'}},enable={{is_default_branch}} + type=raw,value=latest,enable={{is_default_branch}} - name: Log into registry ${{ env.REGISTRY }} uses: docker/login-action@v2.1.0