From 4135f1310c145d8df5e1195e3205715ada8296cb Mon Sep 17 00:00:00 2001 From: Andrea Weikert Date: Sun, 4 Jul 2010 21:14:59 +0000 Subject: 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 --- intern/ghost/CMakeLists.txt | 1 + intern/ghost/GHOST_ISystem.h | 20 ++++++- intern/ghost/GHOST_Path-api.h | 63 +++++++++++++++++++++ intern/ghost/intern/GHOST_Path-api.cpp | 49 ++++++++++++++++ intern/ghost/intern/GHOST_System.h | 19 +++++++ intern/ghost/intern/GHOST_SystemCarbon.cpp | 26 +++++++++ intern/ghost/intern/GHOST_SystemCarbon.h | 21 +++++++ intern/ghost/intern/GHOST_SystemCocoa.h | 20 +++++++ intern/ghost/intern/GHOST_SystemCocoa.mm | 89 ++++++++++++++++++++++++++++++ intern/ghost/intern/GHOST_SystemWin32.cpp | 38 +++++++++++++ intern/ghost/intern/GHOST_SystemWin32.h | 21 ++++++- intern/ghost/intern/GHOST_SystemX11.cpp | 20 +++++++ intern/ghost/intern/GHOST_SystemX11.h | 20 +++++++ 13 files changed, 405 insertions(+), 2 deletions(-) create mode 100644 intern/ghost/GHOST_Path-api.h create mode 100644 intern/ghost/intern/GHOST_Path-api.cpp (limited to 'intern') diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt index fa630ce26f0..1a7627c9099 100644 --- a/intern/ghost/CMakeLists.txt +++ b/intern/ghost/CMakeLists.txt @@ -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 diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h index b4dc88369f4..47f142e4c8a 100644 --- a/intern/ghost/GHOST_ISystem.h +++ b/intern/ghost/GHOST_ISystem.h @@ -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. diff --git a/intern/ghost/GHOST_Path-api.h b/intern/ghost/GHOST_Path-api.h new file mode 100644 index 00000000000..6ad2415b46d --- /dev/null +++ b/intern/ghost/GHOST_Path-api.h @@ -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 \ No newline at end of file diff --git a/intern/ghost/intern/GHOST_Path-api.cpp b/intern/ghost/intern/GHOST_Path-api.cpp new file mode 100644 index 00000000000..4c9727223fc --- /dev/null +++ b/intern/ghost/intern/GHOST_Path-api.cpp @@ -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(); +} \ No newline at end of file diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h index 2b45bfb86cf..a18670738fe 100644 --- a/intern/ghost/intern/GHOST_System.h +++ b/intern/ghost/intern/GHOST_System.h @@ -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. diff --git a/intern/ghost/intern/GHOST_SystemCarbon.cpp b/intern/ghost/intern/GHOST_SystemCarbon.cpp index a4011f89de6..977745589eb 100644 --- a/intern/ghost/intern/GHOST_SystemCarbon.cpp +++ b/intern/ghost/intern/GHOST_SystemCarbon.cpp @@ -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; +} diff --git a/intern/ghost/intern/GHOST_SystemCarbon.h b/intern/ghost/intern/GHOST_SystemCarbon.h index fd5c61fd7b6..723652dc872 100644 --- a/intern/ghost/intern/GHOST_SystemCarbon.h +++ b/intern/ghost/intern/GHOST_SystemCarbon.h @@ -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. diff --git a/intern/ghost/intern/GHOST_SystemCocoa.h b/intern/ghost/intern/GHOST_SystemCocoa.h index e97f8c70521..0a0b900f72a 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.h +++ b/intern/ghost/intern/GHOST_SystemCocoa.h @@ -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 diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 00b00c69cee..b093510c700 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -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; +} diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index 41cbb72c9b9..2b26edea38d 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -88,6 +88,8 @@ #include "GHOST_WindowWin32.h" #include "GHOST_NDOFManager.h" +#include + // 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; +} \ No newline at end of file diff --git a/intern/ghost/intern/GHOST_SystemWin32.h b/intern/ghost/intern/GHOST_SystemWin32.h index 84fca33238f..888d9c0ab3e 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.h +++ b/intern/ghost/intern/GHOST_SystemWin32.h @@ -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. diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp index f286f8ae7d3..7644281bcea 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cpp +++ b/intern/ghost/intern/GHOST_SystemX11.cpp @@ -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; +} \ No newline at end of file diff --git a/intern/ghost/intern/GHOST_SystemX11.h b/intern/ghost/intern/GHOST_SystemX11.h index 6a4ff1b41c7..ab87b6b0fe2 100644 --- a/intern/ghost/intern/GHOST_SystemX11.h +++ b/intern/ghost/intern/GHOST_SystemX11.h @@ -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 -- cgit v1.2.3