1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00

Reorganization of boost filesystem usage

- Removed (most of) boost filesystem namespace usings
- Replaced boost::filesystem::fstream with std::fstream and different
constructor that should be available on any plaftorm
This commit is contained in:
Ivan Savenko 2023-07-28 15:51:14 +03:00
parent 21a39f0b01
commit 4d08a131d3
23 changed files with 56 additions and 65 deletions

View File

@ -50,7 +50,6 @@
namespace po = boost::program_options; namespace po = boost::program_options;
namespace po_style = boost::program_options::command_line_style; namespace po_style = boost::program_options::command_line_style;
namespace bfs = boost::filesystem;
extern boost::thread_specific_ptr<bool> inGuiThread; extern boost::thread_specific_ptr<bool> inGuiThread;
@ -196,7 +195,7 @@ int main(int argc, char * argv[])
console->start(); console->start();
#endif #endif
const bfs::path logPath = VCMIDirs::get().userLogsPath() / "VCMI_Client_log.txt"; const boost::filesystem::path logPath = VCMIDirs::get().userLogsPath() / "VCMI_Client_log.txt";
logConfig = new CBasicLogConfigurator(logPath, console); logConfig = new CBasicLogConfigurator(logPath, console);
logConfig->configureDefault(); logConfig->configureDefault();
logGlobal->info("Starting client of '%s'", GameConstants::VCMI_VERSION); logGlobal->info("Starting client of '%s'", GameConstants::VCMI_VERSION);

View File

@ -247,7 +247,7 @@ void ClientCommandManager::handleGetConfigCommand()
boost::algorithm::replace_all(name, ":", "_"); boost::algorithm::replace_all(name, ":", "_");
const boost::filesystem::path filePath = contentOutPath / (name + ".json"); const boost::filesystem::path filePath = contentOutPath / (name + ".json");
boost::filesystem::ofstream file(filePath); std::ofstream file(filePath.c_str());
file << object.toJson(); file << object.toJson();
} }
} }
@ -273,7 +273,7 @@ void ClientCommandManager::handleGetScriptsCommand()
const scripting::ScriptImpl * script = kv.second.get(); const scripting::ScriptImpl * script = kv.second.get();
boost::filesystem::path filePath = outPath / (name + ".lua"); boost::filesystem::path filePath = outPath / (name + ".lua");
boost::filesystem::ofstream file(filePath); std::ofstream file(filePath.c_str());
file << script->getSource(); file << script->getSource();
} }
printCommandMessage("\rExtracting done :)\n"); printCommandMessage("\rExtracting done :)\n");
@ -300,7 +300,7 @@ void ClientCommandManager::handleGetTextCommand()
boost::filesystem::create_directories(filePath.parent_path()); boost::filesystem::create_directories(filePath.parent_path());
boost::filesystem::ofstream file(filePath); std::ofstream file(filePath.c_str());
auto text = CResourceHandler::get()->load(filename)->readAll(); auto text = CResourceHandler::get()->load(filename)->readAll();
file.write((char*)text.first.get(), text.second); file.write((char*)text.first.get(), text.second);
@ -331,7 +331,7 @@ void ClientCommandManager::handleExtractCommand(std::istringstream& singleWordBu
auto data = CResourceHandler::get()->load(ResourceID(URI))->readAll(); auto data = CResourceHandler::get()->load(ResourceID(URI))->readAll();
boost::filesystem::create_directories(outPath.parent_path()); boost::filesystem::create_directories(outPath.parent_path());
boost::filesystem::ofstream outFile(outPath, boost::filesystem::ofstream::binary); std::ofstream outFile(outPath.c_str(), std::ofstream::binary);
outFile.write((char*)data.first.get(), data.second); outFile.write((char*)data.first.get(), data.second);
} }
else else

View File

@ -61,8 +61,6 @@
#include <SDL.h> #include <SDL.h>
#endif #endif
namespace fs = boost::filesystem;
std::shared_ptr<CMainMenu> CMM; std::shared_ptr<CMainMenu> CMM;
ISelectionScreenInfo * SEL; ISelectionScreenInfo * SEL;

