'**************************************************************************
'*                   Brio Technology Brio Publish Setup
'**************************************************************************

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

'$INCLUDE 'setupapi.inc'
'$INCLUDE 'msdetect.inc'

''Dialog ID's
''   These values match the ID's used in dlgedit.
CONST WELCOME     = 100
CONST ASKQUIT     = 200
CONST DESTPATH    = 300
CONST EXITFAILURE = 400
CONST EXITQUIT    = 600
CONST EXITSUCCESS = 700
CONST PUBLISHHELP = 4000
CONST BADPATH     = 6400
CONST EXTENDEDLIST = 3900
CONST MULTILIST    = 5200
CONST ODBC_LIST    = 4400
CONST ODBC_HELP    = 4500
CONST OPTIONS      = 800
CONST FRAME_ERROR  = 4100
CONST ODBC_ERROR   = 4200
CONST MULTI_HELP   = 4300
CONST FRAMEPATH    = 4600
CONST FRAME_HELP   = 4700
CONST CONFIRM	   = 4900
CONST CONFIRM_HELP = 4800
CONST WHEREPATH	   = 5100
CONST WFRAME_HELP  = 5300
CONST INI_ERROR	   = 5400

''Bitmap ID
CONST LOGO              = 1
CONST C_DRIVE           = "c:\"
CONST BRIOPUBLISH       = "bpublish.exe"
CONST FRAMEMAKER        = "frame.exe"
CONST FMHOME_KEY        = "FMHOME"
CONST FRAME4_SECT       = "FrameMaker4" 
CONST WIN_INI           = "win.ini"
CONST INI_KEY           = "INIFILE"

CONST PUBLISH_VALUE     = "Startup, The Database Publishing Tool for FrameMaker 4, fminit\bpmodule.dll"
CONST LESSON_SECTION    = "BrioPublish Lessons"
CONST LESSON_DESC       = "Files for Lessons in BrioPublish manual"

CONST INSTALL_DESC	= "Installable ISAMS"
CONST DBASE_SECT	= "dBase4"
CONST DBASE_KEY		= "xbs110.dll"
CONST DBASE_DESC	= "dBase ISAM"
CONST COLLATE_SECT	= "CollatingSequence"
CONST COLLATE_KEY	= "ASCII"
CONST DELETE_SECT	= "Deleted"
CONST DELETE_KEY	= "On"
CONST STAT_SECT		= "Statistics"
CONST STAT_KEY		= "Lie"
CONST NET_SECT		= "NetworkAccess"
CONST NET_KEY		= "On"
CONST PAGE_SECT		= "PageTimeout"
CONST PAGE_KEY		= "600"

CONST DIRECTORIES	= "Directories"
CONST PALETTE_DIR	= "PaletteDir"
CONST BPHELP_INSERT	= "help\bpublish"
CONST BPHELP_APPEND	= ",help\bpublish"

CONST DRIVER_DLL        = "Simba.dll"
CONST SETUP_DLL         = "Simadmin.dll"
CONST SETUP             = "Setup"
CONST DRIVER            = "Driver"
CONST ODBC_DRIVERS      = "ODBC Drivers"
CONST INSTALLED         = "Installed"
CONST MMCPL             = "MMCPL"
CONST ODBC              = "ODBC"

CONST ACCESS            = "Access Data (*.mdb)"
CONST BTRIEVE           = "Btrieve Data (file.ddf)"
CONST DBASE             = "dBase Files (*.dbf)"
CONST EXCEL             = "Excel Files (*.xls)"
CONST FOXPRO            = "FoxPro Files (*.dbf)"
CONST PARADOX           = "Paradox Files (*.db )"
CONST TEXT              = "Text Files (*.txt; *.csv)"

CONST C1_PUBLISH        = "BrioPublish Application"
CONST C2_MODULE         = "BrioPublish Module for FrameMaker 4"
CONST C3_HELP           = "BrioPublish Help Files"
CONST C4_LESSONS        = "BrioPublish Lesson Files via ODBC"
CONST C5_ODBC           = "ODBC Drivers"

CONST C1_ACCESS         = "Access Driver"
CONST C2_BTRIEVE        = "Btrieve Driver"
CONST C3_DBASE          = "dBase Driver"
CONST C4_EXCEL          = "Excel Driver"
CONST C5_FOXPRO         = "FoxPro Driver"
CONST C6_PARADOX        = "Paradox Driver"
CONST C7_TEXT           = "Text Driver"

