Config dir cleanup by Graham Harrias (thanks\!)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4379 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2010-01-01 17:01:32 +00:00
parent f58bc8708b
commit 9aba0daeb3

View File

@ -23,6 +23,7 @@
#include <stdexcept> #include <stdexcept>
#include <sstream> #include <sstream>
#include <sys/stat.h> #include <sys/stat.h>
#include <iostream>
#include <string> #include <string>
#ifdef WIN32 #ifdef WIN32
# include <io.h> # include <io.h>
@ -31,15 +32,12 @@
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
// Some portabilty defines // Some portabilty defines
# endif # endif
# define CONFIGDIR "."
#elif defined(__APPLE__)
# include <unistd.h>
# define CONFIGDIR "Library/Application Support/SuperTuxKart"
#else #else
# include <unistd.h> # include <unistd.h>
# define CONFIGDIR ".supertuxkart"
#endif #endif
#define CONFIGDIR "supertuxkart"
#include "irrlicht.h" #include "irrlicht.h"
#include "btBulletDynamicsCommon.h" #include "btBulletDynamicsCommon.h"
@ -348,26 +346,35 @@ std::string FileManager::getHomeDir() const
std::ostringstream s; std::ostringstream s;
if(getenv("APPDATA")!=NULL) if(getenv("APPDATA")!=NULL)
{ {
s<<getenv("APPDATA")<<"/supertuxkart/"; s<<getenv("APPDATA")<<"/"<<CONFIGDIR<<"/";
DIRNAME=s.str(); DIRNAME=s.str();
} }
else DIRNAME="."; else DIRNAME=".";
#else #endif
if(getenv("HOME")!=NULL) #ifdef linux
{ // Use new standards for config directory
if (getenv("XDG_CONFIG_HOME")!=NULL){
DIRNAME = getenv("XDG_CONFIG_HOME");
}else if (getenv("HOME")!=NULL){
DIRNAME = getenv("HOME");
DIRNAME += "/.config";
}else{
std::cerr << "No home directory, this should NOT happen!\n";
// This is what was here before, it looks rather questionable.
DIRNAME=".";
}
DIRNAME += "/";
DIRNAME += CONFIGDIR;
#endif
#ifdef __APPLE__
if (getenv("HOME")!=NULL){
DIRNAME = getenv("HOME"); DIRNAME = getenv("HOME");
} }else{
else std::cerr << "No home directory, this should NOT happen!\n";
{
#ifdef __APPLE__
fprintf(stderr, "Home directory is undefined, this should NOT happen!\n");
// Fall back to system-wide app data (rather than user-specific data), but should not happen anyway. // Fall back to system-wide app data (rather than user-specific data), but should not happen anyway.
DIRNAME = ""; DIRNAME = "";
#else }
DIRNAME = "."; DIRNAME += "/Library/Application Support/";
#endif
}
DIRNAME += "/";
DIRNAME += CONFIGDIR; DIRNAME += CONFIGDIR;
#endif #endif
return DIRNAME; return DIRNAME;