Use latest SDUtilsGetVersion implementation

This commit is contained in:
Maschell 2022-09-03 21:51:38 +02:00
parent 2e4b78d3ed
commit 170c43fcba
2 changed files with 22 additions and 14 deletions

View File

@ -19,7 +19,7 @@ enum SDUtilsStatus {
}; };
typedef uint32_t SDUtilsVersion; typedef uint32_t SDUtilsVersion;
#define SDUTILS_MODULE_VERSION 0x00000001 #define SD_UTILS_MODULE_VERSION_ERROR 0xFFFFFFFF
enum SDUtilsAttachStatus { enum SDUtilsAttachStatus {
SDUTILS_ATTACH_MOUNTED = 1, SDUTILS_ATTACH_MOUNTED = 1,
@ -45,11 +45,17 @@ SDUtilsStatus SDUtils_InitLibrary();
SDUtilsStatus SDUtils_DeInitLibrary(); SDUtilsStatus SDUtils_DeInitLibrary();
/** /**
* Returns the API Version of the WUHBUtils Module. * Retrieves the API Version of the loaded SDUtils.<br>
* @return The WUHBUtilsVersion of the Module * <br>
* @param outVersion pointer to the variable where the version will be stored.
*
* @return SDUTILS_RESULT_SUCCESS: The API version has been store in the version ptr.<br>
* SDUTILS_RESULT_MODULE_NOT_FOUND: The module could not be found. Make sure the module is loaded.<br>
* SDUTILS_RESULT_MODULE_MISSING_EXPORT: The module is missing an expected export.<br>
* SDUTILS_RESULT_INVALID_ARGUMENT: Invalid version pointer.<br>
* SDUTILS_RESULT_UNKNOWN_ERROR: Retrieving the module version failed.
*/ */
SDUtilsVersion SDUtils_GetVersion(); SDUtilsStatus SDUtils_GetVersion(SDUtilsVersion *outVersion);
/** /**
* Registers a callback which will be called whenever a sd card will be inserted or ejected. * Registers a callback which will be called whenever a sd card will be inserted or ejected.

View File

@ -5,7 +5,7 @@
static OSDynLoad_Module sModuleHandle = nullptr; static OSDynLoad_Module sModuleHandle = nullptr;
static SDUtilsVersion (*sSDUtilsGetVersion)() = nullptr; static SDUtilsStatus (*sSDUtilsGetVersion)(SDUtilsVersion *) = nullptr;
static bool (*sSDUtilsAddAttachHandler)(SDAttachHandlerFn) = nullptr; static bool (*sSDUtilsAddAttachHandler)(SDAttachHandlerFn) = nullptr;
static bool (*sSDUtilsRemoveAttachHandler)(SDAttachHandlerFn) = nullptr; static bool (*sSDUtilsRemoveAttachHandler)(SDAttachHandlerFn) = nullptr;
@ -13,6 +13,8 @@ static bool (*sSDUtilsRemoveAttachHandler)(SDAttachHandlerFn) = nullptr;
static bool (*sSDUtilsAddCleanUpHandlesHandler)(SDCleanUpHandlesHandlerFn) = nullptr; static bool (*sSDUtilsAddCleanUpHandlesHandler)(SDCleanUpHandlesHandlerFn) = nullptr;
static bool (*sSDUtilsRemoveCleanUpHandlesHandler)(SDCleanUpHandlesHandlerFn) = nullptr; static bool (*sSDUtilsRemoveCleanUpHandlesHandler)(SDCleanUpHandlesHandlerFn) = nullptr;
static SDUtilsVersion sSDUtilsVersion = SD_UTILS_MODULE_VERSION_ERROR;
SDUtilsStatus SDUtils_InitLibrary() { SDUtilsStatus SDUtils_InitLibrary() {
if (OSDynLoad_Acquire("homebrew_sdhotswap", &sModuleHandle) != OS_DYNLOAD_OK) { if (OSDynLoad_Acquire("homebrew_sdhotswap", &sModuleHandle) != OS_DYNLOAD_OK) {
OSReport("SDUtils_Init: OSDynLoad_Acquire failed.\n"); OSReport("SDUtils_Init: OSDynLoad_Acquire failed.\n");
@ -23,8 +25,9 @@ SDUtilsStatus SDUtils_InitLibrary() {
OSReport("SDUtils_Init: SDUtilsGetVersion failed.\n"); OSReport("SDUtils_Init: SDUtilsGetVersion failed.\n");
return SDUTILS_RESULT_MODULE_MISSING_EXPORT; return SDUTILS_RESULT_MODULE_MISSING_EXPORT;
} }
auto res = SDUtils_GetVersion();
if (res != SDUTILS_MODULE_VERSION) { auto res = SDUtils_GetVersion(&sSDUtilsVersion);
if (res != SDUTILS_RESULT_SUCCESS) {
return SDUTILS_RESULT_UNSUPPORTED_VERSION; return SDUTILS_RESULT_UNSUPPORTED_VERSION;
} }
@ -56,13 +59,12 @@ SDUtilsStatus SDUtils_DeInitLibrary() {
return SDUTILS_RESULT_SUCCESS; return SDUTILS_RESULT_SUCCESS;
} }
SDUtilsVersion GetVersion(); SDUtilsStatus GetVersion(SDUtilsVersion *);
SDUtilsVersion SDUtils_GetVersion() { SDUtilsStatus SDUtils_GetVersion(SDUtilsVersion *version) {
if (sSDUtilsGetVersion == nullptr) { if (version == nullptr) {
return SDUTILS_RESULT_LIB_UNINITIALIZED; return SDUTILS_RESULT_INVALID_ARGUMENT;
} }
return reinterpret_cast<decltype(&GetVersion)>(sSDUtilsGetVersion)(version);
return reinterpret_cast<decltype(&GetVersion)>(sSDUtilsGetVersion)();
} }
SDUtilsStatus SDUtils_IsSdCardMounted(bool *status) { SDUtilsStatus SDUtils_IsSdCardMounted(bool *status) {