'**************************************************************************
'*                       VfW 1.0 Setup
'**************************************************************************

'$INCLUDE 'setupapi.inc'
'$INCLUDE 'mscpydis.inc'    ''System
'$INCLUDE 'msdetect.inc'    ''Detects Avalilable Disk Space

''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 APPHELP2      = 1500
CONST APPHELP3      = 1700
CONST CHECK         = 2500
CONST SMALLDEST	    = 2100
CONST SMALLWIN      = 2200
CONST BADPATH       = 6400

''Bitmap ID
CONST LOGO = 1

''Disk Sizes
CONST OPT1_WIN = 1024000   '' 1 MB
CONST OPT1_DEST = 0

CONST OPT2_WIN = 1536000   '' 1.5 MB
CONST OPT2_DEST = 600000   '' 600KB

CONST OPT3_WIN = 1536000   '' 1.5 MB
CONST OPT3_DEST= 1024000   '' 1 MB

CONST WINDSURF = 1024000

GLOBAL AVISize&         '' File size for optional AVI Sample Files
GLOBAL File1
GLOBAL WantedWinSize&  '' Total Disk Size required for installation
GLOBAL WantedDestSize&  '' Total Disk Size required for installation

''File Types
GLOBAL DEST$        ''Default destination directory.
GLOBAL WINDRIVE$    ''Windows Drive Letter.
GLOBAL OPTCUR$      ''Option selection from option dialog.
GLOBAL CHECKSTATES$

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

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

    MajorVer% = GetWindowsMajorVersion()
    MinorVer% = GetWindowsMinorVersion()

    IF  MajorVer% < 3 OR (MajorVer% = 3 AND MinorVer% < 10) THEN
    i% = DoMsgBox("Microsoft Windows version 3.10 or greater is required for this software.  Please upgrade your version of Windows.", "Installation Problem", MB_OK+MB_TASKMODAL+MB_ICONHAND)
        END
    END IF

    SetBitmap CUIDLL$, LOGO
    SetTitle "Video for Windows 1.0"

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

    WINDRIVE$ = MID$(GetWindowsDir, 1, 1)
    DEST$ = WINDRIVE$ + ":\WINVIDEO"

    OPTCUR$ = "2"                         '' Set default option to Playback and Video Tools

WELCOME:
    sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", APPHELP, HELPPROC$)
    IF sz$ = "CONTINUE" THEN
        UIPop 1
WELCOMEL1:
    '' Get user and company name...
        IF InitSystem(1, "", 0) = 0 THEN
            GOSUB ASKQUIT
            GOTO WELCOMEL1
        END IF
    ELSE
        GOSUB ASKQUIT
        GOTO WELCOME
    END IF

'' Set the default value for the Sample Files RADIO Button.
    AddListItem "CheckItemsIn", "ON"

OPTION:
    SetSymbolValue "RadioDefault", OPTCUR$
OPTL1:
    sz$ = UIStartDlg(CUIDLL$, OPTIONS, "FRadioDlgProc", APPHELP2, HELPPROC$)
    OPTCUR$ = GetSymbolValue("ButtonChecked")

    IF sz$ = "CONTINUE" THEN
        UIPop(1)
    ELSEIF sz$ = "REACTIVATE" THEN
        GOTO OPTL1
    ELSE
        GOSUB ASKQUIT
        GOTO OPTION
    END IF

AVIFiles:
    sz$ = UIStartDlg(CUIDLL$, CHECK, "FCheckDlgProc", 0, "")

'' Re-set file selection based on the user selection in case she decides to go back
'' to the previous dialog box
    SetSymbolValue "CheckItemsIn", GetListItem("CheckItemsOut", 1)
''    AddListItem "CheckItemsIn", GetListItem("CheckItemsOut", 2)

    IF sz$ = "CONTINUE" THEN
        UIPop 1
    ELSEIF sz$ = "BACK" then
        UIPop 1
        GOTO OPTION
    ELSEIF sz$ = "REACTIVATE" THEN
        GOTO AVIFiles
    ELSE
        GOSUB ASKQUIT
    END IF

GETPATH:
    SetSymbolValue "EditTextIn", DEST$
    SetSymbolValue "EditFocus", "END"
GETPATHL1:
    sz$ = UIStartDlg(CUIDLL$, DESTPATH, "FEditDlgProc", APPHELP3, HELPPROC$)
    DEST$ = GetSymbolValue("EditTextOut")

    IF sz$ = "CONTINUE" THEN
        IF IsDirWritable(DEST$) = 0 THEN
            GOSUB BADPATH
            GOTO GETPATHL1
        END IF
        UIPop 1
    ELSEIF sz$ = "REACTIVATE" THEN
        GOTO GETPATHL1
    ELSEIF sz$ = "BACK" THEN
        UIPop 1
        GOTO AVIFiles
    ELSE
        GOSUB ASKQUIT
        GOTO GETPATH
    END IF

