diff --git a/src/FileUtils.cpp b/src/FileUtils.cpp index 9286d86..cca71ec 100644 --- a/src/FileUtils.cpp +++ b/src/FileUtils.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include extern "C" OSMessageQueue *OSGetDefaultAppIOQueue(); @@ -199,4 +200,57 @@ int32_t getRPXInfoForPath(const std::string &path, romfs_fileInfo *info) { return -4; } return res; +} + +int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) { + //! always initialze input + *inbuffer = nullptr; + if (size) { + *size = 0; + } + + int32_t iFd = open(filepath, O_RDONLY); + if (iFd < 0) { + return -1; + } + + uint32_t filesize = lseek(iFd, 0, SEEK_END); + lseek(iFd, 0, SEEK_SET); + + auto *buffer = (uint8_t *) memalign(0x40, ROUNDUP(filesize, 0x40)); + if (buffer == nullptr) { + close(iFd); + return -2; + } + + uint32_t blocksize = 0x20000; + uint32_t done = 0; + int32_t readBytes; + + while (done < filesize) { + if (done + blocksize > filesize) { + blocksize = filesize - done; + } + readBytes = read(iFd, buffer + done, blocksize); + if (readBytes <= 0) + break; + done += readBytes; + } + + ::close(iFd); + + if (done != filesize) { + free(buffer); + buffer = nullptr; + return -3; + } + + *inbuffer = buffer; + + //! sign is optional input + if (size) { + *size = filesize; + } + + return filesize; } \ No newline at end of file diff --git a/src/FileUtils.h b/src/FileUtils.h index d4aa6c8..04789ca 100644 --- a/src/FileUtils.h +++ b/src/FileUtils.h @@ -22,4 +22,6 @@ int32_t CreateSubfolder(const char *fullpath); int32_t getRPXInfoForPath(const std::string &path, romfs_fileInfo *info); -int32_t CheckFile(const char *filepath); \ No newline at end of file +int32_t CheckFile(const char *filepath); + +int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size); \ No newline at end of file diff --git a/src/RPXLoading.cpp b/src/RPXLoading.cpp index b9e6590..2887dbf 100644 --- a/src/RPXLoading.cpp +++ b/src/RPXLoading.cpp @@ -128,11 +128,21 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) { request.fileoffset = ((uint32_t *) &info.offset)[1]; if (romfsMount("rcc", completePath.c_str(), RomfsSource_FileDescriptor_CafeOS) == 0) { - if (ini_parse("rcc:/meta/meta.ini", parseINIhandler, &gReplacementInfo.rpxReplacementInfo.metaInformation) < 0) { - DEBUG_FUNCTION_LINE("Failed to load and parse meta.ini"); - } else { - metaLoaded = true; + uint8_t *buffer = nullptr; + uint32_t size = 0; + if (LoadFileToMem("rcc:/meta/meta.ini", &buffer, &size) >= 0 && size > 0) { + buffer[size - 1] = 0; + if (ini_parse_string((const char *) buffer, parseINIhandler, &gReplacementInfo.rpxReplacementInfo.metaInformation) < 0) { + DEBUG_FUNCTION_LINE("Failed to load and parse meta.ini"); + } else { + metaLoaded = true; + } } + if (buffer) { + free(buffer); + buffer = nullptr; + } + FileReader *reader = nullptr; if (CheckFile("rcc:/meta/iconTex.tga")) {