1 /* 2 * Copyright (c) 2008 Giuseppe Torelli <colossus73@gmail.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 17 * MA 02110-1301 USA. 18 */ 19 20 #ifndef XARCHIVER_ARCHIVE_H 21 #define XARCHIVER_ARCHIVE_H 22 23 #include <gtk/gtk.h> 24 25 typedef enum 26 { 27 XARCHIVETYPE_FIRST, 28 XARCHIVETYPE_7ZIP = XARCHIVETYPE_FIRST, 29 XARCHIVETYPE_AR, 30 XARCHIVETYPE_ARJ, 31 XARCHIVETYPE_BZIP2, 32 XARCHIVETYPE_COMPRESS, 33 XARCHIVETYPE_CPIO, 34 XARCHIVETYPE_GZIP, 35 XARCHIVETYPE_LHA, 36 XARCHIVETYPE_LRZIP, 37 XARCHIVETYPE_LZ4, 38 XARCHIVETYPE_LZIP, 39 XARCHIVETYPE_LZMA, 40 XARCHIVETYPE_LZOP, 41 XARCHIVETYPE_RAR, 42 XARCHIVETYPE_RPM, 43 XARCHIVETYPE_TAR, 44 XARCHIVETYPE_TAR_BZIP2, 45 XARCHIVETYPE_TAR_COMPRESS, 46 XARCHIVETYPE_TAR_GZIP, 47 XARCHIVETYPE_TAR_LRZIP, 48 XARCHIVETYPE_TAR_LZ4, 49 XARCHIVETYPE_TAR_LZIP, 50 XARCHIVETYPE_TAR_LZMA, 51 XARCHIVETYPE_TAR_LZOP, 52 XARCHIVETYPE_TAR_XZ, 53 XARCHIVETYPE_TAR_ZSTD, 54 XARCHIVETYPE_XZ, 55 XARCHIVETYPE_ZIP, 56 XARCHIVETYPE_ZSTD, 57 XARCHIVETYPE_TYPES, 58 XARCHIVETYPE_UNKNOWN, 59 XARCHIVETYPE_NOT_FOUND 60 } XArchiveType; 61 62 typedef enum 63 { 64 XARCHIVESTATUS_IDLE, 65 XARCHIVESTATUS_LIST, 66 XARCHIVESTATUS_TEST, 67 XARCHIVESTATUS_EXTRACT, 68 XARCHIVESTATUS_ADD, 69 XARCHIVESTATUS_DELETE, 70 XARCHIVESTATUS_SFX, 71 XARCHIVESTATUS_RELOAD, 72 XARCHIVESTATUS_ERROR 73 } XArchiveStatus; 74 75 typedef enum 76 { 77 XA_CHILD_EXIT, 78 XA_CHILD_STDOUT, 79 XA_CHILD_STDERR, 80 XA_CHILD_PROCS 81 } XAChildProcess; 82 83 typedef struct _XArchive XArchive; 84 85 typedef void (*ask_func)(XArchive *); 86 typedef void (*list_func)(XArchive *); 87 typedef void (*parse_output_func)(gchar *, XArchive *); 88 typedef void (*test_func)(XArchive *); 89 typedef gboolean (*extract_func)(XArchive *, GSList *); 90 typedef void (*add_func)(XArchive *, GSList *, gchar *); 91 typedef void (*delete_func)(XArchive *, GSList *); 92 93 typedef struct 94 { 95 gchar *program[2]; 96 gboolean is_compressor; 97 GSList *type; 98 GSList *glob; 99 GSList *tags; 100 ask_func ask; 101 list_func list; 102 test_func test; 103 extract_func extract; 104 add_func add; 105 delete_func delete; 106 } XArchiver; 107 108 typedef struct 109 { 110 XArchiveType type; 111 gushort tag; 112 } ArchiveType; 113 114 typedef struct _XEntry XEntry; 115 116 struct _XEntry 117 { 118 gchar *filename; 119 gboolean is_dir; 120 gboolean is_encrypted; 121 gpointer columns; 122 XEntry *child; 123 XEntry *prev; 124 XEntry *next; 125 }; 126 127 typedef struct _XAClipboard XAClipboard; 128 129 struct _XArchive 130 { 131 /* characteristics */ 132 XArchiveType type; 133 gushort tag; 134 XArchiveStatus status; 135 /* data */ 136 XEntry *root_entry; 137 XEntry *current_entry; 138 /* user interface */ 139 GtkWidget *page; 140 GtkWidget *treeview; 141 GtkTreeModel *model; 142 GtkListStore *liststore; 143 gboolean sorted; 144 guint columns; 145 guint size_column; 146 GType *column_types; 147 GtkCellRenderer *pixbuf_renderer; 148 GtkCellRenderer *text_renderer; 149 GSList *back; 150 GSList *forward; 151 XAClipboard *clipboard; 152 /* environment */ 153 gchar *path[3]; // 0: original, 1: escaped, 2: working copy 154 gchar *working_dir; 155 gchar *destination_path; 156 gchar *extraction_dir; // (free before use) 157 gchar *location_path; 158 /* properties */ 159 guint files; 160 guint64 files_size; 161 gboolean has_password; 162 gchar *password; 163 gboolean has_comment; 164 GString *comment; 165 gushort compression; 166 /* capabilities */ // 0: extract, 1: add 167 gboolean can_test; // can test an archive for integrity 168 gboolean can_extract; // can extract files from an archive 169 gboolean can_add; // can add files to an archive 170 gboolean can_delete; // can delete files from an archive 171 // can_rename see macro below: can_extract AND can_delete AND can_add 172 gboolean can_sfx; // can create a self-extracting archive 173 gboolean can_password; // can password protect an archive 174 gboolean can_full_path[2]; // can carry out activity with or without full path 175 gboolean can_touch; // can modify timestamp of files on extraction 176 gboolean can_overwrite; // can overwrite files on extraction 177 gboolean can_update[2]; // can limit activity to only changed or new files 178 gboolean can_freshen[2]; // can limit activity to only changed files 179 gboolean can_move; // can delete files after adding 180 gboolean can_solid; // can create a solid archive 181 /* instructions */ 182 gboolean do_full_path; 183 gboolean do_touch; 184 gboolean do_overwrite; 185 gboolean do_update; 186 gboolean do_freshen; 187 gboolean do_move; 188 gboolean do_solid; 189 /* child process */ 190 gchar *child_dir; // (free and set NULL after use) 191 GPid child_pid; 192 guint child_ref; 193 gint child_fdout; 194 gint child_fderr; 195 gchar *command; // (free before use) 196 GSList *output; 197 /* (un)compressor interface */ 198 XArchiver *archiver; 199 parse_output_func parse_output; 200 }; 201 202 extern XArchive *archive[]; 203 204 #define can_rename(archive) ((archive)->can_extract && (archive)->can_delete && (archive)->can_add) 205 206 #define XA_CLIPBOARD (gdk_atom_intern_static_string("XARCHIVER_OWN_CLIPBOARD")) 207 #define XA_INFO_LIST (gdk_atom_intern_static_string("application/xarchiver-info-list")) 208 209 typedef enum 210 { 211 XA_CLIPBOARD_CUT, 212 XA_CLIPBOARD_COPY 213 } XAClipboardMode; 214 215 struct _XAClipboard 216 { 217 XAClipboardMode mode; 218 GSList *files; 219 XArchive *target; 220 }; 221 222 gchar *xa_build_full_path_name_from_entry(XEntry *); 223 void xa_clean_archive_structure(XArchive *); 224 gchar *xa_create_containing_directory(XArchive *, const gchar *); 225 gboolean xa_create_working_directory(XArchive *); 226 void xa_detect_encrypted_archive(XArchive *); 227 void xa_fill_dir_sidebar(XArchive *, gboolean); 228 void xa_fill_list_with_recursed_entries(XEntry *, GSList **); 229 gint xa_find_archive_index(gint); 230 XEntry *xa_find_entry_from_dirpath(XArchive *, const gchar *); 231 void xa_free_entry(XArchive *, XEntry *); 232 gboolean xa_get_compressed_tar_type(XArchiveType *); 233 gint xa_get_new_archive_idx(); 234 gboolean xa_has_containing_directory(XArchive *); 235 XArchive *xa_init_archive_structure(ArchiveType); 236 gboolean xa_run_command(XArchive *, const gchar *); 237 XEntry *xa_set_archive_entries_for_each_row(XArchive *, const gchar *, gpointer *); 238 void xa_dir_sidebar_row_selected(GtkTreeSelection *, gpointer); 239 void xa_dir_sidebar_select_row(XEntry *); 240 gint xa_sort_dirs_before_files(GtkTreeModel *, GtkTreeIter *, GtkTreeIter *, XArchive *); 241 void xa_spawn_async_process(XArchive *, const gchar *); 242 243 #endif 244