'**************************************************************************
'*                   Peachtree Accounting For Windows Setup
'**************************************************************************

'$DEFINE DEBUG  ''Define for script development/debugging

'$INCLUDE 'setupapi.inc'
'$INCLUDE 'msdetect.inc'
DECLARE SUB _LoadPictControl LIB "Pict.dll" () 
DECLARE SUB ProgmanDeleteItem LIB "mscuistf.dll" ( szItem$ )

''Dialog ID's
CONST WELCOME      = 100
CONST WELCOME2     = 101
CONST ASKQUIT      = 200
CONST DESTPATH     = 300
CONST DESTPATH2    = 301
CONST EXITFAILURE  = 400
CONST EXITQUIT     = 600
CONST EXITSUCCESS  = 700
CONST OPTIONS      = 800
CONST APPHELP      = 900
CONST APPHELP1     = 901
CONST APPHELP2     = 902
CONST APPHELP3     = 903
CONST CUSTINST     = 6200
CONST TOOBIG       = 6300
CONST BILLBOARD1   = 1000
CONST BILLBOARD2   = 1101
CONST BILLBOARD3   = 1100
CONST BILLBOARD4   = 1200
CONST BILLBOARD5   = 6405
CONST BADPATHDLG   = 6400
CONST EGABILLBOARD1 = 6401
CONST EGABILLBOARD2 = 6402
CONST EGABILLBOARD3 = 6403
CONST EGABILLBOARD4 = 6403
CONST IDD_WARN_WIN30 = 103

''Bitmap ID
CONST LOGO         = 1

''File Types
CONST PROGFILES    = 1
CONST SMPLFILES    = 2
CONST FORMFILES    = 3
CONST TUTORFILES   = 4

GLOBAL DATADEST$    ''Default destination directory.
GLOBAL PROGDEST$    ''might be different from DATADEST$ if on a network.
GLOBAL WINDDEST$    ''location of the Windows System Directory
GLOBAL WINDRIVE$    ''Windows drive letter.

GLOBAL PeachINI$    ''The Peach.INI file.
GLOBAL PeachIniSect$ '' "Lib"
GLOBAL SYSINI$      ''The SYSTEM.INI file.
GLOBAL WININI$      ''The WIN.INI file.
GLOBAL INISECT$     ''Section in WIN.INI which contains our options.
GLOBAL UPGRADE$     ''Yes or no, depending on whether this is an upgrade.

''CustInst list symbol names
GLOBAL PROGNEEDS$    ''Option list costs per drive
GLOBAL SMPLNEEDS$
GLOBAL FORMNEEDS$
GLOBAL TUTORNEEDS$    '' For tutorial.
GLOBAL SPECNEEDS$
GLOBAL EXTRACOSTS$  ''List of extra costs to add per drive
GLOBAL BIGLIST$     ''List of option files cost calc results (boolean)
GLOBAL DoComplete%
GLOBAL DriveTooSmall%  '' SET in SetDriveStatus, and tested before install.

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


DECLARE SUB AddOptFilesToCopyList (ftype%)
DECLARE SUB RecalcOptFiles (ftype%)
DECLARE SUB RecalcPath
DECLARE SUB SetDriveStatus
DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING

