== installation paths ==
authorAndrea Weikert <elubie@gmx.net>
Thu, 15 Jul 2010 21:39:47 +0000 (21:39 +0000)
committerAndrea Weikert <elubie@gmx.net>
Thu, 15 Jul 2010 21:39:47 +0000 (21:39 +0000)
* fix for autosave location -> shouldn't use BLI_gethome anymore
* this frees BLI_gethome of having to emulate the local->user->system search path and can now be truly considered as 'home/default location for .blend files'
* removed setting the default G.sce from read_history, was out of context there.
* fix for creating user dir, leftover from previous commit.

jesterKing, please review -> if there are any issues I will fix or revert.

source/blender/blenlib/BLI_path_util.h
source/blender/blenlib/intern/path_util.c
source/blender/python/intern/bpy_app.c
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_init_exit.c

index 57e6d0b16d76953f6abd977c8c0a52b92cd5e8bc..60d35c9ecdf5dc9246bee55a7e16d5fbe35edd97 100644 (file)
@@ -59,6 +59,7 @@ char *BLI_get_folder_create(int folder_id, char *subfolder);
 #define BLENDER_USER_DATAFILES         32
 #define BLENDER_USER_SCRIPTS           33
 #define BLENDER_USER_PLUGINS           34
 #define BLENDER_USER_DATAFILES         32
 #define BLENDER_USER_SCRIPTS           33
 #define BLENDER_USER_PLUGINS           34
+#define BLENDER_USER_AUTOSAVE          35
 
 /* system */
 #define BLENDER_SYSTEM_CONFIG          51      /* optional */
 
 /* system */
 #define BLENDER_SYSTEM_CONFIG          51      /* optional */
index 6ab7ba2a7a581da6d0141c73d45a625ae52546ce..df1e2c7d590fdb8ccd1426ba0fa891f0b53947f7 100644 (file)
@@ -732,66 +732,38 @@ void BLI_getlastdir(const char* dir, char *last, int maxlen)
        }
 }
 
        }
 }
 
+/* This is now only used to really get the user's home folder */
+/* On Windows I chose the 'Users/<MyUserName>/Documents' since it's used
+   as default location to save documents */
 char *BLI_gethome(void) {
        #if !defined(WIN32)
                return getenv("HOME");
 
        #else /* Windows */
                char * ret;
 char *BLI_gethome(void) {
        #if !defined(WIN32)
                return getenv("HOME");
 
        #else /* Windows */
                char * ret;
-               static char dir[512];
-               static char appdatapath[MAXPATHLEN];
+               static char documentfolder[MAXPATHLEN];
                HRESULT hResult;
 
                /* Check for %HOME% env var */
 
                ret = getenv("HOME");
                if(ret) {
                HRESULT hResult;
 
                /* Check for %HOME% env var */
 
                ret = getenv("HOME");
                if(ret) {
-                       sprintf(dir, "%s\\%s", ret, blender_version_decimal());
-                       if (BLI_is_dir(dir)) return dir;
+                       if (BLI_is_dir(ret)) return ret;
                }
                }
-
-               /* else, check install dir (path containing blender.exe) */
-
-               if(BLI_getInstallationDir(dir))
-               {
-                       sprintf(dir, "%s", dir, blender_version_decimal());
-                       if (BLI_is_dir(dir)) return(dir);
-               }
-
                                
                /* add user profile support for WIN 2K / NT.
                 * This is %APPDATA%, which translates to either
                 * %USERPROFILE%\Application Data or since Vista
                 * to %USERPROFILE%\AppData\Roaming
                 */
                                
                /* add user profile support for WIN 2K / NT.
                 * This is %APPDATA%, which translates to either
                 * %USERPROFILE%\Application Data or since Vista
                 * to %USERPROFILE%\AppData\Roaming
                 */
-               hResult = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdatapath);
+               hResult = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, documentfolder);
                
                if (hResult == S_OK)
                {
                
                if (hResult == S_OK)
                {
-                       if (BLI_is_dir(appdatapath)) { /* from fop, also below... */
-                               sprintf(dir, "%s\\Blender Foundation\\Blender", appdatapath);
-                               BLI_recurdir_fileops(dir);
-                               if (BLI_is_dir(dir)) {
-                                       sprintf(dir,"%s\\%s", dir, blender_version_decimal());
-                                       if(BLI_is_dir(dir)) return(dir);
-                               }
-                       }
-                       hResult = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdatapath);
-                       if (hResult == S_OK)
-                       {
-                               if (BLI_is_dir(appdatapath)) 
-                               { /* from fop, also below... */
-                                       sprintf(dir, "%s\\Blender Foundation\\Blender", appdatapath);
-                                       BLI_recurdir_fileops(dir);
-                                       if (BLI_is_dir(dir)) {
-                                               sprintf(dir,"%s\\%s", dir, blender_version_decimal());
-                                               if(BLI_is_dir(dir)) return(dir);
-                                       }
-                               }
-                       }
+                       if (BLI_is_dir(documentfolder)) return documentfolder;
                }
                
                }
                
