2023-05-02 19:26:49 +01:00
|
|
|
#include "core/stdafx.h"
|
|
|
|
#include <tier0/memstd.h>
|
|
|
|
#include "tier1/utlbuffer.h"
|
|
|
|
#include <filesystem/filesystem.h>
|
|
|
|
#include "vpc/rson.h"
|
|
|
|
|
|
|
|
RSON::Node_t* RSON::LoadFromBuffer(const char* pszBufferName, char* pBuffer, RSON::eFieldType rootType)
|
|
|
|
{
|
|
|
|
return RSON_LoadFromBuffer(pszBufferName, pBuffer, rootType, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
RSON::Node_t* RSON::LoadFromFile(const char* pszFilePath)
|
|
|
|
{
|
|
|
|
if (FileSystem()->FileExists(pszFilePath, "GAME"))
|
|
|
|
{
|
|
|
|
FileHandle_t file = FileSystem()->Open(pszFilePath, "rt");
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
uint32_t nFileSize = FileSystem()->Size(file);
|
|
|
|
|
2023-06-26 22:34:24 +02:00
|
|
|
std::unique_ptr<char[]> fileBuf(new char[nFileSize + 1]);
|
2023-05-02 19:26:49 +01:00
|
|
|
|
2023-06-26 22:34:24 +02:00
|
|
|
int nRead = FileSystem()->Read(fileBuf.get(), nFileSize, file);
|
2023-05-02 19:26:49 +01:00
|
|
|
FileSystem()->Close(file);
|
|
|
|
|
|
|
|
fileBuf[nRead] = '\0';
|
|
|
|
|
2023-06-26 22:34:24 +02:00
|
|
|
RSON::Node_t* node = RSON::LoadFromBuffer(pszFilePath, fileBuf.get(), eFieldType::RSON_OBJECT);
|
2023-05-02 19:26:49 +01:00
|
|
|
|
|
|
|
if (node)
|
|
|
|
return node;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// [rexx]: not sure if this should be fatal or not. ideally this should be handled appropriately
|
|
|
|
// in the calling function
|
|
|
|
Error(eDLL_T::ENGINE, NO_ERROR, "Error loading file '%s'\n", pszFilePath);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|