diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index 15ccddc66..218f933ce 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -307,10 +307,10 @@ void CMenuScreen::switchToTab(size_t index) //funciton for std::string -> std::function conversion for main menu static std::function genCommand(CMenuScreen* menu, std::vector menuType, const std::string &string) { - static const std::vector commandType = + static const std::vector commandType = {"to", "campaigns", "start", "load", "exit", "highscores"}; - static const std::vector gameType = + static const std::vector gameType = {"single", "multi", "campaign", "tutorial"}; std::list commands; @@ -554,8 +554,8 @@ CGPreGame *CGPreGame::create() { if(!CGP) CGP = new CGPreGame(); - - GH.terminate_cond.set(false); + + GH.terminate_cond.set(false); return CGP; } @@ -1362,9 +1362,9 @@ void SelectionTab::select( int position ) if(txt) { - std::string filename = *CResourceHandler::get("local")->getResourceName( + auto filename = *CResourceHandler::get("local")->getResourceName( ResourceID(curItems[py]->fileURI, EResType::CLIENT_SAVEGAME)); - txt->setText(CFileInfo(filename).getBaseName()); + txt->setText(filename.stem()); } onSelect(curItems[py]); @@ -1487,8 +1487,8 @@ void SelectionTab::printMaps(SDL_Surface *to) } else { - name = CFileInfo(*CResourceHandler::get("local")->getResourceName( - ResourceID(currentItem->fileURI, EResType::CLIENT_SAVEGAME))).getBaseName(); + name = CResourceHandler::get("local")->getResourceName( + ResourceID(currentItem->fileURI, EResType::CLIENT_SAVEGAME))->stem().string(); } //print name diff --git a/client/Client.cpp b/client/Client.cpp index 8f8ef5be0..894536190 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -59,8 +59,8 @@ template class CApplyOnCL; class CBaseForCLApply { public: - virtual void applyOnClAfter(CClient *cl, void *pack) const =0; - virtual void applyOnClBefore(CClient *cl, void *pack) const =0; + virtual void applyOnClAfter(CClient *cl, void *pack) const =0; + virtual void applyOnClBefore(CClient *cl, void *pack) const =0; virtual ~CBaseForCLApply(){} template static CBaseForCLApply *getApplier(const U * t=nullptr) @@ -144,7 +144,7 @@ void CClient::waitForMoveAndSend(PlayerColor color) { logNetwork->traceStream() << "Send battle action to server: " << ba; MakeAction temp_action(ba); - sendRequest(&temp_action, color); + sendRequest(&temp_action, color); } return; } @@ -169,8 +169,8 @@ void CClient::run() while(!terminate) { CPack *pack = serv->retreivePack(); //get the package from the server - - if (terminate) + + if (terminate) { vstd::clear_pointer(pack); break; @@ -178,10 +178,10 @@ void CClient::run() handlePack(pack); } - } + } //catch only asio exceptions catch (const boost::system::system_error& e) - { + { logNetwork->errorStream() << "Lost connection to server, ending listening thread!"; logNetwork->errorStream() << e.what(); if(!terminate) //rethrow (-> boom!) only if closing connection was unexpected @@ -267,8 +267,8 @@ void CClient::loadGame(const std::string & fname, const bool server, const std:: std::unique_ptr loader; try { - std::string clientSaveName = *CResourceHandler::get("local")->getResourceName(ResourceID(fname, EResType::CLIENT_SAVEGAME)); - std::string controlServerSaveName; + boost::filesystem::path clientSaveName = *CResourceHandler::get("local")->getResourceName(ResourceID(fname, EResType::CLIENT_SAVEGAME)); + boost::filesystem::path controlServerSaveName; if (CResourceHandler::get("local")->existsResource(ResourceID(fname, EResType::SERVER_SAVEGAME))) { @@ -276,7 +276,7 @@ void CClient::loadGame(const std::string & fname, const bool server, const std:: } else// create entry for server savegame. Triggered if save was made after launch and not yet present in res handler { - controlServerSaveName = clientSaveName.substr(0, clientSaveName.find_last_of(".")) + ".vsgm1"; + controlServerSaveName = boost::filesystem::path(clientSaveName).replace_extension(".vsgm1"); CResourceHandler::get("local")->createResource(controlServerSaveName, true); } @@ -320,7 +320,7 @@ void CClient::loadGame(const std::string & fname, const bool server, const std:: *serv << ui8(3) << ui8(loadNumPlayers); //load game; one client if single-player *serv << fname; *serv >> pom8; - if(pom8) + if(pom8) throw std::runtime_error("Server cannot open the savegame!"); else logNetwork->infoStream() << "Server opened savegame properly."; @@ -376,7 +376,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) { enum {SINGLE, HOST, GUEST} networkMode = SINGLE; - if (con == nullptr) + if (con == nullptr) { CServerHandler sh; serv = sh.connectToServer(); @@ -459,7 +459,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) logNetwork->infoStream() << boost::format("Player %s will be lead by %s") % color % AiToGive; installNewPlayerInterface(CDynLibHandler::getNewAI(AiToGive), color); } - else + else { installNewPlayerInterface(std::make_shared(color), color); humanPlayers++; @@ -502,7 +502,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) // nm->giveActionCB(this); // nm->giveInfoCB(this); // nm->init(); -// +// // erm = nm; //something tells me that there'll at most one module and it'll be ERM // } } @@ -510,7 +510,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) void CClient::serialize(COSer & h, const int version) { assert(h.saving); - h & hotSeat; + h & hotSeat; { ui8 players = playerint.size(); h & players; @@ -520,7 +520,7 @@ void CClient::serialize(COSer & h, const int version) LOG_TRACE_PARAMS(logGlobal, "Saving player %s interface", i->first); assert(i->first == i->second->playerID); h & i->first & i->second->dllName & i->second->human; - i->second->saveGame(h, version); + i->second->saveGame(h, version); } } } @@ -536,7 +536,7 @@ void CClient::serialize(CISer & h, const int version) for(int i=0; i < players; i++) { std::string dllname; - PlayerColor pid; + PlayerColor pid; bool isHuman = false; h & pid & dllname & isHuman; @@ -548,7 +548,7 @@ void CClient::serialize(CISer & h, const int version) if(pid == PlayerColor::NEUTRAL) { installNewBattleInterface(CDynLibHandler::getNewBattleAI(dllname), pid); - //TODO? consider serialization + //TODO? consider serialization continue; } else @@ -589,7 +589,7 @@ void CClient::serialize(COSer & h, const int version, const std::setfirst); assert(i->first == i->second->playerID); h & i->first & i->second->dllName & i->second->human; - i->second->saveGame(h, version); + i->second->saveGame(h, version); } } } @@ -605,7 +605,7 @@ void CClient::serialize(CISer & h, const int version, const std::setloadGame(h, version); + nInt->loadGame(h, version); } if(playerIDs.count(PlayerColor::NEUTRAL)) @@ -714,7 +714,7 @@ void CClient::battleStarted(const BattleInfo * info) { for(auto &battleCb : battleCallbacks) { - if(vstd::contains_if(info->sides, [&](const SideInBattle& side) {return side.color == battleCb.first; }) + if(vstd::contains_if(info->sides, [&](const SideInBattle& side) {return side.color == battleCb.first; }) || battleCb.first >= PlayerColor::PLAYER_LIMIT) { battleCb.second->setBattle(info); @@ -742,7 +742,7 @@ void CClient::battleStarted(const BattleInfo * info) { boost::unique_lock un(*LOCPLINT->pim); auto bi = new CBattleInterface(leftSide.armyObject, rightSide.armyObject, leftSide.hero, rightSide.hero, - Rect((screen->w - 800)/2, + Rect((screen->w - 800)/2, (screen->h - 600)/2, 800, 600), att, def); GH.pushInt(bi); @@ -805,7 +805,7 @@ void CClient::commenceTacticPhaseForInt(std::shared_ptr ba catch(...) { handleException(); - } + } } void CClient::invalidatePaths() @@ -889,7 +889,7 @@ void CClient::installNewBattleInterface(std::shared_ptr ba boost::unique_lock un(*LOCPLINT->pim); PlayerColor colorUsed = color.get_value_or(PlayerColor::UNFLAGGABLE); - if(!color) + if(!color) privilagedBattleEventReceivers.push_back(battleInterface); battleints[colorUsed] = battleInterface; @@ -961,7 +961,7 @@ CConnection * CServerHandler::connectToServer() #endif th.update(); //put breakpoint here to attach to server before it does something stupid - + CConnection *ret = justConnectToServer(settings["server"]["server"].String(), port); if(verbose) @@ -1033,7 +1033,7 @@ CConnection * CServerHandler::justConnectToServer(const std::string &host, const try { logNetwork->infoStream() << "Establishing connection..."; - ret = new CConnection( host.size() ? host : settings["server"]["server"].String(), + ret = new CConnection( host.size() ? host : settings["server"]["server"].String(), realPort, NAME); } diff --git a/launcher/StdInc.h b/launcher/StdInc.h index 0803302d5..dcaee354c 100644 --- a/launcher/StdInc.h +++ b/launcher/StdInc.h @@ -24,6 +24,6 @@ inline boost::filesystem::path qstringToPath(const QString & path) #ifdef VCMI_WINDOWS return boost::filesystem::path(path.toStdWString()); #else - return boost::filesystem::path(filename.toUtf8().data()); + return boost::filesystem::path(path.toUtf8().data()); #endif } diff --git a/launcher/modManager/cmodlistview_moc.h b/launcher/modManager/cmodlistview_moc.h index e009d5edf..f273e2343 100644 --- a/launcher/modManager/cmodlistview_moc.h +++ b/launcher/modManager/cmodlistview_moc.h @@ -1,5 +1,6 @@ #pragma once +#include "StdInc.h" #include "../../lib/CConfigHandler.h" namespace Ui { diff --git a/launcher/modManager/cmodmanager.cpp b/launcher/modManager/cmodmanager.cpp index eccd65601..f4a7f8306 100644 --- a/launcher/modManager/cmodmanager.cpp +++ b/launcher/modManager/cmodmanager.cpp @@ -69,8 +69,8 @@ void CModManager::loadMods() ResourceID resID(CModInfo::getModFile(modname)); if (CResourceHandler::get()->existsResource(resID)) { - std::string name = *CResourceHandler::get()->getResourceName(resID); - auto mod = JsonUtils::JsonFromFile(QString::fromUtf8(name.c_str())); + boost::filesystem::path name = *CResourceHandler::get()->getResourceName(resID); + auto mod = JsonUtils::JsonFromFile(qstringToPath(name)); localMods.insert(QString::fromUtf8(modname.c_str()).toLower(), mod); } } @@ -262,7 +262,7 @@ bool CModManager::doUninstallMod(QString modname) { ResourceID resID(std::string("Mods/") + modname.toUtf8().data(), EResType::DIRECTORY); // Get location of the mod, in case-insensitive way - QString modDir = QString::fromUtf8((*CResourceHandler::get()->getResourceName(resID)).c_str()); + QString modDir = qstringFromPath(*CResourceHandler::get()->getResourceName(resID)); if (!QDir(modDir).exists()) return addError(modname, "Data with this mod was not found"); diff --git a/lib/CConfigHandler.cpp b/lib/CConfigHandler.cpp index b2f4f0194..ba213e6e5 100644 --- a/lib/CConfigHandler.cpp +++ b/lib/CConfigHandler.cpp @@ -2,6 +2,7 @@ #include "CConfigHandler.h" #include "../lib/filesystem/Filesystem.h" +#include "../lib/filesystem/FileStream.h" #include "../lib/GameConstants.h" #include "../lib/VCMIDirs.h" @@ -80,7 +81,7 @@ void SettingsStorage::invalidateNode(const std::vector &changedPath savedConf.Struct().erase("session"); JsonUtils::minimize(savedConf, "vcmi:settings"); - std::ofstream file(*CResourceHandler::get()->getResourceName(ResourceID("config/settings.json")), std::ofstream::trunc); + FileStream file(*CResourceHandler::get()->getResourceName(ResourceID("config/settings.json")), std::ofstream::out | std::ofstream::trunc); file << savedConf; } @@ -173,7 +174,7 @@ JsonNode& Settings::operator [](std::string value) { return node[value]; } -// +// // template DLL_LINKAGE struct SettingsStorage::NodeAccessor; // template DLL_LINKAGE struct SettingsStorage::NodeAccessor; @@ -214,14 +215,14 @@ void config::CConfigHandler::init() const JsonNode config(ResourceID("config/resolutions.json")); const JsonVector &guisettings_vec = config["GUISettings"].Vector(); - for(const JsonNode &g : guisettings_vec) + for(const JsonNode &g : guisettings_vec) { std::pair curRes(g["resolution"]["x"].Float(), g["resolution"]["y"].Float()); GUIOptions *current = &conf.guiOptions[curRes]; - + current->ac.inputLineLength = g["InGameConsole"]["maxInputPerLine"].Float(); current->ac.outputLineLength = g["InGameConsole"]["maxOutputPerLine"].Float(); - + current->ac.advmapX = g["AdvMap"]["x"].Float(); current->ac.advmapY = g["AdvMap"]["y"].Float(); current->ac.advmapW = g["AdvMap"]["width"].Float(); diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index 571d5c10b..b4f34b50c 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -2,6 +2,7 @@ #include "CModHandler.h" #include "mapObjects/CObjectClassesHandler.h" #include "JsonNode.h" +#include "filesystem/FileStream.h" #include "filesystem/Filesystem.h" #include "filesystem/AdapterLoaders.h" #include "filesystem/CFilesystemLoader.h" @@ -101,9 +102,9 @@ void CIdentifierStorage::requestIdentifier(std::string scope, std::string type, void CIdentifierStorage::requestIdentifier(std::string scope, std::string fullName, const std::function& callback) { - auto scopeAndFullName = splitString(fullName, ':'); - auto typeAndName = splitString(scopeAndFullName.second, '.'); - + auto scopeAndFullName = splitString(fullName, ':'); + auto typeAndName = splitString(scopeAndFullName.second, '.'); + requestIdentifier(ObjectCallback(scope, scopeAndFullName.first, typeAndName.first, typeAndName.second, callback, false)); } @@ -331,11 +332,11 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali { ModInfo & modInfo = modData[modName]; bool result = true; - + auto performValidate = [&,this](JsonNode & data, const std::string & name){ handler->beforeValidate(data); if (validate) - result &= JsonUtils::validate(data, "vcmi:" + objectName, name); + result &= JsonUtils::validate(data, "vcmi:" + objectName, name); }; // apply patches @@ -355,7 +356,7 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali if (originalData.size() > index) { JsonUtils::merge(originalData[index], data); - + performValidate(originalData[index],name); handler->loadObject(modName, name, originalData[index], index); @@ -880,6 +881,6 @@ void CModHandler::afterLoad() } modSettings["core"] = coreMod.saveLocalData(); - std::ofstream file(*CResourceHandler::get()->getResourceName(ResourceID("config/modSettings.json")), std::ofstream::trunc); + FileStream file(*CResourceHandler::get()->getResourceName(ResourceID("config/modSettings.json")), std::ofstream::out | std::ofstream::trunc); file << modSettings; } diff --git a/lib/Connection.cpp b/lib/Connection.cpp index 20b113a81..3572ec698 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -4,6 +4,7 @@ #include "registerTypes/RegisterTypes.h" #include "mapping/CMap.h" #include "CGameState.h" +#include "filesystem/FileStream.h" #include @@ -282,7 +283,7 @@ void CConnection::enableSmartVectorMemberSerializatoin() CSerializer::smartVectorMembersSerialization = true; } -CSaveFile::CSaveFile( const std::string &fname ): serializer(this) +CSaveFile::CSaveFile( const boost::filesystem::path &fname ): serializer(this) { registerTypes(serializer); openNextFile(fname); @@ -298,12 +299,12 @@ int CSaveFile::write( const void * data, unsigned size ) return size; } -void CSaveFile::openNextFile(const std::string &fname) +void CSaveFile::openNextFile(const boost::filesystem::path &fname) { fName = fname; try { - sfile = make_unique(fname.c_str(), std::ios::binary); + sfile = make_unique(fname, std::ios::out | std::ios::binary); sfile->exceptions(std::ifstream::failbit | std::ifstream::badbit); //we throw a lot anyway if(!(*sfile)) @@ -364,7 +365,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)) @@ -569,7 +570,7 @@ void CSerializer::addStdVecItems(CGameState *gs, LibClasses *lib) smartVectorMembersSerialization = true; } -CLoadIntegrityValidator::CLoadIntegrityValidator( const std::string &primaryFileName, const std::string &controlFileName, int minimalVersion /*= version*/ ) +CLoadIntegrityValidator::CLoadIntegrityValidator( const boost::filesystem::path &primaryFileName, const boost::filesystem::path &controlFileName, int minimalVersion /*= version*/ ) : serializer(this), foundDesync(false) { registerTypes(serializer); diff --git a/lib/Connection.h b/lib/Connection.h index 259b9f23f..ea3f28b91 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -39,6 +39,7 @@ class CGameState; class CCreature; class LibClasses; class CHero; +class FileStream; struct CPack; extern DLL_LINKAGE LibClasses * VLC; namespace mpl = boost::mpl; @@ -1550,14 +1551,14 @@ public: COSer serializer; - std::string fName; - std::unique_ptr sfile; + boost::filesystem::path fName; + std::unique_ptr sfile; - CSaveFile(const std::string &fname); //throws! + CSaveFile(const boost::filesystem::path &fname); //throws! ~CSaveFile(); int write(const void * data, unsigned size) override; - void openNextFile(const std::string &fname); //throws! + void openNextFile(const boost::filesystem::path &fname); //throws! void clear(); void reportState(CLogger * out) override; @@ -1577,8 +1578,8 @@ class DLL_LINKAGE CLoadFile public: CISer serializer; - std::string fName; - std::unique_ptr sfile; + boost::filesystem::path fName; + std::unique_ptr sfile; CLoadFile(const boost::filesystem::path & fname, int minimalVersion = version); //throws! ~CLoadFile(); @@ -1606,7 +1607,7 @@ public: std::unique_ptr primaryFile, controlFile; bool foundDesync; - CLoadIntegrityValidator(const std::string &primaryFileName, const std::string &controlFileName, int minimalVersion = version); //throws! + CLoadIntegrityValidator(const boost::filesystem::path &primaryFileName, const boost::filesystem::path &controlFileName, int minimalVersion = version); //throws! int read( void * data, unsigned size) override; //throws! void checkMagicBytes(const std::string &text); diff --git a/lib/filesystem/AdapterLoaders.cpp b/lib/filesystem/AdapterLoaders.cpp index cb2ceaf23..fc7cd3583 100644 --- a/lib/filesystem/AdapterLoaders.cpp +++ b/lib/filesystem/AdapterLoaders.cpp @@ -27,7 +27,7 @@ std::string CMappedFileLoader::getMountPoint() const return ""; // does not have any meaning with this type of data source } -boost::optional CMappedFileLoader::getResourceName(const ResourceID & resourceName) const +boost::optional CMappedFileLoader::getResourceName(const ResourceID & resourceName) const { return CResourceHandler::get()->getResourceName(fileList.at(resourceName)); } @@ -80,11 +80,11 @@ std::string CFilesystemList::getMountPoint() const return ""; } -boost::optional CFilesystemList::getResourceName(const ResourceID & resourceName) const +boost::optional CFilesystemList::getResourceName(const ResourceID & resourceName) const { if (existsResource(resourceName)) return getResourcesWithName(resourceName).back()->getResourceName(resourceName); - return boost::optional(); + return boost::optional(); } std::unordered_set CFilesystemList::getFilteredFiles(std::function filter) const diff --git a/lib/filesystem/AdapterLoaders.h b/lib/filesystem/AdapterLoaders.h index cabe5760e..ca3058097 100644 --- a/lib/filesystem/AdapterLoaders.h +++ b/lib/filesystem/AdapterLoaders.h @@ -41,7 +41,7 @@ public: std::unique_ptr load(const ResourceID & resourceName) const override; bool existsResource(const ResourceID & resourceName) const override; std::string getMountPoint() const override; - boost::optional getResourceName(const ResourceID & resourceName) const override; + boost::optional getResourceName(const ResourceID & resourceName) const override; std::unordered_set getFilteredFiles(std::function filter) const override; private: @@ -59,14 +59,14 @@ class DLL_LINKAGE CFilesystemList : public ISimpleResourceLoader std::set writeableLoaders; //FIXME: this is only compile fix, should be removed in the end - CFilesystemList(CFilesystemList &) - { - //class is not copyable - } - CFilesystemList &operator=(CFilesystemList &) - { - //class is not copyable - return *this; + CFilesystemList(CFilesystemList &) + { + //class is not copyable + } + CFilesystemList &operator=(CFilesystemList &) + { + //class is not copyable + return *this; } public: @@ -77,7 +77,7 @@ public: std::unique_ptr load(const ResourceID & resourceName) const override; bool existsResource(const ResourceID & resourceName) const override; std::string getMountPoint() const override; - boost::optional getResourceName(const ResourceID & resourceName) const override; + boost::optional getResourceName(const ResourceID & resourceName) const override; std::unordered_set getFilteredFiles(std::function filter) const override; bool createResource(std::string filename, bool update = false) override; std::vector getResourcesWithName(const ResourceID & resourceName) const override; diff --git a/lib/filesystem/CFilesystemLoader.cpp b/lib/filesystem/CFilesystemLoader.cpp index 0704c8a06..5746cab70 100644 --- a/lib/filesystem/CFilesystemLoader.cpp +++ b/lib/filesystem/CFilesystemLoader.cpp @@ -3,6 +3,7 @@ #include "CFileInfo.h" #include "CFileInputStream.h" +#include "FileStream.h" namespace bfs = boost::filesystem; @@ -32,11 +33,11 @@ std::string CFilesystemLoader::getMountPoint() const return mountPoint; } -boost::optional CFilesystemLoader::getResourceName(const ResourceID & resourceName) const +boost::optional CFilesystemLoader::getResourceName(const ResourceID & resourceName) const { assert(existsResource(resourceName)); - return (baseDirectory / fileList.at(resourceName)).string(); + return baseDirectory / fileList.at(resourceName); } std::unordered_set CFilesystemLoader::getFilteredFiles(std::function filter) const @@ -68,8 +69,7 @@ bool CFilesystemLoader::createResource(std::string filename, bool update) if (!update) { - bfs::ofstream newfile(baseDirectory / filename); - if (!newfile.good()) + if (!FileStream::CreateFile(baseDirectory / filename)) return false; } fileList[resID] = filename; diff --git a/lib/filesystem/CFilesystemLoader.h b/lib/filesystem/CFilesystemLoader.h index e7cfd9a81..f5573986b 100644 --- a/lib/filesystem/CFilesystemLoader.h +++ b/lib/filesystem/CFilesystemLoader.h @@ -38,7 +38,7 @@ public: bool existsResource(const ResourceID & resourceName) const override; std::string getMountPoint() const override; bool createResource(std::string filename, bool update = false) override; - boost::optional getResourceName(const ResourceID & resourceName) const override; + boost::optional getResourceName(const ResourceID & resourceName) const override; std::unordered_set getFilteredFiles(std::function filter) const override; private: diff --git a/lib/filesystem/CZipLoader.cpp b/lib/filesystem/CZipLoader.cpp index 44b139d40..4880f7a76 100644 --- a/lib/filesystem/CZipLoader.cpp +++ b/lib/filesystem/CZipLoader.cpp @@ -15,10 +15,10 @@ * */ -CZipStream::CZipStream(const std::string & archive, unz_file_pos filepos) +CZipStream::CZipStream(const boost::filesystem::path & archive, unz64_file_pos filepos) { - file = unzOpen(archive.c_str()); - unzGoToFilePos(file, &filepos); + file = unzOpen2_64(archive.c_str(), FileStream::GetMinizipFilefunc()); + unzGoToFilePos64(file, &filepos); unzOpenCurrentFile(file); } @@ -35,19 +35,19 @@ si64 CZipStream::readMore(ui8 * data, si64 size) si64 CZipStream::getSize() { - unz_file_info info; - unzGetCurrentFileInfo (file, &info, nullptr, 0, nullptr, 0, nullptr, 0); + unz_file_info64 info; + unzGetCurrentFileInfo64 (file, &info, nullptr, 0, nullptr, 0, nullptr, 0); return info.uncompressed_size; } ui32 CZipStream::calculateCRC32() { - unz_file_info info; - unzGetCurrentFileInfo (file, &info, nullptr, 0, nullptr, 0, nullptr, 0); + unz_file_info64 info; + unzGetCurrentFileInfo64 (file, &info, nullptr, 0, nullptr, 0, nullptr, 0); return info.crc; } -CZipLoader::CZipLoader(const std::string & mountPoint, const std::string & archive): +CZipLoader::CZipLoader(const std::string & mountPoint, const boost::filesystem::path & archive): archiveName(archive), mountPoint(mountPoint), files(listFiles(mountPoint, archive)) @@ -55,27 +55,27 @@ CZipLoader::CZipLoader(const std::string & mountPoint, const std::string & archi logGlobal->traceStream() << "Zip archive loaded, " << files.size() << " files found"; } -std::unordered_map CZipLoader::listFiles(const std::string & mountPoint, const std::string & archive) +std::unordered_map CZipLoader::listFiles(const std::string & mountPoint, const boost::filesystem::path & archive) { - std::unordered_map ret; + std::unordered_map ret; - unzFile file = unzOpen(archive.c_str()); + unzFile file = unzOpen2_64(archive.c_str(), FileStream::GetMinizipFilefunc()); if (unzGoToFirstFile(file) == UNZ_OK) { do { - unz_file_info info; + unz_file_info64 info; std::vector filename; // Fill unz_file_info structure with current file info - unzGetCurrentFileInfo (file, &info, nullptr, 0, nullptr, 0, nullptr, 0); + unzGetCurrentFileInfo64 (file, &info, nullptr, 0, nullptr, 0, nullptr, 0); filename.resize(info.size_filename); // Get name of current file. Contrary to docs "info" parameter can't be null - unzGetCurrentFileInfo (file, &info, filename.data(), filename.size(), nullptr, 0, nullptr, 0); + unzGetCurrentFileInfo64 (file, &info, filename.data(), filename.size(), nullptr, 0, nullptr, 0); std::string filenameString(filename.data(), filename.size()); - unzGetFilePos(file, &ret[ResourceID(mountPoint + filenameString)]); + unzGetFilePos64(file, &ret[ResourceID(mountPoint + filenameString)]); } while (unzGoToNextFile(file) == UNZ_OK); } diff --git a/lib/filesystem/CZipLoader.h b/lib/filesystem/CZipLoader.h index dea0f4b63..cf2d749c8 100644 --- a/lib/filesystem/CZipLoader.h +++ b/lib/filesystem/CZipLoader.h @@ -32,7 +32,7 @@ public: * @param archive path to archive to open * @param filepos position of file to open */ - CZipStream(const std::string & archive, unz_file_pos filepos); + CZipStream(const boost::filesystem::path & archive, unz64_file_pos filepos); ~CZipStream(); si64 getSize() override; @@ -44,14 +44,14 @@ protected: class DLL_LINKAGE CZipLoader : public ISimpleResourceLoader { - std::string archiveName; + boost::filesystem::path archiveName; std::string mountPoint; - std::unordered_map files; + std::unordered_map files; - std::unordered_map listFiles(const std::string & mountPoint, const std::string &archive); + std::unordered_map listFiles(const std::string & mountPoint, const boost::filesystem::path &archive); public: - CZipLoader(const std::string & mountPoint, const std::string & archive); + CZipLoader(const std::string & mountPoint, const boost::filesystem::path & archive); /// Interface implementation /// @see ISimpleResourceLoader diff --git a/lib/filesystem/FileStream.cpp b/lib/filesystem/FileStream.cpp index cddf814f8..2facda04f 100644 --- a/lib/filesystem/FileStream.cpp +++ b/lib/filesystem/FileStream.cpp @@ -1,5 +1,4 @@ #include "StdInc.h" -#define INC_FROM_FILESTREAM_CPP #include "FileStream.h" #include "../minizip/unzip.h" diff --git a/lib/filesystem/FileStream.h b/lib/filesystem/FileStream.h index 95af09e89..4c5435439 100644 --- a/lib/filesystem/FileStream.h +++ b/lib/filesystem/FileStream.h @@ -4,7 +4,7 @@ #include #include -class FileBuf +class DLL_LINKAGE FileBuf { public: typedef char char_type; @@ -29,8 +29,6 @@ typedef zlib_filefunc64_def_s zlib_filefunc64_def; #ifdef VCMI_DLL extern template class DLL_LINKAGE boost::iostreams::stream; -#else -template class DLL_LINKAGE boost::iostreams::stream; #endif class DLL_LINKAGE FileStream : public boost::iostreams::stream diff --git a/lib/filesystem/ISimpleResourceLoader.h b/lib/filesystem/ISimpleResourceLoader.h index f04762210..fabb41a5a 100644 --- a/lib/filesystem/ISimpleResourceLoader.h +++ b/lib/filesystem/ISimpleResourceLoader.h @@ -48,9 +48,9 @@ public: * * @return path or empty optional if file can't be accessed independently (e.g. file in archive) */ - virtual boost::optional getResourceName(const ResourceID & resourceName) const + virtual boost::optional getResourceName(const ResourceID & resourceName) const { - return boost::optional(); + return boost::optional(); } /**