System dependent standard directory retrieval functions update : return const strings...
authorDamien Plisson <damien.plisson@yahoo.fr>
Sat, 27 Feb 2010 17:03:46 +0000 (17:03 +0000)
committerDamien Plisson <damien.plisson@yahoo.fr>
Sat, 27 Feb 2010 17:03:46 +0000 (17:03 +0000)
and plug them into wip BLI_bfile.c to replace the hardcoded paths

17 files changed:
intern/ghost/GHOST_C-api.h
intern/ghost/GHOST_ISystem.h
intern/ghost/intern/GHOST_C-api.cpp
intern/ghost/intern/GHOST_System.h
intern/ghost/intern/GHOST_SystemCarbon.cpp
intern/ghost/intern/GHOST_SystemCarbon.h
intern/ghost/intern/GHOST_SystemCocoa.h
intern/ghost/intern/GHOST_SystemCocoa.mm
intern/ghost/intern/GHOST_SystemWin32.cpp
intern/ghost/intern/GHOST_SystemWin32.h
intern/ghost/intern/GHOST_SystemX11.cpp
intern/ghost/intern/GHOST_SystemX11.h
intern/ghost/intern/GHOST_WindowCarbon.cpp
source/blender/blenlib/CMakeLists.txt
source/blender/blenlib/SConscript
source/blender/blenlib/intern/BLI_bfile.c
source/blender/blenlib/intern/Makefile

index 75a0550..346fa29 100644 (file)
@@ -824,14 +824,14 @@ extern void GHOST_putClipboard(GHOST_TInt8 *buffer, int selection);
  * "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 GHOST_TUns8* GHOST_getSystemDir();
+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 GHOST_TUns8* GHOST_getUserDir();
+extern const GHOST_TUns8* GHOST_getUserDir();
 
 
 #ifdef __cplusplus
index 5e0c7f4..fd8641f 100644 (file)
@@ -380,14 +380,14 @@ public:
         * "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 GHOST_TUns8* getSystemDir() const = 0;
+       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 GHOST_TUns8* getUserDir() const = 0;
+       virtual const GHOST_TUns8* getUserDir() const = 0;
 
 protected:
        /**
index fd06d76..51305e8 100644 (file)
@@ -855,13 +855,13 @@ void GHOST_putClipboard(GHOST_TInt8 *buffer, int selection)
        system->putClipboard(buffer, selection);
 }
 
-GHOST_TUns8* GHOST_getSystemDir()
+const GHOST_TUns8* GHOST_getSystemDir()
 {
        GHOST_ISystem* system = GHOST_ISystem::getSystem();
        return system->getSystemDir();
 }
 
-GHOST_TUns8* GHOST_getUserDir()
+const GHOST_TUns8* GHOST_getUserDir()
 {
        GHOST_ISystem* system = GHOST_ISystem::getSystem();
        return system->getUserDir();
index 59f933e..d6c6a35 100644 (file)
@@ -302,14 +302,14 @@ public:
         * "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 GHOST_TUns8* getSystemDir() const = 0;
+       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 GHOST_TUns8* getUserDir() const = 0;
+       virtual const GHOST_TUns8* getUserDir() const = 0;
 
 protected:
        /**
index 52b797f..36ea1c7 100644 (file)
@@ -809,7 +809,7 @@ OSStatus GHOST_SystemCarbon::handleTabletEvent(EventRef event)
                }
        err = noErr;
        }
-
+       return err;
 }
 
 OSStatus GHOST_SystemCarbon::handleMouseEvent(EventRef event)
@@ -1215,22 +1215,19 @@ void GHOST_SystemCarbon::putClipboard(GHOST_TInt8 *buffer, bool selection) const
        }
 }
 
-GHOST_TUns8* GHOST_SystemCarbon::getSystemDir() const
+const GHOST_TUns8* GHOST_SystemCarbon::getSystemDir() const
 {
-       static GHOST_TUns8 sysPath[64];
-       
-       strcpy((char*)sysPath,"/Library/Application Support/Blender");
-       
-       return sysPath;
+       return (GHOST_TUns8*)"/Library/Application Support/Blender";
 }
 
-GHOST_TUns8* GHOST_SystemCarbon::getUserDir() const
+const GHOST_TUns8* GHOST_SystemCarbon::getUserDir() const
 {
-       static char usrPath[512] = "";
+       static char usrPath[256] = "";
        char* env = getenv("HOME");
        
        if (env) {
-               strcpy(usrPath, env);
+               strncpy(usrPath, env, 245);
+               usrPath[245]=0;
                strcat(usrPath, "/Library/Application Support/Blender");
                return (GHOST_TUns8*) usrPath;
        }
index b27d791..7f08706 100644 (file)
@@ -195,14 +195,14 @@ public:
         * "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 GHOST_TUns8* getSystemDir() const;
+       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 GHOST_TUns8* getUserDir() const;
+       virtual const GHOST_TUns8* getUserDir() const;
 
 protected:
        /**
index 2f1a94f..b25f889 100644 (file)
@@ -218,14 +218,14 @@ public:
         * "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 GHOST_TUns8* getSystemDir() const;
+       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 GHOST_TUns8* getUserDir() const;
+       virtual const GHOST_TUns8* getUserDir() const;
 
        /**
      * Handles a window event. Called by GHOST_WindowCocoa window delegate
index 15ea373..5289920 100644 (file)
@@ -1714,7 +1714,7 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
 
 #pragma mark Base directories retrieval
 
-GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
+const GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
 {
        static GHOST_TUns8 tempPath[512] = "";
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -1742,7 +1742,7 @@ GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
        return tempPath;
 }
 
-GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const
+const GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const
 {
        static GHOST_TUns8 tempPath[512] = "";
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
index 0cbd3e9..b1c5ee6 100644 (file)
@@ -1095,12 +1095,12 @@ void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, bool selection) const
        }
 }
 
-GHOST_TUns8* GHOST_SystemWin32::getSystemDir() const
+const GHOST_TUns8* GHOST_SystemWin32::getSystemDir() const
 {
        return NULL;
 }
 
-GHOST_TUns8* GHOST_SystemWin32::getUserDir() const
+const GHOST_TUns8* GHOST_SystemWin32::getUserDir() const
 {
        return NULL;
 }
index 1b7b2aa..75bb858 100644 (file)
@@ -193,14 +193,14 @@ public:
         * "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/).
         */
