Fix json parsing error handling, other small fixes

This commit is contained in:
Maschell
2024-11-29 20:17:30 +01:00
parent d989801b36
commit 82445acaf0
13 changed files with 88 additions and 46 deletions

View File

@@ -116,22 +116,22 @@ void CustomDynLoadFree(void *addr) {
}
}
bool ParseJsonFromFile(const std::string &filePath, nlohmann::json &outJson) {
UtilsIOError ParseJsonFromFile(const std::string &filePath, nlohmann::json &outJson) {
CFile file(filePath, CFile::ReadOnly);
if (!file.isOpen() || file.size() == 0) {
return false;
return UTILS_IO_ERROR_NOT_FOUND;
}
auto *json_data = (uint8_t *) memalign(0x40, ROUNDUP(file.size() + 1, 0x40));
auto *json_data = static_cast<uint8_t *>(memalign(0x40, ROUNDUP(file.size() + 1, 0x40)));
if (!json_data) {
return false;
return UTILS_IO_ERROR_MALLOC_FAILED;
}
bool result = true;
auto result = UTILS_IO_ERROR_SUCCESS;
uint64_t readRes = file.read(json_data, file.size());
if (readRes == file.size()) {
json_data[file.size()] = '\0';
outJson = nlohmann::json::parse(json_data, nullptr, false);
} else {
result = false;
result = UTILS_IO_ERROR_GENERIC;
}
file.close();
free(json_data);