home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / lha2lzx / lha2lzx_v2.6 < prev    next >
Text File  |  1998-04-27  |  14KB  |  409 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:Eval PURE
  4. Resident > NIL: C:List PURE
  5.  
  6. ; $VER: LhA2LZX v2.6 (9.12.97) Richard Burke
  7.  
  8. Failat 60                    ;Allows errors when using LhA & LZX to be captured
  9.  
  10. lab Beg
  11. if EXISTS env:drw1                ;If the file ENV:drw1 exists, the script will perform the actions to endif
  12.     cd $drw1                ;Current Directory is now that which is stated in the contents of the environmental variable 'drw1'
  13.     if EXISTS l2z                ;If the temporary drawer used to store the archive files exists
  14.         delete l2z ALL QUIET FORCE    ;then it is deleted to start freshly
  15.     endif
  16.     delete env:drw1 QUIET
  17. endif
  18.  
  19. if NOT EXISTS env:o                ;If starting, default path of archive is RAM:
  20.     echo RAM: >env:o            ;If converting several archives, the path of the last archive will be used as the default of the next
  21. endif
  22.  
  23. if NOT EXISTS env:d                ;If starting, default path of temporary drawer l2z is RAM:
  24.     echo RAM: >env:d            ;If converting several archives, the previous path of l2z will be used as the default of the next
  25. endif
  26.  
  27. which >env:wlha lha all                ;Finds the location of the LhA tool
  28. if WARN                        ;If the LhA tool cannot be found
  29.     RequestChoice "LhA2LZX Error Message" "Can't find 'LhA' tool!*nSee docs for details!" "Quit"
  30.     quit
  31. endif
  32.  
  33. which >env:wlzx lzx all                ;Finds the location of the LZX tool e.g. 'C:LZX'
  34. if WARN
  35.     RequestChoice "LhA2LZX Error Message" "Can't find 'LZX' tool!*nSee docs for details!" "Quit"
  36.     quit
  37. endif
  38.  
  39. lab Path
  40. 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
  41. if WARN
  42.     skip end
  43. endif
  44.  
  45. if NOT EXISTS $orig
  46.     RequestChoice >nil: "! Error !" "PATH does not exist!" "Try again"
  47.     skip Path BACK
  48. endif
  49.  
  50. echo >env:o $orig                ;Get rid of quotation marks, and also create default path for next archive if converting more
  51. list >env:osz env:o LFORMAT=%L            ;Get size of path name
  52. if $osz EQ 1                    ;Full path not selected
  53.     RequestChoice > NIL: "! Error !" "Choose FULL path!*n(i.e. start with DEVICE listing)" "Try again"
  54.     skip Path BACK
  55. endif
  56.  
  57. lab File
  58. RequestFile >env:ldfl TITLE "Chose file to convert" POSITIVE Convert ACCEPTPATTERN #?.(lha|lzx|lzh) DRAWER $orig        ; $ldfl now contains the complete path and filename of the archive
  59. if WARN
  60.     skip More
  61. endif
  62.  
  63. if NOT EXISTS $ldfl
  64.     RequestChoice >nil: "! Error !" "FILE does not exist!" "Try again"
  65.     skip File BACK
  66. endif
  67.  
  68. echo >env:l $ldfl                ;Get rid of quotation marks
  69. list >env:lsz env:l LFORMAT=%L            ;Get size of file name
  70. if $lsz EQ $osz                    ;No file selected
  71.     RequestChoice > NIL: "! Error !" "No file chosen!" "Try again"
  72.     skip File BACK
  73. endif
  74.  
  75. list >env:bnm1 $ldfl LFORMAT=%S            ;Strips the path of the archive to give only the filename with suffix
  76. list >env:bnm $ldfl LFORMAT=%M            ;Removes .lzx, .lha or .lzh suffix from filename
  77. list >env:suf $ldfl LFORMAT=%E            ;Gives suffix only
  78.  
  79. if $suf NOT EQ lha                ;If file doesn't have .lha suffix
  80.     if $suf NOT EQ lzx            ;If file doesn't have .lzx suffix
  81.         if $suf NOT EQ lzh        ;If file doesn't have .lzh suffix (which is de-archived by LhA)
  82.             RequestChoice "! Error !" "File is NOT an LhA or LZX archive!" "Choose again!"
  83.         endif
  84.     endif
  85. endif
  86.  
  87. if $suf EQ lha
  88.     echo LZX >env:nsuf            ;Gives the type of file to convert to in a requestor later
  89.     echo LhA >env:suf
  90. endif
  91.  
  92. if $suf EQ lzx
  93.     echo LhA >env:nsuf
  94.     echo LZX >env:suf            ;Makes it look better in the requestor
  95. endif
  96.  
  97. if $suf EQ lzh
  98.     echo LZX >env:nsuf
  99.     echo LZH >env:suf
  100. endif
  101.  
  102. lab Temp
  103. 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"
  104. if $drw EQ 1                    ;If the left button (i.e. RAM:) is chosen
  105.     echo "RAM:" >env:drw1
  106. endif
  107.  
  108. lab Other
  109. if $drw EQ 2                    ;If "Other" is chosen
  110.     RequestFile >env:drw1 TITLE "Where should 'L2Z' be made?" DRAWERSONLY NOICONS POSITIVE Create DRAWER "$d"
  111.     if WARN
  112.         skip More
  113.     endif
  114.     echo >env:d $drw1            ;Get rid of quotation marks
  115.     list >env:dsz env:d LFORMAT=%L        ;Get size of path name
  116.     if $dsz EQ 1                ;Full path not selected
  117.         RequestChoice > NIL: "! Error !" "Choose FULL path!*n(i.e. start with DEVICE listing)" "Try again"
  118.         skip Other BACK
  119.     endif
  120.     if NOT EXISTS $drw1
  121.         RequestChoice "! Error !" "PATH does not exist!" "Choose again!"
  122.         skip Other BACK
  123.     endif
  124. endif
  125.  
  126. if $drw EQ 0                    ;If "Cancel" is chosen
  127.     skip More
  128. endif
  129.  
  130. lab Memchk                    ;This labels the following section as "Memchk" so the script can skip to this point from anywhere in the script if it encounters the line "skip Memchk"
  131. set memsz `avail flush total`            ;Saves the result from "avail flush total" (try it in a shell - it gets the total size of available memory) as ENV:memsz
  132. cd $orig                    ;CD's to the directory of the original archive
  133. list >env:flsz $ldfl LFORMAT=%L            ;Gets size of original archive
  134. eval >env:flmem $flsz * 4            ;Multiplies the archive size by 4
  135. if NOT $memsz VAL GT $flmem            ;If your available memory size is less than 4 times the size of the original archive (LZX often decompresses to 3-4 times the size of the archive)
  136.     if $drw1 EQ "RAM:"            ;and RAM: has been chosen to store temporary files
  137.         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"
  138.         if $nomem EQ 0            ;"Cancel"
  139.             skip More
  140.         endif
  141.         if $nomem EQ 1            ;"Other"
  142.             skip Temp back
  143.         endif
  144.         if $nomem EQ 2            ;"Continue"
  145.             skip MkTemp
  146.         endif
  147.     endif
  148.     if $drw1 EQ "Ram Disk:"        ;If user clicks on RAM: in file requestor
  149.         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"
  150.         if $nomem EQ 0            ;"Cancel"
  151.             skip More
  152.         endif
  153.         if $nomem EQ 1            ;"Other"
  154.             skip Temp back
  155.         endif
  156.         if $nomem EQ 2            ;"Continue"
  157.             skip MkTemp
  158.         endif
  159.     endif
  160. endif
  161.  
  162. lab MkTemp
  163. cd $drw1
  164. if NOT EXISTS l2z            ;This creates a temporary drawer in which to de-archive the files in the archive
  165.     makedir > NIL: l2z
  166. else                    ;Drawer is emptied if it is already there
  167.     delete l2z/#? FORCE QUIET
  168. endif
  169.  
  170. lab extra
  171. echo "*e[0 p"                ;This clears the display (the output CLI)
  172. RequestChoice >env:ext "Convert $l to . . ." "Do you want to convert to the other*nfiletype or to the smallest archive?*n*nConvert from $suf to:" "$nsuf" "Smallest" "Cancel"
  173. if WARN                    ;If 'Cancel' is selected
  174.     skip beg BACK            ;This skips back to the section labelled 'Beg', at the beginning
  175. endif
  176.  
  177. if $ext EQ 2                ;If the user wants to make the smallest archive
  178.     skip Conv            ;This skips forward to the section labelled 'Conv'
  179. endif
  180.  
  181. 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
  182.     if $suf EQ lha            ;Means it is an LhA archive
  183.     lab L                ;Label 'L' so the script can skip straight here if told to
  184.         cd $drw1
  185.         cd l2z
  186.         $wlzx x -a -F -x $ldfl        ;As the LZX keyfile is now available, the ability to de-archive LhA files is possible, and also much quicker
  187.         if $RC EQ 20            ;If user aborts it will skip to 'More'
  188.             skip More        ;RC stands for Return Code - the number returned by LhA if the operation fails
  189.         endif
  190.         $wlzx -r -e -3 -X -F a -Qf $bnm #?
  191.         if $RC EQ 50            ;If user aborts it will skip to 'More'
  192.             skip More
  193.         endif
  194.         list >env:old $ldfl LFORMAT=%L            ;Gets the size of the original archive
  195.         list >env:new $bnm.lzx LFORMAT=%L        ;Gets the size of the new archive
  196.         eval >env:diff $old - $new            ;Subtracts the size of the new from the original
  197.         eval >env:diff1 $new - $old            ;Subtracts the size of the original from the new
  198.         delete $ldfl QUIET                ;Original archive is deleted
  199.         copy $bnm.lzx TO $orig QUIET            ;New archive is copied in place of the original
  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.             RequestChoice > NIL: "! Operation Successful !" "$o$bnm.lzx*n  now replaces*n$l*n  and is $diff bytes smaller!" "Nice one!"
  202.         else
  203.             RequestChoice > NIL: "! Operation Successful !" "$o$bnm.lzx*n  now replaces*n$l*n  and is $diff1 bytes larger" "Okay"
  204.         endif
  205.     else                            ;"If that fails, try this..." - i.e. means it is NOT an LhA archive
  206.         if $suf EQ lzh                    ;It is an LZH archive (processed by LhA)
  207.             skip L BACK
  208.         endif
  209.         cd $drw1                    ;If this line is reached, it is an LZX archive
  210.         cd l2z
  211.         $wlzx x -a -F -x $ldfl                ;LZX extracts the original archive to temporary drawer 'l2z'
  212.         if $RC EQ 50                    ;If user aborts it will skip to 'More'
  213.             skip More
  214.         endif
  215.         $wlha -2 -a -r -F -y -M -e -x a $bnm #?            ;LhA archives everything in 'l2z' and saves it as the original name with .lha suffix
  216.         if $RC EQ 20                    ;If user aborts it will skip to 'More'
  217.             skip More
  218.         endif
  219.         list >env:old $ldfl LFORMAT=%L
  220.         list >env:new $bnm.lha LFORMAT=%L
  221.         eval >env:diff $old - $new
  222.         eval >env:diff1 $new - $old
  223.         delete $ldfl QUIET                ;Original archive is deleted
  224.         copy $bnm.lha TO $orig QUIET            ;New archive is copied in place of the original
  225.         if $old GT $new VAL
  226.             RequestChoice > NIL: "! Operation Successful !" "$o$bnm.lha*n  now replaces*n$l*n  and is $diff bytes smaller!" "Nice one!"
  227.         else
  228.             RequestChoice > NIL: "! Operation Successful !" "$o$bnm.lha*n  now replaces*n$l*n  and is $diff1 bytes larger" "Okay"
  229.         endif
  230.     endif
  231. endif
  232.  
  233. skip More
  234.  
  235. lab Conv                    ;This part until 'lab More' converts the archive to either LhA or LZX, and saves whichever is smaller
  236. if $suf EQ lha                    ;Means it is an LhA archive
  237.     lab L2
  238.     cd $drw1
  239.     cd l2z
  240.     $wlzx x -a -F -x $ldfl            ;As the LZX keyfile is now available, the ability to de-archive LhA files is possible, and also much quicker
  241.     if $RC EQ 20                ;If user aborts it will skip to 'More'
  242.         skip More            ;RC stands for Return Code - the number returned by LhA if the operation fails
  243.     endif
  244.     $wlzx -r -e -3 -X -F a -Qf $bnm #?        ;If not aborted, file is archived
  245.     if $RC EQ 50                ;If user aborts it will skip to 'More'
  246.         skip More
  247.     endif
  248. else                        ;Means it is not an LhA archive
  249.     if $suf EQ lzh                ;Means it is an LZH archive
  250.         skip L2 BACK
  251.     endif
  252.     cd $drw1                ;If this line is reached, it is an LZX archive
  253.     cd l2z
  254.     $wlzx x -a -F -x $ldfl
  255.     if $RC EQ 50                ;If user aborts it will skip to 'More'
  256.         skip More
  257.     endif
  258.     $wlha -2 -a -r -F -y -M -e -x a $bnm #?        ;If not aborted, file is archived
  259.     if $RC EQ 20                    ;If user aborts it will skip to 'More'
  260.         skip More
  261.     endif
  262. endif
  263.  
  264. list >env:old $ldfl LFORMAT=%L                ;Gets the size of the original archive
  265. list >env:new $bnm.(lzx|lha) LFORMAT=%L            ;Gets the size of the new archive
  266. eval >env:diff $old - $new                ;Subtracts the size of the new from the original
  267. eval >env:diff1 $new - $old                ;Subtracts the size of the original from the new
  268.  
  269. 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
  270.     delete $ldfl QUIET
  271.     copy $bnm.(lzx|lha) TO $orig QUIET
  272.     list >env:arc $o$bnm.(lzx|lha) LFORMAT=%S%S                                    ;Gets name of new archive
  273.     echo >env:arc1 $arc                                                ;Removes quotation marks
  274.     RequestChoice > NIL: "! $arc1 used !" "Using the new archive because it's $diff bytes smaller!" "Nice one!"
  275. else                                                            ;Original archive is smaller than the new one, so the smaller original one is kept
  276.     RequestChoice > NIL: " $l used" "Using the original archive because it's $diff1 bytes smaller!" "Okay"        ;The difference in file sizes is cleverly given
  277.     cd $drw1
  278.     delete l2z ALL QUIET FORCE
  279. endif
  280.  
  281. lab More
  282. echo "*ec"
  283. RequestChoice >env:ano "Other archives?" "Do you want to convert another archive?" "Yes" "No"
  284. if $ano EQ 0
  285.     skip end
  286. else
  287.     skip beg back
  288. endif
  289.  
  290. lab end
  291. echo "*ec"                                    ;This clears the output window
  292. echo "*n*n*n                       *e[1;32m  Thank you for using"
  293. 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 - known as ANSI - see "v2.2" in "Program History" in the .guide
  294. echo "*n*n*n"
  295. if EXISTS env:old
  296.     delete env:old QUIET
  297. endif
  298.  
  299. if EXISTS env:diff
  300.     delete env:diff QUIET
  301. endif
  302.  
  303. if EXISTS env:diff1
  304.     delete env:diff1 QUIET
  305. endif
  306.  
  307. if EXISTS env:flsz
  308.     delete env:flsz QUIET
  309. endif
  310.  
  311. if EXISTS env:memsz
  312.     delete env:memsz QUIET
  313. endif
  314.  
  315. if EXISTS env:flmem
  316.     delete env:flmem QUIET
  317. endif
  318.  
  319. if EXISTS env:new
  320.     delete env:new QUIET
  321. endif
  322.  
  323. if EXISTS env:ano
  324.     delete env:ano QUIET
  325. endif
  326.  
  327. if EXISTS env:osz
  328.     delete env:osz QUIET
  329. endif
  330.  
  331. if EXISTS env:o
  332.     delete env:o QUIET
  333. endif
  334.  
  335. if EXISTS env:d
  336.     delete env:d QUIET
  337. endif
  338.  
  339. if EXISTS env:dsz
  340.     delete env:dsz QUIET
  341. endif
  342.  
  343. if EXISTS env:arc
  344.     delete env:arc QUIET
  345. endif
  346.  
  347. if EXISTS env:arc1
  348.     delete env:arc1 QUIET
  349. endif
  350.  
  351. if EXISTS env:l
  352.     delete env:l QUIET
  353. endif
  354.  
  355. if EXISTS env:lsz
  356.     delete env:lsz QUIET
  357. endif
  358.  
  359. if EXISTS env:wlha
  360.     delete env:wlha QUIET
  361. endif
  362.  
  363. if EXISTS env:ext
  364.     delete env:ext QUIET
  365. endif
  366.  
  367. if EXISTS env:wlzx
  368.     delete env:wlzx QUIET
  369. endif
  370.  
  371. if EXISTS env:bnm1
  372.     delete env:bnm1 QUIET
  373. endif
  374.  
  375. if EXISTS env:bnm
  376.     delete env:bnm QUIET
  377. endif
  378.  
  379. if EXISTS env:suf
  380.     delete env:suf QUIET
  381. endif
  382.  
  383. if EXISTS env:nsuf
  384.     delete env:nsuf QUIET
  385. endif
  386. if EXISTS env:nomem
  387.     delete env:nomem QUIET
  388. endif
  389.  
  390. if EXISTS env:orig
  391.     delete env:orig QUIET
  392. endif
  393.  
  394. if EXISTS env:ldfl
  395.     delete env:ldfl QUIET
  396. endif
  397.  
  398. if EXISTS env:drw1
  399.     cd $drw1
  400.     if EXISTS l2z
  401.         delete l2z ALL QUIET FORCE
  402.     endif
  403.     delete env:drw1 QUIET
  404. endif
  405.  
  406. if EXISTS env:drw
  407.     delete env:drw QUIET
  408. endif
  409. quit