]> granicus.if.org Git - handbrake/commitdiff
add ghb_override_user_config_dir function (#304)
author2wayne <2wayne@users.noreply.github.com>
Tue, 30 Aug 2016 16:36:17 +0000 (18:36 +0200)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Tue, 30 Aug 2016 16:36:17 +0000 (09:36 -0700)
Allow selection of the config file directory from the command line

gtk/src/main.c
gtk/src/presets.c
gtk/src/presets.h

index 6e12ed3440bb3001ad0bb64d1785ae3fb6e31188..5b4eae3e4f339fff2f9b78a50be9df1178983ae7 100644 (file)
@@ -661,6 +661,7 @@ typedef struct
 static gchar *dvd_device = NULL;
 static gchar *arg_preset = NULL;
 static gboolean ghb_debug = FALSE;
+static gchar *arg_config_dir = NULL;
 #if defined(_WIN32)
 static gboolean win32_console = FALSE;
 #endif
@@ -670,6 +671,7 @@ static GOptionEntry entries[] =
     { "device", 'd', 0, G_OPTION_ARG_FILENAME, &dvd_device, N_("The device or file to encode"), NULL },
     { "preset", 'p', 0, G_OPTION_ARG_STRING, &arg_preset, N_("The preset values to use for encoding"), NULL },
     { "debug",  'x', 0, G_OPTION_ARG_NONE, &ghb_debug, N_("Spam a lot"), NULL },
+    { "config", 'o', 0, G_OPTION_ARG_STRING, &arg_config_dir, N_("The path to override user config dir"), NULL },
 #if defined(_WIN32)
     { "console",'c', 0, G_OPTION_ARG_NONE, &win32_console, N_("Open a console for debug output"), NULL },
 #endif
@@ -911,6 +913,12 @@ main(int argc, char *argv[])
 #endif
     ghb_udev_init();
 
+    // Override user config dir
+    if (arg_config_dir != NULL)
+    {
+        ghb_override_user_config_dir(arg_config_dir);
+    }
+
     ghb_write_pid_file();
     ud = g_malloc0(sizeof(signal_user_data_t));
     ud->debug = ghb_debug;
index c0e238405b2707f6951accf4160a790261c50976..e6813e9a6aad8d8296a85621d635977edb474a76 100644 (file)
@@ -54,6 +54,7 @@ enum
 
 static GhbValue *prefsDict = NULL;
 static gboolean prefs_modified = FALSE;
+static gchar *override_user_config_dir = NULL;
 
 static void store_prefs(void);
 static void store_presets(void);
@@ -596,7 +597,14 @@ ghb_get_user_config_dir(gchar *subdir)
     const gchar *dir;
     gchar       *config;
 
-    dir = g_get_user_config_dir();
+    if (override_user_config_dir != NULL)
+    {
+        dir = override_user_config_dir;
+    }
+    else
+    {
+        dir = g_get_user_config_dir();
+    }
     if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
     {
         dir    = g_get_home_dir();
@@ -631,6 +639,12 @@ ghb_get_user_config_dir(gchar *subdir)
     return config;
 }
 
+void
+ghb_override_user_config_dir(char *dir)
+{
+    override_user_config_dir = dir;
+}
+
 static void
 write_config_file(const gchar *name, GhbValue *dict)
 {
index 3587543fd1ecf859437cb8b1a106c5311bde02d3..aa3eb2e1be7cff0de657669b879fef8f8b3f371c 100644 (file)
@@ -39,6 +39,7 @@ void ghb_save_queue(GhbValue *queue);
 GhbValue* ghb_load_old_queue(int pid);
 void ghb_remove_old_queue_file(int pid);
 gchar* ghb_get_user_config_dir(gchar *subdir);
+void ghb_override_user_config_dir(char *dir);
 void ghb_settings_to_ui(signal_user_data_t *ud, GhbValue *dict);
 void ghb_clear_presets_selection(signal_user_data_t *ud);
 void ghb_select_preset(GtkBuilder *builder, const char *name);