Skip to content
Snippets Groups Projects
Commit 55091537 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Support wildcards in viewable file type extensions (e.g. * and ?)

Now archive.js can be installed as a sort of "fall-through" file viewer (rather than listing all the supported/possible archive extensions as separately viewable file-types):
File Extension        *                
Command Line          ?archive list %f 
parent 90a4a59f
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #2303 passed
......@@ -1076,8 +1076,8 @@ public:
/* viewfile.cpp */
int viewfile(file_t* f, bool extdesc);
void viewfiles(uint dirnum, char *fspec);
void viewfilecontents(file_t* f);
bool viewfile(const char* path);
bool viewfilecontents(file_t* f);
/* xtrn.cpp */
int external(const char* cmdline, long mode, const char* startup_dir=NULL);
......
......@@ -209,9 +209,14 @@ void xfer_opts()
uifc.helpbuf=
"`Viewable File Types:`\n"
"\n"
"This is a list of file types that have content information that can be\n"
"viewed on the Terminal Server through the execution of an external\n"
"program."
"This is a list of file types (extensions) that have content information\n"
"that can be viewed on the Terminal Server through the execution of an\n"
"external program or script.\n"
"\n"
"The file types/extensions are case insensitive and may contain wildcard\n"
"characters (i.e. `?` or `*`).\n"
"\n"
"Specify the filename argument on the command-line with `%s` or `%f`."
;
i=uifc.list(i,0,0,50,&fview_dflt,&fview_bar,"Viewable File Types",opt);
if(i==-1)
......@@ -245,8 +250,8 @@ void xfer_opts()
continue;
}
memset(cfg.fview[0],0,sizeof(fview_t));
strcpy(cfg.fview[0]->ext,"ZIP");
strcpy(cfg.fview[0]->cmd,"%@unzip -vq %s");
strcpy(cfg.fview[0]->ext,"*");
strcpy(cfg.fview[0]->cmd,"?archive list %f");
}
else {
for(j=cfg.total_fviews;j>i;j--)
......@@ -464,6 +469,7 @@ void xfer_opts()
"\n"
"This is a list of file types that will have a command line executed to\n"
"perform an event upon their download (e.g. trigger a download event).\n"
"\n"
"The file types are specified by `extension` and if one file extension\n"
"is listed more than once, each command line will be executed. The\n"
"command lines must return a error level of 0 (no error) in order\n"
......@@ -597,10 +603,11 @@ void xfer_opts()
uifc.helpbuf=
"`Extractable File Types:`\n"
"\n"
"This is a list of archive file types that can be extracted to the temp\n"
"directory by an external program. The file types are specified by their\n"
"extension. For each file type you must specify the command line used to\n"
"extract the file(s).\n"
"List of external extraction methods available by file type/extension.\n"
"\n"
"Support for extracting archives of common formats (i.e. `zip`, etc.)\n"
"is built-into Synchronet (requires no external program), however may be\n"
"extended via external archive/extraction programs configured here."
;
i=uifc.list(i,0,0,50,&fextr_dflt,&fextr_bar,"Extractable File Types",opt);
if(i==-1)
......@@ -717,9 +724,11 @@ void xfer_opts()
uifc.helpbuf=
"`Compressible File Types:`\n"
"\n"
"This is a list of compression methods available for different file types.\n"
"These will be used for items such as creating QWK packets, temporary\n"
"files from the transfer section, and more.\n"
"List of external compression methods available by file type/extension.\n"
"\n"
"Support for creating archives of common formats (i.e. `zip`, `7z`, `tgz`, `tbz`)\n"
"is built-into Synchronet (requires no external program), however may be\n"
"extended via external compression/archive programs configured here."
;
i=uifc.list(i,0,0,50,&fcomp_dflt,&fcomp_bar,"Compressible File Types",opt);
if(i==-1)
......
......@@ -85,67 +85,47 @@ int sbbs_t::viewfile(file_t* f, bool ext)
}
/*****************************************************************************/
/* View viewable file types from dir 'dirnum' */
/* 'fspec' must be padded */
/*****************************************************************************/
void sbbs_t::viewfiles(uint dirnum, char *fspec)
bool sbbs_t::viewfile(const char* path)
{
char tmp[512];
char viewcmd[256];
int i;
curdirnum=dirnum; /* for ARS */
SAFEPRINTF2(viewcmd,"%s%s",cfg.dir[dirnum]->path,fspec);
if(!fexist(viewcmd)) {
if(!fexist(path)) {
bputs(text[FileNotFound]);
return;
return false;
}
char* file_ext = getfext(fspec);
char* file_ext = getfext(path);
if(file_ext == NULL) {
bprintf(text[NonviewableFile], fspec);
return;
bprintf(text[NonviewableFile], getfname(path));
return false;
}
for(i=0;i<cfg.total_fviews;i++)
if(!stricmp(file_ext + 1, cfg.fview[i]->ext) && chk_ar(cfg.fview[i]->ar,&useron,&client)) {
if(wildmatchi(file_ext + 1, cfg.fview[i]->ext, /* path: */false) && chk_ar(cfg.fview[i]->ar,&useron,&client)) {
SAFECOPY(viewcmd,cfg.fview[i]->cmd);
break;
break;
}
if(i==cfg.total_fviews) {
if(i >= cfg.total_fviews) {
bprintf(text[NonviewableFile], file_ext);
return;
return false;
}
SAFEPRINTF2(tmp, "%s%s", cfg.dir[dirnum]->path, fspec);
if((i=external(cmdstr(viewcmd,tmp,tmp,NULL),EX_STDIO|EX_SH))!=0)
if((i=external(cmdstr(viewcmd, path, path, NULL), EX_STDIO|EX_SH))!=0) {
errormsg(WHERE,ERR_EXEC,viewcmd,i); /* must have EX_SH to ^C */
return false;
}
return true;
}
/****************************************************************************/
/****************************************************************************/
void sbbs_t::viewfilecontents(file_t* f)
bool sbbs_t::viewfilecontents(file_t* f)
{
char cmd[128];
char path[MAX_PATH+1];
char* ext;
int i;
char path[MAX_PATH + 1];
getfilepath(&cfg, f, path);
if(getfilesize(&cfg, f) < 1) {
bprintf(text[FileDoesNotExist], path);
return;
}
if((ext=getfext(path))!=NULL) {
ext++;
for(i=0;i<cfg.total_fviews;i++) {
if(!stricmp(ext,cfg.fview[i]->ext)
&& chk_ar(cfg.fview[i]->ar,&useron,&client)) {
SAFECOPY(cmd,cfg.fview[i]->cmd);
break;
}
}
}
if(ext==NULL || i==cfg.total_fviews)
bprintf(text[NonviewableFile],ext);
else
if((i=external(cmdstr(cmd,path,path,NULL),EX_STDIO))!=0)
errormsg(WHERE,ERR_EXEC,cmdstr(cmd,path,path,NULL),i);
uint savedir = curdirnum;
curdirnum = f->dir; /* for ARS */
bool result = viewfile(path);
curdirnum = savedir;
return result;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment