1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

VCMIDirs update #4 fix

This commit is contained in:
Karol
2014-08-11 21:24:31 +02:00
parent c16e7d4bcf
commit 2da6d9e7dd
6 changed files with 145 additions and 139 deletions

View File

@@ -274,13 +274,13 @@ int main(int argc, char** argv)
console->start(); console->start();
atexit(dispose); atexit(dispose);
const bfs::path log_path = VCMIDirs::get().userCachePath() / "VCMI_Client_log.txt"; const bfs::path logPath = VCMIDirs::get().userCachePath() / "VCMI_Client_log.txt";
CBasicLogConfigurator logConfig(log_path, console); CBasicLogConfigurator logConfig(logPath, console);
logConfig.configureDefault(); logConfig.configureDefault();
logGlobal->infoStream() << "Creating console and configuring logger: " << pomtime.getDiff(); logGlobal->infoStream() << "Creating console and configuring logger: " << pomtime.getDiff();
logGlobal->infoStream() << "The log file will be saved to " << log_path; logGlobal->infoStream() << "The log file will be saved to " << logPath;
#ifdef __ANDROID__ #ifdef VCMI_ANDROID
// boost will crash without this // boost will crash without this
setenv("LANG", "C", 1); setenv("LANG", "C", 1);
#endif #endif
@@ -583,7 +583,7 @@ void processCommand(const std::string &message)
{ {
std::cout<<"Command accepted.\t"; std::cout<<"Command accepted.\t";
const bfs::path out_path = const bfs::path outPath =
VCMIDirs::get().userCachePath() / "extracted"; VCMIDirs::get().userCachePath() / "extracted";
auto list = CResourceHandler::get()->getFilteredFiles([](const ResourceID & ident) auto list = CResourceHandler::get()->getFilteredFiles([](const ResourceID & ident)
@@ -593,19 +593,19 @@ void processCommand(const std::string &message)
for (auto & filename : list) for (auto & filename : list)
{ {
const bfs::path file_path = out_path / (filename.getName() + ".TXT"); const bfs::path filePath = outPath / (filename.getName() + ".TXT");
std::string outName = file_path.string(); std::string outName = filePath.string();
bfs::create_directories(file_path.parent_path()); bfs::create_directories(filePath.parent_path());
bfs::ofstream file(file_path); bfs::ofstream file(filePath);
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);
} }
std::cout << "\rExtracting done :)\n"; std::cout << "\rExtracting done :)\n";
std::cout << " Extracted files can be found in " << out_path << " directory\n"; std::cout << " Extracted files can be found in " << outPath << " directory\n";
} }
else if(cn=="crash") else if(cn=="crash")
{ {
@@ -711,13 +711,13 @@ void processCommand(const std::string &message)
{ {
CDefEssential * cde = CDefHandler::giveDefEss(URI); CDefEssential * cde = CDefHandler::giveDefEss(URI);
const bfs::path out_path = VCMIDirs::get().userCachePath() / "extraced" / URI; const bfs::path outPath = VCMIDirs::get().userCachePath() / "extraced" / URI;
bfs::create_directories(out_path); bfs::create_directories(outPath);
for (size_t i = 0; i < cde->ourImages.size(); ++i) for (size_t i = 0; i < cde->ourImages.size(); ++i)
{ {
const bfs::path file_path = out_path / (boost::lexical_cast<std::string>(i) + ".bmp"); const bfs::path filePath = outPath / (boost::lexical_cast<std::string>(i)+".bmp");
SDL_SaveBMP(cde->ourImages[i].bitmap, file_path.string().c_str()); SDL_SaveBMP(cde->ourImages[i].bitmap, filePath.string().c_str());
} }
} }
else else
@@ -730,12 +730,12 @@ void processCommand(const std::string &message)
if (CResourceHandler::get()->existsResource(ResourceID(URI))) if (CResourceHandler::get()->existsResource(ResourceID(URI)))
{ {
const bfs::path out_path = VCMIDirs::get().userCachePath() / "extracted" / URI; const bfs::path outPath = VCMIDirs::get().userCachePath() / "extracted" / URI;
auto data = CResourceHandler::get()->load(ResourceID(URI))->readAll(); auto data = CResourceHandler::get()->load(ResourceID(URI))->readAll();
bfs::create_directories(out_path.parent_path()); bfs::create_directories(outPath.parent_path());
bfs::ofstream outFile(out_path, bfs::ofstream::binary); bfs::ofstream outFile(outPath, bfs::ofstream::binary);
outFile.write((char*)data.first.get(), data.second); outFile.write((char*)data.first.get(), data.second);
} }
else else

View File

@@ -4,7 +4,7 @@
#include "BattleState.h" #include "BattleState.h"
#include "VCMIDirs.h" #include "VCMIDirs.h"
#ifdef _WIN32 #ifdef VCMI_WINDOWS
#define WIN32_LEAN_AND_MEAN //excludes rarely used stuff from windows headers - delete this line if something is missing #define WIN32_LEAN_AND_MEAN //excludes rarely used stuff from windows headers - delete this line if something is missing
#include <windows.h> //for .dll libs #include <windows.h> //for .dll libs
#else #else
@@ -22,7 +22,7 @@
* *
*/ */
#ifdef __ANDROID__ #ifdef VCMI_ANDROID
// we can't use shared libraries on Android so here's a hack // we can't use shared libraries on Android so here's a hack
extern "C" DLL_EXPORT void VCAI_GetAiName(char* name); extern "C" DLL_EXPORT void VCAI_GetAiName(char* name);
extern "C" DLL_EXPORT void VCAI_GetNewAI(shared_ptr<CGlobalAI> &out); extern "C" DLL_EXPORT void VCAI_GetNewAI(shared_ptr<CGlobalAI> &out);
@@ -111,10 +111,10 @@ template<typename rett>
shared_ptr<rett> createAnyAI(std::string dllname, std::string methodName) shared_ptr<rett> createAnyAI(std::string dllname, std::string methodName)
{ {
logGlobal->infoStream() << "Opening " << dllname; logGlobal->infoStream() << "Opening " << dllname;
const boost::filesystem::path file_path = const boost::filesystem::path filePath =
VCMIDirs::get().libraryPath() / "AI" / VCMIDirs::get().libraryName(dllname); VCMIDirs::get().libraryPath() / "AI" / VCMIDirs::get().libraryName(dllname);
// TODO: createAny Should take boost::filesystem::path in argument. // TODO: createAny Should take boost::filesystem::path in argument.
auto ret = createAny<rett>(file_path.string(), methodName); auto ret = createAny<rett>(filePath.string(), methodName);
ret->dllName = dllname; ret->dllName = dllname;
return ret; return ret;
} }

View File

@@ -30,7 +30,7 @@ void IVCMIDirs::init()
#include <Shlobj.h> #include <Shlobj.h>
#include <Shellapi.h> #include <Shellapi.h>
class VCMIDirs_win32 : public IVCMIDirs class VCMIDirsWIN32 : public IVCMIDirs
{ {
public: public:
boost::filesystem::path userDataPath() const override; boost::filesystem::path userDataPath() const override;
@@ -52,7 +52,7 @@ class VCMIDirs_win32 : public IVCMIDirs
void init() override; void init() override;
}; };
void VCMIDirs_win32::init() void VCMIDirsWIN32::init()
{ {
// Call base (init dirs) // Call base (init dirs)
IVCMIDirs::init(); IVCMIDirs::init();
@@ -76,13 +76,13 @@ void VCMIDirs_win32::init()
} }
// Why the hell path strings should be end with double null :/ // Why the hell path strings should be end with double null :/
auto make_double_nulled = [](const bfs::path& path) -> std::unique_ptr<wchar_t[]> auto makeDoubleNulled = [](const bfs::path& path) -> std::unique_ptr<wchar_t[]>
{ {
const std::wstring& path_str = path.native(); const std::wstring& pathStr = path.native();
std::unique_ptr<wchar_t[]> result(new wchar_t[path_str.length() + 2]); std::unique_ptr<wchar_t[]> result(new wchar_t[pathStr.length() + 2]);
size_t i = 0; size_t i = 0;
for (const wchar_t ch : path_str) for (const wchar_t ch : pathStr)
result[i++] = ch; result[i++] = ch;
result[i++] = L'\0'; result[i++] = L'\0';
result[i++] = L'\0'; result[i++] = L'\0';
@@ -90,21 +90,21 @@ void VCMIDirs_win32::init()
return result; return result;
}; };
auto from_dnulled = make_double_nulled(from / L"*.*"); auto fromDNulled = makeDoubleNulled(from / L"*.*");
auto to_dnulled = make_double_nulled(to); auto toDNulled = makeDoubleNulled(to);
SHFILEOPSTRUCTW file_op; SHFILEOPSTRUCTW fileOp;
file_op.hwnd = GetConsoleWindow(); fileOp.hwnd = GetConsoleWindow();
file_op.wFunc = FO_MOVE; fileOp.wFunc = FO_MOVE;
file_op.pFrom = from_dnulled.get(); fileOp.pFrom = fromDNulled.get();
file_op.pTo = to_dnulled.get(); fileOp.pTo = toDNulled.get();
file_op.fFlags = 0; fileOp.fFlags = 0;
file_op.hNameMappings = nullptr; fileOp.hNameMappings = nullptr;
file_op.lpszProgressTitle = nullptr; fileOp.lpszProgressTitle = nullptr;
const int error_code = SHFileOperationW(&file_op); const int errorCode = SHFileOperationW(&fileOp);
if (error_code != 0); // TODO: Log error. User should try to move files. if (errorCode != 0); // TODO: Log error. User should try to move files.
else if (file_op.fAnyOperationsAborted); // TODO: Log warn. User aborted operation. User should move files. else if (fileOp.fAnyOperationsAborted); // TODO: Log warn. User aborted operation. User should move files.
else if (!bfs::is_empty(from)); // TODO: Log warn. Some files not moved. User should try to move files. else if (!bfs::is_empty(from)); // TODO: Log warn. Some files not moved. User should try to move files.
else // TODO: Log fact that we moved files succefully. else // TODO: Log fact that we moved files succefully.
bfs::remove(from); bfs::remove(from);
@@ -113,57 +113,63 @@ void VCMIDirs_win32::init()
moveDirIfExists(userDataPath() / "Games", userSavePath()); moveDirIfExists(userDataPath() / "Games", userSavePath());
} }
bfs::path VCMIDirs_win32::userDataPath() const bfs::path VCMIDirsWIN32::userDataPath() const
{ {
const char* profile_dir_a; wchar_t profileDir[MAX_PATH];
wchar_t profile_dir_w[MAX_PATH];
// The user's profile folder. A typical path is C:\Users\username. // The user's profile folder. A typical path is C:\Users\username.
// FIXME: Applications should not create files or folders at this level; // FIXME: Applications should not create files or folders at this level;
// they should put their data under the locations referred to by CSIDL_APPDATA or CSIDL_LOCAL_APPDATA. // they should put their data under the locations referred to by CSIDL_APPDATA or CSIDL_LOCAL_APPDATA.
if (SHGetSpecialFolderPathW(nullptr, profile_dir_w, CSIDL_PROFILE, FALSE) == FALSE) // WinAPI way failed if (SHGetSpecialFolderPathW(nullptr, profileDir, CSIDL_PROFILE, FALSE) == FALSE) // WinAPI way failed
{ {
// FIXME: Use _wdupenv_s on MS Visual Studio. #if defined(_MSC_VER) && _MSC_VER >= 1700
// or: define _CRT_SECURE_NO_WARNINGS in preprocessor global settings. wchar_t* buffer;
// warning C4996: 'getenv': This function or variable may be unsafe. size_t bufferSize;
// Consider using _dupenv_s instead. errno_t result = _wdupenv_s(&buffer, &bufferSize, L"userprofile");
// To disable deprecation, use _CRT_SECURE_NO_WARNINGS. if (result == 0)
// See online help for details. {
if (profile_dir_a = std::getenv("userprofile")) // STL way succeed bfs::path result(std::wstring(buffer, bufferSize));
return bfs::path(profile_dir_a) / "vcmi"; free(buffer);
return result;
}
#else
const char* profileDirA;
if (profileDirA = std::getenv("userprofile")) // STL way succeed
return bfs::path(profileDirA) / "vcmi";
#endif
else else
return "."; // Every thing failed, return current directory. return "."; // Every thing failed, return current directory.
} }
else else
return bfs::path(profile_dir_w) / "vcmi"; return bfs::path(profileDir) / "vcmi";
//return dataPaths()[0] ???; //return dataPaths()[0] ???;
} }
bfs::path VCMIDirs_win32::userCachePath() const { return userDataPath(); } bfs::path VCMIDirsWIN32::userCachePath() const { return userDataPath(); }
bfs::path VCMIDirs_win32::userConfigPath() const { return userDataPath() / "config"; } bfs::path VCMIDirsWIN32::userConfigPath() const { return userDataPath() / "config"; }
std::vector<bfs::path> VCMIDirs_win32::dataPaths() const std::vector<bfs::path> VCMIDirsWIN32::dataPaths() const
{ {
return std::vector<bfs::path>(1, bfs::path(".")); return std::vector<bfs::path>(1, bfs::path("."));
} }
bfs::path VCMIDirs_win32::clientPath() const { return binaryPath() / "VCMI_client.exe"; } bfs::path VCMIDirsWIN32::clientPath() const { return binaryPath() / "VCMI_client.exe"; }
bfs::path VCMIDirs_win32::serverPath() const { return binaryPath() / "VCMI_server.exe"; } bfs::path VCMIDirsWIN32::serverPath() const { return binaryPath() / "VCMI_server.exe"; }
bfs::path VCMIDirs_win32::libraryPath() const { return "."; } bfs::path VCMIDirsWIN32::libraryPath() const { return "."; }
bfs::path VCMIDirs_win32::binaryPath() const { return "."; } bfs::path VCMIDirsWIN32::binaryPath() const { return "."; }
std::string VCMIDirs_win32::genHelpString() const std::string VCMIDirsWIN32::genHelpString() const
{ {
std::vector<std::string> temp_vec; std::vector<std::string> tempVec;
for (const bfs::path& path : dataPaths()) for (const bfs::path& path : dataPaths())
temp_vec.push_back(path.string()); tempVec.push_back(path.string());
std::string gd_string_a = boost::algorithm::join(temp_vec, ";"); std::string gdStringA = boost::algorithm::join(tempVec, ";");
return return
" game data: " + gd_string_a + "\n" " game data: " + gdStringA + "\n"
" libraries: " + libraryPath().string() + "\n" " libraries: " + libraryPath().string() + "\n"
" server: " + serverPath().string() + "\n" " server: " + serverPath().string() + "\n"
"\n" "\n"
@@ -173,9 +179,9 @@ std::string VCMIDirs_win32::genHelpString() const
" user saves: " + userSavePath().string() + "\n"; // Should end without new-line? " user saves: " + userSavePath().string() + "\n"; // Should end without new-line?
} }
std::string VCMIDirs_win32::libraryName(const std::string& basename) const { return basename + ".dll"; } std::string VCMIDirsWIN32::libraryName(const std::string& basename) const { return basename + ".dll"; }
#elif defined(VCMI_UNIX) #elif defined(VCMI_UNIX)
class IVCMIDirs_UNIX : public IVCMIDirs class IVCMIDirsUNIX : public IVCMIDirs
{ {
public: public:
boost::filesystem::path clientPath() const override; boost::filesystem::path clientPath() const override;
@@ -184,19 +190,19 @@ class IVCMIDirs_UNIX : public IVCMIDirs
std::string genHelpString() const override; std::string genHelpString() const override;
}; };
bfs::path IVCMIDirs_UNIX::clientPath() const { return binaryPath() / "vcmiclient"; } bfs::path IVCMIDirsUNIX::clientPath() const { return binaryPath() / "vcmiclient"; }
bfs::path IVCMIDirs_UNIX::clientPath() const { return binaryPath() / "vcmiserver"; } bfs::path IVCMIDirsUNIX::clientPath() const { return binaryPath() / "vcmiserver"; }
std::string IVCMIDirs_UNIX::genHelpString() const std::string IVCMIDirsUNIX::genHelpString() const
{ {
std::vector<std::string> temp_vec; std::vector<std::string> tempVec;
for (const bfs::path& path : dataPaths()) for (const bfs::path& path : dataPaths())
temp_vec.push_back(path.string()); tempVec.push_back(path.string());
std::string gd_string_a = boost::algorithm::join(temp_vec, ":"); std::string gdStringA = boost::algorithm::join(tempVec, ":");
return return
" game data: " + gd_string_a + "\n" " game data: " + gdStringA + "\n"
" libraries: " + libraryPath().string() + "\n" " libraries: " + libraryPath().string() + "\n"
" server: " + serverPath().string() + "\n" " server: " + serverPath().string() + "\n"
"\n" "\n"
@@ -207,7 +213,7 @@ std::string IVCMIDirs_UNIX::genHelpString() const
} }
#ifdef VCMI_APPLE #ifdef VCMI_APPLE
class VCMIDirs_OSX : public IVCMIDirs_UNIX class VCMIDirsOSX : public IVCMIDirsUNIX
{ {
public: public:
boost::filesystem::path userDataPath() const override; boost::filesystem::path userDataPath() const override;
@@ -224,10 +230,10 @@ class VCMIDirs_OSX : public IVCMIDirs_UNIX
void init() override; void init() override;
}; };
void VCMIDirs_OSX::init() void VCMIDirsOSX::init()
{ {
// Call base (init dirs) // Call base (init dirs)
IVCMIDirs_UNIX::init(); IVCMIDirsUNIX::init();
auto moveDirIfExists = [](const bfs::path& from, const bfs::path& to) auto moveDirIfExists = [](const bfs::path& from, const bfs::path& to)
{ {
@@ -249,13 +255,13 @@ void VCMIDirs_OSX::init()
for (bfs::directory_iterator file(from); file != bfs::directory_iterator(); ++file) for (bfs::directory_iterator file(from); file != bfs::directory_iterator(); ++file)
{ {
const boost::filesystem::path& src_file_path = file->path(); const boost::filesystem::path& srcFilePath = file->path();
const boost::filesystem::path dst_file_path = to / src_file_path.filename(); const boost::filesystem::path dstFilePath = to / srcFilePath.filename();
// TODO: Aplication should ask user what to do when file exists: // TODO: Aplication should ask user what to do when file exists:
// replace/ignore/stop process/replace all/ignore all // replace/ignore/stop process/replace all/ignore all
if (!boost::filesystem::exists(dst_file_path)) if (!boost::filesystem::exists(dstFilePath))
bfs::rename(src_file_path, dst_file_path); bfs::rename(srcFilePath, dstFilePath);
} }
if (!bfs::is_empty(from)); // TODO: Log warn. Some files not moved. User should try to move files. if (!bfs::is_empty(from)); // TODO: Log warn. Some files not moved. User should try to move files.
@@ -266,7 +272,7 @@ void VCMIDirs_OSX::init()
moveDirIfExists(userDataPath() / "Games", userSavePath()); moveDirIfExists(userDataPath() / "Games", userSavePath());
} }
bfs::path VCMIDirs_OSX::userDataPath() const bfs::path VCMIDirsOSX::userDataPath() const
{ {
// This is Cocoa code that should be normally used to get path to Application Support folder but can't use it here for now... // This is Cocoa code that should be normally used to get path to Application Support folder but can't use it here for now...
// NSArray* urls = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask]; // NSArray* urls = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask];
@@ -274,25 +280,25 @@ bfs::path VCMIDirs_OSX::userDataPath() const
// ...so here goes a bit of hardcode instead // ...so here goes a bit of hardcode instead
const char* home_dir = getenv("HOME"); // Should be std::getenv? const char* homeDir = getenv("HOME"); // Should be std::getenv?
if (home_dir == nullptr) if (homeDir == nullptr)
home_dir = "."; homeDir = ".";
return bfs::path(home_dir) / "Library" / "Application Support" / "vcmi"; return bfs::path(homeDir) / "Library" / "Application Support" / "vcmi";
} }
bfs::path VCMIDirs_OSX::userCachePath() const { return userDataPath(); } bfs::path VCMIDirsOSX::userCachePath() const { return userDataPath(); }
bfs::path VCMIDirs_OSX::userConfigPath() const { return userDataPath() / "config"; } bfs::path VCMIDirsOSX::userConfigPath() const { return userDataPath() / "config"; }
std::vector<bfs::path> VCMIDirs_OSX::dataPaths() const std::vector<bfs::path> VCMIDirsOSX::dataPaths() const
{ {
return std::vector<bfs::path>(1, "../Data"); return std::vector<bfs::path>(1, "../Data");
} }
bfs::path VCMIDirs_OSX::libraryPath() const { return "."; } bfs::path VCMIDirsOSX::libraryPath() const { return "."; }
bfs::path VCMIDirs_OSX::binaryPath() const { return "."; } bfs::path VCMIDirsOSX::binaryPath() const { return "."; }
std::string libraryName(const std::string& basename) { return "lib" + basename + ".dylib"; } std::string libraryName(const std::string& basename) { return "lib" + basename + ".dylib"; }
#elif defined(VCMI_LINUX) #elif defined(VCMI_LINUX)
class VCMIDirs_Linux : public IVCMIDirs_UNIX class VCMIDirsLinux : public IVCMIDirsUNIX
{ {
public: public:
boost::filesystem::path userDataPath() const override; boost::filesystem::path userDataPath() const override;
@@ -307,41 +313,41 @@ public:
std::string libraryName(const std::string& basename) const override; std::string libraryName(const std::string& basename) const override;
}; };
bfs::path VCMIDirs_Linux::userDataPath() const bfs::path VCMIDirsLinux::userDataPath() const
{ {
// $XDG_DATA_HOME, default: $HOME/.local/share // $XDG_DATA_HOME, default: $HOME/.local/share
const char* home_dir; const char* homeDir;
if (home_dir = getenv("XDG_DATA_HOME")) if (homeDir = getenv("XDG_DATA_HOME"))
return home_dir; return homeDir;
else if (home_dir = getenv("HOME")) else if (homeDir = getenv("HOME"))
return bfs::path(home_dir) / ".local" / "share" / "vcmi"; return bfs::path(homeDir) / ".local" / "share" / "vcmi";
else else
return "."; return ".";
} }
bfs::path VCMIDirs_Linux::userCachePath() const bfs::path VCMIDirsLinux::userCachePath() const
{ {
// $XDG_CACHE_HOME, default: $HOME/.cache // $XDG_CACHE_HOME, default: $HOME/.cache
const char* home_dir; const char* tempResult;
if (home_dir = getenv("XDG_CACHE_HOME")) if (tempResult = getenv("XDG_CACHE_HOME"))
return bfs::path(home_dir) / "vcmi"; return bfs::path(tempResult) / "vcmi";
else if (home_dir = getenv("HOME")) else if (tempResult = getenv("HOME"))
return bfs::path(home_dir) / ".cache" / "vcmi"; return bfs::path(tempResult) / ".cache" / "vcmi";
else else
return "."; return ".";
} }
bfs::path VCMIDirs_Linux::userConfigPath() const bfs::path VCMIDirsLinux::userConfigPath() const
{ {
// $XDG_CONFIG_HOME, default: $HOME/.config // $XDG_CONFIG_HOME, default: $HOME/.config
const char* home_dir; const char* tempResult;
if (home_dir = getenv("XDG_CONFIG_HOME")) if (tempResult = getenv("XDG_CONFIG_HOME"))
return bfs::path(home_dir) / "vcmi"; return bfs::path(tempResult) / "vcmi";
else if (home_dir = getenv("HOME")) else if (tempResult = getenv("HOME"))
return bfs::path(home_dir) / ".config" / "vcmi"; return bfs::path(tempResult) / ".config" / "vcmi";
else else
return "."; return ".";
} }
std::vector<bfs::path> VCMIDirs_Linux::dataPaths() const std::vector<bfs::path> VCMIDirsLinux::dataPaths() const
{ {
// $XDG_DATA_DIRS, default: /usr/local/share/:/usr/share/ // $XDG_DATA_DIRS, default: /usr/local/share/:/usr/share/
@@ -350,12 +356,12 @@ std::vector<bfs::path> VCMIDirs_Linux::dataPaths() const
// in vcmi fs last directory has highest priority // in vcmi fs last directory has highest priority
std::vector<bfs::path> ret; std::vector<bfs::path> ret;
const char* home_dir; const char* tempResult;
ret.push_back(M_DATA_DIR); ret.push_back(M_DATA_DIR);
if ((home_dir = getenv("XDG_DATA_DIRS")) != nullptr) if ((tempResult = getenv("XDG_DATA_DIRS")) != nullptr)
{ {
std::string dataDirsEnv = home_dir; std::string dataDirsEnv = tempResult;
std::vector<std::string> dataDirs; std::vector<std::string> dataDirs;
boost::split(dataDirs, dataDirsEnv, boost::is_any_of(":")); boost::split(dataDirs, dataDirsEnv, boost::is_any_of(":"));
for (auto & entry : boost::adaptors::reverse(dataDirs)) for (auto & entry : boost::adaptors::reverse(dataDirs))
@@ -370,12 +376,12 @@ std::vector<bfs::path> VCMIDirs_Linux::dataPaths() const
return ret; return ret;
} }
bfs::path VCMIDirs_Linux::libraryPath() const { return M_LIB_PATH; } bfs::path VCMIDirsLinux::libraryPath() const { return M_LIB_PATH; }
bfs::path VCMIDirs_Linux::binaryPath() const { return M_BIN_DIR; } bfs::path VCMIDirsLinux::binaryPath() const { return M_BIN_DIR; }
std::string VCMIDirs_Linux::libraryName(const std::string& basename) const { return "lib" + basename + ".so"; } std::string VCMIDirsLinux::libraryName(const std::string& basename) const { return "lib" + basename + ".so"; }
#ifdef VCMI_ANDROID #ifdef VCMI_ANDROID
class VCMIDirs_Android : public VCMIDirs_Linux class VCMIDirsAndroid : public VCMIDirsLinux
{ {
public: public:
boost::filesystem::path userDataPath() const override; boost::filesystem::path userDataPath() const override;
@@ -386,11 +392,11 @@ public:
}; };
// on Android HOME will be set to something like /sdcard/data/Android/is.xyz.vcmi/files/ // on Android HOME will be set to something like /sdcard/data/Android/is.xyz.vcmi/files/
bfs::path VCMIDirs_Android::userDataPath() const { return getenv("HOME"); } bfs::path VCMIDirsAndroid::userDataPath() const { return getenv("HOME"); }
bfs::path VCMIDirs_Android::userCachePath() const { return userDataPath() / "cache"; } bfs::path VCMIDirsAndroid::userCachePath() const { return userDataPath() / "cache"; }
bfs::path VCMIDirs_Android::userConfigPath() const { return userDataPath() / "config"; } bfs::path VCMIDirsAndroid::userConfigPath() const { return userDataPath() / "config"; }
std::vector<bfs::path> VCMIDirs_Android::dataPaths() const std::vector<bfs::path> VCMIDirsAndroid::dataPaths() const
{ {
return std::vector<bfs::path>(1, userDataPath()); return std::vector<bfs::path>(1, userDataPath());
} }
@@ -404,13 +410,13 @@ namespace VCMIDirs
const IVCMIDirs& get() const IVCMIDirs& get()
{ {
#ifdef VCMI_WINDOWS #ifdef VCMI_WINDOWS
static VCMIDirs_win32 singleton; static VCMIDirsWIN32 singleton;
#elif defined(VCMI_ANDROID) #elif defined(VCMI_ANDROID)
static VCMIDirs_Android singleton; static VCMIDirsAndroid singleton;
#elif defined(VCMI_LINUX) #elif defined(VCMI_LINUX)
static VCMIDirs_Linux singleton; static VCMIDirsLinux singleton;
#elif defined(VCMI_APPLE) #elif defined(VCMI_APPLE)
static VCMIDirs_OSX singleton; static VCMIDirsOSX singleton;
#endif #endif
static bool initialized = false; static bool initialized = false;
if (!initialized) if (!initialized)

View File

@@ -3,16 +3,16 @@
#include "../CConfigHandler.h" #include "../CConfigHandler.h"
CBasicLogConfigurator::CBasicLogConfigurator(const boost::filesystem::path & file_path, CConsoleHandler * const console) : CBasicLogConfigurator::CBasicLogConfigurator(const boost::filesystem::path & filePath, CConsoleHandler * const console) :
file_path(file_path), console(console), appendToLogFile(false) {} filePath(filePath), console(console), appendToLogFile(false) {}
CBasicLogConfigurator::CBasicLogConfigurator(boost::filesystem::path && file_path, CConsoleHandler * const console) : CBasicLogConfigurator::CBasicLogConfigurator(boost::filesystem::path && filePath, CConsoleHandler * const console) :
file_path(std::move(file_path)), console(console), appendToLogFile(false) {} filePath(std::move(filePath)), console(console), appendToLogFile(false) {}
void CBasicLogConfigurator::configureDefault() void CBasicLogConfigurator::configureDefault()
{ {
CLogger::getGlobalLogger()->addTarget(make_unique<CLogConsoleTarget>(console)); CLogger::getGlobalLogger()->addTarget(make_unique<CLogConsoleTarget>(console));
CLogger::getGlobalLogger()->addTarget(make_unique<CLogFileTarget>(file_path, appendToLogFile)); CLogger::getGlobalLogger()->addTarget(make_unique<CLogFileTarget>(filePath, appendToLogFile));
appendToLogFile = true; appendToLogFile = true;
} }
@@ -69,7 +69,7 @@ void CBasicLogConfigurator::configure()
CLogger::getGlobalLogger()->addTarget(std::move(consoleTarget)); CLogger::getGlobalLogger()->addTarget(std::move(consoleTarget));
// Add file target // Add file target
auto fileTarget = make_unique<CLogFileTarget>(file_path, appendToLogFile); auto fileTarget = make_unique<CLogFileTarget>(filePath, appendToLogFile);
const JsonNode & fileNode = loggingNode["file"]; const JsonNode & fileNode = loggingNode["file"];
if(!fileNode.isNull()) if(!fileNode.isNull())
{ {

View File

@@ -22,8 +22,8 @@ class JsonNode;
class DLL_LINKAGE CBasicLogConfigurator class DLL_LINKAGE CBasicLogConfigurator
{ {
public: public:
CBasicLogConfigurator(const boost::filesystem::path & file_path, CConsoleHandler * const console); CBasicLogConfigurator(const boost::filesystem::path & filePath, CConsoleHandler * const console);
CBasicLogConfigurator(boost::filesystem::path && file_path, CConsoleHandler * const console); CBasicLogConfigurator(boost::filesystem::path && filePath, CConsoleHandler * const console);
/// Configures the logging system by parsing the logging settings. It adds the console target and the file target to the global logger. /// Configures the logging system by parsing the logging settings. It adds the console target and the file target to the global logger.
/// Doesn't throw, but logs on success or fault. /// Doesn't throw, but logs on success or fault.
@@ -39,7 +39,7 @@ private:
// Throws: std::runtime_error // Throws: std::runtime_error
static EConsoleTextColor::EConsoleTextColor getConsoleColor(const std::string & colorName); static EConsoleTextColor::EConsoleTextColor getConsoleColor(const std::string & colorName);
boost::filesystem::path file_path; boost::filesystem::path filePath;
CConsoleHandler * console; CConsoleHandler * console;
bool appendToLogFile; bool appendToLogFile;
}; };

View File

@@ -340,13 +340,13 @@ void CLogConsoleTarget::setFormatter(const CLogFormatter & formatter) { this->fo
const CColorMapping & CLogConsoleTarget::getColorMapping() const { return colorMapping; } const CColorMapping & CLogConsoleTarget::getColorMapping() const { return colorMapping; }
void CLogConsoleTarget::setColorMapping(const CColorMapping & colorMapping) { this->colorMapping = colorMapping; } void CLogConsoleTarget::setColorMapping(const CColorMapping & colorMapping) { this->colorMapping = colorMapping; }
CLogFileTarget::CLogFileTarget(const boost::filesystem::path & file_path, bool append /*= true*/) CLogFileTarget::CLogFileTarget(const boost::filesystem::path & filePath, bool append /*= true*/)
: file(file_path, append ? std::ios_base::app : std::ios_base::out) : file(filePath, append ? std::ios_base::app : std::ios_base::out)
{ {
formatter.setPattern("%d %l %n [%t] - %m"); formatter.setPattern("%d %l %n [%t] - %m");
} }
CLogFileTarget::CLogFileTarget(boost::filesystem::path && file_path, bool append /*= true*/) CLogFileTarget::CLogFileTarget(boost::filesystem::path && filePath, bool append /*= true*/)
: file(std::move(file_path), append ? std::ios_base::app : std::ios_base::out) : file(std::move(filePath), append ? std::ios_base::app : std::ios_base::out)
{ {
formatter.setPattern("%d %l %n [%t] - %m"); formatter.setPattern("%d %l %n [%t] - %m");
} }