GLOBAL CHOICELIST$      '' list of Publish files to install
GLOBAL ODBCLIST$        '' List of ODBC drivers to install
GLOBAL DEST$            '' Default destination directory.
GLOBAL SZINF$           '' .inf file name
GLOBAL BACKSET$         '' User chose to Go Back 
GLOBAL EXITSET$         '' User chose to Exit
GLOBAL FRAMEEXE$        '' Directory where frame4.exe is found
GLOBAL DBASEINSTALLED%  '' Lets me know if dBase got installed
GLOBAL CUIDLL$          '' Bitmap DLL
GLOBAL HELPPROC$        '' Help Dialog procedure
GLOBAL SZSRC$           '' Source directory

GLOBAL WinDir$          '' Windows directory
GLOBAL WinSysDir$       '' Windows System directory
GLOBAL FrameDir$        '' Directory where frame exists

DECLARE SUB AskQuitSub
DECLARE SUB FrameErrorSub
DECLARE SUB FrameIniErrorSub
DECLARE SUB GetPathSub
DECLARE SUB QuitSetupSub
DECLARE SUB OdbcErrorSub
DECLARE SUB BadPathSub
DECLARE SUB CreateGroupSub
DECLARE SUB InstallListSub
DECLARE SUB InstallODBCSub
DECLARE SUB InstallDbaseSub

DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING
DECLARE FUNCTION AskForFrameDir () AS INTEGER
DECLARE FUNCTION AskWhereFrameDir () AS INTEGER
DECLARE FUNCTION ConfirmFrameDir () AS INTEGER
DECLARE FUNCTION GetDir (FileName$) AS STRING


	'' 
	''  Set up the known directories needed for BrioPublish  Setup.
INIT:
    CUIDLL$ = "btdpsui.dll"             ''Custom user interface dll
    HELPPROC$ = "FHelpDlgProc"          ''Help dialog procedure

    DEST$ = "c:\bpublish"

    szRet = SetDecompMode (1)           ''Decompress files if they need to be 

    SetBitmap CUIDLL$, LOGO
	SetTitle "Brio Technology's BrioPublish Setup"

    SZINF$ = GetSymbolValue("STF_SRCINFPATH")
    IF SZINF$ = "" THEN
	    SZINF$ = GetSymbolValue("STF_CWDDIR") + "BPUBLISH.INF"
    END IF

    ReadInfFile SZINF$                  ''Read the publish.inf file.


WELCOME:
    sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", PUBLISHHELP, HELPPROC$)
    IF sz$ = "CONTINUE" THEN
	UIPop 1
    ELSE
	AskQuitSub
	GOTO WELCOME
    END IF
    GetPathSub
    GOTO QUIT
    END

QUIT:
    END     

 
'*************************************************************************
'** Purpose: Get the Path to install into.
'*************************************************************************
SUB GetPathSub STATIC

GETPATH:

    SetSymbolValue "EditTextIn", DEST$
    SetSymbolValue "EditFocus", "END"
	
GETPATHL1:

    sz$ = UIStartDlg(CUIDLL$, DESTPATH, "FEditDlgProc", PUBLISHHELP, HELPPROC$)
    DEST$ = GetSymbolValue("EditTextOut")

    IF sz$ = "CONTINUE" THEN
	IF IsDirWritable(DEST$) = 0 THEN
	    BadPathSub
	    GOTO GETPATHL1
	ELSE
	    UIPop 1 
	    InstallListSub
	END IF    
    ELSEIF sz$ = "REACTIVATE" THEN
	GOTO GETPATHL1
    ELSE
	AskQuitSub
	GOTO GETPATH
    END IF
    RemoveSymbol "EditTextIn"	'' remove so we can use a different one later
END SUB


'*************************************************************************
'** Purpose:  Figure out what the user wants to install. Make sure that
'**       FrameMaker 4 is installed and the all the appropriate
'**       directories are there.  Edit the maker.ini file and add
'**       a section with BrioPublish in it.
'*************************************************************************
SUB InstallListSub STATIC

