'**********************************************************
'*     Modified MSSetup Toolkit Sample 1 For Conversions Plus
'**************************************************************************
'

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

''Dialog ID's
CONST ASKQUIT       = 200
CONST BLANK         = 250
CONST DESTPATH      = 300
CONST INSTALLMADLG  = 500
CONST EXITFAILURE   = 400
CONST EXITQUIT      = 600
CONST EXITSUCCESS   = 700
CONST APPHELP       = 900
CONST CONFIG        = 1300
CONST MKTG1         = 1400
CONST MKTG2         = 1500
CONST MKTG3         = 1600
CONST CUSTINST2     = 5250
CONST CUSTINSTDEMO  = 5251
CONST CUSTINST3     = 5275
CONST TOOBIG        = 6300
CONST BADPATH       = 6400
CONST BADREG        = 6500
CONST REGISTER      = 7400
CONST NONAME        = 7700

''Bitmap ID
CONST LOGO = 6

GLOBAL DEST$               ''Default destination directory.
GLOBAL WINDRIVE$           ''Windows drive

GLOBAL LISTITEMSIN$        ''Listbox items for custom installation dialog
GLOBAL LISTITEMSOUT$       ''Listbox items selected for custom installation dialog
GLOBAL ChangeList$         ''Have we changed the global copy list?


GLOBAL WPREADER$           '' List Of Reader/Writers
GLOBAL SSDB$               '' List of SpreadSheets and Databases

GLOBAL samples$            '' Copy Samples?
GLOBAL copyConverters$     '' Copy Any converters
GLOBAL InstMA$             '' Should we Install MacAccess

GLOBAL Upgrade%            '' Is this an upgrade version
GLOBAL normalVersion$      '' Are we a normal version? Otherwise Trial, etc

GLOBAL CHECKSTATES$        ''Check box states for custom dnstallation dialog
GLOBAL DRIVETEXT$          ''Text strings for custom installation dialog
GLOBAL SPACENEEDED$        ''Space required for installation per drive
GLOBAL TOOMUCHNEEDED$      ''Flag if too much space is needed
GLOBAL EXTRACOSTS$         ''Extra cost per drive
GLOBAL ListEdit$
GLOBAL reg$

DECLARE SUB Install
DECLARE SUB InitLists
DECLARE SUB UpdateCopyList
DECLARE SUB CalcCost
DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING
DECLARE FUNCTION CalcRegiCheckSum LIB "mscuistf.dll" AS INTEGER
DECLARE FUNCTION WriteSerialNumber LIB "mscuistf.dll" AS INTEGER
DECLARE FUNCTION ReadSerialNumber LIB "mscuistf.dll" AS INTEGER
DECLARE FUNCTION ReadOldFmtSerialNumber LIB "mscuistf.dll" AS INTEGER
DECLARE FUNCTION UpdateConfig LIB "mscuistf.dll" AS INTEGER
DECLARE FUNCTION InstallMacAccess LIB "mscuistf.dll" AS INTEGER
DECLARE SUB FindProductType LIB "mscuistf.dll"
DECLARE SUB ShowWindowMax LIB "mscuistf.dll" (hwnd%)

INIT:
    Upgrade% = 0
	normalVersion$ = "ON"
	FindProductType
	temp$ = "normVersion"

	normalVersion$ = GetSymbolValue("normVersion")

	upgradeYN$ = GetSymbolValue("Upgrade")

	IF ((upgradeYN$ = "ON") AND (normalVersion = "ON")) THEN
		Upgrade% = 1
	ELSEIF normalVersion$ = "PROMO" THEN
		Upgrade% = 2
	ELSEIF normalVersion$ = "EVAL" THEN
		Upgrade% = 3
	ELSEIF normalVersion$ = "DEMO" THEN
		Upgrade% = 4
	ELSEIF normalVersion$ = "TRIAL" THEN
		Upgrade% = 5
    END IF          

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

    hwnd% = HwndFrame()
    ShowWindowMax(hwnd%)

    SetBitmap CUIDLL$, LOGO
    SetTitle "Conversions Plus Setup"
    SetAbout "Conversions Plus", "ver 2.0"
	old% = SetBeepingMode(1)
    
    AddToBillboardList  CUIDLL$, BLANK, "FModelessDlgProc", 1
    AddToBillboardList  CUIDLL$, MKTG1 + Upgrade%, "FModelessDlgProc", 3
    AddToBillboardList  CUIDLL$, BLANK, "FModelessDlgProc", 1
    AddToBillboardList  CUIDLL$, MKTG2 + Upgrade%, "FModelessDlgProc", 8
    AddToBillboardList  CUIDLL$, BLANK, "FModelessDlgProc", 1
    AddToBillboardList  CUIDLL$, MKTG3 + Upgrade%, "FModelessDlgProc", 3
    AddToBillboardList  CUIDLL$, BLANK, "FModelessDlgProc", 1
	SetCopyGaugePosition  150, 160

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