INIT:
    '' Maximize the window
    CONST WS_VISIBLE=&H10000000
    CONST  WS_BORDER=&H00800000
    CONST WS_CLIPCHILDREN = &H02000000
    CONST GWL_STYLE = -16
    CONST SW_SHOWMAXIMIZED= 3
    DECLARE FUNCTION ShowWindow LIB "user.exe" (hWnd%, iShow%) AS INTEGER
    DECLARE FUNCTION SetWindowLong LIB "user.exe" (hWnd%, offset%, style&) AS LONG
    hWnd% = HwndFrame()
    xi&=SetWindowLong(hWnd%, GWL_STYLE, WS_VISIBLE+WS_BORDER+WS_CLIPCHILDREN)

    j% = ShowWindow(hWnd%, SW_SHOWMAXIMIZED)

    CUIDLL$   = "mscuistf.dll"          ''custom user interface dll
    HELPPROC$ = "FHelpDlgProc"          ''Help dialog procedure
    WININI$   = "WIN.INI"               ''WIN.INI file
    PeachIniSect$ = "Lib"
    INISECT$  = "PEACHW"                ''WIN.INI section for PAW
    DoComplete% = 0
    VersionOK% = 1

    IF 3 > GetWindowsMajorVersion(  ) THEN
        VersionOK% = 0
    END IF
    IF ( VersionOK% <> 0 ) THEN
        IF 0 = GetWindowsMinorVersion(  ) THEN
            VersionOK% = 0
        END IF
    END IF
    IF VersionOK% = 0 THEN
       sz$ = UIStartDlg(CUIDLL$, IDD_WARN_WIN30, "FInfoDlgProc", 0, "")
       UIPop 1
       STOP
    END IF

    SetBitmap CUIDLL$, LOGO
    SetTitle "Peachtree Accounting For Windows"

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

    WINDDEST$ = GetWindowsDir
    PeachINI$ = MakePath (WINDDEST$, "Peach.INI")     ''Peach.INI file
    SYSINI$   = MakePath (WINDDEST$, "SYSTEM.INI")     ''System.INI file
    WINDRIVE$ = MID$(WINDDEST$, 1, 1)
    WINDDEST$ = "                                                                 "
    REM make it 65 charactors long
    _% = GetSystemdirectory (WINDDEST$, 65)
    '' WINDDEST$ = MakePath (WINDDEST$, "SYSTEM")    ''the windows SYSTEM directory
    '' Don't need to do MakePath - we already have it.
    DATADEST$ = WINDRIVE$ + ":\PEACHW"            ''our default directory
    PROGDEST$ = DATADEST$

    ''Check and see if this is an installation or an upgrade.
    UPGRADE$ = ucase$ (GetIniKeyString (WININI$,INISECT$,"INSTALLED"))
    IF UPGRADE$ <> "YES" THEN
        '' UPGRADE$ = ucase$ (GetIniKeyString (PeachINI$, PeachIniSect$, "DATAPATH"))
        UPGRADE$ = ucase$ (GetIniKeyString (PeachINI$, "Install", "INSTALLED"))
        IF UPGRADE$ <> "" THEN
           UPGRADE$ = "YES"
        END IF
    END IF 
    
    IF UPGRADE$ <> "YES" THEN
       UPGRADE$ = "NO"
    END IF

    ''IF this is an upgrade, read the paths already stored
    IF UPGRADE$ = "YES" THEN
       IF DoesIniKeyExist (PeachINI$, "Install", "PROGRAMPATH") THEN
          PROGDEST$ = ucase$ (GetIniKeyString (PeachINI$, "Install", "PROGRAMPATH"))
       ELSE 
           IF DoesIniKeyExist (WININI$,INISECT$,"PROGRAMPATH") THEN
              PROGDEST$ = ucase$ (GetIniKeyString (WININI$,INISECT$,"PROGRAMPATH"))
           END IF
       END IF 
       StartProgDest$ = PROGDEST$   '' Use StartProgDest to tell if a user
                                    '' has changed the program dest by 
                                    '' hand.
       IF DoesIniKeyExist (PeachINI$, PeachIniSect$, "DATAPATH") THEN
          DATADEST$ = ucase$ (GetIniKeyString (PeachINI$, PeachIniSect$, "DATAPATH"))
       ELSE
           IF DoesIniKeyExist (WININI$,INISECT$,"DATAPATH") THEN
              DATADEST$ = ucase$ (GetIniKeyString (WININI$,INISECT$,"DATAPATH"))
           END IF
       END IF
    END IF

