summaryrefslogtreecommitdiffstats
path: root/src/Generating/PrefabPiecePool.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-01-11 17:39:43 +0100
committerGitHub <noreply@github.com>2021-01-11 17:39:43 +0100
commiteeb63b8901a9c049f1bb594abb9ce9b4a9c47620 (patch)
treeb07daae788f918b83eeb0bdbd51e49292f1c8d88 /src/Generating/PrefabPiecePool.cpp
parentFixed switch-ups regarding some slab and stair recipes (#5099) (diff)
downloadcuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar
cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.gz
cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.bz2
cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.lz
cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.xz
cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.zst
cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.zip
Diffstat (limited to 'src/Generating/PrefabPiecePool.cpp')
-rw-r--r--src/Generating/PrefabPiecePool.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/Generating/PrefabPiecePool.cpp b/src/Generating/PrefabPiecePool.cpp
index e52bb1621..28355660c 100644
--- a/src/Generating/PrefabPiecePool.cpp
+++ b/src/Generating/PrefabPiecePool.cpp
@@ -78,15 +78,6 @@ cPrefabPiecePool::cPrefabPiecePool(
-cPrefabPiecePool::cPrefabPiecePool(const AString & a_FileName, bool a_LogWarnings)
-{
- LoadFromFile(a_FileName, a_LogWarnings);
-}
-
-
-
-
-
cPrefabPiecePool::~cPrefabPiecePool()
{
Clear();
@@ -174,21 +165,28 @@ bool cPrefabPiecePool::LoadFromString(const AString & a_Contents, const AString
// If the contents start with GZip signature, ungzip and retry:
if (a_Contents.substr(0, 3) == "\x1f\x8b\x08")
{
- AString Uncompressed;
- auto res = UncompressStringGZIP(a_Contents.data(), a_Contents.size(), Uncompressed);
- if (res == Z_OK)
+ try
{
- return LoadFromString(Uncompressed, a_FileName, a_LogWarnings);
+ const auto Extracted = Compression::Extractor().ExtractGZip(
+ {
+ reinterpret_cast<const std::byte *>(a_Contents.data()), a_Contents.size()
+ });
+
+ // Here we do an extra std::string conversion, hardly efficient, but...
+ // Better would be refactor into LoadFromByteView for the GZip decompression path, and getting cFile to support std::byte.
+ // ...so it'll do for now.
+
+ return LoadFromString(std::string(Extracted.GetStringView()), a_FileName, a_LogWarnings);
}
- else
+ catch (const std::exception & Oops)
{
- CONDWARNING(a_LogWarnings, "Failed to decompress Gzip data in file %s: %d", a_FileName.c_str(), res);
+ CONDWARNING(a_LogWarnings, "Failed to decompress Gzip data in file %s. %s", a_FileName.c_str(), Oops.what());
return false;
}
}
// Search the first 8 KiB of the file for the format auto-detection string:
- auto Header = a_Contents.substr(0, 8192);
+ const auto Header = a_Contents.substr(0, 8 KiB);
if (Header.find("CubesetFormatVersion =") != AString::npos)
{
return LoadFromCubeset(a_Contents, a_FileName, a_LogWarnings);
@@ -391,10 +389,14 @@ std::unique_ptr<cPrefab> cPrefabPiecePool::LoadPrefabFromCubesetVer1(
SchematicFileName = a_FileName.substr(0, PathEnd) + SchematicFileName;
}
cBlockArea area;
- if (!cSchematicFileSerializer::LoadFromSchematicFile(area, SchematicFileName))
+ try
+ {
+ cSchematicFileSerializer::LoadFromSchematicFile(area, SchematicFileName);
+ }
+ catch (const std::exception & Oops)
{
- CONDWARNING(a_LogWarnings, "Cannot load schematic file \"%s\" for piece %s in cubeset %s.",
- SchematicFileName.c_str(), a_PieceName.c_str(), a_FileName.c_str()
+ CONDWARNING(a_LogWarnings, "Cannot load schematic file \"%s\" for piece %s in cubeset %s. %s",
+ SchematicFileName.c_str(), a_PieceName.c_str(), a_FileName.c_str(), Oops.what()
);
return nullptr;
}