''Registration Box Init  
    FOR i% = 1 TO 3 STEP 1
       AddListItem "MultiEditTextIn", ""
    NEXT i%

''Path To Install Init
    WINDRIVE$ = MID$(GetWindowsDir, 1, 1)
    DEST$ = windrive$ + ":\CONVPLUS"

''Space Required/Needed Calculation Init
    TOOMUCHNEEDED$ = "TooMuchNeeded"
    SPACENEEDED$ = "SpaceNeeded"
    EXTRACOST$ = "ExtraCost"
    FOR i% = 1 TO 26 STEP 1
	AddListItem EXTRACOST$, "0"
    NEXT i%
    ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
    ReplaceListItem EXTRACOST$, ndrive%, "10240"

''Custom Installation Box Init

	copyConverters$ = "ON"
	samples$ = "ON"
    InstMA$ = "ON" 

    LISTITEMSIN$ = "ListItemsIn"
    LISTITEMSOUT$ = "ListItemsOut"
    WPREADER$ = "WPReader"
	SSDB$ = "SSDB"

    DRIVETEXT$ = "DriveStatusText"
    
    FOR i% = 1 to 5 STEP 1    
		AddListItem "CheckItemsState", "ON"
    NEXT i%

    FOR i% = 1 TO 5 STEP 1
	    AddListItem DRIVETEXT$, ""
	NEXT i%


