X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=gtk%2Fsrc%2Fpresets.c;h=66f69a748badedbb635503cb4b0fa06e12be09fe;hb=0884cb45aeeb60a46effe1d1056a61fe68300ea7;hp=b59efca79ca72ef2d0fef5bc2089d7062e6b6425;hpb=52d2419a149fd0ccf4f0baddd2b17dbc1c516fb0;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/gtk/src/presets.c b/gtk/src/presets.c index b59efca7..66f69a74 100644 --- a/gtk/src/presets.c +++ b/gtk/src/presets.c @@ -1151,6 +1151,113 @@ ghb_lock_file(const gchar *name) #endif } +void +ghb_write_pid_file() +{ +#if !defined(_WIN32) + gchar *config, *path; + pid_t pid; + FILE *fp; + int fd, lock; + + pid = getpid(); + + config = ghb_get_user_config_dir(NULL); + path = g_strdup_printf ("%s/ghb.pid.%d", config, pid); + + fp = g_fopen(path, "w"); + fprintf(fp, "%d\n", pid); + fclose(fp); + + fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); + lock = lockf(fd, F_TLOCK, 0); + + g_free(config); + g_free(path); +#endif +} + +void +ghb_unlink_pid_file(int pid) +{ + gchar *config, *path; + + config = ghb_get_user_config_dir(NULL); + path = g_strdup_printf ("%s/ghb.pid.%d", config, pid); + + if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) + { + g_unlink(path); + } + + g_free(config); + g_free(path); +} + +int +ghb_find_pid_file() +{ + const gchar *file; + gchar *config; + + config = ghb_get_user_config_dir(NULL); + + if (g_file_test(config, G_FILE_TEST_IS_DIR)) + { + GDir *gdir = g_dir_open(config, 0, NULL); + file = g_dir_read_name(gdir); + while (file) + { + if (strncmp(file, "ghb.pid.", 8) == 0) + { + gchar *path; + pid_t my_pid; + int pid; + + sscanf(file, "ghb.pid.%d", &pid); + my_pid = getpid(); + if (my_pid == pid) + { + file = g_dir_read_name(gdir); + continue; + } + path = g_strdup_printf("%s/%s", config, file); + +#if !defined(_WIN32) + int fd, lock = 1; + + fd = open(path, O_RDWR); + if (fd >= 0) + { + lock = lockf(fd, F_TLOCK, 0); + } + if (lock == 0) + { + close(fd); + g_dir_close(gdir); + g_unlink(path); + g_free(path); + g_free(config); + return pid; + } + g_free(path); + close(fd); +#else + g_dir_close(gdir); + g_unlink(path); + g_free(path); + g_free(config); + return pid; +#endif + } + file = g_dir_read_name(gdir); + } + g_dir_close(gdir); + } + g_free(config); + return -1; +} + static void remove_plist(const gchar *name) { @@ -1806,19 +1913,61 @@ remove_std_presets(signal_user_data_t *ud) void ghb_save_queue(GValue *queue) { - store_plist(queue, "queue"); + pid_t pid; + char *path; + + pid = getpid(); + path = g_strdup_printf ("queue.%d", pid); + store_plist(queue, path); + g_free(path); } GValue* ghb_load_queue() { - return load_plist("queue"); + GValue *queue; + pid_t pid; + char *path; + + pid = getpid(); + path = g_strdup_printf ("queue.%d", pid); + queue = load_plist(path); + g_free(path); + return queue; +} + +GValue* +ghb_load_old_queue(int pid) +{ + GValue *queue; + char *path; + + path = g_strdup_printf ("queue.%d", pid); + queue = load_plist(path); + g_free(path); + return queue; +} + +void +ghb_remove_old_queue_file(int pid) +{ + char *path; + + path = g_strdup_printf ("queue.%d", pid); + remove_plist(path); + g_free(path); } void ghb_remove_queue_file() { - remove_plist("queue"); + pid_t pid; + char *path; + + pid = getpid(); + path = g_strdup_printf ("queue.%d", pid); + remove_plist(path); + g_free(path); } typedef struct @@ -2528,7 +2677,7 @@ import_xlat_preset(GValue *dict) const GValue *gval; vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider")); - if (vquality < 1.0) + if (vquality > 0.0 && vquality < 1.0) { gint vcodec; @@ -3242,7 +3391,6 @@ preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) return; } array = ghb_plist_parse_file(filename); - g_free(filename); import_xlat_presets(array); presets_clear_default(array); @@ -3292,8 +3440,10 @@ preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) ghb_settings_set_string(ud->settings, "ExportDirectory", dir); ghb_pref_save(ud->settings, "ExportDirectory"); } + g_free(filename); g_free(exportDir); g_free(dir); + store_presets(); } gtk_widget_destroy(dialog); }