From f420d5edadcd0aa0b1ef3be88ebcd2f2b19c3ff5 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 6 Aug 2022 15:56:45 +0200 Subject: [PATCH] Add support for FSOpenFileEx(Async) --- src/FSFileReplacements.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/FSFileReplacements.cpp b/src/FSFileReplacements.cpp index 795ee93..17920d8 100644 --- a/src/FSFileReplacements.cpp +++ b/src/FSFileReplacements.cpp @@ -4,6 +4,41 @@ #include #include + +DECL_FUNCTION(FSStatus, FSOpenFileEx, FSClient *client, FSCmdBlock *block, const char *path, const char *mode, FSMode createMode, FSOpenFileFlags openFlag, uint32_t preallocSize, FSFileHandle *handle, FSErrorFlag errorMask) { + DEBUG_FUNCTION_LINE_VERBOSE("%s", path); + if (isForceRealFunction(errorMask)) { + return real_FSOpenFileEx(client, block, path, mode, createMode, openFlag, preallocSize, handle, errorMask); + } + return doForLayer( + client, + errorMask, + [c = client, b = block, p = path, m = mode, cm = createMode, of = openFlag, pa = preallocSize, h = handle](FSErrorFlag realErrorMask) -> FSStatus { + return real_FSOpenFileEx(c, b, p, m, cm, of, pa, h, realErrorMask); + }, + [f = getFullPathForClient(client, path), m = mode, h = handle](std::unique_ptr &layer) -> FSStatus { + return layer->FSOpenFileWrapper(f.c_str(), m, h); + }, + SYNC_RESULT_HANDLER); +} + +DECL_FUNCTION(FSStatus, FSOpenFileExAsync, FSClient *client, FSCmdBlock *block, const char *path, const char *mode, FSMode createMode, FSOpenFileFlags openFlag, uint32_t preallocSize, FSFileHandle *handle, FSErrorFlag errorMask, FSAsyncData *asyncData) { + DEBUG_FUNCTION_LINE_VERBOSE("%s", path); + if (isForceRealFunction(errorMask)) { + return real_FSOpenFileExAsync(client, block, path, mode, createMode, openFlag, preallocSize, handle, getRealErrorFlag(errorMask), asyncData); + } + return doForLayer( + client, + errorMask, + [c = client, b = block, p = path, m = mode, cm = createMode, of = openFlag, pa = preallocSize, h = handle, a = asyncData](FSErrorFlag realErrorMask) -> FSStatus { + return real_FSOpenFileExAsync(c, b, p, m, cm, of, pa, h, realErrorMask, a); + }, + [p = getFullPathForClient(client, path), m = mode, h = handle](std::unique_ptr &layer) -> FSStatus { + return layer->FSOpenFileWrapper(p.c_str(), m, h); + }, + ASYNC_RESULT_HANDLER); +} + DECL_FUNCTION(FSStatus, FSOpenFile, FSClient *client, FSCmdBlock *block, char *path, const char *mode, FSFileHandle *handle, FSErrorFlag errorMask) { DEBUG_FUNCTION_LINE_VERBOSE("%s", path); if (isForceRealFunction(errorMask)) { @@ -523,6 +558,9 @@ DECL_FUNCTION(FSStatus, FSGetFreeSpaceSizeAsync, FSClient *client, FSCmdBlock *b } function_replacement_data_t fs_file_function_replacements[] = { + REPLACE_FUNCTION(FSOpenFileEx, LIBRARY_COREINIT, FSOpenFileEx), + REPLACE_FUNCTION(FSOpenFileExAsync, LIBRARY_COREINIT, FSOpenFileExAsync), + REPLACE_FUNCTION(FSOpenFile, LIBRARY_COREINIT, FSOpenFile), REPLACE_FUNCTION(FSOpenFileAsync, LIBRARY_COREINIT, FSOpenFileAsync),