|
|
@@ -27,6 +27,9 @@ VCMIDirs & VCMIDirs::get()
|
|
|
return VCMIDirsGlobal;
|
|
|
}
|
|
|
|
|
|
+//FIXME: find way to at least decrease size of this ifdef (along with cleanup in CMake)
|
|
|
+#if defined(_WIN32)
|
|
|
+
|
|
|
std::string VCMIDirs::userCachePath() const
|
|
|
{
|
|
|
return userDataPath();
|
|
|
@@ -42,14 +45,6 @@ std::string VCMIDirs::userSavePath() const
|
|
|
return userDataPath() + "/Games";
|
|
|
}
|
|
|
|
|
|
-std::vector<std::string> VCMIDirs::configPaths() const
|
|
|
-{
|
|
|
- return std::vector<std::string>(1, dataPaths()[0] + "/config");
|
|
|
-}
|
|
|
-
|
|
|
-//FIXME: find way to at least decrease size of this ifdef (along with cleanup in CMake)
|
|
|
-#if defined(_WIN32)
|
|
|
-
|
|
|
std::string VCMIDirs::userDataPath() const
|
|
|
{
|
|
|
const std::string homeDir = std::getenv("userprofile");
|
|
|
@@ -84,6 +79,21 @@ std::string VCMIDirs::libraryName(std::string basename) const
|
|
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
|
|
+std::string VCMIDirs::userCachePath() const
|
|
|
+{
|
|
|
+ return userDataPath();
|
|
|
+}
|
|
|
+
|
|
|
+std::string VCMIDirs::userConfigPath() const
|
|
|
+{
|
|
|
+ return userDataPath() + "/config";
|
|
|
+}
|
|
|
+
|
|
|
+std::string VCMIDirs::userSavePath() const
|
|
|
+{
|
|
|
+ return userDataPath() + "/Games";
|
|
|
+}
|
|
|
+
|
|
|
std::string VCMIDirs::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...
|
|
|
@@ -125,11 +135,9 @@ std::string VCMIDirs::libraryName(std::string basename) const
|
|
|
|
|
|
#else
|
|
|
|
|
|
-std::string VCMIDirs::userDataPath() const
|
|
|
+std::string VCMIDirs::libraryName(std::string basename) const
|
|
|
{
|
|
|
- if (getenv("HOME") != nullptr )
|
|
|
- return std::string(getenv("HOME")) + "/.vcmi";
|
|
|
- return ".";
|
|
|
+ return "lib" + basename + ".so";
|
|
|
}
|
|
|
|
|
|
std::string VCMIDirs::libraryPath() const
|
|
|
@@ -147,14 +155,68 @@ std::string VCMIDirs::serverPath() const
|
|
|
return std::string(M_BIN_DIR) + "/" + "vcmiserver";
|
|
|
}
|
|
|
|
|
|
-std::vector<std::string> VCMIDirs::dataPaths() const
|
|
|
+// $XDG_DATA_HOME, default: $HOME/.local/share
|
|
|
+std::string VCMIDirs::userDataPath() const
|
|
|
{
|
|
|
- return std::vector<std::string>(1, M_DATA_DIR);
|
|
|
+ if (getenv("XDG_DATA_HOME") != nullptr )
|
|
|
+ return std::string(getenv("XDG_DATA_HOME")) + "/vcmi";
|
|
|
+ if (getenv("HOME") != nullptr )
|
|
|
+ return std::string(getenv("HOME")) + "/.local/share" + "/vcmi";
|
|
|
+ return ".";
|
|
|
}
|
|
|
|
|
|
-std::string VCMIDirs::libraryName(std::string basename) const
|
|
|
+std::string VCMIDirs::userSavePath() const
|
|
|
{
|
|
|
- return "lib" + basename + ".so";
|
|
|
+ return userDataPath() + "/Saves";
|
|
|
+}
|
|
|
+
|
|
|
+// $XDG_CACHE_HOME, default: $HOME/.cache
|
|
|
+std::string VCMIDirs::userCachePath() const
|
|
|
+{
|
|
|
+ if (getenv("XDG_CACHE_HOME") != nullptr )
|
|
|
+ return std::string(getenv("XDG_CACHE_HOME")) + "/vcmi";
|
|
|
+ if (getenv("HOME") != nullptr )
|
|
|
+ return std::string(getenv("HOME")) + "/.cache" + "/vcmi";
|
|
|
+ return ".";
|
|
|
+}
|
|
|
+
|
|
|
+// $XDG_CONFIG_HOME, default: $HOME/.config
|
|
|
+std::string VCMIDirs::userConfigPath() const
|
|
|
+{
|
|
|
+ if (getenv("XDG_CONFIG_HOME") != nullptr )
|
|
|
+ return std::string(getenv("XDG_CONFIG_HOME")) + "/vcmi";
|
|
|
+ if (getenv("HOME") != nullptr )
|
|
|
+ return std::string(getenv("HOME")) + "/.config" + "/vcmi";
|
|
|
+ return ".";
|
|
|
+}
|
|
|
+
|
|
|
+// $XDG_DATA_DIRS, default: /usr/local/share/:/usr/share/
|
|
|
+std::vector<std::string> VCMIDirs::dataPaths() const
|
|
|
+{
|
|
|
+ // construct list in reverse.
|
|
|
+ // in specification first directory has highest priority
|
|
|
+ // in vcmi fs last directory has highest priority
|
|
|
+
|
|
|
+ std::vector<std::string> ret;
|
|
|
+
|
|
|
+ if (getenv("HOME") != nullptr ) // compatibility, should be removed after 0.96
|
|
|
+ ret.push_back(std::string(getenv("HOME")) + "/.vcmi");
|
|
|
+ ret.push_back(M_DATA_DIR);
|
|
|
+
|
|
|
+ if (getenv("XDG_DATA_DIRS") != nullptr)
|
|
|
+ {
|
|
|
+ std::string dataDirsEnv = getenv("XDG_DATA_DIRS");
|
|
|
+ std::vector<std::string> dataDirs;
|
|
|
+ boost::split(dataDirs, dataDirsEnv, boost::is_any_of(":"));
|
|
|
+ for (auto & entry : boost::adaptors::reverse(dataDirs))
|
|
|
+ ret.push_back(entry + "/vcmi");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ret.push_back("/usr/share/");
|
|
|
+ ret.push_back("/usr/local/share/");
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
#endif
|