[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36101] trunk/blender: operator & splash button to copy over old settings when blender version changes .

Campbell Barton ideasman42 at gmail.com
Mon Apr 11 17:13:06 CEST 2011


Revision: 36101
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36101
Author:   campbellbarton
Date:     2011-04-11 15:13:06 +0000 (Mon, 11 Apr 2011)
Log Message:
-----------
operator & splash button to copy over old settings when blender version changes.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_operators/wm.py
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/release/scripts/startup/bl_operators/wm.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/wm.py	2011-04-11 14:43:01 UTC (rev 36100)
+++ trunk/blender/release/scripts/startup/bl_operators/wm.py	2011-04-11 15:13:06 UTC (rev 36101)
@@ -909,6 +909,34 @@
         return {'FINISHED'}
 
 
+class WM_OT_copy_prev_settings(bpy.types.Operator):
+    '''Generate System Info'''
+    bl_idname = "wm.copy_prev_settings"
+    bl_label = "Copy Previous Settings"
+
+    def execute(self, context):
+        import os
+        import shutil
+        ver = bpy.app.version
+        ver_prev = ((ver[0] * 100) + ver[1]) - 1
+        ver_prev = ver_prev // 100, ver_prev % 100
+        for res in ('USER', 'LOCAL'):
+            path_src = bpy.utils.resource_path(res, ver_prev[0], ver_prev[1])
+            path_dst = bpy.utils.resource_path(res)
+
+            if os.path.isdir(path_dst):
+                self.report({'ERROR'}, "Path %r exists" % path_dst)
+                return {'CANCELLED'}
+            else:
+                break
+
+        if os.path.isdir(path_src):
+            shutil.copytree(path_src, path_dst)
+            bpy.ops.wm.read_homefile()
+
+        return {'FINISHED'}
+
+
 def _webbrowser_bug_fix():
     # test for X11
     import os

Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2011-04-11 14:43:01 UTC (rev 36100)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2011-04-11 15:13:06 UTC (rev 36101)
@@ -1107,6 +1107,33 @@
 	  */
 }
 
+static int wm_resource_check_prev(void)
+{
+
+	char *res= BLI_get_folder_version(BLENDER_RESOURCE_PATH_USER, BLENDER_VERSION, TRUE);
+
+	// if(res) printf("USER: %s\n", res);
+
+	if(res == NULL) {
+		res= BLI_get_folder_version(BLENDER_RESOURCE_PATH_LOCAL, BLENDER_VERSION, TRUE);
+	}
+
+	// if(res) printf("LOCAL: %s\n", res);
+
+	if(res == NULL) {
+		int res_dir[]= {BLENDER_RESOURCE_PATH_USER, BLENDER_RESOURCE_PATH_LOCAL, -1};
+		int i= 0;
+
+		for(i= 0; res_dir[i] != -1; i++) {
+			if(BLI_get_folder_version(res_dir[i], BLENDER_VERSION - 1, TRUE)) {
+				return TRUE;
+			}
+		}
+	}
+
+	return FALSE;
+}
+
 static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(arg))
 {
 	uiBlock *block;
@@ -1183,6 +1210,12 @@
 	for(recent = G.recent_files.first, i=0; (i<5) && (recent); recent = recent->next, i++) {
 		uiItemStringO(col, BLI_path_basename(recent->filepath), ICON_FILE_BLEND, "WM_OT_open_mainfile", "filepath", recent->filepath);
 	}
+
+	if(wm_resource_check_prev()) {
+		uiItemS(col);
+		uiItemO(col, NULL, ICON_NEW, "WM_OT_copy_prev_settings");
+	}
+
 	uiItemS(col);
 	uiItemO(col, NULL, ICON_RECOVER_LAST, "WM_OT_recover_last_session");
 	uiItemL(col, "", ICON_NONE);




More information about the Bf-blender-cvs mailing list