home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -readerstuff- / richard_burke / lha2lzx / lha2lzx_v2.4 < prev    next >
Text File  |  1998-05-02  |  13KB  |  381 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.4 (25.7.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. echo >env:o $orig                ;Get rid of quotation marks, and also create default path for next archive if converting more
  46. list >env:osz env:o LFORMAT=%L            ;Get size of path name
  47. if $osz EQ 1                    ;Full path not selected
  48.     RequestChoice > NIL: "! Error !" "Choose FULL path!*n(i.e. start with DEVICE listing)" "Try again"
  49.     skip Path BACK
  50. endif
  51.  
  52. lab File
  53. 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
  54. if WARN
  55.     skip More
  56. endif
  57.  
  58. echo >env:l $ldfl                ;Get rid of quotation marks
  59. list >env:lsz env:l LFORMAT=%L            ;Get size of file name
  60. if $lsz EQ $osz                    ;No file selected
  61.     RequestChoice > NIL: "! Error !" "No file chosen!" "Try again"
  62.     skip File BACK
  63. endif
  64.  
  65. list >env:bnm1 $ldfl LFORMAT=%S            ;Strips the path of the archive to give only the filename with suffix
  66. list >env:bnm $ldfl LFORMAT=%M            ;Removes .lzx, .lha or .lzh suffix from filename
  67. list >env:suf $ldfl LFORMAT=%E            ;Gives suffix only
  68.  
  69. if $suf NOT EQ lha                ;If file doesn't have .lha suffix
  70.     if $suf NOT EQ lzx            ;If file doesn't have .lzx suffix
  71.         if $suf NOT EQ lzh        ;If file doesn't have .lzh suffix (which is de-archived by LhA)
  72.             RequestChoice "! Error !" "File is NOT an LhA/LZX archive!" "Choose again!"
  73.         endif
  74.     endif
  75. endif
  76.  
  77. lab Temp
  78. 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"
  79. if $drw EQ 1                    ;If the left button (i.e. RAM:) is chosen
  80.     echo RAM: >env:drw1
  81. endif
  82.  
  83. lab Other
  84. if $drw EQ 2                    ;If "Other" is chosen
  85.     RequestFile >env:drw1 TITLE "Where should 'L2Z' be made?" DRAWERSONLY NOICONS POSITIVE Create DRAWER "$d"
  86.     if WARN
  87.         skip More
  88.     endif
  89.     echo >env:d $drw1            ;Get rid of quotation marks
  90.     list >env:dsz env:d LFORMAT=%L        ;Get size of path name
  91.     if $dsz EQ 1                ;Full path not selected
  92.         RequestChoice > NIL: "! Error !" "Choose FULL path!*n(i.e. start with DEVICE listing)" "Try again"
  93.         skip Other BACK
  94.     endif
  95.     if NOT EXISTS $drw1
  96.         RequestChoice "! Error !" "PATH does not exist!" "Choose again!"
  97.         skip Other BACK
  98.     endif
  99. endif
  100.  
  101. if $drw EQ 0                    ;If "Cancel" is chosen
  102.     skip More
  103. endif
  104.  
  105. 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"
  106. 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
  107. cd $orig                    ;CD's to the directory of the original archive
  108. list >env:flsz $ldfl LFORMAT=%L            ;Gets size of original archive
  109. eval >env:flmem $flsz * 4            ;Multiplies the archive size by 4
  110. 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)
  111.     if $drw1 EQ RAM:            ;and RAM: has been chosen to store temporary files
  112.         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"
  113.         if $nomem EQ 0            ;"Cancel"
  114.             skip More
  115.         endif
  116.         if $nomem EQ 1            ;"Other"
  117.             skip Temp back
  118.         endif
  119.         if $nomem EQ 2            ;"Continue"
  120.             skip MkTemp
  121.         endif
  122.     endif
  123.     if "$drw1" EQ "Ram Disk:"        ;If user clicks on RAM: in file requestor
  124.         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"
  125.         if $nomem EQ 0            ;"Cancel"
  126.             skip More
  127.         endif
  128.         if $nomem EQ 1            ;"Other"
  129.             skip Temp back
  130.         endif
  131.         if $nomem EQ 2            ;"Continue"
  132.             skip MkTemp
  133.         endif
  134.     endif
  135. endif
  136.  
  137. lab MkTemp
  138. cd $drw1
  139. if NOT EXISTS l2z            ;This creates a temporary drawer in which to de-archive the files in the archive
  140.     makedir > NIL: l2z
  141. else                    ;Drawer is emptied if it is already there
  142.     delete l2z/#? FORCE QUIET
  143. endif
  144.  
  145. lab extra
  146. echo "*e[0 p"
  147. 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"
  148. if WARN                    ;If 'Cancel' is selected
  149.     skip beg BACK            ;This skips back to the section labelled 'Beg', at the beginning
  150. endif
  151.  
  152. if $ext EQ 2                ;If the user wants to make the smallest archive
  153.     skip Conv            ;This skips forward to the section labelled 'Conv'
  154. endif
  155.  
  156. 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
  157.     if $suf EQ lha            ;Means it is an LhA archive
  158.     lab L                ;Label 'L' so the script can skip straight here if needed
  159.         cd $drw1
  160.         cd l2z
  161.         $wlha x -a -F -M -x $ldfl
  162.         if $RC EQ 20            ;If user aborts it will skip to 'More'
  163.             skip More        ;RC stands for Return Code - the number returned by LhA if the operation fails
  164.         endif
  165.         $wlzx -r -e -3 -X -F a $bnm #?
  166.         if $RC EQ 50            ;If user aborts it will skip to 'More'
  167.             skip More
  168.         endif
  169.         list >env:old $ldfl LFORMAT=%L            ;Gets the size of the original archive
  170.         list >env:new $bnm.lzx LFORMAT=%L        ;Gets the size of the new archive
  171.         eval >env:diff $old - $new            ;Subtracts the size of the new from the original
  172.         eval >env:diff1 $new - $old            ;Subtracts the size of the original from the new
  173.         delete $ldfl QUIET                ;Original archive is deleted
  174.         copy $bnm.lzx TO $orig QUIET            ;New archive is copied in place of the original
  175.         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
  176.             RequestChoice > NIL: "! Operation Successful !" "$o$bnm.lzx*n  now replaces*n$l*n  and is $diff bytes smaller!" "Okay"
  177.         else
  178.             RequestChoice > NIL: "! Operation Successful !" "$o$bnm.lzx*n  now replaces*n$l*n  and is $diff1 bytes larger" "Okay"
  179.         endif
  180.     else                            ;"If that fails, try this..." - i.e. means it is NOT an LhA archive
  181.         if $suf EQ lzh                    ;It is an LZH archive (processed by LhA)
  182.             skip l BACK
  183.         endif
  184.         cd $drw1                    ;If this line is reached, it is an LZX archive
  185.         cd l2z
  186.         $wlzx x -a -F -x $ldfl                ;LZX extracts the original archive to temporary drawer 'l2z'
  187.         if $RC EQ 50                    ;If user aborts it will skip to 'More'
  188.             skip More
  189.         endif
  190.         $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
  191.         if $RC EQ 20                    ;If user aborts it will skip to 'More'
  192.             skip More
  193.         endif
  194.         list >env:old $ldfl LFORMAT=%L
  195.         list >env:new $bnm.lha LFORMAT=%L
  196.         eval >env:diff $old - $new
  197.         eval >env:diff1 $new - $old
  198.         delete $ldfl QUIET                ;Original archive is deleted
  199.         copy $bnm.lha TO $orig QUIET            ;New archive is copied in place of the original
  200.         if $old GT $new VAL
  201.             RequestChoice > NIL: "! Operation Successful !" "$o$bnm.lha*n  now replaces*n$l*n  and is $diff bytes smaller!" "Okay"
  202.         else
  203.             RequestChoice > NIL: "! Operation Successful !" "$o$bnm.lha*n  now replaces*n$l*n  and is $diff1 bytes larger" "Okay"
  204.         endif
  205.     endif
  206. endif
  207.  
  208. skip More
  209.  
  210. lab Conv                    ;This part until 'lab More' converts the archive to either LhA or LZX, and saves whichever is smaller
  211. if $suf EQ lha                    ;Means it is an LhA archive
  212.     lab l2
  213.     cd $drw1
  214.     cd l2z
  215.     $wlha x -a -F -M -x $ldfl
  216.     if $RC EQ 20                ;If user aborts it will skip to 'More'
  217.         skip More            ;RC stands for Return Code - the number returned by LhA if the operation fails
  218.     endif
  219.     $wlzx -r -e -3 -X -F a $bnm #?        ;If not aborted, file is archived
  220.     if $RC EQ 50                ;If user aborts it will skip to 'More'
  221.         skip More
  222.     endif
  223. else                        ;Means it is not an LhA archive
  224.     if $suf EQ lzh                ;Means it is an LZH archive
  225.         skip l2 BACK
  226.     endif
  227.     cd $drw1                ;If this line is reached, it is an LZX archive
  228.     cd l2z
  229.     $wlzx x -a -F -x $ldfl
  230.     if $RC EQ 50                ;If user aborts it will skip to 'More'
  231.         skip More
  232.     endif
  233.     $wlha -2 -a -r -F -y -M -e -x a $bnm #?        ;If not aborted, file is archived
  234.     if $RC EQ 20                ;If user aborts it will skip to 'More'
  235.         skip More
  236.     endif
  237. endif
  238.  
  239. list >env:old $ldfl LFORMAT=%L                ;Gets the size of the original archive
  240. list >env:new $bnm.(lzx|lha) LFORMAT=%L            ;Gets the size of the new archive
  241. eval >env:diff $old - $new                ;Subtracts the size of the new from the original
  242. eval >env:diff1 $new - $old                ;Subtracts the size of the original from the new
  243.  
  244. 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
  245.     delete $ldfl QUIET
  246.     copy $bnm.(lzx|lha) TO $orig QUIET
  247.     list >env:arc $o$bnm.(lzx|lha) LFORMAT=%S%S                                    ;Gets name of new archive
  248.     echo >env:arc1 $arc                                                ;Removes quotation marks
  249.     RequestChoice > NIL: "! $arc1 used !" "Using the new archive because it's $diff bytes smaller!" "Nice one!"
  250. else                                                            ;Original archive is smaller than the new one, so the smaller original one is kept
  251.     RequestChoice > NIL: " $l used" "Using the original archive because it's $diff1 bytes smaller!" "Okay"        ;The difference in file sizes is cleverly given
  252.     cd $drw1
  253.     delete l2z ALL QUIET FORCE
  254. endif
  255.  
  256. lab More
  257. echo "*ec"
  258. RequestChoice >env:ano "Other archives?" "Do you want to convert another archive?" "Yes" "No"
  259. if $ano EQ 0
  260.     skip end
  261. else
  262.     skip beg back
  263. endif
  264.  
  265. lab end
  266. echo "*ec"                                    ;This clears the output window
  267. echo "*n*n*n                       *e[1;32m  Thank you for using"
  268. 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
  269. echo "*n*n*n"
  270. if EXISTS env:old
  271.     delete env:old QUIET
  272. endif
  273.  
  274. if EXISTS env:diff
  275.     delete env:diff QUIET
  276. endif
  277.  
  278. if EXISTS env:diff1
  279.     delete env:diff1 QUIET
  280. endif
  281.  
  282. if EXISTS env:flsz
  283.     delete env:flsz QUIET
  284. endif
  285.  
  286. if EXISTS env:memsz
  287.     delete env:memsz QUIET
  288. endif
  289.  
  290. if EXISTS env:flmem
  291.     delete env:flmem QUIET
  292. endif
  293.  
  294. if EXISTS env:new
  295.     delete env:new QUIET
  296. endif
  297.  
  298. if EXISTS env:ano
  299.     delete env:ano QUIET
  300. endif
  301.  
  302. if EXISTS env:osz
  303.     delete env:osz QUIET
  304. endif
  305.  
  306. if EXISTS env:o
  307.     delete env:o QUIET
  308. endif
  309.  
  310. if EXISTS env:d
  311.     delete env:d QUIET
  312. endif
  313.  
  314. if EXISTS env:dsz
  315.     delete env:dsz QUIET
  316. endif
  317.  
  318. if EXISTS env:arc
  319.     delete env:arc QUIET
  320. endif
  321.  
  322. if EXISTS env:arc1
  323.     delete env:arc1 QUIET
  324. endif
  325.  
  326. if EXISTS env:l
  327.     delete env:l QUIET
  328. endif
  329.  
  330. if EXISTS env:lsz
  331.     delete env:lsz QUIET
  332. endif
  333.  
  334. if EXISTS env:wlha
  335.     delete env:wlha QUIET
  336. endif
  337.  
  338. if EXISTS env:ext
  339.     delete env:ext QUIET
  340. endif
  341.  
  342. if EXISTS env:wlzx
  343.     delete env:wlzx QUIET
  344. endif
  345.  
  346. if EXISTS env:bnm1
  347.     delete env:bnm1 QUIET
  348. endif
  349.  
  350. if EXISTS env:bnm
  351.     delete env:bnm QUIET
  352. endif
  353.  
  354. if EXISTS env:suf
  355.     delete env:suf QUIET
  356. endif
  357.  
  358. if EXISTS env:nomem
  359.     delete env:nomem QUIET
  360. endif
  361.  
  362. if EXISTS env:orig
  363.     delete env:orig QUIET
  364. endif
  365.  
  366. if EXISTS env:ldfl
  367.     delete env:ldfl QUIET
  368. endif
  369.  
  370. if EXISTS env:drw1
  371.     cd $drw1
  372.     if EXISTS l2z
  373.         delete l2z ALL QUIET FORCE
  374.     endif
  375.     delete env:drw1 QUIET
  376. endif
  377.  
  378. if EXISTS env:drw
  379.     delete env:drw QUIET
  380. endif
  381. quit