home *** CD-ROM | disk | FTP | other *** search
/ ANews 1 / AnewsCD01.iso / Script / Lhaction.rexx < prev   
OS/2 REXX Batch file  |  1999-08-13  |  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('f1') /* Blank ou Original */
  335.   if a~='Original  Packed  Ratio   Date      Time   Name' then say 'no Original'
  336.   a=readln('f1') /* --------- */
  337.   if left(a,8)~="--------" then say 'no --------'
  338.   do forever
  339.     a=readln('f1')
  340.     if left(a,8)="--------" then break
  341.     parse var a Taille Compact Ratio Dat Time Name
  342.     if ratio=" 100" then parse var a Taille Compact Ratio p Dat Time Name
  343.     if name~="" then do
  344.      lines=lines+1
  345.      name.lines=right(name,length(name)-1)
  346.      size.lines=taille
  347.     end
  348.   end
  349.   a=readln('f1')
  350.   parse var a unpacksize b
  351.   call close('f1')
  352.   arc=1
  353. end
  354. return
  355.  
  356. readzip:
  357. address command "unzip >T:"||gui||" -l """||arg(1)||""""
  358. if open('f1','T:'||gui,'r') then do
  359.   say 'READ...'
  360.   a=readln('f1')
  361.   a=readln('f1') /* Len */
  362.   if a~=' Length    Date    Time    Name' then say 'Version pb ?'
  363.   a=readln('f1') /* --------- */
  364.   if left(a,7)~=" ------" then say 'no --------'
  365.   do forever
  366.     a=readln('f1')
  367.     if left(a,7)=" ------" then break
  368.     parse var a Taille Dat Time Name
  369.     if name~="" then do
  370.      lines=lines+1
  371.      name.lines=right(name,length(name)-3)
  372.      size.lines=taille
  373.     end
  374.   end
  375.   a=readln('f1')
  376.   parse var a unpacksize b
  377.   call close('f1')
  378.   arc=1
  379. end
  380. return
  381.  
  382. info:
  383. address value GUI;
  384. string ID INFO content arg(1)
  385. return
  386.  
  387. locale:
  388. IF ~SHOW(L,'locale.library') then do
  389.  call ADDLIB('locale.library',0,-30)
  390. end;
  391. IF SHOW(L,'locale.library') then catalog=OpenCatalog("Lhaction.catalog","",0)
  392. else catalog=0
  393. titlewin=GetCS(0,"Lhaction")
  394. labname=GetCS(1,"Archive")
  395. labdir=GetCS(2,"Répertoire")
  396. lablist=GetCS(3,",\033b\033cNom,\033b\033cTaille")
  397. labroot=GetCS(4,"\033I[6:26] Racine")
  398. labpar=GetCS(5,"\033I[6:22] Parent")
  399. labext=GetCS(6,"\033I[6:24] Extraction")
  400. aslarc=GetCS(7,"Nom de l'archive Lha")
  401. asldir=GetCS(8,"Répertoire où décompacter")
  402. direntry=GetCS(9,"\033I[6:22]")
  403. welcome=GetCS(10,"\033cBienvenue")
  404. readlist=GetCS(11,"Lecture du contenu...")
  405. getready=GetCS(12,"A vos ordres...")
  406. showfile=GetCS(13,"Visualisation de:")
  407. extracting=GetCS(14,"Extraction de l'archive...")
  408. filesizeinfo=GetCS(15,"Taille de l'archive:")
  409. labview=GetCS(16,"\033I[6:25] Voir")
  410. helpname=GetCS(17,"Chemain et nom de\nl'archive de travail")
  411. helpdir=GetCS(18,"Répertoire où l'archive\nserra décompactée")
  412. helplist=GetCS(19,"Contenu de l'archive, pour entrer dans\nun répertoire ou visualiser un fichier,\ndouble-cliquez dessus")
  413. helproot=GetCS(20,"Revient au repertoire\nracine dans l'archive")
  414. helppar=GetCS(21,"Retourne dans le répertoire\nparent dans l'archive")
  415. helpext=GetCS(22,"Lance l'extraction du\ncontenu de l'archive")
  416. helpready=GetCS(23,"Affiche des informations\nsur le travail en cours")
  417. helpview=GetCS(24,"Désarchive le fichier selectionné\ndans T: puis l'affiche avec Multiview")
  418. infosize=GetCS(25,"Taille décompactée: ")
  419. if catalog~=0 then call CloseCatalog(catalog)
  420. return
  421.  
  422. GetCS:
  423. if catalog~=0 then return GetCatalogStr(catalog,arg(1),arg(2))
  424. return arg(2)
  425.  
  426. opengui:
  427. muirexx= 'SYS:Utilities/MUIRexx'
  428. if ~(Exists(muirexx)) then do
  429.  muirexx= 'C:MUIRexx'
  430.  if ~(Exists(muirexx)) then do;CALL rtezrequest "I need MUIRexx in SYS:Utilities, Install it properly...",, "Lhaction";exit 20;end
  431. end
  432. address rexx
  433. foo=open('OUT','T:lhact.runscript','W')
  434. foo=writeln('OUT',"FailAt 21")
  435. foo=writeln('OUT',"Stack 40000")
  436. foo=writeln('OUT',"run "||muirexx||" PORT "||gui)
  437. foo=writeln('OUT',"waitforport "||gui)
  438. foo=close('OUT')
  439. address Command 'execute T:lhact.runscript'
  440. address value gui;
  441.  
  442. MUIA_Window_AppWindow = 0x804280cf
  443. MUIA_Window_Title = 0x8042ad3d
  444. MUIA_Window_ScreenTitle = 0x804234b0
  445. MUIA_Popasl_Type = 0x8042df3d
  446. ASLFR_RejectPattern = 0x8008003D
  447. TRUE = 1
  448. FALSE = 0
  449. ASLFR_RejectIcons = 0x8008003C
  450. ASLFR_TitleText = 0x80080001
  451. ASLFR_InitialDrawer = 0x80080009
  452. ASLFR_DrawersOnly = 0x8008002F
  453. MUIA_Listview_MultiSelect = 0x80427e08
  454. MUIA_List_Format = 0x80423c0a
  455. MUIA_Window_CloseGadget = 0x8042a110
  456. MUIA_Window_ID = 0x804201bd
  457. MUIV_List_Insert_Bottom=-3
  458. MUIA_List_Active = 0x8042391c
  459. MUIA_List_Quiet = 0x8042d8c7
  460. MUIA_List_First = 0x804238d4
  461. CycleChain= 0x80421ce7
  462. MUIV_EveryTime = 0x49893131
  463.  
  464. window ID LHACT COMMAND """QUIT""" PORT server TITLE '"'titlewin'"' ATTRS MUIA_Window_CloseGadget TRUE MUIA_Window_AppWindow TRUE
  465.  group HORIZ
  466.   group
  467.    label DOUBLE labname
  468.    label DOUBLE labdir
  469.   endgroup
  470.   group
  471.    popasl ID FILE COMMAND "FILE" PORT server SPEC "6:19" ATTRS ASLFR_RejectPattern TRUE ASLFR_RejectIcons TRUE ASLFR_TitleText '"'aslarc'"' HELP '"'helpname'"' CONTENT currentfile
  472.    popasl ID DIR COMMAND "DIR" PORT server SPEC "6:20" ATTRS ASLFR_DrawersOnly TRUE ASLFR_RejectPattern TRUE ASLFR_TitleText '"'asldir'"' HELP '"'helpdir'"' CONTENT extractdir
  473.   endgroup
  474.  endgroup
  475.  group
  476.   list ID ARCH COMMAND "LIST" PORT server ATTRS MUIA_Listview_MultiSelect TRUE TITLE lablist ATTRS MUIA_List_Format """MIW=60 COL=1 BAR,MIW=40 COL=2 P=\033r""" MUIA_Listview_DoubleClick TRUE MUIA_Disabled TRUE HELP '"'helplist'"'
  477.   group HORIZ
  478.    button ID Root COMMAND "ROOT" PORT server HELP '"'helproot'"' LABEL labroot
  479.    button ID PAR COMMAND "PARENT" PORT server HELP '"'helppar'"' LABEL labpar
  480.    button ID VIEW COMMAND "LIST" PORT server HELP '"'helpview'"' LABEL labview
  481.    button ID EXT COMMAND "EXTRACT" PORT server HELP '"'helpext'"' LABEL labext
  482.   endgroup
  483.   string ID INFO HELP '"'helpready'"' LABEL welcome
  484.   button ID COPIE COMMAND "COPYACT" PORT server Label "Ajoute nom dans Action"
  485.  endgroup
  486. endwindow
  487.  
  488. callhook ID LHACT APP DROP COMMAND '"DROP %s"' PORT server
  489. callhook ID ARCH COMMAND '"LSTUPD"' PORT server ATTRS MUIA_List_Active MUIV_EveryTime
  490. return
  491.