Merge pull request #3685 from aws-lumberyard-dev/cgalvan/UpdateProjectConfiguratorReferences
Updated remaining Project Configurator references to Project Manager and consolidated JsonUtils API usage.
This commit is contained in:
@@ -209,6 +209,11 @@ namespace AZ
|
||||
|
||||
AZ::Outcome<rapidjson::Document, AZStd::string> ReadJsonString(AZStd::string_view jsonText)
|
||||
{
|
||||
if (jsonText.empty())
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Failed to parse JSON: input string is empty."));
|
||||
}
|
||||
|
||||
rapidjson::Document jsonDocument;
|
||||
jsonDocument.Parse<rapidjson::kParseCommentsFlag>(jsonText.data(), jsonText.size());
|
||||
if (jsonDocument.HasParseError())
|
||||
|
||||
@@ -36,28 +36,6 @@ namespace AzFramework
|
||||
{
|
||||
namespace Internal
|
||||
{
|
||||
//! Save a JSON document to a stream. Otherwise returns a failure with error message.
|
||||
AZ::Outcome<void, AZStd::string> WriteJsonToStream(const rapidjson::Document& document, AZ::IO::GenericStream& stream, WriteJsonSettings settings = WriteJsonSettings{})
|
||||
{
|
||||
AZ::IO::RapidJSONStreamWriter jsonStreamWriter(&stream);
|
||||
|
||||
rapidjson::PrettyWriter<AZ::IO::RapidJSONStreamWriter> writer(jsonStreamWriter);
|
||||
|
||||
if (settings.m_maxDecimalPlaces >= 0)
|
||||
{
|
||||
writer.SetMaxDecimalPlaces(settings.m_maxDecimalPlaces);
|
||||
}
|
||||
|
||||
if (document.Accept(writer))
|
||||
{
|
||||
return AZ::Success();
|
||||
}
|
||||
else
|
||||
{
|
||||
return AZ::Failure(AZStd::string{ "Json Writer failed" });
|
||||
}
|
||||
}
|
||||
|
||||
static bool FindFilesInPath(const AZStd::string& folder, const AZStd::string& filter, bool recurseSubFolders, AZStd::list<AZStd::string>& fileList)
|
||||
{
|
||||
AZStd::string file_filter = folder;
|
||||
@@ -107,210 +85,8 @@ namespace AzFramework
|
||||
{
|
||||
return AZStd::string("(^|\\n\\s*)" + key + "([ \\t]*)=([ \\t]*)(.*)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces a value in an ini-style content.
|
||||
*
|
||||
* \param[in] cfgContents The contents of the ini-style file
|
||||
* \param[in] header The optional group title for the key
|
||||
* \param[in] key The key of the value to replace
|
||||
* \param[in] newValue The value to assign to the key
|
||||
*
|
||||
* \returns Void on success, error message on failure.
|
||||
*
|
||||
* If key has multiple values, it does not preserve other values.
|
||||
* enabled_game_projects = oldProject1, oldProject2, oldProject3
|
||||
* becomes
|
||||
* enabled_game_projects = newProject
|
||||
* Cases to handle:
|
||||
* 1. Key exists, value is identical -> do nothing
|
||||
* This can occur if a user modifies a config file while the tooling is open.
|
||||
* Example:
|
||||
* 1) Load Project Configurator.
|
||||
* 2) Modify your bootstrap.cfg to a different project.
|
||||
* 3) Tell Project Configurator to set your project to the project you set in #2.
|
||||
* 2. Key exists, value is missing -> stomps over key with new key value pair.
|
||||
* 3. Key exists, value is different -> stomps over key with new key value pair. Ignores previous values.
|
||||
* 4. Key does not exist, header is not required -> insert "key=value" at the end of file.
|
||||
* 5. Key does not exist, required header does not exist -> insert "\nHeader\n" at end of file and continue to #6.
|
||||
* 6. Key does not exist, required header does exist -> insert "key=value" at next line under the header.
|
||||
* The header will always exist at this point, it was created in the previous check if it was missing.
|
||||
*/
|
||||
AZ::Outcome<void, AZStd::string> UpdateCfgContents(AZStd::string& cfgContents, const AZStd::string& header, const AZStd::string& key, const AZStd::string& value)
|
||||
{
|
||||
// Generate regex str and replacement str
|
||||
AZStd::string lhsStr = key;
|
||||
AZStd::string regexStr = BuildConfigKeyValueRegex(lhsStr);
|
||||
AZStd::string gameFolderAssignment = "$1" + lhsStr + "$2=$03" + value;
|
||||
|
||||
// Replace the current key with the new value
|
||||
// AZStd's regex was not functional at the time this was authored, so convert to std from AZStd.
|
||||
std::regex sysGameRegex(regexStr.c_str());
|
||||
std::smatch matchResults;
|
||||
std::string settingsFileContentsStdStr = cfgContents.c_str();
|
||||
bool matchFound = std::regex_search(settingsFileContentsStdStr, matchResults, sysGameRegex);
|
||||
|
||||
std::string result;
|
||||
if (matchFound)
|
||||
{
|
||||
// Case 1, 2, and 3 - Key value pair exists, stomp over the key with a new value pair.
|
||||
result = std::regex_replace(cfgContents.c_str(), sysGameRegex, gameFolderAssignment.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cases 4 through 6 - the key does not exist.
|
||||
result = cfgContents.c_str();
|
||||
std::size_t insertLocation = 0;
|
||||
// Case 5 & 6 - key does not exist, header is required
|
||||
if (!header.empty())
|
||||
{
|
||||
insertLocation = result.find(header.c_str());
|
||||
// Case 6 - key does not exist, header does exist.
|
||||
// Set the key insertion point to right after the header.
|
||||
if (insertLocation != std::string::npos)
|
||||
{
|
||||
insertLocation += header.length();
|
||||
}
|
||||
// Case 5 - key does not exist, required header does not exist.
|
||||
// Insert the header at the top of the file, set the key insertion point after the header.
|
||||
else
|
||||
{
|
||||
AZStd::string headerAndCr = AZStd::string::format("\n%s\n", header.c_str());
|
||||
result.insert(result.length(), headerAndCr.c_str());
|
||||
insertLocation = result.length() - 1;
|
||||
}
|
||||
}
|
||||
// Case 4 - key does not exist, header is not required.
|
||||
// Case 5 & 6 - the header has been added.
|
||||
// Insert the key at the tracked insertion point
|
||||
AZStd::string newConfigData = AZStd::string::format("\n%s=%s", key.c_str(), value.c_str());
|
||||
result.insert(insertLocation, newConfigData.c_str());
|
||||
}
|
||||
cfgContents = result.c_str();
|
||||
return AZ::Success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a configuration (ini) style contents string representation with a list of replacement string rules
|
||||
*
|
||||
* \param[in] cfgContents The contents of the ini file to update
|
||||
* \param[in] updateRules The update rules (list of update strings, see below) to apply
|
||||
*
|
||||
* The replace string rule format follows the following:
|
||||
* ([header]/)[key]=[value]
|
||||
*
|
||||
* where:
|
||||
* header (optional) : Optional group title for the key
|
||||
* key : The key to lookup or create for the value
|
||||
* value : The value to update or create
|
||||
*/
|
||||
AZ::Outcome<void, AZStd::string> UpdateCfgContents(AZStd::string& cfgContents, const AZStd::list<AZStd::string>& updateRules)
|
||||
{
|
||||
AZStd::string updateCfgContents = cfgContents;
|
||||
for (const AZStd::string& updateRule : updateRules)
|
||||
{
|
||||
// Since we are parsing manually anyways, no need to do a regex validation
|
||||
AZStd::string::size_type headerKeySep = updateRule.find_first_of('/');
|
||||
bool hasHeader = (headerKeySep != AZStd::string::npos);
|
||||
AZStd::string::size_type keyValueSep = updateRule.find_first_of('=', !hasHeader ? 0 : headerKeySep + 1);
|
||||
if (keyValueSep == AZStd::string::npos)
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("Invalid update config rule '%s'. Must be in the format ([header]/)[key]=[value]", updateRule.c_str()));
|
||||
}
|
||||
AZStd::string header = hasHeader ? updateRule.substr(0, headerKeySep) : AZStd::string("");
|
||||
AZStd::string key = hasHeader ? updateRule.substr(headerKeySep + 1, keyValueSep - (headerKeySep + 1)) : updateRule.substr(0, keyValueSep);
|
||||
AZStd::string value = updateRule.substr(keyValueSep + 1);
|
||||
|
||||
auto updateResult = UpdateCfgContents(updateCfgContents, header, key, value);
|
||||
if (!updateResult.IsSuccess())
|
||||
{
|
||||
return updateResult;
|
||||
}
|
||||
}
|
||||
cfgContents = updateCfgContents;
|
||||
return AZ::Success();
|
||||
}
|
||||
} // namespace Internal
|
||||
|
||||
AZ::Outcome<void, AZStd::string> WriteJsonToString(const rapidjson::Document& document, AZStd::string& jsonText, WriteJsonSettings settings)
|
||||
{
|
||||
AZ::IO::ByteContainerStream<AZStd::string> stream{ &jsonText };
|
||||
return Internal::WriteJsonToStream(document, stream, settings);
|
||||
}
|
||||
|
||||
AZ::Outcome<rapidjson::Document, AZStd::string> ReadJsonFromString(AZStd::string_view jsonText)
|
||||
{
|
||||
if (jsonText.empty())
|
||||
{
|
||||
return AZ::Failure(AZStd::string("Failed to parse JSON: input string is empty."));
|
||||
}
|
||||
|
||||
rapidjson::Document jsonDocument;
|
||||
jsonDocument.Parse<rapidjson::kParseCommentsFlag>(jsonText.data(), jsonText.size());
|
||||
if (jsonDocument.HasParseError())
|
||||
{
|
||||
size_t lineNumber = 1;
|
||||
|
||||
const size_t errorOffset = jsonDocument.GetErrorOffset();
|
||||
for (size_t searchOffset = jsonText.find('\n');
|
||||
searchOffset < errorOffset && searchOffset < AZStd::string::npos;
|
||||
searchOffset = jsonText.find('\n', searchOffset + 1))
|
||||
{
|
||||
lineNumber++;
|
||||
}
|
||||
|
||||
return AZ::Failure(AZStd::string::format("JSON parse error at line %zu: %s", lineNumber, rapidjson::GetParseError_En(jsonDocument.GetParseError())));
|
||||
}
|
||||
else
|
||||
{
|
||||
return AZ::Success(AZStd::move(jsonDocument));
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Outcome<rapidjson::Document, AZStd::string> ReadJsonFile(const AZ::IO::Path& jsonFilePath, AZ::IO::FileIOBase* overrideFileIO /*= nullptr*/, size_t maxFileSize /*= AZ::Utils::DefaultMaxFileSize*/)
|
||||
{
|
||||
AZ::IO::FileIOBase* fileIo = overrideFileIO != nullptr ? overrideFileIO : AZ::IO::FileIOBase::GetInstance();
|
||||
if (fileIo == nullptr)
|
||||
{
|
||||
return AZ::Failure(AZStd::string("No FileIO instance present."));
|
||||
}
|
||||
|
||||
// Read into memory first and then parse the JSON, rather than passing a file stream to rapidjson.
|
||||
// This should avoid creating a large number of micro-reads from the file.
|
||||
|
||||
auto readResult = AZ::Utils::ReadFile(jsonFilePath.String(), maxFileSize);
|
||||
if (!readResult.IsSuccess())
|
||||
{
|
||||
return AZ::Failure(readResult.GetError());
|
||||
}
|
||||
|
||||
AZStd::string jsonContent = readResult.TakeValue();
|
||||
|
||||
auto result = ReadJsonFromString(jsonContent);
|
||||
if (!result.IsSuccess())
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("Failed to load '%s'. %s", jsonFilePath.c_str(), result.GetError().c_str()));
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Outcome<void, AZStd::string> WriteJsonFile(const rapidjson::Document& jsonDoc, const AZ::IO::Path& jsonFilePath, WriteJsonSettings settings)
|
||||
{
|
||||
// Write the JSON into memory first and then write the file, rather than passing a file stream to rapidjson.
|
||||
// This should avoid creating a large number of micro-writes to the file.
|
||||
AZStd::string fileContent;
|
||||
auto outcome = WriteJsonToString(jsonDoc, fileContent, settings);
|
||||
if (!outcome.IsSuccess())
|
||||
{
|
||||
return outcome;
|
||||
}
|
||||
|
||||
return AZ::Utils::WriteFile(fileContent, jsonFilePath.String());
|
||||
}
|
||||
|
||||
AZ::Outcome<AZStd::list<AZStd::string>, AZStd::string> FindFilesInPath(const AZStd::string& folder, const AZStd::string& filter, bool recurseSubFolders)
|
||||
{
|
||||
AZStd::list<AZStd::string> fileList;
|
||||
@@ -348,61 +124,6 @@ namespace AzFramework
|
||||
return AZ::Success();
|
||||
}
|
||||
|
||||
AZ::Outcome<void, AZStd::string> ReplaceInCfgFile(const AZStd::string& filePath, const AZStd::list<AZStd::string>& updateRules)
|
||||
{
|
||||
if (!AZ::IO::SystemFile::Exists(filePath.c_str()))
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("Cfg file '%s' does not exist.", filePath.c_str()));
|
||||
}
|
||||
|
||||
// Load the settings file into a string
|
||||
AZ::IO::SystemFile settingsFile;
|
||||
if (!settingsFile.Open(filePath.c_str(), AZ::IO::SystemFile::SF_OPEN_READ_ONLY))
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("Error reading cfg file '%s'.", filePath.c_str()));
|
||||
}
|
||||
|
||||
AZStd::string settingsFileContents(settingsFile.Length(), '\0');
|
||||
settingsFile.Read(settingsFileContents.size(), settingsFileContents.data());
|
||||
settingsFile.Close();
|
||||
|
||||
auto updateContentResult = Internal::UpdateCfgContents(settingsFileContents, updateRules);
|
||||
if (!updateContentResult.IsSuccess())
|
||||
{
|
||||
return updateContentResult;
|
||||
}
|
||||
|
||||
// Write the result.
|
||||
if (!settingsFile.ReOpen(AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY | AZ::IO::SystemFile::SF_OPEN_TRUNCATE))
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("Failed to open settings file %s.", filePath.c_str()));
|
||||
}
|
||||
auto bytesWritten = settingsFile.Write(settingsFileContents.c_str(), settingsFileContents.size());
|
||||
settingsFile.Close();
|
||||
|
||||
if (bytesWritten != settingsFileContents.size())
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("Failed to write to config file %s.", filePath.c_str()));
|
||||
}
|
||||
|
||||
return AZ::Success();
|
||||
}
|
||||
|
||||
AZ::Outcome<void, AZStd::string> ReplaceInCfgFile(const AZStd::string& filePath, const char* header, const AZStd::string& key, const AZStd::string& newValue)
|
||||
{
|
||||
if (key.length() <= 0)
|
||||
{
|
||||
return AZ::Failure(AZStd::string("'key' parameter for ReplaceInCfgFile must not be empty"));
|
||||
}
|
||||
|
||||
AZStd::string updateRule = (header != nullptr) ? AZStd::string::format("%s/%s=%s", header, key.c_str(), newValue.c_str()) : AZStd::string::format("%s=%s", key.c_str(), newValue.c_str());
|
||||
AZStd::list<AZStd::string> updateRules{
|
||||
updateRule
|
||||
};
|
||||
auto replaceResult = ReplaceInCfgFile(filePath, updateRules);
|
||||
return replaceResult;
|
||||
}
|
||||
|
||||
AZ::Outcome<AZStd::string, AZStd::string> GetValueForKeyInCfgFile(const AZStd::string& filePath, const char* key)
|
||||
{
|
||||
AZ::Outcome<AZStd::string, AZStd::string> subCommandResult = GetCfgFileContents(filePath);
|
||||
|
||||
@@ -27,49 +27,6 @@ namespace AzFramework
|
||||
{
|
||||
namespace FileFunc
|
||||
{
|
||||
struct WriteJsonSettings
|
||||
{
|
||||
int m_maxDecimalPlaces = -1; // -1 means use default
|
||||
};
|
||||
|
||||
/*
|
||||
* Read a string into a JSON document
|
||||
*
|
||||
* \param[in] jsonText The string of JSON to parse into a JSON document.
|
||||
* \return Outcome<rapidjson::Document) Returns a failure with error message if the content is not valid JSON.
|
||||
*/
|
||||
AZ::Outcome<rapidjson::Document, AZStd::string> ReadJsonFromString(AZStd::string_view jsonText);
|
||||
|
||||
/*
|
||||
* Read a text file into a JSON document
|
||||
*
|
||||
* \param[in] jsonFilePath The path to the JSON file path to open
|
||||
* \param[in] overrideFileIO Optional file IO instance to use. If null, use the Singleton instead
|
||||
* \param[in] maxFileSize The maximum size, in bytes, of the file to read. Defaults to 1 MB.
|
||||
* \return Outcome(rapidjson::Document) Returns a failure with error message if the content is not valid JSON.
|
||||
*/
|
||||
AZ::Outcome<rapidjson::Document, AZStd::string> ReadJsonFile(const AZ::IO::Path& jsonFilePath, AZ::IO::FileIOBase* overrideFileIO = nullptr, size_t maxFileSize = AZ::Utils::DefaultMaxFileSize);
|
||||
|
||||
/**
|
||||
* Write a JSON document to a string
|
||||
*
|
||||
* \param[in] jsonDoc The JSON document to write to a text file
|
||||
* \param[out] jsonFilePath The string that the JSON text will be written to.
|
||||
* \param[in] settings Settings to pass along to the JSON writer.
|
||||
* \return StringOutcome Saves the JSON document to text. Otherwise returns a failure with error message.
|
||||
*/
|
||||
AZ::Outcome<void, AZStd::string> WriteJsonToString(const rapidjson::Document& document, AZStd::string& jsonText, WriteJsonSettings settings = WriteJsonSettings{});
|
||||
|
||||
/**
|
||||
* Write a JSON document to a text file
|
||||
*
|
||||
* \param[in] jsonDoc The JSON document to write to a text file
|
||||
* \param[in] jsonFilePath The path to the JSON file path to write to
|
||||
* \param[in] settings Settings to pass along to the JSON writer.
|
||||
* \return StringOutcome Saves the JSON document to a file. Otherwise returns a failure with error message.
|
||||
*/
|
||||
AZ::Outcome<void, AZStd::string> WriteJsonFile(const rapidjson::Document& jsonDoc, const AZ::IO::Path& jsonFilePath, WriteJsonSettings settings = WriteJsonSettings{});
|
||||
|
||||
/**
|
||||
* Find all the files in a path based on an optional filter. Recurse if requested.
|
||||
*
|
||||
@@ -91,38 +48,6 @@ namespace AzFramework
|
||||
*/
|
||||
AZ::Outcome<void, AZStd::string> ReadTextFileByLine(const AZStd::string& filePath, AZStd::function<bool(const char* line)> perLineCallback);
|
||||
|
||||
/**
|
||||
* Replaces a value in an ini-style file.
|
||||
*
|
||||
* \param[in] filePath The path to the config file to update
|
||||
* \param[in] updateRules The update rules (list of update strings, see below) to apply
|
||||
*
|
||||
* The replace string rule format follows the following:
|
||||
* ([header]/)[key]=[value]
|
||||
*
|
||||
* where:
|
||||
* header (optional) : Optional group title for the key
|
||||
* key : The key to lookup or create for the value
|
||||
* value : The value to update or create
|
||||
*/
|
||||
AZ::Outcome<void, AZStd::string> ReplaceInCfgFile(const AZStd::string& filePath, const AZStd::list<AZStd::string>& updateRules);
|
||||
|
||||
/**
|
||||
* Replaces a value in an ini-style file.
|
||||
*
|
||||
* \param[in] filePath The path to the config file to update
|
||||
* \param[in] updateRule The update rule (list of update strings, see below) to apply
|
||||
*
|
||||
* The replace string rule format follows the following:
|
||||
* ([header]/)[key]=[value]
|
||||
*
|
||||
* where:
|
||||
* header (optional) : Optional group title for the key
|
||||
* key : The key to lookup or create for the value
|
||||
* value : The value to update or create
|
||||
*/
|
||||
AZ::Outcome<void, AZStd::string> ReplaceInCfgFile(const AZStd::string& filePath, const char* header, const AZStd::string& key, const AZStd::string& newValue);
|
||||
|
||||
/**
|
||||
* Gets the value(s) for a key in an INI style config file.
|
||||
*
|
||||
|
||||
@@ -11,11 +11,12 @@
|
||||
|
||||
#include <AzCore/Component/Entity.h>
|
||||
#include <AzCore/IO/Path/Path.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
|
||||
#include <AzCore/StringFunc/StringFunc.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
|
||||
#include <AzFramework/Asset/AssetSystemBus.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabDomUtils.h>
|
||||
@@ -134,7 +135,7 @@ namespace AzToolsFramework
|
||||
}
|
||||
|
||||
// Read Template's prefab file from disk and parse Prefab DOM from file.
|
||||
AZ::Outcome<PrefabDom, AZStd::string> readPrefabFileResult = AzFramework::FileFunc::ReadJsonFromString(fileContent);
|
||||
AZ::Outcome<PrefabDom, AZStd::string> readPrefabFileResult = AZ::JsonSerializationUtils::ReadJsonString(fileContent);
|
||||
if (!readPrefabFileResult.IsSuccess())
|
||||
{
|
||||
AZ_Error(
|
||||
@@ -346,7 +347,7 @@ namespace AzToolsFramework
|
||||
return false;
|
||||
}
|
||||
|
||||
auto outcome = AzFramework::FileFunc::WriteJsonFile(domAndFilepath->first, GetFullPath(domAndFilepath->second));
|
||||
auto outcome = AZ::JsonSerializationUtils::WriteJsonFile(domAndFilepath->first, GetFullPath(domAndFilepath->second).Native());
|
||||
if (!outcome.IsSuccess())
|
||||
{
|
||||
AZ_Error(
|
||||
@@ -387,7 +388,7 @@ namespace AzToolsFramework
|
||||
return false;
|
||||
}
|
||||
|
||||
auto outcome = AzFramework::FileFunc::WriteJsonFile(domAndFilepath->first, absolutePath);
|
||||
auto outcome = AZ::JsonSerializationUtils::WriteJsonFile(domAndFilepath->first, absolutePath.Native());
|
||||
if (!outcome.IsSuccess())
|
||||
{
|
||||
AZ_Error(
|
||||
@@ -410,7 +411,7 @@ namespace AzToolsFramework
|
||||
return false;
|
||||
}
|
||||
|
||||
auto outcome = AzFramework::FileFunc::WriteJsonToString(domAndFilepath->first, output);
|
||||
auto outcome = AZ::JsonSerializationUtils::WriteJsonString(domAndFilepath->first, output);
|
||||
if (!outcome.IsSuccess())
|
||||
{
|
||||
AZ_Error(
|
||||
|
||||
@@ -26,20 +26,6 @@
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
namespace AzFramework
|
||||
{
|
||||
namespace FileFunc
|
||||
{
|
||||
namespace Internal
|
||||
{
|
||||
AZ::Outcome<void,AZStd::string> UpdateCfgContents(AZStd::string& cfgContents, const AZStd::list<AZStd::string>& updateRules);
|
||||
AZ::Outcome<void,AZStd::string> UpdateCfgContents(AZStd::string& cfgContents, const AZStd::string& header, const AZStd::string& key, const AZStd::string& value);
|
||||
AZ::Outcome<void, AZStd::string> WriteJsonToStream(const rapidjson::Document& document, AZ::IO::GenericStream& stream,
|
||||
WriteJsonSettings settings = WriteJsonSettings{});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
class FileFuncTest : public ScopedAllocatorSetupFixture
|
||||
@@ -62,110 +48,6 @@ namespace UnitTest
|
||||
AZ::IO::FileIOBase* m_prevFileIO;
|
||||
};
|
||||
|
||||
TEST_F(FileFuncTest, UpdateCfgContents_InValidInput_Fail)
|
||||
{
|
||||
AZStd::string cfgContents = "[Foo]\n";
|
||||
AZStd::list<AZStd::string> updateRules;
|
||||
|
||||
updateRules.push_back(AZStd::string("Foo/one*1"));
|
||||
auto result = AzFramework::FileFunc::Internal::UpdateCfgContents(cfgContents, updateRules);
|
||||
ASSERT_FALSE(result.IsSuccess());
|
||||
}
|
||||
|
||||
TEST_F(FileFuncTest, UpdateCfgContents_ValidInput_Success)
|
||||
{
|
||||
AZStd::string cfgContents =
|
||||
"[Foo]\n"
|
||||
"one =2 \n"
|
||||
"two= 3\n"
|
||||
"three = 4\n"
|
||||
"\n"
|
||||
"[Bar]\n"
|
||||
"four=3\n"
|
||||
"five=3\n"
|
||||
"six=3\n"
|
||||
"eight=3\n";
|
||||
|
||||
AZStd::list<AZStd::string> updateRules;
|
||||
|
||||
updateRules.push_back(AZStd::string("Foo/one=1"));
|
||||
updateRules.push_back(AZStd::string("Foo/two=2"));
|
||||
updateRules.push_back(AZStd::string("three=3"));
|
||||
auto result = AzFramework::FileFunc::Internal::UpdateCfgContents(cfgContents, updateRules);
|
||||
EXPECT_TRUE(result.IsSuccess());
|
||||
|
||||
AZStd::string compareCfgContents =
|
||||
"[Foo]\n"
|
||||
"one =1\n"
|
||||
"two= 2\n"
|
||||
"three = 3\n"
|
||||
"\n"
|
||||
"[Bar]\n"
|
||||
"four=3\n"
|
||||
"five=3\n"
|
||||
"six=3\n"
|
||||
"eight=3\n";
|
||||
|
||||
bool equals = cfgContents.compare(compareCfgContents) == 0;
|
||||
ASSERT_TRUE(equals);
|
||||
}
|
||||
|
||||
TEST_F(FileFuncTest, UpdateCfgContents_ValidInputNewEntrySameHeader_Success)
|
||||
{
|
||||
AZStd::string cfgContents =
|
||||
"[Foo]\n"
|
||||
"one =2 \n"
|
||||
"two= 3\n"
|
||||
"three = 4\n";
|
||||
|
||||
AZStd::string header("[Foo]");
|
||||
AZStd::string key("four");
|
||||
AZStd::string value("4");
|
||||
auto result = AzFramework::FileFunc::Internal::UpdateCfgContents(cfgContents, header, key, value);
|
||||
EXPECT_TRUE(result.IsSuccess());
|
||||
|
||||
AZStd::string compareCfgContents =
|
||||
"[Foo]\n"
|
||||
"four=4\n"
|
||||
"one =2 \n"
|
||||
"two= 3\n"
|
||||
"three = 4\n";
|
||||
|
||||
bool equals = cfgContents.compare(compareCfgContents) == 0;
|
||||
ASSERT_TRUE(equals);
|
||||
}
|
||||
|
||||
TEST_F(FileFuncTest, UpdateCfgContents_ValidInputNewEntryDifferentHeader_Success)
|
||||
{
|
||||
AZStd::string cfgContents =
|
||||
";Sample Data\n"
|
||||
"[Foo]\n"
|
||||
"one =2 \n"
|
||||
"two= 3\n"
|
||||
"three = 4\n";
|
||||
|
||||
AZStd::list<AZStd::string> updateRules;
|
||||
|
||||
AZStd::string header("[Bar]");
|
||||
AZStd::string key("four");
|
||||
AZStd::string value("4");
|
||||
auto result = AzFramework::FileFunc::Internal::UpdateCfgContents(cfgContents, header, key, value);
|
||||
EXPECT_TRUE(result.IsSuccess());
|
||||
|
||||
AZStd::string compareCfgContents =
|
||||
";Sample Data\n"
|
||||
"[Foo]\n"
|
||||
"one =2 \n"
|
||||
"two= 3\n"
|
||||
"three = 4\n"
|
||||
"\n"
|
||||
"[Bar]\n"
|
||||
"four=4\n";
|
||||
|
||||
bool equals = cfgContents.compare(compareCfgContents) == 0;
|
||||
ASSERT_TRUE(equals);
|
||||
}
|
||||
|
||||
static bool CreateDummyFile(const QString& fullPathToFile, const QString& tempStr = {})
|
||||
{
|
||||
QFileInfo fi(fullPathToFile);
|
||||
@@ -268,213 +150,4 @@ namespace UnitTest
|
||||
ASSERT_NE(findElement, result.GetValue().end());
|
||||
}
|
||||
}
|
||||
|
||||
class JsonFileFuncTest
|
||||
: public FrameworkApplicationFixture
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
FrameworkApplicationFixture::SetUp();
|
||||
|
||||
AZ::SettingsRegistryInterface* registry = AZ::SettingsRegistry::Get();
|
||||
auto projectPathKey =
|
||||
AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey) + "/project_path";
|
||||
registry->Set(projectPathKey, "AutomatedTesting");
|
||||
AZ::SettingsRegistryMergeUtils::MergeSettingsToRegistry_AddRuntimeFilePaths(*registry);
|
||||
|
||||
m_serializeContext = AZStd::make_unique<AZ::SerializeContext>();
|
||||
m_jsonRegistrationContext = AZStd::make_unique<AZ::JsonRegistrationContext>();
|
||||
m_jsonSystemComponent = AZStd::make_unique<AZ::JsonSystemComponent>();
|
||||
|
||||
m_serializationSettings.m_serializeContext = m_serializeContext.get();
|
||||
m_serializationSettings.m_registrationContext = m_jsonRegistrationContext.get();
|
||||
|
||||
m_deserializationSettings.m_serializeContext = m_serializeContext.get();
|
||||
m_deserializationSettings.m_registrationContext = m_jsonRegistrationContext.get();
|
||||
|
||||
m_jsonSystemComponent->Reflect(m_jsonRegistrationContext.get());
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
m_jsonRegistrationContext->EnableRemoveReflection();
|
||||
m_jsonSystemComponent->Reflect(m_jsonRegistrationContext.get());
|
||||
m_jsonRegistrationContext->DisableRemoveReflection();
|
||||
|
||||
m_jsonRegistrationContext.reset();
|
||||
m_serializeContext.reset();
|
||||
m_jsonSystemComponent.reset();
|
||||
|
||||
FrameworkApplicationFixture::TearDown();
|
||||
}
|
||||
|
||||
AZStd::unique_ptr<AZ::SerializeContext> m_serializeContext;
|
||||
AZStd::unique_ptr<AZ::JsonRegistrationContext> m_jsonRegistrationContext;
|
||||
AZStd::unique_ptr<AZ::JsonSystemComponent> m_jsonSystemComponent;
|
||||
|
||||
AZ::JsonSerializerSettings m_serializationSettings;
|
||||
AZ::JsonDeserializerSettings m_deserializationSettings;
|
||||
};
|
||||
|
||||
TEST_F(JsonFileFuncTest, WriteJsonString_ValidJson_ExpectSuccess)
|
||||
{
|
||||
rapidjson::Document document;
|
||||
document.SetObject();
|
||||
document.AddMember("a", 1, document.GetAllocator());
|
||||
document.AddMember("b", 2, document.GetAllocator());
|
||||
document.AddMember("c", 3, document.GetAllocator());
|
||||
|
||||
AZStd::string expectedJsonText =
|
||||
R"({
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3
|
||||
})";
|
||||
expectedJsonText.erase(AZStd::remove_if(expectedJsonText.begin(), expectedJsonText.end(), ::isspace), expectedJsonText.end());
|
||||
|
||||
AZStd::string outString;
|
||||
AZ::Outcome<void, AZStd::string> result = AzFramework::FileFunc::WriteJsonToString(document, outString);
|
||||
EXPECT_TRUE(result.IsSuccess());
|
||||
|
||||
outString.erase(AZStd::remove_if(outString.begin(), outString.end(), ::isspace), outString.end());
|
||||
EXPECT_EQ(expectedJsonText, outString) << "expected:\n" << expectedJsonText.c_str() << "\nactual:\n" << outString.c_str();
|
||||
}
|
||||
|
||||
TEST_F(JsonFileFuncTest, WriteJsonStream_ValidJson_ExpectSuccess)
|
||||
{
|
||||
rapidjson::Document document;
|
||||
document.SetObject();
|
||||
document.AddMember("a", 1, document.GetAllocator());
|
||||
document.AddMember("b", 2, document.GetAllocator());
|
||||
document.AddMember("c", 3, document.GetAllocator());
|
||||
|
||||
AZStd::string expectedJsonText =
|
||||
R"({
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3
|
||||
})";
|
||||
expectedJsonText.erase(AZStd::remove_if(expectedJsonText.begin(), expectedJsonText.end(), ::isspace), expectedJsonText.end());
|
||||
|
||||
AZStd::vector<char> outBuffer;
|
||||
AZ::IO::ByteContainerStream<AZStd::vector<char>> outStream{ &outBuffer };
|
||||
AZ::Outcome<void, AZStd::string> result = AzFramework::FileFunc::Internal::WriteJsonToStream(document, outStream);
|
||||
EXPECT_TRUE(result.IsSuccess());
|
||||
|
||||
outBuffer.push_back(0);
|
||||
AZStd::string outString = outBuffer.data();
|
||||
outString.erase(AZStd::remove_if(outString.begin(), outString.end(), ::isspace), outString.end());
|
||||
EXPECT_EQ(expectedJsonText, outString) << "expected:\n" << expectedJsonText.c_str() << "\nactual:\n" << outString.c_str();
|
||||
}
|
||||
|
||||
TEST_F(JsonFileFuncTest, WriteJsonFile_ValidJson_ExpectSuccess)
|
||||
{
|
||||
AZ::Test::ScopedAutoTempDirectory tempDir;
|
||||
|
||||
rapidjson::Document document;
|
||||
document.SetObject();
|
||||
document.AddMember("a", 1, document.GetAllocator());
|
||||
document.AddMember("b", 2, document.GetAllocator());
|
||||
document.AddMember("c", 3, document.GetAllocator());
|
||||
|
||||
AZStd::string expectedJsonText =
|
||||
R"({
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3
|
||||
})";
|
||||
expectedJsonText.erase(AZStd::remove_if(expectedJsonText.begin(), expectedJsonText.end(), ::isspace), expectedJsonText.end());
|
||||
|
||||
AZStd::string pathStr;
|
||||
AzFramework::StringFunc::Path::ConstructFull(tempDir.GetDirectory(), "test.json", pathStr, true);
|
||||
|
||||
// Write the JSON to a file
|
||||
AZ::IO::Path path(pathStr);
|
||||
AZ::Outcome<void, AZStd::string> saveResult = AzFramework::FileFunc::WriteJsonFile(document, path);
|
||||
EXPECT_TRUE(saveResult.IsSuccess());
|
||||
|
||||
// Verify that the contents of the file is what we expect
|
||||
AZ::Outcome<AZStd::string, AZStd::string> readResult = AZ::Utils::ReadFile(pathStr);
|
||||
EXPECT_TRUE(readResult.IsSuccess());
|
||||
AZStd::string outString(readResult.TakeValue());
|
||||
outString.erase(AZStd::remove_if(outString.begin(), outString.end(), ::isspace), outString.end());
|
||||
EXPECT_EQ(outString, expectedJsonText);
|
||||
|
||||
// Clean up
|
||||
AZ::IO::FileIOBase::GetInstance()->Remove(path.c_str());
|
||||
}
|
||||
|
||||
TEST_F(JsonFileFuncTest, ReadJsonString_ValidJson_ExpectSuccess)
|
||||
{
|
||||
const char* jsonText =
|
||||
R"(
|
||||
{
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3
|
||||
})";
|
||||
|
||||
AZ::Outcome<rapidjson::Document, AZStd::string> result = AzFramework::FileFunc::ReadJsonFromString(jsonText);
|
||||
|
||||
EXPECT_TRUE(result.IsSuccess());
|
||||
EXPECT_TRUE(result.GetValue().IsObject());
|
||||
EXPECT_TRUE(result.GetValue().HasMember("a"));
|
||||
EXPECT_TRUE(result.GetValue().HasMember("b"));
|
||||
EXPECT_TRUE(result.GetValue().HasMember("c"));
|
||||
EXPECT_EQ(result.GetValue()["a"].GetInt(), 1);
|
||||
EXPECT_EQ(result.GetValue()["b"].GetInt(), 2);
|
||||
EXPECT_EQ(result.GetValue()["c"].GetInt(), 3);
|
||||
}
|
||||
|
||||
TEST_F(JsonFileFuncTest, ReadJsonString_InvalidJson_ErrorReportsLineNumber)
|
||||
{
|
||||
const char* jsonText =
|
||||
R"(
|
||||
{
|
||||
"a": "This line is missing a comma"
|
||||
"b": 2,
|
||||
"c": 3
|
||||
}
|
||||
)";
|
||||
|
||||
AZ::Outcome<rapidjson::Document, AZStd::string> result = AzFramework::FileFunc::ReadJsonFromString(jsonText);
|
||||
|
||||
EXPECT_FALSE(result.IsSuccess());
|
||||
EXPECT_TRUE(result.GetError().find("JSON parse error at line 4:") == 0);
|
||||
}
|
||||
|
||||
TEST_F(JsonFileFuncTest, ReadJsonFile_ValidJson_ExpectSuccess)
|
||||
{
|
||||
AZ::Test::ScopedAutoTempDirectory tempDir;
|
||||
|
||||
const char* inputJsonText =
|
||||
R"({
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3
|
||||
})";
|
||||
|
||||
rapidjson::Document expectedDocument;
|
||||
expectedDocument.SetObject();
|
||||
expectedDocument.AddMember("a", 1, expectedDocument.GetAllocator());
|
||||
expectedDocument.AddMember("b", 2, expectedDocument.GetAllocator());
|
||||
expectedDocument.AddMember("c", 3, expectedDocument.GetAllocator());
|
||||
|
||||
// Create test file
|
||||
AZStd::string path;
|
||||
AzFramework::StringFunc::Path::ConstructFull(tempDir.GetDirectory(), "test.json", path, true);
|
||||
AZ::Outcome<void, AZStd::string> writeResult = AZ::Utils::WriteFile(inputJsonText, path);
|
||||
EXPECT_TRUE(writeResult.IsSuccess());
|
||||
|
||||
|
||||
// Read the JSON from the test file
|
||||
AZ::Outcome<rapidjson::Document, AZStd::string> readResult = AzFramework::FileFunc::ReadJsonFile(path);
|
||||
EXPECT_TRUE(readResult.IsSuccess());
|
||||
|
||||
EXPECT_EQ(expectedDocument, readResult.GetValue());
|
||||
|
||||
// Clean up
|
||||
AZ::IO::FileIOBase::GetInstance()->Remove(path.c_str());
|
||||
}
|
||||
} // namespace UnitTest
|
||||
|
||||
@@ -19,8 +19,7 @@ namespace AZ
|
||||
{
|
||||
// Scene system components are components that can be used to create system components
|
||||
// in situations where the full initialization and/or construction of regular
|
||||
// system components don't apply such as in the Project Configurator's advanced
|
||||
// settings and the ResourceCompilerScene.
|
||||
// system components don't apply such as in the ResourceCompilerScene.
|
||||
class SCENE_CORE_CLASS SceneSystemComponent
|
||||
: public AZ::Component
|
||||
{
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
#include <AzCore/Serialization/Json/RegistrationContext.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerializationResult.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzCore/Serialization/Utils.h>
|
||||
#include <AzCore/std/algorithm.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
#include <AzToolsFramework/Debug/TraceContext.h>
|
||||
#include <SceneAPI/SceneCore/Utilities/Reporting.h>
|
||||
@@ -163,8 +163,7 @@ namespace AZ
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::IO::Path fileIoPath(absoluteFilePath);
|
||||
auto saveToFileOutcome = AzFramework::FileFunc::WriteJsonFile(saveToJsonOutcome.GetValue(), fileIoPath);
|
||||
auto saveToFileOutcome = AZ::JsonSerializationUtils::WriteJsonFile(saveToJsonOutcome.GetValue(), absoluteFilePath);
|
||||
if (!saveToFileOutcome.IsSuccess())
|
||||
{
|
||||
AZ_Error(ErrorWindowName, false, "%s%s", errorMsg.c_str(), saveToFileOutcome.GetError().c_str());
|
||||
@@ -309,7 +308,7 @@ namespace AZ
|
||||
else
|
||||
{
|
||||
// Attempt to read the stream as JSON
|
||||
auto readJsonOutcome = AzFramework::FileFunc::ReadJsonFromString(fileContents);
|
||||
auto readJsonOutcome = AZ::JsonSerializationUtils::ReadJsonString(fileContents);
|
||||
AZStd::string errorMsg;
|
||||
if (!readJsonOutcome.IsSuccess())
|
||||
{
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace AZ
|
||||
|
||||
// Check if this library hasn't already been reflected. This can happen as the ResourceCompilerScene needs
|
||||
// to explicitly load and reflect the SceneAPI libraries to discover the available extension, while
|
||||
// Gems with system components need to do the same in the Project Configurator.
|
||||
// Gems with system components need to do the same in the Project Manager.
|
||||
if (context && (context->IsRemovingReflection() || !context->FindClassData(AZ::SceneAPI::DataTypes::IGroup::TYPEINFO_Uuid())))
|
||||
{
|
||||
AZ::SceneAPI::DataTypes::IManifestObject::Reflect(context);
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
#include <AzCore/IO/SystemFile.h>
|
||||
#include <AzCore/Serialization/Json/RegistrationContext.h>
|
||||
#include <AzCore/Serialization/Json/JsonSystemComponent.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzCore/Serialization/Utils.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
#include <AzToolsFramework/Application/ToolsApplication.h>
|
||||
#include <SceneAPI/SceneCore/Containers/SceneManifest.h>
|
||||
#include <SceneAPI/SceneCore/DataTypes/IManifestObject.h>
|
||||
@@ -325,7 +325,7 @@ namespace AZ
|
||||
ASSERT_TRUE(writeToJsonResult.IsSuccess());
|
||||
|
||||
AZStd::string jsonText;
|
||||
auto writeToStringResult = AzFramework::FileFunc::WriteJsonToString(writeToJsonResult.GetValue(), jsonText);
|
||||
auto writeToStringResult = AZ::JsonSerializationUtils::WriteJsonString(writeToJsonResult.GetValue(), jsonText);
|
||||
ASSERT_TRUE(writeToStringResult.IsSuccess());
|
||||
|
||||
MockSceneManifest loaded;
|
||||
@@ -340,7 +340,7 @@ namespace AZ
|
||||
ASSERT_TRUE(writeToJsonResult.IsSuccess());
|
||||
|
||||
AZStd::string jsonText;
|
||||
auto writeToStringResult = AzFramework::FileFunc::WriteJsonToString(writeToJsonResult.GetValue(), jsonText);
|
||||
auto writeToStringResult = AZ::JsonSerializationUtils::WriteJsonString(writeToJsonResult.GetValue(), jsonText);
|
||||
ASSERT_TRUE(writeToStringResult.IsSuccess());
|
||||
|
||||
MockSceneManifest loaded;
|
||||
@@ -371,7 +371,7 @@ namespace AZ
|
||||
ASSERT_TRUE(writeToJsonResult.IsSuccess());
|
||||
|
||||
AZStd::string jsonText;
|
||||
auto writeToStringResult = AzFramework::FileFunc::WriteJsonToString(writeToJsonResult.GetValue(), jsonText);
|
||||
auto writeToStringResult = AZ::JsonSerializationUtils::WriteJsonString(writeToJsonResult.GetValue(), jsonText);
|
||||
ASSERT_TRUE(writeToStringResult.IsSuccess());
|
||||
|
||||
// Deserialize JSON
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace AZ
|
||||
{
|
||||
// Check if this library hasn't already been reflected. This can happen as the ResourceCompilerScene needs
|
||||
// to explicitly load and reflect the SceneAPI libraries to discover the available extension, while
|
||||
// Gems with system components need to do the same in the Project Configurator.
|
||||
// Gems with system components need to do the same in the Project Manager.
|
||||
if (!context->IsRemovingReflection() && context->FindClassData(SceneData::MeshGroup::TYPEINFO_Uuid()))
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
#include <AzCore/RTTI/BehaviorContext.h>
|
||||
#include <AzCore/RTTI/ReflectionManager.h>
|
||||
#include <AzCore/Serialization/Json/JsonSystemComponent.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzCore/Serialization/Json/RegistrationContext.h>
|
||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||
#include <AzCore/std/smart_ptr/shared_ptr.h>
|
||||
#include <AzCore/UnitTest/Mocks/MockSettingsRegistry.h>
|
||||
#include <AzCore/UnitTest/TestTypes.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
@@ -154,7 +154,7 @@ namespace AZ
|
||||
ASSERT_TRUE(writeToJsonResult.IsSuccess());
|
||||
|
||||
AZStd::string jsonText;
|
||||
auto writeToStringResult = AzFramework::FileFunc::WriteJsonToString(writeToJsonResult.GetValue(), jsonText);
|
||||
auto writeToStringResult = AZ::JsonSerializationUtils::WriteJsonString(writeToJsonResult.GetValue(), jsonText);
|
||||
ASSERT_TRUE(writeToStringResult.IsSuccess());
|
||||
EXPECT_THAT(jsonText.c_str(), ::testing::HasSubstr(R"("$type": "MockRotationRule")"));
|
||||
EXPECT_THAT(jsonText.c_str(), ::testing::HasSubstr(R"("rotation": [)"));
|
||||
@@ -191,7 +191,7 @@ namespace AZ
|
||||
ASSERT_TRUE(writeToJsonResult.IsSuccess());
|
||||
|
||||
AZStd::string jsonText;
|
||||
auto writeToStringResult = AzFramework::FileFunc::WriteJsonToString(writeToJsonResult.GetValue(), jsonText);
|
||||
auto writeToStringResult = AZ::JsonSerializationUtils::WriteJsonString(writeToJsonResult.GetValue(), jsonText);
|
||||
ASSERT_TRUE(writeToStringResult.IsSuccess());
|
||||
EXPECT_THAT(jsonText.c_str(), ::testing::HasSubstr(R"("$type": "MockRotationRule")"));
|
||||
EXPECT_THAT(jsonText.c_str(), ::testing::HasSubstr(R"("rotation": [)"));
|
||||
@@ -230,7 +230,7 @@ namespace AZ
|
||||
ASSERT_TRUE(writeToJsonResult.IsSuccess());
|
||||
|
||||
AZStd::string jsonText;
|
||||
auto writeToStringResult = AzFramework::FileFunc::WriteJsonToString(writeToJsonResult.GetValue(), jsonText);
|
||||
auto writeToStringResult = AZ::JsonSerializationUtils::WriteJsonString(writeToJsonResult.GetValue(), jsonText);
|
||||
ASSERT_TRUE(writeToStringResult.IsSuccess());
|
||||
EXPECT_THAT(jsonText.c_str(), ::testing::HasSubstr(R"("$type": "CoordinateSystemRule")"));
|
||||
EXPECT_THAT(jsonText.c_str(), ::testing::HasSubstr(R"("useAdvancedData": true,)"));
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#include <AzCore/IO/Path/Path.h>
|
||||
#include <AzCore/JSON/schema.h>
|
||||
#include <AzCore/JSON/prettywriter.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzCore/Settings/SettingsRegistry.h>
|
||||
#include <AzCore/Settings/SettingsRegistryImpl.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
|
||||
#include <AWSCoreInternalBus.h>
|
||||
@@ -211,8 +211,7 @@ namespace AWSCore
|
||||
}
|
||||
|
||||
AzFramework::StringFunc::Path::Normalize(configJsonPath);
|
||||
AZ::IO::Path configJsonFileIOPath(configJsonPath);
|
||||
auto readJsonOutcome = AzFramework::FileFunc::ReadJsonFile(configJsonFileIOPath);
|
||||
auto readJsonOutcome = AZ::JsonSerializationUtils::ReadJsonFile(configJsonPath);
|
||||
if (readJsonOutcome.IsSuccess())
|
||||
{
|
||||
auto jsonDocument = readJsonOutcome.TakeValue();
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <AzCore/IO/FileIO.h>
|
||||
#include <AzCore/IO/SystemFile.h>
|
||||
#include <AzCore/IO/Path/Path.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
|
||||
namespace AWSMetrics
|
||||
{
|
||||
@@ -39,8 +39,7 @@ namespace AWSMetrics
|
||||
return "";
|
||||
}
|
||||
|
||||
AZ::IO::Path configIoPath(resolvedPath);
|
||||
auto readOutcome = AzFramework::FileFunc::ReadJsonFile(configIoPath, fileIO);
|
||||
auto readOutcome = AZ::JsonSerializationUtils::ReadJsonFile(resolvedPath);
|
||||
if (!readOutcome.IsSuccess())
|
||||
{
|
||||
AZ_Error("AWSMetrics", false, readOutcome.GetError().c_str());
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#include <AzCore/JSON/schema.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace AWSMetrics
|
||||
return false;
|
||||
}
|
||||
|
||||
auto result = AzFramework::FileFunc::ReadJsonFromString(stringStream.str().c_str());
|
||||
auto result = AZ::JsonSerializationUtils::ReadJsonString(stringStream.str().c_str());
|
||||
if (!result.IsSuccess())
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
#include <AzCore/IO/FileIO.h>
|
||||
#include <AzCore/IO/Path/Path.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzCore/std/sort.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@@ -191,15 +191,7 @@ namespace AWSMetrics
|
||||
|
||||
bool MetricsQueue::ReadFromJson(const AZStd::string& filePath)
|
||||
{
|
||||
AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetDirectInstance();
|
||||
if (!fileIO)
|
||||
{
|
||||
AZ_Error("AWSMetrics", false, "Failed to get file IO instance");
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::IO::Path fileIoPath(filePath);
|
||||
auto result = AzFramework::FileFunc::ReadJsonFile(fileIoPath, fileIO);
|
||||
auto result = AZ::JsonSerializationUtils::ReadJsonFile(filePath);
|
||||
if (!result.IsSuccess() ||!ReadFromJsonDocument(result.GetValue()))
|
||||
{
|
||||
AZ_Error("AWSMetrics", false, "Failed to read metrics file %s", filePath.c_str());
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include <AzCore/JSON/document.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerializationResult.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
#include "Exporter.h"
|
||||
#include <MCore/Source/ReflectionSerializer.h>
|
||||
#include <EMotionFX/Source/MotionEvent.h>
|
||||
@@ -55,10 +55,10 @@ namespace ExporterLib
|
||||
}
|
||||
|
||||
AZStd::string serializedMotionEventTable;
|
||||
auto writeToStringOutcome = AzFramework::FileFunc::WriteJsonToString(jsonDocument, serializedMotionEventTable);
|
||||
auto writeToStringOutcome = AZ::JsonSerializationUtils::WriteJsonString(jsonDocument, serializedMotionEventTable);
|
||||
if (!writeToStringOutcome.IsSuccess())
|
||||
{
|
||||
AZ_Error("EMotionFX", false, "WriteJsonToString failed: %s", writeToStringOutcome.GetError().c_str());
|
||||
AZ_Error("EMotionFX", false, "WriteJsonString failed: %s", writeToStringOutcome.GetError().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <AzCore/Serialization/Json/RegistrationContext.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerializationResult.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
|
||||
#include <EMotionFX/Source/Parameter/GroupParameter.h>
|
||||
#include <EMotionFX/Source/Parameter/ParameterFactory.h>
|
||||
@@ -1081,11 +1081,11 @@ namespace EMotionFX
|
||||
file->Read(&buffer[0], fileEventTable.m_size);
|
||||
AZStd::string_view bufferStringView(&buffer[0], buffer.size());
|
||||
|
||||
auto readJsonOutcome = AzFramework::FileFunc::ReadJsonFromString(bufferStringView);
|
||||
auto readJsonOutcome = AZ::JsonSerializationUtils::ReadJsonString(bufferStringView);
|
||||
AZStd::string errorMsg;
|
||||
if (!readJsonOutcome.IsSuccess())
|
||||
{
|
||||
AZ_Error("EMotionFX", false, "Loading motion event table failed due to ReadJsonFromString. %s", readJsonOutcome.TakeError().c_str());
|
||||
AZ_Error("EMotionFX", false, "Loading motion event table failed due to ReadJsonString. %s", readJsonOutcome.TakeError().c_str());
|
||||
return false;
|
||||
}
|
||||
rapidjson::Document document = readJsonOutcome.TakeValue();
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace EMotionFX
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dock->setWidget(CreateErrorContentWidget("Cloth collider editor depends on the NVIDIA Cloth gem. Please enable it in the project configurator."));
|
||||
m_dock->setWidget(CreateErrorContentWidget("Cloth collider editor depends on the NVIDIA Cloth gem. Please enable it in the Project Manager."));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ namespace EMotionFX
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dock->setWidget(CreateErrorContentWidget("Hit detection collider editor depends on the PhysX gem. Please enable it in the project configurator."));
|
||||
m_dock->setWidget(CreateErrorContentWidget("Hit detection collider editor depends on the PhysX gem. Please enable it in the Project Manager."));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace EMotionFX
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dock->setWidget(CreateErrorContentWidget("Ragdoll editor depends on the PhysX gem. Please enable it in the project configurator."));
|
||||
m_dock->setWidget(CreateErrorContentWidget("Ragdoll editor depends on the PhysX gem. Please enable it in the Project Manager."));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -389,7 +389,7 @@ namespace EMotionFX
|
||||
{
|
||||
QLabel* noColliders = new QLabel(
|
||||
"To adjust the properties of the Simulated Object Colliders, "
|
||||
"enable the PhysX gem via the Project Configurator");
|
||||
"enable the PhysX gem via the Project Manager");
|
||||
|
||||
colliderWidgetLayout->addWidget(noColliders);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <AzCore/Asset/AssetCommon.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
#include <AzFramework/StringFunc/StringFunc.h>
|
||||
#include <AzFramework/IO/LocalFileIO.h>
|
||||
#include <AzCore/Debug/Trace.h>
|
||||
@@ -27,6 +26,7 @@
|
||||
#include <AzCore/Serialization/ObjectStream.h>
|
||||
#include <AzCore/Serialization/Utils.h>
|
||||
#include <AzCore/Serialization/Json/JsonSerialization.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||
#include <AzCore/Asset/AssetSerializer.h>
|
||||
#include <AzCore/Component/ComponentExport.h>
|
||||
@@ -73,9 +73,7 @@ namespace SliceBuilder
|
||||
AzFramework::StringFunc::Path::Join(relativePath.c_str(), settingsAssetInfo.m_relativePath.c_str(), sliceBuilderSettingsPath, true, true);
|
||||
|
||||
// Attempt to load the Slice Builder Settings file
|
||||
AZ::IO::LocalFileIO localFileIO;
|
||||
AZ::IO::Path sliceBuilderSettingsIoPath(sliceBuilderSettingsPath);
|
||||
auto result = AzFramework::FileFunc::ReadJsonFile(sliceBuilderSettingsIoPath, &localFileIO);
|
||||
auto result = AZ::JsonSerializationUtils::ReadJsonFile(sliceBuilderSettingsPath);
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
AZ::JsonSerializationResult::ResultCode serializaionResult = AZ::JsonSerialization::Load(m_settings, result.GetValue());
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace AZ::Prefab
|
||||
AZ::StringFunc::Path::ConstructFull(request.m_watchFolder.c_str(), request.m_sourceFile.c_str(), fullPath);
|
||||
|
||||
// Load the JSON Dom
|
||||
AZ::Outcome<PrefabDom, AZStd::string> readPrefabFileResult = AzFramework::FileFunc::ReadJsonFile(AZ::IO::Path(fullPath));
|
||||
AZ::Outcome<PrefabDom, AZStd::string> readPrefabFileResult = AZ::JsonSerializationUtils::ReadJsonFile(fullPath);
|
||||
if (!readPrefabFileResult.IsSuccess())
|
||||
{
|
||||
AZ_Error(
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <AzCore/IO/SystemFile.h>
|
||||
#include <AzCore/Module/Module.h>
|
||||
#include <AzCore/Module/DynamicModuleHandle.h>
|
||||
#include <AzFramework/FileFunc/FileFunc.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabSystemComponent.h>
|
||||
#include <AzToolsFramework/Prefab/Spawnable/PrefabConversionPipeline.h>
|
||||
#include <Fingerprinting/TypeFingerprinter.h>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "PrefabBuilderTests.h"
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/Serialization/Json/JsonSystemComponent.h>
|
||||
#include <AzCore/Serialization/Json/JsonUtils.h>
|
||||
#include <AzCore/Serialization/Json/RegistrationContext.h>
|
||||
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
|
||||
#include <AzCore/UserSettings/UserSettingsComponent.h>
|
||||
@@ -56,7 +57,7 @@ namespace UnitTest
|
||||
// Save to a string so we can load it as a PrefabDom and so that the nested instance becomes a Source file reference
|
||||
ASSERT_TRUE(prefabLoaderInterface->SaveTemplateToString(parentInstance->GetTemplateId(), serializedInstance));
|
||||
|
||||
AZ::Outcome<PrefabDom, AZStd::string> readPrefabFileResult = AzFramework::FileFunc::ReadJsonFromString(serializedInstance);
|
||||
AZ::Outcome<PrefabDom, AZStd::string> readPrefabFileResult = AZ::JsonSerializationUtils::ReadJsonString(serializedInstance);
|
||||
|
||||
ASSERT_TRUE(readPrefabFileResult.IsSuccess());
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace SceneLoggingExample
|
||||
}
|
||||
|
||||
// In this example, no system components are added. You can use system components
|
||||
// to set global settings for this gem from the Project Configurator.
|
||||
// to set global settings for this gem.
|
||||
// For functionality that should always be available to the SceneAPI, we recommend
|
||||
// that you use a BehaviorComponent instead.
|
||||
AZ::ComponentTypeList GetRequiredSystemComponents() const override
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ namespace AZ
|
||||
ActivateSceneModule(SceneProcessing::s_sceneDataModule);
|
||||
ActivateSceneModule(SceneProcessing::s_sceneBuilderModule);
|
||||
|
||||
// Defaults in case there's no config setup in the Project Configurator.
|
||||
// Defaults in case there's no config setup
|
||||
m_softNames.push_back(aznew NodeSoftNameSetting("^.*_[Ll][Oo][Dd]1(_optimized)?$", PatternMatcher::MatchApproach::Regex, "LODMesh1", true));
|
||||
m_softNames.push_back(aznew NodeSoftNameSetting("^.*_[Ll][Oo][Dd]2(_optimized)?$", PatternMatcher::MatchApproach::Regex, "LODMesh2", true));
|
||||
m_softNames.push_back(aznew NodeSoftNameSetting("^.*_[Ll][Oo][Dd]3(_optimized)?$", PatternMatcher::MatchApproach::Regex, "LODMesh3", true));
|
||||
|
||||
Reference in New Issue
Block a user