mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
replaced std::string with boost::filesystem::path in several places
This commit is contained in:
parent
933b7c1f5e
commit
cf61837ced
@ -1362,9 +1362,9 @@ void SelectionTab::select( int position )
|
|||||||
|
|
||||||
if(txt)
|
if(txt)
|
||||||
{
|
{
|
||||||
std::string filename = *CResourceHandler::get("local")->getResourceName(
|
auto filename = *CResourceHandler::get("local")->getResourceName(
|
||||||
ResourceID(curItems[py]->fileURI, EResType::CLIENT_SAVEGAME));
|
ResourceID(curItems[py]->fileURI, EResType::CLIENT_SAVEGAME));
|
||||||
txt->setText(CFileInfo(filename).getBaseName());
|
txt->setText(filename.stem());
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelect(curItems[py]);
|
onSelect(curItems[py]);
|
||||||
@ -1487,8 +1487,8 @@ void SelectionTab::printMaps(SDL_Surface *to)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
name = CFileInfo(*CResourceHandler::get("local")->getResourceName(
|
name = CResourceHandler::get("local")->getResourceName(
|
||||||
ResourceID(currentItem->fileURI, EResType::CLIENT_SAVEGAME))).getBaseName();
|
ResourceID(currentItem->fileURI, EResType::CLIENT_SAVEGAME))->stem().string();
|
||||||
}
|
}
|
||||||
|
|
||||||
//print name
|
//print name
|
||||||
|
@ -267,8 +267,8 @@ void CClient::loadGame(const std::string & fname, const bool server, const std::
|
|||||||
std::unique_ptr<CLoadFile> loader;
|
std::unique_ptr<CLoadFile> loader;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::string clientSaveName = *CResourceHandler::get("local")->getResourceName(ResourceID(fname, EResType::CLIENT_SAVEGAME));
|
boost::filesystem::path clientSaveName = *CResourceHandler::get("local")->getResourceName(ResourceID(fname, EResType::CLIENT_SAVEGAME));
|
||||||
std::string controlServerSaveName;
|
boost::filesystem::path controlServerSaveName;
|
||||||
|
|
||||||
if (CResourceHandler::get("local")->existsResource(ResourceID(fname, EResType::SERVER_SAVEGAME)))
|
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
|
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);
|
CResourceHandler::get("local")->createResource(controlServerSaveName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,6 @@ inline boost::filesystem::path qstringToPath(const QString & path)
|
|||||||
#ifdef VCMI_WINDOWS
|
#ifdef VCMI_WINDOWS
|
||||||
return boost::filesystem::path(path.toStdWString());
|
return boost::filesystem::path(path.toStdWString());
|
||||||
#else
|
#else
|
||||||
return boost::filesystem::path(filename.toUtf8().data());
|
return boost::filesystem::path(path.toUtf8().data());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "StdInc.h"
|
||||||
#include "../../lib/CConfigHandler.h"
|
#include "../../lib/CConfigHandler.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
@ -69,8 +69,8 @@ void CModManager::loadMods()
|
|||||||
ResourceID resID(CModInfo::getModFile(modname));
|
ResourceID resID(CModInfo::getModFile(modname));
|
||||||
if (CResourceHandler::get()->existsResource(resID))
|
if (CResourceHandler::get()->existsResource(resID))
|
||||||
{
|
{
|
||||||
std::string name = *CResourceHandler::get()->getResourceName(resID);
|
boost::filesystem::path name = *CResourceHandler::get()->getResourceName(resID);
|
||||||
auto mod = JsonUtils::JsonFromFile(QString::fromUtf8(name.c_str()));
|
auto mod = JsonUtils::JsonFromFile(qstringToPath(name));
|
||||||
localMods.insert(QString::fromUtf8(modname.c_str()).toLower(), mod);
|
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);
|
ResourceID resID(std::string("Mods/") + modname.toUtf8().data(), EResType::DIRECTORY);
|
||||||
// Get location of the mod, in case-insensitive way
|
// 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())
|
if (!QDir(modDir).exists())
|
||||||
return addError(modname, "Data with this mod was not found");
|
return addError(modname, "Data with this mod was not found");
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "CConfigHandler.h"
|
#include "CConfigHandler.h"
|
||||||
|
|
||||||
#include "../lib/filesystem/Filesystem.h"
|
#include "../lib/filesystem/Filesystem.h"
|
||||||
|
#include "../lib/filesystem/FileStream.h"
|
||||||
#include "../lib/GameConstants.h"
|
#include "../lib/GameConstants.h"
|
||||||
#include "../lib/VCMIDirs.h"
|
#include "../lib/VCMIDirs.h"
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ void SettingsStorage::invalidateNode(const std::vector<std::string> &changedPath
|
|||||||
savedConf.Struct().erase("session");
|
savedConf.Struct().erase("session");
|
||||||
JsonUtils::minimize(savedConf, "vcmi:settings");
|
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;
|
file << savedConf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "CModHandler.h"
|
#include "CModHandler.h"
|
||||||
#include "mapObjects/CObjectClassesHandler.h"
|
#include "mapObjects/CObjectClassesHandler.h"
|
||||||
#include "JsonNode.h"
|
#include "JsonNode.h"
|
||||||
|
#include "filesystem/FileStream.h"
|
||||||
#include "filesystem/Filesystem.h"
|
#include "filesystem/Filesystem.h"
|
||||||
#include "filesystem/AdapterLoaders.h"
|
#include "filesystem/AdapterLoaders.h"
|
||||||
#include "filesystem/CFilesystemLoader.h"
|
#include "filesystem/CFilesystemLoader.h"
|
||||||
@ -880,6 +881,6 @@ void CModHandler::afterLoad()
|
|||||||
}
|
}
|
||||||
modSettings["core"] = coreMod.saveLocalData();
|
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;
|
file << modSettings;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "registerTypes/RegisterTypes.h"
|
#include "registerTypes/RegisterTypes.h"
|
||||||
#include "mapping/CMap.h"
|
#include "mapping/CMap.h"
|
||||||
#include "CGameState.h"
|
#include "CGameState.h"
|
||||||
|
#include "filesystem/FileStream.h"
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
|
|
||||||
@ -282,7 +283,7 @@ void CConnection::enableSmartVectorMemberSerializatoin()
|
|||||||
CSerializer::smartVectorMembersSerialization = true;
|
CSerializer::smartVectorMembersSerialization = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSaveFile::CSaveFile( const std::string &fname ): serializer(this)
|
CSaveFile::CSaveFile( const boost::filesystem::path &fname ): serializer(this)
|
||||||
{
|
{
|
||||||
registerTypes(serializer);
|
registerTypes(serializer);
|
||||||
openNextFile(fname);
|
openNextFile(fname);
|
||||||
@ -298,12 +299,12 @@ int CSaveFile::write( const void * data, unsigned size )
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSaveFile::openNextFile(const std::string &fname)
|
void CSaveFile::openNextFile(const boost::filesystem::path &fname)
|
||||||
{
|
{
|
||||||
fName = fname;
|
fName = fname;
|
||||||
try
|
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
|
sfile->exceptions(std::ifstream::failbit | std::ifstream::badbit); //we throw a lot anyway
|
||||||
|
|
||||||
if(!(*sfile))
|
if(!(*sfile))
|
||||||
@ -364,7 +365,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))
|
||||||
@ -569,7 +570,7 @@ void CSerializer::addStdVecItems(CGameState *gs, LibClasses *lib)
|
|||||||
smartVectorMembersSerialization = true;
|
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)
|
: serializer(this), foundDesync(false)
|
||||||
{
|
{
|
||||||
registerTypes(serializer);
|
registerTypes(serializer);
|
||||||
|
@ -39,6 +39,7 @@ class CGameState;
|
|||||||
class CCreature;
|
class CCreature;
|
||||||
class LibClasses;
|
class LibClasses;
|
||||||
class CHero;
|
class CHero;
|
||||||
|
class FileStream;
|
||||||
struct CPack;
|
struct CPack;
|
||||||
extern DLL_LINKAGE LibClasses * VLC;
|
extern DLL_LINKAGE LibClasses * VLC;
|
||||||
namespace mpl = boost::mpl;
|
namespace mpl = boost::mpl;
|
||||||
@ -1550,14 +1551,14 @@ public:
|
|||||||
|
|
||||||
COSer serializer;
|
COSer serializer;
|
||||||
|
|
||||||
std::string fName;
|
boost::filesystem::path fName;
|
||||||
std::unique_ptr<std::ofstream> sfile;
|
std::unique_ptr<FileStream> sfile;
|
||||||
|
|
||||||
CSaveFile(const std::string &fname); //throws!
|
CSaveFile(const boost::filesystem::path &fname); //throws!
|
||||||
~CSaveFile();
|
~CSaveFile();
|
||||||
int write(const void * data, unsigned size) override;
|
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 clear();
|
||||||
void reportState(CLogger * out) override;
|
void reportState(CLogger * out) override;
|
||||||
|
|
||||||
@ -1577,8 +1578,8 @@ class DLL_LINKAGE CLoadFile
|
|||||||
public:
|
public:
|
||||||
CISer serializer;
|
CISer serializer;
|
||||||
|
|
||||||
std::string fName;
|
boost::filesystem::path fName;
|
||||||
std::unique_ptr<boost::filesystem::ifstream> sfile;
|
std::unique_ptr<FileStream> sfile;
|
||||||
|
|
||||||
CLoadFile(const boost::filesystem::path & fname, int minimalVersion = version); //throws!
|
CLoadFile(const boost::filesystem::path & fname, int minimalVersion = version); //throws!
|
||||||
~CLoadFile();
|
~CLoadFile();
|
||||||
@ -1606,7 +1607,7 @@ public:
|
|||||||
std::unique_ptr<CLoadFile> primaryFile, controlFile;
|
std::unique_ptr<CLoadFile> primaryFile, controlFile;
|
||||||
bool foundDesync;
|
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!
|
int read( void * data, unsigned size) override; //throws!
|
||||||
void checkMagicBytes(const std::string &text);
|
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
|
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));
|
return CResourceHandler::get()->getResourceName(fileList.at(resourceName));
|
||||||
}
|
}
|
||||||
@ -80,11 +80,11 @@ std::string CFilesystemList::getMountPoint() const
|
|||||||
return "";
|
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))
|
if (existsResource(resourceName))
|
||||||
return getResourcesWithName(resourceName).back()->getResourceName(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
|
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;
|
std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
|
||||||
bool existsResource(const ResourceID & resourceName) const override;
|
bool existsResource(const ResourceID & resourceName) const override;
|
||||||
std::string getMountPoint() 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;
|
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -77,7 +77,7 @@ public:
|
|||||||
std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
|
std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
|
||||||
bool existsResource(const ResourceID & resourceName) const override;
|
bool existsResource(const ResourceID & resourceName) const override;
|
||||||
std::string getMountPoint() 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;
|
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
|
||||||
bool createResource(std::string filename, bool update = false) override;
|
bool createResource(std::string filename, bool update = false) override;
|
||||||
std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourceID & resourceName) const override;
|
std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourceID & resourceName) const override;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "CFileInfo.h"
|
#include "CFileInfo.h"
|
||||||
#include "CFileInputStream.h"
|
#include "CFileInputStream.h"
|
||||||
|
#include "FileStream.h"
|
||||||
|
|
||||||
namespace bfs = boost::filesystem;
|
namespace bfs = boost::filesystem;
|
||||||
|
|
||||||
@ -32,11 +33,11 @@ std::string CFilesystemLoader::getMountPoint() const
|
|||||||
return mountPoint;
|
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));
|
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
|
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)
|
if (!update)
|
||||||
{
|
{
|
||||||
bfs::ofstream newfile(baseDirectory / filename);
|
if (!FileStream::CreateFile(baseDirectory / filename))
|
||||||
if (!newfile.good())
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fileList[resID] = filename;
|
fileList[resID] = filename;
|
||||||
|
@ -38,7 +38,7 @@ public:
|
|||||||
bool existsResource(const ResourceID & resourceName) const override;
|
bool existsResource(const ResourceID & resourceName) const override;
|
||||||
std::string getMountPoint() const override;
|
std::string getMountPoint() const override;
|
||||||
bool createResource(std::string filename, bool update = false) 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;
|
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
|
||||||
|
|
||||||
private:
|
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());
|
file = unzOpen2_64(archive.c_str(), FileStream::GetMinizipFilefunc());
|
||||||
unzGoToFilePos(file, &filepos);
|
unzGoToFilePos64(file, &filepos);
|
||||||
unzOpenCurrentFile(file);
|
unzOpenCurrentFile(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,19 +35,19 @@ si64 CZipStream::readMore(ui8 * data, si64 size)
|
|||||||
|
|
||||||
si64 CZipStream::getSize()
|
si64 CZipStream::getSize()
|
||||||
{
|
{
|
||||||
unz_file_info info;
|
unz_file_info64 info;
|
||||||
unzGetCurrentFileInfo (file, &info, nullptr, 0, nullptr, 0, nullptr, 0);
|
unzGetCurrentFileInfo64 (file, &info, nullptr, 0, nullptr, 0, nullptr, 0);
|
||||||
return info.uncompressed_size;
|
return info.uncompressed_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui32 CZipStream::calculateCRC32()
|
ui32 CZipStream::calculateCRC32()
|
||||||
{
|
{
|
||||||
unz_file_info info;
|
unz_file_info64 info;
|
||||||
unzGetCurrentFileInfo (file, &info, nullptr, 0, nullptr, 0, nullptr, 0);
|
unzGetCurrentFileInfo64 (file, &info, nullptr, 0, nullptr, 0, nullptr, 0);
|
||||||
return info.crc;
|
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),
|
archiveName(archive),
|
||||||
mountPoint(mountPoint),
|
mountPoint(mountPoint),
|
||||||
files(listFiles(mountPoint, archive))
|
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";
|
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)
|
if (unzGoToFirstFile(file) == UNZ_OK)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
unz_file_info info;
|
unz_file_info64 info;
|
||||||
std::vector<char> filename;
|
std::vector<char> filename;
|
||||||
// Fill unz_file_info structure with current file info
|
// 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);
|
filename.resize(info.size_filename);
|
||||||
// Get name of current file. Contrary to docs "info" parameter can't be null
|
// 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());
|
std::string filenameString(filename.data(), filename.size());
|
||||||
unzGetFilePos(file, &ret[ResourceID(mountPoint + filenameString)]);
|
unzGetFilePos64(file, &ret[ResourceID(mountPoint + filenameString)]);
|
||||||
}
|
}
|
||||||
while (unzGoToNextFile(file) == UNZ_OK);
|
while (unzGoToNextFile(file) == UNZ_OK);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
* @param archive path to archive to open
|
* @param archive path to archive to open
|
||||||
* @param filepos position of file 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();
|
~CZipStream();
|
||||||
|
|
||||||
si64 getSize() override;
|
si64 getSize() override;
|
||||||
@ -44,14 +44,14 @@ protected:
|
|||||||
|
|
||||||
class DLL_LINKAGE CZipLoader : public ISimpleResourceLoader
|
class DLL_LINKAGE CZipLoader : public ISimpleResourceLoader
|
||||||
{
|
{
|
||||||
std::string archiveName;
|
boost::filesystem::path archiveName;
|
||||||
std::string mountPoint;
|
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:
|
public:
|
||||||
CZipLoader(const std::string & mountPoint, const std::string & archive);
|
CZipLoader(const std::string & mountPoint, const boost::filesystem::path & archive);
|
||||||
|
|
||||||
/// Interface implementation
|
/// Interface implementation
|
||||||
/// @see ISimpleResourceLoader
|
/// @see ISimpleResourceLoader
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#define INC_FROM_FILESTREAM_CPP
|
|
||||||
#include "FileStream.h"
|
#include "FileStream.h"
|
||||||
#include "../minizip/unzip.h"
|
#include "../minizip/unzip.h"
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <boost/iostreams/categories.hpp>
|
#include <boost/iostreams/categories.hpp>
|
||||||
#include <boost/iostreams/stream.hpp>
|
#include <boost/iostreams/stream.hpp>
|
||||||
|
|
||||||
class FileBuf
|
class DLL_LINKAGE FileBuf
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef char char_type;
|
typedef char char_type;
|
||||||
@ -29,8 +29,6 @@ typedef zlib_filefunc64_def_s zlib_filefunc64_def;
|
|||||||
|
|
||||||
#ifdef VCMI_DLL
|
#ifdef VCMI_DLL
|
||||||
extern template class DLL_LINKAGE boost::iostreams::stream<FileBuf>;
|
extern template class DLL_LINKAGE boost::iostreams::stream<FileBuf>;
|
||||||
#else
|
|
||||||
template class DLL_LINKAGE boost::iostreams::stream<FileBuf>;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class DLL_LINKAGE FileStream : public boost::iostreams::stream<FileBuf>
|
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)
|
* @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>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user