zlib -> libdeflate (#5085)
+ Use libdeflate + Use std::byte * Fix passing temporary to string_view + Emulate make_unique_for_overwrite
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
|
||||
#include "Globals.h"
|
||||
#include "ScoreboardSerializer.h"
|
||||
#include "../StringCompression.h"
|
||||
#include "zlib/zlib.h"
|
||||
#include "OSSupport/GZipFile.h"
|
||||
#include "FastNBT.h"
|
||||
|
||||
#include "../Scoreboard.h"
|
||||
@@ -31,29 +30,24 @@ cScoreboardSerializer::cScoreboardSerializer(const AString & a_WorldName, cScore
|
||||
|
||||
bool cScoreboardSerializer::Load(void)
|
||||
{
|
||||
AString Data = cFile::ReadWholeFile(m_Path);
|
||||
if (Data.empty())
|
||||
try
|
||||
{
|
||||
const auto Data = GZipFile::ReadRestOfFile(m_Path);
|
||||
const cParsedNBT NBT(Data.GetView());
|
||||
|
||||
if (!NBT.IsValid())
|
||||
{
|
||||
// NBT Parsing failed
|
||||
return false;
|
||||
}
|
||||
|
||||
return LoadScoreboardFromNBT(NBT);
|
||||
}
|
||||
catch (const std::exception & Oops)
|
||||
{
|
||||
LOGWARNING("Failed to load scoreboard from \"%s\": %s", m_Path.c_str(), Oops.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
AString Uncompressed;
|
||||
int res = UncompressStringGZIP(Data.data(), Data.size(), Uncompressed);
|
||||
|
||||
if (res != Z_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse the NBT data:
|
||||
cParsedNBT NBT(Uncompressed.data(), Uncompressed.size());
|
||||
if (!NBT.IsValid())
|
||||
{
|
||||
// NBT Parsing failed
|
||||
return false;
|
||||
}
|
||||
|
||||
return LoadScoreboardFromNBT(NBT);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,32 +57,15 @@ bool cScoreboardSerializer::Load(void)
|
||||
bool cScoreboardSerializer::Save(void)
|
||||
{
|
||||
cFastNBTWriter Writer;
|
||||
|
||||
SaveScoreboardToNBT(Writer);
|
||||
|
||||
Writer.Finish();
|
||||
|
||||
#ifdef _DEBUG
|
||||
cParsedNBT TestParse(Writer.GetResult().data(), Writer.GetResult().size());
|
||||
#ifdef _DEBUG
|
||||
cParsedNBT TestParse(Writer.GetResult());
|
||||
ASSERT(TestParse.IsValid());
|
||||
#endif // _DEBUG
|
||||
#endif // _DEBUG
|
||||
|
||||
cFile File;
|
||||
if (!File.Open(m_Path, cFile::fmWrite))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AString Compressed;
|
||||
int res = CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed);
|
||||
|
||||
if (res != Z_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
File.Write(Compressed.data(), Compressed.size());
|
||||
File.Close();
|
||||
GZipFile::Write(m_Path, Writer.GetResult());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user