RequestFile >env:orig TITLE "Full path of drawer of archive?" DRAWERSONLY NOICONS ;Saves the location of the archive in the environment variable 'orig'
if WARN
skip end
endif
RequestFile >env:ldfl TITLE "Chose file to convert" POSITIVE Convert ACCEPTPATTERN #?.(lha|lzx) DRAWER $orig
if WARN
skip more
endif
basename >env:bnm1 $ldfl ;Strips the path of the archive to give only the filename with suffix
basename >env:bnm $bnm1 .lzx ;Removes .lzx suffix from filename if it has it
RequestChoice >env:drw "Default directory" "Where should I store temporary files?*nRAM: is fastest but not advisable if you*nhaven't got much. A temporary drawer called 'L2Z'*nwill be created in your selected destination" "RAM:" "Other"
if $drw EQ 1 ;If the left button (i.e. RAM:) is chosen
echo RAM: >env:drw1
endif
if $drw EQ 0
RequestFile >env:drw1 TITLE "Where should 'L2Z' be made?" DRAWERSONLY NOICONS POSITIVE Create
if WARN
skip more
endif
endif
cd $drw1
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
RequestChoice >env:ext "FileType" "Do you want to convert to the other*nfiletype or to the smallest archive?*n*nConvert to:" "LhA" "LZX" "Smallest" "Cancel"
if WARN ;If 'Cancel' is selected
skip beg BACK ;This skips back to the section labelled 'Beg', at the beginning
endif
if $ext EQ 3 ;If the user wants to make the smallest archive
skip conv ;This skips forward to the section labelled 'Conv'
endif
if $ext EQ 1 ;If the user wants to convert TO LhA
if NOT $bnm1 EQ $bnm ;Means it is NOT an LhA archive (i.e. suffix has been stripped)
cd $drw1
cd l2z
$wlzx x -a $ldfl ;LZX extracts the original archive to temporary drawer 'l2z'
$wlha -2ar a $bnm #? ;LhA archives everything in 'l2z' and saves it as the original name with .lha suffix
delete $ldfl QUIET ;Original archive is deleted
copy $bnm.lha TO $orig QUIET ;New archive is copied in place of the original
else ;Means it IS an LhA archive
echo "*n*e[1;1H*e[J"
echo "*e[2mFile is already an LhA archive!*e[0m"
skip extra BACK
endif
endif
if $ext EQ 2 ;If the user wants to convert TO LZX
if $bnm1 EQ $bnm ;Means it is an LhA archive
delete env:bnm QUIET
basename >env:bnm $bnm1 .lha
cd $drw1
cd l2z
$wlha x -a $ldfl
$wlzx -r -e -3 a $bnm #?
delete $ldfl QUIET
copy $bnm.lzx TO $orig QUIET
else ;Means it is NOT an LhA archive (i.e. suffix has been stripped)
echo "*n*e[1;1H*e[J" ;This clears the output window
echo "*e[2mFile is already an LZX archive!*e[0m" ;Text appears white
skip extra BACK
endif
endif
skip More
lab Conv ;This part until 'lab More' converts the archive to either LhA or LZX, and saves whichever is smaller
if $bnm1 EQ $bnm ;Means it is an LhA archive (i.e. suffix not stripped)
delete env:bnm QUIET
basename >env:bnm $bnm1 .lha
cd $drw1
cd l2z
$wlha x -a $ldfl
$wlzx -r -e -3 a $bnm #?
else ;Means it is an LZX archive
cd $drw1
cd l2z
$wlzx x -a $ldfl
$wlha -2ar a $bnm #?
endif
list >env:old $ldfl LFORMAT=%L ;Gets the size of the original archive
list >env:new $bnm.(lzx|lha) LFORMAT=%L ;Gets the size of the new archive
eval >env:diff $old - $new ;Subtracts the size of the new from the original
eval >env:diff1 $new - $old ;Subtracts the size of the original from the new
if $old GT $new VAL ;Original archive is larger than the new one, so the original is deleted and replaced by the smaller new one
delete $ldfl QUIET
echo "*e[1;1H*e[J*n Using new archive because it's *e[2m$diff *e[0mbytes smaller!" ;All the *e[... parts do is change the colour/style of the text
copy $bnm.(lzx|lha) TO $orig QUIET
else ;Original archive is smaller than the new one, so the smaller original one is kept
echo "*e[1;1H*e[J*n Using old archive because it's *e[2m$diff1 *e[0mbytes smaller!" ;The difference in file sizes is cleverly given
cd $drw1
delete l2z ALL QUIET FORCE
endif
lab More
RequestChoice >env:ano "Other archives?" "Do you want to convert another archive?" "Yes" "No"