Patch [#22339] File/installation paths changes

Update after discussions on IRC:
* operating system specific path retrieval is moved back to GHOST, nothing blender specific here though
* cleaned up path functions a bit to remove #ifdefs
* removed Cocoa from blenlib again

TODO:
* Matt, Damien, please check and correct the functions for Cocoa and Carbon, could only put back existing code but needs adjustment
* finish GHOST_getBinaryDir - this should replace the BLI_where_am_i eventually as well as BLI_getInstallationPath on Windows and get_install_dir for the blenderplayer runtime
* It would probably be nice to define GHOST_getTempDir as well and move those out
* more cleanups...

NOTE:
Things are likely broken for macs
This commit is contained in:
Andrea Weikert 2010-07-04 21:14:59 +00:00
parent 83a2a4e5b8
commit 4135f1310c
17 changed files with 425 additions and 156 deletions

@ -42,6 +42,7 @@ SET(SRC
${CMAKE_CURRENT_SOURCE_DIR}/intern/GHOST_ISystem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/intern/GHOST_ModifierKeys.cpp
${CMAKE_CURRENT_SOURCE_DIR}/intern/GHOST_NDOFManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/intern/GHOST_Path-api.cpp
${CMAKE_CURRENT_SOURCE_DIR}/intern/GHOST_Rect.cpp
${CMAKE_CURRENT_SOURCE_DIR}/intern/GHOST_System.cpp
${CMAKE_CURRENT_SOURCE_DIR}/intern/GHOST_TimerManager.cpp

@ -370,7 +370,25 @@ public:
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0;
/**
* 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.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() 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 directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const = 0;
protected:
/**
* Initialize the system.

@ -0,0 +1,63 @@
/**
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2010 by Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef GHOST_PATH_API_H
#define GHOST_PATH_API_H
#include "GHOST_Types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* 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.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
extern const GHOST_TUns8* GHOST_getSystemDir();
/**
* 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/).
*/
extern const GHOST_TUns8* GHOST_getUserDir();
/**
* Determine the dir in which the binary file is found.
* @return Unsigned char string pointing to binary dir (eg ~/usr/local/bin/).
*/
extern const GHOST_TUns8* GHOST_getBinaryDir();
#ifdef __cplusplus
}
#endif
#endif

@ -0,0 +1,49 @@
/**
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2010 by Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
#include "intern/GHOST_Debug.h"
#include "GHOST_path-api.h"
#include "GHOST_ISystem.h"
const GHOST_TUns8* GHOST_getSystemDir()
{
GHOST_ISystem* system = GHOST_ISystem::getSystem();
return system->getSystemDir();
}
const GHOST_TUns8* GHOST_getUserDir()
{
GHOST_ISystem* system = GHOST_ISystem::getSystem();
return system->getUserDir();
}
const GHOST_TUns8* GHOST_getBinaryDir()
{
GHOST_ISystem* system = GHOST_ISystem::getSystem();
return system->getBinaryDir();
}

@ -297,6 +297,25 @@ public:
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0;
/**
* 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.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() 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 directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const = 0;
protected:
/**
* Initialize the system.

@ -1214,3 +1214,29 @@ void GHOST_SystemCarbon::putClipboard(GHOST_TInt8 *buffer, bool selection) const
CFRelease(textData);
}
}
const GHOST_TUns8* GHOST_SystemCarbon::getSystemDir() const
{
return (GHOST_TUns8*)"/Library/Application Support";
}
const GHOST_TUns8* GHOST_SystemCarbon::getUserDir() const
{
static char usrPath[256] = "";
char* env = getenv("HOME");
if (env) {
strncpy(usrPath, env, 245);
usrPath[245]=0;
strcat(usrPath, "/Library/Application Support");
return (GHOST_TUns8*) usrPath;
}
else
return NULL;
}
const GHOST_TUns8* GHOST_SystemCarbon::getBinaryDir() const
{
return NULL;
}

@ -190,6 +190,27 @@ public:
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* 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.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const;
/**
* 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;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const;
protected:
/**
* Initializes the system.

@ -213,6 +213,26 @@ public:
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* 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.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const;
/**
* 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;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const
/**
* Handles a window event. Called by GHOST_WindowCocoa window delegate
* @param eventType The type of window event

@ -1780,3 +1780,92 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
[pool drain];
}
#pragma mark Base directories retrieval
// TODO: this should only return base path, remove the appending of Blender or .blender
const GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSFileManager *fileManager;
NSString *basePath;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSLocalDomainMask, YES);
if ([paths count] > 0)
basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"];
else { //Fall back to standard unix path in case of issue
basePath = @"/usr/share/blender";
}
/* Ensure path exists, creates it if needed */
fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:basePath isDirectory:NULL]) {
[fileManager createDirectoryAtPath:basePath attributes:nil];
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}
// TODO: this should only return base path, remove the appending of Blenbder or .blender
const GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSFileManager *fileManager;
NSString *basePath;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([paths count] > 0)
basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"];
else { //Fall back to HOME in case of issue
basePath = [NSHomeDirectory() stringByAppendingPathComponent:@".blender"];
}
/* Ensure path exists, creates it if needed */
fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:basePath isDirectory:NULL]) {
[fileManager createDirectoryAtPath:basePath attributes:nil];
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}
// TODO: this is same as getUserDir for now
const GHOST_TUns8* GHOST_SystemCocoa::getBinaryDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSFileManager *fileManager;
NSString *basePath;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([paths count] > 0)
basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"];
else { //Fall back to HOME in case of issue
basePath = [NSHomeDirectory() stringByAppendingPathComponent:@".blender"];
}
/* Ensure path exists, creates it if needed */
fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:basePath isDirectory:NULL]) {
[fileManager createDirectoryAtPath:basePath attributes:nil];
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}

