2013-03-02 21:41:25 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "VCMIDirs.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VCMIDirs.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VCMIDirs VCMIDirsGlobal;
|
|
|
|
|
|
|
|
VCMIDirs::VCMIDirs()
|
|
|
|
{
|
|
|
|
// initialize local directory and create folders to which VCMI needs write access
|
2013-07-08 23:55:22 +03:00
|
|
|
boost::filesystem::create_directory(userDataPath());
|
|
|
|
boost::filesystem::create_directory(userCachePath());
|
|
|
|
boost::filesystem::create_directory(userConfigPath());
|
|
|
|
boost::filesystem::create_directory(userSavePath());
|
2013-03-02 21:41:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VCMIDirs & VCMIDirs::get()
|
|
|
|
{
|
|
|
|
return VCMIDirsGlobal;
|
|
|
|
}
|
|
|
|
|
2013-07-08 23:55:22 +03:00
|
|
|
std::string VCMIDirs::userCachePath() const
|
|
|
|
{
|
|
|
|
return userDataPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string VCMIDirs::userConfigPath() const
|
|
|
|
{
|
|
|
|
return userDataPath() + "/config";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string VCMIDirs::userSavePath() const
|
|
|
|
{
|
|
|
|
return userDataPath() + "/Games";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> VCMIDirs::configPaths() const
|
|
|
|
{
|
|
|
|
return std::vector<std::string>(1, dataPaths()[0] + "/config");
|
|
|
|
}
|
|
|
|
|
2013-03-02 21:41:25 +03:00
|
|
|
//FIXME: find way to at least decrease size of this ifdef (along with cleanup in CMake)
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
2013-07-08 23:55:22 +03:00
|
|
|
std::string VCMIDirs::userDataPath() const
|
2013-03-02 21:41:25 +03:00
|
|
|
{
|
2013-07-08 23:55:22 +03:00
|
|
|
return dataPaths()[0];
|
2013-03-02 21:41:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string VCMIDirs::libraryPath() const
|
|
|
|
{
|
2013-07-08 23:55:22 +03:00
|
|
|
return userDataPath();
|
2013-03-02 21:41:25 +03:00
|
|
|
}
|
|
|
|
|
2013-08-24 23:11:51 +03:00
|
|
|
std::string VCMIDirs::clientPath() const
|
|
|
|
{
|
|
|
|
return userDataPath() + "\\" + "VCMI_client.exe";
|
|
|
|
}
|
|
|
|
|
2013-03-02 21:41:25 +03:00
|
|
|
std::string VCMIDirs::serverPath() const
|
|
|
|
{
|
2013-07-08 23:55:22 +03:00
|
|
|
return userDataPath() + "\\" + "VCMI_server.exe";
|
2013-03-02 21:41:25 +03:00
|
|
|
}
|
|
|
|
|
2013-07-08 23:55:22 +03:00
|
|
|
std::vector<std::string> VCMIDirs::dataPaths() const
|
2013-03-02 21:41:25 +03:00
|
|
|
{
|
2013-07-08 23:55:22 +03:00
|
|
|
return std::vector<std::string>(1, ".");
|
2013-03-02 21:41:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string VCMIDirs::libraryName(std::string basename) const
|
|
|
|
{
|
|
|
|
return basename + ".dll";
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
|
2013-07-08 23:55:22 +03:00
|
|
|
std::string VCMIDirs::userDataPath() const
|
2013-03-02 21:41:25 +03:00
|
|
|
{
|
|
|
|
// 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];
|
|
|
|
// UserPath = path([urls[0] path] + "/vcmi").string();
|
|
|
|
|
|
|
|
// ...so here goes a bit of hardcode instead
|
|
|
|
std::string home_dir = ".";
|
2013-06-26 14:18:27 +03:00
|
|
|
if (getenv("HOME") != nullptr )
|
2013-03-02 21:41:25 +03:00
|
|
|
home_dir = getenv("HOME");
|
|
|
|
|
2013-03-07 01:03:57 +03:00
|
|
|
return boost::filesystem::path(home_dir + "/Library/Application Support/vcmi").string();
|
2013-03-02 21:41:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string VCMIDirs::libraryPath() const
|
|
|
|
{
|
|
|
|
return ".";
|
|
|
|
}
|
|
|
|
|
2013-08-24 23:11:51 +03:00
|
|
|
std::string VCMIDirs::clientPath() const
|
|
|
|
{
|
2013-10-07 06:19:11 +03:00
|
|
|
return "./vcmiclient";
|
2013-08-24 23:11:51 +03:00
|
|
|
}
|
|
|
|
|
2013-03-02 21:41:25 +03:00
|
|
|
std::string VCMIDirs::serverPath() const
|
|
|
|
{
|
2013-10-07 06:19:11 +03:00
|
|
|
return "./vcmiserver";
|
2013-03-02 21:41:25 +03:00
|
|
|
}
|
|
|
|
|
2013-07-08 23:55:22 +03:00
|
|
|
std::vector<std::string> VCMIDirs::dataPaths() const
|
2013-03-02 21:41:25 +03:00
|
|
|
{
|
2013-07-08 23:55:22 +03:00
|
|
|
return std::vector<std::string>(1, "../Data");
|
2013-03-02 21:41:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string VCMIDirs::libraryName(std::string basename) const
|
|
|
|
{
|
|
|
|
return "lib" + basename + ".dylib";
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2013-07-08 23:55:22 +03:00
|
|
|
std::string VCMIDirs::userDataPath() const
|
2013-03-02 21:41:25 +03:00
|
|
|
{
|
2013-06-26 14:18:27 +03:00
|
|
|
if (getenv("HOME") != nullptr )
|
2013-03-02 21:41:25 +03:00
|
|
|
return std::string(getenv("HOME")) + "/.vcmi";
|
|
|
|
return ".";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string VCMIDirs::libraryPath() const
|
|
|
|
{
|
|
|
|
return M_LIB_DIR;
|
|
|
|
}
|
|
|
|
|
2013-08-24 23:11:51 +03:00
|
|
|
std::string VCMIDirs::clientPath() const
|
|
|
|
{
|
|
|
|
return std::string(M_BIN_DIR) + "/" + "vcmiclient";
|
|
|
|
}
|
|
|
|
|
2013-03-02 21:41:25 +03:00
|
|
|
std::string VCMIDirs::serverPath() const
|
|
|
|
{
|
|
|
|
return std::string(M_BIN_DIR) + "/" + "vcmiserver";
|
|
|
|
}
|
|
|
|
|
2013-07-08 23:55:22 +03:00
|
|
|
std::vector<std::string> VCMIDirs::dataPaths() const
|
2013-03-02 21:41:25 +03:00
|
|
|
{
|
2013-07-08 23:55:22 +03:00
|
|
|
return std::vector<std::string>(1, M_DATA_DIR);
|
2013-03-02 21:41:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string VCMIDirs::libraryName(std::string basename) const
|
|
|
|
{
|
|
|
|
return "lib" + basename + ".so";
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|