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
Resident > NIL: C:RequestFile PURE
Resident > NIL: C:Eval PURE
Resident > NIL: C:List PURE
; $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
Failat 60 ;Allows errors when using LhA & LZX to be captured
lab Beg
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
cd $nl2zdrw1 ;Current Directory is now that which is stated in the contents of the environmental variable 'nl2zdrw1'
if EXISTS l2z
delete l2z/#? ALL QUIET FORCE ;The contents of the temporary drawer used to store the archive files are deleted to start freshly
endif
endif
if NOT EXISTS env:nl2zorig ;If starting, default path of archive is RAM:
echo "RAM:" >env:nl2zorig ;If converting several archives, the path of the last archive will be used as the default of the next
endif
if NOT EXISTS env:nl2zd ;If starting, default path of temporary drawer l2z is RAM:
echo RAM: >env:nl2zd ;If converting several archives, the previous path of l2z will be used as the default of the next
endif
which >env:nl2zwlha lha all ;Finds the location of the LhA tool
if EXISTS env:nl2zdrw1 ;If the temporary drawer has been chosen already from a previous run...
cd $nl2zdrw1 ;...we go there and...
makedir l2z >nil: ;...create the temporary drawer...
skip File ;...then we skip to the main body of the program
endif
lab Temp
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"
if $nl2zdrw EQ 1 ;If the left button (i.e. RAM:) is chosen
echo "*"RAM:*"" >envarc:nl2zdrw1 ;Asterisks are used before quote marks to tell AmigaDOS to use the quote character
copy envarc:nl2zdrw1 TO env:nl2zdrw1 >nil:
cd RAM:
makedir l2z >NIL:
endif
if $nl2zdrw EQ 2 ;If "Other" is chosen
lab Other
RequestFile >env:nl2zdrw1 TITLE "Where should 'l2z' be made?" DRAWERSONLY NOICONS POSITIVE Create DRAWER RAM:
if WARN
skip Temp back
endif
if $nl2zdrw1 EQ "Ram Disk:" ;If user clicks on RAM: in file requester...
echo "*"RAM:*"" >envarc:nl2zdrw1 ;...to make things easier when checking for amount of memory needed later
endif
echo >env:nl2zd $nl2zdrw1 ;Get rid of quotation marks
if NOT EXISTS $nl2zdrw1
RequestChoice "! Error !" "PATH does not exist!" "Choose again!"
skip Other BACK
else
copy env:nl2zdrw1 TO envarc:nl2zdrw1 >nil:
cd $nl2zdrw1
makedir l2z >NIL:
endif
endif
if $nl2zdrw EQ 0 ;If "Cancel" is chosen
skip end
endif
;...And now on to the main workings...
lab File
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
if WARN
skip end
endif
list >env:nl2zorig $nl2zldfl LFORMAT="*"%F*"" ;Get the path of the directory that the file is in, surrounded by quotation marks
if $nl2zorig EQ "Ram Disk:"
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...
endif
echo >env:nl2zo $nl2zorig ;Get rid of the quotes around the directory name
if NOT EXISTS $nl2zorig
RequestChoice >nil: "! Error !" "PATH does not exist!" "Try again"
skip File BACK
endif
if $nl2zldfl EQ $nl2zorig
RequestChoice >nil: "! Error !" "No file chosen!" "Try again"
skip File BACK
endif
if NOT EXISTS $nl2zldfl
RequestChoice >nil: "! Error !" "FILE does not exist!" "Try again"
skip File BACK
endif
lab Tilde
search env:nl2zldfl ~ >nil:
if $RC EQ 0
RequestChoice >nil: "! Error !" "Filename contains a tilde (~)*n*nPlease rename the file without a tilde*n*nSee docs for details" "Okay"
skip end
endif
echo >env:nl2zl $nl2zldfl ;Get rid of quotation marks
list >env:nl2zsuf $nl2zldfl LFORMAT=%E ;Gives suffix only
if $nl2zsuf NOT EQ lha ;If file doesn't have .lha suffix
if $nl2zsuf NOT EQ lzx ;If file doesn't have .lzx suffix
if $nl2zsuf NOT EQ lzh ;If file doesn't have .lzh suffix (which is de-archived by LhA)
RequestChoice "! Error !" "File is NOT an LhA or LZX archive!" "Choose again!"
skip File back
endif
endif
endif
list >env:nl2zbnm1 $nl2zldfl LFORMAT=%S ;Strips the path of the archive to give only the filename with suffix
list >env:nl2zbnm $nl2zldfl LFORMAT=%M ;Removes .lzx, .lha or .lzh suffix from filename
list >env:nl2zcom $nl2zldfl LFORMAT=%C ;Gets file comment
list >env:nl2zdat $nl2zldfl LFORMAT=%D DATES ;Gets file creation date
list >env:nl2ztim $nl2zldfl LFORMAT=%T ;Gets file creation time
list >env:nl2zcomsz env:nl2zcom LFORMAT=%L ;Gets size of comment
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"
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
cd $nl2zorig ;CD's to the directory of the original archive
list >env:nl2zflsz $nl2zldfl LFORMAT=%L ;Gets size of original archive
eval >env:nl2zflmem $nl2zflsz * 4 ;Multiplies the archive size by 4
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
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)...
if $nl2zdrw1 EQ "RAM:" ;...and RAM: has been chosen to store temporary files...
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"
if $nl2znomem EQ 0 ;"Cancel"
skip More
endif
if $nl2znomem EQ 1 ;"Other"
skip Other back
endif
endif
endif
if $nl2zsuf EQ lha
echo LZX >env:nl2znsuf ;Gives the type of file to convert to in a requester later
echo LhA >env:nl2zsuf
endif
if $nl2zsuf EQ lzx
echo LhA >env:nl2znsuf
echo LZX >env:nl2zsuf ;Makes it look better in the requester
endif
if $nl2zsuf EQ lzh
echo LZX >env:nl2znsuf
echo LZH >env:nl2zsuf
endif
lab Extra
echo "*e[0 p" ;This clears the display (the output CLI)
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"
if $nl2zext EQ 0 ;If 'Cancel' is selected
skip beg BACK ;This skips back to the section labelled 'Beg', at the beginning
endif
lab Conv ;This part until 'lab More' converts the archive to either LhA or LZX, and saves whichever type the user requested
cd $nl2zdrw1
cd l2z
"$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
if NOT $RC EQ 0 ;If user aborts it will skip to 'More'
skip er ;RC stands for Return Code - the number returned by LhA if the operation fails
endif
if $nl2zsuf EQ lzx ;Means it is an LZX archive
"$nl2zwlha" -2 -a -r -F -y -M -e -x a $nl2zbnm #? ;If not aborted, file is archived
if NOT $RC EQ 0 ;If user aborts it will skip to 'More'
skip er
endif
else ;Means it is an LhA/LZH archive
"$nl2zwlzx" -r -e -3 -X -F a -Qf $nl2zbnm #? ;If not aborted, file is archived
if NOT $RC EQ 0 ;If user aborts it will skip to 'More'
skip er
endif
endif
lab Size
list >env:nl2zold $nl2zldfl LFORMAT=%L ;Gets the size of the original archive
list >env:nl2znew $nl2zbnm.$nl2znsuf LFORMAT=%L ;Gets the size of the new archive
eval >env:nl2zdiff $nl2zold - $nl2znew ;Subtracts the size of the new from the original
eval >env:nl2zdiff1 $nl2znew - $nl2zold ;Subtracts the size of the original from the new
if $nl2znew GT $nl2zold VAL ;Original archive is smaller than the new one, so the original is kept
if $nl2zext EQ 2 ;If the user wanted to convert to the other filetype
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
skip more
endif
endif
delete $nl2zldfl QUIET
copy $nl2zbnm.$nl2znsuf TO $nl2zorig QUIET
if NOT env:nl2zcomsz EQ 1 ;If the original archive had a comment...
filenote FILE "$nl2zo$nl2zbnm.$nl2znsuf" "$nl2zcom" ;...copy it to the new archive
endif
setdate "$nl2zo$nl2zbnm.$nl2znsuf" $nl2zdat $nl2ztim ;Sets the date of the new archive to the old
if $nl2zext EQ 1 ;If the user wanted to convert to the other filetype
if $nl2znew GT $nl2zold VAL
RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.$nl2znsuf*n now replaces*n$nl2zl*n and is $nl2zdiff1 bytes larger" "Okay"
else
RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.$nl2znsuf*n now replaces*n$nl2zl*n and is $nl2zdiff bytes smaller!" "Nice one!"
endif
else
RequestChoice > NIL: "! $nl2zo$nl2zbnm.$nl2znsuf used !" "Using the new archive because it's $nl2zdiff bytes smaller!" "Nice one!"
endif
lab More
echo "*e[1;1H*eJ"
RequestChoice >env:nl2zano "Other archives?" "Do you want to convert another archive?" "Yes" "No"
if $nl2zano EQ 0
skip end
else
skip beg back
endif
lab er
RequestChoice >NIL: "! Error !" "An error/user-abort has occured!*n*nSee docs for details" "Okay"
skip more back
lab end
echo "*e[1;1H*eJ" ;This clears the output window
echo "*n*n*n *e[1;32m Thank you for using"
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
echo "*n*n*n"
if EXISTS env:nl2zdrw1
cd $nl2zdrw1
if EXISTS l2z
delete l2z ALL QUIET FORCE ;Delete all the temporary files
endif
endif
if EXISTS RAM:l2z ;This is in case the drawer where 'l2z' was located had to be changed from RAM: due to insufficient memory
delete RAM:l2z ALL QUIET FORCE
endif
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
execute T:l2ztmp >nil: ;The variables are actually deleted by this line
delete T:l2ztmp >nil: ;The new script generated is deleted here. Now everything LhA2LZX created during its running has been disposed of.
copy envarc:nl2zdrw1 env:nl2zdrw1 >nil: ;Copy the path of the temporary drawer back so that it will be automatically used again