| 854 | } |
| 855 | |
| 856 | static void |
| 857 | set_destination_settings(signal_user_data_t *ud, GhbValue *settings) |
| 858 | { |
| 859 | const gchar *extension, *dest_file, *dest_dir; |
| 860 | gchar *filename; |
| 861 | |
| 862 | extension = get_extension(ud, settings); |
| 863 | |
| 864 | ghb_log_func(); |
| 865 | dest_file = ghb_dict_get_string(ud->settings, "dest_file"); |
| 866 | if (dest_file == NULL) |
| 867 | { |
| 868 | // Initialize destination filename if it has no value yet. |
| 869 | // If auto-naming is disabled, this will be the default filename. |
| 870 | GString *str = g_string_new(""); |
| 871 | const gchar *vol_name; |
| 872 | vol_name = ghb_dict_get_string(settings, "volume"); |
| 873 | g_string_append_printf(str, "%s", vol_name); |
| 874 | g_string_append_printf(str, ".%s", extension); |
| 875 | filename = g_string_free(str, FALSE); |
| 876 | ghb_dict_set_string(settings, "dest_file", filename); |
| 877 | g_free(filename); |
| 878 | } |
| 879 | ghb_dict_set(settings, "dest_dir", ghb_value_dup( |
| 880 | ghb_dict_get_value(ud->prefs, "destination_dir"))); |
| 881 | if (ghb_dict_get_bool(ud->prefs, "auto_name")) |
| 882 | { |
| 883 | GString *str = g_string_new(""); |
| 884 | const gchar *p; |
| 885 | |
| 886 | p = ghb_dict_get_string(ud->prefs, "auto_name_template"); |
| 887 | // {source-path} is only allowed as the first element of the |
| 888 | // template since the path must come first in the filename |
| 889 | if (p != NULL && |
| 890 | (!strncasecmp(p, "{source-path}", strlen("{source-path}")) || |
| 891 | !strncasecmp(p, "{source_path}", strlen("{source_path}")))) |
| 892 | { |
| 893 | const char *source = ghb_get_scan_source(); |
| 894 | if (source != NULL) |
| 895 | { |
| 896 | char * dirname = g_path_get_dirname(source); |
| 897 | // if dirname is a directory and it is writable... |
| 898 | if (dirname != NULL && |
| 899 | g_file_test(dirname, G_FILE_TEST_IS_DIR) && |
| 900 | access(dirname, W_OK) == 0) |
| 901 | { |
| 902 | ghb_dict_set_string(settings, "dest_dir", dirname); |
| 903 | } |
| 904 | g_free(dirname); |
| 905 | } |
| 906 | p += strlen("{source-path}"); |
| 907 | } |
| 908 | while (*p) |
| 909 | { |
| 910 | if (!strncasecmp(p, "{source}", strlen("{source}"))) |
| 911 | { |
| 912 | const gchar *vol_name; |
| 913 | vol_name = ghb_dict_get_string(settings, "volume"); |
no test coverage detected