home *** CD-ROM | disk | FTP | other *** search
/ ANews 2 / AnewsCD2.iso / Script / Lhaction.rexx < prev    next >
OS/2 REXX Batch file  |  1999-10-06  |  14KB  |  491 lines

  1. /************************************/
  2. /*                                  */
  3. /*   Lhaction V1.0 du 11/01/1999    */
  4. /*   Créer par Frédéric RIGNAULT    */
  5. /*   Fortement inspiré par LHA-GUI  */
  6. /*   Version adaptée pour ANews     */
  7. /*                                  */
  8. /************************************/
  9.  
  10. parse arg '"' currentfile '"'
  11. if (currentfile = "") then parse arg currentfile
  12.  
  13. if currentfile = "" then currentfile="Caches:Download/"
  14.  
  15. extractdir="RAM:"
  16.  
  17. options results
  18.  
  19. /* Open libs needed */
  20.  
  21. IF EXISTS("libs:rexxsupport.library") THEN DO
  22.  IF ~SHOW("L","rexxsupport.library") THEN
  23.   IF ~ADDLIB("rexxsupport.library",0,-30,0) THEN EXIT
  24.  END
  25. ELSE EXIT
  26.  
  27. /* Open message Port Of Script */
  28. address rexx
  29. nb=1
  30. do while show("P","LHSER"||nb)
  31.   nb=nb+1
  32. end
  33. server="LHSER"||nb
  34. gui="LHACT"||nb
  35. say server
  36. say gui
  37. OPENPORT(server)
  38.  
  39. /*if currentfile="" then currentfile=""*/
  40. call locale
  41. call opengui
  42. call readlist(currentfile)
  43. tree=""
  44. call listing("")
  45.  
  46. call waiting
  47. address value gui;QUIT
  48. exit
  49.  
  50. waiting:
  51. do forever
  52.  if arc=0 then call info(getready)
  53.  if arc=1 then do
  54.   if tree="" then call info(infosize||unpacksize)
  55.  end
  56.  address value gui;
  57.  window ID LHACT ATTRS MUIA_Window_Sleep FALSE
  58.  address REXX
  59.  gotit=0
  60.  do until gotit
  61.   call waitpkt(server);packet=getpkt(server)
  62.   gotit=(packet ~= null())
  63.  end
  64.  address value gui;
  65.  window ID LHACT ATTRS MUIA_Window_Sleep TRUE
  66.  address REXX;class=getarg(packet);reply(packet,0)
  67.  say class
  68.  if class="QUIT" then break
  69.  if left(class,4)="DROP" then do
  70.   parse var class a ' ' b
  71.   if right(b,1)="/" | right(b,1)=":" then do
  72.     extractdir=b
  73.     address value gui
  74.     popasl ID DIR CONTENT extractdir
  75.   end
  76.   else do
  77.     currentfile=b
  78.     address value gui
  79.     popasl ID FILE CONTENT currentfile
  80.     class="FILE"
  81.   end
  82.  end
  83.  if class="PARENT" then do
  84.   say tree
  85.   if tree~="" then do
  86.    do i=length(tree)-1 to 2 by -1
  87.      if substr(tree,i,1)="/" then break
  88.    end
  89.    say i
  90.    if i=1 then tree=""
  91.    if i>1 then tree=left(tree,i)
  92.    say tree
  93.    call listing(tree)
  94.   end
  95.  end
  96.  if class="FILE" then DO /*  */
  97.    address value gui
  98.    popasl ID FILE
  99.    currentfile=result
  100.    call readlist(currentfile)
  101.    tree=""
  102.    call listing(tree)
  103.  end
  104.  if class="DIR" then do
  105.   popasl ID DIR
  106.   extractdir=resul
  107.  end
  108.  if class="ROOT" then do
  109.   tree=""
  110.   call listing(tree)
  111.  end
  112.  if class="LSTUPD" then do
  113.    address value gui
  114.    list ID ARCH ATTRS MUIA_List_Active
  115.    if result~=4294967295 then do
  116.      list ID ARCH POS result
  117.      say result
  118.      parse var result num "," a "," d "," t
  119.      call info(name.num)
  120.    end
  121.  end
  122.  if class="COPYACT" then do
  123.    address value gui
  124.    list ID ARCH ATTRS MUIA_List_Active
  125.    if result~=4294967295 then do
  126.      list ID ARCH POS result
  127.      say result
  128.      parse var result num "," a "," d "," t
  129.      address ASERV ADDOP
  130.      call delay(25)
  131.      address ANEWS string ID RFILE CONTENT name.num
  132.      address ASERV RFILE
  133.    end
  134.  end
  135.  if class="LIST" then do
  136.    say "List..."
  137.    address value gui
  138.    list ID ARCH ATTRS MUIA_List_Active
  139.    list ID ARCH POS result
  140.    say result
  141.    parse var result num "," a "," d "," t
  142.    say name.num
  143.    say t
  144.    If right(t,1)="/" then do
  145.      SAY "Dir action"
  146.      tree=tree||t
  147.      call listing(tree)
  148.    end
  149.    else do
  150.      call info(showfile||t)
  151.      t2=tree||t
  152.      if type=".LHA" | type=".LZH" then do
  153.        address command "lha >NIL: e -m -q """||currentfile||""" "||t2||" T:"
  154.        address command "run >NIL: sys:utilities/Multiview >NIL: T:"||t2
  155.      end
  156.      if type=".LZX" then do
  157.        address command "lzx >NIL: e -m """||currentfile||""" "||t2||" T:"
  158.        address command "run >NIL: sys:utilities/Multiview >NIL: T:"||t
  159.      end
  160.      if type=".ZIP" then do
  161.        address command "unzip >NIL: -o """||currentfile||""" "||t2||" -d T:"
  162.        address command "run >NIL: sys:utilities/Multiview >NIL: T:"||t2
  163.      end
  164.    end
  165.  end
  166.  if class="EXTRACT" then do
  167.    address value GUI
  168.    ligne=0
  169.    if open('f1','T:list'||gui,'w') then do
  170.      say 'Write...'
  171.      do forever
  172.        list ID ARCH
  173.        b=result
  174.        say b
  175.        if b="" then break
  176.        ligne=ligne+1
  177.        parse var b n "," a "," d "," t
  178.        if right(t,1)="/" then
  179.          do
  180.            t=tree||t
  181.            say "AddRep..."||t
  182.            call addrep(t)
  183.          end
  184.        else do
  185.          say "Add File..."||name.n
  186.          call writeln('f1',name.n)
  187.        end
  188.      end
  189.      call close('f1')
  190.    end
  191.    call info(extracting)
  192.    if ligne=0 then
  193.    do
  194.      if type=".LHA" | type=".LZH" then address command "lha >CON: x """||currentfile||""" "||extractdir
  195.      if type=".LZX" then address command "lzx >CON: x -F """||currentfile||""" "||extractdir
  196.      if type=".ZIP" then address command "unzip >CON: """||currentfile||""" -d "||extractdir
  197.    end
  198.    else do
  199.      if type=".LHA" | upper(right(currentfile,4))=".LZH" then address command "lha x -r """||currentfile||""" @T:list"||gui||" "||extractdir
  200.      if type=".LZX" then address command "lzx >CON: x -F """||currentfile||""" "||extractdir
  201.      if type=".ZIP" then address command "unzip >CON: """||currentfile||""" -d "||extractdir
  202.    end
  203.  end
  204. end
  205. return
  206.  
  207. addrep:
  208. lb=length(arg(1))
  209. nom=upper(arg(1))
  210. do i=1 to lines
  211.   if upper(left(name.i,lb))=nom then do
  212.     call writeln('f1',name.i)
  213.     say name.i
  214.   end
  215. end
  216. return
  217.  
  218. listing:
  219. lbuf=0
  220. dbuf=0
  221. last=""
  222. base=arg(1)
  223. lb=length(base)
  224. address value gui;list ID ARCH string
  225. if lines=0 then return
  226. list ID ARCH ATTRS MUIA_List_Quiet TRUE
  227. do i=1 to lines
  228.   nom=name.i
  229.   if lb~=0 then do
  230.     if upper(left(nom,lb))=upper(base) then do
  231.       nom=RIGHT(nom,length(nom)-lb)
  232.     end
  233.     else do
  234.       nom=""
  235.     end
  236.   end
  237.   if nom~="" then do
  238.     actuel=partone(nom)
  239.     if right(actuel,1)="/" then
  240.     do
  241.       j=dbuf+1
  242.       if dbuf>0 then do
  243.         do j=1 to dbuf
  244.           if upper(dirbuf.j)=upper(tree||actuel) then break
  245.         end
  246.       end
  247.       if j=dbuf+1 then do
  248.         dbuf=dbuf+1
  249.         dirbuf.dbuf=tree||actuel
  250.         lbuf=lbuf+1
  251.         buffer.lbuf=actuel
  252.         buffer2.lbuf="DIR"
  253.         list ID ARCH INSERT POS MUIV_List_Insert_Bottom STRING i||",\0336\033b"||actuel||",\033b\033r\0335"||direntry||","||actuel
  254.         /*list ID ARCH INSERT POS MUIV_List_Insert_Bottom STRING "\033b\0336"||actuel||",\033b\033r\0335"||direntry*/
  255.       end
  256.     end
  257.     else do
  258.       lbuf=lbuf+1
  259.       buffer.lbuf=actuel
  260.       buffer2.lbuf=size.i
  261.       list ID ARCH INSERT POS MUIV_List_Insert_Bottom STRING i||","||actuel||",\033r"||size.i||","||actuel
  262.     end
  263.   end
  264. end
  265. list ID ARCH ATTRS MUIA_List_Quiet FALSE
  266. return
  267.  
  268. partone:
  269. n=arg(1)
  270. parse var n a '/' b
  271. if length(n)~=length(a) then a=a||"/"
  272. return a
  273.  
  274. readlist:
  275. lines=0
  276. arc=0
  277. if right(arg(1),1)=":" | right(arg(1),1)="/" then return
  278. if ~exists(arg(1)) then return
  279. call info(readlist)
  280. type=upper(right(arg(1),4))
  281. if type=".LHA" | type=".LZH" then call readlha(arg(1))
  282. if type=".LZX" then call readlzx(arg(1))
  283. if type=".ZIP" then call readzip(arg(1))
  284. if arc=0 then do
  285.  address command "run >NIL: sys:utilities/Multiview >NIL: """||arg(1)||""""
  286. end
  287. return
  288.  
  289. readlha:
  290. address command "lha >T:"||gui||" v """||arg(1)||""""
  291. say 'T:'||gui
  292.  
  293. if open('f1','T:'||gui,'r') then do
  294.   say 'READ...'
  295.   a=readln('f1') /* Lha... */
  296.   a=readln('f1') /* copy...*/
  297.   a=readln('f1') /* copy...*/
  298.   a=readln('f1') /* Blank */
  299.   a=readln('f1') /* Unable ou Listing */
  300.   if left(a,4)~='List' then say 'NO LISTING!'
  301.   a=readln('f1') /* Blank ou Original */
  302.   if left(a,8)~='Original' then say 'no Original'
  303.   a=readln('f1') /* --------- */
  304.   if left(a,8)~="--------" then say 'no --------'
  305.   do forever
  306.     a=readln('f1')
  307.     if left(a,8)="--------" then break
  308.     if left(a,1)~=":" then do
  309.      parse var a Taille Compact Ratio Dat Time Name
  310.      lines=lines+1
  311.      name.lines=right(name,length(name)-2)
  312.      size.lines=taille
  313.     end
  314.   end
  315.   a=readln('f1')
  316.   parse var a unpacksize b
  317.   call close('f1')
  318.   arc=1
  319. end
  320. return
  321.  
  322. readlzx:
  323. address command "lzx >T:"||gui||" l """||arg(1)||""""
  324. if open('f1','T:'||GUI,'r') then do
  325.   say 'READ...'
  326.   a=readln('f1')
  327.   a=readln('f1') /* LZX Eva... */
  328.   a=readln('f1') /* Copyright...*/
  329.   a=readln('f1') /* Commercial... */
  330.   a=readln('f1')
  331.   a=readln('f1') /* Viewing or ** */
  332.   if left(a,4)~='View' then say 'NO LISTING!'
  333.   a=readln('f1')
  334.   a=readln