FINDOLDVERSION:
    CursorSave% = ShowWaitCursor()

	OldPath$ = GetIniKeyString("WIN.INI", "Conversions Plus", "Path")

	IF OldPath$ = "" THEN
		version1$ = "TRUE"

		i% = 1
		OldExe$ = ""

		HardDriveList$ = "HDList"

		GetLocalHardDrivesList HardDriveList$
		listLength& = GetListLength(HardDriveList$)

		WHILE ((OldExe$ = "") AND (i% <= listLength&))
			checkDrive$ = GetListItem(HardDriveList$, i%)
			OldExe$ = FindFileInTree("CPW.EXE", checkDrive$ + ":\")
			i% = i% + 1
		WEND


	ELSE
	    version1$ = "FALSE"
		OldExe$ = MakePath(OldPath$, "CPW.EXE")

		IF (DoesFileExist(OldExe$, femExists)=0) THEN
			OldExe$ = FindFileInTree("CPW.EXE", "C:\")
	    ENDIF
	ENDIF

	RestoreCursor CursorSave%

    IF OldExe$ = "" THEN
	    GOTO REGISTER
    ELSE                      
	    DEST$ = MID$(OldExe$, 1, (LEN(OldExe$) - 8)) 
		SetSymbolValue "OldPathFile", OldExe$

		IF (version1$ = "TRUE") THEN
			rtrn% = ReadOldFmtSerialNumber()
			OldName$ = ""
	    OldOrg$ = ""
		ELSE
			rtrn% = ReadSerialNumber()
			OldName$ = GetSymbolValue("Name")
			OldOrg$ = GetSymbolValue("Org")
	ENDIF

		OldReg$ = GetSymbolValue("SerialNumber")

		RemoveSymbol "MultiEditTextIn"

	    AddListItem "MultiEditTextIn", OldName$
		AddListItem "MultiEditTextIn", OldOrg$
		AddListItem "MultiEditTextIn", OldReg$
	ENDIF


REGISTER:

	RemoveSymbol "EditFocus"
	SetSymbolValue "EditFocus", "ALL"


	sz$ = UIStartDlg(CUIDLL$, REGISTER, "FMEditDlgProc", APPHELP, HELPPROC$)

    nam$ = GetListItem("MultiEditTextOut", 1)
    org$ = GetListItem("MultiEditTextOut", 2)
    reg$ = GetListItem("MultiEditTextOut", 3)

    IF sz$ = "CONTINUE" THEN
	IF LEN(nam$) = 0 THEN
	    GOSUB NONAME
	    GOTO REGISTER
	END IF
	IF LEN(reg$) <> 11 THEN
	    GOSUB BADREG
		GOTO REGISTER
	END IF
	
	SetSymbolValue "SerialNumber", (MID$(reg$, 1, 6))
	chksum% = CalcRegiCheckSum()
	
	UIPop 1
    ELSEIF sz$ = "REACTIVATE" THEN
	    GOTO REGISTER
    ELSE
	    GOSUB ASKQUIT
	    GOTO REGISTER
	END IF
    dog$ = Makepath(GetWindowsDir(), "SYSTEM.INI") 
	checkReg$ = GetIniKeyString(dog$, "dzbios", "id")

	IF (MID$(reg$, 1, 6) = checkReg$) OR (Upgrade% > 1) OR (normalVersion$ <> "ON") THEN
		GOTO REINSTERRQUIT
    END IF


GETPATH:
    SetSymbolValue "EditTextIn", DEST$
    RemoveSymbol "EditFocus"
	SetSymbolValue "EditFocus", "END"
GETPATHL1:
    sz$ = UIStartDlg(CUIDLL$, DESTPATH, "FEditDlgProc", APPHELP, 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
    ELSE
	   GOSUB ASKQUIT
	   GOTO GETPATH
    END IF


CONFIG:
    
    sz$ = UIStartDlg(CUIDLL$, CONFIG, "FInfoDlgProc", APPHELP, HELPPROC$)
    
    IF sz$ = "CONTINUE" THEN   ''default
	    UIPop 1
		SrcDir$ = GetSymbolValue("STF_SRCDIR")


	    '' Initialize lists

		AddSectionFilesToCopyList "GRAPHICS", SrcDir$, DEST$
		AddSectionFilesToCopyList "RESOURCEFORK", SrcDir$, MakePath(DEST$, "SAMPLES\MAC\RESOURCE.FRK")
		AddSectionFilesToCopyList "MACSAMPLES", SrcDir$, MakePath(DEST$, "SAMPLES\MAC")
		AddSectionFilesToCopyList "PCSAMPLES", SrcDir$, MakePath(DEST$, "SAMPLES\PC")
		AddSectionFilesToCopyList "FILEID", SrcDir$, MakePath(DEST$, "RESOURCE.FRK")
		AddSectionFilesToCopyList "SHELL"  , SrcDir$, DEST$
		AddSectionFilesToCopyList "WPREADER" , SrcDir$, DEST$
		AddSectionFilesToCopyList "WPWRITER" , SrcDir$, DEST$
		AddSectionFilesToCopyList "SSDB", SrcDir$, DEST$
		AddSectionFilesToCopyList "SYSTEM", SrcDir$, GetWindowsSysDir()

		MakeListFromSectionKeys WPREADER$, "WPREADER"
		MakeListFromSectionKeys SSDB$, "SSDB"

		AddSectionFilesToCopyList "MACACCESS", SrcDir$, DEST$

		CalcCost 
		IF GetSymbolValue(TOOMUCHNEEDED$) = "YES" THEN
		    ClearCopyList
		    GOSUB TOOBIG
		    GOTO CONFIG
		END IF
		GOTO INST
	ELSEIF sz$ = "BACK" THEN   ''Customize
		UIPop 1
		GOTO CUSTSETUP
    ELSEIF sz$ = "REACTIVATE" THEN
		GOTO CONFIG
	ELSE
		GOSUB ASKQUIT
		GOTO CONFIG
    END IF



EDIT_LIST:

'' Edit Word Proc. List

    saveCursor% = ShowWaitCursor()
	ListEdit$ = "ON"

	RemoveSymbol(LISTITEMSOUT$)

	listlength& = GetListLength(WPREADER$)            '' Create new outlist
	FOR i% = 1 TO listlength& STEP 1                  '' (For highlighting)
		key$ = GetListItem(WPREADER$, i%)
		AddListItem LISTITEMSOUT$, key$
	NEXT i%

''      MakeListFromSectionKeys LISTITEMSOUT$, WPREADER$  '' New InList

	listlength& = GetListLength(SSDB$)            '' Create new outlist
	FOR i% = 1 TO listlength& STEP 1                  '' (For highlighting)
		key$ = GetListItem(SSDB$, i%)
		AddListItem LISTITEMSOUT$, key$
	NEXT i%

	ReplaceListItem DRIVETEXT$, 1, DEST$
    drive$ = MID$(DEST$, 1, 1)
    free& = GetFreeSpaceForDrive(drive$)
    ReplaceListItem DRIVETEXT$, 3, STR$(free& / 1024) + " K"
	UpdateCopyList
	CalcCost

	restoreCursor saveCursor%


EDIT_LOOP:
	sz$ = UIStartDlg(CUIDLL$, CUSTINST3, "FMultiDlgProc", APPHELP, HELPPROC$)

	IF sz$ = "CONTINUE" THEN
		ChangeList$ = "ON"
	    ListEdit$ = "ON" 
		UIPop 1
		return
	ELSEIF sz$ = "BACK" THEN
		ChangeList$ = "OFF"
		ListEdit$ = "ON"
		UIPop 1
	    return
	ELSEIF sz$ = "REACTIVATE" THEN
		GOTO EDIT_LOOP
	ELSEIF sz$ = "LIST1" THEN
		  ListEdit$ = "ON"
		  CursorSave% = ShowWaitCursor()
	      UpdateCopyList
	      CalcCost
		  RestoreCursor CursorSave%
		GOTO EDIT_LOOP
	ELSE
	    GOSUB ASKQUIT
	    GOTO EDIT_LOOP
	END IF



 CUSTSETUP:
    CursorSave% = ShowWaitCursor()
    ReplaceListItem DRIVETEXT$, 1, DEST$
    drive$ = MID$(DEST$, 1, 1)
    free& = GetFreeSpaceForDrive(drive$)
    ReplaceListItem DRIVETEXT$, 3, STR$(free& / 1024) + " K"

    '' Make sure we have everything in their lists...

    MakeListFromSectionKeys WPREADER$, "WPREADER"
    MakeListFromSectionKeys SSDB$, "SSDB"

    RemoveSymbol LISTITEMSIN$

    listlength& = GetListLength(WPREADER$)          '' Create new outlist
    FOR i% = 1 TO listlength& STEP 1                '' (For highlighting)
		key$ = GetListItem(WPREADER$, i%)
		AddListItem LISTITEMSIN$, key$
    NEXT i%

	listlength& = GetListLength(SSDB$)          '' Create new outlist
    FOR i% = 1 TO listlength& STEP 1                '' (For highlighting)
		key$ = GetListItem(SSDB$, i%)
		AddListItem LISTITEMSIN$, key$
	NEXT i%

    UpdateCopyList
	CalcCost
	RestoreCursor CursorSave%

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

	IF sz$ = "CHK1" THEN                                      '' Converters
		copyConverters$ = GetListItem("CheckItemsState", 1)

	    CursorSave% = ShowWaitCursor()
	    UpdateCopyList
	    CalcCost
	    RestoreCursor CursorSave%


	    GOTO CUSTSETUPL1    
	ELSEIF sz$ = "CHK2" THEN                                                                '' Sample Docs
		samples$ = GetListItem("CheckItemsState", 2)

	    CursorSave% = ShowWaitCursor()
	    UpdateCopyList
	    CalcCost
	    RestoreCursor CursorSave%

	    GOTO CUSTSETUPL1    
	ELSEIF sz$ = "BTN1" THEN               '' Converters More Button
		GOSUB EDIT_LIST

		IF ChangeList$ = "ON" THEN

			RemoveSymbol WPREADER$
			RemoveSymbol SSDB$

			listlength& = GetListLength(LISTITEMSOUT$)

			FOR i% = 1 TO listlength& STEP 1
			found$ = "NOT" 
				key$ = GetListItem(LISTITEMSOUT$, i%)

				IF (MID$(key$,1, 1) <> "W") THEN
					 found$ = "FOUND"
				END IF

				IF (found$ = "FOUND") THEN
				 AddListItem SSDB$, key$
				ELSE
				 AddListItem WPREADER$, key$
			END IF
			NEXT i%
		ELSE
		RemoveSymbol LISTITEMSOUT$

			listlength& = GetListLength(WPREADER$)          '' Create new outlist
			FOR i% = 1 TO listlength& STEP 1                '' (For highlighting)
				key$ = GetListItem(WPREADER$, i%)
				AddListItem LISTITEMSOUT$, key$
			NEXT i%

		listlength& = GetListLength(SSDB$)          '' Create new outlist
			FOR i% = 1 TO listlength& STEP 1                '' (For highlighting)
				key$ = GetListItem(SSDB$, i%)
				AddListItem LISTITEMSOUT$, key$
		NEXT i%
	
		END IF
		UpdateCopyList
		CalcCost
		GOTO CUSTSETUPL1
	ELSEIF sz$ = "CONTINUE" THEN
		UIPop 1
		IF GetSymbolValue(TOOMUCHNEEDED$) = "YES" THEN
				GOSUB TOOBIG
				GOTO CUSTSETUPL1
		END IF
		GOTO INST
	ELSEIF sz$ = "REACTIVATE" THEN
		GOTO CUSTSETUPL1
	ELSEIF sz$ = "BACK" THEN
		UIPop 1
			GOTO CONFIG
    ELSE
	    GOSUB ASKQUIT
	    GOTO CUSTSETUPL1
	END IF

INST:

    RemoveSymbol "SerialNumber"
    RemoveSymbol "Org"
    RemoveSymbol "Name"
	SetSymbolValue "SerialNumber", reg$
	SetSymbolValue "Org", org$
	SetSymbolValue "Name", nam$
	SetSymbolValue "PathFile", MakePath(DEST$,"cpw.exe")
					   
	Install 

    rtrn% = WriteSerialNumber()
    IF rtrn% <> 1 THEN
      GOTO ERRQUITEXE
	ENDIF

    IF InstMA$ = "ON" THEN
      GOSUB MAINST
	END IF

QUIT:
    ON ERROR GOTO ERRQUIT

    IF ERR = 0 THEN
		dlg% = EXITSUCCESS
    ELSEIF ERR = STFQUIT THEN
		dlg% = EXITQUIT
    ELSE
		dlg% = EXITFAILURE
    END IF
QUITL1:
    sz$ = UIStartDlg(CUIDLL$, dlg%, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
		GOTO QUITL1
    END IF
    UIPop 1

	END

ERRQUIT:
    i% = DoMsgBox("Setup sources were corrupted, call DataViz Technical Support at (203) 268-0030!", "Setup Failed", MB_OK+MB_TASKMODAL+MB_ICONHAND)
	END

ERRQUITEXE:
    i% = DoMsgBox("Error " + STR$(rtrn%) + ": executable may be corruped, call DataViz Techinical Support at (203) 268-0030!", "Setup Failed", MB_OK+MB_TASKMODAL+MB_ICONHAND)
	END

REINSTERRQUIT:
	i% = DoMsgBox("You have already installed this expiring version of Conversions Plus.  Please call DataViz for your new copy at (203) 268-0030!", "Setup Failed", 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

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

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

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

TOOBIG:
    sz$ = UIStartDlg(CUIDLL$, TOOBIG, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
		GOTO TOOBIG
    END IF

    UIPop 1
    RETURN

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

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


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

	IF sz$ = "BACK" THEN
	   GOSUB MACACCESSHELP
	   GOTO MAINST
    ELSEIF sz$ = "REACTIVATE" THEN
		GOTO MAINST
	ELSE
		UIPop 1
    END IF
	RETURN

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

SUB Install STATIC


    SrcDir$ = GetSymbolValue("STF_SRCDIR")
    CreateDir DEST$, cmoNone
    CreateDir MakePath(DEST$, "RESOURCE.FRK"), cmoNone
    
    IF samples$ = "ON" THEN
	    CreateDir MakePath(DEST$, "SAMPLES"), cmoNone
	    CreateDir MakePath(DEST$, "SAMPLES\MAC"), cmoNone
	    CreateDir MakePath(DEST$, "SAMPLES\PC"), cmoNone
	    CreateDir MakePath(DEST$, "SAMPLES\MAC\RESOURCE.FRK"), cmoNone
	END IF                                

	CopyFilesInCopyList

	RemoveFile MakePath(DEST$, "EMPTY.DLL"), cmoForce

	'' Add path to Win.Ini (also truncate the ending backsplash off).

	CreateIniKeyValue "WIN.INI", "Conversions Plus", "Path", DEST$, cmoOverwrite

	IF normalVersion$ <> "ON" THEN
		CreateIniKeyValue MakePath(GetWindowsDir(),"SYSTEM.INI"), "dzbios", "id", mid$(reg$, 1, 6), cmoOverwrite
	ELSE
		RemoveIniKey MakePath(GetWindowsDir(), "SYSTEM.INI"), "dzbios", "id", cmoNone
	END IF
    

    CreateProgmanGroup "DataViz", "", cmoNone
    ShowProgmanGroup  "DataViz", 1, cmoNone
    CreateProgmanItem "DataViz", "Conversions Plus", MakePath(DEST$,"cpw.exe"), "", cmoOverwrite

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

'**
'** Purpose:
'**     Updates the copy list after the custom install listbox has 
'**      been changed.
'** Arguments:
'**     none.
'** Returns:
'**     none.
'*************************************************************************
SUB UpdateCopyList STATIC


	ClearCopyList  
	SrcDir$ = GetSymbolValue("STF_SRCDIR")

	IF samples$ = "ON" THEN
	    AddSectionFilesToCopyList "RESOURCEFORK", SrcDir$, MakePath(DEST$, "SAMPLES\MAC\RESOURCE.FRK")
	    AddSectionFilesToCopyList "MACSAMPLES", SrcDir$, MakePath(DEST$, "SAMPLES\MAC")
		AddSectionFilesToCopyList "PCSAMPLES", SrcDir$, MakePath(DEST$, "SAMPLES\PC")
	END IF

    AddSectionFilesToCopyList "SHELL", SrcDir$, DEST$
	AddSectionFilesToCopyList "FILEID", SrcDir$, MakePath(DEST$, "RESOURCE.FRK")
	AddSectionFilesToCopyList "SYSTEM", SrcDir$, GetWindowsSysDir()

	AddSectionFilesToCopyList "MACACCESS", SrcDir$, DEST$

	IF ListEdit$ = "ON" THEN
		listlength& = GetListLength(LISTITEMSOUT$)
	    foundWP$ = "NOT"

		    FOR i% = 1 TO listlength& STEP 1
			    found$ = "NOT" 
				key$ = GetListItem(LISTITEMSOUT$, i%)
				IF MID$(key$, 1, 1) = "W" THEN
				    foundWP$ = "FOUND"
					AddSectionKeyFileToCopyList "WPREADER", key$, SrcDir$, DEST$
					IF key$ <> "WP: MS Works Mac 2.0" THEN
					AddSectionKeyFileToCopyList "WPWRITER", key$, SrcDir$, DEST$
					END IF
				ELSE
					IF key$ = "WP: MS Works Win 2.0" THEN
'                                            AddSectionKeyFileToCopyList "SSDB", "Lotus 1-2-3 WK1/WKS",  SrcDir$, DEST$
					 ELSE
					     AddSectionKeyFileToCopyList "SSDB", key$, SrcDir$, DEST$
					 END IF
				END IF
	    NEXT i%

	IF (foundWP$ = "FOUND") THEN
		'' Place all the Graphics on the copy list
		   AddSectionFilesToCopyList "GRAPHICS", SrcDir$, DEST$
		END IF

	ELSE
	    IF copyConverters$ = "ON" THEN
		'' Place Readers and Writers on the copy list
		   AddSectionFilesToCopyList "WPREADER" , SrcDir$, DEST$
		   AddSectionFilesToCopyList "WPWRITER" , SrcDir$, DEST$
		   listlength& = GetListLength(WPREADER$)

		   IF (listlength& > 0) THEN
		       '' Place all the Graphics on the copy list
			   AddSectionFilesToCopyList "GRAPHICS", SrcDir$, DEST$
		   END IF

		   AddSectionFilesToCopyList "SSDB", SrcDir$, DEST$

	    END IF

    END IF
END SUB



'**
'** Purpose:
'**     Calculates the space required for the selected translators.
'** Arguments:
'**     none.
'** Returns:
'**     none.
'*************************************************************************
SUB CalcCost  STATIC
    
    StillNeed& = GetCopyListCost(EXTRACOST$, SPACENEEDED$, "")  

	i% = ASC(MID$(DEST$,1,1)) - ASC("A") + 1

	cost& = VAL(GetListItem(SPACENEEDED$, i%))

    IF cost& <= 0 THEN 
		cost& = 0
    END IF
	  
    ReplaceListItem DRIVETEXT$, 2, STR$(cost& / 1024) + " K"

    IF StillNeed& > 0 THEN
		SetSymbolValue TOOMUCHNEEDED$, "YES"
    ELSE
		SetSymbolValue TOOMUCHNEEDED$, ""
	END IF

END SUB
