From 2bf277b9924577d93822f6830befe8a2335be8a0 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 3 Sep 2022 23:32:16 +0200 Subject: [PATCH] Improve SDUtils_GetVersion to work without initialization --- source/utils.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/utils.cpp b/source/utils.cpp index 63c5414..e112214 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -61,11 +61,22 @@ SDUtilsStatus SDUtils_DeInitLibrary() { } SDUtilsStatus GetVersion(SDUtilsVersion *); -SDUtilsStatus SDUtils_GetVersion(SDUtilsVersion *version) { - if (version == nullptr) { +SDUtilsStatus SDUtils_GetVersion(SDUtilsVersion *outVersion) { + if (sSDUtilsGetVersion == nullptr) { + if (OSDynLoad_Acquire("homebrew_sdhotswap", &sModuleHandle) != OS_DYNLOAD_OK) { + DEBUG_FUNCTION_LINE_WARN("OSDynLoad_Acquire failed."); + return SDUTILS_RESULT_MODULE_NOT_FOUND; + } + + if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsGetVersion", (void **) &sSDUtilsGetVersion) != OS_DYNLOAD_OK) { + DEBUG_FUNCTION_LINE_WARN("FindExport SDUtilsGetVersion failed."); + return SDUTILS_RESULT_MODULE_MISSING_EXPORT; + } + } + if (outVersion == nullptr) { return SDUTILS_RESULT_INVALID_ARGUMENT; } - return reinterpret_cast(sSDUtilsGetVersion)(version); + return reinterpret_cast(sSDUtilsGetVersion)(outVersion); } SDUtilsStatus SDUtils_IsSdCardMounted(bool *status) {