INSTALL:

    SetSymbolValue "ListItemsIn", CHOICELIST$
    AddListItem "ListItemsIn", C1_PUBLISH
    AddListItem "ListItemsIn", C2_MODULE
    AddListItem "ListItemsIn", C3_HELP
    AddListItem "ListItemsIn", C4_LESSONS
    AddListItem "ListItemsIn", C5_ODBC

    '' make all the components the default
    SetSymbolValue "ListItemsOut", CHOICELIST$
    AddListItem "ListItemsOut", C5_ODBC
    AddListItem "ListItemsOut", C4_LESSONS
    AddListItem "ListItemsOut", C3_HELP
    AddListItem "ListItemsOut", C2_MODULE
    AddListItem "ListItemsOut", C1_PUBLISH

    sz$ = UIStartDlg(CUIDLL$, MULTILIST, "FMultiDlgProc", MULTI_HELP, HELPPROC$)
    
    IF sz$ = "CONTINUE" THEN

	DBASEINSTALLED% = 0     '' lets us know if Dbase got installed
	
	WinDir$ = GetWindowsDir()
	WinSysDir$ = GetWindowsSysDir()
	UIPop 1	
	''
	''  First see if win.ini has the FrameMaker section in it. If
	''  so, we can assume FrameMaker is installed.  If not, then 
	''  search for the frame.exe in the C drive.  If it is not 
	''  found, then ask the user which drive/directory to search
	''  in. The user will either say to exit (frame hasn't been
	''  installed yet), or they will enter the drive and path 
	''  to search for it.
	''
	prevCursorState% = ShowWaitCursor ()
	SZSRC$ = GetSymbolValue ("STF_SRCDIR")   ''Get source directory
	FrameDir$ = GetIniKeyString (WIN_INI, FRAME4_SECT, FMHOME_KEY)
	RestoreCursor prevCursorState%

	IF (FrameDir$ = "") THEN            
	    ''
	    ''  Search for Frame.exe in the C Drive.  If its
	    ''  not found, then ask the user where to start 
	    ''  searching.
	    ''
	    cursorState% = ShowWaitCursor()
	    FrameExe$ = FindFileInTree (FRAMEMAKER, C_DRIVE)
	    FrameDir$ = C_DRIVE		'' set this for now
	    RestoreCursor cursorState%
	    IF (FrameExe$ = "") THEN
	        UIPop 1
GETFRAMEPATH:
	        
	        DirFound% = AskForFrameDir () 
		IF (DirFound% = 0) THEN
