home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Workbench / Archivers / LhA2LZX3.lha / lha2lzx / LhA2LZX_v2.8 < prev    next >
Text File  |  1998-04-07  |  11KB  |  275 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.8 (5.4.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 (which stores the path of the temporary directory 'l2z'), 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
  14.         delete l2z/#? ALL QUIET FORCE    ;The contents of the temporary drawer used to store the archive files are deleted to start freshly
  15.     endif
  16. endif
  17.  
  18. if NOT EXISTS env:nl2zorig            ;If starting, default path of archive is RAM:
  19.     echo "RAM:" >env:nl2zorig        ;If converting several archives, the path of the last archive will be used as the default of the next
  20. endif
  21.  
  22. if NOT EXISTS env:nl2zd                ;If starting, default path of temporary drawer l2z is RAM:
  23.     echo RAM: >env:nl2zd            ;If converting several archives, the previous path of l2z will be used as the default of the next
  24. endif
  25.  
  26. which >env:nl2zwlha lha all            ;Finds the location of the LhA tool
  27. if WARN                        ;If the LhA tool cannot be found
  28.     RequestChoice >nil: "LhA2LZX Error Message" "Can't find 'LhA' tool!*nSee docs for details!" "Quit"
  29.     skip end
  30. endif
  31.  
  32. which >env:nl2zwlzx lzx all            ;Finds the location of the LZX tool e.g. 'C:LZX'
  33. if WARN
  34.     RequestChoice >nil: "LhA2LZX Error Message" "Can't find 'LZX' tool!*nSee docs for details!" "Quit"
  35.     skip end
  36. endif
  37.  
  38. if NOT EXISTS L:lzx.keyfile
  39.     RequestChoice >nil: "LhA2LZX Error Message" "Can't find lzx.keyfile!*nSee docs for details!" "Quit"
  40.     skip end
  41. endif
  42.  
  43. if EXISTS env:nl2zdrw1        ;If the temporary drawer has been chosen already from a previous run...
  44.     cd $nl2zdrw1        ;...we go there and...
  45.     makedir l2z >nil:    ;...create the temporary drawer...
  46.     skip File        ;...then we skip to the main body of the program
  47. endif
  48.  
  49. lab Temp
  50. 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"
  51. if $nl2zdrw EQ 1                ;If the left button (i.e. RAM:) is chosen
  52.     echo "*"RAM:*"" >envarc:nl2zdrw1    ;Asterisks are used before quote marks to tell AmigaDOS to use the quote character
  53.     copy envarc:nl2zdrw1 TO env:nl2zdrw1 >nil:
  54.     cd RAM:
  55.     makedir l2z >NIL:
  56. endif
  57.  
  58. if $nl2zdrw EQ 2                ;If "Other" is chosen
  59.     lab Other
  60.     RequestFile >env:nl2zdrw1 TITLE "Where should 'l2z' be made?" DRAWERSONLY NOICONS POSITIVE Create DRAWER RAM:
  61.     if WARN
  62.         skip Temp back
  63.     endif
  64.  
  65.     if $nl2zdrw1 EQ "Ram Disk:"            ;If user clicks on RAM: in file requester...
  66.         echo "*"RAM:*"" >envarc:nl2zdrw1    ;...to make things easier when checking for amount of memory needed later
  67.     endif
  68.  
  69.     echo >env:nl2zd $nl2zdrw1        ;Get rid of quotation marks
  70.     if NOT EXISTS $nl2zdrw1
  71.         RequestChoice "! Error !" "PATH does not exist!" "Choose again!"
  72.         skip Other BACK
  73.     else
  74.         copy env:nl2zdrw1 TO envarc:nl2zdrw1 >nil:
  75.         cd $nl2zdrw1
  76.         makedir l2z >NIL:
  77.     endif
  78. endif
  79.  
  80. if $nl2zdrw EQ 0                ;If "Cancel" is chosen
  81.     skip end
  82. endif
  83.  
  84.  
  85.  
  86.  
  87. ;...And now on to the main workings...
  88.  
  89.  
  90.  
  91.  
  92. lab File
  93. 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
  94. if WARN
  95.     skip end
  96. endif
  97.  
  98. list >env:nl2zorig $nl2zldfl LFORMAT="*"%F*""    ;Get the path of the directory that the file is in, surrounded by quotation marks
  99. if $nl2zorig EQ "Ram Disk:"
  100.     echo "*"RAM:*"" >env:nl2zorig        ;For some reason, if RAM: is chosen, "RAM:" is stored in env:nl2zldfl but "Ram Disk:" is stored in env:nl2zorig...
  101. endif
  102. echo >env:nl2zo $nl2zorig            ;Get rid of the quotes around the directory name
  103.  
  104. if NOT EXISTS $nl2zorig
  105.     RequestChoice >nil: "! Error !" "PATH does not exist!" "Try again"
  106.     skip File BACK
  107. endif
  108.  
  109. if $nl2zldfl EQ $nl2zorig
  110.     RequestChoice >nil: "! Error !" "No file chosen!" "Try again"
  111.     skip File BACK
  112. endif
  113.  
  114. if NOT EXISTS $nl2zldfl
  115.     RequestChoice >nil: "! Error !" "FILE does not exist!" "Try again"
  116.     skip File BACK
  117. endif
  118.  
  119.  
  120. lab Tilde
  121. search env:nl2zldfl ~ >nil:
  122. if $RC EQ 0
  123.     RequestChoice >nil: "! Error !" "Filename contains a tilde (~)*n*nPlease rename the file without a tilde*n*nSee docs for details" "Okay"
  124.     skip end
  125. endif
  126.  
  127. echo >env:nl2zl $nl2zldfl            ;Get rid of quotation marks
  128.  
  129. list >env:nl2zsuf $nl2zldfl LFORMAT=%E        ;Gives suffix only
  130.  
  131. if $nl2zsuf NOT EQ lha                ;If file doesn't have .lha suffix
  132.     if $nl2zsuf NOT EQ lzx            ;If file doesn't have .lzx suffix
  133.         if $nl2zsuf NOT EQ lzh        ;If file doesn't have .lzh suffix (which is de-archived by LhA)
  134.             RequestChoice "! Error !" "File is NOT an LhA or LZX archive!" "Choose again!"
  135.             skip File back
  136.         endif
  137.     endif
  138. endif
  139.  
  140. list >env:nl2zbnm1 $nl2zldfl LFORMAT=%S        ;Strips the path of the archive to give only the filename with suffix
  141. list >env:nl2zbnm $nl2zldfl LFORMAT=%M        ;Removes .lzx, .lha or .lzh suffix from filename
  142. list >env:nl2zcom $nl2zldfl LFORMAT=%C        ;Gets file comment
  143. list >env:nl2zdat $nl2zldfl LFORMAT=%D DATES    ;Gets file creation date
  144. list >env:nl2ztim $nl2zldfl LFORMAT=%T        ;Gets file creation time
  145. list >env:nl2zcomsz env:nl2zcom LFORMAT=%L    ;Gets size of comment
  146.  
  147. 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"
  148. 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
  149. cd $nl2zorig                    ;CD's to the directory of the original archive
  150. list >env:nl2zflsz $nl2zldfl LFORMAT=%L        ;Gets size of original archive
  151. eval >env:nl2zflmem $nl2zflsz * 4        ;Multiplies the archive size by 4
  152. eval >env:nl2zflk $nl2zflmem / 1024        ;Gives the size of the required memory in Kilobytes, as it will be easier to read and relate to than bytes
  153. 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)...
  154.     if $nl2zdrw1 EQ "RAM:"            ;...and RAM: has been chosen to store temporary files...
  155.         RequestChoice >env:nl2znomem "! Insufficient Memory!" "There may be insufficient memory to store temporary files in RAM:*n(may need at least $nl2zflk k)" "Choose other path" "Continue anyway" "Cancel"
  156.         if $nl2znomem EQ 0        ;"Cancel"
  157.             skip More
  158.         endif
  159.         if $nl2znomem EQ 1        ;"Other"
  160.             skip Other back
  161.         endif
  162.     endif
  163. endif
  164.  
  165. if $nl2zsuf EQ lha
  166.     echo LZX >env:nl2znsuf            ;Gives the type of file to convert to in a requester later
  167.     echo LhA >env:nl2zsuf
  168. endif
  169.  
  170. if $nl2zsuf EQ lzx
  171.     echo LhA >env:nl2znsuf
  172.     echo LZX >env:nl2zsuf            ;Makes it look better in the requester
  173. endif
  174.  
  175. if $nl2zsuf EQ lzh
  176.     echo LZX >env:nl2znsuf
  177.     echo LZH >env:nl2zsuf
  178. endif
  179.  
  180. lab Extra
  181. echo "*e[0 p"                ;This clears the display (the output CLI)
  182. 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"
  183. if $nl2zext EQ 0            ;If 'Cancel' is selected
  184.     skip beg BACK            ;This skips back to the section labelled 'Beg', at the beginning
  185. endif
  186.  
  187.  
  188. lab Conv                ;This part until 'lab More' converts the archive to either LhA or LZX, and saves whichever type the user requested
  189. cd $nl2zdrw1
  190. cd l2z
  191. "$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
  192. if NOT $RC EQ 0                ;If user aborts it will skip to 'More'
  193.     skip er                ;RC stands for Return Code - the number returned by LhA if the operation fails
  194. endif
  195.     
  196. if $nl2zsuf EQ lzx                        ;Means it is an LZX archive
  197.     "$nl2zwlha" -2 -a -r -F -y -M -e -x a $nl2zbnm #?    ;If not aborted, file is archived
  198.     if NOT $RC EQ 0                        ;If user aborts it will skip to 'More'
  199.         skip er
  200.     endif
  201. else                            ;Means it is an LhA/LZH archive
  202.     "$nl2zwlzx" -r -e -3 -X -F a -Qf $nl2zbnm #?    ;If not aborted, file is archived
  203.     if NOT $RC EQ 0                    ;If user aborts it will skip to 'More'
  204.         skip er
  205.     endif
  206. endif
  207.  
  208.  
  209. lab Size
  210. list >env:nl2zold $nl2zldfl LFORMAT=%L            ;Gets the size of the original archive
  211. list >env:nl2znew $nl2zbnm.$nl2znsuf LFORMAT=%L        ;Gets the size of the new archive
  212. eval >env:nl2zdiff $nl2zold - $nl2znew            ;Subtracts the size of the new from the original
  213. eval >env:nl2zdiff1 $nl2znew - $nl2zold            ;Subtracts the size of the original from the new
  214.  
  215. if $nl2znew GT $nl2zold VAL                ;Original archive is smaller than the new one, so the original is kept
  216.     if $nl2zext EQ 2                ;If the user wanted to convert to the other filetype
  217.         RequestChoice > NIL: " $nl2zl used" "Using the original archive because it's $nl2zdiff1 bytes*nsmaller than the $nl2znsuf version!" "Okay"        ;The difference in file sizes is cleverly given
  218.         skip more
  219.     endif
  220. endif
  221.  
  222. delete $nl2zldfl QUIET
  223. copy $nl2zbnm.$nl2znsuf TO $nl2zorig QUIET
  224. if NOT env:nl2zcomsz EQ 1                    ;If the original archive had a comment...
  225.     filenote FILE "$nl2zo$nl2zbnm.$nl2znsuf" "$nl2zcom"    ;...copy it to the new archive
  226. endif
  227. setdate "$nl2zo$nl2zbnm.$nl2znsuf" $nl2zdat $nl2ztim        ;Sets the date of the new archive to the old
  228. if $nl2zext EQ 1                        ;If the user wanted to convert to the other filetype
  229.     if $nl2znew GT $nl2zold VAL
  230.         RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.$nl2znsuf*n  now replaces*n$nl2zl*n  and is $nl2zdiff1 bytes larger" "Okay"
  231.     else
  232.         RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.$nl2znsuf*n  now replaces*n$nl2zl*n  and is $nl2zdiff bytes smaller!" "Nice one!"
  233.     endif
  234. else
  235.     RequestChoice > NIL: "! $nl2zo$nl2zbnm.$nl2znsuf used !" "Using the new archive because it's $nl2zdiff bytes smaller!" "Nice one!"
  236. endif
  237.  
  238.  
  239. lab More
  240. echo "*e[1;1H*eJ"
  241. RequestChoice >env:nl2zano "Other archives?" "Do you want to convert another archive?" "Yes" "No"
  242. if $nl2zano EQ 0
  243.     skip end
  244. else
  245.     skip beg back
  246. endif
  247.  
  248. lab er
  249. RequestChoice >NIL: "! Error !" "An error/user-abort has occured!*n*nSee docs for details" "Okay"
  250. skip more back
  251.  
  252. lab end
  253. echo "*e[1;1H*eJ"                                ;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 - known as ANSI - see "v2.2" in "Program History" in the .guide
  256. echo "*n*n*n"
  257.  
  258. if EXISTS env:nl2zdrw1
  259.     cd $nl2zdrw1
  260.     if EXISTS l2z
  261.         delete l2z ALL QUIET FORCE    ;Delete all the temporary files
  262.     endif
  263. endif
  264.  
  265. if EXISTS RAM:l2z                ;This is in case the drawer where 'l2z' was located had to be changed from RAM: due to insufficient memory
  266.     delete RAM:l2z ALL QUIET FORCE
  267. endif
  268.  
  269.  
  270. 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
  271. execute T:l2ztmp >nil:                        ;The variables are actually deleted by this line
  272. delete T:l2ztmp >nil:                        ;The new script generated is deleted here.  Now everything LhA2LZX created during its running has been disposed of.
  273. copy envarc:nl2zdrw1 env:nl2zdrw1 >nil:                ;Copy the path of the temporary drawer back so that it will be automatically used again
  274.  
  275. Quit                ;The end of LhA2LZX  :^(