WELCOME:
    IF UPGRADE$ = "YES" THEN
       sz$ = UIStartDlg(CUIDLL$, WELCOME2, "FInfoDlgProc", APPHELP, HELPPROC$)
    ELSE
       sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", APPHELP, HELPPROC$)
    END IF
    IF sz$ = "CONTINUE" THEN
        UIPop 1
    ELSEIF Sz$ = "BACK" THEN
        UIPop 1
        DoComplete% = 1
    ELSE
        GOSUB ASKQUIT
        GOTO WELCOME
    END IF

    ''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 10 STEP 1
        AddListItem DRIVETEXT$, ""
    NEXT i%
    ReplaceListItem DRIVETEXT$, 7, DATADEST$

    ''Disk cost list symbols
    PROGNEEDS$  = "ProgNeeds"
    SMPLNEEDS$  = "SmplNeeds"
    FORMNEEDS$  = "FormNeeds"
    TUTORNEEDS$ = "TutorNeeds"
    SPECNEEDS$  = "SpecNeeds"
    EXTRACOSTS$ = "ExtraCosts"
    BIGLIST$    = "BigList"
    FOR i% = 1 TO 4 STEP 1
        AddListItem BIGLIST$, ""
    NEXT i%
    REM Initialize to zeros
    FOR i% = 1 TO 26 STEP 1
        AddListItem EXTRACOSTS$, "0"
    NEXT i%

    RecalcPath
    SetDriveStatus

'$IFDEF DEBUG
    i% = SetSizeCheckMode(scmOnIgnore)    '' could use scmOff; def = scmOnFatal
'$ENDIF ''DEBUG

    IF DoComplete% = 1  THEN
        FOR i% = 1 TO 4 STEP 1
            '' IF GetListItem(BIGLIST$, i%) <> "" THEN
            IF DriveTooSmall% <> 0 THEN
                nnn = DoMsgBox ("Your disk does not have enough room.", "Peachtree Accounting For Windows", MD_OK)
                GOTO CUSTINST
            END IF
        NEXT i%
        GOTO INSTALL
    END IF 
CUSTINST:
    sz$ = UIStartDlg(CUIDLL$, CUSTINST, "FCustInstDlgProc", APPHELP1, HELPPROC$)
    IF sz$ = "CONTINUE" THEN
        ''Install only if it will fit.
        FOR i% = 1 TO 4 STEP 1
            '' IF GetListItem(BIGLIST$, i%) <> "" THEN
            IF DriveTooSmall% <> 0 THEN
                GOSUB TOOBIG
                GOTO CUSTINST
            END IF
        NEXT i%
        UIPop 1
        GOTO INSTALL
    ELSEIF sz$ = "PATH" THEN
        GOTO GETPATH
    ELSEIF sz$ = "CHK1" THEN
        RecalcOptFiles PROGFILES
        SetDriveStatus
        GOTO CUSTINST
    ELSEIF sz$ = "CHK2" THEN
        RecalcOptFiles SMPLFILES
        SetDriveStatus
        GOTO CUSTINST
    ELSEIF sz$ = "CHK3" THEN
        RecalcOptFiles FORMFILES
        SetDriveStatus
        GOTO CUSTINST
    ELSEIF sz$ = "CHK4" THEN
        RecalcOptFiles TUTORFILES
        SetDriveStatus
        GOTO CUSTINST
''  ELSEIF sz$ = "BACK" THEN   '' removed on July 20, 1992 since there were
''      UIPop 1                '' some cases where it would not work
''      GOTO WELCOME
    ELSEIF sz$ = "REACTIVATE" THEN
        RecalcPath
        SetDriveStatus
        GOTO CUSTINST
    ELSE
        GOSUB ASKQUIT
        GOTO CUSTINST
    END IF

