gchar *unique_filename_simple(const gchar *path) { gchar *unique; const gchar *name; const gchar *ext; if (!path) return NULL; name = filename_from_path(path); if (!name) return NULL; ext = extension_from_path(name); if (!ext) { unique = unique_filename(path, NULL, "_", TRUE); } else { gchar *base; base = remove_extension_from_path(path); unique = unique_filename(base, ext, "_", TRUE); g_free(base); } return unique; }
static void fr_command_cfile_list (FrCommand *comm) { FrCommandCFile *comm_cfile = FR_COMMAND_CFILE (comm); if (is_mime_type (comm->mime_type, "application/x-gzip")) { /* gzip let us known the uncompressed size */ fr_process_set_out_line_func (FR_COMMAND (comm)->process, list__process_line, comm); fr_process_begin_command (comm->process, "gzip"); fr_process_add_arg (comm->process, "-l"); fr_process_add_arg (comm->process, "-q"); fr_process_add_arg (comm->process, comm->filename); fr_process_end_command (comm->process); fr_process_start (comm->process); } else { /* ... other compressors do not support this feature so * simply use the archive size, suboptimal but there is no * alternative. */ FileData *fdata; char *filename; fdata = file_data_new (); filename = remove_extension_from_path (comm->filename); fdata->full_path = g_strconcat ("/", file_name_from_path (filename), NULL); g_free (filename); fdata->original_path = fdata->full_path + 1; fdata->link = NULL; fdata->size = get_file_size_for_path (comm->filename); fdata->modified = get_file_mtime_for_path (comm->filename); fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); comm_cfile->error.type = FR_PROC_ERROR_NONE; comm_cfile->error.status = 0; g_signal_emit_by_name (G_OBJECT (comm), "done", comm->action, &comm_cfile->error); } }
static void list__process_line (char *line, gpointer data) { FrCommand *comm = FR_COMMAND (data); FileData *fdata; char **fields; char *filename; fdata = file_data_new (); fields = split_line (line, 2); if (strcmp (fields[1], "-1") != 0) fdata->size = g_ascii_strtoull (fields[1], NULL, 10); g_strfreev (fields); if (fdata->size == 0) fdata->size = get_file_size (comm->filename); filename = get_uncompressed_name_from_archive (comm, comm->filename); if (filename == NULL) filename = remove_extension_from_path (comm->filename); fdata->full_path = g_strconcat ("/", file_name_from_path (filename), NULL); g_free (filename); fdata->original_path = fdata->full_path + 1; fdata->link = NULL; fdata->modified = get_file_mtime_for_path (comm->filename); fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
static void collection_window_update_title(CollectWindow *cw) { gboolean free_name = FALSE; gchar *name; gchar *buf; if (!cw) return; if (file_extension_match(cw->cd->name, GQ_COLLECTION_EXT)) { name = remove_extension_from_path(cw->cd->name); free_name = TRUE; } else { name = cw->cd->name; } buf = g_strdup_printf(_("%s - Collection - %s"), name, GQ_APPNAME); if (free_name) g_free(name); gtk_window_set_title(GTK_WINDOW(cw->window), buf); g_free(buf); }
static void fr_command_cfile_extract (FrCommand *comm, const char *from_file, GList *file_list, const char *dest_dir, gboolean overwrite, gboolean skip_older, gboolean junk_paths) { char *temp_dir; char *dest_file; char *temp_file; char *uncompr_file; char *compr_file; /* copy file to the temp dir, remove the already existing file first */ temp_dir = get_temp_work_dir (NULL); temp_file = g_strconcat (temp_dir, "/", file_name_from_path (comm->filename), NULL); fr_process_begin_command (comm->process, "cp"); fr_process_add_arg (comm->process, "-f"); fr_process_add_arg (comm->process, comm->filename); fr_process_add_arg (comm->process, temp_file); fr_process_end_command (comm->process); /* uncompress the file */ if (is_mime_type (comm->mime_type, "application/x-gzip")) { fr_process_begin_command (comm->process, "gzip"); fr_process_add_arg (comm->process, "-f"); fr_process_add_arg (comm->process, "-d"); fr_process_add_arg (comm->process, "-n"); fr_process_add_arg (comm->process, temp_file); fr_process_end_command (comm->process); } else if (is_mime_type (comm->mime_type, "application/x-bzip")) { fr_process_begin_command (comm->process, "bzip2"); fr_process_add_arg (comm->process, "-f"); fr_process_add_arg (comm->process, "-d"); fr_process_add_arg (comm->process, temp_file); fr_process_end_command (comm->process); } else if (is_mime_type (comm->mime_type, "application/x-compress")) { if (is_program_in_path ("gzip")) { fr_process_begin_command (comm->process, "gzip"); fr_process_add_arg (comm->process, "-d"); fr_process_add_arg (comm->process, "-n"); } else fr_process_begin_command (comm->process, "uncompress"); fr_process_add_arg (comm->process, "-f"); fr_process_add_arg (comm->process, temp_file); fr_process_end_command (comm->process); } else if (is_mime_type (comm->mime_type, "application/x-lzip")) { fr_process_begin_command (comm->process, "lzip"); fr_process_add_arg (comm->process, "-f"); fr_process_add_arg (comm->process, "-d"); fr_process_add_arg (comm->process, temp_file); fr_process_end_command (comm->process); } else if (is_mime_type (comm->mime_type, "application/x-lzma")) { fr_process_begin_command (comm->process, "lzma"); fr_process_add_arg (comm->process, "-f"); fr_process_add_arg (comm->process, "-d"); fr_process_add_arg (comm->process, temp_file); fr_process_end_command (comm->process); } else if (is_mime_type (comm->mime_type, "application/x-xz")) { fr_process_begin_command (comm->process, "xz"); fr_process_add_arg (comm->process, "-f"); fr_process_add_arg (comm->process, "-d"); fr_process_add_arg (comm->process, temp_file); fr_process_end_command (comm->process); } else if (is_mime_type (comm->mime_type, "application/x-lzop")) { fr_process_begin_command (comm->process, "lzop"); fr_process_set_working_dir (comm->process, temp_dir); fr_process_add_arg (comm->process, "-d"); fr_process_add_arg (comm->process, "-fU"); fr_process_add_arg (comm->process, "--no-stdin"); fr_process_add_arg (comm->process, temp_file); fr_process_end_command (comm->process); } else if (is_mime_type (comm->mime_type, "application/x-rzip")) { fr_process_begin_command (comm->process, "rzip"); fr_process_add_arg (comm->process, "-f"); fr_process_add_arg (comm->process, "-d"); fr_process_add_arg (comm->process, temp_file); fr_process_end_command (comm->process); } /* copy uncompress file to the dest dir */ uncompr_file = remove_extension_from_path (temp_file); compr_file = get_uncompressed_name_from_archive (comm, comm->filename); if (compr_file == NULL) compr_file = remove_extension_from_path (file_name_from_path (comm->filename)); dest_file = g_strconcat (dest_dir, "/", compr_file, NULL); fr_process_begin_command (comm->process, "cp"); fr_process_add_arg (comm->process, "-f"); fr_process_add_arg (comm->process, uncompr_file); fr_process_add_arg (comm->process, dest_file); fr_process_end_command (comm->process); /* remove the temp dir */ fr_process_begin_command (comm->process, "rm"); fr_process_set_sticky (comm->process, TRUE); fr_process_add_arg (comm->process, "-rf"); fr_process_add_arg (comm->process, temp_dir); fr_process_end_command (comm->process); g_free (dest_file); g_free (compr_file); g_free (uncompr_file); g_free (temp_file); g_free (temp_dir); }