Remove file size limits when loading prefabs and prefab-based-levels
This commit is contained in:
@@ -169,6 +169,37 @@ namespace AZ::Utils
|
||||
template AZ::Outcome<AZStd::vector<int8_t>, AZStd::string> ReadFile(AZStd::string_view filePath, size_t maxFileSize);
|
||||
template AZ::Outcome<AZStd::vector<uint8_t>, AZStd::string> ReadFile(AZStd::string_view filePath, size_t maxFileSize);
|
||||
|
||||
template<typename Container>
|
||||
AZ::Outcome<Container, AZStd::string> ReadFileWithNoSizeLimit(AZStd::string_view filePath)
|
||||
{
|
||||
IO::FileIOStream file;
|
||||
if (!file.Open(filePath.data(), IO::OpenMode::ModeRead))
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("Failed to open '%.*s'.", AZ_STRING_ARG(filePath)));
|
||||
}
|
||||
|
||||
AZ::IO::SizeType length = file.GetLength();
|
||||
|
||||
if (length == 0)
|
||||
{
|
||||
return AZ::Failure(AZStd::string::format("Failed to load '%.*s'. File is empty.", AZ_STRING_ARG(filePath)));
|
||||
}
|
||||
|
||||
Container fileContent;
|
||||
fileContent.resize(length);
|
||||
AZ::IO::SizeType bytesRead = file.Read(length, fileContent.data());
|
||||
file.Close();
|
||||
|
||||
// Resize again just in case bytesRead is less than length for some reason
|
||||
fileContent.resize(bytesRead);
|
||||
|
||||
return AZ::Success(AZStd::move(fileContent));
|
||||
}
|
||||
|
||||
template AZ::Outcome<AZStd::string, AZStd::string> ReadFileWithNoSizeLimit(AZStd::string_view filePath);
|
||||
template AZ::Outcome<AZStd::vector<int8_t>, AZStd::string> ReadFileWithNoSizeLimit(AZStd::string_view filePath);
|
||||
template AZ::Outcome<AZStd::vector<uint8_t>, AZStd::string> ReadFileWithNoSizeLimit(AZStd::string_view filePath);
|
||||
|
||||
AZ::IO::FixedMaxPathString GetO3deManifestDirectory()
|
||||
{
|
||||
AZ::IO::FixedMaxPath path = GetHomeDirectory();
|
||||
|
||||
@@ -113,8 +113,13 @@ namespace AZ
|
||||
//! Save a string to a file. Otherwise returns a failure with error message.
|
||||
AZ::Outcome<void, AZStd::string> WriteFile(AZStd::string_view content, AZStd::string_view filePath);
|
||||
|
||||
//! Read a file into a string. Returns a failure with error message if the content could not be loaded.
|
||||
//! Read a file into a string. Returns a failure with error message if the content could not be loaded or if
|
||||
//! the file size is larger than the max file size provided.
|
||||
template<typename Container = AZStd::string>
|
||||
AZ::Outcome<Container, AZStd::string> ReadFile(AZStd::string_view filePath, size_t maxFileSize = DefaultMaxFileSize);
|
||||
|
||||
//! Read a file into a string. Returns a failure with error message if the content could not be loaded.
|
||||
template<typename Container = AZStd::string>
|
||||
AZ::Outcome<Container, AZStd::string> ReadFileWithNoSizeLimit(AZStd::string_view filePath);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-7
@@ -185,13 +185,7 @@ namespace AzToolsFramework
|
||||
bool PrefabEditorEntityOwnershipService::LoadFromStream(AZ::IO::GenericStream& stream, AZStd::string_view filename)
|
||||
{
|
||||
Reset();
|
||||
// Make loading from stream to behave the same in terms of filesize as regular loading of prefabs
|
||||
// This may need to be revisited in the future for supporting higher sizes along with prefab loading
|
||||
if (stream.GetLength() > Prefab::MaxPrefabFileSize)
|
||||
{
|
||||
AZ_Error("Prefab", false, "'%.*s' prefab content is bigger than the max supported size (%f MB)", AZ_STRING_ARG(filename), Prefab::MaxPrefabFileSize / (1024.f * 1024.f));
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t bufSize = stream.GetLength();
|
||||
AZStd::unique_ptr<char[]> buf(new char[bufSize]);
|
||||
AZ::IO::SizeType bytes = stream.Read(bufSize, buf.get());
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace AzToolsFramework
|
||||
return InvalidTemplateId;
|
||||
}
|
||||
|
||||
auto readResult = AZ::Utils::ReadFile(GetFullPath(filePath).Native(), MaxPrefabFileSize);
|
||||
auto readResult = AZ::Utils::ReadFileWithNoSizeLimit(GetFullPath(filePath).Native());
|
||||
if (!readResult.IsSuccess())
|
||||
{
|
||||
AZ_Error(
|
||||
|
||||
@@ -21,8 +21,6 @@ namespace AzToolsFramework
|
||||
{
|
||||
namespace Prefab
|
||||
{
|
||||
constexpr size_t MaxPrefabFileSize = 1024 * 1024;
|
||||
|
||||
/*!
|
||||
* PrefabLoaderInterface
|
||||
* Interface for saving/loading Prefab files.
|
||||
|
||||
Reference in New Issue
Block a user