ClearCopyList

'' Settting Sample AVI Files to be copied
    SrcDir$ = GetSymbolValue("STF_SRCDIR")
    AVISize = 0
    File1 = 0

        IF GetListItem("CheckItemsOut", 1) = "ON" THEN
            AddSectionFilesToCopyList "AVI File1", SrcDir$, DEST$
            AVISize& = WINDSURF
        File1 = 1
        END IF

''Set disk size accorting to user selected option
        IF OPTCUR$ = "1" THEN
            WantedWinSize&=OPT1_WIN
        WantedDestSize&=OPT1_DEST
        ElseIf OPTCUR$ = "2" THEN
            WantedWinSize&=OPT2_WIN
        WantedDestSize&=OPT2_DEST
        Else
            WantedWinSize&=OPT3_WIN
        WantedDestSize&=OPT3_DEST
        End If

'' Calculate destination disk size requirements with the AVI Sample Files
        WantedDestSize& = WantedDestSize& + AVISize&

'' Get disk space for the Windows Drive
        DiskSize&=GetFreeSpaceForDrive(WINDRIVE$)

'' Check to see that there is enough space in the windows drive
    If WantedWinSize& > DiskSize& then
        GOSUB SMALLWIN
        GOTO GETPATH
    END IF

'' Get drive letter for the destination path
        Drive$=Mid$(DEST$,1,1)

'' Cet disk space for the destination path
        DiskSize&=GetFreeSpaceForDrive(Drive$)

'' Check to see that there is enough space in the destination drive
        If WantedDestSize& > DiskSize& then
            GOSUB SMALLDEST
            GOTO GETPATH
        End If

Install

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 the included support number", "Setup Problem", MB_OK+MB_TASKMODAL+MB_ICONHAND)
    END

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

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

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

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

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

'**
'** Purpose:
'**     Builds the copy list and performs all installation operations.
'** Arguments:
'**     none.
'** Returns:
'**     none.
'*************************************************************************
SUB Install STATIC

SrcDir$ = GetSymbolValue("STF_SRCDIR")
WinDir$ = GetWindowsDir()
WinSysDir$ = GetWindowsSysDir()

CreateDir DEST$, cmoNone

'' Setting up OLD files that need to be removed from the users computer
        AddSectionFilesToCopyList "Remove Files", SrcDir$, DEST$

'' Setting RUNTIME files to be copied
        AddSectionFilesToCopyList "VfW Runtime", SrcDir$, WinSysDir$
        AddSectionFilesToCopyList "MPlayer", SrcDir$, WinDir$

    IF File1 = 1 then
            AddSectionFilesToCopyList "Release Notes 1", SrcDir$, DEST$
    ELSE
            AddSectionFilesToCopyList "Release Notes", SrcDir$, DEST$
    END IF

        AddSectionFilesToCopyList "AVICodecs", SrcDir$, WinSysDir$

'' Seeting Media Browser, VidEdit and VidCap files to be copied (if appropriate)
        IF OPTCUR$ = "2" OR OPTCUR$ = "3" THEN
            AddSectionFilesToCopyList "MBrowser", SrcDir$, WinDir$
            AddSectionFilesToCopyList "MBrowser Bitmaps", SrcDir$, WinSysDir$
            AddSectionFilesToCopyList "VidEdit", SrcDir$, DEST$
            AddSectionFilesToCopyList "VidCap", SrcDir$, DEST$
        END IF

'' Seeting BitEdit, PalEdit and WaveEdit files to be copied (if appropriate)
        IF OPTCUR$ = "3" THEN
            AddSectionFilesToCopyList "BitEdit", SrcDir$, DEST$
            AddSectionFilesToCopyList "PalEdit", SrcDir$, DEST$
            AddSectionFilesToCopyList "WaveEdit", SrcDir$, DEST$
        END IF

'' Seeting Tools Support files to be copied (if appropriate)
        IF OPTCUR$ = "2" OR OPTCUR$ = "3" THEN
            CreateDir DEST$ + "\INCLUDE", cmoNone
            AddSectionFilesToCopyList "Tool Stuff", SrcDir$, WinSysDir$
            AddSectionFilesToCopyList "Include Files", SrcDir$, DEST$ + "\INCLUDE"
        END IF

CopyFilesInCopyList

