home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / lha2lzx / lha2lzx_v2.7a < prev    next >
Text File  |  1998-04-27  |  14KB  |  323 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.7a (10.2.98) Richard Burke    ;This is a version string, to give details of the file's creation date, author and version number
  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 >nil: "LhA2LZX Error Message" "Can't find 'LhA' tool!*nSee docs for details!" "Quit"
  30.     skip end
  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 >nil: "LhA2LZX Error Message" "Can't find 'LZX' tool!*nSee docs for details!" "Quit"
  36.     skip end
  37. endif
  38.  
  39. if NOT EXISTS L:lzx.keyfile
  40.     RequestChoice >nil: "LhA2LZX Error Message" "Can't find lzx.keyfile!*nSee docs for details!" "Quit"
  41.     skip end
  42. endif
  43.  
  44. lab Path
  45. 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
  46. if WARN
  47.     skip end
  48. endif
  49.  
  50. if NOT EXISTS $nl2zorig
  51.     RequestChoice >nil: "! Error !" "PATH does not exist!" "Try again"
  52.     skip Path BACK
  53. endif
  54.  
  55. echo >env:nl2zo $nl2zorig                ;Get rid of quotation marks, and also create default path for next archive if converting more
  56. list >env:nl2zosz env:nl2zo LFORMAT=%L            ;Get size of path name
  57. if $nl2zosz EQ 1                    ;Full path not selected
  58.     RequestChoice > NIL: "! Error !" "Choose FULL path!*n(i.e. start with DEVICE listing)" "Try again"
  59.     skip Path BACK
  60. endif
  61.  
  62. lab File
  63. 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
  64. if WARN
  65.     skip More
  66. endif
  67.  
  68. if NOT EXISTS $nl2zldfl
  69.     RequestChoice >nil: "! Error !" "FILE does not exist!" "Try again"
  70.     skip File BACK
  71. endif
  72.  
  73. lab Tilde
  74. search env:nl2zldfl ~ >nil:
  75. if $RC EQ 0
  76.     RequestChoice >nil: "! Error !" "Filename contains a tilde (~)*n*nPlease rename the file without a tilde*n*nSee docs for details" "Okay"
  77.     skip end
  78. endif
  79.  
  80. echo >env:nl2zl $nl2zldfl                ;Get rid of quotation marks
  81. list >env:nl2zlsz env:nl2zl LFORMAT=%L            ;Get size of file name
  82. if $nl2zlsz EQ $nl2zosz                    ;No file selected
  83.     RequestChoice > NIL: "! Error !" "No file chosen!" "Try again"
  84.     skip File BACK
  85. endif
  86.  
  87. list >env:nl2zbnm1 $nl2zldfl LFORMAT=%S            ;Strips the path of the archive to give only the filename with suffix
  88. list >env:nl2zbnm $nl2zldfl LFORMAT=%M            ;Removes .lzx, .lha or .lzh suffix from filename
  89. list >env:nl2zsuf $nl2zldfl LFORMAT=%E            ;Gives suffix only
  90.  
  91. if $nl2zsuf NOT EQ lha                ;If file doesn't have .lha suffix
  92.     if $nl2zsuf NOT EQ lzx            ;If file doesn't have .lzx suffix
  93.         if $nl2zsuf NOT EQ lzh        ;If file doesn't have .lzh suffix (which is de-archived by LhA)
  94.             RequestChoice "! Error !" "File is NOT an LhA or LZX archive!" "Choose again!"
  95.         endif
  96.     endif
  97. endif
  98.  
  99. if $nl2zsuf EQ lha
  100.     echo LZX >env:nl2znsuf            ;Gives the type of file to convert to in a requester later
  101.     echo LhA >env:nl2zsuf
  102. endif
  103.  
  104. if $nl2zsuf EQ lzx
  105.     echo LhA >env:nl2znsuf
  106.     echo LZX >env:nl2zsuf            ;Makes it look better in the requester
  107. endif
  108.  
  109. if $nl2zsuf EQ lzh
  110.     echo LZX >env:nl2znsuf
  111.     echo LZH >env:nl2zsuf
  112. endif
  113.  
  114. lab Temp
  115. 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"
  116. if $nl2zdrw EQ 1                    ;If the left button (i.e. RAM:) is chosen
  117.     echo "RAM:" >env:nl2zdrw1
  118. endif
  119.  
  120. lab Other
  121. if $nl2zdrw EQ 2                    ;If "Other" is chosen
  122.     RequestFile >env:nl2zdrw1 TITLE "Where should 'L2Z' be made?" DRAWERSONLY NOICONS POSITIVE Create DRAWER "$nl2zd"
  123.     if WARN
  124.         skip More
  125.     endif
  126.     echo >env:nl2zd $nl2zdrw1            ;Get rid of quotation marks
  127.     list >env:nl2zdsz env:nl2zd LFORMAT=%L        ;Get size of path name
  128.     if $nl2zdsz EQ 1                ;Full path not selected
  129.         RequestChoice > NIL: "! Error !" "Choose FULL path!*n(i.e. start with DEVICE listing)" "Try again"
  130.         skip Other BACK
  131.     endif
  132.     if NOT EXISTS $nl2zdrw1
  133.         RequestChoice "! Error !" "PATH does not exist!" "Choose again!"
  134.         skip Other BACK
  135.     endif
  136. endif
  137.  
  138. if $nl2zdrw EQ 0                    ;If "Cancel" is chosen
  139.     skip More
  140. endif
  141.  
  142. 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"
  143. 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
  144. cd $nl2zorig                    ;CD's to the directory of the original archive
  145. list >env:nl2zflsz $nl2zldfl LFORMAT=%L        ;Gets size of original archive
  146. eval >env:nl2zflmem $nl2zflsz * 4        ;Multiplies the archive size by 4
  147. 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)
  148.     if $nl2zdrw1 EQ "RAM:"            ;and RAM: has been chosen to store temporary files
  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.     if $nl2zdrw1 EQ "Ram Disk:"        ;If user clicks on RAM: in file requester
  161.         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"
  162.         if $nl2znomem EQ 0        ;"Cancel"
  163.             skip More
  164.         endif
  165.         if $nl2znomem EQ 1        ;"Other"
  166.             skip Temp back
  167.         endif
  168.         if $nl2znomem EQ 2        ;"Continue"
  169.             skip MkTemp
  170.         endif
  171.     endif
  172. endif
  173.  
  174. lab MkTemp
  175. cd $nl2zdrw1
  176. if NOT EXISTS l2z            ;This creates a temporary drawer in which to de-archive the files in the archive
  177.     makedir > NIL: l2z
  178. else                    ;Drawer is emptied if it is already there
  179.     delete l2z/#? FORCE QUIET
  180. endif
  181.  
  182. lab extra
  183. echo "*e[0 p"                ;This clears the display (the output CLI)
  184. 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"
  185. if WARN                    ;If 'Cancel' is selected
  186.     skip beg BACK            ;This skips back to the section labelled 'Beg', at the beginning
  187. endif
  188.  
  189. if $nl2zext EQ 2            ;If the user wants to make the smallest archive
  190.     skip Conv            ;This skips forward to the section labelled 'Conv'
  191. endif
  192.  
  193. 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
  194.     if $nl2zsuf EQ lha        ;Means it is an LhA archive
  195.     lab L                ;Label 'L' so the script can skip straight here if told to
  196.         cd $nl2zdrw1
  197.         cd l2z
  198.         "$nl2zwlzx" x -a -F -x -X0 $nl2zldfl    ;As the LZX keyfile is now available, the ability to de-archive LhA files is possible, and also much quicker
  199.         if NOT $RC EQ 0            ;If user aborts it will skip to 'More'
  200.             skip er        ;RC stands for Return Code - the number returned by LhA if the operation fails
  201.         endif
  202.         "$nl2zwlzx" -r -e -3 -X -F a -Qf $nl2zbnm #?
  203.         if NOT $RC EQ 0            ;If user aborts it will skip to 'More'
  204.             skip er
  205.         endif
  206.         list >env:nl2zold $nl2zldfl LFORMAT=%L        ;Gets the size of the original archive
  207.         list >env:nl2znew $nl2zbnm.lzx LFORMAT=%L    ;Gets the size of the new archive
  208.         eval >env:nl2zdiff $nl2zold - $nl2znew        ;Subtracts the size of the new from the original
  209.         eval >env:nl2zdiff1 $nl2znew - $nl2zold        ;Subtracts the size of the original from the new
  210.         delete $nl2zldfl QUIET                ;Original archive is deleted
  211.         copy $nl2zbnm.lzx TO $nl2zorig QUIET        ;New archive is copied in place of the original
  212.         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
  213.             RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.lzx*n  now replaces*n$nl2zl*n  and is $nl2zdiff bytes smaller!" "Nice one!"
  214.         else
  215.             RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.lzx*n  now replaces*n$nl2zl*n  and is $nl2zdiff1 bytes larger" "Okay"
  216.         endif
  217.     else                            ;"If that fails, try this..." - i.e. means it is NOT an LhA archive
  218.         if $nl2zsuf EQ lzh                ;It is an LZH archive (processed by LhA)
  219.             skip L BACK
  220.         endif
  221.         cd $nl2zdrw1                    ;If this line is reached, it is an LZX archive
  222.         cd l2z
  223.         "$nl2zwlzx" x -a -F -x -X0 $nl2zldfl            ;LZX extracts the original archive to temporary drawer 'l2z'
  224.         if NOT $RC EQ 0                    ;If user aborts it will skip to 'More'
  225.             skip er
  226.         endif
  227.         "$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
  228.         if NOT $RC EQ 0                    ;If user aborts it will skip to 'More'
  229.             skip er
  230.         endif
  231.         list >env:nl2zold $nl2zldfl LFORMAT=%L
  232.         list >env:nl2znew $nl2zbnm.lha LFORMAT=%L
  233.         eval >env:nl2zdiff $nl2zold - $nl2znew
  234.         eval >env:nl2zdiff1 $nl2znew - $nl2zold
  235.         delete $nl2zldfl QUIET                ;Original archive is deleted
  236.         copy $nl2zbnm.lha TO $nl2zorig QUIET        ;New archive is copied in place of the original
  237.         if $nl2zold GT $nl2znew VAL
  238.             RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.lha*n  now replaces*n$nl2zl*n  and is $nl2zdiff bytes smaller!" "Nice one!"
  239.         else
  240.             RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.lha*n  now replaces*n$nl2zl*n  and is $nl2zdiff1 bytes larger" "Okay"
  241.         endif
  242.     endif
  243. endif
  244.  
  245. skip More
  246.  
  247. lab er
  248. RequestChoice >NIL: "! Error !" "An error/user-abort has occured!*n*nSee docs for details" "Okay"
  249. skip more
  250.  
  251. lab Conv                    ;This part until 'lab More' converts the archive to either LhA or LZX, and saves whichever is smaller
  252. if $nl2zsuf EQ lha                ;Means it is an LhA archive
  253.     lab L2
  254.     cd $nl2zdrw1
  255.     cd l2z
  256.     "$nl2zwlzx" x -a -F -x -X0 $nl2zldfl    ;As the LZX keyfile is now available, the ability to de-archive LhA files is possible, and also much quicker
  257.     if NOT $RC EQ 0                ;If user aborts it will skip to 'More'
  258.         skip er    back            ;RC stands for Return Code - the number returned by LhA if the operation fails
  259.     endif    
  260.     "$nl2zwlzx" -r -e -3 -X -F a -Qf $nl2zbnm #?    ;If not aborted, file is archived
  261.     if NOT $RC EQ 0                ;If user aborts it will skip to 'More'
  262.         skip er back
  263.     endif
  264. else                        ;Means it is not an LhA archive
  265.     if $nl2zsuf EQ lzh            ;Means it is an LZH archive
  266.         skip L2 BACK
  267.     endif
  268.     cd $nl2zdrw1                ;If this line is reached, it is an LZX archive
  269.     cd l2z
  270.     "$nl2zwlzx" x -a -F -x -X0 $nl2zldfl
  271.     if NOT $RC EQ 0                ;If user aborts it will skip to 'More'
  272.         skip er back
  273.     endif
  274.     "$nl2zwlha" -2 -a -r -F -y -M -e -x a $nl2zbnm #?    ;If not aborted, file is archived
  275.     if NOT $RC EQ 0                    ;If user aborts it will skip to 'More'
  276.         skip er back
  277.     endif
  278. endif
  279.  
  280. list >env:nl2zold $nl2zldfl LFORMAT=%L            ;Gets the size of the original archive
  281. list >env:nl2znew $nl2zbnm.(lzx|lha) LFORMAT=%L        ;Gets the size of the new archive
  282. eval >env:nl2zdiff $nl2zold - $nl2znew            ;Subtracts the size of the new from the original
  283. eval >env:nl2zdiff1 $nl2znew - $nl2zold            ;Subtracts the size of the original from the new
  284.  
  285. 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
  286.     delete $nl2zldfl QUIET
  287.     copy $nl2zbnm.(lzx|lha) TO $nl2zorig QUIET
  288.     list >env:nl2zarc $nl2zo$nl2zbnm.(lzx|lha) LFORMAT=%S%S                                    ;Gets name of new archive
  289.     echo >env:nl2zarc1 $nl2zarc                                                ;Removes quotation marks
  290.     RequestChoice > NIL: "! $nl2zarc1 used !" "Using the new archive because it's $nl2zdiff bytes smaller!" "Nice one!"
  291. else                                                            ;Original archive is smaller than the new one, so the smaller original one is kept
  292.     RequestChoice > NIL: " $nl2zl used" "Using the original archive because it's $nl2zdiff1 bytes smaller!" "Okay"        ;The difference in file sizes is cleverly given
  293.     cd $nl2zdrw1
  294.     delete l2z ALL QUIET FORCE
  295. endif
  296.  
  297. lab More
  298. echo "*e[1;1H*eJ"
  299. RequestChoice >env:nl2zano "Other archives?" "Do you want to convert another archive?" "Yes" "No"
  300. if $nl2zano EQ 0
  301.     skip end
  302. else
  303.     skip beg back
  304. endif
  305.  
  306. lab end
  307. echo "*e[1;1H*eJ"                                ;This clears the output window
  308. echo "*n*n*n                       *e[1;32m  Thank you for using"
  309. 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
  310. echo "*n*n*n"
  311.  
  312. if EXISTS env:nl2zdrw1
  313.     cd $nl2zdrw1
  314.     if EXISTS l2z                ;If a temporary drawer was created to store files temporarily...
  315.         delete l2z ALL QUIET FORCE    ;...delete all the temporary files
  316.     endif
  317. endif
  318.  
  319. c:list >nil: ENV:nl2z#? TO T:l2ztmp LFORMAT "delete %S%S >NIL:"    ;This generates a list of all the environment variables used and deletes them
  320. execute T:l2ztmp >nil:                            ;The variables are actually deleted by this line
  321. delete T:l2ztmp >nil:                            ;The new script generated is deleted here.  Now everything LhA2LZX created during its running has been disposed of.
  322.  
  323. quit                        ;The end of LhA2LZX  :^(