1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Merge pull request #2428 from IvanSavenko/remove_boost_iostreams

(develop) Removed boost::iostreams usage
This commit is contained in:
Ivan Savenko
2023-07-30 20:14:39 +03:00
committed by GitHub
28 changed files with 117 additions and 327 deletions

View File

@@ -50,7 +50,6 @@
namespace po = boost::program_options;
namespace po_style = boost::program_options::command_line_style;
namespace bfs = boost::filesystem;
extern boost::thread_specific_ptr<bool> inGuiThread;
@@ -196,7 +195,7 @@ int main(int argc, char * argv[])
console->start();
#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->configureDefault();
logGlobal->info("Starting client of '%s'", GameConstants::VCMI_VERSION);

View File

@@ -247,7 +247,7 @@ void ClientCommandManager::handleGetConfigCommand()
boost::algorithm::replace_all(name, ":", "_");
const boost::filesystem::path filePath = contentOutPath / (name + ".json");
boost::filesystem::ofstream file(filePath);
std::ofstream file(filePath.c_str());
file << object.toJson();
}
}
@@ -273,7 +273,7 @@ void ClientCommandManager::handleGetScriptsCommand()
const scripting::ScriptImpl * script = kv.second.get();
boost::filesystem::path filePath = outPath / (name + ".lua");
boost::filesystem::ofstream file(filePath);
std::ofstream file(filePath.c_str());
file << script->getSource();
}
printCommandMessage("\rExtracting done :)\n");
@@ -300,7 +300,7 @@ void ClientCommandManager::handleGetTextCommand()
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();
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();
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);
}
else

View File

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

View File

@@ -60,7 +60,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
${MAIN_LIB_DIR}/filesystem/CZipLoader.cpp
${MAIN_LIB_DIR}/filesystem/CZipSaver.cpp
${MAIN_LIB_DIR}/filesystem/FileInfo.cpp
${MAIN_LIB_DIR}/filesystem/FileStream.cpp
${MAIN_LIB_DIR}/filesystem/Filesystem.cpp
${MAIN_LIB_DIR}/filesystem/MinizipExtensions.cpp
${MAIN_LIB_DIR}/filesystem/ResourceID.cpp
@@ -384,7 +383,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
${MAIN_LIB_DIR}/filesystem/CZipLoader.h
${MAIN_LIB_DIR}/filesystem/CZipSaver.h
${MAIN_LIB_DIR}/filesystem/FileInfo.h
${MAIN_LIB_DIR}/filesystem/FileStream.h
${MAIN_LIB_DIR}/filesystem/Filesystem.h
${MAIN_LIB_DIR}/filesystem/ISimpleResourceLoader.h
${MAIN_LIB_DIR}/filesystem/MinizipExtensions.h

View File