-       GHOST_TUns8* getSystemDir() const;
+       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/).
         */
-        GHOST_TUns8* getUserDir() const;
+        virtual const GHOST_TUns8* getUserDir() const;
 
        /**
         * Creates a drag'n'drop event and pushes it immediately onto the event queue. 
index 5eab71e..cbf7750 100644 (file)
@@ -1458,19 +1458,19 @@ void GHOST_SystemX11::putClipboard(GHOST_TInt8 *buffer, bool selection) const
        }
 }
 
-GHOST_TUns8* GHOST_SystemX11::getSystemDir() const
+const GHOST_TUns8* GHOST_SystemX11::getSystemDir() const
 {
-
+       return (GHOST_TUns8*)"/usr/share/blender";
 }
 
-GHOST_TUns8* GHOST_SystemX11::getUserDir() const
+const GHOST_TUns8* GHOST_SystemX11::getUserDir() const
 {
-       char* path;
+       static char path[256];
        char* env = getenv("HOME");
        if(env) {
-               path = (char*) malloc(strlen(env) + 10); // "/.blender/"
-               strcat(path, env);
-               strcat(path, "/,blender/");
+               strncpy(path, env, 245);
+               path[245]=0;
+               strcat(path, "/.blender/");
                return (GHOST_TUns8*) path;
        } else {
                return NULL;
index b839b5a..1d9959c 100644 (file)
@@ -231,14 +231,14 @@ public:
         * "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/).
         */
-       GHOST_TUns8* getSystemDir() const;
+       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/).
         */
