'' $Keywords: setup2.mst 1.17 08Sep93 10:24am$ $nokeywords$
'**************************************************************************
'*                       CorelTools setup script
'**************************************************************************
''    Date         Name                Reason
''-------------------------------------------------------------------------
'' Feb 25 1992  Randall Mack    Modified from sample2.mst provided with
''                              Windows SDK 3.1 Beta.
'' Feb 5	1993	Ibrahim Sallam	Modified for Draw 4.0
'' Apr 24 1993	Ibrahim Sallam	Modified from Draw.mst Draw2.mst of Draw4
'' May 1  1993	Ibrahim Sallam	Merging Net.mst with cdrom.mst in one file setup2.mst


'$INCLUDE 'setupapi.inc'

''C functions
DECLARE SUB				InitializeInstall LIB "mscuistf.dll" (hInstance%, hMainWind% )
DECLARE SUB				ShutDownInstall LIB "mscuistf.dll"
DECLARE SUB				RegisterFont LIB "mscuistf.dll" (szFOTName$, szTTFName$) 
DECLARE SUB				FileChangeString LIB "mscuistf.dll" (szFile1$, szFile2$, szString1$, szString2$)
DECLARE SUB				FRecalcOptFiles LIB "mscuistf.dll" (iType%, szNeeds$)
DECLARE FUNCTION	FIsDrawExist LIB "mscuistf.dll" (szFileName$, szDest$) AS INTEGER
DECLARE FUNCTION	IsSectionKeyExist LIB "mscuistf.dll" (szSectionName$, szKeyName$) AS INTEGER
DECLARE SUB 			FAddFilesToList LIB "mscuistf.dll" (SectionName$, FiltersList$)
DECLARE SUB 			FAddFileToCopyList LIB "mscuistf.dll" (AppendSect$, Section$, FilterName$, SourceDir$, FiltersDir$) 
DECLARE SUB				CommentIniSection LIB "mscuistf.dll" (szFileName$, szTempFile$, szSection$, szPath$ )
DECLARE FUNCTION	GetFilenameFromPath LIB "mscuistf.dll" (szPath$) AS INTEGER
DECLARE FUNCTION	IsTTFEnabled LIB "mscuistf.dll" AS INTEGER
DECLARE SUB				InitScannerSelection LIB "mscuistf.dll" 
DECLARE FUNCTION	FGetScannerLine LIB "mscuistf.dll" (szScannerDir$) AS INTEGER
DECLARE SUB				CloseScannerSelection LIB "mscuistf.dll" 
DECLARE SUB				FModifyFile LIB "mscuistf.dll" (szFileName$, szList$, szWhere$) 
DECLARE FUNCTION	IsWinForWorkgroups LIB "mscuistf.dll" AS INTEGER
DECLARE SUB       MakeFontSectList LIB "mscuistf.dll"
DECLARE FUNCTION	VerifyNumber LIB "mscuistf.dll" (szSerialNumber$) AS INTEGER

'$INCLUDE 'setupvar.inc'

''Strings for loading string resources
GLOBAL szString$
CONST	 STRINGLEN =	128
szString$ = string$( STRINGLEN+1, 32 )

''setup main window
CONST LOGO							= 9100			''must match the constant in dialogs.h
SetTitle TR_TITLE
SetBitmap "mscuistf.dll", LOGO
InitializeInstall hinstFrame(), HwndFrame()		''corel style buttons; max window

'$INCLUDE 'msdetect.inc'

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

''Dialog ID's
''Note: These constants MUST match the constants in dialogs.h
CONST CDBASEDWELCOME    = 9941
CONST NETWELCOME        = 9942
CONST ASKQUIT    				= 9901
CONST DESTPATH   				= 9902
CONST ERROREXITFAILURE	= 9903
CONST EXITQUIT   				= 9904
CONST EXITSUCCESS				= 9905
CONST TOOBIG     				= 9908
CONST ERRORBADPATH   		= 9909
CONST SELECTFONTSYM			= 9917
CONST SELECTFONTTT			= 9918
CONST SELECTFONTTTCD		= 9821
CONST WAIT							= 9919
CONST CDBASEDABOUT			= 9952
CONST NETUSERABOUT			= 9951
CONST ASKINSTALL				= 9922
CONST WARNINGDESTPATH		= 9923
''CONST CUSTTTFONT				= 9924
CONST BILLBOARD					= 9926
CONST UPDATEHELP   		  = 9929
CONST UPDATEAUTOEXEC		= 9930
CONST UPDATEAUTOEXECFORSHARE		= 9931
CONST UPDATECONFIG			= 9934
CONST WAITREGISTER			= 9932
CONST SUCCESS						= 9938
CONST WAITCONFIGER			= 9939
CONST WINREADONLY				= 9943
CONST NETINSTWELCOME		= 9944
CONST NETADDITEMFAILED	= 9949
CONST NETADMINABOUT			= 9950
CONST NETEXITSUCCESS	  = 9948
CONST WELCOMEHELP				= 9800
CONST OPTIONSHELP				= 9801
CONST DESTPATHHELP   		= 9802
CONST SELECTHELP    		= 9806
CONST ASKINSTALLHELP		= 9808
CONST CUSTINSTHELP  		= 9803
CONST CUSTINSTCDBASED		= 9823
CONST CUSTSCAN          = 9815
CONST CUSTSCANHELP      = 9816
CONST REGISTRATION      = 9817
CONST REGISTRATIONBADNAME = 9818
CONST REGISTRATIONBADSN = 9819
CONST BILLBOARD1				= 9990
CONST MOREFONTS         = 9824

''Constants representing each line in the custinst dialog
CONST DRAW  		= 1
CONST CHART 		= 2
CONST SHOW			= 3
CONST PHOTO			= 4
CONST MOVE			= 5
CONST TRACE			= 6
CONST MOSAIC		= 7
CONST SCANNERS  = 8
CONST FILTERS		= 9			''Does not have custom dialog
CONST FONTTT		= 10
CONST NUMCUST	  = FONTTT
CONST MAIN			= NUMCUST + 1
CONST NUMGROUPS	= MAIN

CONST FALSE	= 0
CONST TRUE	= 1

'' used as values for afState(NUMCUST) array.
CONST ALL		= 1
CONST	SOME	= 2
CONST	NONE	= 3

''lists of reference keys for filters, fonts and symbols. 1 = install, 2 = don't
GLOBAL FONTLIST1$
FONTLIST1$		= "FontList1"
GLOBAL FONTLIST2$
FONTLIST2$		= "FontList2"

'' Scanners STUFF
GLOBAL SCANNERLINE$
SCANNERLINE$ = "ScannerLine"
GLOBAL CONFIGLINE$
CONFIGLINE$ = "ConfigLine"
GLOBAL AUTOEXECLINE$
AUTOEXECLINE$ = "AutoexecLine"
GLOBAL SCANNERSECTION$
SCANNERSECTION$ = "ScannerSection"


''information text for custom installation window
GLOBAL STATUSTEXT$
STATUSTEXT$  = "StatusItemsText"
GLOBAL DRIVETEXT$
DRIVETEXT$   = "DriveStatusText"
GLOBAL DrivesList$			''experemental variable for the drives list
DrivesList$ = "DrivesList"
GLOBAL TempList$				'' Used for Temp lists
TempList$ = "TempList"

''used as a parm to GetCopyListCost only
GLOBAL EXTRACOSTS$
EXTRACOSTS$ = "ExtraCosts"
GLOBAL bTooBig%
bTooBig% = FALSE
GLOBAL bBadPath%
bBadPath% = FALSE
GLOBAL bBack%
bBadPath% = FALSE
GLOBAL bFullInstall%		'' TRUE ==> user went through Full Install Option

GLOBAL bAutoexecModified% '' TRUE ==> Config.sys has beed modified.
bAutoexecModified% = FALSE

GLOBAL bDosScanner%	'' Did we install any Scanners? 
bDosScanner% = FALSE
GLOBAL bTwainScanner%	'' Did we install any Scanners? 
bTwainScanner% = FALSE

GLOBAL bInstallWorkstation%			'' Are we installing a network Workstation?

''list of sections (1..NUMGROUPS)
GLOBAL afState(NUMCUST) AS INTEGER		''list of selections for main options
GLOBAL DIR(NUMGROUPS) AS STRING        ''list of directories for main options
GLOBAL NUM(3) AS STRING								''string representations of 1 .. 3
''CustInst list of symbol names - each is a list of 26 numbers corresponding
''  to the space required on that numbered drive for the files in the
''  corresponding group
GLOBAL aszNEEDS(NUMGROUPS) AS STRING

GLOBAL WINDIR$			''Windows directory.
GLOBAL WINSYSDIR$		''Windows directory.
GLOBAL WINDRIVE$		''Windows drive letter.
GLOBAL bWindowsIsNetworked%
GLOBAL bWindowsForWorkgroups%
GLOBAL DEST$    		''destination directory.
GLOBAL SrcDir$      ''SrcDir of the CDROM or the Network files directory.
GLOBAL szSymbolDir$		''directory for Symbols 
GLOBAL szDestScannersDir$''directory for scanner files
GLOBAL szWWinDir$		''Writable Windows directory

GLOBAL szFontSectDisk$
szFontSectDisk$ = "FontSectDisk"

GLOBAL szUserName$			''UserName for registration
GLOBAL szSerialNumber$	''SerialNumber for registration

GLOBAL TOOLGROUP$					'' Group in which tools are to be installed

''Windows version numbers
GLOBAL WinMinor%

''Variables to fake subroutines with parameters
GLOBAL szFlist1a$
GLOBAL szFlist1b$
GLOBAL szFlist2a$
GLOBAL szFlist2b$
GLOBAL Dialog%
GLOBAL SelectType%
GLOBAL szOptions$
GLOBAL bRecalcOpt%

''TRUE => must do a global recalculation after GetPath - starts TRUE
GLOBAL bRecalc%

''Globals for WaitOn and WaitOff
GLOBAL nWaiting%
GLOBAL CursorSave%

