#!/bin/bash
# WineTools was initially written by Frank Hendriksen <frank@franksworld.net>
# and was extended by Joachim von Thadden <thadden@web.de>. It is not nice
# and looks like horror. But it works!
# 
# It is licensed under the GPL.
# 
# Send comments, bugreports, etc. to thadden@web.de"

# base definitions
BASEDIR="/usr/lib/winetools"
DIALOG="/usr/bin/Xdialog"
WINEDIR="`echo ~/.wine`"
CONFIG="$WINEDIR/winetools.log"
SYSDIR="$HOME/winetools"
INIWAIT="600"
WAIT=$INIWAIT
CDROM="`ls -l $HOME/.wine/dosdevices/|grep \" d: -> \"| sed -e \"s/^.* d: -> \(.*\)$/\1/\"`"


init()
{
  unset WINEDLLOVERRIDES
  installer=""
  testname=""
  script=""
  winever=""
  dlsize=""
  dload=""
}


mount_cd()
{
  $DIALOG --title "*** NOTE ***" \
	--yesno "For this software you need a mounted CD.\nShall I mount it for you?" 7 60
  if [ "$?" = "0" ]; then
    mount "$CDROM"
    [ "$?" != "0" ] && $DIALOG --title "*** ERROR ***" \
        --no-cancel \
        --msgbox "Mounting of the CD failed. You should do it manually." 7 60
    mounted="true"
  fi
}


umount_cd()
{
  if [ "$mounted" = "true" ]; then
    $DIALOG --title "*** NOTE ***" \
	--yesno "Shall I unmount the CD for you?" 7 60
    if [ "$?" = "0" ]; then
      umount "$CDROM"
      [ "$?" != "0" ] && $DIALOG --title "*** ERROR ***" \
        --no-cancel \
        --msgbox "Unmounting of the CD failed. You should do it manually." 7 60
    fi
  fi
}


wineboot()
{
  waitforwineexit
  $DIALOG  --title "--- NOTICE ---" --no-buttons --infobox "Simulating a Windows reboot. Please wait..." 7 60
  $WINE wineboot
}


waitforwineexit()
{
      n=0
      wdbcount="0"
      echo "waiting for wineservers to exit..."
      $DIALOG  --title "--- NOTICE ---" --no-buttons --infobox "Waiting $WAIT seconds for wineservers to exit...\nPlease wait..." 7 60
#      while [ "$n" != "$WAIT" ]; do
      while [ true ]; do
        ps axwww|grep wineserver|grep -v "grep wineserver" &>/dev/null
	[ "$?" != "0" ] && break
	ps axwww|grep winedbg|grep -v "grep winedbg" &>/dev/null
	if [ "$?" = "0" ]; then
	  if [ "$wdbcount" = "3" ]; then
	    $DIALOG --title "wine status" \
	      --no-cancel \
	      --msgbox "The wine debugger was startet. If your installation does not continue\nfor a while you should switch to the console where you started winetools\nfrom to debug or just type quit and continue here.\nSometimes you don't have to do anything to continue." 9 70
            $DIALOG  --title "--- NOTICE ---" --no-buttons --infobox "Waiting $WAIT seconds for wineservers to exit...\nPlease wait..." 7 60
	  else
	    wdbcount=$(($wdbcount+1))
	  fi
	else
	  wdbcount="0"
	fi
	n=$(($n+1))
	sleep 1s
        if [ "$n" = "$WAIT" ]; then
          $DIALOG --title "wine status" --no-cancel \
	    --msgbox "There is still a wineserver running after $n seconds waiting.\n
On slow computers or while downloading files this need not mean\n
anything. If you think Wine hangs, you may consider killing it\n
on the console by typing \"wineserver -kill\"." 9 60
	  n=0
        fi
      done
      if [ "$n" = "$WAIT" ]; then
        $DIALOG --title "wine status" --no-cancel \
	  --msgbox "There is still a wineserver running after $n seconds waiting.\nOn slow computers or while downloading files this need not mean\nanything. If you think Wine hangs, you may consider killing it." 7 60
      else
        echo "all wineservers endet after $n seconds..."
      fi
}


#########################
### Create fake drive ###
#########################
function createdrive()
{
WAIT=10
waitforwineexit
WAIT=$INIWAIT
if [ -d ${HOME}/.wine ]; then
$DIALOG --title "WineTools" \
        --yesno "Remove existing Wine configuration?" 7 60
case $? in
  1)
    return
    ;;
esac
fi

cdrommount="`grep -e "cdrom" -e "dvd" /etc/fstab`"	#|cut -d\  -f 1|paste -s|sed -e "s/	/,/"`"
[ "$cdrommount" = "" ] && cdrommount="/mnt/cdrom"
$DIALOG --title "Create Fake Windows Drive" \
	--inputbox "What's the mount point of the cdrom/dvd drive?\n\n
Your /etc/fstab says:\n$cdrommount" 600x300 "`echo "$cdrommount"|cut -d\  -f 1|head -1`" 2> /tmp/cdrom.tmp.$$

retval=$?

cdrommount=`cat /tmp/cdrom.tmp.$$`
rm -f /tmp/cdrom.tmp.$$
[ "$cdrommount" = "" ] && cdrommount="/dev/cdrom"

case $retval in
  0)

if [ "$1" = "--old" ]; then
  $DIALOG --title "Create Fake Windows Drive" \
        --inputbox "What's the device name of the cdrom/dvd drive?\n
e.g. /dev/cdrom:" 300x200 "/dev/cdrom" 2> /tmp/cdrom.tmp.$$

  retval=$?

  cdromdevice=`cat /tmp/cdrom.tmp.$$`
  rm -f /tmp/cdrom.tmp.$$
  [ "$cdromdevice" = "" ] && cdromdevice="/dev/cdrom"
else
  retval=0
fi
  case $retval in
    0)

cd ~/ 
rm -Rf .wine
wine

cp $BASEDIR/scripts/dos "$HOME/bin"
cp $BASEDIR/scripts/uninstall "$HOME/bin"
if [ "$1" = "--old" ]; then
  cp $BASEDIR/config.old ~/.wine/config.1
  ln -s ~/.wine/c ~/.wine/drive_c
  sed -e "scdrommount${cdrommount}g" -e "scdromdevice${cdromdevice}g" ~/.wine/config.1 > ~/.wine/config
  rm -f ~/.wine/config.1
  echo "*old* fake Windows drive created at `date \"+%d.%m.%Y %H:%M:%S\"`" >>$CONFIG
else
  cp $BASEDIR/config.new ~/.wine/config
  ln -s ~/.wine/drive_c ~/.wine/c
  ln -s ${cdrommount} ~/.wine/dosdevices/d:
  ln -s /tmp ~/.wine/dosdevices/e:
  ln -s $SYSDIR ~/.wine/dosdevices/f:
  ln -s $HOME ~/.wine/dosdevices/h:
  ln -s /tmp ~/.wine/dosdevices/t:
  echo "*new* fake Windows drive created at `date \"+%d.%m.%Y %H:%M:%S\"`" >>$CONFIG
fi
touch "$WINEDIR/c/config.sys"
touch "$WINEDIR/c/autoexec.bat"
ln -s "$HOME/.wine/c/Program Files" "$HOME/.wine/drive_c/Programme"
ln -s /tmp "$HOME/.wine/c/tmp"
ln -s /tmp "$HOME/.wine/c/temp"

CDROM="`ls -l $HOME/.wine/dosdevices/|grep \" d: -> \"| sed -e \"s/^.* d: -> \(.*\)$/\1/\"`"

