Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r--source/blender/blenlib/intern/path_util.c144
1 files changed, 92 insertions, 52 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 06dc510f8c6..f7115b4d46f 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -90,7 +90,7 @@
extern char bprogname[];
static int add_win32_extension(char *name);
-static char *blender_version_decimal(void);
+static char *blender_version_decimal(const int ver);
/* implementation */
@@ -823,10 +823,10 @@ const char *BLI_getDefaultDocumentFolder(void) {
// #define PATH_DEBUG2
-static char *blender_version_decimal(void)
+static char *blender_version_decimal(const int ver)
{
static char version_str[5];
- sprintf(version_str, "%d.%02d", BLENDER_VERSION/100, BLENDER_VERSION%100);
+ sprintf(version_str, "%d.%02d", ver/100, ver%100);
return version_str;
}
@@ -836,9 +836,13 @@ static int test_path(char *targetpath, const char *path_base, const char *path_s
if(path_sep) BLI_join_dirfile(tmppath, sizeof(tmppath), path_base, path_sep);
else BLI_strncpy(tmppath, path_base, sizeof(tmppath));
-
- BLI_make_file_string("/", targetpath, tmppath, folder_name);
-
+
+ /* rare cases folder_name is omitted (when looking for ~/.blender/2.xx dir only) */
+ if(folder_name)
+ BLI_make_file_string("/", targetpath, tmppath, folder_name);
+ else
+ BLI_strncpy(targetpath, tmppath, sizeof(tmppath));
+
if (BLI_is_dir(targetpath)) {
#ifdef PATH_DEBUG2
printf("\tpath found: %s\n", targetpath);
@@ -868,7 +872,7 @@ static int test_env_path(char *path, const char *envvar)
}
}
-static int get_path_local(char *targetpath, const char *folder_name, const char *subfolder_name)
+static int get_path_local(char *targetpath, const char *folder_name, const char *subfolder_name, const int ver)
{
char bprogdir[FILE_MAX];
char relfolder[FILE_MAX];
@@ -876,24 +880,29 @@ static int get_path_local(char *targetpath, const char *folder_name, const char
#ifdef PATH_DEBUG2
printf("get_path_local...\n");
#endif
-
- if (subfolder_name) {
- BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name);
- } else {
- BLI_strncpy(relfolder, folder_name, sizeof(relfolder));
+
+ if(folder_name) {
+ if (subfolder_name) {
+ BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name);
+ } else {
+ BLI_strncpy(relfolder, folder_name, sizeof(relfolder));
+ }
+ }
+ else {
+ relfolder[0]= '\0';
}
/* use argv[0] (bprogname) to get the path to the executable */
BLI_split_dirfile(bprogname, bprogdir, NULL);
/* try EXECUTABLE_DIR/2.5x/folder_name - new default directory for local blender installed files */
- if(test_path(targetpath, bprogdir, blender_version_decimal(), relfolder))
+ if(test_path(targetpath, bprogdir, blender_version_decimal(ver), relfolder))
return 1;
return 0;
}
-static int get_path_user(char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar)
+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;
@@ -911,7 +920,7 @@ static int get_path_user(char *targetpath, const char *folder_name, const char *
user_base_path = (const char *)GHOST_getUserDir();
if (user_base_path) {
- BLI_snprintf(user_path, FILE_MAX, BLENDER_USER_FORMAT, user_base_path, blender_version_decimal());
+ BLI_snprintf(user_path, FILE_MAX, BLENDER_USER_FORMAT, user_base_path, blender_version_decimal(ver));
}
if(!user_path[0])
@@ -930,7 +939,7 @@ static int get_path_user(char *targetpath, const char *folder_name, const char *
}
}
-static int get_path_system(char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar)
+static int get_path_system(char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar, const int ver)
{
char system_path[FILE_MAX];
const char *system_base_path;
@@ -945,10 +954,15 @@ static int get_path_system(char *targetpath, const char *folder_name, const char
/* use argv[0] (bprogname) to get the path to the executable */
BLI_split_dirfile(bprogname, bprogdir, NULL);
- if (subfolder_name) {
- BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name);
- } else {
- BLI_strncpy(relfolder, folder_name, sizeof(relfolder));
+ if(folder_name) {
+ if (subfolder_name) {
+ BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name);
+ } else {
+ BLI_strncpy(relfolder, folder_name, sizeof(relfolder));
+ }
+ }
+ else {
+ relfolder[0]= '\0';
}
/* try CWD/release/folder_name */
@@ -978,7 +992,7 @@ static int get_path_system(char *targetpath, const char *folder_name, const char
system_base_path = (const char *)GHOST_getSystemDir();
if (system_base_path) {
- BLI_snprintf(system_path, FILE_MAX, BLENDER_SYSTEM_FORMAT, system_base_path, blender_version_decimal());
+ BLI_snprintf(system_path, FILE_MAX, BLENDER_SYSTEM_FORMAT, system_base_path, blender_version_decimal(ver));
}
if(!system_path[0])
@@ -1001,70 +1015,71 @@ static int get_path_system(char *targetpath, const char *folder_name, const char
/* returns the path if found, NULL string if not */
char *BLI_get_folder(int folder_id, const char *subfolder)
{
+ const int ver= BLENDER_VERSION;
static char path[FILE_MAX] = "";
switch (folder_id) {
case BLENDER_DATAFILES: /* general case */
- if (get_path_local(path, "datafiles", subfolder)) break;
- if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES")) break;
- if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES")) break;
+ if (get_path_local(path, "datafiles", subfolder, ver)) break;
+ if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", 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)) break;
- if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES")) break;
+ if (get_path_local(path, "datafiles", subfolder, ver)) break;
+ if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break;
return NULL;
case BLENDER_SYSTEM_DATAFILES:
- if (get_path_local(path, "datafiles", subfolder)) break;
- if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES")) 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_AUTOSAVE:
- if (get_path_local(path, "autosave", subfolder)) break;
- if (get_path_user(path, "autosave", subfolder, "BLENDER_USER_DATAFILES")) break;
+ 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)) break;
- if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG")) break;
- if (get_path_system(path, "config", subfolder, "BLENDER_SYSTEM_CONFIG")) break;
+ 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)) break;
- if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG")) break;
+ 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)) break;
- if (get_path_system(path, "config", subfolder, "BLENDER_SYSTEM_CONFIG")) break;
+ 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)) break;
- if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS")) break;
- if (get_path_system(path, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS")) break;
+ 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)) break;
- if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS")) break;
+ if (get_path_local(path, "scripts", subfolder, ver)) break;
+ if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver)) break;
return NULL;
case BLENDER_SYSTEM_SCRIPTS:
- if (get_path_local(path, "scripts", subfolder)) break;
- if (get_path_system(path, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS")) break;
+ if (get_path_local(path, "scripts", subfolder, ver)) break;
+ 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)) break;
- if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON")) break;
+ 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)) break;
- if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON")) break;
+ if (get_path_local(path, "python", subfolder, ver)) break;
+ if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON", ver)) break;
return NULL;
}
@@ -1073,20 +1088,21 @@ char *BLI_get_folder(int folder_id, const char *subfolder)
char *BLI_get_user_folder_notest(int folder_id, const char *subfolder)
{
+ const int ver= BLENDER_VERSION;
static char path[FILE_MAX] = "";
switch (folder_id) {
case BLENDER_USER_DATAFILES:
- get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES");
+ get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver);
break;
case BLENDER_USER_CONFIG:
- get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG");
+ get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG", ver);
break;
case BLENDER_USER_AUTOSAVE:
- get_path_user(path, "autosave", subfolder, "BLENDER_USER_AUTOSAVE");
+ get_path_user(path, "autosave", subfolder, "BLENDER_USER_AUTOSAVE", ver);
break;
case BLENDER_USER_SCRIPTS:
- get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS");
+ get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver);
break;
}
if ('\0' == path[0]) {
@@ -1113,6 +1129,30 @@ char *BLI_get_folder_create(int folder_id, const char *subfolder)
return path;
}
+char *BLI_get_folder_version(const int id, const int ver, const int do_check)
+{
+ static char path[FILE_MAX] = "";
+ int ok;
+ switch(id) {
+ case BLENDER_RESOURCE_PATH_USER:
+ ok= get_path_user(path, NULL, NULL, NULL, ver);
+ break;
+ case BLENDER_RESOURCE_PATH_LOCAL:
+ ok= get_path_local(path, NULL, NULL, ver);
+ break;
+ case BLENDER_RESOURCE_PATH_SYSTEM:
+ ok= get_path_system(path, NULL, NULL, NULL, ver);
+ break;
+ default:
+ BLI_assert(!"incorrect ID");
+ }
+
+ if((ok == FALSE) && do_check) {
+ return NULL;
+ }
+
+ return path;
+}
/* End new stuff */
/* ************************************************************* */