''local MSTest functions
DECLARE SUB WaitOnBig
DECLARE SUB WaitOn
DECLARE SUB WaitOff
DECLARE SUB SetDirectories
DECLARE SUB PrepInstall
DECLARE SUB AddOptFilesToCopyList( ftype% )
DECLARE SUB RecalcOptFiles( fType% )
DECLARE SUB RecalcPath
DECLARE SUB SetDriveStatus
''''DECLARE SUB SetFontAndScannerDir
DECLARE SUB	WrapFileChangeString( szFile1$, szFile2$, szString1$, szString2$ )
DECLARE SUB	WrapCommentIniSection( szFileName$, szTempFile$, szSection$, szPath$ )
DECLARE	SUB	CheckBackupFile( szFile1$, szFile2$ )
DECLARE FUNCTION CreateProgmanItem (szGroup$, szItem$, szCmd$, szOther$, cmo%) AS INTEGER
DECLARE FUNCTION MakePath( szDir$, szFile$ ) AS STRING
DECLARE FUNCTION MakeDir( szDir$ ) AS STRING
DECLARE SUB MakeFontList
DECLARE SUB AddFilesToList (SectionName$, FiltersList$)
DECLARE SUB AddFileToCopyList(AppendSect$, Section$, FilterName$) 
DECLARE SUB TestAddSectionFilesToCopyList (szSection$,szFrom$,szTo$)


INIT:
	'' set waiting cursor
	nWaiting% = 0
	WaitOn
	
	''Set default directory names
	WINDIR$ = GetWindowsDir
	WINSYSDIR$ = GetWindowsSysDir
	WINDRIVE$ = MID$(WINDIR$, 1, 1)
	bWindowsIsNetworked% = IsDriveNetwork( MID$(WINSYSDIR$,1,1) )
	OpenLogfile MakePath(WINDIR$, TR_LOGFILE), 0
	IF bWindowsIsNetworked% THEN
		szWWinDir$ = WINDIR$			'' copy files to users personal directory
		WriteToLogFile TR_NETWINDOWS
	ELSE
		szWWinDir$ = WINSYSDIR$		'' copy files to users Windows system directory
	ENDIF
	bWindowsForWorkgroups% = IsWinForWorkgroups
	DEST$ = WINDRIVE$ + ":\"+TR_CORELDRW
	SrcDir$ = GetSymbolValue("STF_SRCDIR")
''	DIR(MAIN) = MID$(SrcDir$,1,2)
	SetDirectories
	
 	IF bInstallWorkstation% THEN
		WriteToLogFile TR_INSTALLNETUSER
	ELSE
		WriteToLogFile TR_INSTALLCDBASED
	ENDIF
		
	''find and read .inf file
	szInf$ = GetSymbolValue("STF_SRCINFPATH")
	IF szInf$ = "" THEN
		szInf$ = MakePath( GetSymbolValue("STF_CWDDIR"), "setup2.inf" )
	ENDIF
	ReadInfFile szInf$
	szInf$ = ""

	FOR i% = 1 TO MAIN
 		AddListItem STATUSTEXT$, ""
	NEXT i%
	''We have 15 DRIVETEXT variables defined for 5 drives only
	FOR i% = 1 TO 15
		AddListItem DRIVETEXT$, ""
	NEXT i%
	
	''Disk cost list symbols
	FOR i% = 1 TO NUMGROUPS STEP 1
		aszNEEDS(i%)		= "DrawNeeds" + STR$(i%)
	NEXT i%
	
	''basic initialization
	NUM(1) = "1"
	NUM(2) = "2"
	NUM(3) = "3"
	''Get Drives List
	GetValidDrivesList(DrivesList$)
'''' The Drives List will define the length of the EXTRACOSTS$
	FOR i%=1 TO GetListLength(DrivesList$)
		''Disk cost list symbols
		FOR j% = DRAW TO NUMGROUPS 
			AddListItem aszNEEDS(j%), "0"
		NEXT j%
	NEXT i%
	
 	WriteToLogFile "Before the Font Lists"
      MakeFontSectList
	WriteToLogFile "After the Font Lists"
		
	''Set windows version - for use with installing windows 3.1 DLL's
	'' 25Feb93: We wont install Draw4 on Win3.0.
	'' 16Mar93: The following Check is not working YET.
''	WinMajor% = GetWindowsMajorVersion
''	WriteToLogFile "Windows Major Version is: " + STR$(WinMajor%)
	WinMinor% = GetWindowsMinorVersion
''	WriteToLogFile "Windows Minor Version is: " + STR$(WinMinor%)
''	WriteToLogFile "Windows For Workgroups Installed Checking Return value: "+STR$(bWindowsForWorkgroups%)
	
	''set the default progman group to put everything in
	TOOLGROUP$	= TR_TOOLGROUP
	
'' Put up the Welcome dialog
WELCOME:
	'$IFDEF DEBUG
		WriteToLogFile "WELCOME:"
	'$ENDIF
	WaitOff
	IF bInstallWorkstation% THEN
		Dialog% = NETWELCOME
	ELSE
		Dialog% = CDBASEDWELCOME
	ENDIF
	sz$ = UIStartDlg( "mscuistf.dll", Dialog%, "FInfoDlgProc", WELCOMEHELP, "FHelpDlgProc" )
	SELECT CASE sz$
	CASE "CONTINUE"
		UIPop 1
	CASE "ABOUT"
		IF bInstallWorkstation% THEN
			Dialog% = NETUSERABOUT
		ELSE
			Dialog% = CDBASEDABOUT
		ENDIF
		GOSUB INFO
		GOTO WELCOME
	CASE "REACTIVATE"
		GOTO WELCOME
	CASE ELSE
		GOSUB ASKQUIT
		GOTO WELCOME
	END SELECT

IF bInstallWorkstation% = FALSE THEN
''Before we give him OPTIONs let's get the user name and his serial number.
REGISTER:
		'$IFDEF DEBUG
			WriteToLogFile "REGISTER:"
		'$ENDIF
	AddListItem "EditText", ""
	AddListItem "EditText", ""
REGISTER1:
	sz$ = UIStartDlg("mscuistf.dll", REGISTRATION, "FMultiEditDlgProc", 0, "")
	SELECT CASE sz$
	CASE "CONTINUE"
		WaitOn
		szUserName$ = RTRIM$(LTRIM$(GetListItem("EditText", 1)))
		szSerialNumber$ = RTRIM$(LTRIM$(GetListItem("EditText", 2)))
		IF szUserName$ = "" THEN
			Dialog% = REGISTRATIONBADNAME
			GOSUB INFO
			GOTO REGISTER1
		ENDIF
		IF VerifyNumber(szSerialNumber$) = FALSE THEN
			''Dialog% = REGISTRATIONBADSN
			''GOSUB INFO
			''GOTO REGISTER1
		ENDIF
			
	CASE "REACTIVATE"
		GOTO REGISTER1
	CASE ELSE
		GOSUB ASKQUIT
		GOTO REGISTER1
	END SELECT
	UIPop 1
RemoveSymbol "EditText"

ENDIF ''bInstallWorkstation%

'' fall through from WELCOME
'' Allow the user to select between full, minimal and custom installation
'' OOPS, we removed minimum, so it's only FULL or CUSTOM.
BEFOREINSTALL:
	PrepInstall
	GOSUB GETPATH
	IF bBack% THEN
		GOTO WELCOME
	ENDIF
	IF DoesDirExist(DIR(FONTTT)) OR DoesDirExist(DIR(SCANNERS)) THEN
		GOSUB CUSTINST
		IF bBack% THEN
			GOTO BEFOREINSTALL
		ENDIF
	ENDIF

