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
if WARN
skip end
endif
if NOT EXISTS $nl2zorig
RequestChoice >nil: "! Error !" "PATH does not exist!" "Try again"
skip Path BACK
endif
echo >env:nl2zo $nl2zorig ;Get rid of quotation marks, and also create default path for next archive if converting more
list >env:nl2zosz env:nl2zo LFORMAT=%L ;Get size of path name
if $nl2zosz EQ 1 ;Full path not selected
RequestChoice > NIL: "! Error !" "Choose FULL path!*n(i.e. start with DEVICE listing)" "Try again"
skip Path BACK
endif
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 More
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:nl2zlsz env:nl2zl LFORMAT=%L ;Get size of file name
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:nl2zsuf $nl2zldfl LFORMAT=%E ;Gives suffix only
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
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!"
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 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:" >env:nl2zdrw1
endif
lab Other
if $nl2zdrw EQ 2 ;If "Other" is chosen
RequestFile >env:nl2zdrw1 TITLE "Where should 'L2Z' be made?" DRAWERSONLY NOICONS POSITIVE Create DRAWER "$nl2zd"
if WARN
skip More
endif
echo >env:nl2zd $nl2zdrw1 ;Get rid of quotation marks
list >env:nl2zdsz env:nl2zd LFORMAT=%L ;Get size of path name
if $nl2zdsz EQ 1 ;Full path not selected
RequestChoice > NIL: "! Error !" "Choose FULL path!*n(i.e. start with DEVICE listing)" "Try again"
skip Other BACK
endif
if NOT EXISTS $nl2zdrw1
RequestChoice "! Error !" "PATH does not exist!" "Choose again!"
skip Other BACK
endif
endif
if $nl2zdrw EQ 0 ;If "Cancel" is chosen
skip More
endif
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
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 $nl2zflmem bytes)" "Choose other path" "Continue anyway" "Cancel"
if $nl2znomem EQ 0 ;"Cancel"
skip More
endif
if $nl2znomem EQ 1 ;"Other"
skip Temp back
endif
if $nl2znomem EQ 2 ;"Continue"
skip MkTemp
endif
endif
if $nl2zdrw1 EQ "Ram Disk:" ;If user clicks on RAM: in file requester
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"
if $nl2znomem EQ 0 ;"Cancel"
skip More
endif
if $nl2znomem EQ 1 ;"Other"
skip Temp back
endif
if $nl2znomem EQ 2 ;"Continue"
skip MkTemp
endif
endif
endif
lab MkTemp
cd $nl2zdrw1
if NOT EXISTS l2z ;This creates a temporary drawer in which to de-archive the files in the archive
makedir > NIL: l2z
else ;Drawer is emptied if it is already there
delete l2z/#? FORCE QUIET
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 WARN ;If 'Cancel' is selected
skip beg BACK ;This skips back to the section labelled 'Beg', at the beginning
endif
if $nl2zext EQ 2 ;If the user wants to make the smallest archive
skip Conv ;This skips forward to the section labelled 'Conv'
endif
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
if $nl2zsuf EQ lha ;Means it is an LhA archive
lab L ;Label 'L' so the script can skip straight here if told to
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
"$nl2zwlzx" -r -e -3 -X -F a -Qf $nl2zbnm #?
if NOT $RC EQ 0 ;If user aborts it will skip to 'More'
skip er
endif
list >env:nl2zold $nl2zldfl LFORMAT=%L ;Gets the size of the original archive
list >env:nl2znew $nl2zbnm.lzx 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
delete $nl2zldfl QUIET ;Original archive is deleted
copy $nl2zbnm.lzx TO $nl2zorig QUIET ;New archive is copied in place of the original
if NOT env:nl2zcomsz EQ 1 ;If the original archive had a comment...
filenote FILE "$nl2zo$nl2zbnm.lzx" "$nl2zcom" ;...copy it to the new archive
endif
setdate "$nl2zo$nl2zbnm.lzx" $nl2zdat $nl2ztim ;Sets the date of the new archive to the old
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
RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.lzx*n now replaces*n$nl2zl*n and is $nl2zdiff bytes smaller!" "Nice one!"
else
RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.lzx*n now replaces*n$nl2zl*n and is $nl2zdiff1 bytes larger" "Okay"
endif
else ;"If that fails, try this..." - i.e. means it is NOT an LhA archive
if $nl2zsuf EQ lzh ;It is an LZH archive (processed by LhA)
skip L BACK
endif
cd $nl2zdrw1 ;If this line is reached, it is an LZX archive
cd l2z
"$nl2zwlzx" x -a -F -x -X0 $nl2zldfl ;LZX extracts the original archive to temporary drawer 'l2z'
if NOT $RC EQ 0 ;If user aborts it will skip to 'More'
skip er
endif
"$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
if NOT $RC EQ 0 ;If user aborts it will skip to 'More'
skip er
endif
list >env:nl2zold $nl2zldfl LFORMAT=%L
list >env:nl2znew $nl2zbnm.lha LFORMAT=%L
eval >env:nl2zdiff $nl2zold - $nl2znew
eval >env:nl2zdiff1 $nl2znew - $nl2zold
delete $nl2zldfl QUIET ;Original archive is deleted
copy $nl2zbnm.lha TO $nl2zorig QUIET ;New archive is copied in place of the original
if NOT env:nl2zcomsz EQ 1 ;If the original archive had a comment...
filenote FILE "$nl2zo$nl2zbnm.lha" "$nl2zcom" ;...copy it to the new archive
endif
setdate "$nl2zo$nl2zbnm.lha" $nl2zdat $nl2ztim ;Sets the date of the new archive to the old
if $nl2zold GT $nl2znew VAL
RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.lha*n now replaces*n$nl2zl*n and is $nl2zdiff bytes smaller!" "Nice one!"
else
RequestChoice > NIL: "! Operation Successful !" "$nl2zo$nl2zbnm.lha*n now replaces*n$nl2zl*n and is $nl2zdiff1 bytes larger" "Okay"
endif
endif
endif
skip More
lab er
RequestChoice >NIL: "! Error !" "An error/user-abort has occured!*n*nSee docs for details" "Okay"
skip more
lab Conv ;This part until 'lab More' converts the archive to either LhA or LZX, and saves whichever is smaller
if $nl2zsuf EQ lha ;Means it is an LhA archive
lab L2
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 back ;RC stands for Return Code - the number returned by LhA if the operation fails
endif
"$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 back
endif
else ;Means it is not an LhA archive
if $nl2zsuf EQ lzh ;Means it is an LZH archive
skip L2 BACK
endif
cd $nl2zdrw1 ;If this line is reached, it is an LZX archive
cd l2z
"$nl2zwlzx" x -a -F -x -X0 $nl2zldfl
if NOT $RC EQ 0 ;If user aborts it will skip to 'More'
skip er back
endif
"$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 back
endif
endif
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 $nl2zold GT $nl2znew VAL ;Original archive is larger than the new one, so the original is deleted and replaced by the smaller new one
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
list >env:nl2zarc $nl2zo$nl2zbnm.$nl2znsuf LFORMAT=%S%S ;Gets name of new archive
echo >env:nl2zarc1 $nl2zarc ;Removes quotation marks
RequestChoice > NIL: "! $nl2zarc1 used !" "Using the new archive because it's $nl2zdiff bytes smaller!" "Nice one!"
else ;Original archive is smaller than the new one, so the smaller original one is kept
RequestChoice > NIL: " $nl2zl used" "Using the original archive because it's $nl2zdiff1 bytes smaller!" "Okay" ;The difference in file sizes is cleverly given
cd $nl2zdrw1
delete l2z ALL QUIET FORCE
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 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 ;If a temporary drawer was created to store files temporarily...
delete l2z ALL QUIET FORCE ;...delete all the temporary files
endif
endif
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
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.