ASKWHERE:
		    DirFound% = AskWhereFrameDir ()
	  	    IF (DirFound% = 0) THEN
			GOTO ASKWHERE		
	    	    END IF
		END IF
	    ELSE
		FrameDir$ = GetDir (FrameExe$)
	    END IF		
        END IF

        ''
    	''  If user has indicated not to go ahead with the
    	''  install and update of Frame files, then give an
    	''  error and get out.
    	''
    	OkToInstall% = ConfirmFrameDir ()
    	IF (OkToInstall% = 0) THEN
            UIPop 1
	    GOTO ASKWHERE	'' go and ask again where it is
   	END IF

	IF (FrameDir$ <> "") THEN	
	    ModuleDir$ = FrameDir$ + "\fminit"
	    DirExists% = DoesDirExist(ModuleDir$)
	
	    IF (DirExists% = 0) THEN
		UIPop 1
	        FrameErrorSub
		RETURN
	    END IF
	ELSE
	    FrameErrorSub   '' tell user to install Frame first
            RETURN    
        END IF

	''
	'' Get the maker.ini file from win.ini - if the path is
	'' not specified, then use the FrameDir$.
	''
	FrameIniFile$ = GetIniKeyString(WIN_INI, FRAME4_SECT, INI_KEY)
	IF (FrameIniFile$ = "") THEN
	    FrameIniFile$ = FindFileInTree ("maker.ini", FrameDir$)
	    IF (FrameIniFile$ = "") THEN 
		UIPop 1   
		FrameIniErrorSub
	 	RETURN
	    END IF
	ELSE
	    IF (MID$(FrameIniFile$, 2, 1) <> ":") THEN
	    	FrameIniFile$ = FrameDir$ + "\" + FrameIniFile$
	    END IF
	END IF
	
    	'' Framemaker 4 must be installed...
    	''
    	PublishInstalled% = 0      '' Did they choose Publish to install?
	 
    	'' Check to see which items the user decided to install.
    	'' For each item do what needs to be done..create directory, etc.
    	''
    	FOR i% = 1 TO GetListLength ("ListItemsOut") STEP 1
	    ListItem$ = GetListItem ("ListItemsOut", i%)
	    IF (ListItem$ = C1_PUBLISH) THEN
	
	    	CreateDir DEST$, cmoNone
	    	PublishInstalled% = 1
	    	AddSectionFilesToCopyList "DLL", SZSRC$, DEST$
				
	    ELSEIF (ListItem$ = C2_MODULE) THEN
	
	    	AddSectionFilesToCopyList "MODULE", SZSRC$, ModuleDir$
				
	    ELSEIF (ListItem$ = C3_HELP) THEN
	
	    	HelpDir$ = FrameDir$ + "\help"
	    	IF (DoesDirExist (HelpDir$) = 0) THEN
		    CreateDir HelpDir$, cmoNone
	    	ENDIF
	    	BpublishHelpDir$ = HelpDir$ + "\bpublish"
	    	IF (DoesDirExist (BpublishHelpDir$) = 0) THEN
		    CreateDir BpublishHelpDir$, cmoNone
	    	ENDIF
	    	AddSectionFilesToCopyList "HELP", SZSRC$, BpublishHelpDir$ 
		''
		'' Check to see if the Directories section exists.
		'' If so, then append the Brio Publish help dir, otherwise
		'' create the section.
		''
		IniExistsQ% = DoesIniKeyExist (FrameIniFile$, DIRECTORIES, PALETTE_DIR)
		IF (IniExistsQ% = 1) THEN
		    SectionStr$ = GetIniKeyString (FrameIniFile$, DIRECTORIES, PALETTE_DIR)
		    IniStr$ = SectionStr$ + BPHELP_APPEND
	    	    CreateIniKeyValue FrameIniFile$, DIRECTORIES, PALETTE_DIR, IniStr$, cmoOverwrite
		ELSE
		    CreateIniKeyValue FrameIniFile$, DIRECTORIES, PALETTE_DIR, BPHELP_INSERT, cmoNone
		END IF
	
	    ELSEIF (ListItem$ = C4_LESSONS) THEN
	
	   	CreateDir DEST$, cmoNone        '' just in case
	    	LessonDir$ = DEST$ + "\lessons"
	    	CreateDir LessonDir$, cmoNone
	   	DataDir$ = DEST$ + "\lessons\data"
	    	CreateDir DataDir$, cmoNone
		
	    	AddSectionFilesToCopyList "LESSONS", SZSRC$, LessonDir$
	    	AddSectionFilesToCopyList "LESSON_DATA", SZSRC$, DataDir$ 
	    	''
            	'' Install the dBASE Driver and ODBC
	    	''
	    	InstallDbaseSub
				
	    	ODBCIniFile$ = WinDir$ + "odbc.ini"
	    	Simba$ = WinSysDir$ + "simba.dll"
	    	CreateIniKeyValue ODBCIniFile$, "ODBC Data Sources", LESSON_SECTION, DBASE, cmoNone
	    	CreateIniKeyValue ODBCIniFile$, LESSON_SECTION, "Driver", Simba$, cmoNone
	    	CreateIniKeyValue ODBCIniFile$, LESSON_SECTION, "Description", LESSON_DESC, cmoNone
	    	CreateIniKeyValue ODBCIniFile$, LESSON_SECTION, "FileType", "dBase4", cmoNone
	    	CreateIniKeyValue ODBCIniFile$, LESSON_SECTION, "DataDirectory", DataDir$, cmoNone
	    	CreateIniKeyValue ODBCIniFile$, LESSON_SECTION, "SingleUser", "False", cmoNone
				
	    	OdbcDll$ = WinSysDir$ + "odbcinst.dll"
	    	ConstrolIniFile$ = WinDir$ + "control.ini"
	    	CreateIniKeyValue ConstrolIniFile$, "MMCPL", "ODBC", OdbcDll$, cmoNone
	    	DBASEINSTALLED% = 1

	    	ODBCIsamFile$ = WinDir$ + "odbcisam.ini"
	    	CreateIniKeyValue ODBCIsamFile$, INSTALL_DESC, DBASE_SECT, DBASE_KEY, cmoNone
	    	CreateIniKeyValue ODBCIsamFile$, DBASE_DESC, COLLATE_SECT, COLLATE_KEY, cmoNone
	    	CreateIniKeyValue ODBCIsamFile$, DBASE_DESC, DELETE_SECT, DELETE_KEY, cmoNone
	    	CreateIniKeyValue ODBCIsamFile$, DBASE_DESC, STAT_SECT, STAT_KEY, cmoNone
	    	CreateIniKeyValue ODBCIsamFile$, DBASE_DESC, NET_SECT, NET_KEY, cmoNone
	    	CreateIniKeyValue ODBCIsamFile$, DBASE_DESC, PAGE_SECT, PAGE_KEY, cmoNone
	
	    ELSEIF (ListItem$ = C5_ODBC) THEN
	    	UIPop 1
	    	InstallODBCSub
	    END IF
	NEXT i%
		
	CreateIniKeyValue FrameIniFile$, "APIClients", "BrioPublish", PUBLISH_VALUE, cmoNone
	CopyFilesInCopyList     '' Copy all the files
	
	IF (PublishInstalled = 1) THEN
	    CreateGroupSub       '' create program group for BrioPublish
	END IF
	
	QuitSetupSub

    ELSEIF sz$ = "BACK" THEN
	UIPop 1
	GetPathSub
    ELSE
	AskQuitSub
	GOTO INSTALL
    END IF

