change behavior of restoring old settings

- 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.
This commit is contained in:
Campbell Barton
2011-04-12 04:23:38 +00:00
parent 3a73a75e84
commit 8fd1d53a31
2 changed files with 27 additions and 31 deletions

View File

@@ -918,23 +918,24 @@ class WM_OT_copy_prev_settings(bpy.types.Operator):
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)
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'}, "Path %r exists" % path_dst)
return {'CANCELLED'}
else:
break
if os.path.isdir(path_src):
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)
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():

View File

@@ -1115,23 +1115,17 @@ static int wm_resource_check_prev(void)
// 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);
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))
@@ -1206,16 +1200,17 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
uiItemL(col, "", ICON_NONE);
col = uiLayoutColumn(split, 0);
if(wm_resource_check_prev()) {
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);
}
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);