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