END SUB



'*************************************************************************
'** Purpose:
'**     Builds the copy list and performs all installation operations.
'*************************************************************************
SUB CreateGroupSub STATIC

    SrcDir$ = GetSymbolValue("STF_SRCDIR")

    ini$ = MakePath(DEST$, "BPublish.ini")

    CreateProgmanGroup "Brio Tools", "", cmoNone
    ShowProgmanGroup  "Brio Tools", 1, cmoNone
    CreateProgmanItem "Brio Tools", "BrioPublish 1.1", MakePath (DEST$, "bpublish.exe"), "", cmoOverwrite
    CreateProgmanItem "Brio Tools", "BrioPublish Readme", MakePath (DEST$, "readme.txt"), "", cmoOverwrite

END SUB



'*************************************************************************
'** Purpose:
'**     Display the dialog to ask for ODBC Drivers to install.
'**     Add selected drivers to the list.
'*************************************************************************
SUB InstallODBCSub STATIC

INSTALL_ODBC:

    SetSymbolValue "ListItemsIn", ODBCLIST$
    AddListItem "ListItemsIn", C1_ACCESS
    AddListItem "ListItemsIn", C2_BTRIEVE
    AddListItem "ListItemsIn", C3_DBASE
    AddListItem "ListItemsIn", C4_EXCEL
    AddListItem "ListItemsIn", C5_FOXPRO
    AddListItem "ListItemsIn", C6_PARADOX
    AddListItem "ListItemsIn", C7_TEXT

    '' make all the components the default
    SetSymbolValue "ListItemsOut", ODBCLIST$
    AddListItem "ListItemsOut", C7_TEXT
    AddListItem "ListItemsOut", C6_PARADOX
    AddListItem "ListItemsOut", C5_FOXPRO
    AddListItem "ListItemsOut", C4_EXCEL
    AddListItem "ListItemsOut", C3_DBASE
    AddListItem "ListItemsOut", C2_BTRIEVE
    AddListItem "ListItemsOut", C1_ACCESS

    sz$ = UIStartDlg(CUIDLL$, ODBC_LIST, "FMultiDlgProc", ODBC_HELP, HELPPROC$)

    OdbcInstIni$        = WinDir$ + "odbcinst.ini"
    OdbcDll$            = WinSysDir$ + "odbcinst.dll"
    ConstrolIniFile$    = WinDir$ + "control.ini"

    IF sz$ = "CONTINUE" THEN

	OdbcInfFile$ = WinSysDir$ + "odbc.inf"
	DriverDll$   = WinSysDir$ + DRIVER_DLL
	SetUpDll$    = WinSysDir$ + SETUP_DLL

	FOR i% = 1 TO GetListLength ("ListItemsOut") STEP 1

	    ListItem$ = GetListItem ("ListItemsOut", i%)
	    IF (ListItem$ = C1_ACCESS) THEN

		AddSectionFilesToCopyList "ODBCCommon", SZSRC$, WinSysDir$
		AddSectionFilesToCopyList "Access", SZSRC$, WinSysDir$
		AddSectionFilesToCopyList "MSJDLL", SZSRC$, WinSysDir$ 
		AddSectionFilesToCopyList "DrvrCommon", SZSRC$, WinSysDir$ 
	
		CreateIniKeyValue ConstrolIniFile$, MMCPL, ODBC, OdbcDll$, cmoNone
		CreateIniKeyValue OdbcInstIni$, ODBC_DRIVERS, ACCESS, INSTALLED, cmoNone
		CreateIniKeyValue OdbcInstIni$, ACCESS, DRIVER, DriverDll$, cmoNone
		CreateIniKeyValue OdbcInstIni$, ACCESS, SETUP, SetUpDll$, cmoNone
			
	    ELSEIF (ListItem$ = C2_BTRIEVE) THEN
	
		AddSectionFilesToCopyList "Btrieve", SZSRC$, WinSysDir$
		AddSectionFilesToCopyList "MSJDLL", SZSRC$, WinSysDir$ 
		AddSectionFilesToCopyList "DrvrCommon", SZSRC$, WinSysDir$ 
		AddSectionFilesToCopyList "ODBCCommon", SZSRC$, WinSysDir$ 
		   
		CreateIniKeyValue ConstrolIniFile$, MMCPL, ODBC, OdbcDll$, cmoNone
		CreateIniKeyValue OdbcInstIni$, ODBC_DRIVERS, BTRIEVE, INSTALLED, cmoNone
		CreateIniKeyValue OdbcInstIni$, BTRIEVE, DRIVER, DriverDll$, cmoNone
		CreateIniKeyValue OdbcInstIni$, BTRIEVE, SETUP, SetUpDll$, cmoNone

	    ELSEIF (ListItem$ = C3_DBASE) AND (DBASEINSTALLED% = 0) THEN

		InstallDbaseSub

	    ELSEIF (ListItem$ = C4_EXCEL) THEN

		AddSectionFilesToCopyList "Excel", SZSRC$, WinSysDir$
		AddSectionFilesToCopyList "DrvrCommon", SZSRC$, WinSysDir$ 
		AddSectionFilesToCopyList "ODBCCommon", SZSRC$, WinSysDir$ 
	
		CreateIniKeyValue ConstrolIniFile$, MMCPL, ODBC, OdbcDll$, cmoNone
		CreateIniKeyValue OdbcInstIni$, ODBC_DRIVERS, EXCEL, INSTALLED, cmoNone
		CreateIniKeyValue OdbcInstIni$, EXCEL, DRIVER, DriverDll$, cmoNone
		CreateIniKeyValue OdbcInstIni$, EXCEL, SETUP, SetUpDll$, cmoNone

	    ELSEIF (ListItem$ = C5_FOXPRO) THEN

		AddSectionFilesToCopyList "FoxPro", SZSRC$, WinSysDir$
		AddSectionFilesToCopyList "MSJDLL", SZSRC$, WinSysDir$ 
		AddSectionFilesToCopyList "XBSDLL", SZSRC$, WinSysDir$ 
		AddSectionFilesToCopyList "DrvrCommon", SZSRC$, WinSysDir$ 
		AddSectionFilesToCopyList "ODBCCommon", SZSRC$, WinSysDir$ 
	
		CreateIniKeyValue ConstrolIniFile$, MMCPL, ODBC, OdbcDll$, cmoNone
		CreateIniKeyValue OdbcInstIni$, ODBC_DRIVERS, FOXPRO, INSTALLED, cmoNone
		CreateIniKeyValue OdbcInstIni$, FOXPRO, DRIVER, DriverDll$, cmoNone
		CreateIniKeyValue OdbcInstIni$, FOXPRO, SETUP, SetUpDll$, cmoNone

	    ELSEIF (ListItem$ = C6_PARADOX) THEN

		AddSectionFilesToCopyList "Paradox", SZSRC$, WinSysDir$
		AddSectionFilesToCopyList "MSJDLL", SZSRC$, WinSysDir$ 
		AddSectionFilesToCopyList "DrvrCommon", SZSRC$, WinSysDir$ 
		AddSectionFilesToCopyList "ODBCCommon", SZSRC$, WinSysDir$ 
	
		CreateIniKeyValue ConstrolIniFile$, MMCPL, ODBC, OdbcDll$, cmoNone
		CreateIniKeyValue OdbcInstIni$, ODBC_DRIVERS, PARADOX, INSTALLED, cmoNone
		CreateIniKeyValue OdbcInstIni$, PARADOX, DRIVER, DriverDll$, cmoNone
		CreateIniKeyValue OdbcInstIni$, PARADOX, SETUP, SetUpDll$, cmoNone

	    ELSEIF (ListItem$ = C7_TEXT) THEN

		AddSectionFilesToCopyList "Text", SZSRC$, WinSysDir$
		AddSectionFilesToCopyList "DrvrCommon", SZSRC$, WinSysDir$ 
		AddSectionFilesToCopyList "ODBCCommon", SZSRC$, WinSysDir$ 
	
		CreateIniKeyValue ConstrolIniFile$, MMCPL, ODBC, OdbcDll$, cmoNone
		CreateIniKeyValue OdbcInstIni$, ODBC_DRIVERS, TEXT, INSTALLED, cmoNone
		CreateIniKeyValue OdbcInstIni$, TEXT, DRIVER, DriverDll$, cmoNone
		CreateIniKeyValue OdbcInstIni$, TEXT, SETUP, SetUpDll$, cmoNone

	    END IF
	NEXT i%
	UIPop 1
    ELSEIF (sz$ = "BACK") THEN
	UIPop 1
	InstallListSub  '' Back to first Installation list
    ELSE
	AskQuitSub
	GOTO INSTALL_ODBC       
    END IF

