change behavior of restoring old settings
authorCampbell Barton <ideasman42@gmail.com>
Tue, 12 Apr 2011 04:23:38 +0000 (04:23 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 12 Apr 2011 04:23:38 +0000 (04:23 +0000)
- only attempt to restore old 'user' settings (not local), since bundled blender's always use their own settings.
- only automatically run 'bpy.ops.wm.read_homefile()' after copying files if the user hasnt alreadt started making changes in the blend file.

release/scripts/startup/bl_operators/wm.py
source/blender/windowmanager/intern/wm_operators.c

index 3ecdb70d2a1bc2e00cb38d5ab03b70d7d9a30880..3e0b30c7b6a802089a43c97d64e8e98f5234a512 100644 (file)
@@ -918,23 +918,24 @@ class WM_OT_copy_prev_settings(bpy.types.Operator):
         import os
         import shutil
         ver = bpy.app.version
         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):
+        ver_old = ((ver[0] * 100) + ver[1]) - 1
+        path_src = bpy.utils.resource_path('USER', ver_old // 100, ver_old % 100)
+        path_dst = bpy.utils.resource_path('USER')
+
+        if os.path.isdir(path_dst):
+            self.report({'ERROR'}, "Target path %r exists" % path_dst)
+        elif not os.path.isdir(path_src):
+            self.report({'ERROR'}, "Source path %r exists" % path_src)
+        else:
             shutil.copytree(path_src, path_dst)
             shutil.copytree(path_src, path_dst)
-            bpy.ops.wm.read_homefile()
+            # dont loose users work if they open the splash later.
+            if bpy.data.is_saved is bpy.data.is_dirty is False:
+                bpy.ops.wm.read_homefile()
+            else:
+                self.report({'INFO'}, "Reload Start-Up file to restore settings.")
+            return {'FINISHED'}
 
 
-        return {'FINISHED'}
+        return {'CANCELLED'}
 
 
 def _webbrowser_bug_fix():
 
 
 def _webbrowser_bug_fix():
index 171ff239c69e68a1676f2cc27e47bec728fa0115..dacfba48ee9e8f9a9febbb94898fbc5e357a89d2 100644 (file)
@@ -1115,23 +1115,17 @@ static int wm_resource_check_prev(void)
        // if(res) printf("USER: %s\n", res);
 
        if(res == NULL) {
        // if(res) printf("USER: %s\n", res);
 
        if(res == NULL) {
+               /* with a local dir, copying old files isnt useful since local dir get priority for config */
                res= BLI_get_folder_version(BLENDER_RESOURCE_PATH_LOCAL, BLENDER_VERSION, TRUE);
        }
 
        // if(res) printf("LOCAL: %s\n", res);
                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;
-                       }
-               }
+       if(res) {
+               return FALSE;
+       }
+       else {
+               return (BLI_get_folder_version(BLENDER_RESOURCE_PATH_USER, BLENDER_VERSION - 1, TRUE) != NULL);
        }
        }
-
-       return FALSE;
 }
 
 static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(arg))
 }
 
 static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(arg))
@@ -1206,14 +1200,15 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
        uiItemL(col, "", ICON_NONE);
 
        col = uiLayoutColumn(split, 0);
        uiItemL(col, "", ICON_NONE);
 
        col = uiLayoutColumn(split, 0);
-       uiItemL(col, "Recent", ICON_NONE);
-       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()) {
 
        if(wm_resource_check_prev()) {
-               uiItemS(col);
                uiItemO(col, NULL, ICON_NEW, "WM_OT_copy_prev_settings");
                uiItemO(col, NULL, ICON_NEW, "WM_OT_copy_prev_settings");
+               uiItemS(col);
+       }
+
+       uiItemL(col, "Recent", ICON_NONE);
+       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);
        }
 
        uiItemS(col);
        }
 
        uiItemS(col);