'*************************************************************************
'*                       Elastic Reality Setup
'**************************************************************************
'$INCLUDE 'setupapi.inc'
'$INCLUDE 'msdetect.inc'
'$INCLUDE 'msregdb.inc'

''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 CUSTINST      = 6200
CONST TOOBIG        = 6300
CONST BADPATH       = 6400
CONST GETNAMEORG    = 7500
CONST WIN32NOTINST  = 8128
CONST WININIMOD     = 8129

''Bitmap ID
CONST LOGO = 1

''File Types
CONST APPFILES     = 1
CONST OPTFILES1    = 2
CONST OPTFILES2    = 3
CONST REQFILES     = 4

''Maximizing constants
CONST WS_VISIBLE      =&H10000000
CONST WS_BORDER       =&H00800000
CONST WS_CLIPCHILDREN =&H02000000
CONST GWL_STYLE =-16
CONST SW_SHOWMAXIMIZED =3
CONST SW_SHOWMINIMIZED =2

DECLARE FUNCTION ShowWindow LIB "user.exe" (hWnd%, iShow%) AS INTEGER
DECLARE FUNCTION SetWindowLong LIB "user.exe" (hWnd%, offset%, style&) AS LONG

GLOBAL DESTSYS$     ''Windows\System directory.
GLOBAL DESTWIN$     ''Windows directory.
GLOBAL DEST$        ''Default destination directory.

GLOBAL WINDRIVE$    ''Windows drive letter.

''CustInst list symbol names
GLOBAL APPNEEDS$    ''Option list costs per drive
GLOBAL OPT1NEEDS$
GLOBAL OPT2NEEDS$
GLOBAL REQNEEDS$
GLOBAL ALLNEEDS$
GLOBAL EXTRACOSTS$  ''List of extra costs to add per drive

GLOBAL WINDRIVECOST$

''Dialog list symbol names
GLOBAL CHECKSTATES$
GLOBAL STATUSTEXT$
GLOBAL DRIVETEXT$

GLOBAL USERNAME$    ''Option selection from name/org/serial dialog.
GLOBAL ORGNAME$     ''Option selection from name/org/serial dialog.
GLOBAL SERIAL As String * 1024

GLOBAL hWnd%

DECLARE SUB AddOptFilesToCopyList (ftype%)
DECLARE SUB RecalcOptFiles (ftype%)
DECLARE SUB RecalcPath
DECLARE SUB SetDriveStatus

DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING

DECLARE FUNCTION ValidateSerial LIB "erinst.dll" (hWnd%, lpSerial$) AS LONG
DECLARE FUNCTION Serialize LIB "erinst.dll" (hWnd%, snFile$, snName$, snOrg$, snSer$, snWhich%) AS INTEGER
DECLARE FUNCTION OnWindowsNT LIB "erinst.dll" AS INTEGER

