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

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