int lock_file(char *file_name, int is_temp) { int fd; char *temp; char buf[ MAX_FILE_NAME_LENGTH ]; fd = open(file_name, O_CREAT | O_EXCL, S_IWUSR | S_IRUSR | S_IRGRP | S_IWGRP | S_IROTH); if(fd >= 0) { close(fd); unlink(file_name); } else { if(errno == EEXIST) if(config.ask_when_file_exists == FALSE || is_temp == TRUE) { if(config.make_mp3_from_existing_wav) { return 1; } /* Prepend config.prepend_char until we succeed open() */ if(strlen(file_name) > MAX_FILE_NAME_LENGTH + MAX_FILE_PATH_LENGTH - 2) { return - 1; } else { temp = file_name_without_path(file_name); strcpy(buf, temp); temp[ 0 ] = config.prepend_char; strcpy(temp + 1, buf); /* now try again */ if(lock_file(file_name, is_temp) < 0) { return - 1; } } } else { if(config.make_mp3_from_existing_wav) { return 1; } if(dialog_handler(WIDGET_CREATE, FALSE, DL_OVERWRITE_CONFIRM, FALSE, file_name_without_path(file_name), NULL, 0) == TRUE) /* Just return. Cdparanoia or 8hz-mp3 will overwrite on it */ { return 0; } /* Let's ask the user what s/he wants */ temp = file_name_without_path(file_name); strcpy(buf, temp); if(dialog_handler(WIDGET_CREATE, TRUE, DL_ENTER_FILE_NAME, TRUE, buf, buf, sizeof(buf) - 1) == FALSE) /* The user does not want to continue. return error */ { return - 1; } strcpy(temp, buf); /* now try again */ if(lock_file(file_name, is_temp) < 0) { return - 1; } } else /* an other error (maybe directory not existent */ { err_handler(CREATING_FILE_ERROR, file_name); return - 1; } } return 0; }
void write_config (void) { FILE *file; int fd; int i; char *str; char t_char; float t_float; int t_int; GtkWidget *main_window = main_window_handler(MW_REQUEST_MW, NULL, NULL); fd = open (construct_file_name (getenv ("HOME"), ".ripperXrc"), O_WRONLY | O_TRUNC); if (fd < 0) { if (errno == ENOENT) { if (dialog_handler (WIDGET_CREATE, FALSE, DL_CREATE_CONFIG_CONFIRM, FALSE, NULL, NULL, 0) == FALSE) return; fd = open (construct_file_name (getenv ("HOME"), ".ripperXrc"), O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR); if (fd < 0) { err_handler (GTK_WINDOW(main_window), CONFIG_CREATION_ERR, ""); return; } } else err_handler (GTK_WINDOW(main_window), CONFIG_OPEN_ERR, ""); } if ((file = fdopen (fd, "w")) == NULL) { err_handler (GTK_WINDOW(main_window), FDOPEN_ERR, "Cannot re-open config file as a stream"); close (fd); return; } fputs ("//\n", file); fputs ("// ~/.ripperXrc\n", file); fputs ("// This is the resource file for ripperX.\n", file); fputs ("// If you edit this file with an editor, you must leave all\n", file); fputs ("// parameters in the order in which they appear. Also note\n", file); fputs ("// that this file is overwritten each time ripperX is run.\n", file); fputs ("//\n// You can configure everything in the config menu within ripperX.\n", file); fputs ("//\n\n", file); fprintf (file, "//-V %s\n\n", VERSION); for (i = 0; i < num_entry; i++) { switch (config_rw_data[i].type) { case STRING: str = (char *) config_rw_data[i].m_id; fprintf (file, "%s = %s\n", config_rw_data[i].f_id, str); break; case CHAR: t_char = *(char *) config_rw_data[i].m_id; fprintf (file, "%s = %c\n", config_rw_data[i].f_id, t_char); break; case FLOAT: t_float = *(float *) config_rw_data[i].m_id; fprintf (file, "%s = %f\n", config_rw_data[i].f_id, t_float); break; case INT: t_int = *(int *) config_rw_data[i].m_id; fprintf (file, "%s = %d\n", config_rw_data[i].f_id, t_int); break; } } fclose (file); return; }
void dl_callback (GtkWidget * widget, gpointer callback_data) { dialog_handler (DL_OK_PRESSED, TRUE, 0, TRUE, NULL, NULL, 0); }