home *** CD-ROM | disk | FTP | other *** search
Wrap
/* $VER: ProcessFile.rexx 0.13 (4.12.94) * process a file according to the extension */ /* Authors Osma Ahvenlampi, Michael Van Elst, Dan Murrell Jr. * View a file after de-archiving enhancement by Alejandro Garza */ /* This is the program used to view the file if no match is found */ file.default = "SYS:Utilities/MultiView" /* If this is set to 1, the user will be asked whether he wants to delete * the file after it has been processed */ file.delete = 1 /* If this is set to 1, the user will be prompted if he/she wants to view * any of the files in the archive after unpacking */ file.arcview = 1 /* list of supported archivers */ file.archive = "LHA LZH GZ Z ZIP" /* where you would like the archive unpacked by default */ file.unpackdir = "RAM:" /* full paths to known (un)packers */ archiver.lha = "LhA" archiver.gzip = "GZip" archiver.zip = "UnZip" /* next is the list of extensions and the programs used to show them * list the extensions in upper case */ file.1.type = "ILBM HAM GIF" file.1.viewer = "MultiView >NIL:" file.2.type = "WAV AU 8SVX" file.2.viewer = "Play16 >NIL:" /* LOTS better than OPlay... */ file.3.type = "JPG JPEG" file.3.viewer = "MultiView >NIL:" file.4.type = "GUIDE TXT DOC" file.4.viewer = "SYS:Utilities/MultiView" file.5.type = "MOD MED" file.5.viewer = "SYS:Utilities/MultiView" file.6.type = "MPG MPEG" file.6.viewer = "mp -dither ham6" /* this is the number of the last type */ file.num = 6 /* get filename */ parse arg '"' completename '"' '"' pubscreen '"' if completename="" then parse arg completename if ~exists(completename) then exit if pubscreen="" then pubscreen = "Workbench" viewed = 0 processed = 0 if ~show(l, 'rexxsupport.library') then do if ~addlib('rexxsupport.library', 0, -30) then do address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File Error" BODY="Could not execute macro*nlibs:rexxsupport.library not found" GADGETS="OK" >NIL:' exit 10 end end call CheckExt /* test it against known archivers/packers */ if (extension ~= "") & (find( file.archive, extension ) > 0) then do viewed = 1 call UnPack end /* test it against known file types */ if ~viewed & (extension ~= "") then do i = 1 to file.num while ~viewed if find( file.i.type, extension ) > 0 then do viewed = 1 address command file.i.viewer '"'completename'"' if rc = 0 then processed = 1 end end if ~viewed then do /* if the type wasn't recognised, try the default viewer on it */ address command file.default '"'completename'"' if rc = 0 then processed = 1 end call DeleteFile exit UnPack: if (extension = "LHA") | (extension = "LZH") then do address command 'LhA v "'completename'" >T:LhaContents.tmp' address command file.default 'T:LhaContents.tmp' address command 'C:Delete >NIL: T:LhaContents.tmp' address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="Un-LHA file 'completename'?" GADGETS="Yes|No" >T:reqchoice.unlha' call open(choicefile, 'T:reqchoice.unlha', 'R') answer = readch(choicefile, 1) call close(choicefile) address command 'C:Delete >NIL: T:reqchoice.unlha' if answer = '1' then do address command 'C:RequestFile SAVEMODE DRAWER="'file.unpackdir'" TITLE="Choose destination directory" NOICONS DRAWERSONLY PUBSCREEN="'pubscreen'" >T:req.drawer' call open(choicefile, 'T:req.drawer', 'R') file.unpackdir = readln(choicefile) call close(choicefile) address command 'C:Delete >NIL: T:req.drawer' if length(answer) > 0 then do address command archiver.lha 'x "'completename'" 'file.unpackdir processed = 1 end end end if (extension = "ZIP") then do address command 'C:UnZIP -v "'completename'" >T:ZIPContents.tmp' address command file.default 'T:ZIPContents.tmp' address command 'C:Delete >NIL: T:ZIPContents.tmp' address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="UnZIP file 'completename'?" GADGETS="Yes|No" >T:reqchoice.unZIP' call open(choicefile, 'T:reqchoice.unZIP', 'R') answer = readch(choicefile, 1) call close(choicefile) address command 'C:Delete >NIL: T:reqchoice.unZIP' if answer = '1' then do address command 'C:RequestFile SAVEMODE DRAWER="'file.unpackdir'" TITLE="Choose destination directory" NOICONS DRAWERSONLY PUBSCREEN="'pubscreen'" >T:req.drawer' call open(choicefile, 'T:req.drawer', 'R') file.unpackdir = readln(choicefile) call close(choicefile) address command 'C:Delete >NIL: T:req.drawer' if length(answer) > 0 then do address command archiver.zip '"'completename'" -d 'file.unpackdir processed = 1 end end end /* Ask if the user wants to view any of the files, if file.arcview == 1 */ if processed & file.arcview then do call DeleteFile file.delete = 0 /* don't touch the unpacked files... */ address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="View a file from the archive?" GADGETS="Yes|No" >T:reqchoice.arcview' call open(choicefile, 'T:reqchoice.arcview', 'R') answer = readln(choicefile) call close(choicefile) address command 'C:Delete >NIL: T:reqchoice.arcview' if answer = '1' then do address command 'C:RequestFile DRAWER='file.unpackdir' TITLE="Choose file to view" NOICONS PUBSCREEN="'pubscreen'" >T:req.arcfile' call open(choicefile, 'T:req.arcfile', 'R') answer = readln(choicefile) call close(choicefile) address command 'C:Delete >NIL: T:req.arcfile' parse var answer '"'completename'"' call CheckExt viewed = 0 processed = 0 end return end if (extension = "GZ") | (extension = "Z") then do address command archiver.gzip '-d "'completename'"' viewed = 0 completename = filename call CheckExt end return CheckExt: /* find position of the last period, if any, to set off the file extension */ dot = lastpos(".", completename) if (dot > 0) then do /* there is an extension.. put it in another variable and make it upper case */ filename = left(completename, dot-1) extension = upper(substr(completename, dot+1)) end else do filename = completename extension = "" end return DeleteFile: if processed & file.delete & exists(completename) then do address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="Delete file 'completename'?" GADGETS="Yes|No" >T:reqchoice.delete' call open(choicefile, 'T:reqchoice.delete', 'R') answer = readch(choicefile, 1) call close(choicefile) address command 'C:Delete >NIL: T:reqchoice.delete' if answer = '1' then do address command 'C:Delete >NIL: "'completename'"' /* address command 'C:RequestChoice >NIL: PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="'completename' deleted" GADGETS="OK"' */ end end return