-               return "C:\\Temp";      /* sheesh! bad, bad, bad! (aphex) */
+               return NULL;
        #endif
 }
 
        #endif
 }
 
@@ -989,6 +961,11 @@ char *BLI_get_folder(int folder_id, char *subfolder)
                        if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES"))  break;
                        return NULL;
                        
                        if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES"))  break;
                        return NULL;
                        
+               case BLENDER_USER_AUTOSAVE:
+                       if (get_path_local(path, "autosave", subfolder)) break;
+                       if (get_path_user(path, "autosave", subfolder, "BLENDER_USER_DATAFILES"))       break;
+                       return NULL;
+
                case BLENDER_CONFIG:            /* general case */
                        if (get_path_local(path, "config", subfolder)) break;
                        if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG")) break;
                case BLENDER_CONFIG:            /* general case */
                        if (get_path_local(path, "config", subfolder)) break;
                        if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG")) break;
@@ -1035,16 +1012,16 @@ char *BLI_get_folder(int folder_id, char *subfolder)
 static char *BLI_get_user_folder_notest(int folder_id, char *subfolder)
 {
        static char path[FILE_MAX] = "";
 static char *BLI_get_user_folder_notest(int folder_id, char *subfolder)
 {
        static char path[FILE_MAX] = "";
-       char search_path[FILE_MAX];
 
        switch (folder_id) {
                case BLENDER_USER_DATAFILES:
 
        switch (folder_id) {
                case BLENDER_USER_DATAFILES:
-                       BLI_join_dirfile(search_path, "datafiles", subfolder);
-                       get_path_user(path, search_path, subfolder, "BLENDER_USER_DATAFILES");
+                       get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES");
                        break;
                case BLENDER_USER_CONFIG:
                        break;
                case BLENDER_USER_CONFIG:
-                       BLI_join_dirfile(search_path, "config", subfolder);
-                       get_path_user(path, search_path, subfolder, "BLENDER_USER_CONFIG");
+                       get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG");
+                       break;
+               case BLENDER_USER_AUTOSAVE:
+                       get_path_user(path, "autosave", subfolder, "BLENDER_USER_AUTOSAVE");
                        break;
        }
        if ('\0' == path[0]) {
                        break;
        }
        if ('\0' == path[0]) {
@@ -1058,7 +1035,7 @@ char *BLI_get_folder_create(int folder_id, char *subfolder)
        char *path;
 
        /* only for user folders */
        char *path;
 
        /* only for user folders */
-       if (!ELEM(folder_id, BLENDER_USER_DATAFILES, BLENDER_USER_CONFIG))
+       if (!ELEM3(folder_id, BLENDER_USER_DATAFILES, BLENDER_USER_CONFIG, BLENDER_USER_AUTOSAVE))
                return NULL;
        
        path = BLI_get_folder(folder_id, subfolder);
                return NULL;
        
        path = BLI_get_folder(folder_id, subfolder);
index 4a2ac0c9252492ff5219d06a6cd0a9f628d9775f..78658a611a3492349629ad644f5e2da438c2687b 100644 (file)
@@ -43,7 +43,6 @@ static PyTypeObject BlenderAppType;
 static PyStructSequence_Field app_info_fields[] = {
        {"version", "The Blender version as a tuple of 3 numbers. eg. (2, 50, 11)"},
        {"version_string", "The Blender version formatted as a string"},
 static PyStructSequence_Field app_info_fields[] = {
        {"version", "The Blender version as a tuple of 3 numbers. eg. (2, 50, 11)"},
        {"version_string", "The Blender version formatted as a string"},
-       {"home", "The blender home directory, normally matching $HOME"},
        {"binary_path", "The location of blenders executable, useful for utilities that spawn new instances"},
        {"debug", "Boolean, set when blender is running in debug mode (started with -d)"},
        {"background", "Boolean, True when blender is running without a user interface (started with -b)"},
        {"binary_path", "The location of blenders executable, useful for utilities that spawn new instances"},
        {"debug", "Boolean, set when blender is running in debug mode (started with -d)"},
        {"background", "Boolean, True when blender is running without a user interface (started with -b)"},
@@ -85,7 +84,6 @@ static PyObject *make_app_info(void)
 
        SetObjItem(Py_BuildValue("(iii)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION));
        SetObjItem(PyUnicode_FromFormat("%d.%02d (sub %d)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION));
 
        SetObjItem(Py_BuildValue("(iii)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION));
        SetObjItem(PyUnicode_FromFormat("%d.%02d (sub %d)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION));
-       SetStrItem(BLI_gethome());
        SetStrItem(bprogname);
        SetObjItem(PyBool_FromLong(G.f & G_DEBUG));
        SetObjItem(PyBool_FromLong(G.background));
        SetStrItem(bprogname);
        SetObjItem(PyBool_FromLong(G.f & G_DEBUG));
        SetObjItem(PyBool_FromLong(G.background));
index ff859ebe166414669b60c635c26da5e93dc2226f..89b8267bb0591c191290f7813cc3461563e43d6b 100644 (file)
@@ -434,9 +434,6 @@ void read_history(void)
                        num++;
                }
        }
                        num++;
                }
        }
-
-       if(G.sce[0] == 0)
-               BLI_make_file_string("/", G.sce, BLI_gethome(), "untitled.blend");
        
        BLI_free_file_lines(lines);
 
        
        BLI_free_file_lines(lines);
 
@@ -686,21 +683,14 @@ void wm_autosave_location(char *filename)
 {
        char pidstr[32];
 #ifdef WIN32
 {
        char pidstr[32];
 #ifdef WIN32
-       char subdir[9];
-       char savedir[FILE_MAXDIR];
+       char *savedir;
 #endif
 
        sprintf(pidstr, "%d.blend", abs(getpid()));
        
 #ifdef WIN32
        if (!BLI_exists(U.tempdir)) {
 #endif
 
        sprintf(pidstr, "%d.blend", abs(getpid()));
        
 #ifdef WIN32
        if (!BLI_exists(U.tempdir)) {
-               BLI_strncpy(subdir, "autosave", sizeof(subdir));
-               BLI_make_file_string("/", savedir, BLI_gethome(), subdir);
-               
-               /* create a new autosave dir
-                * function already checks for existence or not */
-               BLI_recurdir_fileops(savedir);
-       
+               savedir = BLI_get_folder_create(BLENDER_USER_AUTOSAVE, NULL);
                BLI_make_file_string("/", filename, savedir, pidstr);
                return;
        }
                BLI_make_file_string("/", filename, savedir, pidstr);
                return;
        }
index db668390b881af2c67a1fb3908b8a4eaad2f71ae..5bfaf91aa1108faaf4da4821693bd122a4774c8e 100644 (file)
@@ -164,6 +164,10 @@ void WM_init(bContext *C, int argc, char **argv)
        G.ndofdevice = -1;      /* XXX bad initializer, needs set otherwise buttons show! */
        
        read_history();
        G.ndofdevice = -1;      /* XXX bad initializer, needs set otherwise buttons show! */
        
        read_history();
+
+       if(G.sce[0] == 0)
+               BLI_make_file_string("/", G.sce, BLI_gethome(), "untitled.blend");
+
        BLI_strncpy(G.lib, G.sce, FILE_MAX);
 
 }
        BLI_strncpy(G.lib, G.sce, FILE_MAX);
 
 }