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

  1. /*rx
  2.  *
  3.  * AddFilesLhA.rexx - Add the selected files to an LhA archive previously
  4.  *                    listed in a DOpus window by ListLha.rexx.
  5.  *
  6.  * $VER: AddFilesLhA 40.6 (03/01/94) by Geoff Seeley
  7.  *
  8.  * Usage: ARexx command AddFilesLhA.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. AddList      = 'T:lha_file_list'
  17. ListLhARexx  = "RX DOpus:ARexx/ListLhA.rexx"
  18.  
  19. /*---------------------------------------------------------------------------*/
  20.  
  21. /* misc. variables */
  22.  
  23. DOpusPort = 'DOPUS.1'
  24.  
  25. LhaAddCmd    = ''
  26. LhaAddBase   = '-m a '
  27. LhaRecurse   = '-r '
  28. LhaSavePath  = '-x '
  29. CreateNew    = 0
  30. AddSubDirs   = 0
  31.  
  32. /* make sure we've got somebody to talk to */
  33.  
  34. if showlist('Ports', DOpusPort) = 0 then do
  35.    say 'Directory Opus ARexx port not found. Aborting.'
  36.    call CleanUp
  37. end
  38.  
  39. /* make sure the right task is listening... */
  40.  
  41. address 'DOPUS.1'
  42. options results
  43.  
  44. TopText "Adding File(s) to an LhA Archive"
  45.  
  46. Busy on
  47.  
  48. /* get the path/name of the LhA archive file */
  49.  
  50. 'Status 14 -1'
  51. LhaArchive = result
  52.  
  53. /* if this isn't an LhA buffer, try the other window then ask for new arc. */
  54.  
  55. if (IsLhAFile(LhaArchive) = 0) then do
  56.  
  57.    /* Hmm, let's try the other window */
  58.  
  59.    OtherWindow
  60.    'Status 14 -1'
  61.    LhaArchive = result
  62.  
  63.    /* if neither window looks right, ask for name */
  64.  
  65.    if (IsLhAFile(LhaArchive) = 0) then do
  66.  
  67.       call SetYesNo
  68.       Request "No LhA archive listed. Do you wish to create one?"
  69.  
  70.       if Result = 0 then do
  71.  
  72.          OtherWindow
  73.          TopText "Adding files to LhA archive aborted."
  74.          call CleanUp
  75.  
  76.       end
  77.       else
  78.  
  79.          CreateNew = 1
  80.  
  81.       call RestoreRequester
  82.  
  83.       /* get path of window */
  84.  
  85.       'Status 13 -1'
  86.  
  87.       LhaPath = Result
  88.  
  89.       /* get new archive */
  90.  
  91.       GetString "'Enter LhA Archive Name: (Path: '"||LhaPath||"')'"
  92.       LhaArchive = Result
  93.  
  94.       /* cancel it? */
  95.  
  96.       if RC = 1 then do
  97.  
  98.          TopText "LhA archive creation aborted."
  99.          call CleanUp
  100.  
  101.       end
  102.  
  103.       if (IsLhAFile(LhaArchive) = 0) then
  104.         LhaArchive = LhaArchive || ".lha"
  105.  
  106.       NewLhaArchive = LhaArchive
  107.  
  108.       LhaArchive = LhaPath || LhaArchive
  109.  
  110.    end
  111.    else do
  112.  
  113.       /* get path to archive */
  114.  
  115.       call FindLhAPath
  116.       LhaArchive = LhaPath || LhaArchive
  117.  
  118.    end
  119. end
  120. else do
  121.  
  122.    /* make sure we don't have *two* LhA buffers */
  123.  
  124.    OtherWindow
  125.    'Status 14 -1'
  126.  
  127.    if (IsLhAFile(result) = 1) then do
  128.  
  129.       Notify "Sorry, You have two LhA archives listed.\Cannot add files from LhA archive."
  130.       OtherWindow
  131.       call CleanUp
  132.  
  133.    end
  134.  
  135.    OtherWindow
  136.  
  137.    /* get path to archive */
  138.  
  139.    call FindLhAPath
  140.    LhaArchive = LhaPath || LhaArchive
  141.  
  142. end
  143.  
  144. /* check for existance of archive */
  145.  
  146. if CreateNew = 0 then do
  147.    if ~exists(LhaArchive) then do
  148.  
  149.       Notify "Can't seem to find '" || LhaArchive || "'\Aborting."
  150.       call CleanUp
  151.    end
  152. end
  153.  
  154. /* switch to window with files to add... */
  155.  
  156. OtherWindow
  157.  
  158. /* get list of selected entries */
  159.  
  160. GetSelectedAll
  161. SelectedEntries = result
  162.  
  163. /* must select *something* man... */
  164.  
  165. if SelectedEntries = 'RESULT' then do
  166.  
  167.    Notify "Please select file(s) to add first..."
  168.    call CleanUp
  169.  
  170. end
  171.  
  172. NumberOfEntries = words(SelectedEntries)
  173.  
  174. /* get source directory */
  175.  
  176. 'Status 13 -1'
  177. SrcDir = result
  178.  
  179. /* verify, (I think I'm paranoid :-) */
  180.  
  181. if SrcDir = 'RESULT' | SrcDir = "" then do
  182.  
  183.    Notify "Unable to get source directory. Aborting."
  184.    call CleanUp
  185.  
  186. end
  187.  
  188. /* ask user if they want the path included */
  189.  
  190. call SetYesNo
  191.  
  192. Request "Store pathname(s) of selected file(s) in LhA archive?"
  193. StorePath = Result
  194.  
  195. Request "Add any possible subdirectories?"
  196. AddSubDirs = Result
  197.  
  198. call RestoreRequester
  199.  
  200. /* form proper command */
  201.  
  202. LhaAddCmd = LhaAddBase
  203.  
  204. if StorePath = 1 then do
  205.  
  206.    LhaAddCmd = LhaSavePath || LhaAddCmd
  207.  
  208. end
  209. if AddSubDirs = 1 then do
  210.  
  211.    LhaAddCmd = LhaRecurse || LhaAddCmd
  212.  
  213. end
  214.  
  215. /* add the files */
  216.  
  217. call AddFileList
  218.  
  219. /* go back to the archive window */
  220.  
  221. OtherWindow
  222.  
  223. if CreateNew = 0 then do
  224.  
  225.    /* call ListLhA to re-list the LhA archive in the window */
  226.  
  227.    address command ListLhARexx
  228.  
  229. end
  230. else do
  231.  
  232.    /* rescan the directory */
  233.  
  234.    'Rescan -1'
  235.  
  236.    /* select the new archive and list it in the window */
  237.  
  238.    'Select '|| NewLhaArchive || ' onlyfiles name'
  239.    address command ListLhARexx
  240.  
  241. end
  242.  
  243. TopText "Finished adding selected file(s) to LhA archive."
  244.  
  245. call CleanUp
  246.  
  247. exit
  248.  
  249. /*---------------------------------------------------------------------------*/
  250.  
  251. AddFileList: /* build a list of selected files, add list */
  252.  
  253.    /* toast possible old list */
  254.  
  255.    if exists(AddList) then
  256.  
  257.       delete(AddList)
  258.  
  259.    if ~open(FileList, AddList, 'W') then do
  260.  
  261.       Notify "Can't open file " || AddList
  262.       call CleanUp
  263.  
  264.    end
  265.  
  266.    TopText "Creating file(s) list..."
  267.  
  268.    do EntryNumber = 1 to NumberOfEntries
  269.  
  270.       /* get entry */
  271.  
  272.       Entry = word(SelectedEntries, EntryNumber)
  273.  
  274.       /* grab file name/path, protect in quotes */
  275.  
  276.       File = '"' || Entry || '"'
  277.  
  278.       /* make sure user see's the entry */
  279.  
  280.       ScrollToShow Entry
  281.  
  282.       /* put it in the file list */
  283.  
  284.       call ReplaceMetaChars
  285.       writeln(FileList, File)
  286.  
  287.    end
  288.  
  289.    close(FileList)
  290.  
  291.    /* form CLI command and add the file(s) */
  292.  
  293.    TopText "Adding file(s) to LhA archive..."
  294.  
  295.    /* move into source directory */
  296.  
  297.    pragma(D, SrcDir)
  298.  
  299.    CliCommand = LhaCommand || OutputWindow || LhaAddCmd || LhaArchive
  300.    CliCommand = CliCommand || ' @' || AddList
  301.  
  302.    address command CliCommand
  303.  
  304. return
  305.  
  306. /*---------------------------------------------------------------------------*/
  307.  
  308. SetYesNo:  /* set requester strings */
  309.  
  310.    'Status 26 set Yes'
  311.    'Status 27 set No'
  312.  
  313. return
  314.  
  315. /*---------------------------------------------------------------------------*/
  316.  
  317. RestoreRequester: /* restore (default) requester strings */
  318.  
  319.    Busy On
  320.    'Status 26 set Okay'
  321.    'Status 27 set Cancel'
  322.  
  323. return
  324.  
  325. /*---------------------------------------------------------------------------*/
  326.  
  327. ReplaceMetaChars: /* replace special wildcards with ? */
  328.  
  329.    File = translate(File, '???', '()`', '?')
  330.  
  331. return
  332.  
  333. /*---------------------------------------------------------------------------*/
  334.  
  335. IsLhAFile: procedure   /* look at extension, return 1 if right, else 0 */
  336.  
  337.    parse arg AFileName
  338.  
  339.    lps = lastpos(".", AFileName)               
  340.    if lps = 0 then                           
  341.       return 0
  342.  
  343.    FileExt = upper(right(AFileName,length(AFileName)-lps))
  344.  
  345.    if FileExt ~= "LHA" & FileExt ~= "LZH" then
  346.       return 0
  347.    else
  348.       return 1
  349.  
  350. return 0
  351.  
  352. /*--------------------------------------------------------------------------*/
  353.  
  354. FindLhAPath: /* grab invisible file path to archive */
  355.  
  356.    /* find number of entries, path is the last one */
  357.  
  358.    'Status 6 -1'
  359.  
  360.    GetEntry Result
  361.    LhaPath = Result
  362.  
  363. return
  364.  
  365. /*--------------------------------------------------------------------------*/
  366.  
  367. CleanUp: /* clean up files and exit */
  368.  
  369.    if exists(AddList) then
  370.       delete(AddList)
  371.  
  372.    Busy off
  373.  
  374.    exit
  375.  
  376. return
  377.  
  378.