INIT:
    CUIDLL$ = "mscuistf.dll"            ''Custom user interface dll
    HELPPROC$ = "FHelpDlgProc"          ''Help dialog procedure

    SetTitle "Elastic Reality Setup"

    ''Maximize window
    hWnd% = HwndFrame()
    i1& = SetWindowLong(hWnd%, GWL_STYLE, WS_VISIBLE+WS_BORDER+WS_CLIPCHILDREN)
    j1% = ShowWindow(hWnd%, SW_SHOWMAXIMIZED)

    SetBitmap CUIDLL$, LOGO

    szInf$ = GetSymbolValue("STF_SRCINFPATH")
    IF szInf$ = "" THEN
        szInf$ = GetSymbolValue("STF_CWDDIR") + "EREALITY.INF"
    END IF
    ReadInfFile szInf$

    DEST$ = "C:\EREALITY"
    DESTSYS$ = GetWindowsSysDir()
    DESTWIN$ = GetWindowsDir()
    WINDRIVE$ = MID$(GetWindowsDir, 1, 1)

    ''CustInst list symbols
    CHECKSTATES$ = "CheckItemsState"
    STATUSTEXT$  = "StatusItemsText"
    DRIVETEXT$   = "DriveStatusText"
    FOR i% = 1 TO 4 STEP 1
        AddListItem CHECKSTATES$, "ON"
    NEXT i%
    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, DEST$

    ''Disk cost list symbols
    APPNEEDS$   = "AppNeeds"
    OPT1NEEDS$  = "Opt1Needs"
    OPT2NEEDS$  = "Opt2Needs"
    REQNEEDS$   = "ReqNeeds"
    ALLNEEDS$   = "ReqNeeds"
    EXTRACOSTS$ = "ExtraCosts"
    IF OnWindowsNT() = 0 THEN
	'' Program Manager's .GRP file
	cost& = 7168
	'' Our copy of the WIN.INI file
	cost& = cost& + GetSizeOfFile (DESTWIN$ + "WIN.INI") + 512
    END IF
    WINDRIVECOST$ = STR$(cost&)
    FOR i% = 1 TO 26 STEP 1
        AddListItem EXTRACOSTS$, "0"
    NEXT i%

    RecalcPath
    SetDriveStatus

WIN32CHECK:
    IF OnWindowsNT() = 0 THEN
	'' Check if Win32s is installed
	sz$ = GetIniKeyString (DESTSYS$ + "WIN32S.INI", "Win32s", "Setup")
	IF sz$ <> "1" THEN
	    sz$ = UIStartDlg(CUIDLL$, WIN32NOTINST, "FInfoDlgProc", APPHELP, HELPPROC$)
	    IF sz$ = "REACTIVATE" THEN
		GOTO WIN32CHECK
	    ELSEIF sz$ = "CONTINUE" THEN
		UIPop 1
	    ELSE
		GOSUB ASKQUIT
		GOTO WIN32CHECK
	    END IF
	END IF
    END IF


WELCOME:
    sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", APPHELP, HELPPROC$)
    IF sz$ = "REACTIVATE" THEN
	GOTO WELCOME
    ELSEIF sz$ = "CONTINUE" THEN
        UIPop 1
    ELSE
        GOSUB ASKQUIT
        GOTO WELCOME
    END IF


CUSTINST:
    sz$ = UIStartDlg(CUIDLL$, CUSTINST, "FCustInstDlgProc", APPHELP, HELPPROC$)

    IF sz$ = "CONTINUE" THEN
        ''Install only if it will fit.
	CursorSave% = ShowWaitCursor()
	ClearCopyList
	AddOptFilesToCopyList APPFILES
	AddOptFilesToCopyList OPTFILES1
	AddOptFilesToCopyList OPTFILES2
	AddOptFilesToCopyList REQFILES
	StillNeed& = GetCopyListCost(EXTRACOSTS$, ALLNEEDS$, "")
	RestoreCursor CursorSave%
	IF StillNeed& > 0 THEN
            GOTO TOOBIG
        END IF
	IF (GetListItem(CHECKSTATES$, APPFILES) <> "ON") AND (GetListItem(CHECKSTATES$, OPTFILES1) <> "ON") AND (GetListItem(CHECKSTATES$, OPTFILES2) <> "ON") THEN
	    GOTO CUSTINST
	END IF
        UIPop 1
        GOTO NAMEORGSERIAL
    ELSEIF sz$ = "PATH" THEN
        GOTO GETPATH
    ELSEIF sz$ = "CHK1" THEN
        RecalcOptFiles APPFILES
        RecalcOptFiles REQFILES
        SetDriveStatus
        GOTO CUSTINST
    ELSEIF sz$ = "CHK2" THEN
        RecalcOptFiles OPTFILES1
        RecalcOptFiles REQFILES
        SetDriveStatus
        GOTO CUSTINST
    ELSEIF sz$ = "CHK3" THEN
        RecalcOptFiles OPTFILES2
        SetDriveStatus
        GOTO CUSTINST
    ELSEIF sz$ = "REACTIVATE" THEN
        RecalcPath
        SetDriveStatus
        GOTO CUSTINST
    ELSE
        GOSUB ASKQUIT
        GOTO CUSTINST
    END IF

