home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / opus / v4 / dopuslharexx / arexx / extractfileslha.rexx < prev    next >
OS/2 REXX Batch file  |  1995-09-18  |  6KB  |  298 lines

  1. /*rx
  2.  *
  3.  * ExtractFilesLhA.rexx - Extract selected files from an LhA archive previously
  4.  *                        listed in a DOpus window by ListLha.rexx
  5.  *
  6.  * $VER: ExtractFilesLhA 40.8 (03/01/94) by Geoff Seeley
  7.  *
  8.  * Usage: ARexx command ExtractFilesLhA.rexx (from DOpus)
  9.  *
  10.  */
  11.  
  12. /* configuration variables (change these to suit your setup) */
  13.  
  14. LhaCommand    = 'XFH_Work:C/Archivers/File/LhA '
  15. OutputWindow  = '>CON:30/145/640/100/LhA_Output/CLOSE/SCREENDOPUS.1 '
  16. ExtractList   = 'T:lha_file_list'
  17. ExtractAll    = 1 /* set to 1 if you want to extract all files at one time */
  18.                   /* else set to 0 for file-by-file extraction (slow) */
  19.  
  20. /* misc. variables */
  21.  
  22. DOpusPort = 'DOPUS.1'
  23.  
  24. LhaExtractCmd  = '-x -m x '
  25.  
  26. /* make sure we've got somebody to talk to */
  27.  
  28. if showlist('Ports', DOpusPort) = 0 then do
  29.    say 'Directory Opus ARexx port not found. Aborting.'
  30.    call CleanUp
  31. end
  32.  
  33. address 'DOPUS.1'
  34. options results
  35.  
  36. TopText "Extracting File(s) From an LhA Archive"
  37.  
  38. Busy on
  39.  
  40. /* get window information from DOpus */
  41.  
  42. Status 3
  43. CurrentWindow = result
  44.  
  45. if CurrentWindow = 0 then
  46.    DestinationWindow = 1
  47. else
  48.    DestinationWindow = 0
  49.  
  50. /* get the path/name of the LhA archive file */
  51.  
  52. 'Status 14 -1'
  53. LhaArchive = result
  54.  
  55. /* make sure it's an LhA archive listing buffer */
  56.  
  57. if (IsLhAFile(LhaArchive) = 0) then do
  58.  
  59.    /* try other window */
  60.  
  61.    OtherWindow
  62.    'Status 14 -1'
  63.    LhaArchive = Result
  64.    
  65.    if (IsLhAFile(LhaArchive) = 0) then do
  66.  
  67.       Notify "Sorry, no LhA archive buffer found. You must use the ListLha button first."
  68.       call CleanUp
  69.  
  70.    end
  71.  
  72.    /* adjust destination as we switched windows */
  73.  
  74.    if DestinationWindow = 0 then
  75.       DestinationWindow = 1
  76.    else
  77.       DestinationWindow = 0
  78.  
  79. end
  80.  
  81. call FindLhAPath
  82. LhaArchive = LhaPath || LhaArchive
  83.  
  84. /* check for existance of archive */
  85.  
  86. if ~exists(LhaArchive) then do
  87.  
  88.    Notify "Can't seem to find '" || LhaArchive || "'. Aborting."
  89.    call CleanUp
  90.  
  91. end
  92.  
  93. /* get the destination path from the other window */
  94.  
  95. OtherWindow
  96.  
  97. 'Status 13 -1'
  98. DestinationPath = result
  99.  
  100. OtherWindow
  101.  
  102. /* check for valid destination path */
  103.  
  104. if DestinationPath = '' then do
  105.  
  106.    Notify "The destination path is invalid\Pick another destination"
  107.    call CleanUp
  108.  
  109. end
  110.  
  111. /* get list of selected entries */
  112.  
  113. GetSelectedAll
  114. SelectedEntries = result
  115.  
  116. if SelectedEntries = 'RESULT' then do
  117.  
  118.    Notify "Please select some files to extract first..."
  119.    call CleanUp
  120.  
  121. end
  122.  
  123. NumberOfEntries = words(SelectedEntries)
  124.  
  125. /* extract the files */
  126.  
  127. if ExtractAll then
  128.  
  129.    call ExtractFileList
  130.  
  131. else
  132.  
  133.    call ExtractEachFile
  134.  
  135. /* update destination window, tell user we are finished */
  136.  
  137. Rescan DestinationWindow
  138.  
  139. TopText "Finished extracting selected file(s) from LhA archive."
  140.  
  141. call CleanUp
  142.  
  143. exit 0
  144.  
  145. /*---------------------------------------------------------------------------*/
  146.  
  147. ExtractEachFile: /* extract each selected file */
  148.  
  149.    do EntryNumber = 1 to NumberOfEntries
  150.  
  151.       /* get entry number, retrieve entry */
  152.  
  153.       Index = word(SelectedEntries, EntryNumber)
  154.  
  155.       GetEntry Index + 1
  156.       Entry = result
  157.  
  158.       /* grab file name/path */
  159.  
  160.       File = substr(Entry, 10)
  161.  
  162.       TopText "Extracting " || File || "..."
  163.  
  164.       /* make sure user see's the entry */
  165.  
  166.       ScrollToShow Index
  167.  
  168.       /* form CLI command and extract the file(s) */
  169.  
  170.       CliCommand = LhaCommand || OutputWindow || LhaExtractCmd || LhaArchive
  171.       CliCommand = CliCommand || ' "' || File || '" ' || DestinationPath
  172.  
  173.       address command CliCommand
  174.  
  175.       /* deselect this entry */
  176.  
  177.       selection = Index ||' '|| 0 ||' '|| 1
  178.       SelectEntry selection
  179.  
  180.    end
  181.  
  182. return
  183.  
  184. /*----------------------------------------------------------------------------*/
  185.  
  186. ExtractFileList: /* build a list of selected files, extract list */
  187.  
  188.    /* toast old list */
  189.  
  190.    if exists(ExtractList) then
  191.  
  192.       delete(ExtractList)
  193.  
  194.    if ~open(FileList, ExtractList, 'W') then do
  195.  
  196.       Notify "Can't open file " || ExtractList
  197.       call CleanUp
  198.  
  199.    end
  200.  
  201.    TopText "Creating file(s) list..."
  202.  
  203.    do EntryNumber = 1 to NumberOfEntries
  204.  
  205.       /* get entry number, retrieve entry */
  206.  
  207.       Index = word(SelectedEntries, EntryNumber)
  208.  
  209.       GetEntry Index + 1
  210.       Entry = result
  211.  
  212.       /* grab file name/path, protect in quotes */
  213.  
  214.       File = substr(Entry, 10)
  215.       File = '"' || File || '"'
  216.  
  217.       /* make sure user see's the entry */
  218.  
  219.       ScrollToShow Index
  220.  
  221.       /* put it in the file list */
  222.  
  223.       call ReplaceMetaChars
  224.       writeln(FileList, File)
  225.  
  226.       /* deselect this entry */
  227.  
  228.       selection = Index ||' '|| 0 ||' '|| 1
  229.       SelectEntry selection
  230.  
  231.    end
  232.  
  233.    close(FileList)
  234.  
  235.    /* form CLI command and extract the file(s) */
  236.  
  237.    TopText "Extracting file(s) from LhA archive..."
  238.  
  239.    CliCommand = LhaCommand || OutputWindow || LhaExtractCmd || LhaArchive
  240.    CliCommand = CliCommand || ' @' || ExtractList || ' ' || DestinationPath
  241.  
  242.    address command CliCommand
  243.  
  244. return
  245.  
  246. /*--------------------------------------------------------------------------*/
  247.  
  248. IsLhAFile: procedure   /* look at extension, return 1 if right, else 0 */
  249.  
  250.    parse arg AFileName
  251.  
  252.    lps = lastpos(".", AFileName)               
  253.    if lps = 0 then                           
  254.       return 0
  255.  
  256.    FileExt = upper(right(AFileName,length(AFileName)-lps))
  257.  
  258.    if FileExt ~= "LHA" & FileExt ~= "LZH" then
  259.       return 0
  260.    else
  261.       return 1
  262.  
  263. return 0
  264.  
  265. /*--------------------------------------------------------------------------*/
  266.  
  267. FindLhAPath: /* grab invisible file path to archive */
  268.  
  269.    /* find number of entries, path is the last one */
  270.  
  271.    'Status 6 -1'
  272.  
  273.    GetEntry Result
  274.    LhaPath = Result
  275.  
  276. return
  277.  
  278. /*--------------------------------------------------------------------------*/
  279.  
  280. ReplaceMetaChars: /* replace special wildcards with ? */
  281.  
  282.    File = translate(File, '???', '()`', '?')
  283.  
  284. return
  285.  
  286. /*--------------------------------------------------------------------------*/
  287.  
  288. CleanUp: /* clean up files and exit */
  289.  
  290.    if exists(ExtractList) then
  291.       delete(ExtractList)
  292.  
  293.    Busy off
  294.  
  295.    exit 0
  296.  
  297. return
  298.