]> granicus.if.org Git - handbrake/commitdiff
presets: add result to indicate if preset import modified presets
authorJohn Stebbins <jstebbins.hb@gmail.com>
Wed, 7 Oct 2015 17:52:22 +0000 (10:52 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Fri, 9 Oct 2015 20:48:30 +0000 (13:48 -0700)
This information is useful to the frontends in creation of preset
backups.

libhb/preset.c
libhb/preset.h
macosx/HBPreset.m
macosx/HBPresetsManager.m

index e733a175a38d14df7bb00b5fcacd7185074ab87f..ff5bdf02623de7c4bff7e0e267361ec74242a42e 100644 (file)
@@ -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;
 }
index 62ce3d361ada8ff7228b0da011c4ea2950c6839f..63eaf1cde2b47d08a87b18bb81550cd50fae3840 100644 (file)
@@ -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);
index 26edbba6cd8ef370c9e4862cc471d8030226a5da..8b3d5c6bab54ead9e268ba1e7b3165922eafe9ea 100644 (file)
     // 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)
         {
index b17294b27ca146d7164f4481ef6d6bc2b4e708c1..a98269298378c28c3a655b925d0d9a84251e390a 100644 (file)
@@ -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);
         }