END SUB

'*************************************************************************
'** Purpose: Install Dbase.
'*************************************************************************
SUB InstallDbaseSub STATIC

    OdbcInstIni$        = WinDir$ + "odbcinst.ini"
    OdbcDll$            = WinSysDir$ + "odbcinst.dll"
    ConstrolIniFile$    = WinDir$ + "control.ini"
    DriverDll$          = WinSysDir$ + DRIVER_DLL
    SetUpDll$           = WinSysDir$ + SETUP_DLL

    AddSectionFilesToCopyList "dBASE", SZSRC$, WinSysDir$
    AddSectionFilesToCopyList "XBSDLL", SZSRC$, WinSysDir$ 
    AddSectionFilesToCopyList "MSJDLL", SZSRC$, WinSysDir$ 
    AddSectionFilesToCopyList "DrvrCommon", SZSRC$, WinSysDir$ 
    AddSectionFilesToCopyList "ODBCCommon", SZSRC$, WinSysDir$ 

    CreateIniKeyValue ConstrolIniFile$, MMCPL, ODBC, OdbcDll$, cmoNone
    CreateIniKeyValue OdbcInstIni$, ODBC_DRIVERS, DBASE, INSTALLED, cmoNone
    CreateIniKeyValue OdbcInstIni$, DBASE, DRIVER, DriverDll$, cmoNone
    CreateIniKeyValue OdbcInstIni$, DBASE, SETUP, SetUpDll$, cmoNone

