mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
VCMIDirs update #6
- Minor fixes - CLoadFile updated to boost::filesystem::path
This commit is contained in:
parent
a34d148fa3
commit
53ab0593b7
4
Global.h
4
Global.h
@ -96,7 +96,7 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
/* Commonly used C++, Boost headers */
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
#ifndef VCMI_WINDOWS
|
||||
#ifdef VCMI_WINDOWS
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
#define NOMINMAX // Exclude min/max macros from <Windows.h>
|
||||
#endif
|
||||
@ -164,7 +164,7 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
|
||||
#include <boost/math/special_functions/round.hpp>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
# define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
|
@ -114,8 +114,7 @@ void startGameFromFile(const bfs::path &fname)
|
||||
if(fname.empty() || !bfs::exists(fname))
|
||||
throw std::runtime_error("Startfile \"" + fname.string() + "\" does not exist!");
|
||||
|
||||
// TODO: CLoadFile should take boost::path as an argument
|
||||
CLoadFile out(fname.string());
|
||||
CLoadFile out(fname);
|
||||
if (!out.sfile || !*out.sfile)
|
||||
throw std::runtime_error("Cannot read from startfile \"" + fname.string() +"\"!");
|
||||
out >> si;
|
||||
@ -594,7 +593,6 @@ void processCommand(const std::string &message)
|
||||
for (auto & filename : list)
|
||||
{
|
||||
const bfs::path filePath = outPath / (filename.getName() + ".TXT");
|
||||
std::string outName = filePath.string();
|
||||
|
||||
bfs::create_directories(filePath.parent_path());
|
||||
|
||||
|
@ -37,13 +37,6 @@
|
||||
#include "gui/CGuiHandler.h"
|
||||
#include "../lib/UnlockGuard.h"
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
/*
|
||||
* CPlayerInterface.cpp, part of VCMI engine
|
||||
*
|
||||
|
@ -777,8 +777,9 @@ std::string CClient::aiNameForPlayer(const PlayerSettings &ps, bool battleAI)
|
||||
{
|
||||
if(ps.name.size())
|
||||
{
|
||||
boost::filesystem::path ai_path = VCMIDirs::get().libraryPath() / "AI" / VCMIDirs::get().libraryName(ps.name);
|
||||
if (boost::filesystem::exists(ai_path))
|
||||
const boost::filesystem::path aiPath =
|
||||
VCMIDirs::get().libraryPath() / "AI" / VCMIDirs::get().libraryName(ps.name);
|
||||
if (boost::filesystem::exists(aiPath))
|
||||
return ps.name;
|
||||
}
|
||||
|
||||
@ -865,9 +866,8 @@ CServerHandler::~CServerHandler()
|
||||
void CServerHandler::callServer()
|
||||
{
|
||||
setThreadName("CServerHandler::callServer");
|
||||
// TODO: Make more boost::filesystem::path based
|
||||
const std::string logName = (VCMIDirs::get().userCachePath() / "server_log.txt").string();
|
||||
const std::string comm = VCMIDirs::get().serverPath().string() + " --port=" + port + " > " + logName;
|
||||
const std::string comm = VCMIDirs::get().serverPath().string() + " --port=" + port + " > \"" + logName + '\"';
|
||||
int result = std::system(comm.c_str());
|
||||
if (result == 0)
|
||||
logNetwork->infoStream() << "Server closed correctly";
|
||||
|
@ -86,7 +86,7 @@ shared_ptr<rett> createAny(const boost::filesystem::path& libpath, const std::st
|
||||
#endif
|
||||
if (!dll)
|
||||
{
|
||||
logGlobal->errorStream() << "Cannot open dynamic library ("<<libpath<<"). Throwing...";
|
||||
logGlobal->errorStream() << "Cannot open dynamic library ("<<libpath<<"). Throwing...";
|
||||
throw std::runtime_error("Cannot open dynamic library");
|
||||
}
|
||||
else if(!getName || !getAI)
|
||||
@ -113,9 +113,9 @@ shared_ptr<rett> createAny(const boost::filesystem::path& libpath, const std::st
|
||||
}
|
||||
|
||||
template<typename rett>
|
||||
shared_ptr<rett> createAnyAI(std::string dllname, std::string methodName)
|
||||
shared_ptr<rett> createAnyAI(std::string dllname, const std::string& methodName)
|
||||
{
|
||||
logGlobal->infoStream() << "Opening " << dllname;
|
||||
logGlobal->infoStream() << "Opening " << dllname;
|
||||
const boost::filesystem::path filePath =
|
||||
VCMIDirs::get().libraryPath() / "AI" / VCMIDirs::get().libraryName(dllname);
|
||||
auto ret = createAny<rett>(filePath, methodName);
|
||||
|
@ -347,7 +347,7 @@ void CSaveFile::putMagicBytes( const std::string &text )
|
||||
write(text.c_str(), text.length());
|
||||
}
|
||||
|
||||
CLoadFile::CLoadFile(const std::string &fname, int minimalVersion /*= version*/)
|
||||
CLoadFile::CLoadFile(const boost::filesystem::path & fname, int minimalVersion /*= version*/)
|
||||
{
|
||||
registerTypes(*this);
|
||||
openNextFile(fname, minimalVersion);
|
||||
@ -363,33 +363,33 @@ int CLoadFile::read(void * data, unsigned size)
|
||||
return size;
|
||||
}
|
||||
|
||||
void CLoadFile::openNextFile(const std::string &fname, int minimalVersion)
|
||||
void CLoadFile::openNextFile(const boost::filesystem::path & fname, int minimalVersion)
|
||||
{
|
||||
assert(!reverseEndianess);
|
||||
assert(minimalVersion <= version);
|
||||
|
||||
try
|
||||
{
|
||||
fName = fname;
|
||||
sfile = make_unique<std::ifstream>(fname, std::ios::binary);
|
||||
fName = fname.string();
|
||||
sfile = make_unique<boost::filesystem::ifstream>(fname, std::ios::binary);
|
||||
sfile->exceptions(std::ifstream::failbit | std::ifstream::badbit); //we throw a lot anyway
|
||||
|
||||
if(!(*sfile))
|
||||
THROW_FORMAT("Error: cannot open to read %s!", fname);
|
||||
THROW_FORMAT("Error: cannot open to read %s!", fName);
|
||||
|
||||
//we can read
|
||||
char buffer[4];
|
||||
sfile->read(buffer, 4);
|
||||
if(std::memcmp(buffer,"VCMI",4))
|
||||
THROW_FORMAT("Error: not a VCMI file(%s)!", fname);
|
||||
THROW_FORMAT("Error: not a VCMI file(%s)!", fName);
|
||||
|
||||
*this >> fileVersion;
|
||||
if(fileVersion < minimalVersion)
|
||||
THROW_FORMAT("Error: too old file format (%s)!", fname);
|
||||
THROW_FORMAT("Error: too old file format (%s)!", fName);
|
||||
|
||||
if(fileVersion > version)
|
||||
{
|
||||
logGlobal->warnStream() << boost::format("Warning format version mismatch: found %d when current is %d! (file %s)\n") % fileVersion % version % fname;
|
||||
logGlobal->warnStream() << boost::format("Warning format version mismatch: found %d when current is %d! (file %s)\n") % fileVersion % version % fName;
|
||||
|
||||
auto versionptr = (char*)&fileVersion;
|
||||
std::reverse(versionptr, versionptr + 4);
|
||||
@ -401,7 +401,7 @@ void CLoadFile::openNextFile(const std::string &fname, int minimalVersion)
|
||||
reverseEndianess = true;
|
||||
}
|
||||
else
|
||||
THROW_FORMAT("Error: too new file format (%s)!", fname);
|
||||
THROW_FORMAT("Error: too new file format (%s)!", fName);
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
|
@ -1530,17 +1530,17 @@ class DLL_LINKAGE CLoadFile
|
||||
|
||||
public:
|
||||
std::string fName;
|
||||
unique_ptr<std::ifstream> sfile;
|
||||
unique_ptr<boost::filesystem::ifstream> sfile;
|
||||
|
||||
CLoadFile(const std::string &fname, int minimalVersion = version); //throws!
|
||||
CLoadFile(const boost::filesystem::path & fname, int minimalVersion = version); //throws!
|
||||
~CLoadFile();
|
||||
int read(void * data, unsigned size); //throws!
|
||||
|
||||
void openNextFile(const std::string &fname, int minimalVersion); //throws!
|
||||
void openNextFile(const boost::filesystem::path & fname, int minimalVersion); //throws!
|
||||
void clear();
|
||||
void reportState(CLogger * out);
|
||||
|
||||
void checkMagicBytes(const std::string &text);
|
||||
void checkMagicBytes(const std::string & text);
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CLoadIntegrityValidator : public CISer<CLoadIntegrityValidator>
|
||||
|
@ -289,9 +289,9 @@ private:
|
||||
class DLL_LINKAGE CLogFileTarget : public ILogTarget
|
||||
{
|
||||
public:
|
||||
/// Constructs a CLogFileTarget and opens the file designated by file_path. If the append parameter is true, the file
|
||||
/// Constructs a CLogFileTarget and opens the file designated by filePath. If the append parameter is true, the file
|
||||
/// will be appended to. Otherwise the file designated by filePath will be truncated before being opened.
|
||||
explicit CLogFileTarget(boost::filesystem::path file_path, bool append = true);
|
||||
explicit CLogFileTarget(boost::filesystem::path filePath, bool append = true);
|
||||
|
||||
const CLogFormatter & getFormatter() const;
|
||||
void setFormatter(const CLogFormatter & formatter);
|
||||
|
Loading…
Reference in New Issue
Block a user