diff options
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/src/presets.c | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/gtk/src/presets.c b/gtk/src/presets.c index 33757b992..122756e84 100644 --- a/gtk/src/presets.c +++ b/gtk/src/presets.c @@ -662,12 +662,35 @@ presets_add_config_file(const gchar *name) g_free(path); if (preset != NULL) { - hb_presets_add(preset); - int hb_major, hb_minor, hb_micro; int major, minor, micro; hb_presets_version(preset, &major, &minor, µ); hb_presets_current_version(&hb_major, &hb_minor, &hb_micro); + if (major > hb_major) + { + // Change in major indicates non-backward compatible preset changes. + // We can't successfully load presets that were generated by + // a newer version of handbrake than is currently running. + hb_value_free(&preset); + return -1; + } + + hb_value_t *backup = hb_value_dup(preset); + int result = hb_presets_import(preset); + if (result) + { + // hb_presets_import modified the preset. So make a backup + // of the original. + config = ghb_get_user_config_dir(NULL); + path = g_strdup_printf ("%s/presets.%d.%d.%d.json", + config, major, minor, micro); + hb_value_write_json(backup, path); + g_free(config); + g_free(path); + } + hb_value_free(&backup); + + hb_presets_add(preset); if (major != hb_major || minor != hb_minor || micro != hb_micro) { // Reload hb builtin presets @@ -1524,12 +1547,26 @@ ghb_presets_load(signal_user_data_t *ud) { if (presets_add_config_file("presets.json") < 0) { - if (presets_add_config_file("presets") < 0) + // The above can fail if the presets file was written by a + // more recent version of HandBrake than is currently running. + // Look for a backup version that matches the currently running + // version. + gchar *name; + int major, minor, micro; + + hb_presets_current_version(&major, &minor, µ); + name = g_strdup_printf("presets.%d.%d.%d.json", major, minor, micro); + ghb_log("Failed to read presets file, trying backup (%s)...", name); + if (presets_add_config_file(name) < 0) { - ghb_log("Failed to read preset file, initailizing new presets..."); - hb_presets_builtin_update(); - store_presets(); + if (presets_add_config_file("presets") < 0) + { + ghb_log("Failed to read presets file, initailizing new presets..."); + hb_presets_builtin_update(); + store_presets(); + } } + g_free(name); } } |