END SUB


'*************************************************************************
'** Purpose:
'** Arguments: None
'** Returns: Returns just the path of the given file. c:\xxx - no backslash
'**          on the end of the path.
'*************************************************************************
FUNCTION GetDir (FileName$) STATIC AS STRING

    holdPos% = 1
    pos% = -1
    WHILE (pos% <> 0)
        pos% = InStr(holdPos%, FileName$, "\")
        IF (pos% <> 0) THEN
            holdPos% = pos% + 1 
        END IF 
    WEND
    
    GetDir = MID$(FileName$, 1, holdPos%-2)

END FUNCTION


'*************************************************************************
'** Purpose:
'**    Ask the user to enter the path to search for the Frame
'**    directory. 
'** Arguments: None
'** Returns: Path where Frame.exe exists.
'*************************************************************************
FUNCTION AskForFrameDir () STATIC AS INTEGER

ASKFORFRAMEDIR:
    
    SetSymbolValue "EditTextIn", FrameDir$
    SetSymbolValue "EditFocus", "END"
    
    sz$ = UIStartDlg(CUIDLL$, FRAMEPATH, "FEditDlgProc", FRAME_HELP, HELPPROC$)
    FrameDir$ = GetSymbolValue("EditTextOut")
 
    IF sz$ = "CONTINUE" THEN
	IF (FrameDir$ = "") THEN
	    i% = DoMsgBox("Please enter the path to start searching", "Setup Message", MB_OK+MB_TASKMODAL+MB_ICONHAND)
	    GOTO ASKFORFRAMEDIR
	END IF
	cursorState% = ShowWaitCursor()
	FrameExe$ = FindFileInTree (FRAMEMAKER, FrameDir$) 
	RestoreCursor cursorState%

	IF (FrameExe$ = "") THEN
	    AskForFrameDir = 0
	ELSE
	    FrameDir$ = GetDir(FrameExe$)
	    AskForFrameDir = 1    
	END IF
	UIPop 1
    ELSE		'' exit
        UIPop 1
	AskQuitSub
	GOTO ASKFORFRAMEDIR
    END IF
    RemoveSymbol "EditTextIn"
    
END FUNCTION
'*************************************************************************
'** Purpose:
'**    Ask the user again where to look for frame.exe.
'** Arguments: None
'** Returns: Path where Frame.exe exists.
'*************************************************************************
FUNCTION AskWhereFrameDir () STATIC AS INTEGER

WHEREPATH:

    SetSymbolValue "EditTextIn", FrameDir$
    SetSymbolValue "EditFocus", "END"
    
    sz$ = UIStartDlg(CUIDLL$, WHEREPATH, "FEditDlgProc", WFRAME_HELP, HELPPROC$)
    FrameDir$ = GetSymbolValue("EditTextOut")

    IF sz$ = "CONTINUE" THEN
	IF (FrameDir$ = "") THEN
	    i% = DoMsgBox("Please enter the path to start searching", "Setup Message", MB_OK+MB_TASKMODAL+MB_ICONHAND)
	    GOTO WHEREPATH
	END IF
	cursorState% = ShowWaitCursor()
	FrameExe$ = FindFileInTree (FRAMEMAKER, FrameDir$) 
	RestoreCursor cursorState%

	IF (FrameExe$ = "") THEN
	    AskWhereFrameDir = 0
	ELSE
	    FrameDir$ = GetDir(FrameExe$)
	    AskWhereFrameDir = 1
	END IF
	UIPop 1
    ELSE
	UIPop 1		'' exit
	AskQuitSub
	GOTO WHEREPATH
    END IF
    RemoveSymbol "EditTextIn"    
END FUNCTION

'*************************************************************************
'** Purpose:   Ask the user if its ok to update the win.ini file.
'** Arguments: Frame Directory to update win.ini in.
'** Returns:   Returns TRUE if OK to go ahead with install, FALSE otherwise.
'*************************************************************************
FUNCTION ConfirmFrameDir () STATIC AS INTEGER

CONFIRMFRAME:

    SetSymbolValue "EditTextIn", FrameDir$
    SetSymbolValue "EditFocus", "END"
    
    sz$ = UIStartDlg(CUIDLL$, CONFIRM, "FEditDlgProc", CONFIRM_HELP, HELPPROC$)
    FrameDir$ = GetSymbolValue("EditTextOut")

    IF sz$ = "CONTINUE" THEN
	IF (FrameDir$ = "") THEN
	    i% = DoMsgBox("Please enter the path to start searching", "Setup Message", MB_OK+MB_TASKMODAL+MB_ICONHAND)
	    GOTO CONFIRMFRAME
	END IF
	cursorState% = ShowWaitCursor()
	FrameExe$ = FindFileInTree (FRAMEMAKER, FrameDir$)	
	RestoreCursor cursorState%
	IF (FrameExe$ <> "") THEN
	    ConfirmFrameDir = 1
	ELSE
	    ConfirmFrameDir = 0
	END IF
    END IF
    UIPop 1 
    RemoveSymbol "EditTextIn"
END FUNCTION


'*************************************************************************
'** 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


'*************************************************************************
'** Purpose: Tell user path is invalid.
'*************************************************************************
SUB BadPathSub STATIC

BADPATH:

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

END SUB



'*************************************************************************
'** Purpose: Exit setup.
'*************************************************************************
SUB QuitSetupSub STATIC

    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 SUB
'*************************************************************************
'** Purpose: Display Error about FrameMaker maker.ini not found.
'*************************************************************************
SUB FrameIniErrorSub STATIC

    '' User needs to have the a maker.ini file 
    ''
    sz$ = UIStartDlg (CUIDLL$, INI_ERROR, "FInfo0DlgProc", 0, "")
    UIPopAll

END SUB



'*************************************************************************
'** Purpose: Display Error about FrameMaker not being installed.
'*************************************************************************
SUB FrameErrorSub STATIC

    '' User needs to install FrameMaker first before installing 
    '' BrioPublish.
    sz$ = UIStartDlg (CUIDLL$, FRAME_ERROR, "FInfo0DlgProc", 0, "")
    UIPopAll

END SUB


'*************************************************************************
'** Purpose: Display error about ODBC not installed correctly.
'*************************************************************************
SUB OdbcErrorSub STATIC

    ''  The Installation of ODBC failed
    ''
    sz$ = UIStartDlg (CUIDLL$, ODBC_ERROR, "FInfo0DlgProc", 0, "")
    UIPopAll 

END SUB


'*************************************************************************
'** Purpose: Ask the user if they want to exit setup.
'*************************************************************************
SUB AskQuitSub Static

    CUIDLL$ = "btdpsui.dll"             ''Custom user interface dll 
    sz$ = UIStartDlg(CUIDLL$, ASKQUIT, "FQuitDlgProc", 0, "")

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

END SUB

