mirror of
https://github.com/wiiu-env/RPXLoadingModule.git
synced 2024-11-25 03:16:53 +01:00
Parse the meta.ini from buffer
This commit is contained in:
parent
9c8e69003d
commit
4e8f62248b
@ -12,6 +12,7 @@
|
||||
#include <coreinit/debug.h>
|
||||
#include <coreinit/thread.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <map>
|
||||
|
||||
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;
|
||||
}
|
@ -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);
|
||||
int32_t CheckFile(const char *filepath);
|
||||
|
||||
int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size);
|
@ -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")) {
|
||||
|
Loading…
Reference in New Issue
Block a user