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