$DIALOG --title "Create Fake Windows Drive" \
	--no-cancel \
	--msgbox "Fake Windows drive created in ~/.wine." 7 60

esac
;;
esac
}


add_printcap_printers()
{
  PRINTERS="`cat /etc/printcap|grep -v \"^.*:.*:\\\\\*$\"|grep -v \"^#\"|sed -e \"s/\(.*\):\\\\\/\1/\"`"
  echo $PRINTERS
  grep -i "^\[ppd\]$" ~/.wine/config &>/dev/null
  if [ "$?" = "0" ]; then
    $DIALOG --title "Add printcap printers" \
	--no-cancel \
	--msgbox "You already have printers defined in your config. Please edit this manually." 7 80
  else
    $DIALOG --title "Add printcap printers" \
	--inputbox "What's the path to your ppd-file?\n
e.g. /usr/share/wine/generic.ppd" 300x200 "/usr/share/wine/generic.ppd" 2> /tmp/ppd.tmp.$$

    retval=$?

    ppdpath=`cat /tmp/ppd.tmp.$$`
    rm -f /tmp/ppd.tmp.$$
    [ "$ppdpath" = "" ] && ppdpath="/usr/share/wine/generic.ppd"

    case $retval in
      0)
         echo -e "\n[ppd]" >> ~/.wine/config
         num=0
         for n in $PRINTERS; do
           echo "\"$n\" = \"/usr/share/wine/generic.ppd\"" >> ~/.wine/config
           num=$(($num+1))
         done
         echo -e "; [ppd] end of section\n" >> ~/.wine/config

         wineboot
         $DIALOG --title "Add printcap printers" \
	    --no-cancel \
	    --msgbox "$num printers added to your config." 7 60
	 ;;
    esac
  fi
}


##################
### Fonts menu ###
##################
function fonts()
{
init
$DIALOG --title "TrueType Fonts" \
	--cancel-label "Main menu" \
	--icon $BASEDIR/icon/font.xpm \
        --menu "" 400x300 0 \
        "Andale" "" \
        "Arial" "" \
        "Arial Black" "" \
        "Comic Sans" "" \
        "Courier New"  "" \
        "Georgia"  "" \
	"Impact"  "" \
	"Times New Roman"  "" \
	"Trebuchet"  "" \
	"Verdana"  "" \
	"Webdings"  "" 2> /tmp/menu.tmp.$$
	
retval=$?

choice=`cat /tmp/menu.tmp.$$`
rm -f /tmp/menu.tmp.$$

case $retval in
0)

case $choice in
Andale)
fontname="andale32.exe"
dlsize=198384
fontsinstall
fonts
;;

Arial)
fontname="arial32.exe"
dlsize="554208"
fontsinstall
fonts
;;

"Arial Black")
fontname="arialb32.exe"
dlsize="168176"
fontsinstall
fonts
;;

"Comic Sans")
fontname="comic32.exe"
dlsize="246008"
fontsinstall
fonts
;;

"Courier New")
fontname="courie32.exe"
dlsize="646368"
fontsinstall
fonts
;;

Georgia)
fontname="georgi32.exe"
dlsize="392440"
fontsinstall
fonts
;;

Impact)
fontname="impact32.exe"
dlsize="173288"
fontsinstall
fonts
;;

"Times New Roman")
fontname="times32.exe"
dlsize="661728"
fontsinstall
fonts
;;

Trebuchet)
fontname="trebuc32.exe"
dlsize="357200"
fontsinstall
fonts
;;

Verdana)
fontname="verdan32.exe"
dlsize="351992"
fontsinstall
fonts
;;

Webdings)
fontname="webdin32.exe"
dlsize="185072"
fontsinstall
fonts
esac
;;
1)
    mainmenu
;;
esac
}

##############################
### Fonts download/install ###
##############################
function fontsinstall()
{
cd $SYSDIR/fonts

dload="http://umn.dl.sourceforge.net/sourceforge/corefonts/${fontname}"
sysname="${fontname}"
realinstall "" "--nofail"
}


#########################################
### Install system software and files ###
#########################################
function testsw()
{
    echo "$1"
    # test via registry
    regedit /e ~/.wine/installed.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    grep "\"DisplayName\"=" ~/.wine/installed.reg | sed -e "s/.*=\"\(.*\)\".*/\1/g"|sort > $HOME/.wine/installed-software
    grep "QuietDisplayName\"=" ~/.wine/installed.reg | sed -e "s/.*=\"\(.*\)\".*/\1/g"|sort > $HOME/.wine/quiet-installed-software
    rm ~/.wine/installed.reg
    grep "^$1$" ~/.wine/installed-software
    if [ "$?" = "0" ]; then
      echo "software installation verified by registry value"
    else
      grep "^$1$" ~/.wine/quiet-installed-software
      if [ "$?" = "0" ]; then
        echo "software installation verified by quiet registry value"
      else
#        # test via path
#        testfile=`winepath -u "$1"`
#        if [ -s "$testfile" ]; then
#          echo "software installation verified by path"
#        else
          # test via logfile
	  echo "software installation verified by $CONFIG"
	  grep "^$1 = installed at " $CONFIG
#        fi
      fi
    fi
}


function needsw()
{
  testsw "$1"
  if [ "$?" != "0" ]; then
    echo "dependency "$1" *not* fulfilled"
    $DIALOG  --title "--- ERROR ---" --defaultno --yesno "This software depends on $1.\nYour config file states that you have not installed $1 yet.\nIn that case you will\nnot be able to install the desired software. Continue anyway?" 9 60
    if [ "$?" = "0" ]; then
      # continue anyway
      return 0
    else
      # abort
      return 1
    fi
  else
    echo "dependency "$1" fulfilled"
  fi
  # continue
  return 0
}


function mustnotsw()
{
  testsw "$1"
  if [ "$?" = "0" ]; then
    $DIALOG  --title "--- ERROR ---" --defaultno --yesno "Your config file states that you have already installed $1.\nIn that case the installation\nof your desired software will fail! Continue anyway?" 7 60
    if [ "$?" = "0" ]; then
      # continue anyway
      return 0
    else
      # abort
      return 1
    fi
  fi
  # continue
  return 0
}


function sysinstallsw()
{
  cd $SYSDIR/sys
  $DIALOG  --title "Download File" --yesno "If you downloaded the file by yourself (e.g. in a different language)\nyou can use this one instead of the default.\nDo you want to use the default?" 10 60
  if [ "$?" = "0" ]; then
    realinstall "$1" "$2"
    failed="$?"
  else
    $DIALOG  --title "Select File" --fselect "~/.wine/c/" 50 70 2>/tmp/file.tmp.$$
    if [ "$?" = "0" ]; then
      sysname="`cat /tmp/file.tmp.$$`"
      cp "$sysname" "$SYSDIR/user"
      sysname="$SYSDIR/user/`basename \"$sysname\"`"
      installer="$WINE $sysname"
      dload="none"
      dlsize="selected"
      realinstall "$1" "$2"
      failed="$?"
    fi
    rm /tmp/file.tmp.$$
  fi
  echo "Failed: $failed"
  return "$failed"
}

function sysinstall()
{
cd $SYSDIR/sys
realinstall "$1" "$2"
}

