home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Workbench / Archivers / LhA2LZX3.lha / lha2lzx / LhA2LZX_v2.6a < prev    next >
Text File  |  1998-02-05  |  13KB  |  307 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.6a (4.2.98) Richard Burke
  7.  
  8. Failat 60                    ;Allows errors when using LhA & LZX to be captured
  9.  
  10. lab Beg
  11. if EXISTS env:nl2zdrw1                ;If the file ENV:nl2zdrw1 exists, the script will perform the actions to endif
  12.     cd $nl2zdrw1                ;Current Directory is now that which is stated in the contents of the environmental variable 'nl2zdrw1'
  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:nl2zdrw1 QUIET
  17. endif
  18.  
  19. if NOT EXISTS env:nl2zo                ;If starting, default path of archive is RAM:
  20.     echo RAM: >env:nl2zo            ;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:nl2zd                ;If starting, default path of temporary drawer l2z is RAM:
  24.     echo RAM: >env:nl2zd            ;If converting several archives, the previous path of l2z will be used as the default of the next
  25. endif
  26.  
  27. which >env:nl2zwlha 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:nl2zwlzx 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:nl2zorig TITLE "Full path of drawer of archive?" DRAWERSONLY NOICONS DRAWER "$nl2zo"    ;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 $nl2zorig
  46.     RequestChoice >nil: "! Error !" "PATH does not exist!" "Try again"
  47.     skip Path BACK
  48. endif
  49.  
  50. echo >env:nl2zo $nl2zorig                ;Get rid of quotation marks, and also create default path for next archive if converting more
  51. list >env:nl2zosz env:nl2zo LFORMAT=%L            ;Get size of path name
  52. if $nl2zosz 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:nl2zldfl TITLE "Chose file to convert" POSITIVE Convert ACCEPTPATTERN #?.(lha|lzx|lzh) DRAWER $nl2zorig        ; $nl2zldfl now contains the complete path and filename of the archive
  59. if WARN
  60.     skip More
  61. endif
  62.  
  63. if NOT EXISTS $nl2zldfl
  64.     RequestChoice >nil: "! Error !" "FILE does not exist!" "Try again"
  65.     skip File BACK
  66. endif
  67.  
  68. echo >env:nl2zl $nl2zldfl                ;Get rid of quotation marks
  69. list >env:nl2zlsz env:nl2zl LFORMAT=%L            ;Get size of file name
  70. if $nl2zlsz EQ $nl2zosz                    ;No file selected
  71.     RequestChoice > NIL: "! Error !" "No file chosen!" "Try again"
  72.     skip File BACK
  73. endif
  74.  
  75. list >env:nl2zbnm1 $nl2zldfl LFORMAT=%S            ;Strips the path of the archive to give only the filename with suffix
  76. list >env:nl2zbnm $nl2zldfl LFORMAT=%M            ;Removes .lzx, .lha or .lzh suffix from filename
  77. list >env:nl2zsuf $nl2zldfl LFORMAT=%E            ;Gives suffix only
  78.  
  79. if $nl2zsuf NOT EQ lha                ;If file doesn't have .lha suffix
  80.     if $nl2zsuf NOT EQ lzx            ;If file doesn't have .lzx suffix
  81.         if $nl2zsuf 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 $nl2zsuf EQ lha
  88.     echo LZX >env:nl2znsuf            ;Gives the type of file to convert to in a requestor later
  89.     echo LhA >env:nl2zsuf
  90. endif
  91.  
  92. if $nl2zsuf EQ lzx
  93.     echo LhA >env:nl2znsuf
  94.     echo LZX >env:nl2zsuf            ;Makes it look better in the requestor
  95. endif
  96.  
  97. if $nl2zsuf EQ lzh
  98.     echo LZX >env:nl2znsuf
  99.     echo LZH >env:nl2zsuf
  100. endif
  101.  
  102. lab Temp
  103. RequestChoice >env:nl2zdrw "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 $nl2zdrw EQ 1                    ;If the left button (i.e. RAM:) is chosen
  105.     echo "RAM:" >env:nl2zdrw1
  106. endif
  107.  
  108. lab Other
  109. if $nl2zdrw EQ 2                    ;If "Other" is chosen
  110.     RequestFile >env:nl2zdrw1 TITLE "Where should 'L2Z' be made?" DRAWERSONLY NOICONS POSITIVE Create DRAWER "$nl2zd"
  111.     if WARN
  112.         skip More
  113.     endif
  114.     echo >env:nl2zd $nl2zdrw1            ;Get rid of quotation marks
  115.     list >env:nl2zdsz env:nl2zd LFORMAT=%L        ;Get size of path name
  116.     if $nl2zdsz 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 $nl2zdrw1
  121.         RequestChoice "! Error !" "PATH does not exist!" "Choose again!"
  122.         skip Other BACK
  123.     endif
  124. endif
  125.  
  126. if $nl2zdrw 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 nl2zmemsz `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:nl2zmemsz
  132. cd $nl2zorig                    ;CD's to the directory of the original archive
  133. list >env:nl2zflsz $nl2zldfl LFORMAT=%L        ;Gets size of original archive
  134. eval >env:nl2zflmem $nl2zflsz * 4        ;Multiplies the archive size by 4
  135. if NOT $nl2zmemsz VAL GT $nl2zflmem        ;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 $nl2zdrw1 EQ "RAM:"            ;and RAM: has been chosen to store temporary files
  137.         RequestChoice >env:nl2znomem "! Insufficient Memory!" "There may be insufficient memory to store temporary files in RAM:*n(may need at least $nl2zflmem bytes)" "Choose other path" "Continue anyway" "Cancel"
  138.         if $nl2znomem EQ 0        ;"Cancel"
  139.             skip More
  140.         endif
  141.         if $nl2znomem EQ 1        ;"Other"
  142.             skip Temp back
  143.         endif
  144.         if $nl2znomem EQ 2        ;"Continue"
  145.             skip MkTemp
  146.         endif
  147.     endif
  148.     if $nl2zdrw1 EQ "Ram Disk:"        ;If user clicks on RAM: in file requestor
  149.         RequestChoice >env:nl2znomem "! Insufficient Memory!" "There may be insufficient memory to store temporary files in RAM:*n(may need at least $nl2zflmem bytes)" "Choose other path" "Continue anyway" "Cancel"
  150.         if $nl2znomem EQ 0        ;"Cancel"
  151.             skip More
  152.         endif
  153.         if $nl2znomem EQ 1        ;"Other"
  154.             skip Temp back
  155.         endif
  156.         if $nl2znomem EQ 2        ;"Continue"
  157.             skip MkTemp
  158.         endif
  159.     endif
  160. endif
  161.  
  162. lab MkTemp
  163. cd $nl2zdrw1
  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:nl2zext "Convert $nl2zl to . . ." "Do you want to convert to the other*nfiletype or to the smallest archive?*n*nConvert from $nl2zsuf to:" "$nl2znsuf" "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 $nl2zext 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 $nl2zext 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 $nl2zsuf 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 $nl2zdrw1
  185.         cd l2z
  186.         $nl2zwlzx x -a -F -x $nl2zldfl    ;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.         $nl2zwlzx -r -e -3 -X -F a -Qf $nl2zbnm #?
  191.         if $RC EQ 50            ;If user aborts it will skip to 'More'
  192.             skip More
  193.         endif
  194.         list >env:nl2zold $nl2zldfl LFORMAT=%L        ;Gets the size of the original archive
  195.         list >env:nl2znew $nl2zbnm.lzx LFORMAT=%L    ;Gets the size of the new archive
  196.         eval >env:nl2zdiff $nl2zold - $nl2znew        ;Subtracts the size of the new from the original
  197.         eval >env:nl2zdiff1 $nl2znew - $nl2zold        ;Subtracts the size of the original from the new
  198.         delete $nl2zldfl QUIET                ;Original archive is deleted
  199.         copy $nl2zbnm.lzx TO $nl2zorig QUIET        ;New archive is copied in place of the original
  200.         if $nl2zold GT $nl2znew 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 !" "$nl2zo$nl2zbnm.lzx*n  now replaces*n$nl2zl*n  and is $nl2zdiff bytes smaller!" "Nice one!"
  202.         else
  203.             RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.lzx*n  now replaces*n$nl2zl*n  and is $nl2zdiff1 bytes larger" "Okay"
  204.         endif
  205.     else                            ;"If that fails, try this..." - i.e. means it is NOT an LhA archive
  206.         if $nl2zsuf EQ lzh                ;It is an LZH archive (processed by LhA)
  207.             skip L BACK
  208.         endif
  209.         cd $nl2zdrw1                    ;If this line is reached, it is an LZX archive
  210.         cd l2z
  211.         $nl2zwlzx x -a -F -x $nl2zldfl            ;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.         $nl2zwlha -2 -a -r -F -y -M -e -x a $nl2zbnm #?    ;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:nl2zold $nl2zldfl LFORMAT=%L
  220.         list >env:nl2znew $nl2zbnm.lha LFORMAT=%L
  221.         eval >env:nl2zdiff $nl2zold - $nl2znew
  222.         eval >env:nl2zdiff1 $nl2znew - $nl2zold
  223.         delete $nl2zldfl QUIET                ;Original archive is deleted
  224.         copy $nl2zbnm.lha TO $nl2zorig QUIET        ;New archive is copied in place of the original
  225.         if $nl2zold GT $nl2znew VAL
  226.             RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.lha*n  now replaces*n$nl2zl*n  and is $nl2zdiff bytes smaller!" "Nice one!"
  227.         else
  228.             RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.lha*n  now replaces*n$nl2zl*n  and is $nl2zdiff1 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 $nl2zsuf EQ lha                ;Means it is an LhA archive
  237.     lab L2
  238.     cd $nl2zdrw1
  239.     cd l2z
  240.     $nl2zwlzx x -a -F -x $nl2zldfl        ;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.     $nl2zwlzx -r -e -3 -X -F a -Qf $nl2zbnm #?    ;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 $nl2zsuf EQ lzh            ;Means it is an LZH archive
  250.         skip L2 BACK
  251.     endif
  252.     cd $nl2zdrw1                ;If this line is reached, it is an LZX archive
  253.     cd l2z
  254.     $nl2zwlzx x -a -F -x $nl2zldfl
  255.     if $RC EQ 50                ;If user aborts it will skip to 'More'
  256.         skip More
  257.     endif
  258.     $nl2zwlha -2 -a -r -F -y -M -e -x a $nl2zbnm #?    ;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:nl2zold $nl2zldfl LFORMAT=%L            ;Gets the size of the original archive
  265. list >env:nl2znew $nl2zbnm.(lzx|lha) LFORMAT=%L        ;Gets the size of the new archive
  266. eval >env:nl2zdiff $nl2zold - $nl2znew            ;Subtracts the size of the new from the original
  267. eval >env:nl2zdiff1 $nl2znew - $nl2zold            ;Subtracts the size of the original from the new
  268.  
  269. if $nl2zold GT $nl2znew VAL                                                    ;Original archive is larger than the new one, so the original is deleted and replaced by the smaller new one
  270.     delete $nl2zldfl QUIET
  271.     copy $nl2zbnm.(lzx|lha) TO $nl2zorig QUIET
  272.     list >env:nl2zarc $nl2zo$nl2zbnm.(lzx|lha) LFORMAT=%S%S                                    ;Gets name of new archive
  273.     echo >env:nl2zarc1 $nl2zarc                                                ;Removes quotation marks
  274.     RequestChoice > NIL: "! $nl2zarc1 used !" "Using the new archive because it's $nl2zdiff bytes smaller!" "Nice one!"
  275. else                                                            ;Original archive is smaller than the new one, so the smaller original one is kept
  276.     RequestChoice > NIL: " $nl2zl used" "Using the original archive because it's $nl2zdiff1 bytes smaller!" "Okay"        ;The difference in file sizes is cleverly given
  277.     cd $nl2zdrw1
  278.     delete l2z ALL QUIET FORCE
  279. endif
  280.  
  281. lab More
  282. echo "*e[1;1H*eJ"
  283. RequestChoice >env:nl2zano "Other archives?" "Do you want to convert another archive?" "Yes" "No"
  284. if $nl2zano EQ 0
  285.     skip end
  286. else
  287.     skip beg back
  288. endif
  289.  
  290. lab end
  291. echo "*e[1;1H*eJ"                                ;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.  
  296. if EXISTS env:nl2zdrw1
  297.     cd $nl2zdrw1
  298.     if EXISTS l2z
  299.         delete l2z ALL QUIET FORCE
  300.     endif
  301. endif
  302.  
  303. c:list >nil: ENV:nl2z#? TO T:l2ztmp LFORMAT "delete %S%S >NIL:*n"
  304. execute T:l2ztmp >nil:
  305. delete T:l2ztmp >nil:
  306.  
  307. quit