1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-04 23:17:41 +02:00

VCMIDirs update #6

- Minor fixes
- CLoadFile updated to boost::filesystem::path
This commit is contained in:
Karol 2014-08-27 12:31:58 +02:00
parent a34d148fa3
commit 53ab0593b7
8 changed files with 25 additions and 34 deletions

View File

@ -96,7 +96,7 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
/* ---------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------- */
/* Commonly used C++, Boost headers */ /* Commonly used C++, Boost headers */
/* ---------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------- */
#ifndef VCMI_WINDOWS #ifdef VCMI_WINDOWS
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define NOMINMAX // Exclude min/max macros from <Windows.h> #define NOMINMAX // Exclude min/max macros from <Windows.h>
#endif #endif

View File

@ -114,8 +114,7 @@ void startGameFromFile(const bfs::path &fname)
if(fname.empty() || !bfs::exists(fname)) if(fname.empty() || !bfs::exists(fname))
throw std::runtime_error("Startfile \"" + fname.string() + "\" does not exist!"); throw std::runtime_error("Startfile \"" + fname.string() + "\" does not exist!");
// TODO: CLoadFile should take boost::path as an argument CLoadFile out(fname);
CLoadFile out(fname.string());
if (!out.sfile || !*out.sfile) if (!out.sfile || !*out.sfile)
throw std::runtime_error("Cannot read from startfile \"" + fname.string() +"\"!"); throw std::runtime_error("Cannot read from startfile \"" + fname.string() +"\"!");
out >> si; out >> si;
@ -594,7 +593,6 @@ void processCommand(const std::string &message)
for (auto & filename : list) for (auto & filename : list)
{ {
const bfs::path filePath = outPath / (filename.getName() + ".TXT"); const bfs::path filePath = outPath / (filename.getName() + ".TXT");
std::string outName = filePath.string();
bfs::create_directories(filePath.parent_path()); bfs::create_directories(filePath.parent_path());

View File

@ -37,13 +37,6 @@
#include "gui/CGuiHandler.h" #include "gui/CGuiHandler.h"
#include "../lib/UnlockGuard.h" #include "../lib/UnlockGuard.h"
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
/* /*
* CPlayerInterface.cpp, part of VCMI engine * CPlayerInterface.cpp, part of VCMI engine
* *

View File

@ -777,8 +777,9 @@ std::string CClient::aiNameForPlayer(const PlayerSettings &ps, bool battleAI)
{ {
if(ps.name.size()) if(ps.name.size())
{ {
boost::filesystem::path ai_path = VCMIDirs::get().libraryPath() / "AI" / VCMIDirs::get().libraryName(ps.name); const boost::filesystem::path aiPath =
if (boost::filesystem::exists(ai_path)) VCMIDirs::get().libraryPath() / "AI" / VCMIDirs::get().libraryName(ps.name);
if (boost::filesystem::exists(aiPath))
return ps.name; return ps.name;
} }
@ -865,9 +866,8 @@ CServerHandler::~CServerHandler()
void CServerHandler::callServer() void CServerHandler::callServer()
{ {
setThreadName("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 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()); int result = std::system(comm.c_str());
if (result == 0) if (result == 0)
logNetwork->infoStream() << "Server closed correctly"; logNetwork->infoStream() << "Server closed correctly";

View File

@ -113,7 +113,7 @@ shared_ptr<rett> createAny(const boost::filesystem::path& libpath, const std::st
} }
template<typename rett> 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 = const boost::filesystem::path filePath =

View File

@ -347,7 +347,7 @@ void CSaveFile::putMagicBytes( const std::string &text )
write(text.c_str(), text.length()); 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); registerTypes(*this);
openNextFile(fname, minimalVersion); openNextFile(fname, minimalVersion);
@ -363,33 +363,33 @@ int CLoadFile::read(void * data, unsigned size)
return 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(!reverseEndianess);
assert(minimalVersion <= version); assert(minimalVersion <= version);
try try
{ {
fName = fname; fName = fname.string();
sfile = make_unique<std::ifstream>(fname, std::ios::binary); sfile = make_unique<boost::filesystem::ifstream>(fname, 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))
THROW_FORMAT("Error: cannot open to read %s!", fname); THROW_FORMAT("Error: cannot open to read %s!", fName);
//we can read //we can read
char buffer[4]; char buffer[4];
sfile->read(buffer, 4); sfile->read(buffer, 4);
if(std::memcmp(buffer,"VCMI",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; *this >> fileVersion;
if(fileVersion < minimalVersion) if(fileVersion < minimalVersion)
THROW_FORMAT("Error: too old file format (%s)!", fname); THROW_FORMAT("Error: too old file format (%s)!", fName);
if(fileVersion > version) 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; auto versionptr = (char*)&fileVersion;
std::reverse(versionptr, versionptr + 4); std::reverse(versionptr, versionptr + 4);
@ -401,7 +401,7 @@ void CLoadFile::openNextFile(const std::string &fname, int minimalVersion)
reverseEndianess = true; reverseEndianess = true;
} }
else else
THROW_FORMAT("Error: too new file format (%s)!", fname); THROW_FORMAT("Error: too new file format (%s)!", fName);
} }
} }
catch(...) catch(...)

View File

@ -1530,13 +1530,13 @@ class DLL_LINKAGE CLoadFile
public: public:
std::string fName; 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(); ~CLoadFile();
int read(void * data, unsigned size); //throws! 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 clear();
void reportState(CLogger * out); void reportState(CLogger * out);

View File

@ -289,9 +289,9 @@ private:
class DLL_LINKAGE CLogFileTarget : public ILogTarget class DLL_LINKAGE CLogFileTarget : public ILogTarget
{ {
public: 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. /// 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; const CLogFormatter & getFormatter() const;
void setFormatter(const CLogFormatter & formatter); void setFormatter(const CLogFormatter & formatter);