From 195cc9c6a647a98cf0f8c760867233dfa2479357 Mon Sep 17 00:00:00 2001 From: Andrea Weikert Date: Wed, 5 Jan 2011 14:00:14 +0000 Subject: ToDo: long outstanding patch to allow access to system paths in background mode Thanks Damien Plisson for contributing the Carbon and Cocoa implementation --- intern/ghost/CMakeLists.txt | 10 ++ intern/ghost/GHOST_C-api.h | 1 - intern/ghost/GHOST_ISystem.h | 20 +--- intern/ghost/GHOST_ISystemPaths.h | 93 +++++++++++++++++ intern/ghost/GHOST_Path-api.h | 14 +++ intern/ghost/GHOST_Types.h | 2 + intern/ghost/SConscript | 2 +- intern/ghost/intern/GHOST_ISystemPaths.cpp | 104 ++++++++++++++++++ intern/ghost/intern/GHOST_Path-api.cpp | 25 +++-- intern/ghost/intern/GHOST_System.h | 20 +--- intern/ghost/intern/GHOST_SystemCarbon.cpp | 36 ------- intern/ghost/intern/GHOST_SystemCarbon.h | 21 ---- intern/ghost/intern/GHOST_SystemCocoa.h | 20 ---- intern/ghost/intern/GHOST_SystemCocoa.mm | 64 ------------ intern/ghost/intern/GHOST_SystemPaths.h | 74 +++++++++++++ intern/ghost/intern/GHOST_SystemPathsCarbon.cpp | 78 ++++++++++++++ intern/ghost/intern/GHOST_SystemPathsCarbon.h | 83 +++++++++++++++ intern/ghost/intern/GHOST_SystemPathsCocoa.h | 75 +++++++++++++ intern/ghost/intern/GHOST_SystemPathsCocoa.mm | 116 +++++++++++++++++++++ intern/ghost/intern/GHOST_SystemPathsWin32.cpp | 81 ++++++++++++++ intern/ghost/intern/GHOST_SystemPathsWin32.h | 82 +++++++++++++++ intern/ghost/intern/GHOST_SystemPathsX11.cpp | 76 ++++++++++++++ intern/ghost/intern/GHOST_SystemPathsX11.h | 73 +++++++++++++ intern/ghost/intern/GHOST_SystemWin32.cpp | 38 +------ intern/ghost/intern/GHOST_SystemWin32.h | 20 ---- intern/ghost/intern/GHOST_SystemX11.cpp | 19 ---- intern/ghost/intern/GHOST_SystemX11.h | 20 ---- intern/ghost/intern/Makefile | 2 +- source/blender/windowmanager/intern/wm_init_exit.c | 6 ++ 29 files changed, 990 insertions(+), 285 deletions(-) create mode 100644 intern/ghost/GHOST_ISystemPaths.h create mode 100644 intern/ghost/intern/GHOST_ISystemPaths.cpp create mode 100644 intern/ghost/intern/GHOST_SystemPaths.h create mode 100644 intern/ghost/intern/GHOST_SystemPathsCarbon.cpp create mode 100644 intern/ghost/intern/GHOST_SystemPathsCarbon.h create mode 100644 intern/ghost/intern/GHOST_SystemPathsCocoa.h create mode 100644 intern/ghost/intern/GHOST_SystemPathsCocoa.mm create mode 100644 intern/ghost/intern/GHOST_SystemPathsWin32.cpp create mode 100644 intern/ghost/intern/GHOST_SystemPathsWin32.h create mode 100644 intern/ghost/intern/GHOST_SystemPathsX11.cpp create mode 100644 intern/ghost/intern/GHOST_SystemPathsX11.h diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt index 7a147097cc7..7c2a2ddb870 100644 --- a/intern/ghost/CMakeLists.txt +++ b/intern/ghost/CMakeLists.txt @@ -36,10 +36,12 @@ set(SRC intern/GHOST_Buttons.cpp intern/GHOST_CallbackEventConsumer.cpp intern/GHOST_C-api.cpp + intern/GHOST_Path-api.cpp intern/GHOST_DisplayManager.cpp intern/GHOST_EventManager.cpp intern/GHOST_EventPrinter.cpp intern/GHOST_ISystem.cpp + intern/GHOST_ISystemPaths.cpp intern/GHOST_ModifierKeys.cpp intern/GHOST_NDOFManager.cpp intern/GHOST_Path-api.cpp @@ -87,20 +89,24 @@ if(APPLE) list(APPEND SRC intern/GHOST_DisplayManagerCocoa.mm intern/GHOST_SystemCocoa.mm + intern/GHOST_SystemPathsCocoa.mm intern/GHOST_WindowCocoa.mm intern/GHOST_DisplayManagerCocoa.h intern/GHOST_SystemCocoa.h + intern/GHOST_SystemPathsCocoa.h intern/GHOST_WindowCocoa.h ) else() list(APPEND SRC intern/GHOST_DisplayManagerCarbon.cpp intern/GHOST_SystemCarbon.cpp + intern/GHOST_SystemPathsCarbon.cpp intern/GHOST_WindowCarbon.cpp intern/GHOST_DisplayManagerCarbon.h intern/GHOST_SystemCarbon.h + intern/GHOST_SystemPathsCarbon.h intern/GHOST_WindowCarbon.h ) endif() @@ -115,10 +121,12 @@ elseif(UNIX) list(APPEND SRC intern/GHOST_DisplayManagerX11.cpp intern/GHOST_SystemX11.cpp + intern/GHOST_SystemPathsX11.cpp intern/GHOST_WindowX11.cpp intern/GHOST_DisplayManagerX11.h intern/GHOST_SystemX11.h + intern/GHOST_SystemPathsX11.h intern/GHOST_WindowX11.h ) @@ -134,12 +142,14 @@ elseif(WIN32) list(APPEND SRC intern/GHOST_DisplayManagerWin32.cpp intern/GHOST_SystemWin32.cpp + intern/GHOST_SystemPathsWin32.cpp intern/GHOST_WindowWin32.cpp intern/GHOST_DropTargetWin32.cpp intern/GHOST_DisplayManagerWin32.h intern/GHOST_DropTargetWin32.h intern/GHOST_SystemWin32.h + intern/GHOST_SystemPathsWin32.h intern/GHOST_WindowWin32.h ) endif() diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h index 8bee4c5230e..5d531ae3f75 100644 --- a/intern/ghost/GHOST_C-api.h +++ b/intern/ghost/GHOST_C-api.h @@ -46,7 +46,6 @@ extern "C" { * In the API the pointer is casted to the actual C++ class. * @param name Name of the handle to create. */ -#define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name GHOST_DECLARE_HANDLE(GHOST_SystemHandle); GHOST_DECLARE_HANDLE(GHOST_TimerTaskHandle); diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h index 227ba4448c3..ec39248e366 100644 --- a/intern/ghost/GHOST_ISystem.h +++ b/intern/ghost/GHOST_ISystem.h @@ -370,25 +370,7 @@ 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_ISystemPaths.h b/intern/ghost/GHOST_ISystemPaths.h new file mode 100644 index 00000000000..a4bb94229e0 --- /dev/null +++ b/intern/ghost/GHOST_ISystemPaths.h @@ -0,0 +1,93 @@ +/** + * $Id: $ + * + * ***** 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) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef _GHOST_ISYSTEMPATHS_H_ +#define _GHOST_ISYSTEMPATHS_H_ + +#include "GHOST_Types.h" + +class GHOST_ISystemPaths +{ +public: + /** + * Creates the one and only system. + * @return An indication of success. + */ + static GHOST_TSuccess create(); + + /** + * Disposes the one and only system. + * @return An indication of success. + */ + static GHOST_TSuccess dispose(); + + /** + * Returns a pointer to the one and only system (nil if it hasn't been created). + * @return A pointer to the system. + */ + static GHOST_ISystemPaths* get(); + +protected: + /** + * Constructor. + * Protected default constructor to force use of static createSystem member. + */ + GHOST_ISystemPaths() {} + + /** + * Destructor. + * Protected default constructor to force use of static dispose member. + */ + virtual ~GHOST_ISystemPaths() {} + +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. + * @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; + +private: + /** The one and only system paths*/ + static GHOST_ISystemPaths* m_systemPaths; +}; + +#endif diff --git a/intern/ghost/GHOST_Path-api.h b/intern/ghost/GHOST_Path-api.h index 60b05f55b90..23a50623fb7 100644 --- a/intern/ghost/GHOST_Path-api.h +++ b/intern/ghost/GHOST_Path-api.h @@ -36,6 +36,20 @@ extern "C" { #endif +GHOST_DECLARE_HANDLE(GHOST_SystemPathsHandle); + +/** + * Creates the one and only instance of the system path access. + * @return An indication of success. + */ +extern GHOST_TSuccess GHOST_CreateSystemPaths(void); + +/** + * Disposes the one and only system. + * @return An indication of success. + */ +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. diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h index dd7b0527bf8..af17b10bf00 100644 --- a/intern/ghost/GHOST_Types.h +++ b/intern/ghost/GHOST_Types.h @@ -33,6 +33,8 @@ #include "MEM_guardedalloc.h" #endif +#define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name + typedef char GHOST_TInt8; typedef unsigned char GHOST_TUns8; typedef short GHOST_TInt16; diff --git a/intern/ghost/SConscript b/intern/ghost/SConscript index e6190c50577..7aedc08ce96 100644 --- a/intern/ghost/SConscript +++ b/intern/ghost/SConscript @@ -11,7 +11,7 @@ if window_system == 'darwin': sources += env.Glob('intern/*.mm') -pf = ['GHOST_DisplayManager', 'GHOST_System', 'GHOST_Window', 'GHOST_DropTarget'] +pf = ['GHOST_DisplayManager', 'GHOST_System', 'GHOST_SystemPaths', 'GHOST_Window', 'GHOST_DropTarget'] defs=['_USE_MATH_DEFINES'] if window_system in ('linux2', 'openbsd3', 'sunos5', 'freebsd7', 'freebsd8', 'freebsd9', 'irix6', 'aix4', 'aix5'): diff --git a/intern/ghost/intern/GHOST_ISystemPaths.cpp b/intern/ghost/intern/GHOST_ISystemPaths.cpp new file mode 100644 index 00000000000..5241cbbf197 --- /dev/null +++ b/intern/ghost/intern/GHOST_ISystemPaths.cpp @@ -0,0 +1,104 @@ +/** + * $Id: GHOST_ISystem.cpp 28254 2010-04-18 10:28:37Z campbellbarton $ + * ***** 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) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** + + * $Id: GHOST_ISystem.cpp 28254 2010-04-18 10:28:37Z campbellbarton $ + * Copyright (C) 2001 NaN Technologies B.V. + * @author Maarten Gribnau + * @date May 7, 2001 + */ + +#include "GHOST_ISystemPaths.h" + +#ifdef WIN32 +# include "GHOST_SystemPathsWin32.h" +#else +# ifdef __APPLE__ +# ifdef GHOST_COCOA +# include "GHOST_SystemPathsCocoa.h" +# else +# include "GHOST_SystemPathsCarbon.h" +# endif +# else +# include "GHOST_SystemPathsX11.h" +# endif +#endif + + +GHOST_ISystemPaths* GHOST_ISystemPaths::m_systemPaths = 0; + + +GHOST_TSuccess GHOST_ISystemPaths::create() +{ + GHOST_TSuccess success; + if (!m_systemPaths) { +#ifdef WIN32 + m_systemPaths = new GHOST_SystemPathsWin32 (); +#else +# ifdef __APPLE__ +# ifdef GHOST_COCOA + m_systemPaths = new GHOST_SystemPathsCocoa (); +# else + m_systemPaths = new GHOST_SystemPathsarbon (); +# endif +# else + m_systemPaths = new GHOST_SystemPathsX11 (); +# endif +#endif + success = m_systemPaths != 0 ? GHOST_kSuccess : GHOST_kFailure; + } + else { + success = GHOST_kFailure; + } + return success; +} + +GHOST_TSuccess GHOST_ISystemPaths::dispose() +{ + GHOST_TSuccess success = GHOST_kSuccess; + if (m_systemPaths) { + delete m_systemPaths; + m_systemPaths = 0; + } + else { + success = GHOST_kFailure; + } + return success; +} + +GHOST_ISystemPaths* GHOST_ISystemPaths::get() +{ + if (!m_systemPaths) { + create(); + } + return m_systemPaths; +} + + + diff --git a/intern/ghost/intern/GHOST_Path-api.cpp b/intern/ghost/intern/GHOST_Path-api.cpp index b2b7c68e998..adb8a7d0b97 100644 --- a/intern/ghost/intern/GHOST_Path-api.cpp +++ b/intern/ghost/intern/GHOST_Path-api.cpp @@ -28,23 +28,34 @@ */ #include "intern/GHOST_Debug.h" +#include "GHOST_Types.h" #include "GHOST_Path-api.h" -#include "GHOST_ISystem.h" +#include "GHOST_ISystemPaths.h" + +GHOST_TSuccess GHOST_CreateSystemPaths(void) +{ + return GHOST_ISystemPaths::create();; +} + +GHOST_TSuccess GHOST_DisposeSystemPaths(void) +{ + return GHOST_ISystemPaths::dispose(); +} const GHOST_TUns8* GHOST_getSystemDir() { - GHOST_ISystem* system = GHOST_ISystem::getSystem(); - return system ? system->getSystemDir() : NULL; + GHOST_ISystemPaths* systemPaths = GHOST_ISystemPaths::get(); + return systemPaths ? systemPaths->getSystemDir() : 0; } const GHOST_TUns8* GHOST_getUserDir() { - GHOST_ISystem* system = GHOST_ISystem::getSystem(); - return system ? system->getUserDir() : NULL; /* will be NULL in background mode */ + GHOST_ISystemPaths* systemPaths = GHOST_ISystemPaths::get(); + return systemPaths ? systemPaths->getUserDir() : 0; /* shouldn't be NULL */ } const GHOST_TUns8* GHOST_getBinaryDir() { - GHOST_ISystem* system = GHOST_ISystem::getSystem(); - return system ? system->getBinaryDir() : NULL; /* will be NULL in background mode */ + GHOST_ISystemPaths* systemPaths = GHOST_ISystemPaths::get(); + return systemPaths ? systemPaths->getBinaryDir() : 0; /* shouldn't be NULL */ } diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h index a18670738fe..d9b901235ca 100644 --- a/intern/ghost/intern/GHOST_System.h +++ b/intern/ghost/intern/GHOST_System.h @@ -297,25 +297,7 @@ 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 75cbe5db574..0cd11f676b0 100644 --- a/intern/ghost/intern/GHOST_SystemCarbon.cpp +++ b/intern/ghost/intern/GHOST_SystemCarbon.cpp @@ -1214,39 +1214,3 @@ 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 -{ - CFURLRef bundleURL; - CFStringRef pathStr; - static char path[256]; - CFBundleRef mainBundle = CFBundleGetMainBundle(); - - bundleURL = CFBundleCopyBundleURL(mainBundle); - pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle); - CFStringGetCString(pathStr, path, 255, kCFStringEncodingASCII); - CFRelease(pathStr); - CFRelease(bundleURL); - return (GHOST_TUns8*)path; -} diff --git a/intern/ghost/intern/GHOST_SystemCarbon.h b/intern/ghost/intern/GHOST_SystemCarbon.h index 723652dc872..fd5c61fd7b6 100644 --- a/intern/ghost/intern/GHOST_SystemCarbon.h +++ b/intern/ghost/intern/GHOST_SystemCarbon.h @@ -190,27 +190,6 @@ 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 3ae8ec02dda..ffc9a6bbfb7 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.h +++ b/intern/ghost/intern/GHOST_SystemCocoa.h @@ -213,26 +213,6 @@ 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 80356c19c9b..08d83565e5c 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -1796,67 +1796,3 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const [pool drain]; } -#pragma mark Base directories retrieval - -const GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const -{ - static GHOST_TUns8 tempPath[512] = ""; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *basePath; - NSArray *paths; - - paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSLocalDomainMask, YES); - - if ([paths count] > 0) - basePath = [paths objectAtIndex:0]; - else { - [pool drain]; - return NULL; - } - - strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]); - - [pool drain]; - return tempPath; -} - -const GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const -{ - static GHOST_TUns8 tempPath[512] = ""; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *basePath; - NSArray *paths; - - paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); - - if ([paths count] > 0) - basePath = [paths objectAtIndex:0]; - else { - [pool drain]; - return NULL; - } - - strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]); - - [pool drain]; - return tempPath; -} - -const GHOST_TUns8* GHOST_SystemCocoa::getBinaryDir() const -{ - static GHOST_TUns8 tempPath[512] = ""; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *basePath; - - basePath = [[NSBundle mainBundle] bundlePath]; - - if (basePath == nil) { - [pool drain]; - return NULL; - } - - strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]); - - [pool drain]; - return tempPath; -} diff --git a/intern/ghost/intern/GHOST_SystemPaths.h b/intern/ghost/intern/GHOST_SystemPaths.h new file mode 100644 index 00000000000..526a39e45f1 --- /dev/null +++ b/intern/ghost/intern/GHOST_SystemPaths.h @@ -0,0 +1,74 @@ +/** + * $Id: $ + * + * ***** 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) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef _GHOST_SYSTEMPATHS_H_ +#define _GHOST_SYSTEMPATHS_H_ + +#include "GHOST_ISystemPaths.h" + +class GHOST_SystemPaths : public GHOST_ISystemPaths +{ +protected: + /** + * Constructor. + * Protected default constructor to force use of static createSystem member. + */ + GHOST_SystemPaths(){}; + + /** + * Destructor. + * Protected default constructor to force use of static dispose member. + */ + virtual ~GHOST_SystemPaths(){}; + +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. + * @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; + +}; + +#endif + + diff --git a/intern/ghost/intern/GHOST_SystemPathsCarbon.cpp b/intern/ghost/intern/GHOST_SystemPathsCarbon.cpp new file mode 100644 index 00000000000..d35ab6e311f --- /dev/null +++ b/intern/ghost/intern/GHOST_SystemPathsCarbon.cpp @@ -0,0 +1,78 @@ +/** + * $Id: $ + * + * ***** 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) 2009 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Damien Plisson 2010 + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include +#include +#include "GHOST_SystemPathsCarbon.h" + + +/***/ + +GHOST_SystemPathsCarbon::GHOST_SystemPathsCarbon() +{ +} + +GHOST_SystemPathsCarbon::~GHOST_SystemPathsCarbon() +{ +} + +const GHOST_TUns8* GHOST_SystemPathsCarbon::getSystemDir() const +{ + return (GHOST_TUns8*)"/Library/Application Support"; +} + +const GHOST_TUns8* GHOST_SystemPathsCarbon::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_SystemPathsCarbon::getBinaryDir() const +{ + CFURLRef bundleURL; + CFStringRef pathStr; + static char path[256]; + CFBundleRef mainBundle = CFBundleGetMainBundle(); + + bundleURL = CFBundleCopyBundleURL(mainBundle); + pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle); + CFStringGetCString(pathStr, path, 255, kCFStringEncodingASCII); + CFRelease(pathStr); + CFRelease(bundleURL); + return (GHOST_TUns8*)path; +} + diff --git a/intern/ghost/intern/GHOST_SystemPathsCarbon.h b/intern/ghost/intern/GHOST_SystemPathsCarbon.h new file mode 100644 index 00000000000..f50e66a7f9e --- /dev/null +++ b/intern/ghost/intern/GHOST_SystemPathsCarbon.h @@ -0,0 +1,83 @@ +/** + * $Id: $ + * + * ***** 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 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Damien Plisson 2010 + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef _GHOST_SYSTEM_PATHS_CARBON_H_ +#define _GHOST_SYSTEM_PATHS_CARBON_H_ + +#ifndef __APPLE__ +#error Apple OSX only! +#endif // __APPLE__ + +#include + +#include "GHOST_SystemPaths.h" + +/** + * OSX/Carbon Implementation of GHOST_SystemPaths class. + * @see GHOST_System. + * @author Andrea Weikert + * @date Aug 1, 2010 + */ +class GHOST_SystemPathsCarbon : public GHOST_SystemPaths { +public: + /** + * Constructor. + */ + GHOST_SystemPathsCarbon(); + + /** + * Destructor. + */ + ~GHOST_SystemPathsCarbon(); + + /** + * 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; + +}; + +#endif // _GHOST_SYSTEM_CARBON_H_ + + + diff --git a/intern/ghost/intern/GHOST_SystemPathsCocoa.h b/intern/ghost/intern/GHOST_SystemPathsCocoa.h new file mode 100644 index 00000000000..59909d9fdd7 --- /dev/null +++ b/intern/ghost/intern/GHOST_SystemPathsCocoa.h @@ -0,0 +1,75 @@ +/** + * $Id: $ + * + * ***** 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 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Damien Plisson 2010 + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef _GHOST_SYSTEM_PATHS_COCOA_H_ +#define _GHOST_SYSTEM_PATHS_COCOA_H_ + +#ifndef __APPLE__ +#error Apple OSX only! +#endif // __APPLE__ + + +#include "GHOST_SystemPaths.h" + + +class GHOST_SystemPathsCocoa : public GHOST_SystemPaths { +public: + /** + * Constructor. + */ + GHOST_SystemPathsCocoa(); + + /** + * Destructor. + */ + ~GHOST_SystemPathsCocoa(); + + /** + * 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; + +}; + +#endif // _GHOST_SYSTEM_COCOA_H_ + diff --git a/intern/ghost/intern/GHOST_SystemPathsCocoa.mm b/intern/ghost/intern/GHOST_SystemPathsCocoa.mm new file mode 100644 index 00000000000..d12ad6fb978 --- /dev/null +++ b/intern/ghost/intern/GHOST_SystemPathsCocoa.mm @@ -0,0 +1,116 @@ +/** + * $Id: $ + * + * ***** 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 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Damien Plisson 2010 + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#import + +/*For the currently not ported to Cocoa keyboard layout functions (64bit & 10.6 compatible)*/ +#include + +#include +#include +#include + +#include "GHOST_SystemPathsCocoa.h" + + +#pragma mark initialization/finalization + + +GHOST_SystemPathsCocoa::GHOST_SystemPathsCocoa() +{ +} + +GHOST_SystemPathsCocoa::~GHOST_SystemPathsCocoa() +{ +} + + +#pragma mark Base directories retrieval + +const GHOST_TUns8* GHOST_SystemPathsCocoa::getSystemDir() const +{ + static GHOST_TUns8 tempPath[512] = ""; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSString *basePath; + NSArray *paths; + + paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSLocalDomainMask, YES); + + if ([paths count] > 0) + basePath = [paths objectAtIndex:0]; + else { + [pool drain]; + return NULL; + } + + strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]); + + [pool drain]; + return tempPath; +} + +const GHOST_TUns8* GHOST_SystemPathsCocoa::getUserDir() const +{ + static GHOST_TUns8 tempPath[512] = ""; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSString *basePath; + NSArray *paths; + + paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); + + if ([paths count] > 0) + basePath = [paths objectAtIndex:0]; + else { + [pool drain]; + return NULL; + } + + strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]); + + [pool drain]; + return tempPath; +} + +const GHOST_TUns8* GHOST_SystemPathsCocoa::getBinaryDir() const +{ + static GHOST_TUns8 tempPath[512] = ""; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSString *basePath; + + basePath = [[NSBundle mainBundle] bundlePath]; + + if (basePath == nil) { + [pool drain]; + return NULL; + } + + strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]); + + [pool drain]; + return tempPath; +} diff --git a/intern/ghost/intern/GHOST_SystemPathsWin32.cpp b/intern/ghost/intern/GHOST_SystemPathsWin32.cpp new file mode 100644 index 00000000000..99467689a7a --- /dev/null +++ b/intern/ghost/intern/GHOST_SystemPathsWin32.cpp @@ -0,0 +1,81 @@ +/** + * $Id: GHOST_SystemWin32.cpp 30060 2010-07-06 20:31:55Z elubie $ + * ***** 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) 2011 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Blender Foundation + * Andrea Weikert + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "GHOST_SystemPathsWin32.h" + +#define WIN32_LEAN_AND_MEAN +#ifdef _WIN32_IE +#undef _WIN32_IE +#endif +#define _WIN32_IE 0x0501 +#include +#include + + +GHOST_SystemPathsWin32::GHOST_SystemPathsWin32() +{ +} + +GHOST_SystemPathsWin32::~GHOST_SystemPathsWin32() +{ +} + +const GHOST_TUns8* GHOST_SystemPathsWin32::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_SystemPathsWin32::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_SystemPathsWin32::getBinaryDir() const +{ + static char fullname[MAX_PATH]; + if(GetModuleFileName(0, fullname, MAX_PATH)) { + return (GHOST_TUns8*)fullname; + } + + return NULL; +} diff --git a/intern/ghost/intern/GHOST_SystemPathsWin32.h b/intern/ghost/intern/GHOST_SystemPathsWin32.h new file mode 100644 index 00000000000..c4abfbb235b --- /dev/null +++ b/intern/ghost/intern/GHOST_SystemPathsWin32.h @@ -0,0 +1,82 @@ +/** + * $Id: $ + * ***** 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) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef _GHOST_SYSTEM_PATHS_WIN32_H_ +#define _GHOST_SYSTEM_PATHS_WIN32_H_ + +#ifndef WIN32 +#error WIN32 only! +#endif // WIN32 + +#include + +#include "GHOST_SystemPaths.h" + + +/** + * WIN32 Implementation of GHOST_SystemPaths class. + * @see GHOST_SystemPaths. + * @author Andrea Weikert + * @date August 1, 2010 + */ +class GHOST_SystemPathsWin32 : public GHOST_SystemPaths { +public: + /** + * Constructor. + */ + GHOST_SystemPathsWin32(); + + /** + * Destructor. + */ + virtual ~GHOST_SystemPathsWin32(); + + /** + * 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/). + */ + 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 ~/). + */ + 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; + +}; + +#endif // _GHOST_SYSTEM_PATHS_WIN32_H_ + diff --git a/intern/ghost/intern/GHOST_SystemPathsX11.cpp b/intern/ghost/intern/GHOST_SystemPathsX11.cpp new file mode 100644 index 00000000000..0f0578f4ef5 --- /dev/null +++ b/intern/ghost/intern/GHOST_SystemPathsX11.cpp @@ -0,0 +1,76 @@ +/** + * $Id: $ + * + * ***** 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 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "GHOST_SystemPathsX11.h" + +#include "GHOST_Debug.h" + +// For timing + +#include +#include + +#include // for fprintf only +#include // for exit + +#ifndef PREFIX +# define PREFIX "/usr/local" +#endif + + +using namespace std; + +GHOST_SystemPathsX11::GHOST_SystemPathsX11() +{ +} + +GHOST_SystemPathsX11::~GHOST_SystemPathsX11() +{ +} + +const GHOST_TUns8* GHOST_SystemPathsX11::getSystemDir() const +{ + return (GHOST_TUns8*) PREFIX "/share"; +} + +const GHOST_TUns8* GHOST_SystemPathsX11::getUserDir() const +{ + char* env = getenv("HOME"); + if(env) { + return (GHOST_TUns8*) env; + } else { + return NULL; + } +} + +const GHOST_TUns8* GHOST_SystemPathsX11::getBinaryDir() const +{ + return NULL; +} + + diff --git a/intern/ghost/intern/GHOST_SystemPathsX11.h b/intern/ghost/intern/GHOST_SystemPathsX11.h new file mode 100644 index 00000000000..f4b7dda4e60 --- /dev/null +++ b/intern/ghost/intern/GHOST_SystemPathsX11.h @@ -0,0 +1,73 @@ +/** + * $Id: $ + * + * ***** 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 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef _GHOST_SYSTEM_PATHS_X11_H_ +#define _GHOST_SYSTEM_PATHS_X11_H_ + +#include "GHOST_SystemPaths.h" +#include "../GHOST_Types.h" + + +class GHOST_SystemPathsX11 : public GHOST_SystemPaths { +public: + + /** + * Constructor + * this class should only be instanciated by GHOST_ISystem. + */ + GHOST_SystemPathsX11(); + + /** + * Destructor. + */ + virtual ~GHOST_SystemPathsX11(); + + /** + * 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; + +}; + +#endif + diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index a458d2dc504..df968d30cb1 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -851,7 +851,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, * specifies a character code generated by a dead key. A dead key is a key that * generates a character, such as the umlaut (double-dot), that is combined with * another character to form a composite character. For example, the umlaut-O - * character (Ö) is generated by typing the dead key for the umlaut character, and + * character (Ö) is generated by typing the dead key for the umlaut character, and * then typing the O key. */ case WM_SYSDEADCHAR: @@ -1209,39 +1209,3 @@ 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; -} diff --git a/intern/ghost/intern/GHOST_SystemWin32.h b/intern/ghost/intern/GHOST_SystemWin32.h index bda0c9fb9be..29f4e64efa0 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.h +++ b/intern/ghost/intern/GHOST_SystemWin32.h @@ -187,26 +187,6 @@ 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/). - */ - 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. * Called by GHOST_DropTargetWin32 class. diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp index 5f7c59fa5e6..5e63cc4d10f 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cpp +++ b/intern/ghost/intern/GHOST_SystemX11.cpp @@ -1476,23 +1476,4 @@ void GHOST_SystemX11::putClipboard(GHOST_TInt8 *buffer, bool selection) const } } -const GHOST_TUns8* GHOST_SystemX11::getSystemDir() const -{ - return (GHOST_TUns8*) PREFIX "/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; -} diff --git a/intern/ghost/intern/GHOST_SystemX11.h b/intern/ghost/intern/GHOST_SystemX11.h index 13ad4200ab8..6a4ff1b41c7 100644 --- a/intern/ghost/intern/GHOST_SystemX11.h +++ b/intern/ghost/intern/GHOST_SystemX11.h @@ -226,26 +226,6 @@ 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 diff --git a/intern/ghost/intern/Makefile b/intern/ghost/intern/Makefile index a251ce26b31..016577f4e80 100644 --- a/intern/ghost/intern/Makefile +++ b/intern/ghost/intern/Makefile @@ -35,7 +35,7 @@ DIR = $(OCGDIR)/intern/$(LIBNAME) CCSRCS = GHOST_Buttons.cpp GHOST_System.cpp GHOST_Window.cpp CCSRCS += GHOST_EventManager.cpp GHOST_EventPrinter.cpp GHOST_WindowManager.cpp -CCSRCS += GHOST_ISystem.cpp GHOST_ModifierKeys.cpp GHOST_TimerManager.cpp +CCSRCS += GHOST_ISystem.cpp GHOST_ISystemPaths.cpp GHOST_ModifierKeys.cpp GHOST_TimerManager.cpp CCSRCS += GHOST_Rect.cpp GHOST_DisplayManager.cpp GHOST_C-api.cpp CCSRCS += GHOST_CallbackEventConsumer.cpp CCSRCS += GHOST_NDOFManager.cpp GHOST_Path-api.cpp diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 7eefacca2c6..89a7598038a 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -68,6 +68,7 @@ #ifdef WITH_GAMEENGINE #include "SYS_System.h" #endif +#include "GHOST_Path-api.h" #include "RNA_define.h" @@ -118,6 +119,8 @@ void WM_init(bContext *C, int argc, char **argv) wm_ghost_init(C); /* note: it assigns C to ghost! */ wm_init_cursor_data(); } + GHOST_CreateSystemPaths(); + wm_operatortype_init(); set_free_windowmanager_cb(wm_close_and_free); /* library.c */ @@ -443,6 +446,9 @@ void WM_exit(bContext *C) #ifdef WITH_GAMEENGINE SYS_DeleteSystem(SYS_GetSystem()); #endif + + GHOST_DisposeSystemPaths(); + if(MEM_get_memory_blocks_in_use()!=0) { printf("Error Totblock: %d\n", MEM_get_memory_blocks_in_use()); MEM_printmemlist(); -- cgit v1.2.3