function realinstall()
{
if [ "$testname" = "" ]; then
  testsw "$sysname"
else
  testsw "$testname"
fi
if [ "$?" = "0" ]; then
  $DIALOG  --title "Software Exists" --yesno "The config file says the software you want\nto install is already installed. Continue?" 7 60
  if [ "$?" != "0" ]; then
    return "99"
  fi
fi

if [ "$dload" = "none" ]; then
  [ "$dlsize" = "" ] && mount_cd
else
  PROGRESS="`ls -l "$sysname" |sed -e \"s/\ \+/,/g\"|cut -d\, -f5`"
  realdownload=1
  echo "$PROGRESS"

  if [ "$PROGRESS" = "$dlsize" ]; then
#    $DIALOG  --title "Download File Exists" --yesno "The required download file already exists. Do you want to use this one?" 7 60
#    if [ "$?" = "0" ]; then
      realdownload=0
#    else
#      realdownload=1
#    fi
  fi

  if [ "$realdownload" = "1" ]; then
    echo "downloading $dload to $sysname with $dlsize bytes..."
    PROGRESS="0"
    > $sysname
    {
      wget "$dload" -O "$sysname" 2>wget.errors &
      echo 0
      while [ "$PROGRESS" != "$dlsize" ]
      do
        PROGRESS="`ls -l "$sysname" |sed -e \"s/\ \+/,/g\"|cut -d\, -f5`"
        echo $[PROGRESS*100/dlsize] 
        sleep 1s
      done
      echo 100
    }  | $DIALOG  --title "Downloading" --gauge "Downloading..." 7 60 0
  fi

fi

#[ "$installer" = "" ] && installer="$WINE ./$sysname"
#echo "WINEDLLOVERRIDES=\"$WINEDLLOVERRIDES\" $installer"
#$installer
      [ -e "$HOME/.wine/dosdevices/z:" ] && mv "$HOME/.wine/dosdevices/z:" "$HOME/.wine/dosdevices/.z:"
      if [ "$installer" = "" ]; then
        {
	  echo "WINEDLLOVERRIDES=\"$WINEDLLOVERRIDES\" $WINE ./$sysname"
	  WINEDLLOVERRIDES="$WINEDLLOVERRIDES" $WINE ./$sysname
	  echo "$?" >/tmp/wineinstall.$$.tmp
        } &
      else
        {
	  echo "WINEDLLOVERRIDES=\"$WINEDLLOVERRIDES\" $installer"
	  WINEDLLOVERRIDES="$WINEDLLOVERRIDES" $installer
	  echo "$?" >/tmp/wineinstall.$$.tmp
	} &
      fi
      waitforwineexit
      failed="`cat /tmp/wineinstall.$$.tmp`"
      echo "Failed: $failed"
      [ "$2" = "--nofail" ] && failed="0"
      [ -e "$HOME/.wine/dosdevices/.z:" ] && mv "$HOME/.wine/dosdevices/.z:" "$HOME/.wine/dosdevices/z:"

if [ "$testname" = "" ]; then
  echo "check installation by return value..."
  [ "$failed" = "0" ] && echo "$sysname = installed at `date \"+%d.%m.%Y %H:%M:%S\"`" >>$CONFIG
  [ "$failed" = "1" ] && echo "$sysname = installation failed at `date \"+%d.%m.%Y %H:%M:%S\"`" >>$CONFIG
else
  echo "check installation by path or registry value..."
  waitforwineexit
  testsw "$testname"
  failed="$?"
  [ "$failed" = "0" ] && echo "$testname = installed at `date \"+%d.%m.%Y %H:%M:%S\"`" >>$CONFIG
  [ "$failed" = "1" ] && echo "$testname = installation failed at `date \"+%d.%m.%Y %H:%M:%S\"`" >>$CONFIG
fi

[ "$1" = "--noboot" ] || wineboot

echo "Failed: $failed"

if [ "$failed" != "0" ]; then
  $DIALOG --title "wine status" \
          --no-cancel \
          --msgbox "It seems that the installation has failed." 7 70
else
  if [ "$script" != "" ]; then
    for n in $script; do
      cp -a "$BASEDIR/scripts/$n" "$HOME/bin"
    done
    $DIALOG  --title "--- NOTICE ---" --msgbox "To start the installed software WineTools has copied\nthe following start scripts to your ~/bin directory:\n\n$script" 12 60
  fi
fi

if [ "$dload" = "none" ]; then
  umount_cd
fi

return $failed
}

#########################
###  System Software  ###
#########################
function systemmenu()
{
init
$DIALOG --title "System Software" \
	--cancel-label "Main menu" \
	--icon $BASEDIR/icon/computer.xpm \
        --menu "" 400x300 0 \
        "HTML Help Update Package" "" \
	"Visual Basic 5 Runtime" "" \
        "Visual Basic 6 Runtime" "" \
        "Visual C++ run-time German" "" \
        "Visual C++ run-time English" "" \
        "Windows Installer"  "" \
        "Windows Script 5.6"  "" \
	"Common Controls 5.0" "" 2> /tmp/menu.tmp.$$

retval=$?

choice=`cat /tmp/menu.tmp.$$`
rm -f /tmp/menu.tmp.$$

case $retval in
0)

case "$choice" in
"HTML Help Update Package")
dload="http://go.microsoft.com/fwlink/?LinkId=14498"
dlsize="752944"
sysname="HHUPD.EXE"
sysinstall
systemmenu
;;
"Common Controls 5.0")
dload="http://download.microsoft.com/download/platformsdk/Comctl32/5.80.2614.3600/W9XNT4/EN-US/50comupd.exe"
sysname="50comupd.exe"
dlsize="509984"
sysinstall
systemmenu
;;
"Visual C++ run-time German")
dload="http://download.microsoft.com/download/vc60pro/update/2/w9xnt4/en-us/vc6redistsetup_deu.exe"
sysname="vc6redistsetup_deu.exe"
installer="$WINE vc6redistsetup_deu.exe /T:f:\\sys"
dlsize="1837888"
sysinstall
dload="none"
sysname="vcredist.exe"
installer=""
dlsize="none"
sysinstall
systemmenu
;;
"Visual C++ run-time English")
dload="http://download.microsoft.com/download/vc60pro/update/1/w9xnt4/en-us/vc6redistsetup_enu.exe"
sysname="vc6redistsetup_enu.exe"
installer="$WINE vc6redistsetup_enu.exe /T:f:\\sys"
dlsize="1833232"
sysinstall
dload="none"
sysname="vcredist.exe"
installer=""
dlsize="none"
sysinstall
systemmenu
;;
"Visual Basic 5 Runtime")
dload="http://download.microsoft.com/download/vb50pro/utility/1/win98/EN-US/Msvbvm50.exe"
sysname="Msvbm50.exe"
dlsize="992864"
sysinstall
systemmenu
;;
"Visual Basic 6 Runtime")
dload="http://download.microsoft.com/download/vb60pro/install/6/Win98Me/EN-US/VBRun60.exe"
sysname="VBRun60.exe"
dlsize="1067688"
sysinstall
systemmenu
;;
"Windows Installer")
  $DIALOG  --title "--- WARNING ---" --defaultno --yesno "Also it is a good idea to install the Windows Installer\nit could be that some installer based installations will fail afterwards.\nContinue anyway?" 7 60
  if [ "$?" = "0" ]; then
    dload="http://download.microsoft.com/download/WindowsInstaller/Install/2.0/W9XMe/EN-US/InstMsiA.exe"
    sysname="InstMsiA.exe"
    dlsize="1709160"
    sysinstall
  fi
  systemmenu
;;
"Windows Script 5.6")
dload="http://download.microsoft.com/download/winscript56/Install/5.6/W9XNT4Me/EN-US/scr56en.exe"
sysname="scr56en.exe"
dlsize="732768"
sysinstall
systemmenu
;;
esac
;;

1)
    mainmenu
;;
esac
}


