summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2024-06-15 16:43:38 +0200
committerGitHub <noreply@github.com>2024-06-15 16:43:38 +0200
commita95c3dbc974ab08460ac10797babb49d51d18d6e (patch)
tree68e2ec9e6ed54b3e6c1ca520f79a44f937dabc9e /Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp
parentf71d6498d0a5f3f48787867c0d99737260867609 (diff)
parent50b95bbea998f0e677edf0c10b3e1e535f510782 (diff)
Merge pull request #12818 from iwubcode/json_file_operations
Common: add Json helper utilities for loading or saving to a file
Diffstat (limited to 'Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp')
-rw-r--r--Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp62
1 files changed, 20 insertions, 42 deletions
diff --git a/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp b/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp
index be5159b448..90d77d8ec9 100644
--- a/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp
+++ b/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp
@@ -10,6 +10,7 @@
#include "Common/FileUtil.h"
#include "Common/IOFile.h"
+#include "Common/JsonUtil.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "VideoCommon/Assets/MaterialAsset.h"
@@ -133,24 +134,16 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadPixelShader(const
return {};
}
- std::string json_data;
- if (!File::ReadFileToString(PathToString(metadata->second), json_data))
- {
- ERROR_LOG_FMT(VIDEO, "Asset '{}' error - failed to load the json file '{}',", asset_id,
- PathToString(metadata->second));
- return {};
- }
-
picojson::value root;
- const auto error = picojson::parse(root, json_data);
-
- if (!error.empty())
+ std::string error;
+ if (!JsonFromFile(PathToString(metadata->second), &root, &error))
{
ERROR_LOG_FMT(VIDEO,
"Asset '{}' error - failed to load the json file '{}', due to parse error: {}",
asset_id, PathToString(metadata->second), error);
return {};
}
+
if (!root.is<picojson::object>())
{
ERROR_LOG_FMT(
@@ -181,18 +174,21 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMaterial(const As
}
const auto& asset_path = asset_map.begin()->second;
- std::string json_data;
- if (!File::ReadFileToString(PathToString(asset_path), json_data))
+ std::size_t metadata_size;
{
- ERROR_LOG_FMT(VIDEO, "Asset '{}' error - material failed to load the json file '{}',",
- asset_id, PathToString(asset_path));
- return {};
+ std::error_code ec;
+ metadata_size = std::filesystem::file_size(asset_path, ec);
+ if (ec)
+ {
+ ERROR_LOG_FMT(VIDEO, "Asset '{}' error - failed to get material file size with error '{}'!",
+ asset_id, ec);
+ return {};
+ }
}
picojson::value root;
- const auto error = picojson::parse(root, json_data);
-
- if (!error.empty())
+ std::string error;
+ if (!JsonFromFile(PathToString(asset_path), &root, &error))
{
ERROR_LOG_FMT(
VIDEO,
@@ -220,7 +216,7 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMaterial(const As
return {};
}
- return LoadInfo{json_data.size(), GetLastAssetWriteTime(asset_id)};
+ return LoadInfo{metadata_size, GetLastAssetWriteTime(asset_id)};
}
CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMesh(const AssetID& asset_id,
@@ -292,18 +288,9 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMesh(const AssetI
return {};
}
- std::string json_data;
- if (!File::ReadFileToString(PathToString(metadata->second), json_data))
- {
- ERROR_LOG_FMT(VIDEO, "Asset '{}' error - failed to load the json file '{}'!", asset_id,
- PathToString(metadata->second));
- return {};
- }
-
picojson::value root;
- const auto error = picojson::parse(root, json_data);
-
- if (!error.empty())
+ std::string error;
+ if (!JsonFromFile(PathToString(metadata->second), &root, &error))
{
ERROR_LOG_FMT(VIDEO,
"Asset '{}' error - failed to load the json file '{}', due to parse error: {}",
@@ -362,18 +349,9 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const Ass
return {};
}
- std::string json_data;
- if (!File::ReadFileToString(PathToString(metadata->second), json_data))
- {
- ERROR_LOG_FMT(VIDEO, "Asset '{}' error - failed to load the json file '{}',", asset_id,
- PathToString(metadata->second));
- return {};
- }
-
picojson::value root;
- const auto error = picojson::parse(root, json_data);
-
- if (!error.empty())
+ std::string error;
+ if (!JsonFromFile(PathToString(metadata->second), &root, &error))
{
ERROR_LOG_FMT(VIDEO,
"Asset '{}' error - failed to load the json file '{}', due to parse error: {}",