mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	replaced std::string with boost::filesystem::path in several places
This commit is contained in:
		| @@ -307,10 +307,10 @@ void CMenuScreen::switchToTab(size_t index) | ||||
| //funciton for std::string -> std::function conversion for main menu | ||||
| static std::function<void()> genCommand(CMenuScreen* menu, std::vector<std::string> menuType, const std::string &string) | ||||
| { | ||||
| 	static const std::vector<std::string> commandType  =  | ||||
| 	static const std::vector<std::string> commandType  = | ||||
| 		{"to", "campaigns", "start", "load", "exit", "highscores"}; | ||||
|  | ||||
| 	static const std::vector<std::string> gameType =  | ||||
| 	static const std::vector<std::string> gameType = | ||||
| 		{"single", "multi", "campaign", "tutorial"}; | ||||
|  | ||||
| 	std::list<std::string> 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 | ||||
|   | ||||
| @@ -59,8 +59,8 @@ template <typename T> 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<typename U> 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<CLoadFile> 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<CPlayerInterface>(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::set<PlayerColor | ||||
| 			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); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @@ -605,7 +605,7 @@ void CClient::serialize(CISer & h, const int version, const std::set<PlayerColor | ||||
| 		for(int i=0; i < players; i++) | ||||
| 		{ | ||||
| 			std::string dllname; | ||||
| 			PlayerColor pid;  | ||||
| 			PlayerColor pid; | ||||
| 			bool isHuman = false; | ||||
|  | ||||
| 			h & pid & dllname & isHuman; | ||||
| @@ -618,7 +618,7 @@ void CClient::serialize(CISer & h, const int version, const std::set<PlayerColor | ||||
| 				{ | ||||
|                     if(playerIDs.count(pid)) | ||||
|                        installNewBattleInterface(CDynLibHandler::getNewBattleAI(dllname), pid); | ||||
| 					//TODO? consider serialization  | ||||
| 					//TODO? consider serialization | ||||
| 					continue; | ||||
| 				} | ||||
| 				else | ||||
| @@ -640,7 +640,7 @@ void CClient::serialize(CISer & h, const int version, const std::set<PlayerColor | ||||
|             if(playerIDs.count(pid)) | ||||
|                  installNewPlayerInterface(nInt, pid); | ||||
|  | ||||
|             nInt->loadGame(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<boost::recursive_mutex> 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<CBattleGameInterface> ba | ||||
| 	catch(...) | ||||
| 	{ | ||||
| 		handleException(); | ||||
| 	}	 | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CClient::invalidatePaths() | ||||
| @@ -889,7 +889,7 @@ void CClient::installNewBattleInterface(std::shared_ptr<CBattleGameInterface> ba | ||||
| 	boost::unique_lock<boost::recursive_mutex> 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); | ||||
| 		} | ||||
|   | ||||
| @@ -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 | ||||
| } | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "StdInc.h" | ||||
| #include "../../lib/CConfigHandler.h" | ||||
|  | ||||
| namespace Ui { | ||||
|   | ||||
| @@ -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"); | ||||
|   | ||||
| @@ -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<std::string> &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<SettingsListener>; | ||||
| // template DLL_LINKAGE struct SettingsStorage::NodeAccessor<Settings>; | ||||
|  | ||||
| @@ -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<int,int> 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(); | ||||
|   | ||||
| @@ -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<void(si32)>& 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; | ||||
| } | ||||
|   | ||||
| @@ -4,6 +4,7 @@ | ||||
| #include "registerTypes/RegisterTypes.h" | ||||
| #include "mapping/CMap.h" | ||||
| #include "CGameState.h" | ||||
| #include "filesystem/FileStream.h" | ||||
|  | ||||
| #include <boost/asio.hpp> | ||||
|  | ||||
| @@ -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<std::ofstream>(fname.c_str(), std::ios::binary); | ||||
| 		sfile = make_unique<FileStream>(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<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)) | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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<std::ofstream> sfile; | ||||
| 	boost::filesystem::path fName; | ||||
| 	std::unique_ptr<FileStream> 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<boost::filesystem::ifstream> sfile; | ||||
| 	boost::filesystem::path fName; | ||||
| 	std::unique_ptr<FileStream> sfile; | ||||
|  | ||||
| 	CLoadFile(const boost::filesystem::path & fname, int minimalVersion = version); //throws! | ||||
| 	~CLoadFile(); | ||||
| @@ -1606,7 +1607,7 @@ public: | ||||
| 	std::unique_ptr<CLoadFile> 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); | ||||
|   | ||||
| @@ -27,7 +27,7 @@ std::string CMappedFileLoader::getMountPoint() const | ||||
| 	return ""; // does not have any meaning with this type of data source | ||||
| } | ||||
|  | ||||
| boost::optional<std::string> CMappedFileLoader::getResourceName(const ResourceID & resourceName) const | ||||
| boost::optional<boost::filesystem::path> 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<std::string> CFilesystemList::getResourceName(const ResourceID & resourceName) const | ||||
| boost::optional<boost::filesystem::path> CFilesystemList::getResourceName(const ResourceID & resourceName) const | ||||
| { | ||||
| 	if (existsResource(resourceName)) | ||||
| 		return getResourcesWithName(resourceName).back()->getResourceName(resourceName); | ||||
| 	return boost::optional<std::string>(); | ||||
| 	return boost::optional<boost::filesystem::path>(); | ||||
| } | ||||
|  | ||||
| std::unordered_set<ResourceID> CFilesystemList::getFilteredFiles(std::function<bool(const ResourceID &)> filter) const | ||||
|   | ||||
| @@ -41,7 +41,7 @@ public: | ||||
| 	std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override; | ||||
| 	bool existsResource(const ResourceID & resourceName) const override; | ||||
| 	std::string getMountPoint() const override; | ||||
| 	boost::optional<std::string> getResourceName(const ResourceID & resourceName) const override; | ||||
| 	boost::optional<boost::filesystem::path> getResourceName(const ResourceID & resourceName) const override; | ||||
| 	std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override; | ||||
|  | ||||
| private: | ||||
| @@ -59,14 +59,14 @@ class DLL_LINKAGE CFilesystemList : public ISimpleResourceLoader | ||||
| 	std::set<ISimpleResourceLoader *> 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<CInputStream> load(const ResourceID & resourceName) const override; | ||||
| 	bool existsResource(const ResourceID & resourceName) const override; | ||||
| 	std::string getMountPoint() const override; | ||||
| 	boost::optional<std::string> getResourceName(const ResourceID & resourceName) const override; | ||||
| 	boost::optional<boost::filesystem::path> getResourceName(const ResourceID & resourceName) const override; | ||||
| 	std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override; | ||||
| 	bool createResource(std::string filename, bool update = false) override; | ||||
| 	std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourceID & resourceName) const override; | ||||
|   | ||||
| @@ -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<std::string> CFilesystemLoader::getResourceName(const ResourceID & resourceName) const | ||||
| boost::optional<boost::filesystem::path> CFilesystemLoader::getResourceName(const ResourceID & resourceName) const | ||||
| { | ||||
| 	assert(existsResource(resourceName)); | ||||
|  | ||||
| 	return (baseDirectory / fileList.at(resourceName)).string(); | ||||
| 	return baseDirectory / fileList.at(resourceName); | ||||
| } | ||||
|  | ||||
| std::unordered_set<ResourceID> CFilesystemLoader::getFilteredFiles(std::function<bool(const ResourceID &)> 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; | ||||
|   | ||||
| @@ -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<std::string> getResourceName(const ResourceID & resourceName) const override; | ||||
| 	boost::optional<boost::filesystem::path> getResourceName(const ResourceID & resourceName) const override; | ||||
| 	std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override; | ||||
|  | ||||
| private: | ||||
|   | ||||
| @@ -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<ResourceID, unz_file_pos> CZipLoader::listFiles(const std::string & mountPoint, const std::string & archive) | ||||
| std::unordered_map<ResourceID, unz64_file_pos> CZipLoader::listFiles(const std::string & mountPoint, const boost::filesystem::path & archive) | ||||
| { | ||||
| 	std::unordered_map<ResourceID, unz_file_pos> ret; | ||||
| 	std::unordered_map<ResourceID, unz64_file_pos> 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<char> 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); | ||||
| 	} | ||||
|   | ||||
| @@ -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<ResourceID, unz_file_pos> files; | ||||
| 	std::unordered_map<ResourceID, unz64_file_pos> files; | ||||
|  | ||||
| 	std::unordered_map<ResourceID, unz_file_pos> listFiles(const std::string & mountPoint, const std::string &archive); | ||||
| 	std::unordered_map<ResourceID, unz64_file_pos> 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 | ||||
|   | ||||
| @@ -1,5 +1,4 @@ | ||||
| #include "StdInc.h" | ||||
| #define INC_FROM_FILESTREAM_CPP | ||||
| #include "FileStream.h" | ||||
| #include "../minizip/unzip.h" | ||||
|  | ||||
|   | ||||
| @@ -4,7 +4,7 @@ | ||||
| #include <boost/iostreams/categories.hpp> | ||||
| #include <boost/iostreams/stream.hpp> | ||||
|  | ||||
| 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<FileBuf>; | ||||
| #else | ||||
| template class DLL_LINKAGE boost::iostreams::stream<FileBuf>; | ||||
| #endif | ||||
|  | ||||
| class DLL_LINKAGE FileStream : public boost::iostreams::stream<FileBuf> | ||||
|   | ||||
| @@ -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<std::string> getResourceName(const ResourceID & resourceName) const | ||||
| 	virtual boost::optional<boost::filesystem::path> getResourceName(const ResourceID & resourceName) const | ||||
| 	{ | ||||
| 		return boost::optional<std::string>(); | ||||
| 		return boost::optional<boost::filesystem::path>(); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
|   | ||||
		Reference in New Issue
	
	Block a user