View File

@ -113,7 +113,7 @@ JsonNode toJson(QVariant object)
void JsonToFile(QString filename, QVariant object) void JsonToFile(QString filename, QVariant object)
{ {
boost::filesystem::fstream file(qstringToPath(filename), std::ios::out | std::ios_base::binary); std::fstream file(qstringToPath(filename).c_str(), std::ios::out | std::ios_base::binary);
file << toJson(object).toJson(); file << toJson(object).toJson();
} }

View File

@ -76,7 +76,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");
boost::filesystem::fstream file(*CResourceHandler::get()->getResourceName(ResourceID("config/settings.json")), std::ofstream::out | std::ofstream::trunc); std::fstream file(CResourceHandler::get()->getResourceName(ResourceID("config/settings.json"))->c_str(), std::ofstream::out | std::ofstream::trunc);
file << savedConf.toJson(); file << savedConf.toJson();
} }

View File

@ -1157,7 +1157,7 @@ void CModHandler::afterLoad(bool onlyEssential)
if(!onlyEssential) if(!onlyEssential)
{ {
boost::filesystem::fstream file(*CResourceHandler::get()->getResourceName(ResourceID("config/modSettings.json")), std::ofstream::out | std::ofstream::trunc); std::fstream file(CResourceHandler::get()->getResourceName(ResourceID("config/modSettings.json"))->c_str(), std::ofstream::out | std::ofstream::trunc);
file << modSettings.toJson(); file << modSettings.toJson();
} }

View File

@ -24,7 +24,7 @@ ArchiveEntry::ArchiveEntry()
} }
CArchiveLoader::CArchiveLoader(std::string _mountPoint, bfs::path _archive, bool _extractArchives) : CArchiveLoader::CArchiveLoader(std::string _mountPoint, boost::filesystem::path _archive, bool _extractArchives) :
archive(std::move(_archive)), archive(std::move(_archive)),
mountPoint(std::move(_mountPoint)), mountPoint(std::move(_mountPoint)),
extractArchives(_extractArchives) extractArchives(_extractArchives)
@ -217,7 +217,7 @@ void CArchiveLoader::extractToFolder(const std::string & outputSubFolder, CInput
fileStream.seek(entry.offset); fileStream.seek(entry.offset);
fileStream.read(data.data(), entry.fullSize); fileStream.read(data.data(), entry.fullSize);
bfs::path extractedFilePath = createExtractedFilePath(outputSubFolder, entry.name); boost::filesystem::path extractedFilePath = createExtractedFilePath(outputSubFolder, entry.name);
// writeToOutputFile // writeToOutputFile
std::ofstream out(extractedFilePath.string(), std::ofstream::binary); std::ofstream out(extractedFilePath.string(), std::ofstream::binary);
@ -235,12 +235,12 @@ void CArchiveLoader::extractToFolder(const std::string & outputSubFolder, const
extractToFolder(outputSubFolder, *inputStream, entry); extractToFolder(outputSubFolder, *inputStream, entry);
} }
bfs::path createExtractedFilePath(const std::string & outputSubFolder, const std::string & entryName) boost::filesystem::path createExtractedFilePath(const std::string & outputSubFolder, const std::string & entryName)
{ {
bfs::path extractionFolderPath = VCMIDirs::get().userExtractedPath() / outputSubFolder; boost::filesystem::path extractionFolderPath = VCMIDirs::get().userExtractedPath() / outputSubFolder;
bfs::path extractedFilePath = extractionFolderPath / entryName; boost::filesystem::path extractedFilePath = extractionFolderPath / entryName;
bfs::create_directories(extractionFolderPath); boost::filesystem::create_directories(extractionFolderPath);
return extractedFilePath; return extractedFilePath;
} }

View File

