mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Serializer refactoring: fix FileStream usage for game loading
Miss this one rebase. Without this one non-English characters in paths to saves cause issues.
This commit is contained in:
@@ -15,7 +15,8 @@
|
|||||||
|
|
||||||
extern template void registerTypes<BinaryDeserializer>(BinaryDeserializer & s);
|
extern template void registerTypes<BinaryDeserializer>(BinaryDeserializer & s);
|
||||||
|
|
||||||
CLoadFile::CLoadFile(const boost::filesystem::path & fname, int minimalVersion /*= version*/): serializer(this)
|
CLoadFile::CLoadFile(const boost::filesystem::path & fname, int minimalVersion /*= version*/)
|
||||||
|
: serializer(this)
|
||||||
{
|
{
|
||||||
registerTypes(serializer);
|
registerTypes(serializer);
|
||||||
openNextFile(fname, minimalVersion);
|
openNextFile(fname, minimalVersion);
|
||||||
@@ -39,7 +40,7 @@ void CLoadFile::openNextFile(const boost::filesystem::path & fname, int minimalV
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
fName = fname.string();
|
fName = fname.string();
|
||||||
sfile = make_unique<boost::filesystem::ifstream>(fname, std::ios::binary);
|
sfile = make_unique<FileStream>(fname, std::ios::in | std::ios::binary);
|
||||||
sfile->exceptions(std::ifstream::failbit | std::ifstream::badbit); //we throw a lot anyway
|
sfile->exceptions(std::ifstream::failbit | std::ifstream::badbit); //we throw a lot anyway
|
||||||
|
|
||||||
if(!(*sfile))
|
if(!(*sfile))
|
||||||
@@ -55,7 +56,7 @@ void CLoadFile::openNextFile(const boost::filesystem::path & fname, int minimalV
|
|||||||
if(serializer.fileVersion < minimalVersion)
|
if(serializer.fileVersion < minimalVersion)
|
||||||
THROW_FORMAT("Error: too old file format (%s)!", fName);
|
THROW_FORMAT("Error: too old file format (%s)!", fName);
|
||||||
|
|
||||||
if(serializer.fileVersion > SERIALIZATION_VERSION )
|
if(serializer.fileVersion > SERIALIZATION_VERSION)
|
||||||
{
|
{
|
||||||
logGlobal->warnStream() << boost::format("Warning format version mismatch: found %d when current is %d! (file %s)\n") % serializer.fileVersion % SERIALIZATION_VERSION % fName;
|
logGlobal->warnStream() << boost::format("Warning format version mismatch: found %d when current is %d! (file %s)\n") % serializer.fileVersion % SERIALIZATION_VERSION % fName;
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ void CLoadFile::clear()
|
|||||||
serializer.fileVersion = 0;
|
serializer.fileVersion = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLoadFile::checkMagicBytes( const std::string &text )
|
void CLoadFile::checkMagicBytes(const std::string &text)
|
||||||
{
|
{
|
||||||
std::string loaded = text;
|
std::string loaded = text;
|
||||||
read((void*)loaded.data(), text.length());
|
read((void*)loaded.data(), text.length());
|
||||||
|
|||||||
@@ -514,9 +514,9 @@ public:
|
|||||||
BinaryDeserializer serializer;
|
BinaryDeserializer serializer;
|
||||||
|
|
||||||
std::string fName;
|
std::string fName;
|
||||||
std::unique_ptr<boost::filesystem::ifstream> sfile;
|
std::unique_ptr<FileStream> sfile;
|
||||||
|
|
||||||
CLoadFile(const boost::filesystem::path & fname, int minimalVersion = SERIALIZATION_VERSION ); //throws!
|
CLoadFile(const boost::filesystem::path & fname, int minimalVersion = SERIALIZATION_VERSION); //throws!
|
||||||
~CLoadFile();
|
~CLoadFile();
|
||||||
int read(void * data, unsigned size) override; //throws!
|
int read(void * data, unsigned size) override; //throws!
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
|
|
||||||
extern template void registerTypes<BinarySerializer>(BinarySerializer & s);
|
extern template void registerTypes<BinarySerializer>(BinarySerializer & s);
|
||||||
|
|
||||||
CSaveFile::CSaveFile(const boost::filesystem::path &fname): serializer(this)
|
CSaveFile::CSaveFile(const boost::filesystem::path &fname)
|
||||||
|
: serializer(this)
|
||||||
{
|
{
|
||||||
registerTypes(serializer);
|
registerTypes(serializer);
|
||||||
openNextFile(fname);
|
openNextFile(fname);
|
||||||
@@ -25,7 +26,7 @@ CSaveFile::~CSaveFile()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int CSaveFile::write( const void * data, unsigned size )
|
int CSaveFile::write(const void * data, unsigned size)
|
||||||
{
|
{
|
||||||
sfile->write((char *)data,size);
|
sfile->write((char *)data,size);
|
||||||
return size;
|
return size;
|
||||||
@@ -68,7 +69,7 @@ void CSaveFile::clear()
|
|||||||
sfile = nullptr;
|
sfile = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSaveFile::putMagicBytes( const std::string &text )
|
void CSaveFile::putMagicBytes(const std::string &text)
|
||||||
{
|
{
|
||||||
write(text.c_str(), text.length());
|
write(text.c_str(), text.length());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user