MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / presets_add_config_file

Function presets_add_config_file

gtk/src/presets.c:810–863  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

808}
809
810static int
811presets_add_config_file(const gchar *name)
812{
813 gchar *config, *path;
814 hb_value_t *preset;
815
816 config = ghb_get_user_config_dir(NULL);
817 path = g_strdup_printf ("%s/%s", config, name);
818 g_free(config);
819 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR))
820 return -1;
821 preset = hb_presets_read_file(path);
822 g_free(path);
823 if (preset != NULL)
824 {
825 int hb_major, hb_minor, hb_micro;
826 int major, minor, micro;
827 hb_presets_version(preset, &major, &minor, &micro);
828 hb_presets_current_version(&hb_major, &hb_minor, &hb_micro);
829 if (major != hb_major)
830 {
831 // Make a backup whenever the preset version changes
832 config = ghb_get_user_config_dir(NULL);
833 path = g_strdup_printf ("%s/presets.%d.%d.%d.json",
834 config, major, minor, micro);
835 hb_value_write_json(preset, path);
836 g_free(config);
837 g_free(path);
838 }
839
840 if (major > hb_major)
841 {
842 // Change in major indicates non-backward compatible preset changes.
843 // We can't successfully load presets that were generated by
844 // a newer version of handbrake than is currently running.
845 hb_value_free(&preset);
846 return -2;
847 }
848
849 hb_value_t *imported;
850 hb_presets_import(preset, &imported);
851 hb_presets_add(imported);
852 if (major != hb_major || minor != hb_minor || micro != hb_micro)
853 {
854 // Reload hb builtin presets
855 hb_presets_builtin_update();
856 store_presets();
857 }
858 hb_value_free(&imported);
859 hb_value_free(&preset);
860 return 0;
861 }
862 return -1;
863}
864
865static GhbValue*
866read_config_file(const gchar *name)

Callers 1

ghb_presets_loadFunction · 0.85

Calls 10

ghb_get_user_config_dirFunction · 0.85
hb_presets_read_fileFunction · 0.85
hb_presets_versionFunction · 0.85
hb_value_write_jsonFunction · 0.85
hb_value_freeFunction · 0.85
hb_presets_importFunction · 0.85
hb_presets_addFunction · 0.85
store_presetsFunction · 0.85

Tested by

no test coverage detected