@@ -9,7 +9,6 @@
*/
#include "StdInc.h"
#include "jsonutils.h"
#include "../lib/filesystem/FileStream.h"
static QVariantMap JsonToMap(const JsonMap & json)
{
@@ -114,7 +113,7 @@ JsonNode toJson(QVariant object)
void JsonToFile(QString filename, QVariant object)
{
FileStream 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();
}

View File

@@ -11,7 +11,6 @@
#include "CConfigHandler.h"
#include "../lib/filesystem/Filesystem.h"
#include "../lib/filesystem/FileStream.h"
#include "../lib/GameConstants.h"
#include "../lib/VCMIDirs.h"
@@ -77,7 +76,7 @@ void SettingsStorage::invalidateNode(const std::vector<std::string> &changedPath
savedConf.Struct().erase("session");
JsonUtils::minimize(savedConf, "vcmi:settings");
FileStream 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();
}

View File

@@ -10,7 +10,6 @@
#include "StdInc.h"
#include "CModHandler.h"
#include "rmg/CRmgTemplateStorage.h"
#include "filesystem/FileStream.h"
#include "filesystem/AdapterLoaders.h"
#include "filesystem/CFilesystemLoader.h"
#include "filesystem/Filesystem.h"
@@ -1158,7 +1157,7 @@ void CModHandler::afterLoad(bool onlyEssential)
if(!onlyEssential)
{
FileStream 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();
}

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)),
mountPoint(std::move(_mountPoint)),
extractArchives(_extractArchives)
@@ -217,7 +217,7 @@ void CArchiveLoader::extractToFolder(const std::string & outputSubFolder, CInput
fileStream.seek(entry.offset);
fileStream.read(data.data(), entry.fullSize);
bfs::path extractedFilePath = createExtractedFilePath(outputSubFolder, entry.name);
boost::filesystem::path extractedFilePath = createExtractedFilePath(outputSubFolder, entry.name);
// writeToOutputFile
std::ofstream out(extractedFilePath.string(), std::ofstream::binary);
@@ -235,12 +235,12 @@ void CArchiveLoader::extractToFolder(const std::string & outputSubFolder, const
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;
bfs::path extractedFilePath = extractionFolderPath / entryName;
boost::filesystem::path extractionFolderPath = VCMIDirs::get().userExtractedPath() / outputSubFolder;
boost::filesystem::path extractedFilePath = extractionFolderPath / entryName;
bfs::create_directories(extractionFolderPath);
boost::filesystem::create_directories(extractionFolderPath);
return extractedFilePath;
}

View File

@@ -12,8 +12,6 @@
#include "ISimpleResourceLoader.h"
#include "ResourceID.h"
namespace bfs = boost::filesystem;
VCMI_LIB_NAMESPACE_BEGIN
class CFileInputStream;
@@ -58,7 +56,7 @@ public:
*
* @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
/// @see ISimpleResourceLoader
@@ -95,7 +93,7 @@ private:
void initSNDArchive(const std::string &mountPoint, CFileInputStream & fileStream);
/** The file path to the archive which is scanned and indexed. */
bfs::path archive;
boost::filesystem::path archive;
std::string mountPoint;
@@ -107,6 +105,6 @@ private:
};
/** 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

View File

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

View File

@@ -10,7 +10,6 @@
#pragma once
#include "CInputStream.h"
#include "FileStream.h"
VCMI_LIB_NAMESPACE_BEGIN
@@ -75,7 +74,7 @@ private:
si64 dataSize;
/** Native c++ input file stream object. */
FileStream fileStream;
std::fstream fileStream;
};
VCMI_LIB_NAMESPACE_END

View File

