home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Workbench / Archivers / LhA2LZX2.lha / lha2lzx / LhA2LZX_v2.0 < prev    next >
Text File  |  1997-07-10  |  7KB  |  262 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.0 (24.6.97) Richard Burke
  8.  
  9. lab beg
  10. if EXISTS env:wlha            ;All the environment variables LhA2LZX uses are deleted
  11.         delete env:wlha QUIET        ;if they are present to start freshly
  12. endif
  13.  
  14. if EXISTS env:wlzx
  15.         delete env:wlzx QUIET
  16. endif
  17.  
  18. if EXISTS env:diff
  19.         delete env:diff QUIET
  20. endif
  21.  
  22. if EXISTS env:diff1
  23.         delete env:diff1 QUIET
  24. endif
  25.  
  26. if EXISTS env:ext
  27.         delete env:ext QUIET
  28. endif
  29.  
  30. if EXISTS env:ano
  31.         delete env:ano QUIET
  32. endif
  33.  
  34. if EXISTS env:old
  35.         delete env:old QUIET
  36. endif
  37.  
  38. if EXISTS env:new
  39.         delete env:new QUIET
  40. endif
  41.  
  42. if EXISTS env:bnm1
  43.         delete env:bnm1 QUIET
  44. endif
  45.  
  46. if EXISTS env:bnm
  47.         delete env:bnm QUIET
  48. endif
  49.  
  50. if EXISTS env:orig
  51.         delete env:orig QUIET
  52. endif
  53.  
  54. if EXISTS env:ldfl
  55.         delete env:ldfl QUIET
  56. endif
  57.  
  58. if EXISTS env:drw1
  59.         cd $drw1                ;Current Directory is now that which is stated in the contents of the environmental variable 'drw1'
  60.         if EXISTS l2z                ;If the temporary drawer used to store the archive files exists
  61.                 delete l2z ALL QUIET FORCE    ;then it is deleted to start freshly
  62.         endif
  63.         delete env:drw1 QUIET
  64. endif
  65.  
  66. if EXISTS env:drw
  67.         delete env:drw QUIET
  68. endif
  69.  
  70. which lha all >env:wlha                ;Finds the location of the LhA tool
  71. if WARN                        ;If the LhA tool cannot be found
  72.         requestchoice "LhA2LZX Error Message" "Can't find 'LhA' tool!*nSee docs for details!" "Quit"
  73.         quit
  74. endif
  75.  
  76. which lzx all >env:wlzx                ;Finds the location of the LZX tool e.g. 'C:LZX'
  77. if WARN
  78.         requestchoice "LhA2LZX Error Message" "Can't find 'LZX' tool!*nSee docs for details!" "Quit"
  79.         quit
  80. endif
  81.  
  82. RequestFile >env:orig TITLE "Full path of drawer of archive?" DRAWERSONLY NOICONS    ;Saves the location of the archive in the environment variable 'orig'
  83. if WARN
  84.         skip end
  85. endif
  86.  
  87. RequestFile >env:ldfl TITLE "Chose file to convert" POSITIVE Convert ACCEPTPATTERN #?.(lha|lzx) DRAWER $orig
  88. if WARN
  89.         skip more
  90. endif
  91.  
  92. basename >env:bnm1 $ldfl    ;Strips the path of the archive to give only the filename with suffix
  93. basename >env:bnm $bnm1 .lzx    ;Removes .lzx suffix from filename if it has it
  94.  
  95. 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"
  96. if $drw EQ 1                ;If the left button (i.e. RAM:) is chosen
  97.         echo RAM: >env:drw1
  98. endif
  99.  
  100. if $drw EQ 0
  101.         RequestFile >env:drw1 TITLE "Where should 'L2Z' be made?" DRAWERSONLY NOICONS POSITIVE Create
  102.     if WARN
  103.         skip more
  104.     endif
  105. endif
  106.  
  107. cd $drw1
  108. if NOT EXISTS l2z            ;This creates a temporary drawer in which to de-archive the files in the archive
  109.         makedir > NIL: l2z
  110. else                    ;Drawer is emptied if it is already there
  111.         delete l2z/#? FORCE QUIET
  112. endif
  113.  
  114. lab extra
  115. RequestChoice >env:ext "FileType" "Do you want to convert to the other*nfiletype or to the smallest archive?*n*nConvert to:" "LhA" "LZX" "Smallest" "Cancel"
  116. if WARN                    ;If 'Cancel' is selected
  117.         skip beg BACK            ;This skips back to the section labelled 'Beg', at the beginning
  118. endif
  119.  
  120. if $ext EQ 3                ;If the user wants to make the smallest archive
  121.         skip conv            ;This skips forward to the section labelled 'Conv'
  122. endif
  123.  
  124. if $ext EQ 1                        ;If the user wants to convert TO LhA
  125.         if NOT $bnm1 EQ $bnm                ;Means it is NOT an LhA archive (i.e. suffix has been stripped)
  126.                 cd $drw1
  127.                 cd l2z
  128.                 $wlzx x -a $ldfl            ;LZX extracts the original archive to temporary drawer 'l2z'
  129.                 $wlha -2ar a $bnm #?            ;LhA archives everything in 'l2z' and saves it as the original name with .lha suffix
  130.         delete $ldfl QUIET            ;Original archive is deleted
  131.             copy $bnm.lha TO $orig QUIET        ;New archive is copied in place of the original
  132.     else                        ;Means it IS an LhA archive
  133.         echo "*n*e[1;1H*e[J"
  134.         echo "*e[2mFile is already an LhA archive!*e[0m"
  135.         skip extra BACK
  136.     endif
  137. endif
  138.  
  139. if $ext EQ 2                        ;If the user wants to convert TO LZX
  140.     if $bnm1 EQ $bnm                ;Means it is an LhA archive
  141.             delete env:bnm QUIET
  142.             basename >env:bnm $bnm1 .lha
  143.             cd $drw1
  144.             cd l2z
  145.             $wlha x -a $ldfl
  146.             $wlzx -r -e -3 a $bnm #?
  147.         delete $ldfl QUIET
  148.             copy $bnm.lzx TO $orig QUIET
  149.     else                        ;Means it is NOT an LhA archive (i.e. suffix has been stripped)
  150.         echo "*n*e[1;1H*e[J"            ;This clears the output window
  151.         echo "*e[2mFile is already an LZX archive!*e[0m"    ;Text appears white
  152.         skip extra BACK
  153.     endif
  154. endif
  155.  
  156. skip More
  157.  
  158. lab Conv                ;This part until 'lab More' converts the archive to either LhA or LZX, and saves whichever is smaller
  159. if $bnm1 EQ $bnm            ;Means it is an LhA archive (i.e. suffix not stripped)
  160.         delete env:bnm QUIET
  161.         basename >env:bnm $bnm1 .lha
  162.         cd $drw1
  163.         cd l2z
  164.         $wlha x -a $ldfl
  165.         $wlzx -r -e -3 a $bnm #?
  166. else                    ;Means it is an LZX archive
  167.         cd $drw1
  168.         cd l2z
  169.         $wlzx x -a $ldfl
  170.         $wlha -2ar a $bnm #?
  171. endif
  172.  
  173. list >env:old $ldfl LFORMAT=%L        ;Gets the size of the original archive
  174. list >env:new $bnm.(lzx|lha) LFORMAT=%L    ;Gets the size of the new archive
  175. eval >env:diff $old - $new        ;Subtracts the size of the new from the original
  176. eval >env:diff1 $new - $old        ;Subtracts the size of the original from the new
  177.  
  178. 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
  179.         delete $ldfl QUIET
  180.         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
  181.         copy $bnm.(lzx|lha) TO $orig QUIET
  182. else                                                ;Original archive is smaller than the new one, so the smaller original one is kept
  183.         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
  184.         cd $drw1
  185.         delete l2z ALL QUIET FORCE
  186. endif
  187.  
  188. lab More
  189. RequestChoice >env:ano "Other archives?" "Do you want to convert another archive?" "Yes" "No"
  190. if $ano EQ 0
  191.         skip end
  192. else
  193.         skip beg back
  194. endif
  195.  
  196. lab end
  197. echo "*e[1;1H*e[J"        ;This clears the output window
  198. echo ""
  199. echo ""
  200. echo ""
  201. echo "                       *e[1;32m  Thank you for using"
  202. echo "                              *e[33m LhA*e[0m*e[3;1m2*e[0m*e[2mLZX"
  203. if EXISTS env:old
  204.         delete env:old QUIET
  205. endif
  206.  
  207. if EXISTS env:diff
  208.         delete env:diff QUIET
  209. endif
  210.  
  211. if EXISTS env:diff1
  212.         delete env:diff1 QUIET
  213. endif
  214.  
  215. if EXISTS env:new
  216.         delete env:new QUIET
  217. endif
  218.  
  219. if EXISTS env:ano
  220.         delete env:ano QUIET
  221. endif
  222.  
  223. if EXISTS env:wlha
  224.         delete env:wlha QUIET
  225. endif
  226.  
  227. if EXISTS env:ext
  228.         delete env:ext QUIET
  229. endif
  230.  
  231. if EXISTS env:wlzx
  232.         delete env:wlzx QUIET
  233. endif
  234.  
  235. if EXISTS env:bnm1
  236.         delete env:bnm1 QUIET
  237. endif
  238.  
  239. if EXISTS env:bnm
  240.         delete env:bnm QUIET
  241. endif
  242.  
  243. if EXISTS env:orig
  244.         delete env:orig QUIET
  245. endif
  246.  
  247. if EXISTS env:ldfl
  248.         delete env:ldfl QUIET
  249. endif
  250.  
  251. if EXISTS env:drw1
  252.         cd $drw1
  253.         if EXISTS l2z
  254.                 delete l2z ALL QUIET FORCE
  255.         endif
  256.         delete env:drw1 QUIET
  257. endif
  258.  
  259. if EXISTS env:drw
  260.         delete env:drw QUIET
  261. endif
  262. quit