@ -88,6 +88,8 @@
#include "GHOST_WindowWin32.h"
#include "GHOST_NDOFManager.h"
#include <shlobj.h>
// Key code values not found in winuser.h
#ifndef VK_MINUS
#define VK_MINUS 0xBD
@ -1092,3 +1094,39 @@ void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, bool selection) const
return;
}
}
const GHOST_TUns8* GHOST_SystemWin32::getSystemDir() const
{
static char knownpath[MAX_PATH];
HRESULT hResult = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath);
if (hResult == S_OK)
{
return (GHOST_TUns8*)knownpath;
}
return NULL;
}
const GHOST_TUns8* GHOST_SystemWin32::getUserDir() const
{
static char knownpath[MAX_PATH];
HRESULT hResult = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath);
if (hResult == S_OK)
{
return (GHOST_TUns8*)knownpath;
}
return NULL;
}
const GHOST_TUns8* GHOST_SystemWin32::getBinaryDir() const
{
static char fullname[MAX_PATH];
if(GetModuleFileName(0, fullname, MAX_PATH)) {
return (GHOST_TUns8*)fullname;
}
return NULL;
}

@ -186,7 +186,26 @@ public:
* @return No return
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* 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.
* @return Unsigned char string pointing to system dir (eg /usr/share/).
*/
virtual const GHOST_TUns8* getSystemDir() const;
/**
* 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 ~/).
*/
virtual const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const;
/**
* Creates a drag'n'drop event and pushes it immediately onto the event queue.

@ -1458,3 +1458,23 @@ void GHOST_SystemX11::putClipboard(GHOST_TInt8 *buffer, bool selection) const
fprintf(stderr, "failed to own primary\n");
}
}
const GHOST_TUns8* GHOST_SystemX11::getSystemDir() const
{
return (GHOST_TUns8*)"/usr/share/";
}
const GHOST_TUns8* GHOST_SystemX11::getUserDir() const
{
char* env = getenv("HOME");
if(env) {
return (GHOST_TUns8*) env;
} else {
return NULL;
}
}
const GHOST_TUns8* GHOST_SystemX11::getBinaryDir() const
{
return NULL;
}

@ -226,6 +226,26 @@ public:
*/
void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* 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.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
const GHOST_TUns8* getSystemDir() const;
/**
* 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/).
*/
const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
const GHOST_TUns8* getBinaryDir() const
/**
* Atom used for ICCCM, WM-spec and Motif.
* We only need get this atom at the start, it's relative

@ -100,6 +100,11 @@ char *BLI_get_folder_create(int folder_id, char *subfolder);
#define BLENDER_BOOKMARK_FILE "bookmarks.txt"
#define BLENDER_HISTORY_FILE "recent-files.txt"
#ifdef WIN32
#define BLENDER_BASE_FORMAT "%s\\Blender Foundation\\Blender\\%s"
#else
#define BLENDER_BASE_FORMAT "%s/.blender/%s"
#endif
void BLI_setenv(const char *env, const char *val);
void BLI_setenv_if_new(const char *env, const char* val);

@ -33,10 +33,6 @@ SET(INC
${ZLIB_INC}
)
IF(APPLE)
SET(SRC ${SRC} intern/path_util_cocoa.mm)
ENDIF(APPLE)
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
SET(INC
${INC}

@ -46,8 +46,7 @@
#include "BKE_utildefines.h"
#include "BKE_blender.h" // BLENDER_VERSION
#include "GHOST_Path-api.h"
#ifdef WIN32
@ -916,7 +915,7 @@ char *BLI_gethome_folder(char *folder_name, int flag)
/* ************************************************************* */
/* ************************************************************* */
#define PATH_DEBUG2
// #define PATH_DEBUG2
static char *blender_version_decimal(void)
{
@ -1004,54 +1003,20 @@ static int get_path_local(char *targetpath, char *folder_name)
return 0;
}
#ifdef WIN32
static int get_knownfolder_path(char *path, int folder)
{
static char knownpath[MAXPATHLEN];
HRESULT hResult = SHGetFolderPath(NULL, folder, NULL, SHGFP_TYPE_CURRENT, knownpath);
if (hResult == S_OK)
{
if (BLI_exists(knownpath)) { /* from fop, also below... */
BLI_strncpy(path, knownpath, FILE_MAX);
return 1;
}
}
return 0;
}
#endif
#if defined(__APPLE__)
#ifndef WITH_COCOA
const char* BLI_osx_getBasePath(basePathesTypes pathType)
{
return "/tmp/";
}
#endif
#endif
static int get_path_user(char *targetpath, char *folder_name, char *envvar)
{
char user_path[FILE_MAX];
#if defined(WIN32)
char appdata[FILE_MAX];
#endif
const char *user_base_path;
user_path[0] = '\0';
if (test_env_path(targetpath, envvar))
return 1;
#if defined(__APPLE__)
BLI_snprintf(user_path, FILE_MAX, "%s/%s", BLI_osx_getBasePath(BasePath_BlenderUser), blender_version_decimal());
#elif defined(WIN32)
if (get_knownfolder_path(appdata, CSIDL_APPDATA)) {
BLI_snprintf(user_path, FILE_MAX, "%s\\Blender Foundation\\Blender\\%s", appdata, blender_version_decimal());
user_base_path = (const char *)GHOST_getUserDir();
if (user_base_path) {
BLI_snprintf(user_path, FILE_MAX, BLENDER_BASE_FORMAT, user_base_path, blender_version_decimal());
}
#else /* UNIX */
/* XXX example below - replace with OS API */
BLI_snprintf(user_path, FILE_MAX, "%s/.blender/%s", BLI_gethome(), blender_version_decimal());
#endif
if(!user_path[0])
return 0;
@ -1067,23 +1032,17 @@ static int get_path_user(char *targetpath, char *folder_name, char *envvar)
static int get_path_system(char *targetpath, char *folder_name, char *envvar)
{
char system_path[FILE_MAX];
#if defined(WIN32)
char appdata[FILE_MAX];
#endif
const char *system_base_path;
system_path[0] = '\0';
if (test_env_path(targetpath, envvar))
return 1;
#if defined(__APPLE__)
BLI_snprintf(system_path, FILE_MAX, "%s/%s", BLI_osx_getBasePath(BasePath_ApplicationBundle), blender_version_decimal());
#elif defined(WIN32)
if (get_knownfolder_path(appdata, CSIDL_COMMON_APPDATA)) {
BLI_snprintf(system_path, FILE_MAX, "%s\\Blender Foundation\\Blender\\%s", appdata, blender_version_decimal());
system_base_path = (const char *)GHOST_getSystemDir();
if (system_base_path) {
BLI_snprintf(system_path, FILE_MAX, BLENDER_BASE_FORMAT, system_base_path, blender_version_decimal());
}
#else /* UNIX */
/* XXX example below - replace with OS API */
BLI_snprintf(system_path, FILE_MAX, "/usr/share/blender/%s", blender_version_decimal());
#endif
if(!system_path[0])
return 0;

@ -1,94 +0,0 @@
/*
* $Id$
*
* Functions specific to osx that use API available only in Objective-C
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): Damien Plisson 2010
*
* ***** END GPL LICENSE BLOCK *****
*
*/
#import <Cocoa/Cocoa.h>
#include <string.h>
#include "BLI_path_util.h"
/**
* Gets the ~/Library/Application Data/Blender folder
*/
const char* BLI_osx_getBasePath(basePathesTypes pathType)
{
static char tempPath[512] = "";
NSAutoreleasePool *pool;
NSString *basePath;
NSArray *paths;
pool = [[NSAutoreleasePool alloc] init];
switch (pathType) {
/* Standard pathes */
case BasePath_Temporary:
strcpy(tempPath, [NSTemporaryDirectory() cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
break;
/* Blender specific pathes */
case BasePath_BlenderShared:
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSLocalDomainMask, YES);
if ([paths count] > 0)
basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"];
else { //Error
basePath = @"";
}
break;
case BasePath_BlenderUser:
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([paths count] > 0)
basePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Blender"];
else { //Error
basePath = @"";
}
break;
case BasePath_ApplicationBundle:
basePath = [[NSBundle mainBundle] bundlePath];
break;
default:
tempPath[0] = 0;
[pool drain];
return tempPath;
}
strcpy(tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}