@ -12,8 +12,6 @@
#include "ISimpleResourceLoader.h" #include "ISimpleResourceLoader.h"
#include "ResourceID.h" #include "ResourceID.h"
namespace bfs = boost::filesystem;
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class CFileInputStream; class CFileInputStream;
@ -58,7 +56,7 @@ public:
* *
* @throws std::runtime_error if the archive wasn't found or if the archive isn't supported * @throws std::runtime_error if the archive wasn't found or if the archive isn't supported
*/ */
CArchiveLoader(std::string mountPoint, bfs::path archive, bool extractArchives = false); CArchiveLoader(std::string mountPoint, boost::filesystem::path archive, bool extractArchives = false);
/// Interface implementation /// Interface implementation
/// @see ISimpleResourceLoader /// @see ISimpleResourceLoader
@ -95,7 +93,7 @@ private:
void initSNDArchive(const std::string &mountPoint, CFileInputStream & fileStream); void initSNDArchive(const std::string &mountPoint, CFileInputStream & fileStream);
/** The file path to the archive which is scanned and indexed. */ /** The file path to the archive which is scanned and indexed. */
bfs::path archive; boost::filesystem::path archive;
std::string mountPoint; std::string mountPoint;
@ -107,6 +105,6 @@ private:
}; };
/** Constructs the file path for the extracted file. Creates the subfolder hierarchy aswell **/ /** Constructs the file path for the extracted file. Creates the subfolder hierarchy aswell **/
bfs::path createExtractedFilePath(const std::string & outputSubFolder, const std::string & entryName); boost::filesystem::path createExtractedFilePath(const std::string & outputSubFolder, const std::string & entryName);
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -15,7 +15,7 @@ VCMI_LIB_NAMESPACE_BEGIN
CFileInputStream::CFileInputStream(const boost::filesystem::path & file, si64 start, si64 size) CFileInputStream::CFileInputStream(const boost::filesystem::path & file, si64 start, si64 size)
: dataStart{start}, : dataStart{start},
dataSize{size}, dataSize{size},
fileStream{file, std::ios::in | std::ios::binary} fileStream{file.c_str(), std::ios::in | std::ios::binary}
{ {
if (fileStream.fail()) if (fileStream.fail())
throw std::runtime_error("File " + file.string() + " isn't available."); throw std::runtime_error("File " + file.string() + " isn't available.");

View File

@ -74,7 +74,7 @@ private:
si64 dataSize; si64 dataSize;
/** Native c++ input file stream object. */ /** Native c++ input file stream object. */
boost::filesystem::fstream fileStream; std::fstream fileStream;
}; };
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -14,9 +14,7 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
namespace bfs = boost::filesystem; CFilesystemLoader::CFilesystemLoader(std::string _mountPoint, boost::filesystem::path baseDirectory, size_t depth, bool initial):
CFilesystemLoader::CFilesystemLoader(std::string _mountPoint, bfs::path baseDirectory, size_t depth, bool initial):
baseDirectory(std::move(baseDirectory)), baseDirectory(std::move(baseDirectory)),
mountPoint(std::move(_mountPoint)), mountPoint(std::move(_mountPoint)),
fileList(listFiles(mountPoint, depth, initial)), fileList(listFiles(mountPoint, depth, initial)),
@ -28,7 +26,7 @@ CFilesystemLoader::CFilesystemLoader(std::string _mountPoint, bfs::path baseDire
std::unique_ptr<CInputStream> CFilesystemLoader::load(const ResourceID & resourceName) const std::unique_ptr<CInputStream> CFilesystemLoader::load(const ResourceID & resourceName) const
{ {
assert(fileList.count(resourceName)); assert(fileList.count(resourceName));
bfs::path file = baseDirectory / fileList.at(resourceName); boost::filesystem::path file = baseDirectory / fileList.at(resourceName);
logGlobal->trace("loading %s", file.string()); logGlobal->trace("loading %s", file.string());
return std::make_unique<CFileInputStream>(file); return std::make_unique<CFileInputStream>(file);
} }
@ -88,7 +86,7 @@ bool CFilesystemLoader::createResource(std::string filename, bool update)
if (!update) if (!update)
{ {
// create file, if not exists // create file, if not exists
boost::filesystem::fstream file(baseDirectory / filename); std::fstream file((baseDirectory / filename).c_str());
if (!file.is_open()) if (!file.is_open())
return false; return false;
@ -97,7 +95,7 @@ bool CFilesystemLoader::createResource(std::string filename, bool update)
return true; return true;
} }
std::unordered_map<ResourceID, bfs::path> CFilesystemLoader::listFiles(const std::string &mountPoint, size_t depth, bool initial) const std::unordered_map<ResourceID, boost::filesystem::path> CFilesystemLoader::listFiles(const std::string &mountPoint, size_t depth, bool initial) const
{ {
static const EResType::Type initArray[] = { static const EResType::Type initArray[] = {
EResType::DIRECTORY, EResType::DIRECTORY,
@ -108,16 +106,16 @@ std::unordered_map<ResourceID, bfs::path> CFilesystemLoader::listFiles(const std
EResType::ARCHIVE_ZIP }; EResType::ARCHIVE_ZIP };
static const std::set<EResType::Type> initialTypes(initArray, initArray + std::size(initArray)); static const std::set<EResType::Type> initialTypes(initArray, initArray + std::size(initArray));
assert(bfs::is_directory(baseDirectory)); assert(boost::filesystem::is_directory(baseDirectory));
std::unordered_map<ResourceID, bfs::path> fileList; std::unordered_map<ResourceID, boost::filesystem::path> fileList;
std::vector<bfs::path> path; //vector holding relative path to our file std::vector<boost::filesystem::path> path; //vector holding relative path to our file
bfs::recursive_directory_iterator enddir; boost::filesystem::recursive_directory_iterator enddir;
#if BOOST_VERSION >= 107200 // 1.72 #if BOOST_VERSION >= 107200 // 1.72
bfs::recursive_directory_iterator it(baseDirectory, bfs::directory_options::follow_directory_symlink); boost::filesystem::recursive_directory_iterator it(baseDirectory, boost::filesystem::directory_options::follow_directory_symlink);
#else #else
bfs::recursive_directory_iterator it(baseDirectory, bfs::symlink_option::recurse); boost::filesystem::recursive_directory_iterator it(baseDirectory, boost::filesystem::symlink_option::recurse);
#endif #endif
for(; it != enddir; ++it) for(; it != enddir; ++it)
@ -129,7 +127,7 @@ std::unordered_map<ResourceID, bfs::path> CFilesystemLoader::listFiles(const std
const auto currentDepth = it.level(); const auto currentDepth = it.level();
#endif #endif
if (bfs::is_directory(it->status())) if (boost::filesystem::is_directory(it->status()))
{ {
path.resize(currentDepth + 1); path.resize(currentDepth + 1);
path.back() = it->path().filename(); path.back() = it->path().filename();
@ -148,7 +146,7 @@ std::unordered_map<ResourceID, bfs::path> CFilesystemLoader::listFiles(const std
if (!initial || vstd::contains(initialTypes, type)) if (!initial || vstd::contains(initialTypes, type))
{ {
//reconstruct relative filename (not possible via boost AFAIK) //reconstruct relative filename (not possible via boost AFAIK)
bfs::path filename; boost::filesystem::path filename;
const size_t iterations = std::min(static_cast<size_t>(currentDepth), path.size()); const size_t iterations = std::min(static_cast<size_t>(currentDepth), path.size());
if (iterations) if (iterations)
{ {
@ -161,13 +159,13 @@ std::unordered_map<ResourceID, bfs::path> CFilesystemLoader::listFiles(const std
filename = it->path().filename(); filename = it->path().filename();
std::string resName; std::string resName;
if (bfs::path::preferred_separator != '/') if (boost::filesystem::path::preferred_separator != '/')
{ {
// resource names are using UNIX slashes (/) // resource names are using UNIX slashes (/)
resName.reserve(resName.size() + filename.native().size()); resName.reserve(resName.size() + filename.native().size());
resName = mountPoint; resName = mountPoint;
for (const char c : filename.string()) for (const char c : filename.string())
if (c != bfs::path::preferred_separator) if (c != boost::filesystem::path::preferred_separator)
resName.push_back(c); resName.push_back(c);
else else
resName.push_back('/'); resName.push_back('/');

View File

@ -214,7 +214,7 @@ bool ZipArchive::extract(const boost::filesystem::path & from, const boost::file
if (boost::algorithm::ends_with(file, "/")) if (boost::algorithm::ends_with(file, "/"))
continue; continue;
boost::filesystem::fstream destFile(fullName, std::ios::out | std::ios::binary); std::fstream destFile(fullName.c_str(), std::ios::out | std::ios::binary);
if (!destFile.good()) if (!destFile.good())
return false; return false;

View File

@ -425,7 +425,7 @@ const CColorMapping & CLogConsoleTarget::getColorMapping() const { return colorM
void CLogConsoleTarget::setColorMapping(const CColorMapping & colorMapping) { this->colorMapping = colorMapping; } void CLogConsoleTarget::setColorMapping(const CColorMapping & colorMapping) { this->colorMapping = colorMapping; }
CLogFileTarget::CLogFileTarget(const boost::filesystem::path & filePath, bool append): CLogFileTarget::CLogFileTarget(const boost::filesystem::path & filePath, bool append):
file(filePath, append ? std::ios_base::app : std::ios_base::out) file(filePath.c_str(), append ? std::ios_base::app : std::ios_base::out)
{ {
// formatter.setPattern("%d %l %n [%t] - %m"); // formatter.setPattern("%d %l %n [%t] - %m");
formatter.setPattern("%l %n [%t] - %m"); formatter.setPattern("%l %n [%t] - %m");

View File

@ -219,7 +219,7 @@ public:
void write(const LogRecord & record) override; void write(const LogRecord & record) override;
private: private:
boost::filesystem::fstream file; std::fstream file;
CLogFormatter formatter; CLogFormatter formatter;
mutable std::mutex mx; mutable std::mutex mx;
}; };

View File

@ -80,7 +80,7 @@ void CMapService::saveMap(const std::unique_ptr<CMap> & map, boost::filesystem::
} }
{ {
boost::filesystem::remove(fullPath); boost::filesystem::remove(fullPath);
boost::filesystem::ofstream tmp(fullPath, boost::filesystem::ofstream::binary); std::ofstream tmp(fullPath.c_str(), std::ofstream::binary);
tmp.write(reinterpret_cast<const char *>(serializeBuffer.getBuffer().data()), serializeBuffer.getSize()); tmp.write(reinterpret_cast<const char *>(serializeBuffer.getBuffer().data()), serializeBuffer.getSize());
tmp.flush(); tmp.flush();

View File

@ -40,7 +40,7 @@ void CLoadFile::openNextFile(const boost::filesystem::path & fname, int minimalV
try try
{ {
fName = fname.string(); fName = fname.string();
sfile = std::make_unique<boost::filesystem::fstream>(fname, std::ios::in | std::ios::binary); sfile = std::make_unique<std::fstream>(fname.c_str(), 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))

View File

@ -580,7 +580,7 @@ public:
BinaryDeserializer serializer; BinaryDeserializer serializer;
std::string fName; std::string fName;
std::unique_ptr<boost::filesystem::fstream> sfile; std::unique_ptr<std::fstream> sfile;
CLoadFile(const boost::filesystem::path & fname, int minimalVersion = SERIALIZATION_VERSION); //throws! CLoadFile(const boost::filesystem::path & fname, int minimalVersion = SERIALIZATION_VERSION); //throws!
virtual ~CLoadFile(); virtual ~CLoadFile();

View File

@ -37,7 +37,7 @@ void CSaveFile::openNextFile(const boost::filesystem::path &fname)
fName = fname; fName = fname;
try try
{ {
sfile = std::make_unique<boost::filesystem::fstream>(fname, std::ios::out | std::ios::binary); sfile = std::make_unique<std::fstream>(fname.c_str(), 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))

View File

@ -390,7 +390,7 @@ public:
BinarySerializer serializer; BinarySerializer serializer;
boost::filesystem::path fName; boost::filesystem::path fName;
std::unique_ptr<boost::filesystem::fstream> sfile; std::unique_ptr<std::fstream> sfile;
CSaveFile(const boost::filesystem::path &fname); //throws! CSaveFile(const boost::filesystem::path &fname); //throws!
~CSaveFile(); ~CSaveFile();

View File

@ -119,7 +119,7 @@ JsonNode toJson(QVariant object)
void JsonToFile(QString filename, QVariant object) void JsonToFile(QString filename, QVariant object)
{ {
boost::filesystem::fstream file(qstringToPath(filename), std::ios::out | std::ios_base::binary); std::fstream file(qstringToPath(filename).c_str(), std::ios::out | std::ios_base::binary);
file << toJson(object).toJson(); file << toJson(object).toJson();
} }

View File

@ -24,8 +24,8 @@
void ResourceConverter::convertExtractedResourceFiles(ConversionOptions conversionOptions) void ResourceConverter::convertExtractedResourceFiles(ConversionOptions conversionOptions)
{ {
bfs::path spritesPath = VCMIDirs::get().userExtractedPath() / "SPRITES"; boost::filesystem::path spritesPath = VCMIDirs::get().userExtractedPath() / "SPRITES";
bfs::path imagesPath = VCMIDirs::get().userExtractedPath() / "IMAGES"; boost::filesystem::path imagesPath = VCMIDirs::get().userExtractedPath() / "IMAGES";
std::vector<std::string> defFiles = { "TwCrPort.def", "CPRSMALL.def", "FlagPort.def", "ITPA.def", "ITPt.def", "Un32.def", "Un44.def" }; std::vector<std::string> defFiles = { "TwCrPort.def", "CPRSMALL.def", "FlagPort.def", "ITPA.def", "ITPt.def", "Un32.def", "Un44.def" };
if(conversionOptions.splitDefs) if(conversionOptions.splitDefs)
@ -35,16 +35,16 @@ void ResourceConverter::convertExtractedResourceFiles(ConversionOptions conversi
doConvertPcxToPng(imagesPath, conversionOptions.deleteOriginals); doConvertPcxToPng(imagesPath, conversionOptions.deleteOriginals);
} }
void ResourceConverter::doConvertPcxToPng(const bfs::path & sourceFolder, bool deleteOriginals) void ResourceConverter::doConvertPcxToPng(const boost::filesystem::path & sourceFolder, bool deleteOriginals)
{ {
logGlobal->info("Converting .pcx to .png from folder: %s ...\n", sourceFolder); logGlobal->info("Converting .pcx to .png from folder: %s ...\n", sourceFolder);
for(const auto & directoryEntry : bfs::directory_iterator(sourceFolder)) for(const auto & directoryEntry : boost::filesystem::directory_iterator(sourceFolder))
{ {
const auto filename = directoryEntry.path().filename(); const auto filename = directoryEntry.path().filename();
try try
{ {
if(!bfs::is_regular_file(directoryEntry)) if(!boost::filesystem::is_regular_file(directoryEntry))
continue; continue;
std::string fileStem = directoryEntry.path().stem().string(); std::string fileStem = directoryEntry.path().stem().string();
@ -53,11 +53,11 @@ void ResourceConverter::doConvertPcxToPng(const bfs::path & sourceFolder, bool d
if(boost::algorithm::to_lower_copy(filename.extension().string()) == ".pcx") if(boost::algorithm::to_lower_copy(filename.extension().string()) == ".pcx")
{ {
auto img = BitmapHandler::loadBitmap(filenameLowerCase); auto img = BitmapHandler::loadBitmap(filenameLowerCase);
bfs::path pngFilePath = sourceFolder / (fileStem + ".png"); boost::filesystem::path pngFilePath = sourceFolder / (fileStem + ".png");
img.save(pathToQString(pngFilePath), "PNG"); img.save(pathToQString(pngFilePath), "PNG");
if(deleteOriginals) if(deleteOriginals)
bfs::remove(directoryEntry.path()); boost::filesystem::remove(directoryEntry.path());
} }
} }
catch(const std::exception& ex) catch(const std::exception& ex)
@ -67,7 +67,7 @@ void ResourceConverter::doConvertPcxToPng(const bfs::path & sourceFolder, bool d
} }
} }
void ResourceConverter::splitDefFile(const std::string & fileName, const bfs::path & sourceFolder, bool deleteOriginals) void ResourceConverter::splitDefFile(const std::string & fileName, const boost::filesystem::path & sourceFolder, bool deleteOriginals)
{ {
if(CResourceHandler::get()->existsResource(ResourceID("SPRITES/" + fileName))) if(CResourceHandler::get()->existsResource(ResourceID("SPRITES/" + fileName)))
{ {
@ -76,13 +76,13 @@ void ResourceConverter::splitDefFile(const std::string & fileName, const bfs::pa
anim->exportBitmaps(pathToQString(sourceFolder)); anim->exportBitmaps(pathToQString(sourceFolder));
if(deleteOriginals) if(deleteOriginals)
bfs::remove(sourceFolder / fileName); boost::filesystem::remove(sourceFolder / fileName);
} }
else else
logGlobal->error("Def File Split error! " + fileName); logGlobal->error("Def File Split error! " + fileName);
} }
void ResourceConverter::splitDefFiles(const std::vector<std::string> & defFileNames, const bfs::path & sourceFolder, bool deleteOriginals) void ResourceConverter::splitDefFiles(const std::vector<std::string> & defFileNames, const boost::filesystem::path & sourceFolder, bool deleteOriginals)
{ {
logGlobal->info("Splitting Def Files from folder: %s ...\n", sourceFolder); logGlobal->info("Splitting Def Files from folder: %s ...\n", sourceFolder);

View File

@ -9,8 +9,6 @@
*/ */
#pragma once #pragma once
namespace bfs = boost::filesystem;
// Struct for holding all Convertor Options // Struct for holding all Convertor Options
struct ConversionOptions struct ConversionOptions
{ {
@ -45,14 +43,14 @@ public:
private: private:
// Converts all .pcx from extractedFolder/Images into .png // Converts all .pcx from extractedFolder/Images into .png
static void doConvertPcxToPng(const bfs::path & sourceFolder, bool deleteOriginals); static void doConvertPcxToPng(const boost::filesystem::path & sourceFolder, bool deleteOriginals);
// splits a .def file into individual images and converts the output to PNG format // splits a .def file into individual images and converts the output to PNG format
static void splitDefFile(const std::string & fileName, const bfs::path & sourceFolder, bool deleteOriginals); static void splitDefFile(const std::string & fileName, const boost::filesystem::path & sourceFolder, bool deleteOriginals);
/// <summary> /// <summary>
/// Splits the given .def files into individual images. /// Splits the given .def files into individual images.
/// For each .def file, the resulting images will be output in the same folder, in a subfolder (named just like the .def file) /// For each .def file, the resulting images will be output in the same folder, in a subfolder (named just like the .def file)
/// </summary> /// </summary>
static void splitDefFiles(const std::vector<std::string> & defFileNames, const bfs::path & sourceFolder, bool deleteOriginals); static void splitDefFiles(const std::vector<std::string> & defFileNames, const boost::filesystem::path & sourceFolder, bool deleteOriginals);
}; };

View File

@ -31,7 +31,7 @@ static void saveTestMap(CMemoryBuffer & serializeBuffer, const std::string & fil
{ {
auto path = VCMIDirs::get().userDataPath() / filename; auto path = VCMIDirs::get().userDataPath() / filename;
boost::filesystem::remove(path); boost::filesystem::remove(path);
boost::filesystem::ofstream tmp(path, boost::filesystem::ofstream::binary); std::ofstream tmp(path.c_str(), std::ofstream::binary);
tmp.write((const char *)serializeBuffer.getBuffer().data(), serializeBuffer.getSize()); tmp.write((const char *)serializeBuffer.getBuffer().data(), serializeBuffer.getSize());
tmp.flush(); tmp.flush();