Support extract, list archives with default utils

This commit is contained in:
Arun Prakash Jana 2019-07-27 16:40:30 +05:30
parent 8e00d74259
commit de931db8a0
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 33 additions and 23 deletions

View File

@ -337,10 +337,12 @@ static char g_tmpfpath[TMP_LEN_MAX] __attribute__ ((aligned));
#define OPENER 2 #define OPENER 2
#define ATOOL 3 #define ATOOL 3
#define BSDTAR 4 #define BSDTAR 4
#define LOCKER 5 #define UNZIP 5
#define CMATRIX 6 #define TAR 6
#define NLAUNCH 7 #define LOCKER 7
#define UNKNOWN 8 #define CMATRIX 8
#define NLAUNCH 9
#define UNKNOWN 10
/* Utilities to open files, run actions */ /* Utilities to open files, run actions */
static char * const utils[] = { static char * const utils[] = {
@ -355,6 +357,8 @@ static char * const utils[] = {
#endif #endif
"atool", "atool",
"bsdtar", "bsdtar",
"unzip",
"tar",
#ifdef __APPLE__ #ifdef __APPLE__
"bashlock", "bashlock",
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
@ -2589,31 +2593,37 @@ static bool show_mediainfo(const char *fpath, const char *arg)
return TRUE; return TRUE;
} }
/* Extracts or lists archive */ /* List or extract archive */
static bool handle_archive(char *fpath, const char *dir, char op) static void handle_archive(char *fpath, const char *dir, char op)
{ {
char larg[] = "-tf"; char arg[] = "-tvf"; /* options for tar/bsdtar to list files */
char xarg[] = "-xf";
char *util; char *util;
if (getutil(utils[ATOOL])) { if (getutil(utils[ATOOL])) {
util = utils[ATOOL]; util = utils[ATOOL];
larg[1] = op; arg[1] = op;
larg[2] = xarg[2] = '\0'; arg[2] = '\0';
} else if (getutil(utils[BSDTAR])) } else if (getutil(utils[BSDTAR])) {
util = utils[BSDTAR]; util = utils[BSDTAR];
else if (op == 'x')
return FALSE; arg[1] = op;
} else if (is_suffix(fpath, ".zip")) {
if (op == 'x') { /* extract */ util = utils[UNZIP];
spawn(util, xarg, fpath, dir, F_NORMAL); arg[1] = (op == 'l') ? 'v' /* verbose listing */ : '\0';
} else { /* list */ arg[2] = '\0';
exitcurses(); } else {
get_output(NULL, 0, util, larg, fpath, TRUE); util = utils[TAR];
refresh(); if (op == 'x')
arg[1] = op;
} }
return TRUE; if (op == 'x') { /* extract */
spawn(util, arg, fpath, dir, F_NORMAL);
} else { /* list */
exitcurses();
get_output(NULL, 0, util, arg, fpath, TRUE);
refresh();
}
} }
static char *visit_parent(char *path, char *newpath, int *presel) static char *visit_parent(char *path, char *newpath, int *presel)
@ -3885,10 +3895,10 @@ nochange:
setdirwatch(); setdirwatch();
goto nochange; goto nochange;
case SEL_ARCHIVELS: case SEL_ARCHIVELS:
r = handle_archive(newpath, path, 'l'); handle_archive(newpath, path, 'l');
break; break;
case SEL_EXTRACT: case SEL_EXTRACT:
r = handle_archive(newpath, path, 'x'); handle_archive(newpath, path, 'x');
break; break;
case SEL_REDRAW: case SEL_REDRAW:
if (ndents) if (ndents)