diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-25 16:08:29 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-25 16:08:29 +0400 |
commit | 942fcf44150aea4eea8e0f44de6b05229bb7c182 (patch) | |
tree | 95737a1de510dcf9400a748eb0acfefaac651cdf /intern/ghost | |
parent | 81935ee6772afce569ddadc5ce5870728452b5d9 (diff) |
Unix: enable use of XDG paths for storing Blender configuration on Linux/BSD/..,
starting from version 2.64. Unless you have a special system setup, this means the
will be in ~/.config/blender rather than ~/.blender.
When the version number is changed to 2.64, the "Copy Previous Settings" operator
in the splash will copy the settings to the new location.
XDG base directory specification:
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
Diffstat (limited to 'intern/ghost')
-rw-r--r-- | intern/ghost/CMakeLists.txt | 4 | ||||
-rw-r--r-- | intern/ghost/GHOST_ISystemPaths.h | 8 | ||||
-rw-r--r-- | intern/ghost/GHOST_Path-api.h | 8 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_Path-api.cpp | 8 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemPaths.h | 16 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemPathsCarbon.cpp | 18 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemPathsCarbon.h | 8 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemPathsCocoa.h | 8 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemPathsCocoa.mm | 16 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemPathsWin32.cpp | 16 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemPathsWin32.h | 8 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemPathsX11.cpp | 52 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemPathsX11.h | 8 |
13 files changed, 97 insertions, 81 deletions
diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt index eeb924d7bf0..277b14e2c66 100644 --- a/intern/ghost/CMakeLists.txt +++ b/intern/ghost/CMakeLists.txt @@ -108,10 +108,6 @@ if(WITH_INPUT_NDOF) ) endif() -if(WITH_XDG_USER_DIRS) - add_definitions(-DWITH_XDG_USER_DIRS) -endif() - if(WITH_HEADLESS OR WITH_GHOST_SDL) if(WITH_HEADLESS) list(APPEND SRC diff --git a/intern/ghost/GHOST_ISystemPaths.h b/intern/ghost/GHOST_ISystemPaths.h index f610fde4582..ee8bd9d1eda 100644 --- a/intern/ghost/GHOST_ISystemPaths.h +++ b/intern/ghost/GHOST_ISystemPaths.h @@ -72,17 +72,17 @@ protected: public: /** * Determine the base dir in which shared resources are located. It will first try to use - * "unpack and run" path, then look for properly installed path, not including versioning. + * "unpack and run" path, then look for properly installed path, including versioning. * @return Unsigned char string pointing to system dir (eg /usr/share/blender/). */ - virtual const GHOST_TUns8 *getSystemDir() const = 0; + virtual const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const = 0; /** - * Determine the base dir in which user configuration is stored, not including versioning. + * Determine the base dir in which user configuration is stored, including versioning. * If needed, it will create the base directory. * @return Unsigned char string pointing to user dir (eg ~/.blender/). */ - virtual const GHOST_TUns8 *getUserDir() const = 0; + virtual const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const = 0; /** * Determine the directory of the current binary diff --git a/intern/ghost/GHOST_Path-api.h b/intern/ghost/GHOST_Path-api.h index 811f39bb023..a037f2e3760 100644 --- a/intern/ghost/GHOST_Path-api.h +++ b/intern/ghost/GHOST_Path-api.h @@ -55,16 +55,16 @@ extern GHOST_TSuccess GHOST_DisposeSystemPaths(void); /** * Determine the base dir in which shared resources are located. It will first try to use - * "unpack and run" path, then look for properly installed path, not including versioning. + * "unpack and run" path, then look for properly installed path, including versioning. * @return Unsigned char string pointing to system dir (eg /usr/share/blender/). */ -extern const GHOST_TUns8 *GHOST_getSystemDir(void); +extern const GHOST_TUns8 *GHOST_getSystemDir(int version, const char *versionstr); /** - * Determine the base dir in which user configuration is stored, not including versioning. + * Determine the base dir in which user configuration is stored, including versioning. * @return Unsigned char string pointing to user dir (eg ~). */ -extern const GHOST_TUns8 *GHOST_getUserDir(void); +extern const GHOST_TUns8 *GHOST_getUserDir(int version, const char *versionstr); /** diff --git a/intern/ghost/intern/GHOST_Path-api.cpp b/intern/ghost/intern/GHOST_Path-api.cpp index e92623352b4..2bc58517e75 100644 --- a/intern/ghost/intern/GHOST_Path-api.cpp +++ b/intern/ghost/intern/GHOST_Path-api.cpp @@ -45,16 +45,16 @@ GHOST_TSuccess GHOST_DisposeSystemPaths(void) return GHOST_ISystemPaths::dispose(); } -const GHOST_TUns8 *GHOST_getSystemDir() +const GHOST_TUns8 *GHOST_getSystemDir(int version, const char *versionstr) { GHOST_ISystemPaths *systemPaths = GHOST_ISystemPaths::get(); - return systemPaths ? systemPaths->getSystemDir() : 0; + return systemPaths ? systemPaths->getSystemDir(version, versionstr) : 0; } -const GHOST_TUns8 *GHOST_getUserDir() +const GHOST_TUns8 *GHOST_getUserDir(int version, const char *versionstr) { GHOST_ISystemPaths *systemPaths = GHOST_ISystemPaths::get(); - return systemPaths ? systemPaths->getUserDir() : 0; /* shouldn't be NULL */ + return systemPaths ? systemPaths->getUserDir(version, versionstr) : 0; /* shouldn't be NULL */ } const GHOST_TUns8 *GHOST_getBinaryDir() diff --git a/intern/ghost/intern/GHOST_SystemPaths.h b/intern/ghost/intern/GHOST_SystemPaths.h index a8c43ff7e09..75acbf885e3 100644 --- a/intern/ghost/intern/GHOST_SystemPaths.h +++ b/intern/ghost/intern/GHOST_SystemPaths.h @@ -52,17 +52,17 @@ public: /** * Determine the base dir in which shared resources are located. It will first try to use - * "unpack and run" path, then look for properly installed path, not including versioning. + * "unpack and run" path, then look for properly installed path, including versioning. * @return Unsigned char string pointing to system dir (eg /usr/share/blender/). */ - virtual const GHOST_TUns8 *getSystemDir() const = 0; + virtual const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const = 0; - /** - * Determine the base dir in which user configuration is stored, not including versioning. - * If needed, it will create the base directory. - * @return Unsigned char string pointing to user dir (eg ~/.blender/). - */ - virtual const GHOST_TUns8 *getUserDir() const = 0; + /** + * Determine the base dir in which user configuration is stored, including versioning. + * If needed, it will create the base directory. + * @return Unsigned char string pointing to user dir (eg ~/.blender/). + */ + virtual const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const = 0; /** * Determine the directory of the current binary diff --git a/intern/ghost/intern/GHOST_SystemPathsCarbon.cpp b/intern/ghost/intern/GHOST_SystemPathsCarbon.cpp index f4be03ac2f3..7d43392a79c 100644 --- a/intern/ghost/intern/GHOST_SystemPathsCarbon.cpp +++ b/intern/ghost/intern/GHOST_SystemPathsCarbon.cpp @@ -44,21 +44,23 @@ GHOST_SystemPathsCarbon::~GHOST_SystemPathsCarbon() { } -const GHOST_TUns8 *GHOST_SystemPathsCarbon::getSystemDir() const +const GHOST_TUns8 *GHOST_SystemPathsCarbon::getSystemDir(int, const char *versionstr) const { - return (GHOST_TUns8 *)"/Library/Application Support"; + static char systemPath[1024]; + + snprintf(systemPath, sizeof(systemPath), "/Library/Application Support/Blender/%s", versionstr); + + return (GHOST_TUns8*)systemPath; } -const GHOST_TUns8 *GHOST_SystemPathsCarbon::getUserDir() const +const GHOST_TUns8 *GHOST_SystemPathsCarbon::getUserDir(int, const char *versionstr) const { - static char usrPath[256] = ""; + static char usrPath[1024]; char *env = getenv("HOME"); if (env) { - strncpy(usrPath, env, 245); - usrPath[245] = 0; - strcat(usrPath, "/Library/Application Support"); - return (GHOST_TUns8 *) usrPath; + snprintf(usrPath, sizeof(usrPath), "%s/Library/Application Support/Blender/%s", env, versionstr); + return (GHOST_TUns8*)usrPath; } else return NULL; diff --git a/intern/ghost/intern/GHOST_SystemPathsCarbon.h b/intern/ghost/intern/GHOST_SystemPathsCarbon.h index c005f373726..6a94c1d6606 100644 --- a/intern/ghost/intern/GHOST_SystemPathsCarbon.h +++ b/intern/ghost/intern/GHOST_SystemPathsCarbon.h @@ -60,17 +60,17 @@ public: /** * Determine the base dir in which shared resources are located. It will first try to use - * "unpack and run" path, then look for properly installed path, not including versioning. + * "unpack and run" path, then look for properly installed path, including versioning. * @return Unsigned char string pointing to system dir (eg /usr/share/blender/). */ - virtual const GHOST_TUns8 *getSystemDir() const; + virtual const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const; /** - * Determine the base dir in which user configuration is stored, not including versioning. + * Determine the base dir in which user configuration is stored, including versioning. * If needed, it will create the base directory. * @return Unsigned char string pointing to user dir (eg ~/.blender/). */ - virtual const GHOST_TUns8 *getUserDir() const; + virtual const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const; /** * Determine the directory of the current binary diff --git a/intern/ghost/intern/GHOST_SystemPathsCocoa.h b/intern/ghost/intern/GHOST_SystemPathsCocoa.h index 77efbf2dd1b..ad44396c3ff 100644 --- a/intern/ghost/intern/GHOST_SystemPathsCocoa.h +++ b/intern/ghost/intern/GHOST_SystemPathsCocoa.h @@ -54,17 +54,17 @@ public: /** * Determine the base dir in which shared resources are located. It will first try to use - * "unpack and run" path, then look for properly installed path, not including versioning. + * "unpack and run" path, then look for properly installed path, including versioning. * @return Unsigned char string pointing to system dir (eg /usr/share/blender/). */ - virtual const GHOST_TUns8 *getSystemDir() const; + virtual const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const; /** - * Determine the base dir in which user configuration is stored, not including versioning. + * Determine the base dir in which user configuration is stored, including versioning. * If needed, it will create the base directory. * @return Unsigned char string pointing to user dir (eg ~/.blender/). */ - virtual const GHOST_TUns8 *getUserDir() const; + virtual const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const; /** * Determine the directory of the current binary diff --git a/intern/ghost/intern/GHOST_SystemPathsCocoa.mm b/intern/ghost/intern/GHOST_SystemPathsCocoa.mm index cce07c223e8..50ad91eeb99 100644 --- a/intern/ghost/intern/GHOST_SystemPathsCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemPathsCocoa.mm @@ -50,9 +50,9 @@ GHOST_SystemPathsCocoa::~GHOST_SystemPathsCocoa() #pragma mark Base directories retrieval -const GHOST_TUns8* GHOST_SystemPathsCocoa::getSystemDir() const +const GHOST_TUns8* GHOST_SystemPathsCocoa::getSystemDir(int, const char *versionstr) const { - static GHOST_TUns8 tempPath[512] = ""; + static char tempPath[512] = ""; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *basePath; NSArray *paths; @@ -66,15 +66,15 @@ const GHOST_TUns8* GHOST_SystemPathsCocoa::getSystemDir() const return NULL; } - strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]); + snprintf(tempPath, sizeof(tempPath), "%s/Blender/%s", [basePath cStringUsingEncoding:NSASCIIStringEncoding], versionstr); [pool drain]; - return tempPath; + return (GHOST_TUns8*)tempPath; } -const GHOST_TUns8* GHOST_SystemPathsCocoa::getUserDir() const +const GHOST_TUns8* GHOST_SystemPathsCocoa::getUserDir(int, const char *versionstr) const { - static GHOST_TUns8 tempPath[512] = ""; + static char tempPath[512] = ""; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *basePath; NSArray *paths; @@ -88,10 +88,10 @@ const GHOST_TUns8* GHOST_SystemPathsCocoa::getUserDir() const return NULL; } - strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]); + snprintf(tempPath, sizeof(tempPath), "%s/Blender/%s", [basePath cStringUsingEncoding:NSASCIIStringEncoding], versionstr); [pool drain]; - return tempPath; + return (GHOST_TUns8*)tempPath; } const GHOST_TUns8* GHOST_SystemPathsCocoa::getBinaryDir() const diff --git a/intern/ghost/intern/GHOST_SystemPathsWin32.cpp b/intern/ghost/intern/GHOST_SystemPathsWin32.cpp index ecf10463079..3a313c792d0 100644 --- a/intern/ghost/intern/GHOST_SystemPathsWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemPathsWin32.cpp @@ -69,9 +69,9 @@ GHOST_SystemPathsWin32::~GHOST_SystemPathsWin32() { } -const GHOST_TUns8 *GHOST_SystemPathsWin32::getSystemDir() const +const GHOST_TUns8 *GHOST_SystemPathsWin32::getSystemDir(int, const char *versionstr) const { - static char knownpath[MAX_PATH * 3] = {0}; /* 1 utf-16 might translante into 3 utf-8. 2 utf-16 translates into 4 utf-8*/ + static char knownpath[MAX_PATH * 3 + 128] = {0}; /* 1 utf-16 might translante into 3 utf-8. 2 utf-16 translates into 4 utf-8*/ wchar_t knownpath_16[MAX_PATH]; HRESULT hResult = SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath_16); @@ -79,15 +79,17 @@ const GHOST_TUns8 *GHOST_SystemPathsWin32::getSystemDir() const if (hResult == S_OK) { conv_utf_16_to_8(knownpath_16, knownpath, MAX_PATH * 3); - return (GHOST_TUns8 *)knownpath; + strcat(knownpath, "\\Blender Foundation\\Blender\\"); + strcat(knownpath, versionstr); + return (GHOST_TUns8*)knownpath; } return NULL; } -const GHOST_TUns8 *GHOST_SystemPathsWin32::getUserDir() const +const GHOST_TUns8 *GHOST_SystemPathsWin32::getUserDir(int, const char *versionstr) const { - static char knownpath[MAX_PATH * 3] = {0}; + static char knownpath[MAX_PATH * 3 + 128] = {0}; wchar_t knownpath_16[MAX_PATH]; HRESULT hResult = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath_16); @@ -95,7 +97,9 @@ const GHOST_TUns8 *GHOST_SystemPathsWin32::getUserDir() const if (hResult == S_OK) { conv_utf_16_to_8(knownpath_16, knownpath, MAX_PATH * 3); - return (GHOST_TUns8 *)knownpath; + strcat(knownpath, "\\Blender Foundation\\Blender\\"); + strcat(knownpath, versionstr); + return (GHOST_TUns8*)knownpath; } return NULL; diff --git a/intern/ghost/intern/GHOST_SystemPathsWin32.h b/intern/ghost/intern/GHOST_SystemPathsWin32.h index 133aa2cacab..3a243f8be16 100644 --- a/intern/ghost/intern/GHOST_SystemPathsWin32.h +++ b/intern/ghost/intern/GHOST_SystemPathsWin32.h @@ -64,17 +64,17 @@ public: /** * Determine the base dir in which shared resources are located. It will first try to use - * "unpack and run" path, then look for properly installed path, not including versioning. + * "unpack and run" path, then look for properly installed path, including versioning. * @return Unsigned char string pointing to system dir (eg /usr/share/). */ - const GHOST_TUns8 *getSystemDir() const; + const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const; /** - * Determine the base dir in which user configuration is stored, not including versioning. + * Determine the base dir in which user configuration is stored, including versioning. * If needed, it will create the base directory. * @return Unsigned char string pointing to user dir (eg ~/). */ - const GHOST_TUns8 *getUserDir() const; + const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const; /** * Determine the directory of the current binary diff --git a/intern/ghost/intern/GHOST_SystemPathsX11.cpp b/intern/ghost/intern/GHOST_SystemPathsX11.cpp index c148a16d5fc..95f82fe0e60 100644 --- a/intern/ghost/intern/GHOST_SystemPathsX11.cpp +++ b/intern/ghost/intern/GHOST_SystemPathsX11.cpp @@ -41,10 +41,8 @@ #include <stdio.h> // for fprintf only #include <cstdlib> // for exit -#ifdef WITH_XDG_USER_DIRS -# include <pwd.h> // for get home without use getenv() -# include <limits.h> // for PATH_MAX -#endif +#include <pwd.h> // for get home without use getenv() +#include <limits.h> // for PATH_MAX #ifdef PREFIX static const char *static_path = PREFIX "/share"; @@ -60,35 +58,51 @@ GHOST_SystemPathsX11::~GHOST_SystemPathsX11() { } -const GHOST_TUns8 *GHOST_SystemPathsX11::getSystemDir() const +const GHOST_TUns8 *GHOST_SystemPathsX11::getSystemDir(int, const char *versionstr) const { /* no prefix assumes a portable build which only uses bundled scripts */ - return (const GHOST_TUns8 *)static_path; + if(static_path) { + static char system_path[PATH_MAX]; + snprintf(system_path, sizeof(system_path), "%s/blender/%s", static_path, versionstr); + return (GHOST_TUns8*)system_path; + } + + return NULL; } -const GHOST_TUns8 *GHOST_SystemPathsX11::getUserDir() const +const GHOST_TUns8 *GHOST_SystemPathsX11::getUserDir(int version, const char *versionstr) const { -#ifndef WITH_XDG_USER_DIRS - return (const GHOST_TUns8 *)getenv("HOME"); -#else /* WITH_XDG_USER_DIRS */ - const char *home = getenv("XDG_CONFIG_HOME"); + static char user_path[PATH_MAX]; + + /* in blender 2.64, we migrate to XDG. to ensure the copy previous settings + * operator works we give a different path depending on the requested version */ + if(version < 264) { + const char *home = getenv("HOME"); - if (home) { - return (const GHOST_TUns8 *)home; + if(home) { + snprintf(user_path, sizeof(user_path), "%s/.blender/%s", home, versionstr); + return (GHOST_TUns8*)user_path; + } + + return NULL; } else { - static char user_path[PATH_MAX]; + const char *home= getenv("XDG_CONFIG_HOME"); + + if (home) { + snprintf(user_path, sizeof(user_path), "%s/blender/%s", home, versionstr); + } + else { + home= getenv("HOME"); - home = getenv("HOME"); + if (home == NULL) + home= getpwuid(getuid())->pw_dir; - if (home == NULL) { - home = getpwuid(getuid())->pw_dir; + snprintf(user_path, sizeof(user_path), "%s/.config/blender/%s", home, versionstr); } - snprintf(user_path, sizeof(user_path), "%s/.config", home); return (const GHOST_TUns8 *)user_path; } -#endif /* WITH_XDG_USER_DIRS */ } const GHOST_TUns8 *GHOST_SystemPathsX11::getBinaryDir() const diff --git a/intern/ghost/intern/GHOST_SystemPathsX11.h b/intern/ghost/intern/GHOST_SystemPathsX11.h index 8ded9a35276..db6d5a6c6ea 100644 --- a/intern/ghost/intern/GHOST_SystemPathsX11.h +++ b/intern/ghost/intern/GHOST_SystemPathsX11.h @@ -52,17 +52,17 @@ public: /** * Determine the base dir in which shared resources are located. It will first try to use - * "unpack and run" path, then look for properly installed path, not including versioning. + * "unpack and run" path, then look for properly installed path, including versioning. * @return Unsigned char string pointing to system dir (eg /usr/share/blender/). */ - const GHOST_TUns8 *getSystemDir() const; + const GHOST_TUns8 *getSystemDir(int version, const char *versionstr) const; /** - * Determine the base dir in which user configuration is stored, not including versioning. + * Determine the base dir in which user configuration is stored, including versioning. * If needed, it will create the base directory. * @return Unsigned char string pointing to user dir (eg ~/.blender/). */ - const GHOST_TUns8 *getUserDir() const; + const GHOST_TUns8 *getUserDir(int version, const char *versionstr) const; /** * Determine the directory of the current binary |