home *** CD-ROM | disk | FTP | other *** search
- /* Convert archives to LhA v1.1*/
-
- archivers. = ''
-
- /* Name of archive formats */
-
- archivers.lzh = 'LhArc'
- archivers.arc = 'Arc'
- archivers.pak = 'Pak'
- archivers.zip = 'ZIp'
- archivers.arj = 'ARJ'
- archivers.zoo = 'Zoo'
- archivers.z = 'compress'
- archivers.lzx = 'LZX'
-
- /* How the different formats shall be unarced */
-
- archivers.lzh.unpack = 'LhA x'
- archivers.arc.unpack = 'PKAX'
- archivers.pak.unpack = ''
- archivers.zip.unpack = 'UnZIp'
- archivers.arj.unpack = 'UnARJ x'
- archivers.zoo.unpack = 'Zoo x'
- archivers.z.unpack = 'compress -d'
- archivers.lzx.unpack = 'LZX x'
-
- /* Talk to DirOpus and open an active window through it displaying which
- directory is chosen and the number of selected files */
-
- options results
- address 'DOPUS.1'
-
- 'toptext' 'Archive Converter'
-
- 'checkabort'
-
- 'status 3'
- activewin = result
-
- 'status 7' activewin
- numfiles = result
-
- 'status 13' activewin
- dirname = result
-
- /* Remember the old filenames */
-
- oldnames. = ''
- k = 0
-
- /* Process the selected files */
-
- do i = 1 to numfiles
- 'getnextselected'
- name = result
- 'fileinfo 'name
- comment = subword(result, 8, words(result)-8)
-
- /* Check file extention to see if it's a supported archive */
-
- extension = getExtension(name)
- if extension = '' then do
- toptext name 'is not a known archive type...'
- call updateDirOpus
- iterate
- end
-
- /* Make a name for the LhA archive */
-
- dotpos = lastpos('.',name)
- newname = left(name,dotpos) || 'lha'
-
- convtxt = 'Converting' name '(Format'
- convtxt = convtxt archivers.extension') ->' newname
- toptxt convtxt
-
- tmpdir = extract(name,dirname,extension)
- if tmpdir = '' then do
- address 'DOPUS.1'
- toptxt 'Could not unpack' name
- call updateDirOpus
- iterate
- end
-
- if doabort() then
- leave
-
- /* Pack the files in a LhA archive */
-
- address command
- 'lha -r a' dirname || newname tmpdir'/' '#?'
- if rc ~= 0 then do
- address 'DOPUS.1'
- toptxt 'Couldn't create' newname
- iterate
- end
-
- 'delete' tmpdir 'all quiet'
- if rx ~=0 then do
- address 'DOPUS.1'
- toptxt 'Couldn't delete temporary files... Sorry!'
- end
-
- 'filenote 'dirname||newname' "'comment'"'
-
- address
- call updateDirOpus
-
- /* Put the old archive name in memory */
- k = k + 1
- oldnames.k = dirname || name
- end
-
- /* Ask if old archives shall be removed */
- 'request' 'Shall the converted files be deleted?'
- if result then
- do i = 1 to k
- address command 'delete' oldnames.i
- end
- 'rescan' activewin
-
- exit 0
-
-
- /* PROCEDURES */
-
- /* Unmark the converted files and update the DirOpus window */
-
- updateDirOpus:
- address 'DOPUS.1'
- 'selectfile' name 0 1
- 'rescan' activewin
- 'reselect'
- address
- return
-
- /* Pick out the filename extension and check if it's valid */
-
- getExtension: procedure expose archivers.
- name = arg(1)
-
- dotpos = lastpos('.',name)
- ext = upper(right(name,length(name)-dotpos))
-
- if archivers.ext = '' then
- ext = ''
- return ext
-
- /* Extract all files in a temporary directory */
-
- extract: procedure expose archivers.
- name = arg(1)
- dirname = arg(2)
- ext = arg(3)
-
- do until ~exists(tmpdir)
- tmpdir = 'T:TMPlh' || time(s)
- end
-
- if doabort() then
- return
-
- /* Go to temporary directory and unarc there. Some programs can only unarc
- in the current directory */
-
- address command
- 'makedir' tmpdir
- olddir = pragma('d',tmpdir)
- if ext ~= 'Z' then
- archivers.ext.unpack dirname || name
- else do
- 'copy' dirname || name name
- archivers.ext.unpack name
- end
-
- if rc ~= 0 then do
- 'delete' tmpdir
- tmpdir = ''
- end
- address
-
- call pragma('d',olddir)
- return tmpdir
-
- /* Check if the user want to abort */
-
- doabort: procedure
- address 'DOPUS.1' 'checkabort'
- return result
-