NAMEORGSERIAL:
    IF (GetListItem(CHECKSTATES$, APPFILES) = "ON") OR (GetListItem(CHECKSTATES$, OPTFILES1) = "ON") THEN
	sz$ = UIStartDlg(CUIDLL$, GETNAMEORG, "FNameOrgDlgProc", APPHELP, HELPPROC$)
	USERNAME$ = GetSymbolValue("NameOut")
	ORGNAME$ = GetSymbolValue("OrgOut")
	SERIAL   = GetSymbolValue("SerialOut")

	IF sz$ = "CONTINUE" THEN
	    IF ValidateSerial(hWnd%, SERIAL) = 0 THEN
		GOTO NAMEORGSERIAL
	    END IF
	    UIPop 1
	ELSEIF sz$ = "REACTIVATE" THEN
	    GOTO NAMEORGSERIAL
	ELSE
	    GOSUB ASKQUIT
	    GOTO NAMEORGSERIAL
	END IF
    END IF

INSTALL:
    SrcDir$ = GetSymbolValue("STF_SRCDIR")
    CreateDir DEST$, cmoNone
    IF (GetListItem(CHECKSTATES$, APPFILES) = "ON") OR (GetListItem(CHECKSTATES$, OPTFILES1) = "ON") THEN
	CreateDir MakePath(DEST$, "PROGRAMS"), cmoNone
	CreateDir MakePath(DEST$, "HIIP"), cmoNone
	CreateDir MakePath(DEST$, "HIIP\LOADERS"), cmoNone
	CreateDir MakePath(DEST$, "HIIP\SAVERS"), cmoNone
	CreateDir MakePath(DEST$, "OUTPUT"), cmoNone
    END IF
    IF (GetListItem(CHECKSTATES$, OPTFILES1) = "ON") OR (GetListItem(CHECKSTATES$, OPTFILES2) = "ON") THEN
	CreateDir MakePath(DEST$, "IMAGES"), cmoNone
	CreateDir MakePath(DEST$, "IMAGES\STAMPS"), cmoNone
	IF GetListItem(CHECKSTATES$, OPTFILES1) = "ON" THEN
	    CreateDir MakePath(DEST$, "TJ_PROJS"), cmoNone
	END IF
	IF GetListItem(CHECKSTATES$, OPTFILES2) = "ON" THEN
	    CreateDir MakePath(DEST$, "ER_PROJS"), cmoNone
	    CreateDir MakePath(DEST$, "SHAPES"), cmoNone
	END IF
    END IF

    '' This is to speed up testing -- says "don't copy files"
    ''cm% = SetCopyMode(0)

    CopyFilesInCopyList

    IF (GetListItem(CHECKSTATES$, APPFILES) = "ON") OR (GetListItem(CHECKSTATES$, OPTFILES1) = "ON") THEN
	IF GetListItem(CHECKSTATES$, APPFILES) = "ON" THEN
	    j1% = Serialize(hWnd%, MakePath(DEST$, "PROGRAMS\ER.EXE"), USERNAME$, ORGNAME$, SERIAL, 0)
	    CreateRegKeyValue "ereality", "Elastic Reality"
	    CreateRegKeyValue "ereality\shell\open\command", "er.exe %1"
	    CreateRegKeyValue ".er", "ereality"
	END IF
	IF GetListItem(CHECKSTATES$, OPTFILES1) = "ON" THEN
	    j1% = Serialize(hWnd%, MakePath(DEST$, "PROGRAMS\TRNSJMMR.EXE"), USERNAME$, ORGNAME$, SERIAL, 1)
	    CreateRegKeyValue "transjammer", "TransJammer"
	    CreateRegKeyValue "transjammer\shell\open\command", "trnsjmmr.exe %1"
	END IF

	''Minimize window
	j1% = ShowWindow(hWnd%, SW_SHOWMINIMIZED)

	CreateProgmanGroup "Elastic Reality", "", cmoNone
	ShowProgmanGroup  "Elastic Reality", 1, cmoNone
	IF GetListItem(CHECKSTATES$, APPFILES) = "ON" THEN
	    CreateProgmanItem "Elastic Reality", "Elastic Reality", MakePath(DEST$, "PROGRAMS\ER.EXE"), ",,,," + MakePath(DEST$, "ER_PROJS"), cmoOverwrite
	END IF
	IF GetListItem(CHECKSTATES$, OPTFILES1) = "ON" THEN
	    CreateProgmanItem "Elastic Reality", "TransJammer", MakePath(DEST$, "PROGRAMS\TRNSJMMR.EXE"), ",,,," + MakePath(DEST$, "TJ_PROJS"), cmoOverwrite
	END IF
	CreateProgmanItem "Elastic Reality", "Elastic Reality ReadMe", "NOTEPAD.EXE " + MakePath(DEST$, "PROGRAMS\README.TXT"), "", cmoOverwrite

	''Maximize window
	j1% = ShowWindow(hWnd%, SW_SHOWMAXIMIZED)

	'' Now we want to modify the system "win.ini" file under 3.1, so we'll
	'' want to prompt the user about it. We'll also be making a backup
	'' of the existing .INI file under 3.1
	GOSUB UPDATEWININI
    END IF

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