''Updating WIN.INI and SYSTEM.INI
        CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.MSVC", "msvidc.drv", cmoOverwrite
        CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.RT21", "indeo.drv", cmoOverwrite
        CreateIniKeyValue "WIN.INI", "mci extensions", "avi", "AVIVideo", cmoOverwrite
        CreateIniKeyValue WinDir$ + "system.ini", "mci", "AVIVideo", "mciavi.drv", cmoOverwrite

        IF OPTCUR$ = "2" OR OPTCUR$ = "3" THEN
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Animals", "VFW_SAMPLES,\ANIMALS.MBR,vidclip.bmp,Video for Windows  Animals,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Funstuff_Animation", "VFW_SAMPLES,\ANIMATN.MBR,funclip.bmp,Video for Windows  Funstuff Animation,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__People_and_Places", "VFW_SAMPLES,\CANTFRGT.MBR,vidclip.bmp,Video for Windows  People and Places,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Environment", "VFW_SAMPLES,\ENVIRMNT.MBR,vidclip.bmp,Video for Windows  Environment,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Family", "VFW_SAMPLES,\FAMILY.MBR,vidclip.bmp,Video for Windows  Family,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Frontier", "VFW_SAMPLES,\FRONTIER.MBR,vidclip.bmp,Video for Windows  Frontier,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Global", "VFW_SAMPLES,\GLOBAL.MBR,vidclip.bmp,Video for Windows  Global,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Kids", "VFW_SAMPLES,\KIDS.MBR,vidclip.bmp,Video for Windows  Kids,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Funstuff_Larger_Samples", "VFW_SAMPLES,\LARGER.MBR,funclip.bmp,Video for Windows  Funstuff Larger Samples,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Leisure", "VFW_SAMPLES,\LEISURE.MBR,vidclip.bmp,Video for Windows  Leisure,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Landscape", "VFW_SAMPLES,\LNDSCAPE.MBR,vidclip.bmp,Video for Windows  Landscape,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Funstuff_Performances", "VFW_SAMPLES,\PERFORM.MBR,funclip.bmp,Video for Windows  Funstuff Performances,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Space", "VFW_SAMPLES,\SPACE.MBR,vidclip.bmp,Video for Windows  Space,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Funstuff_Sports", "VFW_SAMPLES,\SPORTS.MBR,funclip.bmp,Video for Windows  Funstuff Sports,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Transportation", "VFW_SAMPLES,\TRANSPTN.MBR,vidclip.bmp,Video for Windows  Transportation,Video for Windows CD-ROM",cmoOverwrite
            CreateIniKeyValue WinDir$ + "MBROWSER.INI", "Collections", "Video_for_Windows__Workers", "VFW_SAMPLES,\WORKERS.MBR,vidclip.bmp,Video for Windows  Workers,Video for Windows CD-ROM",cmoOverwrite
        End IF

Run ("regedit.exe /s " + MakePath(WinDir$, "mplayer.reg"))

'' Updating Progman Groups
        CreateProgmanGroup "Video for Windows 1.0", "", cmoNone
        ShowProgmanGroup  "Video for Windows 1.0", 1, cmoNone
'' Mplayer
        CreateProgmanItem "Video for Windows 1.0", "Media Player", MakePath(WinDir$, "mplayer.exe"), "", cmoOverwrite

    IF File1 = 1 then
            CreateProgmanItem "Video for Windows 1.0", "Windsurf Clip", MakePath(Dest$, "WndSurf1.avi"), "", cmoOverwrite
    END IF

'' Readme.txt
        CreateProgmanItem "Video for Windows 1.0", "Release Notes", MakePath(DEST$, "vfw1.wri"), "", cmoOverwrite

        IF OPTCUR$ = "2" OR OPTCUR$ = "3" THEN
'' Browser
            CreateProgmanGroup "Accessories", "", cmoNone
            ShowProgmanGroup  "Accessories", 1, cmoNone
            CreateProgmanItem "Accessories", "Media Browser", MakePath(WinDir$, "mbrowser.exe"), "", cmoOverwrite

'' VidEdit
            CreateProgmanItem "Video for Windows 1.0", "VidEdit", MakePath(DEST$,"videdit.exe"), "", cmoOverwrite
'' VidCap
            CreateProgmanItem "Video for Windows 1.0", "VidCap", MakePath(DEST$,"vidcap.exe"), "", cmoOverwrite
        END IF

        IF OPTCUR$ = "3" THEN
            CreateProgmanGroup "Multimedia Data Tools", "", cmoNone
            ShowProgmanGroup  "Multimedia Data Tools", 1, cmoNone
'' BitEdit
            CreateProgmanItem "Multimedia Data Tools", "BitEdit", MakePath(DEST$,"bitedit.exe"), "", cmoOverwrite
'' PlaEdit
            CreateProgmanItem "Multimedia Data Tools", "PalEdit", MakePath(DEST$,"paledit.exe"), "", cmoOverwrite
'' WaveEdit
            CreateProgmanItem "Multimedia Data Tools", "WaveEdit", MakePath(DEST$,"waveedit.exe"), "", cmoOverwrite
        END IF

Run ("profdisp.exe")

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

