summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2015-10-07 10:52:22 -0700
committerJohn Stebbins <[email protected]>2015-10-09 13:48:30 -0700
commit71ec27786fb8f2d455b5b7317b9384d6dc3b058f (patch)
tree8e4e5ebe85106f4f8eb53abbbf7a3e0a4adb2cbf
parent305d591def7d9bb32f3dd3020c511970f3363960 (diff)
presets: add result to indicate if preset import modified presets
This information is useful to the frontends in creation of preset backups.
-rw-r--r--libhb/preset.c36
-rw-r--r--libhb/preset.h4
-rw-r--r--macosx/HBPreset.m5
-rw-r--r--macosx/HBPresetsManager.m5
4 files changed, 37 insertions, 13 deletions
diff --git a/libhb/preset.c b/libhb/preset.c
index e733a175a..ff5bdf026 100644
--- a/libhb/preset.c
+++ b/libhb/preset.c
@@ -32,7 +32,7 @@ static hb_value_t *hb_presets = NULL;
static hb_value_t *hb_presets_builtin = NULL;
static void preset_clean(hb_value_t *preset, hb_value_t *template);
-static void preset_import(hb_value_t *preset, int major, int minor, int micro);
+static int preset_import(hb_value_t *preset, int major, int minor, int micro);
enum
{
@@ -62,6 +62,7 @@ typedef struct
int major;
int minor;
int micro;
+ int result;
} preset_import_context_t;
typedef struct
@@ -150,7 +151,7 @@ static int do_preset_search(hb_value_t *preset, preset_do_context_t *do_ctx)
static int do_preset_import(hb_value_t *preset, preset_do_context_t *do_ctx)
{
preset_import_context_t *ctx = (preset_import_context_t*)do_ctx;
- preset_import(preset, ctx->major, ctx->minor, ctx->micro);
+ ctx->result |= preset_import(preset, ctx->major, ctx->minor, ctx->micro);
return PRESET_DO_NEXT;
}
@@ -2204,21 +2205,26 @@ static void import_10_0_0(hb_value_t *preset)
import_deint_10_0_0(preset);
}
-static void preset_import(hb_value_t *preset, int major, int minor, int micro)
+static int preset_import(hb_value_t *preset, int major, int minor, int micro)
{
+ int result = 0;
+
if (!hb_value_get_bool(hb_dict_get(preset, "Folder")))
{
if (major == 0 && minor == 0 && micro == 0)
{
// Convert legacy presets (before versioning introduced)
import_0_0_0(preset);
+ result = 1;
}
else if (major == 10 && minor == 0 && micro == 0)
{
import_10_0_0(preset);
+ result = 1;
}
preset_clean(preset, hb_preset_template);
}
+ return result;
}
int hb_presets_version(hb_value_t *preset, int *major, int *minor, int *micro)
@@ -2243,23 +2249,35 @@ int hb_presets_version(hb_value_t *preset, int *major, int *minor, int *micro)
return -1;
}
-void hb_presets_import(hb_value_t *preset)
+int hb_presets_import(hb_value_t *preset)
{
preset_import_context_t ctx;
ctx.do_ctx.path.depth = 1;
+ ctx.result = 0;
hb_presets_version(preset, &ctx.major, &ctx.minor, &ctx.micro);
presets_do(do_preset_import, preset, (preset_do_context_t*)&ctx);
+
+ return ctx.result;
}
-char * hb_presets_import_json(const char *json)
+int hb_presets_import_json(const char *in, char **out)
{
- hb_value_t * dict = hb_value_json(json);
+ int result;
+
+ if (out != NULL)
+ {
+ *out = NULL;
+ }
+ hb_value_t * dict = hb_value_json(in);
if (dict == NULL)
- return NULL;
+ return 0;
- hb_presets_import(dict);
- char * result = hb_value_get_json(dict);
+ result = hb_presets_import(dict);
+ if (out != NULL)
+ {
+ *out = hb_value_get_json(dict);
+ }
hb_value_free(&dict);
return result;
}
diff --git a/libhb/preset.h b/libhb/preset.h
index 62ce3d361..63eaf1cde 100644
--- a/libhb/preset.h
+++ b/libhb/preset.h
@@ -84,11 +84,11 @@ char * hb_presets_clean_json(const char *json);
// Import a preset. Sanitizes and converts old key/value pairs
// to new key/value pairs. This is applied for you by hb_presets_add(),
// hb_presets_add_json(), hb_presets_add_file(), and hb_presets_add_path()
-void hb_presets_import(hb_value_t *preset);
+int hb_presets_import(hb_value_t *preset);
// Import a json preset. Sanitizes and converts old key/value pairs
// to new key/value pairs.
-char * hb_presets_import_json(const char *json);
+int hb_presets_import_json(const char *in, char **out);
// Register new presets with libhb from json string
int hb_presets_add_json(const char *json);
diff --git a/macosx/HBPreset.m b/macosx/HBPreset.m
index 26edbba6c..8b3d5c6ba 100644
--- a/macosx/HBPreset.m
+++ b/macosx/HBPreset.m
@@ -98,7 +98,10 @@
// Run the json through the libhb import function
// to avoid importing unknowns keys.
if (presetsJson.length) {
- char *importedJson = hb_presets_import_json(presetsJson.UTF8String);
+ char *importedJson;
+ int result;
+
+ result = hb_presets_import_json(presetsJson.UTF8String, &importedJson);
if (importedJson)
{
diff --git a/macosx/HBPresetsManager.m b/macosx/HBPresetsManager.m
index b17294b27..a98269298 100644
--- a/macosx/HBPresetsManager.m
+++ b/macosx/HBPresetsManager.m
@@ -111,7 +111,10 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification";
if ([self checkIfOutOfDate:presetsDict])
{
- char *updatedJson = hb_presets_import_json(cleanedJson);
+ char *updatedJson;
+ int result;
+
+ result = hb_presets_import_json(cleanedJson, &updatedJson);
presetsDict = [NSJSONSerialization HB_JSONObjectWithUTF8String:updatedJson options:0 error:NULL];
free(updatedJson);
}