diff options
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 64 |
1 files changed, 19 insertions, 45 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 1f4b0ffdd5c..f89283178ec 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -153,7 +153,7 @@ void BLI_stringenc(char *string, const char *head, const char *tail, unsigned sh int BLI_split_name_num(char *left, int *nr, const char *name, const char delim) { int a; - + *nr= 0; a= strlen(name); memcpy(left, name, (a + 1) * sizeof(char)); @@ -216,13 +216,13 @@ int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, cons int number; int len= BLI_split_name_num(left, &number, name, delim); do { - int newlen= BLI_snprintf(tempname, name_len, "%s%c%03d", left, delim, number); + int newlen= BLI_snprintf(tempname, name_len, "%s%c%03d", left, delim, ++number); if(newlen >= name_len) { len -= ((newlen + 1) - name_len); if(len < 0) len= number= 0; left[len]= '\0'; } - } while(number++, unique_check(arg, tempname)); + } while(unique_check(arg, tempname)); BLI_strncpy(name, tempname, name_len); @@ -736,7 +736,7 @@ int BLI_path_cwd(char *path) * cwd should contain c:\ etc on win32 so the relbase can be NULL * relbase being NULL also prevents // being misunderstood as relative to the current * blend file which isnt a feature we want to use in this case since were dealing - * with a path from the command line, rather then from inside Blender */ + * with a path from the command line, rather than from inside Blender */ char origpath[FILE_MAXDIR + FILE_MAXFILE]; BLI_strncpy(origpath, path, FILE_MAXDIR + FILE_MAXFILE); @@ -902,10 +902,23 @@ static int get_path_local(char *targetpath, const char *folder_name, const char return 0; } +static int is_portable_install(void) +{ + /* detect portable install by the existance of config folder */ + const int ver= BLENDER_VERSION; + char path[FILE_MAX]; + + return get_path_local(path, "config", NULL, ver); +} + static int get_path_user(char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar, const int ver) { char user_path[FILE_MAX]; const char *user_base_path; + + /* for portable install, user path is always local */ + if (is_portable_install()) + return get_path_local(targetpath, folder_name, subfolder_name, ver); user_path[0] = '\0'; @@ -1020,13 +1033,12 @@ char *BLI_get_folder(int folder_id, const char *subfolder) switch (folder_id) { case BLENDER_DATAFILES: /* general case */ - if (get_path_local(path, "datafiles", subfolder, ver)) break; if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break; + if (get_path_local(path, "datafiles", subfolder, ver)) break; if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES", ver)) break; return NULL; case BLENDER_USER_DATAFILES: - if (get_path_local(path, "datafiles", subfolder, ver)) break; if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break; return NULL; @@ -1036,34 +1048,14 @@ char *BLI_get_folder(int folder_id, const char *subfolder) return NULL; case BLENDER_USER_AUTOSAVE: - if (get_path_local(path, "autosave", subfolder, ver)) break; if (get_path_user(path, "autosave", subfolder, "BLENDER_USER_DATAFILES", ver)) break; return NULL; - case BLENDER_CONFIG: /* general case */ - if (get_path_local(path, "config", subfolder, ver)) break; - if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG", ver)) break; - if (get_path_system(path, "config", subfolder, "BLENDER_SYSTEM_CONFIG", ver)) break; - return NULL; - case BLENDER_USER_CONFIG: - if (get_path_local(path, "config", subfolder, ver)) break; if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG", ver)) break; return NULL; - case BLENDER_SYSTEM_CONFIG: - if (get_path_local(path, "config", subfolder, ver)) break; - if (get_path_system(path, "config", subfolder, "BLENDER_SYSTEM_CONFIG", ver)) break; - return NULL; - - case BLENDER_SCRIPTS: /* general case */ - if (get_path_local(path, "scripts", subfolder, ver)) break; - if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver)) break; - if (get_path_system(path, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS", ver)) break; - return NULL; - case BLENDER_USER_SCRIPTS: - if (get_path_local(path, "scripts", subfolder, ver)) break; if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver)) break; return NULL; @@ -1072,11 +1064,6 @@ char *BLI_get_folder(int folder_id, const char *subfolder) if (get_path_system(path, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS", ver)) break; return NULL; - case BLENDER_PYTHON: /* general case */ - if (get_path_local(path, "python", subfolder, ver)) break; - if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON", ver)) break; - return NULL; - case BLENDER_SYSTEM_PYTHON: if (get_path_local(path, "python", subfolder, ver)) break; if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON", ver)) break; @@ -1691,10 +1678,9 @@ void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name) #ifdef _WIN32 if(GetModuleFileName(0, fullname, maxlen)) { - GetShortPathName(fullname, fullname, maxlen); if(!BLI_exists(fullname)) { printf("path can't be found: \"%.*s\"\n", maxlen, fullname); - MessageBox(NULL, "path constains invalid characters or is too long (see console)", "Error", MB_OK); + MessageBox(NULL, "path contains invalid characters or is too long (see console)", "Error", MB_OK); } return; } @@ -1745,18 +1731,6 @@ void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name) printf("guessing '%s' == '%s'\n", name, fullname); } #endif - -#ifdef _WIN32 - // in windows change long filename to short filename because - // win2k doesn't know how to parse a commandline with lots of - // spaces and double-quotes. There's another solution to this - // with spawnv(P_WAIT, bprogname, argv) instead of system() but - // that's even uglier - GetShortPathName(fullname, fullname, maxlen); -#if defined(DEBUG) - printf("Shortname = '%s'\n", fullname); -#endif -#endif } } |