-       GHOST_TUns8* getUserDir() const;
+       const GHOST_TUns8* getUserDir() const;
 
        /**
         * Atom used for ICCCM, WM-spec and Motif.
index ab06df8..65584e4 100644 (file)
@@ -136,14 +136,14 @@ GHOST_WindowCarbon::GHOST_WindowCarbon(
                                                                 &m_windowRef);
                
                if ( err != noErr) {
-                       fprintf(stderr," error creating window %i \n",err);
+                       fprintf(stderr," error creating window %i \n",(int)err);
                } else {
                        
                        ::SetWRefCon(m_windowRef,(SInt32)this);
                        setTitle(title);
                        err = InstallWindowEventHandler (m_windowRef, myWEventHandlerProc, GetEventTypeCount(kWEvents), kWEvents,NULL,NULL); 
                        if ( err != noErr) {
-                               fprintf(stderr," error creating handler %i \n",err);
+                               fprintf(stderr," error creating handler %i \n",(int)err);
                        } else {
                                //      ::TransitionWindow (m_windowRef,kWindowZoomTransitionEffect,kWindowShowTransitionAction,NULL);
                                ::ShowWindow(m_windowRef);
index b534087..fec5f18 100644 (file)
@@ -28,7 +28,7 @@ FILE(GLOB SRC intern/*.c)
 
 SET(INC 
        . ../makesdna ../blenkernel ../../../intern/guardedalloc ../include
-       ../gpu
+       ../gpu ../../../intern/ghost
        ${FREETYPE_INCLUDE_DIRS}
        ${ZLIB_INC}
 )
index df1a096..090094a 100644 (file)
@@ -4,7 +4,7 @@ Import ('env')
 sources = env.Glob('intern/*.c')
 
 cflags=''
-incs = '. ../makesdna ../blenkernel #/intern/guardedalloc ../editors/include ../gpu'
+incs = '. ../makesdna ../blenkernel #/intern/guardedalloc #/intern/ghost ../editors/include ../gpu'
 incs += ' ' + env['BF_FREETYPE_INC']
 incs += ' ' + env['BF_ZLIB_INC']
 defs = ''
index 9540b16..3306283 100644 (file)
@@ -46,6 +46,8 @@
 #include "BLI_storage.h"
 #include "BLI_bfile.h"
 
+#include "GHOST_C-api.h"
+
 /* Internal bfile classification flags */
 #define BCF_OPEN     (0)
 #define BCF_FOPEN    (1<<0)
 #define BCF_AT_END   (1<<3)
 #define BCF_DISCARD  (1<<4)
 
+/* Standard files names */
+#define LAST_SESSION_FILE "last-session"
+#define ENVIRONMENT_FILE "environment"
+
+
 /* Declaration of internal functions */
 void chomp(char* line);
 void expand_envvars(char* src, char* dst);
@@ -221,19 +228,6 @@ void BLI_bfile_set_error(BFILE *bfile, int error) {
 }
 
 
-#if defined(WIN32)
- #define LAST_SESSION_FILE "%HOME%\\Blender\\last-session FIXME FIXME FIXME"
- #define ENVIRONMENT_FILE "FIXME"
- #define SHARED_DIRECTORY "FIXME TOO"
-#elif defined(OSX)
- #define LAST_SESSION_FILE "${HOME}/Library/Application Support/Blender/last-session"
- #define ENVIRONMENT_FILE "${HOME}/Library/Application Support/Blender/${BLENDER_VERSION}/environment"
- #define SHARED_DIRECTORY "/Library/Application Support/Blender"
-#else
- #define LAST_SESSION_FILE "${HOME}/.blender/last-session"
- #define ENVIRONMENT_FILE "${HOME}/.blender/${BLENDER_VERSION}/environment"
- #define SHARED_DIRECTORY "/usr/share/blender"
-#endif
 void BLI_bfile_init_vars() {
        char file[MAXPATHLEN];
        char temp[MAXPATHLEN];
@@ -249,10 +243,12 @@ void BLI_bfile_init_vars() {
        if(BLI_exist(temp)) {
                BLI_setenv_if_new("BLENDER_SHARE", dirname(bprogname));
        } else {
-               BLI_setenv_if_new("BLENDER_SHARE", SHARED_DIRECTORY);
+               BLI_setenv_if_new("BLENDER_SHARE", (const char*)GHOST_getSystemDir());
        }
 
-       expand_envvars(LAST_SESSION_FILE, file);
+       strcpy(file, (const char*)GHOST_getUserDir());
+       BLI_add_slash(file);
+       strcat(file, LAST_SESSION_FILE);
        fp = fopen(file, "r");
        /* 1st line, read previous version */
        if (fp && (fscanf(fp, "%3c\n", temp) == 1)) {
@@ -283,7 +279,9 @@ void BLI_bfile_init_vars() {
        }
 
        /* Load vars from user and system files */
-       expand_envvars(ENVIRONMENT_FILE, file);
+       strcpy(file, (const char *)GHOST_getUserDir());
+       BLI_add_slash(file);
+       strcat(file, ENVIRONMENT_FILE);
        init_vars_from_file(file);
        sprintf(temp, "/%d/environment", BLENDER_VERSION);
        BLI_make_file_string("/", file, getenv("BLENDER_SHARE"), temp);
index d8aed3a..130f025 100644 (file)
@@ -52,6 +52,8 @@ CPPFLAGS += -I$(NAN_ZLIB)/include
 
 CPPFLAGS += -I../../gpu
 
+CPPFLAGS += -I../../../intern/ghost
+
 ifdef NAN_PTHREADS
   CPPFLAGS += -I$(NAN_PTHREADS)/include
 endif