ERRQUIT:
    i% = DoMsgBox("Setup sources were corrupted, call Elastic Reality tech. support (608) 273-6585", "Setup Message", MB_OK+MB_TASKMODAL+MB_ICONHAND)
    END



GETPATH:
    SetSymbolValue "EditTextIn", DEST$
    SetSymbolValue "EditFocus", "ALL"
GETPATHL1:
    sz$ = UIStartDlg(CUIDLL$, DESTPATH, "FEditDlgProc", APPHELP, HELPPROC$)

    IF sz$ = "CONTINUE" THEN
        olddest$ = DEST$
        DEST$ = GetSymbolValue("EditTextOut")

        ''Validate new path.
        IF IsDirWritable(DEST$) = 0 THEN
            GOSUB BADPATH
            GOTO GETPATHL1
        END IF
        UIPop 1

        ''Truncate display if too long.
        IF LEN(DEST$) > 23 THEN
            ReplaceListItem DRIVETEXT$, 7, MID$(DEST$, 1, 23)+"..."
        ELSE
            ReplaceListItem DRIVETEXT$, 7, DEST$
        END IF

        ''Recalc if path changed.
        IF (olddest$ <> DEST$) AND (olddest$ <> DEST$+"\") AND (olddest$+"\" <> DEST$) THEN
            RecalcPath
            SetDriveStatus
        END IF

        olddest$ = ""
        GOTO CUSTINST
    ELSEIF sz$ = "REACTIVATE" THEN
        RecalcPath
        SetDriveStatus
        GOTO GETPATHL1
    ELSEIF sz$ = "EXIT" THEN
        GOSUB ASKQUIT
        GOTO GETPATHL1
    ELSE
        UIPop 1
        GOTO CUSTINST
    END IF


TOOBIG:
    '' Tell the user there's no room, but give them a chance to continue anyway
    sz$ = UIStartDlg(CUIDLL$, TOOBIG, "FInfoDlgProc", APPHELP, HELPPROC$)
    IF sz$ = "REACTIVATE" THEN
        RecalcPath
        SetDriveStatus
        GOTO TOOBIG
    ELSEIF sz$ = "CONTINUE" THEN
	UIPop 2
	GOTO NAMEORGSERIAL
    ELSE
	UIPop 1
	GOTO CUSTINST
    END IF

BADPATH:
    sz$ = UIStartDlg(CUIDLL$, BADPATH, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
        RecalcPath
        SetDriveStatus
        GOTO BADPATH
    END IF
    UIPop 1
    RETURN

ASKQUIT:
    sz$ = UIStartDlg(CUIDLL$, ASKQUIT, "FInfoDlgProc", 0, "")

    IF sz$ = "EXIT" THEN
        UIPopAll
        ERROR STFQUIT
    ELSEIF sz$ = "REACTIVATE" THEN
        GOTO ASKQUIT
    ELSE
        UIPop 1
    END IF
    RETURN

UPDATEWININI:
    UpdateIni% = 0
    IF OnWindowsNT() = 0 THEN
	IF IsDirWritable(DESTWIN$) <> 0 THEN
	    '' Ask the user if we should backup & modify the WIN.INI file.
	    sz$ = UIStartDlg(CUIDLL$, WININIMOD, "FInfoDlgProc", APPHELP, HELPPROC$)
	    IF sz$ = "REACTIVATE" THEN
	        GOTO UPDATEWININI
	    ELSEIF sz$ = "CONTINUE" THEN
		CopyFile DESTWIN$ + "WIN.INI", DESTWIN$ + "WININI.ERI", cmoOverwrite, 0
		UpdateIni% = 1
	    END IF
	    UIPop 1
	END IF
    ELSE
	UpdateIni% = 1
    END IF
    IF UpdateIni% <>0 THEN
	IF GetListItem(CHECKSTATES$, APPFILES) = "ON" THEN
	    CreateIniKeyValue "win.ini", "programs", "er.exe", MakePath(DEST$, "PROGRAMS\ER.EXE"), cmoOverwrite
	END IF
	IF GetListItem(CHECKSTATES$, OPTFILES1) = "ON" THEN
	    CreateIniKeyValue "win.ini", "programs", "trnsjmmr.exe", MakePath(DEST$, "PROGRAMS\TRNSJMMR.EXE"), cmoOverwrite
	END IF
    END IF
    RETURN


'**
'** Purpose:
'**     Adds the specified option files to the copy list.
'** Arguments:
'**     ftype%  - type of files to add, one of the following:
'**             APPFILES, OPTFILES1, OPTFILES2
'** Returns:
'**     none.
'*************************************************************************
SUB AddOptFilesToCopyList (ftype%) STATIC

    IF GetListItem(CHECKSTATES$, ftype%) = "ON" THEN
        SrcDir$ = GetSymbolValue("STF_SRCDIR")
        IF ftype% = APPFILES THEN
	    AddSectionFilesToCopyList "ERPROGRAMS", SrcDir$, MakePath(DEST$, "PROGRAMS")
        ELSEIF ftype% = OPTFILES1 THEN
	    AddSectionFilesToCopyList "TJPROGRAMS", SrcDir$, MakePath(DEST$, "PROGRAMS")
            AddSectionFilesToCopyList "TJPROJECTS", SrcDir$, MakePath(DEST$, "TJ_PROJS")
            AddSectionFilesToCopyList "TJIMAGES", SrcDir$, MakePath(DEST$, "IMAGES")
            AddSectionFilesToCopyList "TJSTAMPS", SrcDir$, MakePath(DEST$, "IMAGES\STAMPS")
        ELSEIF ftype% = OPTFILES2 THEN
            AddSectionFilesToCopyList "ERPROJECTS", SrcDir$, MakePath(DEST$, "ER_PROJS")
            AddSectionFilesToCopyList "ERIMAGES", SrcDir$, MakePath(DEST$, "IMAGES")
            AddSectionFilesToCopyList "ERSTAMPS", SrcDir$, MakePath(DEST$, "IMAGES\STAMPS")
            AddSectionFilesToCopyList "SHAPES", SrcDir$, MakePath(DEST$, "SHAPES")
        ELSEIF ftype% = REQFILES THEN
	    IF (GetListItem(CHECKSTATES$, APPFILES) = "ON") OR (GetListItem(CHECKSTATES$, OPTFILES1) = "ON") THEN
		AddSectionFilesToCopyList "PROGRAMS", SrcDir$, MakePath(DEST$, "PROGRAMS")
		AddSectionFilesToCopyList "HIIP", SrcDir$, MakePath(DEST$, "HIIP")
		AddSectionFilesToCopyList "LOADERS", SrcDir$, MakePath(DEST$, "HIIP\LOADERS")
		AddSectionFilesToCopyList "SAVERS", SrcDir$, MakePath(DEST$, "HIIP\SAVERS")
		IF OnWindowsNT() THEN
		    AddSectionFilesToCopyList "NTSYSFILES", SrcDir$, DESTWIN$ + "SYSTEM32"
		ELSE
		    AddSectionFilesToCopyList "SYSFILES", SrcDir$, DESTSYS$
		END IF
	    END IF
        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:
'**             APPFILES, OPTFILES1, OPTFILES2
'** Returns:
'**     none.
'*************************************************************************
SUB RecalcOptFiles (ftype%) STATIC
    CursorSave% = ShowWaitCursor()
    ClearCopyList
    AddOptFilesToCopyList ftype%

    fExtra% = 0
    IF ftype% = APPFILES THEN
        ListSym$ = APPNEEDS$
    ELSEIF ftype% = OPTFILES1 THEN
        ListSym$ = OPT1NEEDS$
        IF (GetListItem(CHECKSTATES$, OPTFILES1) = "ON") AND (GetListItem(CHECKSTATES$, APPFILES) <> "ON") THEN
            ''Add extra cost to Windows drive for ini/progman, etc.
            ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
            ReplaceListItem EXTRACOSTS$, ndrive%, WINDRIVECOST$
            fExtra% = 1
        END IF
    ELSEIF ftype% = OPTFILES2 THEN
        ListSym$ = OPT2NEEDS$
    ELSEIF ftype% = REQFILES THEN
        ListSym$ = REQNEEDS$
        IF (GetListItem(CHECKSTATES$, APPFILES) = "ON") OR (GetListItem(CHECKSTATES$, OPTFILES1) = "ON") THEN
            ''Add extra cost to Windows drive for ini/progman, etc.
            ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
            ReplaceListItem EXTRACOSTS$, ndrive%, WINDRIVECOST$
            fExtra% = 1
        END IF
    END IF

    StillNeed& = GetCopyListCost(EXTRACOSTS$, ListSym$, "")

    cost& = 0
    FOR i% = 1 TO 26 STEP 1
        cost&  = cost& + VAL(GetListItem(ListSym$, i%))
    NEXT i%
    ReplaceListItem STATUSTEXT$, ftype%, STR$(cost& / 1024) + " K"

    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 APPFILES
    RecalcOptFiles OPTFILES1
    RecalcOptFiles OPTFILES2
    RecalcOptFiles REQFILES

    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(APPNEEDS$, ndrive%)) + VAL(GetListItem(OPT1NEEDS$, ndrive%)) + VAL(GetListItem(OPT2NEEDS$, ndrive%)) + VAL(GetListItem(REQNEEDS$, 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, ""
        ReplaceListItem DRIVETEXT$, 6, ""
    ELSE
        ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
        cost& = VAL(GetListItem(APPNEEDS$, ndrive%)) + VAL(GetListItem(OPT1NEEDS$, ndrive%)) + VAL(GetListItem(OPT2NEEDS$, ndrive%)) + VAL(GetListItem(REQNEEDS$, ndrive%))
        IF cost& = 0 THEN
            ReplaceListItem DRIVETEXT$, 4, ""
            ReplaceListItem DRIVETEXT$, 5, ""
            ReplaceListItem DRIVETEXT$, 6, ""
        ELSE
            free& = GetFreeSpaceForDrive(WINDRIVE$)
            ReplaceListItem DRIVETEXT$, 4, WINDRIVE$ + ":"
            ReplaceListItem DRIVETEXT$, 5, STR$(cost& / 1024) + " K"
            ReplaceListItem DRIVETEXT$, 6, STR$(free& / 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

