Fixed bug when reading text files using internal file system

Small oversight causing defect, but found during extensive tests and code inspection.
This commit is contained in:
Kawe Mazidjatari 2022-09-01 01:05:15 +02:00
parent 41fda3a8ac
commit d946f9d1a1
2 changed files with 8 additions and 4 deletions

View File

@ -340,16 +340,18 @@ void MOD_PreloadPakFile(const string& svLevelName)
ostringstream ostream; ostringstream ostream;
ostream << "scripts/levels/settings/" << svLevelName << ".json"; ostream << "scripts/levels/settings/" << svLevelName << ".json";
FileHandle_t pFile = FileSystem()->Open(ostream.str().c_str(), "rb"); FileHandle_t pFile = FileSystem()->Open(ostream.str().c_str(), "rt");
if (!pFile) if (!pFile)
return; return;
uint32_t nLen = FileSystem()->Size(pFile); uint32_t nLen = FileSystem()->Size(pFile);
uint8_t* pBuf = MemAllocSingleton()->Alloc<uint8_t>(nLen); uint8_t* pBuf = MemAllocSingleton()->Alloc<uint8_t>(nLen);
FileSystem()->Read(pBuf, nLen, pFile); int nRead = FileSystem()->Read(pBuf, nLen, pFile);
FileSystem()->Close(pFile); FileSystem()->Close(pFile);
pBuf[nRead] = '\0';
try try
{ {
nlohmann::json jsIn = nlohmann::json::parse(pBuf); nlohmann::json jsIn = nlohmann::json::parse(pBuf);

View File

@ -19,15 +19,17 @@ void StreamDB_Init(const char* pszLevelName)
ostringstream ostream; ostringstream ostream;
ostream << "scripts/levels/settings/" << pszLevelName << ".json"; ostream << "scripts/levels/settings/" << pszLevelName << ".json";
FileHandle_t pFile = FileSystem()->Open(ostream.str().c_str(), "rb"); FileHandle_t pFile = FileSystem()->Open(ostream.str().c_str(), "rt");
if (pFile) if (pFile)
{ {
uint32_t nLen = FileSystem()->Size(pFile); uint32_t nLen = FileSystem()->Size(pFile);
uint8_t* pBuf = MemAllocSingleton()->Alloc<uint8_t>(nLen); uint8_t* pBuf = MemAllocSingleton()->Alloc<uint8_t>(nLen);
FileSystem()->Read(pBuf, nLen, pFile); int nRead = FileSystem()->Read(pBuf, nLen, pFile);
FileSystem()->Close(pFile); FileSystem()->Close(pFile);
pBuf[nRead] = '\0';
try try
{ {
nlohmann::json jsIn = nlohmann::json::parse(pBuf); nlohmann::json jsIn = nlohmann::json::parse(pBuf);