Read the meta.ini into memory on the heap

This commit is contained in:
Maschell 2022-02-14 19:30:59 +01:00
parent 40592af3df
commit 0f10ccc487

View File

@ -13,6 +13,7 @@
#include <coreinit/title.h> #include <coreinit/title.h>
#include <cstring> #include <cstring>
#include <fs/DirList.h> #include <fs/DirList.h>
#include <malloc.h>
#include <nn/acp.h> #include <nn/acp.h>
#include <rpxloader.h> #include <rpxloader.h>
#include <sysapp/title.h> #include <sysapp/title.h>
@ -211,21 +212,26 @@ void readCustomTitlesFromSD() {
uint32_t file_handle = 0; uint32_t file_handle = 0;
if (RL_FileOpen("romfscheck:/meta/meta.ini", &file_handle) == 0) { if (RL_FileOpen("romfscheck:/meta/meta.ini", &file_handle) == 0) {
// this buffer should be big enough for our .ini // this buffer should be big enough for our .ini
char ini_buffer[0x1000]; char *ini_buffer = (char *) memalign(0x40, 0x1000);
memset(ini_buffer, 0, sizeof(ini_buffer)); if (ini_buffer) {
uint32_t offset = 0; memset(ini_buffer, 0, 0x1000);
uint32_t toRead = sizeof(ini_buffer); uint32_t offset = 0;
do { uint32_t toRead = 0x1000;
int res = RL_FileRead(file_handle, reinterpret_cast<uint8_t *>(&ini_buffer[offset]), toRead); do {
if (res <= 0) { int res = RL_FileRead(file_handle, reinterpret_cast<uint8_t *>(&ini_buffer[offset]), toRead);
break; if (res <= 0) {
} break;
offset += res; }
toRead -= res; offset += res;
} while (offset < sizeof(ini_buffer)); toRead -= res;
} while (offset < sizeof(ini_buffer));
if (ini_parse_string(ini_buffer, handler, &gFileInfos[j]) < 0) { if (ini_parse_string(ini_buffer, handler, &gFileInfos[j]) < 0) {
DEBUG_FUNCTION_LINE("Failed to parse ini"); DEBUG_FUNCTION_LINE("Failed to parse ini");
}
free(ini_buffer);
} else {
DEBUG_FUNCTION_LINE("Failed to alloc memory");
} }
RL_FileClose(file_handle); RL_FileClose(file_handle);