home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / FileMover / Dopus4 / JTE-DopusConfig.lha / jtedopus / DOpConv.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1995-08-06  |  3.6 KB  |  190 lines

  1. /* Convert archives to LhA v1.1*/
  2.  
  3. archivers. = ''
  4.  
  5. /* Name of archive formats */
  6.  
  7. archivers.lzh = 'LhArc'
  8. archivers.arc = 'Arc'
  9. archivers.pak = 'Pak'
  10. archivers.zip = 'ZIp'
  11. archivers.arj = 'ARJ'
  12. archivers.zoo = 'Zoo'
  13. archivers.z   = 'compress'
  14. archivers.lzx = 'LZX'
  15.  
  16. /* How the different formats shall be unarced */
  17.  
  18. archivers.lzh.unpack = 'LhA x'
  19. archivers.arc.unpack = 'PKAX'
  20. archivers.pak.unpack = ''
  21. archivers.zip.unpack = 'UnZIp'
  22. archivers.arj.unpack = 'UnARJ x'
  23. archivers.zoo.unpack = 'Zoo x'
  24. archivers.z.unpack   = 'compress -d'
  25. archivers.lzx.unpack = 'LZX x'
  26.  
  27. /* Talk to DirOpus and open an active window through it displaying which
  28.    directory is chosen and the number of selected files */
  29.  
  30. options results
  31. address 'DOPUS.1'
  32.  
  33. 'toptext' 'Archive Converter'
  34.  
  35. 'checkabort'
  36.  
  37. 'status 3'
  38. activewin = result
  39.  
  40. 'status 7' activewin
  41. numfiles = result
  42.  
  43. 'status 13' activewin
  44. dirname = result
  45.  
  46. /* Remember the old filenames */
  47.  
  48. oldnames. = ''
  49. k = 0
  50.  
  51. /* Process the selected files */
  52.  
  53. do i = 1 to numfiles
  54.    'getnextselected'
  55.    name = result
  56.    'fileinfo 'name
  57.    comment = subword(result, 8, words(result)-8)
  58.  
  59.    /* Check file extention to see if it's a supported archive */
  60.  
  61.    extension = getExtension(name)
  62.    if extension = '' then do
  63.       toptext name 'is not a known archive type...'
  64.       call updateDirOpus
  65.       iterate
  66.    end
  67.  
  68.    /* Make a name for the LhA archive */
  69.  
  70.    dotpos = lastpos('.',name)
  71.    newname = left(name,dotpos) || 'lha'
  72.  
  73.    convtxt = 'Converting' name '(Format'
  74.    convtxt = convtxt archivers.extension') ->' newname
  75.    toptxt convtxt
  76.  
  77.    tmpdir = extract(name,dirname,extension)
  78.    if tmpdir = '' then do
  79.       address 'DOPUS.1'
  80.       toptxt 'Could not unpack' name
  81.       call updateDirOpus
  82.       iterate
  83.    end
  84.  
  85.    if doabort() then
  86.       leave
  87.  
  88.    /* Pack the files in a LhA archive */
  89.  
  90.    address command
  91.    'lha -r a' dirname || newname tmpdir'/' '#?'
  92.    if rc ~= 0 then do
  93.       address 'DOPUS.1'
  94.       toptxt 'Couldn't create' newname
  95.       iterate
  96.    end
  97.  
  98.    'delete' tmpdir 'all quiet'
  99.    if rx ~=0 then do
  100.       address 'DOPUS.1'
  101.       toptxt 'Couldn't delete temporary files... Sorry!'
  102.    end
  103.  
  104.    'filenote 'dirname||newname' "'comment'"'
  105.  
  106.    address
  107.    call updateDirOpus
  108.  
  109.    /* Put the old archive name in memory */
  110.    k = k + 1
  111.    oldnames.k = dirname || name
  112. end
  113.  
  114. /* Ask if old archives shall be removed */
  115. 'request' 'Shall the converted files be deleted?'
  116. if result then
  117.    do i = 1 to k
  118.       address command 'delete' oldnames.i
  119.    end
  120. 'rescan' activewin
  121.  
  122. exit 0
  123.  
  124.  
  125. /* PROCEDURES */
  126.  
  127. /* Unmark the converted files and update the DirOpus window */
  128.  
  129. updateDirOpus:
  130. address 'DOPUS.1'
  131. 'selectfile' name 0 1
  132. 'rescan' activewin
  133. 'reselect'
  134. address
  135. return
  136.  
  137. /* Pick out the filename extension and check if it's valid */
  138.  
  139. getExtension: procedure expose archivers.
  140. name = arg(1)
  141.  
  142. dotpos = lastpos('.',name)
  143. ext = upper(right(name,length(name)-dotpos))
  144.  
  145. if archivers.ext = '' then
  146.    ext = ''
  147. return ext
  148.  
  149. /* Extract all files in a temporary directory */
  150.  
  151. extract: procedure expose archivers.
  152. name = arg(1)
  153. dirname = arg(2)
  154. ext = arg(3)
  155.  
  156. do until ~exists(tmpdir)
  157.    tmpdir = 'T:TMPlh' || time(s)
  158. end
  159.  
  160. if doabort() then
  161.    return
  162.  
  163. /* Go to temporary directory and unarc there. Some programs can only unarc
  164.    in the current directory */
  165.  
  166. address command
  167. 'makedir' tmpdir
  168. olddir = pragma('d',tmpdir)
  169. if ext ~= 'Z' then
  170.    archivers.ext.unpack dirname || name
  171. else do
  172.    'copy' dirname || name name
  173.    archivers.ext.unpack name
  174. end
  175.  
  176. if rc ~= 0 then do
  177.    'delete' tmpdir
  178.    tmpdir = ''
  179. end
  180. address
  181.  
  182. call pragma('d',olddir)
  183. return tmpdir
  184.  
  185. /* Check if the user want to abort */
  186.  
  187. doabort: procedure
  188. address 'DOPUS.1' 'checkabort'
  189. return result
  190.