#########################
###     Base Setup    ###
#########################
systemsoftware()
{
init
$DIALOG --title "Base Setup" \
	--cancel-label "Main menu" \
	--icon $BASEDIR/icon/computer.xpm \
        --menu "" 400x400 0 \
	" --- New Setup (past April 2004) --- " "" \
	"Create a fake Windows drive" "" \
	"TrueType Font Arial" "" \
        "DCOM98" "" \
	"Internet Explorer 6.0 SP1 English" "" \
	"Internet Explorer 6.0 SP1 German" "" \
	"Add printcap (non CUPS) printers" "" 2> /tmp/menu.tmp.$$
	
#	" " "" \
#	" --- Old Setup (prev. April 2004) --- " "" \
#	" ---   Not supported any longer   --- " "" \
#	"Create a fake Windows drive for wine-20031212" "" \
#	"TrueType Font Arial" "" \
#        "DCOM98" "" \
#	"Internet Explorer 6.0 SP1 (Frank's method 1, english)" "" \
#	"Internet Explorer 6.0 SP1 (Frank's method 3)" "" \
#	"Windows Media Player 6.4" "" \
#	"Add printcap (non CUPS) printers" "" 2> /tmp/menu.tmp.$$

retval=$?

choice=`cat /tmp/menu.tmp.$$`
rm -f /tmp/menu.tmp.$$

case $retval in
0)

echo "Choice is $choice"
case "$choice" in
"Create a fake Windows drive for wine-20031212")  
  $DIALOG  --title "--- WARNING ---" --defaultno --yesno "Note that the old method is not fully supported any more and installations may fail. Continue anyway?" 7 60
  if [ "$?" = "0" ]; then
    createdrive --old
  fi
  systemsoftware
;;
"Create a fake Windows drive")
  createdrive --new
  systemsoftware
;;
"TrueType Font Arial")
fontname="arial32.exe"
dlsize="554208"
fontsinstall
systemsoftware
;;
"DCOM98")
#  $DIALOG  --title "--- WARNING ---" --defaultno --yesno "If you install dcom98 previous to IE6 (method 1) the installation\nof IE6 may fail. Continue anyway?" 7 60
#  if [ "$?" = "0" ]; then
    dload="http://download.microsoft.com/download/d/1/3/d13cd456-f0cf-4fb2-a17f-20afc79f8a51/DCOM98.EXE"
    dlsize="1229056"
    sysname="dcom98.exe"
    export WINEDLLOVERRIDES="ole32=n"
    sysinstall
#  fi
  systemsoftware
;;
"Internet Explorer 6.0 SP1 German"|"Internet Explorer 6.0 SP1 English")
needsw dcom98.exe
if [ "$?" = "0" ]; then
  if [ -s "$WINEDIR/installed-software" ] || [ -s "$WINEDIR/quiet-installed-software" ]; then
    $DIALOG  --title "--- WARNING ---" --defaultno --yesno "You already installed software!!!\n\nAfter the installation of IE6 your system.reg will be replaced!\nYou will loose all registry keys of installed programs (except for DCOM98)!\nThis could mean that these already installed programs have to\nbe reinstalled or repaired after the installation of IE6.\n\nContinue anyway?" 14 70
  fi
#  $DIALOG  --title "--- WARNING ---" --defaultno --yesno "After the installation your system.reg will be replaced!\nYou will loose all registry keys of installed programs (except for DCOM98)!\nDuring install you have to select customized setup and check\neverything except for VML, additional Web Fonts and all foreign languages.\nYou can add additional components later by using the uninstaller.\nContinue anyway?" 12 70
  if [ "$?" = "0" ]; then
    $DIALOG  --title "--- HINT ---" --msgbox "This is a full automatic installation of almost all\ncomponents of IE6 and Media Player 6.4.\nYou can add additional components\nlater by using the uninstaller." 11 70
    mv ~/.wine/config ~/.wine/config.$$
    cp $BASEDIR/config.ie6 ~/.wine/config
    cp $BASEDIR/iebatch.txt $SYSDIR/sys
    if [ "$choice" = "Internet Explorer 6.0 SP1 German" ]; then
      echo "using german setup..."
      setupdir="Windows Update Setup-Dateien"
      dload="http://download.microsoft.com/download/ie6sp1/finrel/6_sp1/W98NT42KMeXP/DE/ie6setup.exe"
      dlsize="496888"
    elif [ "$choice" = "Internet Explorer 6.0 SP1 English" ]; then
      echo "using english setup..."
      setupdir="Windows Update Setup Files"
      dload="http://download.microsoft.com/download/ie6sp1/finrel/6_sp1/W98NT42KMeXP/EN-US/ie6setup.exe"
      dlsize="491768"
    fi
    if [ -s "$SYSDIR/sys/${setupdir}" ] && [ ! -e "$HOME/.wine/c/windows/${setupdir}" ]; then
      cp -a "$SYSDIR/sys/${setupdir}" ~/.wine/c/windows
    fi
    sysname="ie6setup.exe"
    testname="Microsoft Internet Explorer 6 SP1 .*"
    script="ie6 outlookexpress wmplayer"
    WINEDLLOVERRIDES="advpack=n, wininet=n, ole32=n"
    sysinstallsw "--noboot"
    failed="$?"
    echo "Failed: $failed"
    mv -f ~/.wine/config.$$ ~/.wine/config
    if [ "$failed" = "0" ]; then
      echo "installing new registry..."
      waitforwineexit
      mv ~/.wine/system.reg ~/.wine/system.reg.last
      cp $BASEDIR/system.reg ~/.wine/system.reg
      wineboot
      regedit $BASEDIR/ie6-icw.reg
      wineboot
      $DIALOG --title "Hint" \
	--no-cancel \
	--msgbox "If your start IE6 for the first time\nthe internet wizzard will be startet.\nCancel it!" 7 60
    fi
    sizewt="`du -s \"$SYSDIR/sys/${setupdir}\"|cut -d\	 -f1`"
    sizewine="`du -s \"$HOME/.wine/c/windows/${setupdir}\"|cut -d\	 -f1`"
    [ "$sizewt" = "" ] && sizewt=0
    [ "$sizewine" = "" ] && sizewine=0
    echo "Downloaded IE6-Files=$sizewine"
    echo "Winetools  IE6-Files=$sizewt"
    if [ $sizewt -lt $sizewine ]; then
      $DIALOG  --title "--- Copy downloaded files ---" --defaultno --yesno "Do you want to save the downloaded files for later?" 7 60
      if [ "$?" = "0" ]; then
        cp -a "$HOME/.wine/c/windows/${setupdir}" "$SYSDIR/sys"
      fi
    fi
  fi
fi
systemsoftware
;;
"Internet Explorer 6.0 SP1 (Frank's method 1, english)")
mustnotsw dcom98.exe
if [ "$?" = "0" ]; then
  dload="http://bylands.dur.ac.uk/~mh/wine-ie/install-ie6.sh"
  sysname="install-ie6.sh"
  dlsize="652348"
  installer="sh ./$sysname"
  sysinstall
  [ "$?" = "0" ] && $DIALOG  --title "--- NOTICE ---" --msgbox "Note that you have to install dcom98 now for IE6 to work." 7 60
fi
systemsoftware
;;
"Internet Explorer 6.0 SP1 (Frank's method 3)")
needsw dcom98.exe
if [ "$?" = "0" ]; then
#  $DIALOG  --title "--- WARNING ---" --defaultno --yesno "For this installation method your wine config will be replaced\! Continue anyway?" 7 80
  if [ "$?" = "0" ]; then
