mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
RSON::LoadFromFile light cleanup and bug fix
Remove 'FileExists' check, if open fails, NULL file handle is returned and we just check on that. Also, commit 'a90302f0' introduced the option to open RSON files from path ID's, but the ID was only passed in the FileExist function, the actual 'Open' call did not receive the path ID argument, and therefore, did not open from there.
This commit is contained in:
parent
4e8b27a1e9
commit
91a8ad7cfd
@ -11,33 +11,29 @@ RSON::Node_t* RSON::LoadFromBuffer(const char* pszBufferName, char* pBuffer, RSO
|
|||||||
|
|
||||||
RSON::Node_t* RSON::LoadFromFile(const char* pszFilePath, const char* pPathID)
|
RSON::Node_t* RSON::LoadFromFile(const char* pszFilePath, const char* pPathID)
|
||||||
{
|
{
|
||||||
if (FileSystem()->FileExists(pszFilePath, pPathID))
|
FileHandle_t file = FileSystem()->Open(pszFilePath, "rt", pPathID);
|
||||||
|
|
||||||
|
if (!file)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
unsigned int nFileSize = FileSystem()->Size(file);
|
||||||
|
std::unique_ptr<char[]> fileBuf(new char[nFileSize + 1]);
|
||||||
|
|
||||||
|
int nRead = FileSystem()->Read(fileBuf.get(), nFileSize, file);
|
||||||
|
FileSystem()->Close(file);
|
||||||
|
|
||||||
|
fileBuf[nRead] = '\0';
|
||||||
|
|
||||||
|
RSON::Node_t* node = RSON::LoadFromBuffer(pszFilePath, fileBuf.get(), eFieldType::RSON_OBJECT);
|
||||||
|
|
||||||
|
if (node)
|
||||||
|
return node;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
FileHandle_t file = FileSystem()->Open(pszFilePath, "rt");
|
// [rexx]: not sure if this should be fatal or not. ideally this should be handled appropriately
|
||||||
|
// in the calling function
|
||||||
if (!file)
|
Error(eDLL_T::ENGINE, NO_ERROR, "Error loading file '%s'\n", pszFilePath);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
uint32_t nFileSize = FileSystem()->Size(file);
|
|
||||||
|
|
||||||
std::unique_ptr<char[]> fileBuf(new char[nFileSize + 1]);
|
|
||||||
|
|
||||||
int nRead = FileSystem()->Read(fileBuf.get(), nFileSize, file);
|
|
||||||
FileSystem()->Close(file);
|
|
||||||
|
|
||||||
fileBuf[nRead] = '\0';
|
|
||||||
|
|
||||||
RSON::Node_t* node = RSON::LoadFromBuffer(pszFilePath, fileBuf.get(), eFieldType::RSON_OBJECT);
|
|
||||||
|
|
||||||
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;
|
return NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user