failat 21

if not exists XEN-Icons
  echo "*n Please change current directory to that of MagicWB *n or start the installation from the Workbench!*n"
  quit
endif

assign Magic: ""

echo "*n*e[1;32m ____________________________________________________________________"
echo " *e[43m                                                                    *e[0m"
echo " *e[0;32;43m             Welcome to MagicWB v2.1p: UPDATE DRAWERS*e[1m               *e[0m"
echo " *e[1;4;43m                                                                    *e[0m"
echo "*n*n This  small  installation  was  written to provide you with the most"
echo " comfortable  way of replacing the old Drawer-Icons with the new ones"
echo " from MagicWB."
echo " *n If  you  have  found  old drawers on your Workbench, please remember"
echo " the  PATH  where  they are located to provide this installation with"
echo " the exact path so that it can update these drawers."
echo " *n Comment:  This  installation  WILL  PRESERVE  the original positions"
echo " of  your  old  drawers.  Only  the old Drawer-Images will be changed."
echo " So, don't be afraid.  You  will  NOT  lose your old drawer snapshots.*n"
echo " This  installation  even  takes  care of the new Image-Drawers which"
echo " means  that  it  recognizes these Image-Drawers and does not replace"
echo " them  with  the default drawer in that case. This saves you a lot of"
echo " work.  You  can even update your SYS: partition without any concerns."
echo noline "*n Start the Drawer-Update? "

set > nil: InpVar ?

if $InpVar eq "ja"
  skip Start
endif

if $InpVar eq "j"
  skip Start
endif

if $InpVar eq "y"
  skip Start
endif

if $InpVar eq "yes"
  skip Start
endif

echo noline "*n*e[32m Update aborted."
quit

lab Start
resident IU programs/IconUpdate pure
echo "*e[1;1H*e[J"
echo "*n Information: You can always abort this installation by pressing"
echo " CTRL-D (and, if needed, followed by pressing RETURN).*n"
echo "*n You can decide now if you want to update the drawers ONLY"
echo " IN THE DIRECTORY of the given path (= Normal mode) or INCLUDING"
echo " ALL SUB-DIRECTORIES of the given path (= Recursive mode).*n"
echo " If you want to do it in the normal mode enter [32mN[0m."
echo " If you want to do it recursively enter [32mR[0m."
echo noline "*n Which mode do you prefer? *e[32m"
set Mode [Return]
set > NIL: Mode ?
if $Mode eq "N"
  skip PathN
endif
if $Mode eq "R"
  skip PathR
endif
echo "[32m*n You have not selected the correct mode! Please try again...[0m"
wait 4
skip back Start


lab PathN
echo noline "*e[0m*n*N Please enter the PATH where old Drawer-Icons are located: *e[32m"
set > NIL: Path ?
echo noline "*e[0m"
  if > NIL: not exists $Path
    echo " Wrong path, `$path' does not exist! Try again...*n"
    skip back PathN
  endif
echo noline "*n*n Analysing [32m$Path[0m for any old drawers..."
C:LIST > ram:MWB $Path dirs lformat "if exists *"%f%n.info*" *n  C:LIST > ram:Length *"%f%n.info*" nohead nodates *n  search > NIL: ram:Length 1233 *n  if not warn *n  else *n    search > NIL: ram:Length 2625 *n    if not warn *n    else *n      IU > NIL: cwn XEN-Icons/Prefs/Env-Archive/Sys/def_Drawer.info *"%f%n.info*" *n    endif *n  endif *nendif*n"
echo ".....................*e[33mDONE*e[0m"
echo noline " Updating Drawer-Icons in [32m$Path[0m..."
failat 21
execute > NIL: ram:MWB
if warn
  echo " Update has failed!!!"
  skip end
endif
echo "..........................*e[33mDONE*e[0m"
echo "*n*n*e[32m Drawer-Update successfully finished!*e[0m"
skip trash


lab PathR
echo "*e[1;1H*e[J"
echo "*n*n ATTENTION: This recursive mode might need a lot of memory! The amount"
echo " of memory depends on how complex your directory structure is."
echo "*n Example: If your partition has got 400 drawers this installation will"
echo " approximately need 150 KB of memory. That are 300 bytes per directory."
echo noline "*e[0m*N*n*N Please enter the PATH where old Drawer-Icons are located: *e[32m"
set > NIL: Path ?
echo noline "*e[0m"
  if > NIL: not exists $Path
    echo " Wrong path, `$path' does not exist! Try again...*n"
    skip back PathR
  endif
echo noline "*n*n Recursively analysing [32m$Path[0m for any old drawers..."
C:LIST > ram:MWB $Path dirs all lformat "if exists *"%f%n.info*" *n  C:LIST > ram:Length *"%f%n.info*" nohead nodates *n  search > NIL: ram:Length 1233 *n  if not warn *n  else *n    search > NIL: ram:Length 2625 *n    if not warn *n    else *n      IU > NIL: cwn XEN-Icons/Prefs/Env-Archive/Sys/def_Drawer.info *"%f%n.info*" *n    endif *n  endif *nendif*n"
echo "........*e[33mDONE*e[0m"
echo noline "*n Recursively updating Drawer-Icons in [32m$Path[0m..."
failat 21
execute > NIL: ram:MWB
if warn
  echo " Update has failed!!!"
  skip end
endif
echo ".............*e[33mDONE*e[0m"
echo "*n*n*e[32m Drawer-Update successfully finished!*e[0m"


lab trash

cd $path
if exists Trashcan.info
  IU > NIL: cwn Magic:XEN-Icons/Prefs/Env-Archive/Sys/def_trashcan.info Trashcan.info
endif


lab end
resident IU remove
delete > NIL: ram:MWB
delete > NIL: ram:Length
assign Magic: remove
wait 4
quit
