home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #6
/
amigamamagazinepolishissue1998.iso
/
opus
/
v4
/
arexx
/
viewlhafile.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1977-12-31
|
8KB
|
333 lines
/*rx
*
* ViewLhAFile.rexx - Extract and view a file from an LhA archive previously
* listed in a DOpus window by ListLha.rexx.
*
* $VER: ViewLhAFile 40.1 (23/05/94) by Geoff Seeley
*
* Usage: ARexx command ViewLhAFile.rexx (from DOpus)
*
*/
/*----- Configuration Variables (change these to suit your setup) ----------*/
LhaCommand = 'XFH_Work:C/Archivers/File/LhA '
OutputWindow = '>CON:30/145/640/100/LhA_Output/CLOSE/SCREENDOPUS.1 '
TmpDir = 'T:'
TextViewer = 'XFH_Work:C/Text/Viewers/Most '
GuideViewer = 'Sys:Utilities/MultiView '
IFFViewer = 'XFH_Work:C/Graphics/Viewers/VT '
JPGViewer = 'XFH_Work:C/Graphics/Viewers/FJPEG_ECS '
GIFViewer = 'XFH_Work:C/Graphics/Viewers/VT '
ANIMPlayer = 'XFH_Work:C/Graphics/Viewers/VT '
MPEGPlayer = 'XFH_Work:C/Animation/Players/mp -dither gray '
SNDPlayer = 'XFH_Work:C/Sound/Players/OPlay '
InfoViewer = 'IconInfo '
DefaultViewer = 'XFH_Work:C/Text/Viewers/xMore '
/*--------------------------------------------------------------------------*/
/* misc. variables */
DOpusPort = 'DOPUS.1'
LhaExtractCmd = '-x x '
if ~show(l,"rexxsupport.library") then
call addlib("rexxsupport.library",0,-30,0)
/* make sure we've got somebody to talk to */
if showlist('Ports', DOpusPort) = 0 then do
say 'Directory Opus ARexx port not found. Aborting.'
call CleanUp
end
address 'DOPUS.1'
options results
signal on failure
TopText "View File(s) From an LhA Archive Buffer"
Busy on
/* get the path/name of the LhA archive file */
'Status 14 -1'
LhaArchive = result
/* make sure it's an LhA archive listing buffer */
if (IsLhAFile(LhaArchive) = 0) then do
/* try other window */
OtherWindow
'Status 14 -1'
LhaArchive = Result
if (IsLhAFile(LhaArchive) = 0) then do
Notify "Sorry, no LhA archive buffer found.\You must use the ListLha button first."
call CleanUp
end
end
/* get path to archive */
call FindLhaPath
LhaArchive = LhaPath || LhaArchive
/* check for existance of archive */
if ~exists(LhaArchive) then do
Notify "Can't seem to find '" || LhaArchive || "'\Aborting."
call CleanUp
end
/* get list of selected entries */
GetSelectedAll
SelectedEntries = result
if SelectedEntries = 'RESULT' then do
Notify "Please Select File(s) to View First..."
call CleanUp
end
/* extract and view the files */
NumberOfEntries = words(SelectedEntries)
call ViewFileList
TopText "Finished Viewing Selected File(s) From LhA Archive."
call CleanUp
exit
/*---------------------------------------------------------------------------*/
ViewFileList: /* extract and view each file */
do EntryNumber = 1 to NumberOfEntries
/* get entry */
Index = word(SelectedEntries, EntryNumber)
GetEntry Index + 1
Entry = result
/* grab file name/path, protect in quotes */
File = substr(Entry, 10)
/* make sure user see's the entry */
ScrollToShow Index
/* put it in the file list */
call ReplaceMetaChars
ExtractFile = File
/* deselect this entry */
selection = Index ||' '|| 0 ||' '|| 1
SelectEntry selection
/* form CLI command and delete the file(s) */
TopText 'Extracting "'||GetFileInPath(ExtractFile)||'"... Please Wait.'
/* toast possible old file */
pragma(Directory, TmpDir)
if exists(ExtractFile) then
delete(ExtractFile)
CliCommand = LhaCommand||LhaExtractCmd||Quote(LhaArchive)
CliCommand = CliCommand||' '||Quote(ExtractFile)
address COMMAND CliCommand
/* view the file */
TopText 'Viewing "'||GetFileInPath(ExtractFile)||'"... Please Wait.'
FEx = GetFileExt(File)
FBs = upper(GetFileInPath(ExtractFile))
select /* pick a viewer */
when FEx='GUIDE' then
address COMMAND GuideViewer||Quote(TmpDir||ExtractFile)
when FEx='DOC'|FEx='README'|FEx='MAN'|FEx='TEXT'|FEx="TXT"|FEx="ME"|FBs="README" then
address COMMAND TextViewer||Quote(ExtractFile)
when FEx='IFF'|FEx='HAM'|FEx='PIC'|FEx='BRUSH'|FEx='ILBM' then
address COMMAND IFFViewer||Quote(ExtractFile)
when FEx='JPG'|FEx='JPEG'|FEx='JFIF' then
address COMMAND JPGViewer||Quote(ExtractFile)
when FEx='GIF'|FEx='JIF' then
address COMMAND GIFViewer||Quote(ExtractFile)
when FEx='INFO' then
address DOPUS.1 'IconInfo '||Quote(TmpDir||ExtractFile)
when FEx='SND'|FEx='8SVX' then
address COMMAND SNDPlayer||Quote(ExtractFile)
when FEx='ANIM' then
address COMMAND ANIMPlayer||Quote(ExtractFile)
when FEx='MPG'|FEx='MPEG' then
address COMMAND MPEGPlayer||Quote(ExtractFile)
otherwise
address COMMAND DefaultViewer||Quote(ExtractFile)
end /* select */
end
return
/*---------------------------------------------------------------------------*/
GetFileExt: procedure /* return file extension, or null */
parse arg BFileName
lps = lastpos(".", BFileName)
BFileName = StripQuotes(BFileName)
if lps ~= 0 then
return(upper(right(BFileName,length(BFileName)-lps)))
return ""
/*---------------------------------------------------------------------------*/
GetFileInPath: procedure /* return file from path */
parse arg FilePath
if lastpos('/', FilePath) = 0 then
return FilePath
DivPos = max(lastpos(':', FilePath),lastpos('/', FilePath)) +1
parse var FilePath PathSpec =DivPos FileName
Filename = StripQuotes(Filename)
return Filename
/*---------------------------------------------------------------------------*/
IsLhAFile: procedure /* look at extension, return 1 if right, else 0 */
parse arg AFileName
FileExt = GetFileExt(AFileName)
if FileExt ~= "LHA" & FileExt ~= "LZH" then
return 0
else
return 1
return 0
/*---------------------------------------------------------------------------*/
DeletePath: procedure
parse arg FilePath
x = pos('/', FilePath)
if x = 0 then
return
CliCommand = 'C:Delete '||Quote(substr(FilePath, 1, x))||' ALL'
address COMMAND CliCommand
return
/*---------------------------------------------------------------------------*/
ReplaceMetaChars: /* replace special wildcards with ? */
File = translate(File, '?????', '()`', '?')
return
/*---------------------------------------------------------------------------*/
FindLhAPath: /* grab invisible file path to archive */
/* find number of entries, path is the last one */
'Status 6 -1'
GetEntry Result
LhaPath = Result
return
/*---------------------------------------------------------------------------*/
Quote: procedure /* add quotes to string */
parse arg string
return '"'||string||'"'
/*---------------------------------------------------------------------------*/
StripQuotes: procedure /* strip quotes from string */
parse arg string
return strip(string,, '"')
/*---------------------------------------------------------------------------*/
failure: /* most likely a failed COMMAND */
Notify "View command failed. The archive is probably corrupt."
Busy off
exit
return
/*---------------------------------------------------------------------------*/
CleanUp: /* clean up files and exit */
ExtractFile = StripQuotes(ExtractFile)
pragma(Directory, TmpDir)
if exists(ExtractFile) then do
delete(ExtractFile)
call DeletePath(ExtractFile)
end
Busy off
exit
return