[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36099] trunk/blender: api changes needed for for copying old settings to new.

Campbell Barton ideasman42 at gmail.com
Mon Apr 11 15:56:59 CEST 2011


Revision: 36099
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36099
Author:   campbellbarton
Date:     2011-04-11 13:56:58 +0000 (Mon, 11 Apr 2011)
Log Message:
-----------
api changes needed for for copying old settings to new.
- py: bpy.utils.resource_path('USER', 2, 56)
- C: BLI_get_folder_version(id, major, minor, check);

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy/utils.py
    trunk/blender/source/blender/blenlib/BLI_path_util.h
    trunk/blender/source/blender/blenlib/intern/path_util.c
    trunk/blender/source/blender/python/intern/bpy.c
    trunk/blender/source/blender/python/intern/bpy_interface.c

Modified: trunk/blender/release/scripts/modules/bpy/utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/utils.py	2011-04-11 05:33:43 UTC (rev 36098)
+++ trunk/blender/release/scripts/modules/bpy/utils.py	2011-04-11 13:56:58 UTC (rev 36099)
@@ -23,7 +23,7 @@
 not assosiated with blenders internal data.
 """
 
-from _bpy import register_class, unregister_class, blend_paths
+from _bpy import register_class, unregister_class, blend_paths, resource_path
 from _bpy import script_paths as _bpy_script_paths
 from _bpy import user_resource as _user_resource
 

Modified: trunk/blender/source/blender/blenlib/BLI_path_util.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_path_util.h	2011-04-11 05:33:43 UTC (rev 36098)
+++ trunk/blender/source/blender/blenlib/BLI_path_util.h	2011-04-11 13:56:58 UTC (rev 36099)
@@ -45,6 +45,7 @@
 char *BLI_get_folder(int folder_id, const char *subfolder);
 char *BLI_get_folder_create(int folder_id, const char *subfolder);
 char *BLI_get_user_folder_notest(int folder_id, const char *subfolder);
+char *BLI_get_folder_version(const int id, const int ver, const int do_check);
 
 /* folder_id */
 
@@ -73,6 +74,11 @@
 
 #define BLENDER_USERFOLDER(id) (id >= BLENDER_USER_CONFIG && id <= BLENDER_USER_PLUGINS)
 
+/* for BLI_get_folder_version only */
+#define BLENDER_RESOURCE_PATH_USER		0
+#define BLENDER_RESOURCE_PATH_LOCAL		1
+#define BLENDER_RESOURCE_PATH_SYSTEM	2
+
 #define BLENDER_STARTUP_FILE	"startup.blend"
 #define BLENDER_BOOKMARK_FILE	"bookmarks.txt"
 #define BLENDER_HISTORY_FILE	"recent-files.txt"

Modified: trunk/blender/source/blender/blenlib/intern/path_util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/path_util.c	2011-04-11 05:33:43 UTC (rev 36098)
+++ trunk/blender/source/blender/blenlib/intern/path_util.c	2011-04-11 13:56:58 UTC (rev 36099)
@@ -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 @@
 
 // #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 @@
 	
 	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 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];
@@ -887,13 +891,13 @@
 	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 +915,7 @@
 
 	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 +934,7 @@
 	}
 }
 
-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,11 +949,16 @@
 	/* 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 */
 	if(BLI_getwdN(cwd, sizeof(cwd))) {
@@ -978,7 +987,7 @@
 
 	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 +1010,71 @@
 /* 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:

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list