#    cp $BASEDIR/config.old ~/.wine/config
    dload="http://download.microsoft.com/download/ie6sp1/finrel/6_sp1/W98NT42KMeXP/DE/ie6setup.exe"
    dlsize="496888"
    sysname="ie6setup.exe"
    sysinstallsw
  fi
fi
systemsoftware
;;
"Windows Media Player 6.4")
dload="http://download.microsoft.com/download/winmediaplayer/Update/6.4/W9XNT4/EN-US/mpfull.exe"
sysname="mpfull.exe"
dlsize="3596784"
testname="Microsoft Windows Media Player 6.4"
sysinstallsw
sleep 1
systemsoftware
;;
"Add printcap (non CUPS) printers")
  grep "This file was automatically generated by cupsd" /etc/printcap &>/dev/null
  if [ "$?" = "0" ]; then
    $DIALOG  --title "--- NOTICE ---" --msgbox "WineTools detected that you use CUPS on your system.\nAs Wine works perfecly together with CUPS, nothing\nhas to be done for using printers in Windows programs." 8 60
  else
    add_printcap_printers
  fi
  systemsoftware
;;
*)
  systemsoftware
;;
esac
;;

1)
    mainmenu
;;
esac
}


#########################
###  Additional Soft  ###
#########################
additionalsoftware()
{
init
$DIALOG --title "Additional Software" \
	--cancel-label "Main menu" \
	--icon $BASEDIR/icon/apps.xpm \
        --menu "" 400x800 0 \
	" --- Office --- " "" \
	"(Lotus Notes 6.5.1)" "" \
	"Microsoft Office 95" "" \
	"Microsoft Office 97" "" \
	"Microsoft Office 2000" "" \
	"Word Viewer 97" "" \
	"Excel Viewer 97" "" \
	"Powerpoint Viewer 97" "" \
	"Powerpoint Viewer 2003" "" \
	" " "" \
	" --- Business --- " "" \
	"(Agenda 2004/2005 Client German)" "" \
	" " "" \
	" --- Edutainment ---" "" \
	"Encarta 99" "" \
	" " "" \
	" --- Games --- " "" \
	"give me input and I playce them here!" "" \
	" " "" \
	" --- Graphics --- " "" \
	"Adobe Photoshop 7.0" "" \
	"Adobe Illustrator 9.0" "" \
	"IrfanView 3.95" "" \
	"Typograf 4 Fontmanagement German" "" \
	"Typograf 4 Fontmanagement English" "" \
	"VirtualDub 1.6.1" "" \
	" " "" \
	" --- Player --- " "" \
	"Acrobat Reader 5.1" "" \
	"Macromedia Flash Player Plugin for IE6" "" \
	"Macromedia Shockwave Player Plugin for IE6" "" \
	"QuickTime Player 6.5.2" "" \
	"QuickTime Player 5.0" "" \
	" " "" \
	" --- File Tools --- " "" \
	"Total Commander 6.03a" "" \
	"WinZip 9.0" "" \
	"WinRAR 3.41" "" \
	" " "" \
	" --- eBay --- " "" \
	"Lauge 1.88 German" "" \
	" " "" \
	" --- Communication --- " "" \
	"Eudora 6.2" "" \
	"The Bat! 3.01 Professional" "" \
	"Fort Agent Newsreader 2.0" "" \
	"mIRC 6.16" "" \
	"putty 0.56" "" \
	"DC++" "" \
	" " "" \
	" --- Database --- " "" \
	"PostgreSQL ODBC driver psqlODBC 7.03.0200" "" \
	"DBCrab 1.50 German with BDE 5.1.1 German" "" \
	"Borland Database Engine (BDE) 5.1.1 English" "" \
	" " "" \
	" --- Tools --- " "" \
	"Dependency Walker" "" \
	"Splash Screen Killer" "" 2> /tmp/menu.tmp.$$

retval=$?

choice=`cat /tmp/menu.tmp.$$`
rm -f /tmp/menu.tmp.$$

case $retval in
0)

case "$choice" in
"Splash Screen Killer")
    mkdir "$HOME/.wine/c/Programme/SplashKiller"
    dload="http://www.digitallis.co.uk/pc/downloads/SplashKiller.zip"
    dlsize="32224"
    sysname="SplashKiller.zip"
    installer="unzip -o SplashKiller.zip -d $HOME/.wine/c/Programme/SplashKiller"
    script="splashkiller"
    sysinstall
    additionalsoftware
;;
"Microsoft Office 95"|"Microsoft Office 97"|"Microsoft Office 2000")
    if [ "$choice" = "Microsoft Office 2000" ]; then
      needsw "SplashKiller.zip"
      $DIALOG --title "Hint" \
	      --no-cancel \
	      --msgbox "If you are asked for, select drive D: for installation.\nNever install Office-Tools/Office-Assistents.\nThey might shredder your setup." 9 60
      script="winword excel access powerpoint outlook outlook.executor finder msquery sammelmappe"
    fi
    dload="none"
    dlsize=""
    sysname="$choice"
    installer="$WINE d:\\setup.exe"
    if [ "$choice" = "Microsoft Office 95" ]; then
      testname="Microsoft Office.*"
    else
      testname="${choice}.*"
    fi
    sysinstallsw
    if [ "$failed" = "0" ]; then
      $DIALOG --title "Hint" \
              --no-cancel \
              --msgbox "During the first start of Outlook you should not decide\nto install Symnatec Fax because it does no work." 9 60
    fi
    additionalsoftware
;;
"Macromedia Flash Player Plugin for IE6")
$DIALOG --title "Hint" \
	--no-cancel \
	--msgbox "Starting IE6.\nIf this is the first time you start IE6the internet wizzard will be startet.\nCancel it!" 7 60
  $WINE c:\\Program\ Files\\Internet\ Explorer\\IEXPLORE.EXE "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"
  wineboot
  testsw "Shockwave Flash"
  [ "$?" != "0" ] && $DIALOG --title "wine status" \
		             --no-cancel \
			     --msgbox "It seems that the installation has failed." 7 70
  additionalsoftware
;;
"Macromedia Shockwave Player Plugin for IE6")
$DIALOG --title "Hint" \
	--no-cancel \
	--msgbox "Starting IE6.\nIf this is the first time you start IE6 the internet wizzard will be startet.\nCancel it!\nAnd do not install the Yahoo! Toolbar!\nNote that IE6 will slow extremely down while playing Shockwave files." 7 60
  $WINE c:\\Program\ Files\\Internet\ Explorer\\IEXPLORE.EXE "http://sdc.shockwave.com/shockwave/download/download.cgi?"
  wineboot
  testsw "Macromedia Shockwave Player"
  [ "$?" != "0" ] && $DIALOG --title "wine status" \
		             --no-cancel \
			     --msgbox "It seems that the installation has failed." 7 70
  additionalsoftware
;;
"Word Viewer 97")
    dload="http://download.microsoft.com/download/word97win/wd97vwr/97/WIN98/DE/wd97vwr32.exe"
    dlsize="4364456"
    sysname="wd97vwr32.exe"
    testname="Microsoft Word Viewer 97"
    script="winword wordview97"
    sysinstallsw
    additionalsoftware
;;
"Excel Viewer 97")
    dload="http://download.microsoft.com/download/excel2000/Xlviewer/2000/WIN98/EN-US/xlViewer.exe"
    dlsize="3905464"
    sysname="xlViewer.exe"
    testname="Microsoft Excel Viewer 97"
    script="excel excelview97"
    sysinstallsw
    additionalsoftware
;;
"Powerpoint Viewer 97")
    dload="http://download.microsoft.com/download/c/2/f/c2fd9ca4-4505-453b-84b6-5839b7baffd3/PPView97.exe"
    dlsize="2855552"
    sysname="PPView97.exe"
    testname="Microsoft PowerPoint Viewer 97"
    script="powerpoint ppointview97"
    sysinstallsw
    additionalsoftware
;;
"Powerpoint Viewer 2003")
    dload="http://download.microsoft.com/download/f/e/2/fe23f2ca-19b8-4d4b-8275-35ec02699c8f/ppviewer.exe"
    dlsize="1949896"
    sysname="ppviewer.exe"
    testname="Microsoft Office PowerPoint Viewer 2003"
    script="powerpoint ppointview2003"
    sysinstallsw
    additionalsoftware
;;
"Visio Viewer 2002")
    dload="http://download.microsoft.com/download/b/d/2/bd274b57-b97a-4fa1-a320-54bbe658e8ac/vviewer.exe"
    dlsize="3845840"
    sysname="vviewer.exe"
    testname="Microsoft Visio Viewer 2002"
    script="visio visioview2002"
    sysinstallsw
    additionalsoftware
;;
"Encarta 99")
    dload="none"
    dlsize=""
    sysname=""
    installer="$WINE d:\\setup.exe"
    testname="Microsoft Encarta 99.*"
    script="encarta"
    sysinstallsw
    additionalsoftware
;;
"Acrobat Reader 5.1")
    dload="http://ardownload.adobe.com/pub/adobe/acrobatreader/win/5.x/5.1/AcroReader51_ENU.exe"
    dlsize="8839120"
    sysname="AcroReader51_ENU.exe"
    testname="Adobe Acrobat 5.0"
    script="acro5"
    sysinstallsw
    additionalsoftware
;;
"Lauge 1.88 German")
    dload="http://www.lauge.de/public/lauge188_setup.exe"
    dlsize="1285510"
    sysname="lauge188_setup.exe"
    testname="Lauge 1.88"
    script="lauge"
    sysinstall
    cp "$BASEDIR/lauge-prefs.ini" "$WINEDIR/c/Program Files/Lauge/prefs.ini"
    additionalsoftware
;;
"VirtualDub 1.6.1")
    $DIALOG --title "Hint" \
	    --no-cancel \
	    --msgbox "During the first start go to Options-Preferences-Display and disable\nDirectX to prevent VD to mess up your display." 7 60
    mkdir "$HOME/.wine/c/Programme/VirtualDub"
    dload="http://mesh.dl.sourceforge.net/sourceforge/virtualdub/VirtualDub-1.6.1.zip"
    dlsize="796130"
    sysname="VirtualDub-1.6.1.zip"
    installer="unzip -o VirtualDub-1.6.1.zip -d $HOME/.wine/c/Programme/VirtualDub"
    script="virtualdub"
    sysinstall
    additionalsoftware
;;
"Agenda 2004/2005 Client German")
    needsw DBCrab
    $DIALOG --title "Hint" \
	    --no-cancel \
	    --msgbox "You will get an error during the installation.\nAfter that the installer seems to hang.\nIt does not, just give it time to complete." 9 60
    #  error: we can not copy to winetools/sys if there are other files laying around 
    dload="none"
    sysname="setup.exe"
    testname="Agenda Software"
    script="agenda"
    sysinstallsw
    additionalsoftware
;;
"Total Commander 6.03a")
    dload="http://fileforum.betanews.com/sendfile/945901171/1/tcmd603a.exe"
    dlsize="1484021"
    sysname="tcmd603a.exe"
    testname="Total Commander (Remove or Repair)"
    script="wincmd totalcmd"
    sysinstall
    additionalsoftware
;;
"Dependency Walker")
    mkdir "$HOME/.wine/c/Programme/DependencyWalker"
    dload="http://www.dependencywalker.com/depends21_x86.zip"
    dlsize="415352"
    sysname="depends21_x86.zip"
    installer="unzip -o "$sysname" -d $HOME/.wine/c/Programme/DependencyWalker"
    script="depwalker"
    sysinstall
    additionalsoftware
;;
"Eudora 6.2")
    dload="http://www.eudora.com/download/eudora/windows/6.2/Eudora_6.2.exe"
    dlsize="9537272"
    sysname="Eudora_6.2.exe"
    testname="Eudora"
    script="eudora"
    sysinstallsw
    additionalsoftware
;;
"The Bat! 3.01 Professional")
    dload="http://www.ritlabs.com/download/files3/the_bat/thebat_professional.msi"
    dlsize="8776704"
    sysname="thebat_professional.msi"
    installer="$WINE msiexec /i f:\\thebat_professional.msi"
    testname="The Bat.*"
    script="thebat"
    sysinstallsw
    additionalsoftware
;;
"QuickTime Player 6.5.2")
    $DIALOG --title "Hint" \
	    --yesno "Note that you might have to change the fifo-Size in the\nplayer settings for uninterrupted sound. A size of 333 was\ngood for me. Continue?" 8 60
    if [ "$?" = "0" ]; then
      dload="http://a1540.g.akamai.net/7/1540/52/20041101/qtinstall.info.apple.com/pthalo/de/win/QuickTimeFullInstaller.exe"
      dlsize="12903592"
      sysname="QuickTimeFullInstaller.exe"
      testname="QuickTime"
      script="quicktime"
      sysinstallsw
    fi
    additionalsoftware
;;
"QuickTime Player 5.0")
      $DIALOG --title "Hint" \
	      --no-cancel \
	      --msgbox "For older QuickTime installations you need the files on a CD\nor any other medium since they are not downloadable any more..." 7 60
    dload="none"
    dlsize=""
    installer="$WINE d:\\setup.exe"
    testname="QuickTime"
    script="quicktime"
    sysinstallsw    
    additionalsoftware
;;
"Typograf 4 Fontmanagement German")
    $DIALOG --title "Hint" \
	    --no-cancel \
	    --msgbox "Note that the installer will not quit with the finish button.\nYou have to quit the dialog by closing the window." 7 60
    waitforwineexit
    cp -a ~/.wine/config ~/.wine/config.t$$
    cat >>~/.wine/config <<EOF
[AppDefaults\\\\setup.exe\\\\x11drv]
"Managed" = "N"
"Desktop" = "1024x768"

EOF
    dload="http://www.neuber.biz/download/typo40d.exe"
    dlsize="1008304"
    sysname="typo40d.exe"
    script="typograf"
    sysinstall "" "-nofail"
    cp -a ~/.wine/config.t$$ ~/.wine/config
    rm ~/.wine/config.t$$
    additionalsoftware
;;
"Typograf 4 Fontmanagement English")
    $DIALOG --title "Hint" \
	    --no-cancel \
	    --msgbox "Note that the installer will not quit with the finish button.\nYou have to quit the dialog by closing the window." 7 60
    waitforwineexit
    cp -a ~/.wine/config ~/.wine/config.t$$
    cat >>~/.wine/config <<EOF
[AppDefaults\\\\setup.exe\\\\x11drv]
"Managed" = "N"
"Desktop" = "1024x768"

EOF
    dload="http://www.neuber.biz/download/typo40e.exe"
    dlsize="982200"
    sysname="typo40e.exe"
    script="typograf"
    sysinstall "" "-nofail"
    cp -a ~/.wine/config.t$$ ~/.wine/config
    rm ~/.wine/config.t$$
    additionalsoftware
;;
"Fort Agent Newsreader 2.0")
    dload="ftp://ftp3.forteinc.com/pub/agent/english/agentenu200-652.exe"
    dlsize="3818184"
    sysname="agentenu200-652.exe"
    testname="Fort Agent"
    script="agentnr"
    sysinstallsw
    additionalsoftware
;;
"DBCrab 1.50 German with BDE 5.1.1 German" )
    [ -e "$SYSDIR/sys/dbcrab" ] || mkdir -p "$SYSDIR/sys/dbcrab"
    dload="http://www.dbcrab.de/zip/dbcrab150.zip"
    dlsize="5418434"
    sysname="dbcrab150.zip"
    installer="unzip -o dbcrab150.zip -d $SYSDIR/sys/dbcrab"
    sysinstall
    init
    dload="none"
    dlsize="45312"
    sysname="dbcrab/SETUP.EXE"
    testname="DBCrab"
    script="dbcrab"
    sysinstall
    regedit "$BASEDIR/bde.reg"
    additionalsoftware
;;
"Borland Database Engine (BDE) 5.1.1 English")
    needsw "DBCrab"
    for n in BDEADMIN.CNT BDEADMIN.EXE BDEADMIN.HLP BDEADMIN.TOC; do
      rm "$WINEDIR/c/Program Files/Common Files/Borland Shared/BDE/$n"
    done
    regedit "$BASEDIR/bde.reg"
    dload="ftp://ftpc.borland.com/pub/bde/devsupport/updates/bde511en.exe"
    dlsize="11895034"
    sysname="bde511en.exe"
    script="bdeadmin"
    sysinstall
    regedit "$BASEDIR/bde.reg"
    additionalsoftware
;;
"Borland Database Engine (BDE) 5.1.1 German")
    dload="ftp://ftpc.borland.com/pub/bde/devsupport/updates/bde511ge.exe"
    dlsize="12039880"
    sysname="bde511ge.exe"
    testname="bde511.*exe"
    script="bdeadmin"
    sysinstall
    additionalsoftware
;;
"PostgreSQL ODBC driver psqlODBC 7.03.0200")
    dload="ftp://ftp.postgresql.org/pub/odbc/versions/full/psqlodbc-07_03_0200.zip"
    dlsize="3781611"
    sysname="psqlodbc-07_03_0200.zip"
    installer="unzip -o psqlodbc-07_03_0200.zip -d $SYSDIR/sys"
    sysinstall
    init
    dload="none"
    dlsize="3781611"
    sysname="psqlodbc.exe"
    installer=""
    testname="psqlODBC"
    script=""
    sysinstall    
    additionalsoftware
;;
"mIRC 6.16")
    dload="ftp://ftp.freenet.de/pub/mirc.com/mirc616.exe"
    dlsize="1302528"
    sysname="mirc616.exe"
    testname="mIRC"
    script="mirc"
    sysinstallsw
    additionalsoftware
;;
"IrfanView 3.95")
    dload="http://fileforum.betanews.com/sendfile/967963863/1/iview395.exe"
    dlsize="877056"
    sysname="iview395.exe"
    testname="IrfanView.*"
    script="iview"
    sysinstallsw
    if [ "$failed" = "0" ]; then
      $DIALOG --title "IrfanView" \
	      --no-cancel \
	      --msgbox "Installing the Plugins now..." 7 60
      dload="http://fileforum.betanews.com/sendfile/1099412658/1/irfanview_plugins_395.exe"
      dlsize="4692992"
      sysname="irfanview_plugins_395.exe"
      testname=""
      script=""
      sysinstallsw
    fi
    additionalsoftware
;;
"putty 0.56")
    dload="http://the.earth.li/~sgtatham/putty/latest/x86/putty-0.56-installer.exe"
    dlsize="1221389"
    sysname="putty-0.56-installer.exe"
    testname="PuTTY version .*"
    script="putty puttygent puttygen"
    sysinstallsw
    additionalsoftware
;;
"DC++")
    dload="http://mesh.dl.sourceforge.net/sourceforge/dcplusplus/DCPlusPlus-0.668.exe"
    dlsize="2452326"
    sysname="DCPlusPlus-0.668.exe"
    testname="DC++ .*"
    script="dc++"
    sysinstall
    if [ "$failed" = "0" ]; then
      $DIALOG --title "Hint" \
	    --no-cancel \
	    --msgbox "After first start disable the\n'progress bars for transfer'\nat advanced options." 9 60
    
    fi
    additionalsoftware
;;
"Adobe Photoshop 7.0")
    dload="none"
    dlsize=""
    sysname="$choice"
    installer="$WINE d:\\setup.exe"
    testname="$choice"
    script="photoshop imageready"
    sysinstallsw
    additionalsoftware
;;
"Adobe Illustrator 9.0")
    dload="none"
    dlsize=""
    sysname="$choice"
    installer="$WINE d:\\autoplay.exe"
    testname="$choice"
    script="illustrator"
    sysinstallsw
    additionalsoftware
;;
"WinZip 9.0")
    $DIALOG --title "Hint" \
	--no-cancel \
	--msgbox "If the WinZip installer starts WinZip after completion of the installation quit it.\nAnd in the system tray you will also find a WinZip icon. Richt click and quit also.\nCheck that it never starts again!" 7 60
    dload="http://download.winzip.com/german/wz90gev.exe"
    dlsize="2609152"
    sysname="wz90gev.exe"
    testname="WinZip"
    scipt="winzip"
    sysinstallsw
    additionalsoftware
;;
"WinRAR 3.41")
    dload="http://www.rarlab.com/rar/wrar341d.exe"
    dlsize="1144977"
    sysname="wrar341d.exe"
    testname="WinRAR .*"
    scipt="winrar"
    sysinstallsw
    additionalsoftware
;;
*)
  additionalsoftware
;;
esac
;;

1)
    mainmenu
;;
esac
}

#################
### Main menu ###
#################

function mainmenu()
{
init
$DIALOG --title "WineTools 2.1.0" \
	--cancel-label "exit" \
	--icon $BASEDIR/icon/wt.xpm \
        --menu ""  400x420 0  \
	"Read Intro again" "" \
        "Base setup" "" \
        "Install Windows system software" "" \
        "Install Microsoft TrueType core fonts" "" \
        "Install additional software" "" \
	" " "" \
	"Control Center" "" \
	"Registry Editor" "" \
	"Show installed Software" "" \
	"Uninstaller" "" \
	"Simulate a Windows reboot" "" \
	"Show active Wine processes" "" \
	"Kill all Wine processes" "" \
	" " "" \
	"Save your Wine directory" "" \
	"Restore your Wine directory" "" \
	"Edit the Wine configuration file" "" \
	" " "" \
	"About" "" 2> /tmp/menu.tmp.$$

retval=$?

choice=`cat /tmp/menu.tmp.$$`
rm -f /tmp/menu.tmp.$$

case $retval in
0)
case $choice in
"Read Intro again")
about
readme
mainmenu
;;
"Base setup")
  systemsoftware
;;
"Install Windows system software")
  systemmenu
;;
"Install Microsoft TrueType core fonts")
  fonts
;;
"Install additional software")
  additionalsoftware
;;
"Control Center")
  $WINE control
  mainmenu
;;
"Registry Editor")
  $WINE regedit
  mainmenu
;;
"Uninstaller")
  $WINE uninstaller
  wineboot
  mainmenu
;;
"Simulate a Windows reboot")
  wineboot
  mainmenu
;;
"Show active Wine processes")
  ps axwww|grep wine|grep -v "grep wine" >/tmp/psoutput.tmp.$$
  $DIALOG --tailbox /tmp/psoutput.tmp.$$ 60 80
  rm /tmp/psoutput.tmp.$$
  mainmenu
;;
"Show installed Software")
  testsw "testsw"
  echo -e " --- Installed software via registry --- " >/tmp/psoutput.tmp.$$
  cat $HOME/.wine/installed-software >>/tmp/psoutput.tmp.$$
  echo -e "\n\n --- Quiet installed software via registry --- " >>/tmp/psoutput.tmp.$$
  cat $HOME/.wine/quiet-installed-software >>/tmp/psoutput.tmp.$$
  echo -e "\n\n --- Hidden installed software via $CONFIG --- " >>/tmp/psoutput.tmp.$$
  grep " = installed at " "$CONFIG" >>/tmp/psoutput.tmp.$$
  echo -e "\n\n --- Failed software installations via $CONFIG --- " >>/tmp/psoutput.tmp.$$
  grep " = installation failed at " "$CONFIG" >>/tmp/psoutput.tmp.$$
  $DIALOG --no-cancel --tailbox /tmp/psoutput.tmp.$$ 60 80
  rm /tmp/psoutput.tmp.$$
  mainmenu
;;

"Kill all Wine processes")
  $DIALOG  --defaultno --title "Kill" --yesno "Are you shure you want to kill *all* Wine processes???" 7 60
  $DIALOG  --title "--- NOTICE ---" --no-buttons --infobox "Please wait..." 7 60
  [ "$?" = "0" ] && wineserver -kill
  mainmenu
;;
"Save your Wine directory")
  cd ~
  $DIALOG --title "Create Fake Windows Drive" \
          --inputbox "Give a description for the file.\nIt will be called wine-<Description>.tar.gz:" 300x200 2> /tmp/description.tmp.$$
  if [ "$?" = "0" ]; then
    realtar="1"
    if [ -e "wine-`cat /tmp/description.tmp.$$`.tar.gz" ]; then
      $DIALOG  --title "tar File Exists" --yesno "The file already exists. Do you want to overwrite?" 7 60
      if [ "$?" = "0" ]; then
        realtar="1"
      else
        realtar="0"
      fi
    fi
    if [ "$realtar" = "1" ]; then
      (tar -cpvzf "wine-`cat /tmp/description.tmp.$$`.tar.gz" .wine; echo -e "===============================\ndone. You can close the window now!")  &>/tmp/taroutput.tmp.$$ &
      $DIALOG --tailbox /tmp/taroutput.tmp.$$ 60 80
    fi
  fi
  rm /tmp/taroutput.tmp.$$
  mainmenu
;;
"Restore your Wine directory")
  cd ~
  $DIALOG --title "Create Fake Windows Drive" \
          --inputbox "Give the description for the saved file.\nThe file will be called wine-<Description>.tar.gz:" 300x200 2> /tmp/description.tmp.$$
  if [ "$?" = "0" ]; then
    realtar="1"
    if [ -e "wine-`cat /tmp/description.tmp.$$`.tar.gz" ]; then
      if [ -e ".wine" ]; then
        $DIALOG  --title ".wine exists" --defaultno --yesno "The .wine directory already exists. Do you want to delete it?" 7 60
        if [ "$?" = "0" ]; then
          rm -Rf .wine
	  if [ "$?" = "0" ]; then
            realtar="1"
	  else
            $DIALOG  --title "--- ERROR ---" --msgbox "There was a error deleting the .wine directory. We can not continue." 7 60
            realtar="0"
	  fi
        else
          $DIALOG  --title "--- NOTICE ---" --msgbox "We can not continue!" 7 60
          realtar="0"
        fi
      fi
    else
      $DIALOG  --title "--- ERROR ---" --msgbox "The tar file does not exist! We can not continue." 7 60
      realtar="0"
    fi
    if [ "$realtar" = "1" ]; then
      (tar -xpvzf "wine-`cat /tmp/description.tmp.$$`.tar.gz"; echo -e "===============================\ndone. You can close the window now!")  &>/tmp/taroutput.tmp.$$ &
      $DIALOG --tailbox /tmp/taroutput.tmp.$$ 60 80
    fi
  fi
  rm /tmp/taroutput.tmp.$$
  mainmenu
;;
"Edit the Wine configuration file")
  editconfig
;;
"About")
  about
  mainmenu
;;
*)
  mainmenu
;;
esac
;;

1)
    clear
;;
esac
}

###################
### Edit config ###
###################
function editconfig_new()
{
cp ~/.wine/config ~/.wine/config.bak
winecfg
$DIALOG  --defaultno --title "Save Wine config" --yesno "Do you want to save your changes?" 7 60
case $? in
  0)
    mainmenu 
    ;;
  1)
    cp ~/.wine/config.bak ~/.wine/config
    mainmenu
    ;;
esac

rm -f /tmp/xedit$$
}

function editconfig()
{
cp ~/.wine/config ~/.wine/config.edit.$$
$DIALOG --title "Edit Wine config" --fixed-font "" \
	--ok-label "Save" \
	--editbox ~/.wine/config.edit.$$ 0 0 2> ~/.wine/config.edited.$$
choice="$?"
echo "Return value is $choice"
case $choice in
  0)
    echo "saved new config"
    mv -f ~/.wine/config.edited.$$ ~/.wine/config
    rm ~/.wine/config.edit.$$
    mainmenu
    ;;
  *)
    echo "aborted editing new config"
    rm ~/.wine/config.edit.$$ ~/.wine/config.edited.$$
    mainmenu
    ;;
esac

rm -f /tmp/xedit$$
}



#############
### About ###
#############
function about()
{
$DIALOG --title "About WineTools" \
	--msgbox \
"WineTools was initially written by Frank Hendriksen <frank@franksworld.net>
and was extended and is maintained by Joachim von Thadden <thadden@web.de>.

It is licensed under the GPL.

Send comments, bugreports, etc. to thadden@web.de. Don't blame me for the
code. It's a horrible hack but it works.

Note:	This software comes with absolutely no warranty.
	You will not get any support or help for WineTools, Wine, software
	installations, Linux or Microsoft Windows from the author. If you need
	help, ask the mailing lists at http://www.winehq.org/site/forums. If you
	want support, buy the commercial versions of wine: CodeWeavers
	CrossOver Office (http://www.codeweavers.com) for Desktop
	Applications or	TransGamings Cedega (formerly known as WineX)
	(http://www.transgaming.com) for playing games." 25 80

}


function readme()
{
    cat ${BASEDIR}/README.first ${BASEDIR}/README.${WINEVER} > /tmp/README.wine.$$
    $DIALOG --title "Intro" --fixed-font "" \
	--no-cancel \
	--textbox /tmp/README.wine.$$ 35 60
    rm /tmp/README.wine.$$
}


####################
### Main Program ###
####################

[ ! -d $SYSDIR ] && mkdir $SYSDIR

[ ! -d $SYSDIR/fonts ] && mkdir $SYSDIR/fonts

[ ! -d $SYSDIR/sys ] && mkdir $SYSDIR/sys

[ ! -d $SYSDIR/user ] && mkdir $SYSDIR/user

[ ! -d ${HOME}/bin ] && mkdir ${HOME}/bin

rm ~/.wine/dosdevices/f: && ln -s $SYSDIR ~/.wine/dosdevices/f:

. ${BASEDIR}/findwine

if [ $WINEVER -lt 20040914 ] && [ $WINEVER -gt 20041201 ]; then
  $DIALOG  --title "--- NOTICE ---" --msgbox "WineTools is tested with Wine versions 20040914, 20041019, 20041201.\nYou use a different version so the results are unpredictable." 7 60
else
  echo "Version of Wine is OK."
fi

echo "Calls to wine are executed as \"$WINE\"."
echo "Config is $CONFIG."
echo "CDROM is $CDROM."

about
readme
mainmenu
