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
echo >env:o $orig ;Get rid of quotation marks
list >env:osz env:o LFORMAT=%L ;Get size of path name
if "$osz" EQ "1" ;Full path not selected
echo "Choose FULL path!"
skip Path BACK
delete env:osz QUIET
delete env:o QUIET
endif
lab File
RequestFile >env:ldfl TITLE "Chose file to convert" POSITIVE Convert ACCEPTPATTERN #?.(lha|lzx) DRAWER $orig
if WARN
skip More
endif
echo >env:l $ldfl ;Get rid of quotation marks
list >env:lsz env:l LFORMAT=%L ;Get size of file name
if "$lsz" EQ "$osz" ;No file selected
echo "No file chosen!"
skip File BACK
delete env:lsz QUIET
delete env:l QUIET
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:" "Other" "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 2 ;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 the other format - original format is found and is intelligently converted to the other
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
if $RC EQ 20 ;If user aborts it will skip to 'More'
skip More
endif
$wlzx -r -e -3 a $bnm #?
if $RC EQ 50 ;If user aborts it will skip to 'More'
skip More
endif
delete $ldfl QUIET
copy $bnm.lzx TO $orig QUIET
else ;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'
if $RC EQ 50 ;If user aborts it will skip to 'More'
skip More
endif
$wlha -2ar a $bnm #? ;LhA archives everything in 'l2z' and saves it as the original name with .lha suffix
if $RC EQ 20 ;If user aborts it will skip to 'More'
skip More
endif
delete $ldfl QUIET ;Original archive is deleted
copy $bnm.lha TO $orig QUIET ;New archive is copied in place of the original
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
if $RC EQ 20 ;If user aborts it will skip to 'More'
skip More
endif
$wlzx -r -e -3 a $bnm #? ;If not aborted, file is archived
if $RC EQ 50 ;If user aborts it will skip to 'More'
skip More
endif
else ;Means it is an LZX archive
cd $drw1
cd l2z
$wlzx x -a $ldfl
if $RC EQ 50 ;If user aborts it will skip to 'More'
skip More
endif
$wlha -2ar a $bnm #? ;If not aborted, file is archived
if $RC EQ 20 ;If user aborts it will skip to 'More'
skip More
endif
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"