@@ -11,13 +11,10 @@
#include "CFilesystemLoader.h"
#include "CFileInputStream.h"
#include "FileStream.h"
VCMI_LIB_NAMESPACE_BEGIN
namespace bfs = boost::filesystem;
CFilesystemLoader::CFilesystemLoader(std::string _mountPoint, bfs::path baseDirectory, size_t depth, bool initial):
CFilesystemLoader::CFilesystemLoader(std::string _mountPoint, boost::filesystem::path baseDirectory, size_t depth, bool initial):
baseDirectory(std::move(baseDirectory)),
mountPoint(std::move(_mountPoint)),
fileList(listFiles(mountPoint, depth, initial)),
@@ -29,7 +26,7 @@ CFilesystemLoader::CFilesystemLoader(std::string _mountPoint, bfs::path baseDire
std::unique_ptr<CInputStream> CFilesystemLoader::load(const ResourceID & resourceName) const
{
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());
return std::make_unique<CFileInputStream>(file);
}
@@ -88,14 +85,17 @@ bool CFilesystemLoader::createResource(std::string filename, bool update)
if (!update)
{
if (!FileStream::createFile(baseDirectory / filename))
// create file, if not exists
std::fstream file((baseDirectory / filename).c_str());
if (!file.is_open())
return false;
}
fileList[resID] = filename;
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[] = {
EResType::DIRECTORY,
@@ -106,16 +106,16 @@ std::unordered_map<ResourceID, bfs::path> CFilesystemLoader::listFiles(const std
EResType::ARCHIVE_ZIP };
static const std::set<EResType::Type> initialTypes(initArray, initArray + std::size(initArray));
assert(bfs::is_directory(baseDirectory));
std::unordered_map<ResourceID, bfs::path> fileList;
assert(boost::filesystem::is_directory(baseDirectory));
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
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
bfs::recursive_directory_iterator it(baseDirectory, bfs::symlink_option::recurse);
boost::filesystem::recursive_directory_iterator it(baseDirectory, boost::filesystem::symlink_option::recurse);
#endif
for(; it != enddir; ++it)
@@ -127,7 +127,7 @@ std::unordered_map<ResourceID, bfs::path> CFilesystemLoader::listFiles(const std
const auto currentDepth = it.level();
#endif
if (bfs::is_directory(it->status()))
if (boost::filesystem::is_directory(it->status()))
{
path.resize(currentDepth + 1);
path.back() = it->path().filename();
@@ -146,7 +146,7 @@ std::unordered_map<ResourceID, bfs::path> CFilesystemLoader::listFiles(const std
if (!initial || vstd::contains(initialTypes, type))
{
//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());
if (iterations)
{
@@ -159,13 +159,13 @@ std::unordered_map<ResourceID, bfs::path> CFilesystemLoader::listFiles(const std
filename = it->path().filename();
std::string resName;
if (bfs::path::preferred_separator != '/')
if (boost::filesystem::path::preferred_separator != '/')
{
// resource names are using UNIX slashes (/)
resName.reserve(resName.size() + filename.native().size());
resName = mountPoint;
for (const char c : filename.string())
if (c != bfs::path::preferred_separator)
if (c != boost::filesystem::path::preferred_separator)
resName.push_back(c);
else
resName.push_back('/');

View File

@@ -9,7 +9,6 @@
*/
#include "StdInc.h"
#include "CZipLoader.h"
#include "FileStream.h"
#include "../ScopeGuard.h"
@@ -155,7 +154,10 @@ std::vector<std::string> ZipArchive::listFiles(const boost::filesystem::path & f
{
std::vector<std::string> ret;
unzFile file = unzOpen2_64(filename.c_str(), FileStream::GetMinizipFilefunc());
CDefaultIOApi zipAPI;
auto zipStructure = zipAPI.getApiStructure();
unzFile file = unzOpen2_64(filename.c_str(), &zipStructure);
if (unzGoToFirstFile(file) == UNZ_OK)
{
@@ -188,7 +190,10 @@ bool ZipArchive::extract(const boost::filesystem::path & from, const boost::file
bool ZipArchive::extract(const boost::filesystem::path & from, const boost::filesystem::path & where, const std::vector<std::string> & what)
{
unzFile archive = unzOpen2_64(from.c_str(), FileStream::GetMinizipFilefunc());
CDefaultIOApi zipAPI;
auto zipStructure = zipAPI.getApiStructure();
unzFile archive = unzOpen2_64(from.c_str(), &zipStructure);
auto onExit = vstd::makeScopeGuard([&]()
{
@@ -209,7 +214,7 @@ bool ZipArchive::extract(const boost::filesystem::path & from, const boost::file
if (boost::algorithm::ends_with(file, "/"))
continue;
FileStream destFile(fullName, std::ios::out | std::ios::binary);
std::fstream destFile(fullName.c_str(), std::ios::out | std::ios::binary);
if (!destFile.good())
return false;

View File

@@ -1,175 +0,0 @@
/*
* FileStream.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "FileStream.h"
#ifdef USE_SYSTEM_MINIZIP
#include <minizip/unzip.h>
#include <minizip/ioapi.h>
#else
#include "../minizip/unzip.h"
#include "../minizip/ioapi.h"
#endif
#include <cstdio>
#define GETFILE static_cast<std::FILE*>(filePtr)
#ifdef VCMI_WINDOWS
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <cwchar>
#define CHAR_LITERAL(s) L##s
using CharType = wchar_t;
#else
#define CHAR_LITERAL(s) s
using CharType = char;
#endif
namespace
{
inline FILE* do_open(const CharType* name, const CharType* mode)
{
#ifdef VCMI_WINDOWS
return _wfopen(name, mode);
#else
return std::fopen(name, mode);
#endif
}
voidpf ZCALLBACK MinizipOpenFunc(voidpf opaque, const void* filename, int mode)
{
const CharType* mode_fopen = [mode]() -> const CharType*
{
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
return CHAR_LITERAL("rb");
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
return CHAR_LITERAL("r+b");
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
return CHAR_LITERAL("wb");
return nullptr;
}();
if (filename != nullptr && mode_fopen != nullptr)
return do_open(static_cast<const CharType*>(filename), mode_fopen);
else
return nullptr;
}
} // namespace
template struct boost::iostreams::stream<VCMI_LIB_WRAP_NAMESPACE(FileBuf)>;
VCMI_LIB_NAMESPACE_BEGIN
zlib_filefunc64_def* FileStream::GetMinizipFilefunc()
{
static zlib_filefunc64_def MinizipFilefunc;
static bool initialized = false;
if (!initialized)
{
fill_fopen64_filefunc(&MinizipFilefunc);
MinizipFilefunc.zopen64_file = &MinizipOpenFunc;
initialized = true;
}
return &MinizipFilefunc;
}
/*static*/
bool FileStream::createFile(const boost::filesystem::path& filename)
{
FILE* f = do_open(filename.c_str(), CHAR_LITERAL("wb"));
bool result = (f != nullptr);
if(result)
fclose(f);
return result;
}
FileBuf::FileBuf(const boost::filesystem::path& filename, std::ios_base::openmode mode)
{
auto openmode = [mode]() -> std::basic_string<CharType>
{
using namespace std;
switch (mode & (~ios_base::ate & ~ios_base::binary))
{
case (ios_base::in):
return CHAR_LITERAL("r");
case (ios_base::out):
case (ios_base::out | ios_base::trunc):
return CHAR_LITERAL("w");
case (ios_base::app):
case (ios_base::out | ios_base::app):
return CHAR_LITERAL("a");
case (ios_base::out | ios_base::in):
return CHAR_LITERAL("r+");
case (ios_base::out | ios_base::in | ios_base::trunc):
return CHAR_LITERAL("w+");
case (ios_base::out | ios_base::in | ios_base::app):
case (ios_base::in | ios_base::app):
return CHAR_LITERAL("a+");
default:
throw std::ios_base::failure("invalid open mode");
}
}();
if (mode & std::ios_base::binary)
openmode += CHAR_LITERAL('b');
filePtr = do_open(filename.c_str(), openmode.c_str());
if (filePtr == nullptr)
throw std::ios_base::failure("could not open file");
if (mode & std::ios_base::ate) {
if (std::fseek(GETFILE, 0, SEEK_END)) {
fclose(GETFILE);
throw std::ios_base::failure("could not open file");
}
}
}
void FileBuf::close()
{
std::fclose(GETFILE);
}
std::streamsize FileBuf::read(char* s, std::streamsize n)
{
return static_cast<std::streamsize>(std::fread(s, 1, n, GETFILE));
}
std::streamsize FileBuf::write(const char* s, std::streamsize n)
{
return static_cast<std::streamsize>(std::fwrite(s, 1, n, GETFILE));
}
std::streamoff FileBuf::seek(std::streamoff off, std::ios_base::seekdir way)
{
const auto src = [way]() -> int
{
switch(way)
{
case std::ios_base::beg:
return SEEK_SET;
case std::ios_base::cur:
return SEEK_CUR;
case std::ios_base::end:
return SEEK_END;
default:
throw std::ios_base::failure("bad seek direction");
}
}();
if(std::fseek(GETFILE, static_cast<long>(off), src))
throw std::ios_base::failure("bad seek offset");
return static_cast<std::streamsize>(std::ftell(GETFILE));
}
VCMI_LIB_NAMESPACE_END

View File

@@ -1,67 +0,0 @@
/*
* FileStream.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/stream.hpp>
VCMI_LIB_NAMESPACE_BEGIN
class DLL_LINKAGE FileBuf
{
public:
using char_type = char;
using category = struct category_ :
boost::iostreams::seekable_device_tag,
boost::iostreams::closable_tag
{};
FileBuf(const boost::filesystem::path& filename, std::ios_base::openmode mode);
std::streamsize read(char* s, std::streamsize n);
std::streamsize write(const char* s, std::streamsize n);
std::streamoff seek(std::streamoff off, std::ios_base::seekdir way);
void close();
private:
void* filePtr;
};
VCMI_LIB_NAMESPACE_END
struct zlib_filefunc64_def_s;
using zlib_filefunc64_def = zlib_filefunc64_def_s;
#ifdef VCMI_DLL
#ifdef _MSC_VER
#pragma warning (push)
#pragma warning (disable : 4910)
#endif
extern template struct DLL_LINKAGE boost::iostreams::stream<VCMI_LIB_WRAP_NAMESPACE(FileBuf)>;
#ifdef _MSC_VER
#pragma warning (pop)
#endif
#endif
VCMI_LIB_NAMESPACE_BEGIN
class DLL_LINKAGE FileStream : public boost::iostreams::stream<FileBuf>
{
public:
FileStream() = default;
explicit FileStream(const boost::filesystem::path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
: boost::iostreams::stream<FileBuf>(p, mode) {}
static bool createFile(const boost::filesystem::path& filename);
static zlib_filefunc64_def* GetMinizipFilefunc();
};
VCMI_LIB_NAMESPACE_END

View File

@@ -11,7 +11,6 @@
#include "MinizipExtensions.h"
#include "CMemoryBuffer.h"
#include "FileStream.h"
VCMI_LIB_NAMESPACE_BEGIN
@@ -86,10 +85,59 @@ inline int streamProxyClose(voidpf opaque, voidpf stream)
}
///CDefaultIOApi
#define GETFILE static_cast<std::FILE*>(filePtr)
#ifdef VCMI_WINDOWS
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <cwchar>
#define CHAR_LITERAL(s) L##s
using CharType = wchar_t;
#else
#define CHAR_LITERAL(s) s
using CharType = char;
#endif
static inline FILE* do_open(const CharType* name, const CharType* mode)
{
#ifdef VCMI_WINDOWS
return _wfopen(name, mode);
#else
return std::fopen(name, mode);
#endif
}
static voidpf ZCALLBACK MinizipOpenFunc(voidpf opaque, const void* filename, int mode)
{
const CharType* mode_fopen = [mode]() -> const CharType*
{
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
return CHAR_LITERAL("rb");
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
return CHAR_LITERAL("r+b");
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
return CHAR_LITERAL("wb");
return nullptr;
}();
if (filename != nullptr && mode_fopen != nullptr)
return do_open(static_cast<const CharType*>(filename), mode_fopen);
else
return nullptr;
}
zlib_filefunc64_def CDefaultIOApi::getApiStructure()
{
return * FileStream::GetMinizipFilefunc();
static zlib_filefunc64_def MinizipFilefunc;
static bool initialized = false;
if (!initialized)
{
fill_fopen64_filefunc(&MinizipFilefunc);
MinizipFilefunc.zopen64_file = &MinizipOpenFunc;
initialized = true;
}
return MinizipFilefunc;
}
///CProxyIOApi

View File

@@ -425,7 +425,7 @@ const CColorMapping & CLogConsoleTarget::getColorMapping() const { return colorM
void CLogConsoleTarget::setColorMapping(const CColorMapping & colorMapping) { this->colorMapping = colorMapping; }
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("%l %n [%t] - %m");

View File

@@ -10,7 +10,6 @@
#pragma once
#include "../CConsoleHandler.h"
#include "../filesystem/FileStream.h"
VCMI_LIB_NAMESPACE_BEGIN
@@ -220,7 +219,7 @@ public:
void write(const LogRecord & record) override;
private:
boost::filesystem::fstream file;
std::fstream file;
CLogFormatter formatter;
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::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.flush();

View File

@@ -9,7 +9,6 @@
*/
#include "StdInc.h"
#include "BinaryDeserializer.h"
#include "../filesystem/FileStream.h"
#include "../registerTypes/RegisterTypes.h"
@@ -41,7 +40,7 @@ void CLoadFile::openNextFile(const boost::filesystem::path & fname, int minimalV
try
{
fName = fname.string();
sfile = std::make_unique<FileStream>(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
if(!(*sfile))

View File

@@ -19,7 +19,6 @@
VCMI_LIB_NAMESPACE_BEGIN
class CStackInstance;
class FileStream;
class DLL_LINKAGE CLoaderBase
{
@@ -581,7 +580,7 @@ public:
BinaryDeserializer serializer;
std::string fName;
std::unique_ptr<FileStream> sfile;
std::unique_ptr<std::fstream> sfile;
CLoadFile(const boost::filesystem::path & fname, int minimalVersion = SERIALIZATION_VERSION); //throws!
virtual ~CLoadFile();

View File

@@ -9,7 +9,6 @@
*/
#include "StdInc.h"
#include "BinarySerializer.h"
#include "../filesystem/FileStream.h"
#include "../registerTypes/RegisterTypes.h"
@@ -38,7 +37,7 @@ void CSaveFile::openNextFile(const boost::filesystem::path &fname)
fName = fname;
try
{
sfile = std::make_unique<FileStream>(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
if(!(*sfile))

View File

@@ -14,8 +14,6 @@
VCMI_LIB_NAMESPACE_BEGIN
class FileStream;
class DLL_LINKAGE CSaverBase
{
protected:
@@ -392,7 +390,7 @@ public:
BinarySerializer serializer;
boost::filesystem::path fName;
std::unique_ptr<FileStream> sfile;
std::unique_ptr<std::fstream> sfile;
CSaveFile(const boost::filesystem::path &fname); //throws!
~CSaveFile();

View File

@@ -9,7 +9,6 @@
*/
#include "StdInc.h"
#include "CLoadIntegrityValidator.h"
#include "../filesystem/FileStream.h"
#include "../registerTypes/RegisterTypes.h"

View File

@@ -9,7 +9,6 @@
*/
#include "StdInc.h"
#include "jsonutils.h"
#include "../lib/filesystem/FileStream.h"
static QVariantMap JsonToMap(const JsonMap & json)
{
@@ -120,7 +119,7 @@ JsonNode toJson(QVariant object)
void JsonToFile(QString filename, QVariant object)
{
FileStream 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();
}

View File

@@ -24,8 +24,8 @@
void ResourceConverter::convertExtractedResourceFiles(ConversionOptions conversionOptions)
{
bfs::path spritesPath = VCMIDirs::get().userExtractedPath() / "SPRITES";
bfs::path imagesPath = VCMIDirs::get().userExtractedPath() / "IMAGES";
boost::filesystem::path spritesPath = VCMIDirs::get().userExtractedPath() / "SPRITES";
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" };
if(conversionOptions.splitDefs)
@@ -35,16 +35,16 @@ void ResourceConverter::convertExtractedResourceFiles(ConversionOptions conversi
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);
for(const auto & directoryEntry : bfs::directory_iterator(sourceFolder))
for(const auto & directoryEntry : boost::filesystem::directory_iterator(sourceFolder))
{
const auto filename = directoryEntry.path().filename();
try
{
if(!bfs::is_regular_file(directoryEntry))
if(!boost::filesystem::is_regular_file(directoryEntry))
continue;
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")
{
auto img = BitmapHandler::loadBitmap(filenameLowerCase);
bfs::path pngFilePath = sourceFolder / (fileStem + ".png");
boost::filesystem::path pngFilePath = sourceFolder / (fileStem + ".png");
img.save(pathToQString(pngFilePath), "PNG");
if(deleteOriginals)
bfs::remove(directoryEntry.path());
boost::filesystem::remove(directoryEntry.path());
}
}
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)))
{
@@ -76,13 +76,13 @@ void ResourceConverter::splitDefFile(const std::string & fileName, const bfs::pa
anim->exportBitmaps(pathToQString(sourceFolder));
if(deleteOriginals)
bfs::remove(sourceFolder / fileName);
boost::filesystem::remove(sourceFolder / fileName);
}
else
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);

View File

@@ -9,8 +9,6 @@
*/
#pragma once
namespace bfs = boost::filesystem;
// Struct for holding all Convertor Options
struct ConversionOptions
{
@@ -45,14 +43,14 @@ public:
private:
// 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
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>
/// 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)
/// </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;
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.flush();