INSTALL:
    ClearCopyList
    AddOptFilesToCopyList PROGFILES
    AddOptFilesToCopyList SMPLFILES
    AddOptFilesToCopyList FORMFILES
    AddOptFilesToCopyList TUTORFILES
    '' SetDriveStatus
    '' IF DriveTooSmall% <> 0 THEN
    ''     GOSUB TOOBIG
    ''     GOTO CUSTINST
    '' END IF

    CreateDir DATADEST$, cmoNone
    CreateDir PROGDEST$, cmoNone
    IF GetListItem(CHECKSTATES$, SMPLFILES) = "ON" THEN
       CreateDir MakePath (DATADEST$, "BCS"), cmoNone
       CreateDir MakePath (DATADEST$, "SAMACCC"), cmoNone
       CreateDir MakePath (DATADEST$, "SAMRETC"), cmoNone
       CreateDir MakePath (DATADEST$, "SAMCONC"), cmoNone
       CreateDir MakePath (DATADEST$, "SAMMANC"), cmoNone
       CreateDir MakePath (DATADEST$, "SAMDISC"), cmoNone
       CreateDir MakePath (DATADEST$, "SAMFINC"), cmoNone
       CreateDir MakePath (DATADEST$, "SAMRESC"), cmoNone
       CreateDir MakePath (DATADEST$, "SAMPROPC"), cmoNone
       CreateDir MakePath (DATADEST$, "SAMSALSC"), cmoNone
       CreateDir MakePath (DATADEST$, "SAMMEDPC"), cmoNone
       '' CreateDir MakePath (DATADEST$, "SAMNONC"), cmoNone
       CreateDir MakePath (DATADEST$, "SAMSERC"), cmoNone
    END IF
    IF GetListItem( CHECKSTATES$, TUTORFILES ) = "ON" THEN
       CreateDir MakePath (DATADEST$, "TUTOR"), cmoNone
    END IF 

    '' Billboards
    _LoadPictControl
    IF 360 > GetScreenHeight( ) THEN    '' EGA
        AddToBillboardList "MSCUISTF.DLL", EGABILLBOARD1, "FModelessDlgProc", 50 
        AddToBillboardList "MSCUISTF.DLL", EGABILLBOARD2, "FModelessDlgProc", 50 
        AddToBillboardList "MSCUISTF.DLL", EGABILLBOARD3, "FModelessDlgProc", 50 
        AddToBillboardList "MSCUISTF.DLL", EGABILLBOARD4, "FModelessDlgProc", 50 
    ELSE                                '' Must be better than EGA
        AddToBillboardList "MSCUISTF.DLL", BILLBOARD1, "FModelessDlgProc", 50 
        AddToBillboardList "MSCUISTF.DLL", BILLBOARD2, "FModelessDlgProc", 50 
        AddToBillboardList "MSCUISTF.DLL", BILLBOARD3, "FModelessDlgProc", 50 
        AddToBillboardList "MSCUISTF.DLL", BILLBOARD4, "FModelessDlgProc", 50
    END IF
    SetCopyGaugePosition 55, 215
    CopyFilesInCopyList

    IF GetListItem(CHECKSTATES$, TUTORFILES) = "ON" THEN
        '' Make path file
        OpenLogFile MakePath( DATADEST$, "TUTOR\IAUTHOR.PTH" ), 0
        WriteToLogFile "@_ANIMATE_PATH"
        WriteToLogFile MakePath( DATADEST$, "TUTOR" )
        WriteToLogFile "@_AUDIO_PATH"
        WriteToLogFile MakePath( DATADEST$, "TUTOR" )
        WriteToLogFile "@_DATA_PATH"
        WriteToLogFile MakePath( DATADEST$, "TUTOR" )
        WriteToLogFile "@_GRAPHIC_PATH"
        WriteToLogFile MakePath( DATADEST$, "TUTOR" )
        WriteToLogFile "@_FORMAT_PATH"
        WriteToLogFile MakePath( DATADEST$, "TUTOR" )
        WriteToLogFile "@_ICONWARE_PATH"
        WriteToLogFile MakePath( DATADEST$, "TUTOR" )
        WriteToLogFile "@_INPUT_PATH"
        WriteToLogFile MakePath( DATADEST$, "TUTOR" )
        WriteToLogFile "@_LIB_PATH"
        WriteToLogFile MakePath( DATADEST$, "TUTOR" )
        WriteToLogFile "@_TEXT_PATH"
        WriteToLogFile MakePath( DATADEST$, "TUTOR" )
        WriteToLogFile "@_VARIABLE_PATH"
        WriteToLogFile MakePath( DATADEST$, "TUTOR" )
        WriteToLogFile "@_USER_PATH"
        WriteToLogFile MakePath( DATADEST$, "TUTOR" )
        CloseLogFile 
    END IF

    IF GetListItem(CHECKSTATES$, PROGFILES) = "ON" THEN
        CreateIniKeyValue PeachINI$, PeachIniSect$, "DATAPATH", DATADEST$, cmoOverwrite
        CreateIniKeyValue PeachINI$, PeachIniSect$, "BTRIEVE", "/M:50 /P:4096 /T:" + MakePath (DATADEST$, "BTRIEVE.TRN") + " /C /B:15 /F:50 /L:100 /N:15 /U:30", cmoOverwrite

        CreateIniKeyValue PeachINI$, "Install", "INSTALLED", "YES", cmoOverwrite
        CreateIniKeyValue PeachINI$, "Install", "PROGRAMPATH", PROGDEST$, cmoOverwrite

        CreateIniKeyValue SYSINI$, "386Enh", "UniqueDOSPSP", "True", cmoOverwrite

        IF UPGRADE$ = "NO" THEN
           CreateProgmanGroup "Peachtree Accounting", "", cmoNone
           ShowProgmanGroup   "Peachtree Accounting", 1, cmoNone
           CreateProgmanItem  "Peachtree Accounting", "Peachtree Accounting", MakePath(PROGDEST$,"PEACHW.EXE"), "", cmoOverwrite
        ELSEIF StartProgDest$ <> PROGDEST$ THEN
           CreateProgmanGroup "Peachtree Accounting", "", cmoNone
           ShowProgmanGroup   "Peachtree Accounting", 1, cmoNone
           CreateProgmanItem  "Peachtree Accounting", "Peachtree Accounting", MakePath(PROGDEST$,"PEACHW.EXE"), "", cmoOverwrite
        ELSE '' Installing to same place.
           CreateProgmanGroup "Peachtree Accounting", "", cmoNone
           ShowProgmanGroup   "Peachtree Accounting", 1, cmoNone
           ProgmanDeleteItem "PeachW 5.0"
           CreateProgmanItem  "Peachtree Accounting", "Peachtree Accounting", MakePath(PROGDEST$,"PEACHW.EXE"), "", cmoOverwrite
        END IF
    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:
    '' Delete old unused files.
    IF Exists( MakePath( DATADEST$, "T9901001.FRM" ) ) THEN
        KILL( MakePath( DATADEST$, "T9901001.FRM" ) )
    END IF
    sz$ = UIStartDlg(CUIDLL$, dlg%, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
        GOTO QUITL1
    ELSEIF dlg% = EXITSUCCESS THEN
        IF sz$ = "CONTINUE" THEN
            RUN "NOTEPAD " + MakePath (DATADEST$, "Readme.TXT"), NOWAIT
        ELSEIF sz$ = "BACK" THEN
            RUN MakePath( PROGDEST$, "PEACHW"), NOWAIT
        END IF
    END IF
    UIPop 1
    END

ERRQUIT:
    i% = DoMsgBox("Setup sources were corrupted!", "Setup Message", MB_OK+MB_TASKMODAL+MB_ICONHAND)
    END



GETPATH:
    SetSymbolValue "EditTextIn", DATADEST$
    SetSymbolValue "EditFocus", "END"
GETPATHL1:
    sz$ = UIStartDlg(CUIDLL$, DESTPATH, "FEditDlgProc", APPHELP2, HELPPROC$)

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

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

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

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

        olddest$ = ""
        GOSUB GETPATH2
        IF sz$ = "BACK" THEN   ''other cases handled inside subroutine
           GOTO GETPATH
        ELSE
           GOTO CUSTINST
        END IF
    ELSEIF sz$ = "REACTIVATE" THEN
        RecalcPath
        SetDriveStatus
        GOTO GETPATHL1
    ELSEIF sz$ = "EXIT" THEN
        GOSUB ASKQUIT
        GOTO GETPATHL1
    ELSE
        UIPop 1
        GOTO CUSTINST
    END IF


GETPATH2:
    olddest$ = PROGDEST$
    PROGDEST$ = DATADEST$
    drive$ = MID$(DATADEST$, 1, 1)
    IF IsDriveNetwork (drive$) THEN
       SetSymbolValue "EditTextIn", PROGDEST$
       SetSymbolValue "EditFocus", "END"
GETPATH2b:
       sz$ = UIStartDlg(CUIDLL$, DESTPATH2, "FEditDlgProc", APPHELP3, HELPPROC$)

       IF sz$ = "CONTINUE" THEN
           PROGDEST$ = ucase$ (GetSymbolValue("EditTextOut"))

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

       ELSEIF sz$ = "REACTIVATE" THEN
           RecalcPath
           SetDriveStatus
           GOTO GETPATH2b
       ELSEIF sz$ = "EXIT" THEN
           GOSUB ASKQUIT
           GOTO GETPATH2b
       ELSE
           UIPop 1
       END IF
    END IF
           ''Recalc if path changed.
    IF (olddest$ <> PROGDEST$) AND (olddest$ <> PROGDEST$+"\") AND (olddest$+"\" <> PROGDEST$) THEN
       RecalcPath
       SetDriveStatus
    END IF
    olddest$ = ""
    RETURN

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



BADPATH:
    sz$ = UIStartDlg(CUIDLL$, BADPATHDLG, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
        RecalcPath
        SetDriveStatus
        GOTO BADPATH
    END IF
    UIPop 1
    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:
'**             PROGFILES, SMPLFILES, FORMFILES, TUTORFILES
'** Returns:
'**     none.
'*************************************************************************
SUB AddOptFilesToCopyList (ftype%) STATIC

    IF GetListItem(CHECKSTATES$, ftype%) = "ON" THEN
        SrcDir$ = GetSymbolValue("STF_SRCDIR")
        IF ftype% = PROGFILES THEN
            AddSectionFilesToCopyList "Program", SrcDir$, PROGDEST$
            '' AddSectionFilesToCopyList "WProgram", SrcDir$, WINDDEST$
            AddSectionFilesToCopyList "Help", SrcDir$, DATADEST$
            AddSectionFilesToCopyList "Vital Data", SrcDir$, DATADEST$
            AddSectionFilesToCopyList "HelpProg", SrcDir$, GetWindowsDir
        ELSEIF ftype% = SMPLFILES THEN
            AddSectionFilesToCopyList "Sample Data", SrcDir$, DATADEST$
        ELSEIF ftype% = FORMFILES THEN
            AddSectionFilesToCopyList "Forms", SrcDir$, DATADEST$
        ELSEIF ftype% = TUTORFILES THEN
            TUTORPATH$ = MakePath( DATADEST$, "TUTOR" )
            AddSectionFilesToCopyList "Tutor", SrcDir$, TUTORPATH$
        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:
'**             PROGFILES, SMPLFILES, FORMFILES, TUTORFILES
'** Returns:
'**     none.
'*************************************************************************
SUB RecalcOptFiles (ftype%) STATIC
    CursorSave% = ShowWaitCursor()
    ClearCopyList
    AddOptFilesToCopyList ftype%

    fExtra% = 0
    IF ftype% = PROGFILES THEN
        ListSym$ = PROGNEEDS$
        IF GetListItem(CHECKSTATES$, PROGFILES) = "ON" THEN
            ''Add extra cost to Windows drive for ini/progman, etc.
            ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
            ReplaceListItem EXTRACOSTS$, ndrive%, "10240"
            fExtra% = 1
        END IF
    ELSEIF ftype% = SMPLFILES THEN
        ListSym$ = SMPLNEEDS$
    ELSEIF ftype% = FORMFILES THEN
        ListSym$ = FORMNEEDS$
    ELSEIF ftype% = TUTORFILES THEN
        ListSym$ = TUTORNEEDS$
    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 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 PROGFILES
    RecalcOptFiles SMPLFILES
    RecalcOptFiles FORMFILES
    RecalcOptFiles TUTORFILES

    RestoreCursor CursorSave%
END SUB


'**
'** Purpose:
'**     Sets drive status info according to latest disk space calcs.
'** Arguments:
'**     none.
'** Returns:
'**     none.
'*************************************************************************
SUB SetDriveStatus STATIC
    DriveTooSmall% = 0
    drive$ = MID$(DATADEST$, 1, 1)
    ndrive% = ASC(ucase$(drive$)) - ASC("A") + 1
    cost& = VAL(GetListItem(PROGNEEDS$, ndrive%)) 
    cost& = cost& + VAL(GetListItem(SMPLNEEDS$, ndrive%)) 
    cost& = cost&+ VAL(GetListItem(FORMNEEDS$, ndrive%))
    cost& = cost&+ VAL(GetListItem(TUTORNEEDS$, ndrive%))
    free& = GetFreeSpaceForDrive(drive$)
    DataDriveSpace& = cost& - free&
    IF DataDriveSpace& >= 0 THEN  '' Allow 100K work space.
        DriveTooSmall% = 1
    END IF

    WinDriveSpace&  = 0
    ProgDriveSpace& = 0

    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(PROGNEEDS$, ndrive%))
        cost& = cost& + VAL(GetListItem(SMPLNEEDS$, ndrive%)) 
        cost& = cost& + VAL(GetListItem(FORMNEEDS$, ndrive%))
        cost& = cost& + VAL(GetListItem(TUTORNEEDS$, ndrive%))
        IF cost& = 0 THEN
            ReplaceListItem DRIVETEXT$, 4, ""
            ReplaceListItem DRIVETEXT$, 5, ""
            ReplaceListItem DRIVETEXT$, 6, ""
        ELSE
            free& = GetFreeSpaceForDrive(WINDRIVE$)
            WinDriveSpace& = cost& - free&
            IF WinDriveSpace& >= 1 THEN  '' Allow 100K work space.
                DriveTooSmall% = 1
            END IF
            ReplaceListItem DRIVETEXT$, 4, WINDRIVE$ + ":"
            ReplaceListItem DRIVETEXT$, 5, STR$(cost& / 1024) + " K"
            ReplaceListItem DRIVETEXT$, 6, STR$(free& / 1024) + " K"
        END IF
    END IF

    IF drive$ = MID$(PROGDEST$, 1, 1) THEN
        ReplaceListItem DRIVETEXT$, 8, ""
        ReplaceListItem DRIVETEXT$, 9, ""
        ReplaceListItem DRIVETEXT$, 10, ""
    ELSE
        drive$ = MID$(PROGDEST$, 1, 1)
        ndrive% = ASC(ucase$(drive$)) - ASC("A") + 1
        cost& = VAL(GetListItem(PROGNEEDS$, ndrive%)) 
        cost& = cost& + VAL(GetListItem(SMPLNEEDS$, ndrive%)) 
        cost& = cost& + VAL(GetListItem(FORMNEEDS$, ndrive%))
        cost& = cost& + VAL(GetListItem(TUTORNEEDS$, ndrive%))
        IF cost& = 0 THEN
            ReplaceListItem DRIVETEXT$, 8, ""
            ReplaceListItem DRIVETEXT$, 9, ""
            ReplaceListItem DRIVETEXT$, 10, ""
        ELSE
            free& = GetFreeSpaceForDrive(drive$)
            ProgDriveSpace& = cost& - free&
            IF ProgDriveSpace& >= 100000 THEN  '' Allow 100K work space.
                DriveTooSmall% = 1
            END IF
            ReplaceListItem DRIVETEXT$, 8, drive$ + ":"
            ReplaceListItem DRIVETEXT$, 9, STR$(cost& / 1024) + " K"
            ReplaceListItem DRIVETEXT$, 10, 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

