mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +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:
parent
a1cca251ec
commit
e79c522c4b
@ -15,7 +15,8 @@
|
||||
|
||||
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);
|
||||
openNextFile(fname, minimalVersion);
|
||||
@ -39,7 +40,7 @@ void CLoadFile::openNextFile(const boost::filesystem::path & fname, int minimalV
|
||||
try
|
||||
{
|
||||
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
|
||||
|
||||
if(!(*sfile))
|
||||
@ -55,7 +56,7 @@ void CLoadFile::openNextFile(const boost::filesystem::path & fname, int minimalV
|
||||
if(serializer.fileVersion < minimalVersion)
|
||||
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;
|
||||
|
||||
@ -95,7 +96,7 @@ void CLoadFile::clear()
|
||||
serializer.fileVersion = 0;
|
||||
}
|
||||
|
||||
void CLoadFile::checkMagicBytes( const std::string &text )
|
||||
void CLoadFile::checkMagicBytes(const std::string &text)
|
||||
{
|
||||
std::string loaded = text;
|
||||
read((void*)loaded.data(), text.length());
|
||||
|
@ -514,9 +514,9 @@ public:
|
||||
BinaryDeserializer serializer;
|
||||
|
||||
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();
|
||||
int read(void * data, unsigned size) override; //throws!
|
||||
|
||||
|
@ -15,7 +15,8 @@
|
||||
|
||||
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);
|
||||
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);
|
||||
return size;
|
||||
@ -68,7 +69,7 @@ void CSaveFile::clear()
|
||||
sfile = nullptr;
|
||||
}
|
||||
|
||||
void CSaveFile::putMagicBytes( const std::string &text )
|
||||
void CSaveFile::putMagicBytes(const std::string &text)
|
||||
{
|
||||
write(text.c_str(), text.length());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user