home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / lha2lzx / lha2lzx_v2.1 < prev    next >
Text File  |  1998-04-27  |  9KB  |  328 lines

  1. Resident > NIL: C:RequestChoice PURE
  2. Resident > NIL: C:RequestFile PURE
  3. Resident > NIL: C:BaseName PURE
  4. Resident > NIL: C:Eval PURE
  5. Resident > NIL: C:List PURE
  6.  
  7. ; $VER: LhA2LZX v2.1 (10.7.97) Richard Burke
  8.  
  9. Failat 60
  10.  
  11. lab beg
  12. if EXISTS env:wlha            ;All the environment variables LhA2LZX uses are deleted
  13.         delete env:wlha QUIET        ;if they are present to start freshly
  14. endif
  15.  
  16. if EXISTS env:wlzx
  17.         delete env:wlzx QUIET
  18. endif
  19.  
  20. if EXISTS env:diff
  21.         delete env:diff QUIET
  22. endif
  23.  
  24. if EXISTS env:diff1
  25.         delete env:diff1 QUIET
  26. endif
  27.  
  28. if EXISTS env:ext
  29.         delete env:ext QUIET
  30. endif
  31.  
  32. if EXISTS env:ano
  33.         delete env:ano QUIET
  34. endif
  35.  
  36. if EXISTS env:osz
  37.         delete env:osz QUIET
  38. endif
  39.  
  40. if EXISTS env:o
  41.         delete env:o QUIET
  42. endif
  43.  
  44. if EXISTS env:l
  45.         delete env:l QUIET
  46. endif
  47.  
  48. if EXISTS env:lsz
  49.         delete env:lsz QUIET
  50. endif
  51.  
  52. if EXISTS env:old
  53.         delete env:old QUIET
  54. endif
  55.  
  56. if EXISTS env:new
  57.         delete env:new QUIET
  58. endif
  59.  
  60. if EXISTS env:bnm1
  61.         delete env:bnm1 QUIET
  62. endif
  63.  
  64. if EXISTS env:bnm
  65.         delete env:bnm QUIET
  66. endif
  67.  
  68. if EXISTS env:orig
  69.         delete env:orig QUIET
  70. endif
  71.  
  72. if EXISTS env:ldfl
  73.         delete env:ldfl QUIET
  74. endif
  75.  
  76. if EXISTS env:drw1
  77.         cd $drw1                ;Current Directory is now that which is stated in the contents of the environmental variable 'drw1'
  78.         if EXISTS l2z                ;If the temporary drawer used to store the archive files exists
  79.                 delete l2z ALL QUIET FORCE    ;then it is deleted to start freshly
  80.         endif
  81.         delete env:drw1 QUIET
  82. endif
  83.  
  84. if EXISTS env:drw
  85.         delete env:drw QUIET
  86. endif
  87.  
  88. which lha all >env:wlha                ;Finds the location of the LhA tool
  89. if WARN                        ;If the LhA tool cannot be found
  90.         requestchoice "LhA2LZX Error Message" "Can't find 'LhA' tool!*nSee docs for details!" "Quit"
  91.         quit
  92. endif
  93.  
  94. which lzx all >env:wlzx                ;Finds the location of the LZX tool e.g. 'C:LZX'
  95. if WARN
  96.         requestchoice "LhA2LZX Error Message" "Can't find 'LZX' tool!*nSee docs for details!" "Quit"
  97.         quit
  98. endif
  99.  
  100. lab Path
  101. RequestFile >env:orig TITLE "Full path of drawer of archive?" DRAWERSONLY NOICONS    ;Saves the location of the archive in the environment variable 'orig'
  102. if WARN
  103.         skip end
  104. endif
  105.  
  106. echo >env:o $orig                ;Get rid of quotation marks
  107. list >env:osz env:o LFORMAT=%L            ;Get size of path name
  108. if "$osz" EQ "1"                ;Full path not selected
  109.     echo "Choose FULL path!"
  110.     skip Path BACK
  111.     delete env:osz QUIET
  112.     delete env:o QUIET
  113. endif
  114.  
  115. lab File
  116. RequestFile >env:ldfl TITLE "Chose file to convert" POSITIVE Convert ACCEPTPATTERN #?.(lha|lzx) DRAWER $orig
  117. if WARN
  118.         skip More
  119. endif
  120.  
  121. echo >env:l $ldfl                ;Get rid of quotation marks
  122. list >env:lsz env:l LFORMAT=%L            ;Get size of file name
  123. if "$lsz" EQ "$osz"                ;No file selected
  124.     echo "No file chosen!"
  125.     skip File BACK
  126.     delete env:lsz QUIET
  127.     delete env:l QUIET
  128. endif
  129.  
  130. basename >env:bnm1 $ldfl    ;Strips the path of the archive to give only the filename with suffix
  131. basename >env:bnm $bnm1 .lzx    ;Removes .lzx suffix from filename if it has it
  132.  
  133. RequestChoice >env:drw "Default directory" "Where should I store temporary files?*nRAM: is fastest but not advisable if you*nhaven't got much. A temporary drawer called 'L2Z'*nwill be created in your selected destination" "RAM:" "Other"
  134. if $drw EQ 1                ;If the left button (i.e. RAM:) is chosen
  135.         echo RAM: >env:drw1
  136. endif
  137.  
  138. if $drw EQ 0
  139.         RequestFile >env:drw1 TITLE "Where should 'L2Z' be made?" DRAWERSONLY NOICONS POSITIVE Create
  140.     if WARN
  141.         skip more
  142.     endif
  143. endif
  144.  
  145. cd $drw1
  146. if NOT EXISTS l2z            ;This creates a temporary drawer in which to de-archive the files in the archive
  147.         makedir > NIL: l2z
  148. else                    ;Drawer is emptied if it is already there
  149.         delete l2z/#? FORCE QUIET
  150. endif
  151.  
  152. lab extra
  153. RequestChoice >env:ext "FileType" "Do you want to convert to the other*nfiletype or to the smallest archive?*n*nConvert to:" "Other" "Smallest" "Cancel"
  154. if WARN                    ;If 'Cancel' is selected
  155.         skip beg BACK            ;This skips back to the section labelled 'Beg', at the beginning
  156. endif
  157.  
  158. if $ext EQ 2                ;If the user wants to make the smallest archive
  159.         skip Conv            ;This skips forward to the section labelled 'Conv'
  160. endif
  161.  
  162. if $ext EQ 1                        ;If the user wants to convert to the other format - original format is found and is intelligently converted to the other
  163.     if $bnm1 EQ $bnm                ;Means it is an LhA archive
  164.             delete env:bnm QUIET
  165.             basename >env:bnm $bnm1 .lha
  166.             cd $drw1
  167.             cd l2z
  168.             $wlha x -a $ldfl
  169.         if $RC EQ 20                ;If user aborts it will skip to 'More'
  170.             skip More
  171.         endif
  172.             $wlzx -r -e -3 a $bnm #?
  173.         if $RC EQ 50                ;If user aborts it will skip to 'More'
  174.             skip More
  175.         endif
  176.         delete $ldfl QUIET
  177.             copy $bnm.lzx TO $orig QUIET
  178.     else                        ;Means it is NOT an LhA archive (i.e. suffix has been stripped)
  179.                 cd $drw1
  180.                 cd l2z
  181.                 $wlzx x -a $ldfl            ;LZX extracts the original archive to temporary drawer 'l2z'
  182.         if $RC EQ 50                ;If user aborts it will skip to 'More'
  183.             skip More
  184.         endif
  185.                 $wlha -2ar a $bnm #?            ;LhA archives everything in 'l2z' and saves it as the original name with .lha suffix
  186.         if $RC EQ 20                ;If user aborts it will skip to 'More'
  187.             skip More
  188.         endif
  189.         delete $ldfl QUIET            ;Original archive is deleted
  190.             copy $bnm.lha TO $orig QUIET        ;New archive is copied in place of the original
  191.     endif
  192. endif
  193.  
  194. skip More
  195.  
  196. lab Conv                ;This part until 'lab More' converts the archive to either LhA or LZX, and saves whichever is smaller
  197. if $bnm1 EQ $bnm            ;Means it is an LhA archive (i.e. suffix not stripped)
  198.         delete env:bnm QUIET
  199.         basename >env:bnm $bnm1 .lha
  200.         cd $drw1
  201.         cd l2z
  202.         $wlha x -a $ldfl
  203.     if $RC EQ 20            ;If user aborts it will skip to 'More'
  204.         skip More
  205.     endif
  206.         $wlzx -r -e -3 a $bnm #?    ;If not aborted, file is archived
  207.     if $RC EQ 50            ;If user aborts it will skip to 'More'
  208.         skip More
  209.     endif
  210. else                    ;Means it is an LZX archive
  211.         cd $drw1
  212.         cd l2z
  213.         $wlzx x -a $ldfl
  214.     if $RC EQ 50            ;If user aborts it will skip to 'More'
  215.         skip More
  216.     endif
  217.         $wlha -2ar a $bnm #?        ;If not aborted, file is archived
  218.     if $RC EQ 20            ;If user aborts it will skip to 'More'
  219.         skip More
  220.     endif
  221. endif
  222.  
  223. list >env:old $ldfl LFORMAT=%L        ;Gets the size of the original archive
  224. list >env:new $bnm.(lzx|lha) LFORMAT=%L    ;Gets the size of the new archive
  225. eval >env:diff $old - $new        ;Subtracts the size of the new from the original
  226. eval >env:diff1 $new - $old        ;Subtracts the size of the original from the new
  227.  
  228. if $old GT $new VAL                                        ;Original archive is larger than the new one, so the original is deleted and replaced by the smaller new one
  229.         delete $ldfl QUIET
  230.         echo "*e[1;1H*e[J*n Using new archive because it's *e[2m$diff *e[0mbytes smaller!"    ;All the *e[... parts do is change the colour/style of the text
  231.         copy $bnm.(lzx|lha) TO $orig QUIET
  232. else                                                ;Original archive is smaller than the new one, so the smaller original one is kept
  233.         echo "*e[1;1H*e[J*n Using old archive because it's *e[2m$diff1 *e[0mbytes smaller!"    ;The difference in file sizes is cleverly given
  234.         cd $drw1
  235.         delete l2z ALL QUIET FORCE
  236. endif
  237.  
  238. lab More
  239. RequestChoice >env:ano "Other archives?" "Do you want to convert another archive?" "Yes" "No"
  240. if $ano EQ 0
  241.         skip end
  242. else
  243.         skip beg back
  244. endif
  245.  
  246. lab end
  247. echo "*e[1;1H*e[J"        ;This clears the output window
  248. echo ""
  249. echo ""
  250. echo ""
  251. echo "                       *e[1;32m  Thank you for using"
  252. echo "                              *e[33m LhA*e[0m*e[3;1m2*e[0m*e[2mLZX"
  253. if EXISTS env:old
  254.         delete env:old QUIET
  255. endif
  256.  
  257. if EXISTS env:diff
  258.         delete env:diff QUIET
  259. endif
  260.  
  261. if EXISTS env:diff1
  262.         delete env:diff1 QUIET
  263. endif
  264.  
  265. if EXISTS env:new
  266.         delete env:new QUIET
  267. endif
  268.  
  269. if EXISTS env:ano
  270.         delete env:ano QUIET
  271. endif
  272.  
  273. if EXISTS env:osz
  274.         delete env:osz QUIET
  275. endif
  276.  
  277. if EXISTS env:o
  278.         delete env:o QUIET
  279. endif
  280.  
  281. if EXISTS env:l
  282.         delete env:l QUIET
  283. endif
  284.  
  285. if EXISTS env:lsz
  286.         delete env:lsz QUIET
  287. endif
  288.  
  289. if EXISTS env:wlha
  290.         delete env:wlha QUIET
  291. endif
  292.  
  293. if EXISTS env:ext
  294.         delete env:ext QUIET
  295. endif
  296.  
  297. if EXISTS env:wlzx
  298.         delete env:wlzx QUIET
  299. endif
  300.  
  301. if EXISTS env:bnm1
  302.         delete env:bnm1 QUIET
  303. endif
  304.  
  305. if EXISTS env:bnm
  306.         delete env:bnm QUIET
  307. endif
  308.  
  309. if EXISTS env:orig
  310.         delete env:orig QUIET
  311. endif
  312.  
  313. if EXISTS env:ldfl
  314.         delete env:ldfl QUIET
  315. endif
  316.  
  317. if EXISTS env:drw1
  318.         cd $drw1
  319.         if EXISTS l2z
  320.                 delete l2z ALL QUIET FORCE
  321.         endif
  322.         delete env:drw1 QUIET
  323. endif
  324.  
  325. if EXISTS env:drw
  326.         delete env:drw QUIET
  327. endif
  328. quit