'' Install the neccessaty files, and the selected fonts and scanners.
INSTALL:
	'$IFDEF DEBUG
		WriteToLogFile "INSTALL:"
	'$ENDIF
	WaitOn
	''Make sure there is enough space for CorelDRAW!
		WaitOnBig
		bRecalc% = FALSE
		RecalcPath 
		SetDriveStatus
	IF bTooBig% THEN
		Dialog% = TOOBIG
		GOSUB INFO
		ERROR STFQUIT
	ENDIF
	
	ClearCopyList
	''Create all directories needed and assign all the files to copy
	FOR i% = 1 TO NUMGROUPS STEP 1
			AddOptFilesToCopyList i%
	NEXT i%
	
		'' backup files to *.cor - do not overwrite
		CheckBackupFile MakePath(WINDIR$,"win.ini"), MakePath(WINDIR$,"win.cor")
		CheckBackupFile MakePath(WINDIR$,"reg.dat"), MakePath(WINDIR$,"reg.cor")
		CheckBackupFile MakePath(WINDIR$,"progman.ini"), MakePath(WINDIR$,"progman.cor")
	
		IF DoesFileExist( MakePath(DIR(MAIN),TR_PROGRAMS+"\"+ TR_CORELDRW_EXE), femExists ) THEN 
			CreateDir MakePath(DEST$,TR_DRAW), cmoNone
			CreateDir MakePath( DEST$, TR_DRAW+"\"+TR_AUTOBACK ), cmoNone
			CreateDir MakePath( DEST$, TR_DRAW+"\"+TR_TEMPLATE ), cmoNone
		ENDIF
		IF DoesFileExist( MakePath(DIR(MAIN),TR_PROGRAMS+"\"+ TR_CORELCHT_EXE), femExists ) THEN 
			CreateDir MakePath(DEST$,TR_CHART), cmoNone
		ENDIF
		IF DoesFileExist( MakePath(DIR(MAIN),TR_PROGRAMS+"\"+ TR_CORELSHW_EXE), femExists ) THEN 
			CreateDir MakePath(DEST$,TR_SHOW), cmoNone
		ENDIF
		IF DoesFileExist( MakePath(DIR(MAIN),TR_PROGRAMS+"\"+ TR_CORELPNT_EXE), femExists ) THEN 
			CreateDir MakePath(DEST$,TR_PHOTOPNT), cmoNone
		ENDIF
		IF DoesFileExist( MakePath(DIR(MAIN),TR_PROGRAMS+"\"+ TR_CORELMOV_EXE), femExists ) THEN 
			CreateDir MakePath(DEST$,TR_MOVE), cmoNone
		ENDIF
	
 	'' If installing as a network administrator, copy redists to redist dir
	
 	'' Add billboards
	BilBrd% = BILLBOARD1 
	FOR i% = 0 TO 5 STEP 1
		AddToBillBoardList "mscuistf.dll", BilBrd+i%, "FModelessBillBoardDlgProc", 20
	NEXT i%
	
	''Copy all the files over
	WaitOff
		CopyFilesInCopyList
	WaitOn
		
	'' if installing as a network administrator don't create .fot files
		'' Register all the ttf fonts with Windows
		IF IsTTFEnabled = 1 AND DoesDirExist(DIR(FONTTT)) THEN
			WriteToLogFile "**** TTFEnabled ****"
				sz$ = UIStartDlg("mscuistf.dll", WAITREGISTER, "FModelessDlgProc", 0, "")
			'' Let's register the Symbols TTF,... FONTLIST1$ is an empty Symbole varaible
				IF szSymbolDir <> "" THEN
					MakeListFromSectionKeys TempList$, "WFN"
					FOR i% = 1 TO GetListLength(TempList$)
						szFileName$ = GetSectionKeyFilename( "WFN", GetListItem(TempList$, i%))
						IF DoesFileExist( MakePath(DEST$, TR_SYMBOLS +"\"+ szFileName$),  femExists) THEN
''						WriteToLogFile "In Symbols: FileName: " + szFileName2$
''						WriteToLogFile "This is the Extension:"+ MID$(szFileName$, LEN(szFileName$)-3) 
							IF MID$(szFileName$, LEN(szFileName$)-2) = "ttf" THEN
								index% = GetFilenameFromPath( szFileName$ )
								szFileName2$ = MID$( szFileName$, index%, LEN(szFileName$) - index% + 1 )
''							WriteToLogFile "This is a TTF file let's register " 
								szFOTName$ = MID$(szFileName2$,1,LEN(szFileName2$)-3) + "fot"
''							WriteToLogFile "This is the filename:"+ MID$(szFileName$, 1, LEN(szFileName$)-3) 
								RegisterFont MakePath(szWWinDir$,szFOTName$), MakePath(DEST$, TR_SYMBOLS +"\"+ szFileName$)
								temp% = GetTypeFaceNameFromTTF( MakePath(DEST$, TR_SYMBOLS +"\"+ szFileName$), szString$, STRINGLEN )
								IF temp% > 0 AND temp% < STRINGLEN THEN
									CreateIniKeyValue TR_WIN_INI, "fonts", szString$+" "+TR_TRUETYPE, UCASE$(szFOTName$), cmoOverWrite
								ENDIF
							ENDIF
						ENDIF
					NEXT i%
				ENDIF
					
			''Lets register Avante Garde Book first, it's always been installed.
			MakeListFromSectionKeys TempList$, "DrawFonts"
			FOR i% = 1 TO GetListLength(TempList$)
				szFileName$ = GetSectionKeyFileName("DrawFonts", GetListItem(TempList$, i%))
				index% = GetFilenameFromPath( szFileName$ )
				szFileName2$ = MID$( szFileName$, index%, LEN(szFileName$) - index% + 1 )
				IF bInstallWorkstation% THEN
					szFontFile$ = szFileName2$
				ELSE
					szFontFile$ = szFileName$
				ENDIF
				IF DoesFileExist( MakePath(DIR(FONTTT), szFontFile$),  femExists) THEN
					szFOTName$ = MID$(szFileName2$,1,LEN(szFileName2$)-3) + "fot"
					RegisterFont MakePath(szWWinDir$,szFOTName$), MakePath(DIR(FONTTT),szFontFile$)
						temp% = GetTypeFaceNameFromTTF( MakePath(DIR(FONTTT),szFontFile$), szString$, STRINGLEN )
						IF temp% > 0 AND temp% < STRINGLEN THEN
							CreateIniKeyValue TR_WIN_INI, "fonts", szString$+" "+TR_TRUETYPE, UCASE$(szFOTName$), cmoOverWrite
						ENDIF
				ENDIF
			NEXT i%
			
			IF afState(FONTTT) <> NONE THEN
				WriteToLogFile "afState(FONTTT) <> NONE"
				IF afState(FONTTT) = ALL THEN
					MakeFontList					
				ENDIF
				FOR nIndex% = 1 TO GetListLength(FONTLIST2$)
					FOR i% = 1 TO GetListLength(szFontSectDisk$)
						IF IsSectionKeyExist( GetListItem(szFontSectDisk$, i%), GetListItem(FONTLIST2$, nIndex%)) THEN
							szFileName$ = GetSectionKeyFilename( GetListItem(szFontSectDisk$, i%), GetListItem(FONTLIST2$, nIndex%))
							EXIT FOR
						ENDIF
					NEXT i%							
					index% = GetFilenameFromPath( szFileName$ )
					szFileName2$ = MID$( szFileName$, index%, LEN(szFileName$) - index% + 1 )
					IF bInstallWorkstation% THEN
						szFontFile$ = szFileName2$
					ELSE
						szFontFile$ = szFileName$
					ENDIF
					IF DoesFileExist( MakePath(DIR(FONTTT), szFontFile$),  femExists) THEN
						szFOTName$ = MID$(szFileName2$,1,LEN(szFileName2$)-3) + "fot"
						RegisterFont MakePath(szWWinDir$,szFOTName$), MakePath(DIR(FONTTT),szFontFile$)
						temp% = GetTypeFaceNameFromTTF( MakePath(DIR(FONTTT),szFontFile$), szString$, STRINGLEN )
						IF temp% > 0 AND temp% < STRINGLEN THEN
							CreateIniKeyValue TR_WIN_INI, "fonts", szString$+" "+TR_TRUETYPE, UCASE$(szFOTName$), cmoOverWrite
						ENDIF
					ENDIF
					szString$ = string$( STRINGLEN+1, 32 )
					szFileName$ = ""
					szFileName2$ = ""
					szFOTName$ = ""
				NEXT nIndex%
				UIPop 1
			ENDIF
		ENDIF
	
	'' When installing as a network administrator, register nothing
	
		sz$ = UIStartDlg("mscuistf.dll", WAITCONFIGER, "FModelessDlgProc", 0, "")
		
 		nAddItemFailed% = 0
		
		'' Updating the INI files in the Config directory	only if an APP installed.
		IF DoesDirExist( MakePath(DEST$, TR_CONFIG) ) THEN
			CreateIniKeyValue TR_WIN_INI, "CorelGraphics4", "Dir", MakePath(DEST$,TR_CONFIG), cmoOverWrite
		ENDIF
		IF bWindowsIsNetworked% = TRUE AND DoesFileExist( MakePath(WINSYSDIR$,"ole2.dll"), femExists ) = 1 THEN 
			RUN( TR_REGLOAD_S + " " + MakePath(WINSYSDIR$, "OLE2.REG") )
		ELSE
			RUN( TR_REGLOAD_S + " " + MakePath(szWWinDir$, "OLE2.REG") )
		ENDIF
		IF DoesFileExist( MakePath(DEST$, TR_CONFIG+"\"+TR_CORELAPP_INI), femExists) THEN
			ini$ = MakePath( DEST$, TR_CONFIG+"\"+TR_CORELAPP_INI)
				CreateIniKeyValue ini$, "Config", "ProgramsDir", MakePath(DIR(MAIN),TR_PROGRAMS), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "DataDir", MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_DATA), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "CustomDir", MakePath(DEST$,TR_CUSTOM), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "DrawDir", MakePath(DEST$,TR_DRAW), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "ChartDir", MakePath(DEST$, TR_CHART), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "ShowDir", MakePath(DEST$, TR_SHOW), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "PhotoPaintDir", MakePath(DEST$, TR_PHOTOPNT), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "MoveDir", MakePath(DEST$, TR_MOVE), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "TraceDir", MakePath(DEST$, TR_TRACE), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "MosaicDir", MakePath(DIR(MAIN),TR_PROGRAMS), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "FontsDir", MakePath(DEST$, TR_SYMBOLS ), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "FiltersDir", MakePath(DIR(MAIN),TR_PROGRAMS), cmoOverWrite
				CreateIniKeyValue ini$, "Registration", "UserName", szUserName$, cmoOverWrite
				CreateIniKeyValue ini$, "Registration", "SerialNumber", szSerialNumber$, cmoOverWrite
			ini$ = MakePath( DEST$, TR_CONFIG+"\"+TR_CORELPRN_INI)
				CreateIniKeyValue ini$, "ColorPath", "CircuitPath", MakePath(DEST$,TR_CUSTOM), cmoOverwrite
			ini$ = MakePath( DEST$, TR_CONFIG+"\"+TR_CORELFLT_INI)
				CreateIniKeyValue ini$, "ColorPath", "CircuitPath", MakePath(DEST$,TR_CUSTOM), cmoOverWrite
				CreateIniKeyValue ini$, "ColorPath", "CurvePath", MakePath(DEST$,TR_CUSTOM), cmoOverWrite
				WrapCommentIniSection ini$, MakePath(DEST$,"___temp_"), "ImportFilters", MakePath(DIR(MAIN),TR_PROGRAMS+"\")
				WrapCommentIniSection ini$, MakePath(DEST$,"___temp_"), "ExportFilters", MakePath(DIR(MAIN),TR_PROGRAMS+"\")
				WrapCommentIniSection ini$, MakePath(DEST$,"___temp_"), "CorelAIExport", MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_DATA+"\")
				WrapCommentIniSection ini$, MakePath(DEST$,"___temp_"), "CorelDXFExport", MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_DATA+"\")
			ini$ = MakePath( DEST$, TR_CONFIG+"\"+TR_CORELFNT_INI)
				WrapCommentIniSection ini$, MakePath(DEST$,"___temp_"), "Fonts", MakePath(DEST$, TR_SYMBOLS +"\")
				WrapCommentIniSection ini$, MakePath(DEST$,"___temp_"), "Symbols", MakePath(DEST$, TR_SYMBOLS +"\")
				CreateProgmanGroup TOOLGROUP$, "", cmoNone
				ShowProgmanGroup  TOOLGROUP$, 1, cmoNone
		ENDIF ''DoesFileExist	CORELAPP_INI

		IF DoesFileExist( MakePath(DIR(MAIN), TR_README_WRI), femExists) THEN
				nAddItemFailed% = nAddItemFailed% + CreateProgmanItem( TOOLGROUP$, TR_RELEASENOTES, TR_WRITE_EXE + " " + MakePath(DIR(MAIN),TR_README_WRI), "", cmoOverwrite)
				nAddItemFailed% = nAddItemFailed% + CreateProgmanItem( TOOLGROUP$, "Manuel de l’utilisateur", MakePath(DIR(MAIN),"cpnfren.cdr"), "", cmoOverwrite)
				nAddItemFailed% = nAddItemFailed% + CreateProgmanItem( TOOLGROUP$, "Carte d’enregistrement", MakePath(DIR(MAIN),"rcfren.cdr"), "", cmoOverwrite)
		ENDIF
		
				'' setup coreldrw.reg
		IF DoesFileExist( MakePath(DEST$, TR_CONFIG+"\"+TR_CORELDRW_REG), femExists) THEN
				WrapFileChangeString MakePath(DEST$,TR_CONFIG+"\"+TR_CORELDRW_REG), MakePath(DEST$,"___temp_"), TR_CORELDRW_EXE, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CORELDRW_EXE)
				WrapFileChangeString MakePath(DEST$,TR_CONFIG+"\"+TR_CORELDRW_REG), MakePath(DEST$,"___temp_"), TR_CDROL140_DLL, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CDROL140_DLL)
				RUN( TR_REGLOAD_S + " " + MakePath(DEST$,TR_CONFIG+"\"+TR_CORELDRW_REG) )
		ENDIF
		IF DoesFileExist( MakePath(DEST$, TR_CONFIG+"\"+TR_CORELDRW_INI), femExists)  THEN
				ini$ = MakePath(DEST$, TR_CONFIG+"\"+TR_CORELDRW_INI)
					CreateIniKeyValue ini$, "Config", "AutoBackupDir", MakePath(DEST$,TR_DRAW+"\"+TR_AUTOBACK), cmoOverwrite
					CreateIniKeyValue ini$, "Config", "TemplateDir", MakePath(DEST$,TR_DRAW+"\"+TR_TEMPLATE), cmoOverwrite
				nAddItemFailed% = nAddItemFailed% + CreateProgmanItem( TOOLGROUP$, TR_CORELDRAW, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CORELDRW_EXE),"", cmoOverwrite)
		ENDIF

				'' setup corelcht.reg
		IF DoesFileExist( MakePath(DEST$, TR_CONFIG+"\"+TR_CORELCHT_REG), femExists) THEN
				WrapFileChangeString MakePath(DEST$,TR_CONFIG+"\"+TR_CORELCHT_REG), MakePath(DEST$,"___temp_"), TR_CORELCHT_EXE, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CORELCHT_EXE)
				WrapFileChangeString MakePath(DEST$,TR_CONFIG+"\"+TR_CORELCHT_REG), MakePath(DEST$,"___temp_"), TR_CDROL140_DLL, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CDROL140_DLL)
				RUN( TR_REGLOAD_S + " " + MakePath(DEST$,TR_CONFIG+"\"+TR_CORELCHT_REG) )
		ENDIF
		IF DoesFileExist( MakePath(DEST$, TR_CONFIG+"\"+TR_CORELCHT_INI), femExists) THEN
				ini$ = MakePath(DEST$, TR_CONFIG+"\"+"CORELCHT.INI")
					CreateIniKeyValue ini$, "Config", "Vector_path", MakePath(DIR(MAIN),TR_CLIPART+"\"+TR_VECTORS), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "1", CHR$(34)+TR_BAR+CHR$(34)+","+MakePath(DIR(CHART),TR_BAR), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "2", CHR$(34)+TR_LINE+CHR$(34)+","+MakePath(DIR(CHART),TR_LINE), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "3", CHR$(34)+TR_AREA+CHR$(34)+","+MakePath(DIR(CHART),TR_AREA), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "4", CHR$(34)+TR_PIE+CHR$(34)+","+MakePath(DIR(CHART),TR_PIE), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "5", CHR$(34)+TR_SCATTER+CHR$(34)+","+MakePath(DIR(CHART),TR_SCATTER), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "6", CHR$(34)+TR_HIGH+"/"+TR_LOW+"/"+TR_OPEN+"/"+TR_CLOSE+CHR$(34)+","+MakePath(DIR(CHART),TR_HILO), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "7", CHR$(34)+TR_SPECTRAL_MAPS+CHR$(34)+","+MakePath(DIR(CHART),TR_SPECTRAL), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "8", CHR$(34)+TR_HISTOGRAMS+CHR$(34)+","+MakePath(DIR(CHART),TR_HIST), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "9", CHR$(34)+TR_TABLE_CHARTS+CHR$(34)+","+MakePath(DIR(CHART),TR_TABLE), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "10", CHR$(34)+TR_3D_RISER+CHR$(34)+","+MakePath(DIR(CHART),TR_3DRISER), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "11", CHR$(34)+TR_3D_SCATTER+CHR$(34)+","+MakePath(DIR(CHART),TR_3DSCAT), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "12", CHR$(34)+TR_PICTOGRAPHS+CHR$(34)+","+MakePath(DIR(CHART),TR_PICTO), cmoOverwrite
					CreateIniKeyValue ini$, "Templates", "13", CHR$(34)+TR_SAMPLES+CHR$(34)+","+MakePath(DIR(CHART),TR_SAMPLES), cmoOverwrite
				nAddItemFailed% = nAddItemFailed% + CreateProgmanItem( TOOLGROUP$, TR_CORELCHART, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CORELCHT_EXE), "", cmoOverwrite)
		ENDIF '' DoesFileExist CORELCHT_INI

				'' setup corelshw.reg
		IF DoesFileExist( MakePath(DEST$, TR_CONFIG+"\"+TR_CORELSHW_REG), femExists) THEN
				WrapFileChangeString MakePath(DEST$,TR_CONFIG+"\"+TR_CORELSHW_REG), MakePath(DEST$,"___temp_"),TR_CORELSHW_EXE, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CORELSHW_EXE)
				RUN( TR_REGLOAD_S + " " + MakePath(DEST$,TR_CONFIG+"\"+TR_CORELSHW_REG) )
		ENDIF
		IF DoesFileExist( MakePath(DEST$, TR_CONFIG+"\"+TR_CORELSHW_INI), femExists) THEN
				ini$ = MakePath(DEST$, TR_CONFIG+"\"+TR_CORELSHW_INI)
					CreateIniKeyValue ini$, "HomeDirectories", "Presentations", MakePath(DIR(SHOW), TR_SAMPLES), cmoOverwrite
					CreateIniKeyValue ini$, "HomeDirectories", "Animations", MakePath(DIR(SHOW),TR_SAMPLES), cmoOverwrite
				nAddItemFailed% = nAddItemFailed% + CreateProgmanItem( TOOLGROUP$, TR_CORELSHOW, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CORELSHW_EXE), "", cmoOverwrite)
				CreateIniKeyValue TR_WIN_INI, "AAPLAY Animation", "WaveAudio", "c,522", cmoOverWrite
				CreateIniKeyValue TR_WIN_INI, "AAPLAY Animation", "Sequencer", "x,523", cmoOverWrite
				CreateIniKeyValue TR_WIN_INI, "AAPLAY Animation", "FullScreen", "AAVGA.DLL", cmoOverWrite
				CreateIniKeyValue TR_WIN_INI, "AAPLAY Animation", "DualScreen", "no", cmoOverWrite
		ENDIF ''DoesFileExist CORELSHW_INI

				'' Register photo with OLE
		IF DoesFileExist( MakePath(DEST$, TR_CONFIG+"\"+TR_CORELPNT_REG), femExists) THEN
				WrapFileChangeString MakePath(DEST$,TR_CONFIG+"\"+TR_CORELPNT_REG), MakePath(DEST$,"___temp_"),TR_CORELPNT_EXE, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CORELPNT_EXE)
				WrapFileChangeString MakePath(DEST$,TR_CONFIG+"\"+TR_CORELPNT_REG), MakePath(DEST$,"___temp_"),TR_PNTHNDLR_DLL, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_PNTHNDLR_DLL)
				RUN( TR_REGLOAD_S + " " + MakePath(DEST$,TR_CONFIG+"\"+TR_CORELPNT_REG) )
		ENDIF
		IF DoesFileExist( MakePath(DEST$, TR_CONFIG+"\"+TR_CORELPNT_INI), femExists) THEN
				ini$ = MakePath(DEST$,TR_CONFIG+"\"+TR_CORELPNT_INI)
					CreateIniKeyValue ini$, "CorelPaintDll", "PCX 16 Color/Gray", MakePath(DIR(MAIN),TR_PROGRAMS+"\"+"pcx16.dll,*.pcx"), cmoOverWrite
					CreateIniKeyValue ini$, "ARTIST", "Path", MakePath(DIR(PHOTO),TR_BRUSHES+"\"), cmoOverWrite
					CreateIniKeyValue ini$, "COLORSELECT", "Brush", MakePath(DIR(PHOTO),TR_BRUSHES+"\"+TR_PNTBRUSH_BMP), cmoOverWrite
					CreateIniKeyValue ini$, "COLORSELECT", "Area", MakePath(DEST$,TR_PHOTOPNT+"\"+TR_COLORS+"\"+TR_DEFAULT_CLR), cmoOverWrite
					CreateIniKeyValue ini$, "CANVAS", "Canvas", MakePath(DIR(PHOTO),TR_CANVAS+"\"+TR_CANVAS_PCX), cmoOverWrite
					CreateIniKeyValue ini$, "ColorPath", "CircuitPath", MakePath(DEST$,TR_CUSTOM), cmoOverWrite
					CreateIniKeyValue ini$, "ColorPath", "CurvePath", MakePath(DEST$,TR_CUSTOM), cmoOverWrite
					CreateIniKeyValue ini$, "ColorPath", "TargetPath", MakePath(DEST$,TR_CUSTOM), cmoOverWrite
					CreateIniKeyValue ini$, "FILL", "Fill", MakePath(DIR(PHOTO),TR_TILES+"\"+"SAND.PCX"), cmoOverWrite
				nAddItemFailed% = nAddItemFailed% + CreateProgmanItem( TOOLGROUP$, TR_CORELPHOTO, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CORELPNT_EXE), "", cmoOverwrite)
				nAddItemFailed% = nAddItemFailed% + CreateProgmanItem( TOOLGROUP$, TR_CCAPTURE, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CCAPTURE_EXE), "", cmoOverwrite)
		ENDIF  '' DoesFileExist CORELPNT_INI
		
				'' Register move with OLE
		IF DoesFileExist( MakePath(DEST$, TR_CONFIG+"\"+TR_CORELMOV_INI), femExists) THEN
				ini$ = MakePath(DEST$,TR_CONFIG+"\"+TR_CORELMOV_INI)
					CreateIniKeyValue ini$, "Config", "FilterDir", MakePath(DIR(MAIN),TR_PROGRAMS), cmoOverWrite
				'' Make the changes for media player installation	
				ini$ = MakePath(WINDIR$, "system.ini")
					CopyFile MakePath(WINDIR$, "system.ini"), MakePath(WINDIR$, "system.cor"), cmoOverwrite, 0
					CreateIniKeyValue ini$, "mci", "CorelMOVE", MakePath(DIR(MAIN),TR_PROGRAMS+"\"+"mcicmv40.drv"), cmoOverWrite
					CreateIniKeyValue ini$, "drivers", "VIDC.MSVC", "msvidc.drv", cmoOverWrite
					CreateIniKeyValue TR_WIN_INI, "mci extensions", "cmv", "CorelMOVE", cmoOverWrite
					CreateIniKeyValue TR_WIN_INI, "mci extensions", "mwf", "CorelMOVE", cmoOverWrite
				ini$ = MakePath(WINDIR$, "MPLAYER.INI")
					CopyFile MakePath(WINDIR$, "mplayer.ini"), MakePath(WINDIR$, "mplayer.cor"), cmoOverwrite, 0
					CreateIniKeyValue ini$, "Devices", "CorelMOVE", "350, CorelMove Player", cmoOverWrite
				nAddItemFailed% = nAddItemFailed% + CreateProgmanItem( TOOLGROUP$, TR_CORELMOVE, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CORELMOV_EXE), "", cmoOverwrite)
		ENDIF ''DoesFileExist CORELMOV_INI

		IF DoesFileExist( MakePath(DIR(MAIN), TR_PROGRAMS+"\"+TR_CORELTRC_EXE), femExists) THEN
			ini$ = MakePath(DEST$,TR_CONFIG+"\"+"coreltrc.ini")
				CreateIniKeyValue ini$, "Config", "1", MakePath(DEST$, TR_TRACE+"\"+"NORMAL.CTR"), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "2", MakePath(DEST$, TR_TRACE+"\"+"DITHERED.CTR"), cmoOverWrite
				CreateIniKeyValue ini$, "Config", "3", MakePath(DEST$, TR_TRACE+"\"+"BIGFORMS.CTR"), cmoOverWrite
			nAddItemFailed% = nAddItemFailed% + CreateProgmanItem( TOOLGROUP$, TR_CORELTRACE, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CORELTRC_EXE), "", cmoOverwrite)
		ENDIF
		
		IF DoesFileExist( MakePath(DIR(MAIN), TR_PROGRAMS+"\"+TR_CORELMOS_EXE), femExists) THEN
			nAddItemFailed% = nAddItemFailed% + CreateProgmanItem( TOOLGROUP$, TR_CORELMOSAIC, MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_CORELMOS_EXE), "", cmoOverwrite)
		ENDIF
		
		UIPop 1 ''WAITCONFIGER Dialog
		
		IF nAddItemFailed% > 0 THEN
			Dialog% = NETADDITEMFAILED
			GOSUB INFO
		ENDIF
		
		''Let's get the bootable drive, by looking at COMSPEC enviro variable
		TempStr$ = GetEnvVariableValue("COMSPEC")
		''Assume that config.sys & autoexec.bat are in the same drive as command.com
		Drive$ = MID$ (TempStr$, 1, 1)
		'' If Scanners installed we need to add the lines to config.sys & autoexec.bat
		IF afState(SCANNERS) = SOME THEN
			'$IFDEF DEBUG
				WriteToLogFile "Drive of Command.com is: " + Drive$
			'$ENDIF
			IF DoesFileExist( MakePath(WINDIR$, TR_TWAIN+"\"+TR_COREL+"\"+"CORTWAIN.INI"), femExists) THEN
				ini$ = MakePath(WINDIR$,TR_TWAIN+"\"+TR_COREL+"\"+"CORTWAIN.INI")
				IF bDosScanner% AND GetListLength(AUTOEXECLINE$) THEN
					CopyFile Drive$+":\"+TR_AUTOEXEC_BAT, Drive$+":\"+TR_AUTOEXEC_COR, cmoOverwrite, 0
					bAutoexecModified% = TRUE
UPDATEAUTO:
				WaitOff
		 		sz$ = UIStartDlg( "mscuistf.dll", UPDATEAUTOEXEC, "FButtonsDlgProc", UPDATEHELP, "FHelpDlgProc" )
  		  SELECT CASE sz$
    			CASE "U"
						UIPop(1)
						FModifyFile Drive$+":\"+TR_AUTOEXEC_BAT, AUTOEXECLINE$, "E"
						'$IFDEF DEBUG
							FOR i% =1 TO GetListLength(AUTOEXECLINE$)
								WriteToLogFile "the Autoexec is: "+GetListItem(AUTOEXECLINE$, i%)
							NEXT i%
						'$ENDIF
					CASE "D"
						UIPop(1)
						FModifyFile Drive$+":\"+TR_AUTOEXEC_COR, AUTOEXECLINE$, "E"
					CASE ELSE
						GOTO UPDATEAUTO
				END SELECT
				ENDIF
		
				IF bDosScanner% AND GetListLength(CONFIGLINE$) THEN
					CopyFile Drive$+":\"+TR_CONFIG_SYS, Drive$+":\"+TR_CONFIG_COR, cmoOverwrite, 0
UPDATECONFIG:
					WaitOff
 					sz$ = UIStartDlg( "mscuistf.dll", UPDATECONFIG, "FButtonsDlgProc", UPDATEHELP, "FHelpDlgProc" )
  		  	SELECT CASE sz$
    				CASE "U"
							UIPop(1)
							FModifyFile Drive$+":\"+TR_CONFIG_SYS, CONFIGLINE$, "B"
							'$IFDEF DEBUG
								FOR i% =1 TO GetListLength(CONFIGLINE$)
									WriteToLogFile "the Config is: "+GetListItem(CONFIGLINE$, i%)
								NEXT i%
							'$ENDIF
''							bConfigUpdated% = TRUE
						CASE "D"
							FModifyFile Drive$+":\"+TR_CONFIG_COR, CONFIGLINE$, "B"
							UIPop(1)
						CASE ELSE
							GOTO UPDATECONFIG
					END SELECT
				ENDIF
				IF bDosScanner% THEN
					CreateIniKeyValue ini$, "ZSTWAIN.DLL", "path", MakePath(szDestScannersDir$, "zstwain.dll"), cmoOverWrite
				ELSEIF bTwainScanner% THEN
					CreateIniKeyValue ini$, "CANON", "IPUBJS-SCANNER", MakePath(szDestScannersDir$,"canoncj1.dll"), cmoOverWrite
				ENDIF
			ENDIF
		ENDIF
		
'' Installing SHARE
		'' We don't want to install SHARE for Windows for Workgroups
		IF bWindowsForWorkgroups% = FALSE THEN
			ShareFile$ = FindFileInTree("SHARE.EXE", Drive$+":\")
				WriteToLogFile "Found Share in: "+ShareFile$
			IF ShareFile <> "" THEN
				SetSymbolValue "ShareLine", "{}"
				AddListItem "ShareLine", ShareFile$+" /L:500 /F:5100"
				IF bAutoexecModified% = FALSE THEN
					CopyFile Drive$+":\"+TR_AUTOEXEC_BAT, Drive$+":\"+TR_AUTOEXEC_COR, cmoOverwrite, 0
				ENDIF
UPDATEAUTOEXECFORSHARE:				
				WaitOff
 				sz$ = UIStartDlg( "mscuistf.dll", UPDATEAUTOEXECFORSHARE, "FButtonsDlgProc", UPDATEHELP, "FHelpDlgProc" )
  	  	SELECT CASE sz$
	    		CASE "U"
						UIPop(1)
							FModifyFile Drive$+":\"+TR_AUTOEXEC_BAT, "ShareLine", "E"
						'$IFDEF DEBUG
							FOR i% =1 TO GetListLength("ShareLine")
								WriteToLogFile "the Config is: "+GetListItem("ShareLine", i%)
							NEXT i%
						'$ENDIF
					CASE "D"
						FModifyFile Drive$+":\"+TR_AUTOEXEC_COR, "ShareLine", "E"
						UIPop(1)
					CASE ELSE
						GOTO UPDATEAUTOEXECFORSHARE
				END SELECT
			ENDIF
		ENDIF
		
'' User has completed run of setup or has unconditionally decided to quit
QUIT:
	WaitOff
	'' On MSTest errors report "setup file corrupted" and abort
	ON ERROR GOTO ERRQUIT

	IF ERR = 0 THEN
		sz$ = UIStartDlg("mscuistf.dll", SUCCESS, "FSuccessBitmapDlgProc", 0, "")
		IF bInstallWorkstation% THEN
			dlg% = NETEXITSUCCESS
		ELSE
			dlg% = EXITSUCCESS
		ENDIF
		szDlgProc$ = "FInfo075DlgProc"
		WriteToLogfile TR_SETUPSUCCEEDED
	ELSEIF ERR = STFQUIT THEN
		dlg% = EXITQUIT
		szDlgProc$ = "FInfo0DlgProc"
		WriteToLogfile TR_SETUPQUIT
	ELSE
		dlg% = ERROREXITFAILURE
		szDlgProc$ = "FInfo0DlgProc"
		WriteToLogfile TR_SETUPFAILED
	ENDIF
	WriteToLogfile ""
	
 
'' Put up one of the exit message dialog boxes
QUITL1:
	sz$ = UIStartDlg("mscuistf.dll", dlg%, szDlgProc, 0, "")
	IF sz$ = "REACTIVATE" THEN
		GOTO QUITL1
	ENDIF
 GOTO FINISH


'' An error has occurred in MSTest. Tell the user and abort.
ERRQUIT:
	i% = DoMsgBox( TR_ERRQUIT, TR_SETUPMESSAGE, MB_OK+MB_TASKMODAL+MB_ICONHAND)
	WriteToLogfile TR_SETUPCORRUPTED
	WriteToLogFile ""
FINISH:
	UIPopAll
	ShutDownInstall
	CloseLogFile
	END


'' allow the user to select all the customize options
CUSTINST:
		'$IFDEF DEBUG
			WriteToLogFile "CUSTINST:"
		'$ENDIF
	bBack% = FALSE
	RemoveSymbol "InstallDirs"
	RemoveSymbol "InstallState"
	'' pass current directories and custom install state to dlgproc
	FOR i%= 1 to NUMCUST
		AddListItem "InstallDirs", " "
		AddListItem "InstallState", NUM(afState(i%))
	NEXT i%
		ReplaceListItem "InstallDirs", SCANNERS, szDestScannersDir$

	''Do a full recalculation if necessary
''	IF bRecalc% THEN
		WaitOnBig
		bRecalc% = FALSE
		RecalcPath
''	ENDIF
	
CUSTINSTL2:	
	WaitOn
		'$IFDEF DEBUG
			WriteToLogFile "CUSTINSTL2:"
		'$ENDIF
''	SetDriveStatus
	
CUSTINSTL22:
		
	SetDriveStatus				'' set DriveText$ and StatusText$
	WaitOff
	
	sz$ = UIStartDlg("mscuistf.dll", CUSTINSTCDBASED, "FCustInstDlgProc", CUSTINSTHELP, "FHelpDlgProc")
	
	
	SELECT CASE sz$
	CASE "CONTINUE"
		WaitOn
		GOSUB SetDirFromSymbol	'' set afState and DIR array from symbols
		IF bBadPath% THEN
			GOTO CUSTINSTL22
		ENDIF
		SetDriveStatus					'' Test for not enough space
		IF bTooBig% THEN
			Dialog% = TOOBIG
			GOSUB INFO
			GOTO CUSTINSTL22
		ENDIF
		IF afState(FONTTT) = ALL AND bInstallWorkstation% = FALSE THEN
			'Dialog% = MOREFONTS
			'GOSUB INFO
		ENDIF
		
		WriteToLogFile TR_DIRECTORIES
		WriteToLogFile TR_CUSTOMSELECT
		WriteToLogFile TR_CUSTOMMESSAGE
		WriteToLogFile TR_FILTERS + " - " + STR$(afState(FILTERS)) + " - " + DIR(FILETRS)
		WriteToLogFile TR_TTF + " - " + STR$(afState(FONTTT)) + " - " + DIR(FONTTT)
		WriteToLogFile TR_SCANNERS + " - " + STR$(afState(SCANNERS)) + " - " + DIR(SCANNERS)
		WriteToLogFile TR_ASTERIXES
		
	CASE "CUST8"
		WaitOn
		IF DoesDirExist(DIR(SCANNERS)) THEN
	''		szOptions$ = OPTS(SCANNERS)
			SelectType% = SCANNERS
			GOSUB SetDirFromSymbol	'' set afState and DIR array from symbols
			IF bBadPath% THEN
				GOTO CUSTINSTL22
			ENDIF
			FOR i%=1 TO 3
				AddListItem "StatusText", ""
			NEXT i%
			InitScannerSelection
			bDosScanner% = FALSE
			bTwainScanner% = FALSE
			GOSUB CUSTSCANNERS
			CloseScannerSelection
			RecalcOptFiles SelectType%
		ENDIF
		GOTO CUSTINSTL22
		
	CASE "CUST10"
		WaitOn
		IF DoesDirExist(DIR(FONTTT)) THEN
			SelectType% = FONTTT
			IF bInstallWorkstation% THEN
				Dialog% = SELECTFONTTT
			ELSE
				Dialog% = SELECTFONTTTCD
			ENDIF
				szFList1a$ = FONTLIST1$
				szFList1b$ = FONTLIST2$
''				RecalcOptFiles SelectType%
				GOSUB SELECTFILES
				szFList1a$ = ""
				szFList1b$ = ""
		ENDIF
		GOTO CUSTINSTL22
		
	''reset afState, the drive status and status text
	CASE "RESET"
		WaitOn
		GOSUB SetDirFromSymbol	'' set afState and DIR array from symbols
		bRecalc% = TRUE
		GOTO CUSTINSTL22
		
	CASE "REACTIVATE"
		GOSUB SetDirFromSymbol	'' set afState and DIR array from symbols
		bRecalc% = TRUE
		GOTO CUSTINSTL22
		
	CASE "CANCEL", "BACK"
		WaitOn
		bBack% = TRUE
		
	CASE ELSE
		GOSUB ASKQUIT
		GOSUB SetDirFromSymbol	'' set afState and DIR array from symbols
		GOTO CUSTINSTL22
	END SELECT
	UIPop 1
	RETURN    '' The work needed is done, let's install the files.
	
'' Don't ask what progman group to use if installing as an administrator
'' Since the group selection is deleted, we don't need to jump anything: 16Apr93

CUSTSCANNERS:
	 	AddListItem "CombosStatus", GetListItem("ScanList", 1)
		IF GetListLength("OptionList") THEN
		 	AddListItem "CombosStatus", GetListItem("OptionList", 1)
		ELSE
		 	AddListItem "CombosStatus", ""
		ENDIF
		IF GetListLength("SubOptionList") THEN
		 	AddListItem "CombosStatus", GetListItem("SubOptionList", 1)
		ELSE
		 	AddListItem "CombosStatus", ""
		ENDIF
		bDosScanner% = 0
		bTwainScanner% = 0
			
CUSTSCANNERS2:
	WaitOff
	

	sz$ = UIStartDlg("mscuistf.dll", CUSTSCAN, "FScannerDlgProc", CUSTSCANHELP, "FHelpDlgProc")


	SELECT CASE sz$
	CASE "CONTINUE"
		SetSymbolValue SCANNERSECTION, "{}"
		SetSymbolValue CONFIGLINE, "{}"
		SetSymbolValue AUTOEXECLINE, "{}"
		bDosScanner% = FGetScannerLine(szDestScannersDir$+"\")
		bTwainScanner% = NOT bDosScanner%
		IF afState(SCANNERS) <> SOME THEN
			afState(SCANNERS) = SOME  
		ENDIF
		WaitOn
		GOSUB SetDirFromSymbol	
		RecalcOptFiles SCANNERS
	
	CASE "COMBO1"
		GOTO CUSTSCANNERS2
	CASE "COMBO2"
		GOTO CUSTSCANNERS2
	CASE "COMBO3"
		GOTO CUSTSCANNERS2
		
	CASE "REACTIVATE"
		GOTO CUSTSCANNERS2
		
	CASE "CANCEL"
		UIPop 1
		RETURN
			
	CASE ELSE
		GOSUB ASKQUIT
		GOTO CUSTSCANNERS2
		
	END SELECT
	UIPop 1
RETURN

'' Display an information dialog
'' Uses the global Dialog% to identify which dialog to display
INFO:
	WaitOff
	sz$ = UIStartDlg( "mscuistf.dll", Dialog%, "FInfo0DlgProc", 0, "" )
	SELECT CASE sz$
	CASE "CONTINUE"
		''Do nothing
	CASE "REACTIVATE"
		bRecalc% = TRUE
		GOTO INFO
	CASE "EXIT"
		GOSUB ASKQUIT
		GOTO INFO
	END SELECT
	UIPop 1
RETURN

'' Get the base directory under which CorelDRAW! will be installed
GETPATH:
	bBack% = FALSE
		'$IFDEF DEBUG
			WriteToLogFile "GETPATH:"
		'$ENDIF
	bRet% = FIsDrawExist(TR_WIN_INI, szString$)
	WriteToLogFile "FIsDrawExist returns: "+STR$(bRet%)
	IF bRet% THEN  '' We have DRAW installed before (could be DRAW3 or DRAW4)
		DEST$ = szString$
	ENDIF
	Dialog% = DESTPATH
	SetSymbolValue "EditTextIn", DEST$
	SetSymbolValue "EditFocus", "END"
GETPATHL1:
	WaitOff
		'$IFDEF DEBUG
			WriteToLogFile "GETPATHL1:"
		'$ENDIF
	sz$ = UIStartDlg("mscuistf.dll", Dialog%, "FEditDlgProc", DESTPATHHELP, "FHelpDlgProc")
	SELECT CASE sz$
	CASE "CONTINUE"
		WaitOn
		olddest$ = DEST$
		DEST$ = RTRIM$(LTRIM$(GetSymbolValue("EditTextOut")))
		''Validate new path.
		IF DEST$ = "" OR IsDirWritable(DEST$) = 0 THEN
			OldDialog% = Dialog%
			Dialog% = ERRORBADPATH
			GOSUB INFO
			Dialog% = OldDialog%
			GOTO GETPATHL1
		ENDIF

		''Set Recalc and change subdirectories if DEST$ changed
		IF (olddest$ <> DEST$) AND (olddest$ <> DEST$+"\") AND (olddest$+"\" <> DEST$) THEN
			bRecalc% = TRUE
		ENDIF
		
	CASE "REACTIVATE"
		bRecalc% = TRUE
		GOTO GETPATHL1
	CASE "CANCEL", "BACK"
		UIPop 1
		bBack% = TRUE
		RETURN
	CASE ELSE
		GOSUB ASKQUIT
		GOTO GETPATHL1
	END SELECT
	WriteToLogFile TR_BASEDIR + DEST$
	WriteToLogFile ""
	UIPop 1
RETURN


'' The user has asked to quit - confirm his decision
ASKQUIT:
	WaitOff
	sz$ = UIStartDlg("mscuistf.dll", ASKQUIT, "FQuitDlgProc", 0, "")
	SELECT CASE sz$
	CASE "EXIT"
''		GOTO FINISH
''		UIPopAll
		ERROR STFQUIT
	CASE "REACTIVATE"
		bRecalc% = TRUE
		GOTO ASKQUIT
	CASE ELSE
		''Do nothing
	END SELECT
	UIPop 1
RETURN


'' Permit the user to select which filters or fonts/symbols he wants to install
SELECTFILES:
	'$IFDEF DEBUG
		WriteToLogFile "SELECTFILES:"
	'$ENDIF
	SetSymbolValue "ListItems1a", GetSymbolValue( szFList1a$ )
	SetSymbolValue "ListItems1b", GetSymbolValue( szFList1b$ )

SELECTL1:
	'$IFDEF DEBUG
		WriteToLogFile "SELECTL1:"
	'$ENDIF
	WaitOff
	sz$ = UIStartDlg("mscuistf.dll", Dialog%, "FList4DlgProc", SELECTHELP, "FHelpDlgProc")
	
	SELECT CASE sz$
	CASE "CONTINUE"
		WaitOn
		''If lists have been modified, reset them and recalculate
		newlist$ = GetSymbolValue( "ListItems1a" )
		IF newlist$ <> GetSymbolValue( szFList1a$ ) THEN
			IF newlist$ = "" THEN
				SetSymbolValue szFList1a$, "{}"
			ELSE
				SetSymbolValue szFList1a$, newlist$
			ENDIF
			newlist$ = GetSymbolValue( "ListItems1b" )
			IF newlist$ = "" THEN
				SetSymbolValue szFList1b$, "{}"
			ELSE
				SetSymbolValue szFList1b$, newlist$
			ENDIF
			bRecalcOpt = TRUE
		ENDIF
		UIPop 1
''		IF SelectType% = FONTSYM OR SelectType% = FONTTT AND bRecalcOpt% THEN
			WaitOnBig
			RecalcOptFiles SelectType%
''		ENDIF
''		newlist$ = ""
	CASE "REACTIVATE"
		bRecalc% = TRUE
		GOTO SELECTL1
	CASE "CANCEL", "BACK"
		UIPop 1
		IF SelectType% = FONTSYM OR SelectType% = FONTTT THEN
			WaitOnBig
			RecalcOptFiles SelectType%
		ENDIF
	CASE ELSE
		GOSUB ASKQUIT
		GOTO SELECTL1
	END SELECT
	RemoveSymbol "ListItems1a"
	RemoveSymbol "ListItems1b"
	RemoveSymbol "ListItems2a"
	RemoveSymbol "ListItems2b"
RETURN

'' $Keywords: draw2.mst 2.22 15Oct92 11:43am$ $nokeywords$
'**
'** Purpose:
'**     Adds the specified option files to the copy list.
'** Arguments:
'**     ftype%  - type of files to add, one of the following:
'**             DRAW, CHART, SHOW, PHOTO, MOVE, TRACE, MOSAIC, FILTERS or FONTTT
'** Returns:
'**     none.
'*************************************************************************
SUB AddOptFilesToCopyList (ftype%) STATIC

	'$IFDEF DEBUG
		WriteToLogFile "SUB AddOptFilesToCopyList " + STR$(ftype%)
	'$ENDIF
	fState% = afState(ftype%)
		
	SELECT CASE ftype%
	CASE DRAW
			TestAddSectionFilesToCopyList "DrawDraw", DIR(DRAW), MakePath(DEST$, TR_DRAW)
			TestAddSectionFilesToCopyList "DrawConfig", MakePath(DIR(MAIN), TR_CONFIG), MakePath(DEST$,TR_CONFIG)
			
	CASE CHART
			TestAddSectionFilesToCopyList "ChartConfig", MakePath(DIR(MAIN), TR_CONFIG), MakePath(DEST$,TR_CONFIG)
			
	CASE SHOW
			TestAddSectionFilesToCopyList "ShowConfig", MakePath(DIR(MAIN), TR_CONFIG), MakePath(DEST$,TR_CONFIG)
			IF bWindowsIsNetworked% = FALSE OR DoesFileExist( MakePath(WINSYSDIR$,"qtnotify.exe"), femExists ) = 0 THEN 
				TestAddSectionFilesToCopyList "ShowRedist", MakePath(DIR(MAIN), TR_REDIST), szWWinDir$
			ENDIF
			TestAddSectionFilesToCopyList "ShowRedistWin", MakePath(DIR(MAIN), TR_REDIST), WINDIR$
			
	CASE PHOTO
			TestAddSectionFilesToCopyList "PhotoConfig", MakePath(DIR(MAIN), TR_CONFIG), MakePath(DEST$,TR_CONFIG)
			TestAddSectionFilesToCopyList "PhotoColors", MakePath(DIR(PHOTO), TR_COLORS), MakePath(DEST$, TR_PHOTOPNT+"\"+TR_COLORS)
			
	CASE MOVE
			TestAddSectionFilesToCopyList "MoveConfig", MakePath(DIR(MAIN), TR_CONFIG), MakePath(DEST$,TR_CONFIG)
			IF bWindowsIsNetworked% = FALSE OR DoesFileExist( MakePath(WINSYSDIR$,"dib.drv"), femExists ) = 0 THEN 
				TestAddSectionFilesToCopyList "MoveRedist", MakePath(DIR(MAIN), TR_REDIST), szWWinDir$
			ENDIF
			TestAddSectionFilesToCopyList "MoveRedistWin", MakePath(DIR(MAIN), TR_REDIST), WINDIR$

	CASE TRACE
			TestAddSectionFilesToCopyList "TraceConfig", MakePath(DIR(MAIN), TR_CONFIG), MakePath(DEST$,TR_CONFIG)
			TestAddSectionFilesToCopyList "TraceTrace", DIR(TRACE), MakePath(DEST$, TR_TRACE)
			
	CASE MOSAIC
			IF bWindowsIsNetworked% = FALSE OR DoesFileExist( MakePath(WINSYSDIR$,"pcdxbmp.dll"), femExists ) = 0 THEN 
				TestAddSectionFilesToCopyList "MosaicRedist", MakePath(DIR(MAIN), TR_REDIST), szWWinDir$
			ENDIF
			
	CASE FILTERS
			IF bWindowsIsNetworked% = FALSE OR DoesFileExist( MakePath(WINSYSDIR$,"pcdlib.dll"), femExists ) = 0 THEN 
				TestAddSectionFilesToCopyList "ImpKodak Photo-CD", MakePath(DIR(MAIN), TR_REDIST), szWWinDir$ 
			ENDIF
			
	CASE FONTTT
			
	CASE SCANNERS
		IF fState% <> NONE THEN
			IF fstate% = SOME THEN
				TestAddSectionFilesToCopyList "Twain", MakePath(DIR(MAIN), TR_REDIST), WINDIR$
				TestAddSectionFilesToCopyList "TwainScan", DIR(SCANNERS), MakePath(WINDIR$, TR_TWAIN+"\"+TR_COREL)
				WriteToLogFile "Added TwainScan: szDestScannersDir = " + szDestScannersDir$
				IF bDosScanner% THEN
					TestAddSectionFilesToCopyList "ZSTwainScan", DIR(SCANNERS), szDestScannersDir$ 
					Section$ = GetListItem(SCANNERSECTION$, 1)
					TestAddSectionFilesToCopyList Section$, DIR(SCANNERS), szDestScannersDir$ 
				ENDIF
				IF bTwainScanner% THEN
					Section$ = GetListItem(SCANNERSECTION$, 1)
					TestAddSectionFilesToCopyList Section$, DIR(SCANNERS), szDestScannersDir$ 
				ENDIF
			ENDIF
		ENDIF
			
		 
	CASE MAIN
		
			'' So we have an App to install, so we can create the main directory
''''''''' The following section has been commented
''''''''' We'll not copy Readme.wri to the user harddisk, but if it exist
''''''''' we'll create teh icon and point to it.				
''		IF bInstallWorkstation% THEN
''			TestAddSectionFilesToCopyList "Main", DIR(MAIN), DEST$
''		ENDIF

		TestAddSectionFilesToCopyList "CommonConfig", MakePath(DIR(MAIN), TR_CONFIG), MakePath(DEST$,TR_CONFIG)
		TestAddSectionFilesToCopyList "Custom", MakePath(DIR(MAIN), TR_CUSTOM), MakePath(DEST$,TR_CUSTOM)
		TestAddSectionFilesToCopyList "WFN", szSymbolDir$, MakePath(DEST$,TR_SYMBOLS)
			
		IF bInstallWorkstation% THEN
			IF bWindowsIsNetworked% = FALSE OR DoesFileExist( MakePath(WINSYSDIR$,"ole2.dll"), femExists ) = 0 THEN 
				TestAddSectionFilesToCopyList "CommonRedist", MakePath(DIR(MAIN), TR_REDIST), szWWinDir$
			ENDIF
		ELSE
			TestAddSectionFilesToCopyList "CommonRedist", MakePath(DIR(MAIN), TR_REDIST), szWWinDir$
		ENDIF
		
	END SELECT
	
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:
'**       DRAW, CHART, SHOW, PHOTO, MOVE, TRACE, MOSAIC, FILTERS, FONTTT, MAIN
'** Returns:
'**     none.
'*************************************************************************
SUB RecalcOptFiles (ftype%) STATIC
		'$IFDEF DEBUG
			WriteToLogFile "SUB RecalcOptFiles"
		'$ENDIF
	ClearCopyList
	AddOptFilesToCopyList ftype%
	
	FRecalcOptFiles ftype%, aszNEEDS(ftype%)
		
END SUB


'**
'** Purpose:
'**     Recalculates disk space and sets option status info according
'**     to the current destination path.
'** Arguments: Type%: Passed to RecalcGroup
'**     none.
'** Returns:
'**     none.
'*************************************************************************
SUB RecalcPath STATIC

		'$IFDEF DEBUG
			WriteToLogFile "SUB RecalcPath"
		'$ENDIF
	
	FOR i% = 1 TO NUMGROUPS STEP 1
		RecalcOptFiles i%
	NEXT i%
END SUB


'**
'** Purpose:
'**     Sets drive status info according to latest disk space calcs.
'**     Checks that enough space is available on all drives.
'** Arguments:
'**     none.
'** Returns:
'**     none.
'*************************************************************************
SUB SetDriveStatus STATIC
	
	'$IFDEF DEBUG
		WriteToLogFile "SUB SetDriveStatus"
	'$ENDIF
	DIM alCosts AS POINTER TO LONG
	NoOfDrives% = GetListLength(DrivesList$)	
	ALLOCATE alCosts, NoOfDrives%
	
	''Calculate total costs for each drive
	FOR i% = 0 TO NoOfDrives%-1 STEP 1
		alCosts[i%] = 0
	NEXT i%
	
	FOR i% = 0 TO NoOfDrives%-1
		ndrive% = ASC(GetListItem(DrivesList$, i%+1)) - ASC("A") 
		FOR j%= 1 TO NUMGROUPS
			alCosts[i%] = alCosts[i%] + VAL(GetListItem(aszNEEDS(j%), ndrive%+1))
		NEXT j%
	NEXT i%
	
	''Store the costs and free space for the first five drives used
	j% = 0
	bTooBig% = FALSE
	FOR i% = 0 TO NoOfDrives%-1 STEP 1
		if alCosts[i%] > 0 THEN
			j% = j% + 1
			drive$ = GetListItem(DrivesList$, i%+1) 
			free& = GetFreeSpaceForDrive(drive$)
			IF free& < alCosts[i%] THEN
				bTooBig% = TRUE
			ENDIF
			IF j% < 6 THEN
				ReplaceListItem DRIVETEXT$, j%*3-2, drive$ + ":"
				ReplaceListItem DRIVETEXT$, j%*3-1, STR$(alCosts[i%] / 1024) + " K"
				ReplaceListItem DRIVETEXT$, j%*3, STR$(free& / 1024) + " K"
			ENDIF
			drive=""
		ENDIF
	NEXT i%
	''wipe clean all remaining directory information
	FOR i% = j%*3+1 TO 15 STEP 1
		ReplaceListItem DRIVETEXT$, i%, ""
	NEXT i%
	DEALLOCATE alCosts

END SUB


'**
'** Purpose:
'**     Removes the optional trailing "\"
'** Arguments:
'**     szDir$  - full directory path (with optional ending "\")
'** Returns:
'**     szDir$ without a trailing "\"
'*************************************************************************
FUNCTION MakeDir (szDir$) STATIC AS STRING
	IF szDir$ <> "" THEN
		IF MID$(szDir$, LEN(szDir$), 1) = "\" THEN
			MakeDir = MID$( szDir$, 1, LEN(szDir$) - 1 )
		ELSE
			MakeDir = szDir$
		ENDIF
	ELSE
		MakeDir = szDir$
	ENDIF
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
	MakePath = MakeDir(szDir$) + "\" + szFile$
END FUNCTION


'** This sub converts the symbol "InstallDirs" into the DIR array
'** and the symbol "InstallState" into the afState array, 
'** recalculating disk usage if anything has changed.
'** NOTE: this a only a simulated subroutine because we want to be
'**       able to GOSUB BADPATH from inside it.
'*************************************************************************
SetDirFromSymbol:
		'$IFDEF DEBUG
			WriteToLogFile "SetDirFromSymbol:"	
		'$ENDIF
	'' Convert "InstallState" into the afState array
	bRecalcMain% = FALSE
	FOR i% = SCANNERS TO FONTTT
		WriteToLogFile "SetDirFromSymbol: Status of "+STR$(i%)
		WriteToLogFile "with InstallState of: "+GetListItem("InstallState", i%)
		fNewState% = ASC( GetListItem("InstallState", i%) ) - ASC("1") + 1
		WriteToLogFile "fNewState% is: "+ STR$(fNewState)
		IF fNewState% <> afState(i%) THEN
			afState(i%) = fNewState%
			WriteToLogFile "State is: "+STR$(afState(i%))
			RecalcOptFiles i%
		ENDIF
	NEXT i%
	
	'' Convert "InstallDir" into the DIR array
		WriteToLogFile "Testing Directory changes"
		szList$ = "InstallDirs"
		bBadPath% = FALSE
			szDir$ = MakeDir(GetListItem(szList$, SCANNERS))
			WriteToLogFile "szDir$ of scanners: "+szDir$
			'' If the directory is not writable, tell the user and don't update it.
			IF szDir$ = "" OR IsDirWritable( szDir$ ) = 0 THEN
				WriteToLogFile "Directory has a problem: "+ szDir$
				Dialog% = ERRORBADPATH
				GOSUB INFO
				bBadPath% = TRUE
				RETURN
			ENDIF
			'' If the directory has changed - recalculate disk usage
			IF szDestScannersDir$ <> szDir$ THEN
				szDestScannersDir$ = szDir$
				RecalcOptFiles SCANNERS
			ENDIF
			WriteToLogFile "EndOf Subroutine.....SetDirFromSymbol"
	szDir$ = ""
	szList$ = ""
RETURN

'** This sub sets all files to load - sets directory structure to default
'*************************************************************************
SUB PrepInstall STATIC

	
	''Set all sections to install
	FOR i% = DRAW TO NUMGROUPS
		afState(i%) = ALL
	NEXT i%
		afState(SCANNERS) = NONE

	SetSymbolValue FONTLIST1$, "{}"
	MakeFontList
END SUB


'** Set the subdirectories to their default values.
'*************************************************************************
SUB SetDirectories STATIC
	'$IFDEF DEBUG
		WriteToLogFile "SUB SetDirectories"
	'$ENDIF
	Drive$ = ""
	ini$ = MakePath( SrcDir$, TR_SETUP_INI )
	DIR(MAIN) 		= GetIniKeyString( ini$, "Directories", TR_MAIN )
	DIR(DRAW) 		= GetIniKeyString( ini$, "Directories", TR_DRAW )
	DIR(CHART) 		= GetIniKeyString( ini$, "Directories", TR_CHART )
	DIR(SHOW) 		= GetIniKeyString( ini$, "Directories", TR_SHOW )
	DIR(PHOTO) 		= GetIniKeyString( ini$, "Directories", TR_PHOTOPNT )
	DIR(MOVE) 		= GetIniKeyString( ini$, "Directories", TR_MOVE )
	DIR(TRACE) 		= GetIniKeyString( ini$, "Directories", TR_TRACE )
	DIR(MOSAIC) 	= GetIniKeyString( ini$, "Directories", TR_MOSAIC )
	szSymbolDir$  = GetIniKeyString( ini$, "Directories", TR_WFN )
	DIR(SCANNERS)	= GetIniKeyString( ini$, "Directories", TR_SCANNERS )
	szDestScannersDir$ = MakePath(WINDIR$,TR_TWAIN+"\"+TR_COREL)
	DIR(FILTERS) 	= MakePath( DIR(MAIN), TR_PROGRAMS )
	DIR(FONTTT) 	= GetIniKeyString( ini$, "Directories", TR_TTF )
	
	KeyVal$ = GetIniKeyString( ini$, "Directories", TR_FIXEDDRIVE )
	IF KeyVal$ = "CDROM" THEN
		bInstallWorkstation% = FALSE
		FOR i% = DRAW TO MAIN STEP 1
			DIR(i%) = MID$( ini$, 1, 1) + ":\" + DIR(i%)
			WriteToLogFile "Dir of " + STR$(i%) + " " + DIR(i%)
		NEXT i%
		szSymbolDir$ = MID$( ini$, 1, 1)+ ":\" + szSymbolDir$
	ELSE
		bInstallWorkstation% = TRUE
	ENDIF	
	IF KeyVal$ = "FALSE"  THEN
			FOR i% = DRAW TO MAIN 
				DIR(i%) = MID$( ini$, 1, 1) + MID$( DIR(i%), 2, LEN(DIR(i%))-1 )
				WriteToLogFile "Dir of " + STR$(i%) + " " + DIR(i%)
			NEXT i%
			szSymbolDir$ = MID$( ini$, 1, 1) + MID$( szSymbolDir$, 2, LEN(szSymbolDir$)-1 )
	ENDIF
	IF bInstallWorkstation% THEN
		szUserName$	= GetIniKeyString( ini$, "Registration", "UserName" )
		szSerialNumber$	= GetIniKeyString( ini$, "Registration", "SerialNumber" )
	ENDIF
	
END SUB


'** Make sure that the long wait dialog is displayed and the hourglass cursor
'** are being used
'*************************************************************************
SUB WaitOnBig STATIC
	IF nWaiting% = 0 THEN
		CursorSave% = ShowWaitCursor()
	ENDIF
	IF nWaiting% <> 2 THEN
		sz$ = UIStartDlg("mscuistf.dll", WAIT, "FModelessDlgProc", 0, "")
	ENDIF
	nWaiting% = 2
END SUB


'** Make sure that the hourglass cursor is being used
'*************************************************************************
SUB WaitOn STATIC
	IF nWaiting% = 0 THEN
		CursorSave% = ShowWaitCursor()
		nWaiting% = 1
	ENDIF
END SUB


'** Remove the long wait dialog if it is being displayed and reset the cursor
'** back to normal if it was set to the hourglass icon
'*************************************************************************
SUB WaitOff STATIC
	IF nWaiting% = 2 THEN
		UIPop 1
	ENDIF
	IF nWaiting% <> 0 THEN
		RestoreCursor CursorSave%
	ENDIF
	nWaiting% = 0
END SUB


'** Wrapper function - should reduce size of code segment.
'**
'** FileChangeString replaces szString1$ in szFile1$ with szString2$.
'** szFile2$ is a temporary file name.
'*************************************************************************
SUB	WrapFileChangeString( szFile1$, szFile2$, szString1$, szString2$ ) STATIC
	FileChangeString szFile1$, szFile2$, szString1$, szString2$
END SUB


'** Wrapper function - should reduce size of code segment.
'**
'** CommentIniSection checks to see whether or not the files mentioned in
'** szSection$ can be found in directory szPath$. If not, it sticks a ';'
'** in front of that line of the ini file. Otherwise it makes sure there
'** is not semi-colon commenting out that line.
'** Note: this function is heavily dependent on the format of coreldrw.ini
'*************************************************************************
SUB	WrapCommentIniSection( szFileName$, szTempFile$, szSection$, szPath$ ) STATIC
	CommentIniSection szFileName$, szTempFile$, szSection$, szPath$
END SUB


'** If the second file does not exist, backup szFile1$ as szFile2$
'*************************************************************************
SUB CheckBackupFile( szFile1$, szFile2$ ) STATIC
	IF DoesFileExist(szFile2$,femExists) = 0 AND DoesFileExist(szFile1$,femExists) THEN
		CopyFile szFile1$, szFile2$, cmoNone, 0
	ENDIF
END SUB

'*************************************************************************
FUNCTION CreateProgmanItem (szGroup$, szItem$, szCmd$, szOther$, cmo%) STATIC AS INTEGER
  szItemNew$ = szItem$
  IF szOther$ <> "" THEN
    szItemNew$ = szItem$ + "," + szOther$
  END IF

  IF FCreateProgManItem(szGroup$, szItemNew$, szCmd$, cmo%) = 0 THEN
		CreateProgmanItem = 1
	ELSE
		CreateProgmanItem = 0
  END IF
	szItemNew$ = ""
END FUNCTION


'** This sub Add fonts to the user choice list, if he didn't choose the group.
'** It add the fonts which will not be installed by the unsellected list
'*************************************************************************
SUB MakeFontList STATIC
	
 	WriteToLogFile "SUB MakeFontList"
	SetSymbolValue FONTLIST2$, "{}"
			FOR i% = 1 TO GetListLength(szFontSectDisk$)
					AddFilesToList GetListItem(szFontSectDisk$, i%), "FON"
			NEXT i%
			
END SUB


'***********************************************************************
'***********************************************************************
'**** Add Filters in Section to the Fileters List
'***********************************************************************
SUB AddFilesToList (SectionName$, FiltersList$) STATIC
		FAddFilesToList SectionName$, FiltersList$
END SUB

'***********************************************************************
'***********************************************************************
'**** Add Filter (If Exist in Section) to copy list ********************
'***********************************************************************
SUB AddFileToCopyList(AppendSect$, Section$, FilterName$) STATIC
		Destination$ = DIR(FILTERS)
''		IF Section$ = "ImpKodak Photo-CD" THEN
''			Destination$ = WINSYSDIR$
''		ELSE
''			IF Section$ = "ExpAdobe Illustrator" OR Section$ = "ExpAutoCAD DXF" Then
''				Destination$ = MakePath(DIR(MAIN),TR_PROGRAMS+"\"+TR_DATA)
''			ENDIF
''		ENDIF
		'$IFDEF DEBUG
			WriteToLogFile "Section: "+Section$+"  FilterName: "+FilterName$+"  Destination: "+Destination$
		'$ENDIF
		FAddFileToCopyList AppendSect$, Section$, FilterName$, SrcDir$, Destination$
		Destination$ = ""
END SUB

'**	Adds each file in the given section to the list of files to be copied,
'** after checking to see if the file was installed by the administrator.
'*************************************************************************
SUB TestAddSectionFilesToCopyList (szSection$,szFrom$,szTo$) STATIC
	MakeListFromSectionKeys TempList$, szSection$
	FOR i% = 1 TO GetListLength(TempList$)
		szKey$ = GetListItem(TempList$, i%)
		szFileName$ = GetSectionKeyFilename( szSection$, szKey$ )
		IF DoesFileExist( MakePath(szFrom$,szFileName$), femExists) = 1 THEN 
			AddSectionKeyFileToCopyList szSection$, szKey$, szFrom$, szTo$
		ENDIF
	NEXT i%
	szFileName$ = ""
	szKey$ = ""
END SUB

