From e79c522c4b254695ea504f86523290a4639fd89d Mon Sep 17 00:00:00 2001 From: Arseniy Shestakov Date: Sun, 30 Oct 2016 15:14:59 +0300 Subject: [PATCH] Serializer refactoring: fix FileStream usage for game loading Miss this one rebase. Without this one non-English characters in paths to saves cause issues. --- lib/serializer/BinaryDeserializer.cpp | 9 +++++---- lib/serializer/BinaryDeserializer.h | 4 ++-- lib/serializer/BinarySerializer.cpp | 7 ++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/serializer/BinaryDeserializer.cpp b/lib/serializer/BinaryDeserializer.cpp index 68b0f3008..ce47c7c43 100644 --- a/lib/serializer/BinaryDeserializer.cpp +++ b/lib/serializer/BinaryDeserializer.cpp @@ -15,7 +15,8 @@ extern template void registerTypes(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(fname, std::ios::binary); + sfile = make_unique(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()); diff --git a/lib/serializer/BinaryDeserializer.h b/lib/serializer/BinaryDeserializer.h index 7b082db33..447ba54da 100644 --- a/lib/serializer/BinaryDeserializer.h +++ b/lib/serializer/BinaryDeserializer.h @@ -514,9 +514,9 @@ public: BinaryDeserializer serializer; std::string fName; - std::unique_ptr sfile; + std::unique_ptr 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! diff --git a/lib/serializer/BinarySerializer.cpp b/lib/serializer/BinarySerializer.cpp index 1c0a8afff..b5b7276ec 100644 --- a/lib/serializer/BinarySerializer.cpp +++ b/lib/serializer/BinarySerializer.cpp @@ -15,7 +15,8 @@ extern template void registerTypes(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()); }