mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-29 22:45:34 +00:00
Follow the 'XDG Base Directory Specification' instead of putting the configfile in ~/.openmw/
Also updated based on feedback from athile: Fix broken Linux elif. Use boost:filesystem instead of mkdir for increased future portability. Break appart class definition and implementation.
This commit is contained in:
parent
753a4f681e
commit
a724de2429
3 changed files with 59 additions and 47 deletions
|
@ -4,7 +4,8 @@ project(OpenMW)
|
|||
|
||||
set(GAME
|
||||
main.cpp
|
||||
engine.cpp)
|
||||
engine.cpp
|
||||
path.cpp)
|
||||
set(GAME_HEADER
|
||||
engine.hpp)
|
||||
source_group(game FILES ${GAME} ${GAME_HEADER})
|
||||
|
|
56
apps/openmw/path.cpp
Normal file
56
apps/openmw/path.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include "path.hpp"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
||||
#include <stdlib.h> //getenv
|
||||
#endif
|
||||
|
||||
|
||||
std::string OMW::Path::getPath(PathTypeEnum parType, const std::string parApp, const std::string parFile)
|
||||
{
|
||||
std::string theBasePath;
|
||||
if(parType == GLOBAL_CFG_PATH)
|
||||
{
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
theBasePath = macBundlePath() + "/Contents/MacOS/"; //FIXME do we have global/local with OSX?
|
||||
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
||||
theBasePath = "/etc/"+parApp+"/";
|
||||
#else
|
||||
theBasePath = "";
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
theBasePath = macBundlePath() + "/Contents/MacOS/"; //FIXME do we have global/local with OSX?
|
||||
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
||||
const char* theDir;
|
||||
if ((theDir = getenv("OPENMW_HOME")) != NULL)
|
||||
{
|
||||
theBasePath = std::string(theDir)+"/";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((theDir = getenv("XDG_CONFIG_HOME")))
|
||||
{
|
||||
theBasePath = std::string(theDir)+"/"+parApp+"/";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((theDir = getenv("HOME")) == NULL)
|
||||
return parFile;
|
||||
theBasePath = std::string(theDir)+"/.config/"+parApp+"/";
|
||||
}
|
||||
}
|
||||
boost::filesystem::create_directories(boost::filesystem::path(theBasePath));
|
||||
#else
|
||||
theBasePath = "";
|
||||
#endif
|
||||
}
|
||||
|
||||
theBasePath.append(parFile);
|
||||
return theBasePath;
|
||||
}
|
||||
|
|
@ -4,12 +4,6 @@
|
|||
#include <OgrePlatform.h>
|
||||
#include <string>
|
||||
|
||||
#if OGRE_PLATFORM_LINUX
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h> //getenv
|
||||
#endif
|
||||
|
||||
namespace OMW
|
||||
{
|
||||
class Path
|
||||
|
@ -21,46 +15,7 @@ namespace OMW
|
|||
GLOBAL_CFG_PATH
|
||||
};
|
||||
|
||||
//TODO use application data dir on windows?
|
||||
static std::string getPath(PathTypeEnum parType, const std::string parApp, const std::string parFile)
|
||||
{
|
||||
std::string theBasePath;
|
||||
if(parType == GLOBAL_CFG_PATH)
|
||||
{
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
theBasePath = macBundlePath() + "/Contents/MacOS/"; //FIXME do we have global/local with OSX?
|
||||
#elif OGRE_PLATFORM_LINUX
|
||||
theBasePath = "/etc/"+parApp+"/";
|
||||
#else
|
||||
theBasePath = "";
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
||||
theBasePath = macBundlePath() + "/Contents/MacOS/"; //FIXME do we have global/local with OSX?
|
||||
#elif OGRE_PLATFORM_LINUX
|
||||
const char* homedir;
|
||||
if ((homedir = getenv("OPENMW_HOME")) != NULL)
|
||||
{
|
||||
theBasePath = std::string(homedir)+"/";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((homedir = getenv("HOME")) == NULL)
|
||||
return NULL;
|
||||
theBasePath = std::string(homedir)+"/."+parApp+"/";
|
||||
}
|
||||
mkdir(theBasePath.c_str(), 0777);
|
||||
#else
|
||||
theBasePath = "";
|
||||
#endif
|
||||
}
|
||||
|
||||
theBasePath.append(parFile);
|
||||
return theBasePath;
|
||||
}
|
||||
static std::string getPath(PathTypeEnum parType, const std::string parApp, const std::string parFile);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue