''***************************************************************
''* This is the setup script for the Microsoft SQL Tools
''*
''* Modification History
''*
''* Trish Millines-7/8/92- Upgraded to version 2.0 of Setup
''*                        Made changes for SQL Object Manager
''* Trish Millines-10/8/92 - Added routines to load in stored procs.
''* Trish Millines-11/23/92 - Finished adding routines to load in
''*                           stored procs.  Fixed bugs.
''* Casey Kiernan - 06/15/93 - tightened it up and fixed bugs
''* XavierS - 10/25/94 - Added Multiprot NetLib support
''***************************************************************

'$DEFINE DEBUG  ''Define for script development/debugging

'$INCLUDE 'setupapi.inc'
'$INCLUDE 'msdetect.inc'
'$INCLUDE 'mscpydis.inc'    ''System


''Dialog ID's
CONST WELCOME       = 100
CONST ASKQUIT       = 200
CONST DESTPATH      = 300
CONST EXITFAILURE   = 400
CONST EXITQUIT      = 600
CONST EXITSUCCESS   = 700
CONST OPTIONS       = 800
CONST APPHELP       = 900
CONST RENAMEOLDDLL  = 950
CONST AUTOEXECUPDATE  = 955
CONST ASKSKIPAUTOEXEC  = 958
CONST RENAMEERRDLG  = 960

CONST ISQLWDISKETTE = 1200
CONST SETLOCATION   = 1300
CONST CUSTHELP      = 1400
CONST LOGINHELP     = 2300
CONST LOGINFAIL     = 2400
CONST WELCOMEHELP   = 1500
CONST PATHHELP      = 1600

CONST CUSTINST      = 6200
CONST TOOBIG        = 6300
CONST BADPATH       = 6400
CONST BILLBOARD     = 4545
CONST CONNECTTOSERVER = 2100
CONST EXECTSQL        = 2200

CONST WM_SYSCOMMAND = 274
CONST SC_MAXIMIZE = 61488

''Bitmap ID
CONST LOGO = 1

''File Types
CONST ISQLW          = 1    ''ISQLW Procedures
CONST CLIENTCONFIG   = 2   ''SQL Obj Procedures
CONST SQLBOOKS	     = 3   '' SQL Books on line
CONST BASEFILES      = 4    ''dblib DLLs and the Sqltools.dll file

GLOBAL DEST$        ''Default destination directory.
GLOBAL BOOKDEST$        ''Default help destination directory.
GLOBAL SQLROOT$		''SQL Root
GLOBAL WINDRIVE$    ''Windows drive letter.
GLOBAL WINDOWSDIR$  ''Windows directory
GLOBAL SQLTOOLS$    ''Name of the sqltools series

''CustInst list symbol names
GLOBAL ISQLWNEEDS$      ''ISQL/w costs per drive
GLOBAL CLIENTNEEDS$     ''Client Config costs per drive
GLOBAL BASENEEDS$       ''Base files costs per drive
GLOBAL BOOKNEEDS$       ''SQL Books Online costs
GLOBAL EXTRACOSTS$      ''List of extra costs to add per drive
GLOBAL BIGLIST$         ''List of option files cost calc results (boolean)
GLOBAL NETLIB$			''Net Lib to put in DSQUERY
GLOBAL WINSYSDIR$		''Window system directory
GLOBAL SQLBOOKINI$	'' location of msin.ini

''Dialog list symbol names
GLOBAL CHECKSTATES$
GLOBAL STATUSTEXT$
GLOBAL DRIVETEXT$

''TSQL Execute symbol names
GLOBAL SERVERNAME$     ''Name of the SQL Server to install scripts on
GLOBAL SERVERVERSION$  ''SQL Server version
GLOBAL TSQLFILE$       ''Name of the Transact-SQL File to process
GLOBAL TSQLRETURN$     ''SUCCEED or FAIL

DECLARE SUB AddOptFilesToCopyList (ftype%)
DECLARE SUB RecalcOptFiles (ftype%)
DECLARE SUB RecalcPath
DECLARE SUB SetDriveStatus
DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING
DECLARE FUNCTION BitmapCntrlInit LIB "mscuistf.dll" as INTEGER
DECLARE FUNCTION SendMessage LIB "user"(hwnd%, wMsg%, wParam%, lParam&)
DECLARE FUNCTION GetWinSystemDir LIB "mscuistf.dll" (szBuf$, cbBuf%) AS INTEGER
DECLARE FUNCTION GetWindowsNTVersion LIB "mscuistf.dll" (szBuf$, cbBuf%) AS INTEGER

INIT:
    SetSymbolValue "DLLCurrentVersion", "1996.04.03.0"



    hwnd% = HwndFrame()
    istatus% = SendMessage(hwnd%, WM_SYSCOMMAND, SC_MAXIMIZE,0)   ''Maximize the window

    '' Get the Window's system directory
    cb% = 256
    szBuf$ = STRING$(cb%, 32)
    cbRet% = GetWinSystemDir(szBuf$, cb%)

    WINSYSDIR$ = szBuf$
    SQLBOOKINI$ = GetWindowsDir()+"INFOVIEW.INI"
    CUIDLL$ = "mscuistf.dll"            ''Custom user interface dll
    HELPPROC$ = "FHelpDlgProc"          ''Help dialog procedure
    SQLTOOLS$ = "SQL Server Tools"
    SetBitmap CUIDLL$, LOGO
    SetTitle "Microsoft SQL Server Client Tools Setup"

    szInf$ = GetSymbolValue("STF_SRCINFPATH")
    IF szInf$ = "" THEN
    szInf$ = GetSymbolValue("STF_CWDDIR") + "SQLTOOLS.INF"
    END IF
    ReadInfFile szInf$
    szVer$ = STRING$(cb%, 32)
    cbRet% = GetWindowsNTVersion(szVer$, cb%)

    WINDRIVE$ = MID$(GetWindowsDir, 1, 1)
    WINDOWSDIR$ = GetWindowsDir()
    SQLROOT$ = WINDRIVE$ + ":\mssql"
    DEST$ = SQLROOT$ + "\BIN"
    BOOKDEST$ = SQLROOT$ + "\BOOKS"

    ''CustInst list symbols
    CHECKSTATES$ = "CheckItemsState"
    STATUSTEXT$  = "StatusItemsText"
    DRIVETEXT$   = "DriveStatusText"
    RENAMEDLLS$  = "HuntedVersionDLLs"
    DLLVERSNING$ = "DLLCurrentVersion"
    AUTOEXECUPD$ = "AutoexecUpdate"
    NETLIBSEL$   = "NetLibSelection"

    NETLIB$ = "DBNMP3"

    AddListItem CHECKSTATES$, "ON"     ''ISQL/w
    AddListItem CHECKSTATES$, "ON"     ''Client Config
    AddListItem CHECKSTATES$, "ON"     ''SQL Books online
    AddListItem CHECKSTATES$, "ON"     ''Base files (DLLs) checked on

    FOR i% = 1 TO 4 STEP 1
    AddListItem STATUSTEXT$, ""
    NEXT i%
    FOR i% = 1 TO 7 STEP 1
    AddListItem DRIVETEXT$, ""
    NEXT i%
    ReplaceListItem DRIVETEXT$, 7, SQLROOT$

    AddListItem NETLIBSEL$,  "Named Pipes"
    AddListItem NETLIBSEL$,  "Novell SPX"
    AddListItem NETLIBSEL$,  "Banyan Vines"
    AddListItem NETLIBSEL$,  "TCPIP Sockets"
    AddListItem NETLIBSEL$,  "Multi-protocol"

    AddListItem RENAMEDLLS$, "dbnmp3.dll"
    AddListItem RENAMEDLLS$, "dbmsspx3.dll"
    AddListItem RENAMEDLLS$, "dbmsvin3.dll"
    AddListItem RENAMEDLLS$, "dbmssoc3.dll"
    AddListItem RENAMEDLLS$, "w3dblib.dll"
    AddListItem RENAMEDLLS$, "msdblib3.dll"
    AddListItem RENAMEDLLS$, "dbmsrpc3.dll"

    ''Disk cost list symbols
    ISQLWNEEDS$     = "ISQLWNeeds"
    CLIENTNEEDS$    = "ClientNeeds"
    BASENEEDS$      = "BaseNeeds"
    BOOKNEEDS$      = "SQLBookNeeds"

    EXTRACOSTS$ = "ExtraCosts"
    BIGLIST$    = "BigList"
    FOR i% = 1 TO 6 STEP 1
    AddListItem BIGLIST$, ""
    NEXT i%
    FOR i% = 1 TO 26 STEP 1
    AddListItem EXTRACOSTS$, "0"
    NEXT i%

    FOR i% = 1 TO 26 STEP 1
    AddListItem ISQLWNEEDS$, "0"
    NEXT i%
    FOR i% = 1 TO 26 STEP 1
    AddListItem CLIENTNEEDS$, "0"
    NEXT i%
    FOR i% = 1 TO 26 STEP 1
    AddListItem BASENEEDS$, "0"
    NEXT i%
    FOR i% = 1 TO 26 STEP 1
    AddListItem BOOKNEEDS$, "0"
    NEXT i%


WELCOME:
    sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", WELCOMEHELP, HELPPROC$)
    IF sz$ = "CONTINUE" THEN
    UIPop 1
    ELSE
    GOSUB ASKQUIT
    GOTO WELCOME
    END IF

GETPATH:
    SetSymbolValue "EditTextIn", SQLROOT$
    SetSymbolValue "EditFocus", "END"
GETPATHL1:
    sz$ = UIStartDlg(CUIDLL$, DESTPATH, "FEditDlgProc", PATHHELP, HELPPROC$)
    SQLROOT$ = GetSymbolValue("EditTextOut")
    DEST$ = SQLROOT$ + "\BIN"
    BOOKDEST$ = SQLROOT$ + "\BOOKS"

    IF sz$ = "CONTINUE" THEN
	    IF IsDirWritable(SQLROOT$) = 0 THEN
		GOSUB BADPATH
		GOTO GETPATHL1
	    END IF
	    UIPop 1
    ELSEIF sz$ = "REACTIVATE" THEN
	    GOTO GETPATHL1
    ELSE
	    GOSUB ASKQUIT
	    GOTO GETPATH
    END IF

''********************************************************************
''* Display the custom installation dialog.  As each item is checked,
''* the disk space requirements are recalculated
''********************************************************************

 RecalcPath
 SetDriveStatus

CUSTINST:
    ReplaceListItem DRIVETEXT$, 7, SQLROOT$
    sz$ = UIStartDlg(CUIDLL$, CUSTINST, "FCustInstDlgProc", CUSTHELP, HELPPROC$)

    IF sz$ = "CONTINUE" THEN
	    ''Install only if it will fit.
	    FOR i% = 1 TO 4 STEP 1
		IF GetListItem(BIGLIST$, i%) <> "" THEN
		GOSUB TOOBIG
		GOTO CUSTINST
		END IF
	    NEXT i%
	    UIPop 1
	    GOTO CHECKCD
    ELSEIF sz$ = "PATH" THEN
	    GOTO GETPATH
    ELSEIF sz$ = "CHK1" THEN
	    RecalcOptFiles ISQLW
	    SetDriveStatus
	    GOTO CUSTINST
    ELSEIF sz$ = "CHK2" THEN
	    RecalcOptFiles CLIENTCONFIG
	    SetDriveStatus
	    GOTO CUSTINST
    ELSEIF sz$ = "CHK3" THEN
	    RecalcOptFiles SQLBOOKS
	    SetDriveStatus
	    GOTO CUSTINST
    ELSEIF sz$ = "CMB1" THEN
        COMBOSEL$ = GetSymbolValue("CMBSEL")
        IF COMBOSEL$ = "1" THEN
          NETLIB$ = "DBNMP3"
        ELSEIF COMBOSEL$ = "2" THEN
          NETLIB$ = "DBMSSPX3"
        ELSEIF COMBOSEL$ = "3" THEN
          NETLIB$ = "DBMSVIN3"
	ELSEIF COMBOSEL$ = "4" THEN
	  NETLIB$ = "DBMSSOC3"
        ELSEIF COMBOSEL$ = "5" THEN
          NETLIB$ = "DBMSRPC3"
	END IF
        GOTO CUSTINST
    ELSEIF sz$ = "REACTIVATE" THEN
	    RecalcPath
	    SetDriveStatus
	    GOTO CUSTINST
    ELSE
	    GOSUB ASKQUIT
	    GOTO CUSTINST
    END IF

''********************************************************************
''* Create the destination directory.
''* Note: Size checking is being turned off because we can install
''* files from any version of our products, but won't necessarily know
''* the sizes of the files.
''********************************************************************

CHECKCD:

   SrcDir$ = GetSymbolValue("STF_SRCDIR")
   I% = DoesFileExist(SrcDir$ + "ISQLW.EXE",0)
   if I% = 1 THEN
	  GOTO CREATEDEST
   ELSE
      sz$ = UIStartDlg(CUIDLL$, ISQLWDISKETTE, "FQuitDlgProc", 1100,  HELPPROC$)
      UIPopAll
      ERROR STFQUIT
   END IF

CREATEDEST:
    CreateDir DEST$, cmoVital                 ''Create the destination directory
    if GetListItem(CHECKSTATES$, SQLBOOKS) = "ON" THEN
       CreateDir BOOKDEST$, cmoVital                 ''Create the Help files destination directory
    END IF
    i% = SetSizeCheckMode(scmOff)
    SrcDir$ = GetSymbolValue("STF_SRCDIR")


RENAMEOLDDLLS:
    sz$ = UIStartDlg(CUIDLL$, RENAMEOLDDLL, "FCustRenameDLLDlgProc", CUSTHELP, HELPPROC$)
    IF sz$ = "RENAME_ERROR" THEN
      UIPop 1
      GOTO RENAMEERR
    END IF
    UIPop 1

    IF szVer$ = "TRUE" THEN
      GOTO COPYDLLFILES
    ENDIF

UPDATEAUTOEXEC:
    AddListItem AUTOEXECUPD$, DEST$
    AddListItem AUTOEXECUPD$, "TRUE"
    AddListItem AUTOEXECUPD$, "FALSE"
    sz$ = UIStartDlg(CUIDLL$, AUTOEXECUPDATE, "FCustUpdateAutoexecDlgProc", CUSTHELP, HELPPROC$)
    IF sz$ = "AUTOEXEC_ERROR" THEN
      UIPop 1
      GOTO AUTOEXECERR
    END IF
    UIPop 1


''********************************************************************
''* If installing any of the products, then copy over the base files
''* which include the DLLs
''********************************************************************

COPYDLLFILES:
    i% = BitmapCntrlInit()                ''Initialize the billboard bitmap
    ClearCopyList                         ''Clear the copy list



''********************************************************************
''* Prompt user for the Administrator diskette if they checked the
''* option to install it.
''* Run the normal copy disincentive check.  Save the org and name for
''* use with the other tool installations if they are new one's
''* NOTE: At some point we may also want to save other copy
''* disincentive information
''* Copy the files.
''********************************************************************

ISQLWDISKETTE:                                  ''Prompt for SQL Admin diskette
 ClearCopyList                             ''Clear the copy list

     SrcDir$ = GetSymbolValue("STF_SRCDIR")
     AddSectionFilesToCopyList "DblibDlls", SrcDir$, DEST$
     AddSectionFilesToCopyList "SystemDLLs", DEST$, WINSYSDIR$
     AddSectionFilesToCopyList "Readme", SrcDir$, SQLROOT$

 IF GetListItem(CHECKSTATES$, CLIENTCONFIG) = "ON" OR  GetListItem(CHECKSTATES$, ISQLW) = "ON" OR GetListItem(CHECKSTATES$, SQLBOOKS) = "ON" THEN

    SrcDir$ = GetSymbolValue("STF_SRCDIR")

    IF GetListItem(CHECKSTATES$, ISQLW) = "ON" THEN
	  AddSectionFilesToCopyList "Isqlw", SrcDir$, DEST$
    END IF
    IF GetListItem(CHECKSTATES$, SQLBOOKS) = "ON" THEN
	  AddSectionFilesToCopyList "SQLBooks", SrcDir$, BOOKDEST$
	  AddSectionFilesToCopyList "SQLBooksEXE", SrcDir$, DEST$
    END IF

    IF GetListItem(CHECKSTATES$, CLIENTCONFIG) = "ON" THEN
	  AddSectionFilesToCopyList "dbver", SrcDir$, SQLROOT$
    END IF

    SetCopyGaugePosition 170, 145
    CopyFilesInCopyList                   ''Copy the files
 END IF




''********************************************************************
''* Create the Sqltools.ini file.
''********************************************************************

MAKEINIFILE:

    CreateIniKeyValue "WIN.INI","SQLMONITOR","DBNMP3","?1:\\?1\pipe\winsql\backup", cmoOverwrite
    CreateIniKeyValue "WIN.INI","SQLMONITOR","DBMSSPX3","?1:?1_mon", cmoOverwrite
    CreateIniKeyValue "WIN.INI","SQLMONITOR","DBMSVIN3","?1@?2:?1_mon?2", cmoOverwrite
    CreateIniKeyValue "WIN.INI","SQLMONITOR","DBMSSOC3","?1,?2:?1,1434", cmoOverwrite
    CreateIniKeyValue "WIN.INI","SQLSERVER","DSQUERY",NETLIB$, cmoOverwrite
    IF GetListItem(CHECKSTATES$, SQLBOOKS) = "ON" THEN
       CreateIniKeyValue SQLBOOKINI$,"SQLBOOKS.Settings","licensed.name","SQL Server Client",cmoNone
       CreateIniKeyValue SQLBOOKINI$,"SQLBOOKS.Settings","licensed.organization","SQL Server Liscensee",cmoNone
       CreateIniKeyValue SQLBOOKINI$,"SQLBOOKS.Settings","license_version","6/1/95",cmoNone
       CreateIniKeyValue SQLBOOKINI$,"SQLBOOKS.Settings","license_last_read","6/1/95",cmoNone
       CreateIniKeyValue SQLBOOKINI$,"series","SQLBOOKS","SQLBOOKS.MVB",cmoOverwrite
       CreateIniKeyValue SQLBOOKINI$,"all titles","SQLBOOKS.MVB","SQLBOOKS.MVB",cmoOverwrite
       CreateIniKeyValue SQLBOOKINI$,"SQLBOOKS.MVB","title","SQL Server Books Online",cmoOverwrite
       CreateIniKeyValue SQLBOOKINI$,"SQLBOOKS.MVB","installtype","Complete",cmoOverwrite
       CreateIniKeyValue SQLBOOKINI$,"SQLBOOKS.MVB","path",BOOKDEST$,cmoOverwrite
       CreateIniKeyValue SQLBOOKINI$,"SQLBOOKS.MVB","Exe",MakePath(DEST$,"infoview.exe"),cmoOverwrite
       CreateIniKeyValue SQLBOOKINI$,"SQLBOOKS.MVB","LocalDir",DEST$,cmoOverwrite
    END IF



''********************************************************************
''* Create the Sqltools program manager group.
''********************************************************************

MAKEPROGGROUP:

    grp$ = MakePath(WINDOWSDIR$, "sqltools.grp")
    CreateProgmanGroup SQLTOOLS$,grp$,cmoNone

    IF GetListItem(CHECKSTATES$, CLIENTCONFIG) = "ON" THEN
       sqldbexe$ = MakePath(SQLROOT$, "w3dbver.exe")
      CreateProgmanItem SQLTOOLS$,"SQL Client Configuration Utility", sqldbexe$, "", cmoOverwrite
    END IF
    IF GetListItem(CHECKSTATES$, ISQLW) = "ON" THEN
       sqldbexe$ = MakePath(DEST$, "isqlw.exe")
      CreateProgmanItem SQLTOOLS$,"ISQL/w", sqldbexe$, "", cmoOverwrite
    END IF
    IF GetListItem(CHECKSTATES$, SQLBOOKS) = "ON" THEN
       sqldbexe$ = MakePath(DEST$, "infoview.exe") + " SQLBOOKS.MVB"
       sqlico$ = MakePath(DEST$, "sqlbooks.ico")
      CreateProgmanItem SQLTOOLS$,"SQL Server Books Online", sqldbexe$,  sqlico$, cmoOverwrite
    END IF

    sqlreadme$ = MakePath(SQLROOT$, "readme.txt")
    CreateProgmanItem SQLTOOLS$,"Release Notes", "NOTEPAD.EXE " + sqlreadme$, "", cmoOverwrite

    ShowProgManGroup SQLTOOLS$, 1,cmoNone

''********************************************************************
''* This is the exit routine.
''* If loaded any stored procedures, first remove the W3DBLIB.DLL and
''* DBNMP3.DLL files from the windows\system directory.
''********************************************************************

QUIT:

    ON ERROR GOTO ERRQUIT

    IF ERR = 0 THEN
    dlg% = EXITSUCCESS
    ELSEIF ERR = STFQUIT THEN
    dlg% = EXITQUIT
    ELSE
    dlg% = EXITFAILURE
    END IF

QUITL1:
    sz$ = UIStartDlg(CUIDLL$, dlg%, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
    GOTO QUITL1
    END IF
    UIPop 1
    END

RENAMEERR:
    sz$ = UIStartDlg(CUIDLL$, RENAMEERRDLG, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
    GOTO RENAMEERR
    END IF
    UIPop 1
    END

AUTOEXECERR:
    sz$ = UIStartDlg(CUIDLL$, ASKSKIPAUTOEXEC, "FInfoDlgProc", 0, "")
    IF sz$ = "CONTINUE" THEN
    UIPop 1
    GOTO COPYDLLFILES
    ELSEIF sz$ = "REACTIVATE" THEN
    GOTO AUTOEXECERR
    ELSEIF sz$ = "EXIT" THEN
    UIPop 1
    dlg% = EXITQUIT
    GOTO QUITL1
    END IF
    UIPop 1
    END

ERRQUIT:
    i% = DoMsgBox("Setup sources were corrupted, call product support!", "Setup Message", MB_OK+MB_TASKMODAL+MB_ICONHAND)
    END

TOOBIG:
    sz$ = UIStartDlg(CUIDLL$, TOOBIG, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
    RecalcPath
    SetDriveStatus
    GOTO TOOBIG
    END IF
    UIPop 1
    RETURN

BADPATH:
    sz$ = UIStartDlg(CUIDLL$, BADPATH, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
    GOTO BADPATH
    END IF
    UIPop 1
    RETURN

LOGONFAILED:
    sz$ = UIStartDlg(CUIDLL$, LOGINFAIL, "FQuitDlgProc", 0, "")

    IF sz$ = "EXIT" THEN
	UIPopAll
	ERROR STFQUIT
    ELSEIF sz$ = "REACTIVATE" THEN
	GOTO LOGONFAILED
    ELSE
	  UIPop 1
    END IF
    RETURN

ASKQUIT:
    sz$ = UIStartDlg(CUIDLL$, ASKQUIT, "FQuitDlgProc", 0, "")

    IF sz$ = "EXIT" THEN
    UIPopAll
    ERROR STFQUIT
    ELSEIF sz$ = "REACTIVATE" THEN
    GOTO ASKQUIT
    ELSE
    UIPop 1
    END IF
    RETURN

'**
'** Purpose:
'**     Adds the specified option files to the copy list.
'** Arguments:
'**     ftype%  - type of files to add, one of the following:
'**             ADMINFILES, OBJFILES, BASEFILES
'** Returns:
'**     none.
'*************************************************************************
SUB AddOptFilesToCopyList (ftype%) STATIC

    SrcDir$ = GetSymbolValue("STF_SRCDIR")

    IF  ftype% = BASEFILES THEN
      AddSectionFilesToCopyList "DblibDlls", SrcDir$, DEST$
    ELSEIF  GetListItem(CHECKSTATES$, ftype%) = "ON" THEN
    IF ftype% = ISQLW THEN
	  AddSectionFilesToCopyList "Isqlw", SrcDir$, DEST$
    ELSEIF ftype% = CLIENTCONFIG THEN
	  AddSectionFilesToCopyList "dbver", SrcDir$, SQLROOT$
    ELSEIF ftype% = SQLBOOKS THEN
	  AddSectionFilesToCopyList "SQLBooks", SrcDir$, BOOKDEST$
	  AddSectionFilesToCopyList "SQLBooksEXE", SrcDir$, DEST$
    END IF
    SrcDir$ = ""
    END IF
END SUB

'**
'** Purpose:
'**     Recalculates disk space for the given option files and sets
'**     the status info symbol "StatusItemsText".
'** Arguments:
'**     ftype% - type of files to add, one of the following:
'**             ADMINFILES, OBJFILES, BASEFILES
'** Returns:
'**     none.
'*************************************************************************
SUB RecalcOptFiles (ftype%) STATIC
    CursorSave% = ShowWaitCursor()
    ClearCopyList
    AddOptFilesToCopyList ftype%

    fExtra% = 0
    IF ftype% = ISQLW THEN
    ListSym$ = ISQLWNEEDS$
    IF GetListItem(CHECKSTATES$, ISQLW) = "ON" THEN
	''Add extra cost to Windows drive for ini/progman, etc.
	ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
	ReplaceListItem EXTRACOSTS$, ndrive%, "0"
	fExtra% = 1
    END IF
    ELSEIF ftype% = CLIENTCONFIG THEN
    ListSym$ = CLIENTNEEDS$
    IF GetListItem(CHECKSTATES$, CLIENTCONFIG) = "ON" THEN
	''Add extra cost to Windows drive for ini/progman, etc.
	ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
	ReplaceListItem EXTRACOSTS$, ndrive%, "0"
	fExtra% = 1
    END IF
    ELSEIF ftype% = SQLBOOKS THEN
    ListSym$ = BOOKNEEDS$
    IF GetListItem(CHECKSTATES$, SQLBOOKS) = "ON" THEN
	''Add extra cost to Windows drive for ini/progman, etc.
	ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
	ReplaceListItem EXTRACOSTS$, ndrive%, "2048"
	fExtra% = 1
    END IF
    ELSEIF ftype% = BASEFILES THEN
    ListSym$ = BASENEEDS$
'    IF GetListItem(CHECKSTATES$, BASEFILES) = "ON" THEN
	''Add extra cost to Windows drive for ini/progman, etc.
	ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
	ReplaceListItem EXTRACOSTS$, ndrive%, "0"
	fExtra% = 1
 '   END IF
    END IF

    StillNeed& = GetCopyListCost(EXTRACOSTS$, ListSym$, "")
''I% = DoMsgBox (STR$(StillNeed&),"still need for " + ListSym$,1)

    cost& = 0
    FOR i% = 1 TO 26 STEP 1
    cost&  = cost& + VAL(GetListItem(ListSym$, i%))
''I% = DoMsgBox (LstSym$,"listsym" + STR$(I%),1)
''I% = DoMsgBox (EXTRACOST$,"extracost",1)

    NEXT i%

    if cost& < 0 THEN
      ReplaceListItem STATUSTEXT$, ftype%, "0 K"
    ELSE
      ReplaceListItem STATUSTEXT$, ftype%, STR$(cost& / 1024) + " K"
    ENDIF

''I% = DoMsgBox (STR$(cost& / 1024) + " K","Status text type = " + STR$(ftype%),1)

    IF StillNeed& > 0 THEN
    ReplaceListItem BIGLIST$, ftype%, "YES"
    ELSE
    ReplaceListItem BIGLIST$, ftype%, ""
    END IF

    IF fExtra% THEN
    ReplaceListItem EXTRACOSTS$, ndrive%, "0"
    END IF
    RestoreCursor CursorSave%
    ListSym$ = ""
END SUB

'**
'** Purpose:
'**     Recalculates disk space and sets option status info according
'**     to the current destination path.
'** Arguments:
'**     none.
'** Returns:
'**     none.
'*************************************************************************
SUB RecalcPath STATIC

    CursorSave% = ShowWaitCursor()

    RecalcOptFiles ISQLW
    RecalcOptFiles CLIENTCONFIG
    RecalcOptFiles SQLBOOKS
    RecalcOptFiles BASEFILES

    RestoreCursor CursorSave%
END SUB


'**
'** Purpose:
'**     Sets drive status info according to latest disk space calcs.
'** Arguments:
'**     none.
'** Returns:
'**     none.
'*************************************************************************
SUB SetDriveStatus STATIC

    drive$ = MID$(DEST$, 1, 1)
    ndrive% = ASC(ucase$(drive$)) - ASC("A") + 1
    cost& =  VAL(GetListItem(ISQLWNEEDS$, ndrive%)) + VAL(GetListItem(CLIENTNEEDS$, ndrive%))+ VAL(GetListItem(BOOKNEEDS$, ndrive%))+ VAL(GetListItem(BASENEEDS$, ndrive%))
    free& = GetFreeSpaceForDrive(drive$)

    ReplaceListItem DRIVETEXT$, 1, drive$ + ":"
    ReplaceListItem DRIVETEXT$, 2, STR$(cost& / 1024) + " K"
    ReplaceListItem DRIVETEXT$, 3, STR$(free& / 1024) + " K"

    IF drive$ = WINDRIVE$ THEN
    ReplaceListItem DRIVETEXT$, 4, ""
    ReplaceListItem DRIVETEXT$, 5, ""
    ELSE
    ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
    cost& = VAL(GetListItem(ISQLWNEEDS$, ndrive%))  + VAL(GetListItem(CLIENTNEEDS$, ndrive%))+ VAL(GetListItem(BOOKNEEDS$, ndrive%))+ VAL(GetListItem(BASENEEDS$, ndrive%))
    IF cost& = 0 THEN
	ReplaceListItem DRIVETEXT$, 4, ""
	ReplaceListItem DRIVETEXT$, 5, ""
    ELSE
	free& = GetFreeSpaceForDrive(WINDRIVE$)
	ReplaceListItem DRIVETEXT$, 4, WINDRIVE$ + ":"
	ReplaceListItem DRIVETEXT$, 5, STR$(cost& / 1024) + " K"
    END IF
    END IF
END SUB

'**
'** Purpose:
'**     Appends a file name to the end of a directory path,
'**     inserting a backslash character as needed.
'** Arguments:
'**     szDir$  - full directory path (with optional ending "\")
'**     szFile$ - filename to append to directory
'** Returns:
'**     Resulting fully qualified path name.
'*************************************************************************
FUNCTION MakePath (szDir$, szFile$) STATIC AS STRING
    IF szDir$ = "" THEN
    MakePath = szFile$
    ELSEIF szFile$ = "" THEN
    MakePath = szDir$
    ELSEIF MID$(szDir$, LEN(szDir$), 1) = "\" THEN
    MakePath = szDir$ + szFile$
    ELSE
    MakePath = szDir$ + "\" + szFile$
    END IF
END FUNCTION
