Parse the meta.ini from buffer

This commit is contained in:
Maschell 2022-03-06 12:51:45 +01:00
parent 9c8e69003d
commit 4e8f62248b
3 changed files with 71 additions and 5 deletions

View File

@ -12,6 +12,7 @@
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <coreinit/thread.h> #include <coreinit/thread.h>
#include <dirent.h> #include <dirent.h>
#include <fcntl.h>
#include <map> #include <map>
extern "C" OSMessageQueue *OSGetDefaultAppIOQueue(); extern "C" OSMessageQueue *OSGetDefaultAppIOQueue();
@ -199,4 +200,57 @@ int32_t getRPXInfoForPath(const std::string &path, romfs_fileInfo *info) {
return -4; return -4;
} }
return res; 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;
} }

View File

@ -22,4 +22,6 @@ int32_t CreateSubfolder(const char *fullpath);
int32_t getRPXInfoForPath(const std::string &path, romfs_fileInfo *info); int32_t getRPXInfoForPath(const std::string &path, romfs_fileInfo *info);
int32_t CheckFile(const char *filepath); int32_t CheckFile(const char *filepath);
int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size);

View File

@ -128,11 +128,21 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) {
request.fileoffset = ((uint32_t *) &info.offset)[1]; request.fileoffset = ((uint32_t *) &info.offset)[1];
if (romfsMount("rcc", completePath.c_str(), RomfsSource_FileDescriptor_CafeOS) == 0) { if (romfsMount("rcc", completePath.c_str(), RomfsSource_FileDescriptor_CafeOS) == 0) {
if (ini_parse("rcc:/meta/meta.ini", parseINIhandler, &gReplacementInfo.rpxReplacementInfo.metaInformation) < 0) { uint8_t *buffer = nullptr;
DEBUG_FUNCTION_LINE("Failed to load and parse meta.ini"); uint32_t size = 0;
} else { if (LoadFileToMem("rcc:/meta/meta.ini", &buffer, &size) >= 0 && size > 0) {
metaLoaded = true; 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; FileReader *reader = nullptr;
if (CheckFile("rcc:/meta/iconTex.tga")) { if (CheckFile("rcc:/meta/iconTex.tga")) {