'$DEFINE DEBUG  ''Define for script development/debugging
'$INCLUDE 'setupapi.inc'
'$INCLUDE 'msdetect.inc'

CONST MB_Q = 32

CONST WELCOME = 100
CONST WELCOMEH = 900 ''101
CONST SIZENOTE = 110
CONST MACHNOTE = 111
CONST PORTNOTE = 112
CONST ININOTE = 113
CONST UPNOTE = 114
CONST FULLCUST = 120
CONST FULLCUSTH = 900 ''121
CONST NOTNEW = 130
CONST NOTNEW2 = 131
CONST NOTNEWH = 900 ''131
CONST WINNOTE = 140
CONST ASKQUIT = 200
CONST DESTPATH = 300
CONST DESTPATHH = 900 ''301
CONST EXITFAILURE = 400
CONST EXITQUIT = 600
CONST EXITSUCCESS = 700
CONST OPTIONS = 800
CONST APPHELP = 900
CONST CUSTINST = 6200
CONST CUSTSEC = 6202
CONST CUSTFRM = 6204
CONST TOOBIG = 6300
CONST BADPATH = 6400
CONST NAMEORGSER = 6500
CONST PARAPATH = 6600
CONST DEVICE = 9000
CONST COMPORT = 9001
CONST COMPORTL = 9002
CONST DEVICE2 = 9003
CONST MACROINF = 9004

CONST LOGO = 1

CONST  PATHOK = 1
CONST  PATHUCHANGE = 2

GLOBAL SCREENW%
GLOBAL SCREENH%
GLOBAL SCREENTYPE%

GLOBAL LOGOPEN%

GLOBAL WinMinor%
GLOBAL bInstallWinDLL%	
GLOBAL bWin31%	
GLOBAL bRestart%	
GLOBAL bCasInstalled%
GLOBAL bFoundModem%
GLOBAL bCommDrv%
GLOBAL bScrnSave%
GLOBAL bBadShell%
GLOBAL bBadSysdr%
GLOBAL bPromptIni%
GLOBAL bWinfaxDefault%
GLOBAL bNoPhoneBook%
GLOBAL bByPassComm%
GLOBAL bRegister%
GLOBAL CPU%	
GLOBAL CPUT%	
GLOBAL SPEED%	
GLOBAL MODE%	
GLOBAL MHZ%	

GLOBAL WHICHINSTALL%
GLOBAL WHICHVER%
CONST  INSTFULL = 1
CONST  INSTMIN = 2
CONST  INSTCUST = 3

GLOBAL UPDATENEW%
CONST  INSTUPDATE = 1
CONST  INSTNEW = 2
CONST  INSTMDM = 3

CONST FILEGROUPS = 4

CONST FILESAPP = 1
CONST FILESOCR = 2
CONST FILESCVP = 3
CONST FILESDIST = 4 ' Must be the last one
CONST FILESSETUP = 99

CONST FRMGROUPS = 10

CONST FRMTOW = 1
CONST FRMMEM = 2
CONST FRMOVE = 3
CONST FRMMEE = 4
CONST FRMNUT = 5
CONST FRMMON = 6
CONST FRMOOP = 7
CONST FRMSER = 8
CONST FRMCON = 9
CONST FRMETC = 10

GLOBAL DEVOPT$
GLOBAL DEVOPT2$
GLOBAL DEVOPTI$
GLOBAL COMOPT$

GLOBAL OLDMODEM$
GLOBAL OLDCOM$
GLOBAL OLDINIT$
GLOBAL OLDCLASS$

GLOBAL IO$
GLOBAL DEST$
GLOBAL OLDDEST$
GLOBAL OLDDAT$
GLOBAL OLDCVP$
GLOBAL LOGFILE$
GLOBAL WINDRIVE$
GLOBAL WINDIR$
GLOBAL SYSDIR$

GLOBAL WININI$
GLOBAL SYSINI$
GLOBAL FAXGRP$
GLOBAL PROINI$

GLOBAL DATDIR$
GLOBAL CVPDIR$
GLOBAL MACDIR$
GLOBAL TEMP$

GLOBAL bDATDIR%
GLOBAL bCVPDIR%

GLOBAL VON$
GLOBAL VOFF$

GLOBAL WINDISK%

GLOBAL TOBIG&

GLOBAL SPACEGRP$
GLOBAL SPACEAPP$
GLOBAL SPACEDIST$
GLOBAL SPACEOCR$
GLOBAL SPACECVP$
GLOBAL SPACESETUP$

GLOBAL SPACEFR1$
GLOBAL SPACEFR2$
GLOBAL SPACEFR3$
GLOBAL SPACEFR4$
GLOBAL SPACEFR5$
GLOBAL SPACEFR6$
GLOBAL SPACEFR7$
GLOBAL SPACEFR8$
GLOBAL SPACEFR9$
GLOBAL SPACEFR10$

GLOBAL EXTRACOSTS$
GLOBAL BIGLIST$

GLOBAL CHECKSTATES$
GLOBAL STATUSTEXT$
GLOBAL DRIVETEXT$

GLOBAL FRMCHECKSTATES$
GLOBAL FRMSTATUSTEXT$
GLOBAL FRMDRIVETEXT$

GLOBAL LISTIN$
GLOBAL LISTOUT$

GLOBAL DEVIN$
GLOBAL DEVOUT$
GLOBAL DEVIN2$
GLOBAL DEVOUT2$

GLOBAL PORTTYPES$
GLOBAL INISTR$
GLOBAL TMPSTR$
GLOBAL LASTSEND$
GLOBAL LASTRESP$

GLOBAL STARS$

GLOBAL PATHTEXT$

DECLARE SUB BCInitInstall LIB "mscuistf.dll" (hInstance%, hMainWind%)
DECLARE SUB BCMaxWindow   LIB "mscuistf.dll" (hMainWind%)
DECLARE SUB LoadModems    LIB "mscuistf.dll"
DECLARE SUB FreeModems    LIB "mscuistf.dll"
DECLARE SUB BCFreeMem     LIB "mscuistf.dll"
DECLARE FUNCTION BCExit   LIB "mscuistf.dll" AS INTEGER
DECLARE FUNCTION FindModems LIB "mscuistf.dll" (szModem$, szClass$) AS INTEGER
DECLARE FUNCTION BCLaunchWait LIB "mscuistf.dll" (szCmd$, szOpt$) AS INTEGER
DECLARE FUNCTION BCPbkThere LIB "mscuistf.dll" (szDir$) AS INTEGER
DECLARE FUNCTION BCPbkConv LIB "mscuistf.dll" (szPgm$, szDir$, szNewDir$, szOpt$) AS INTEGER
DECLARE FUNCTION BCYesNo LIB "mscuistf.dll" (hWnd%, szT1$, szT4$) AS INTEGER
DECLARE FUNCTION BCOkOnly LIB "mscuistf.dll" (hWnd%, szT1$, szT4$) AS INTEGER
DECLARE FUNCTION BCHdrConv LIB "mscuistf.dll" (txt$, ini$, grp$, tag$) AS INTEGER
DECLARE FUNCTION BCUnPackLSZ LIB "mscuistf.dll" (dest$, lb$) AS INTEGER
DECLARE FUNCTION IsEQ LIB "mscuistf.dll" (s1$, s2$) AS INTEGER
DECLARE SUB BCPath LIB "mscuistf.dll" (szfile$, szkey$, szpath$)
DECLARE SUB GetLastSend LIB "mscuistf.dll" (szIni$)
DECLARE SUB GetLastResp LIB "mscuistf.dll" (szIni$)
DECLARE SUB GetLastI3   LIB "mscuistf.dll" (szIni$)
DECLARE SUB GetModemsIniString LIB "mscuistf.dll" (szIni$, num%)
DECLARE SUB SetModemsIniString LIB "mscuistf.dll" (szIni$, num%)
DECLARE SUB BCGetSerialPortsList LIB "mscuistf.dll" (szList$, num%)
DECLARE FUNCTION IsCASInstalled LIB "mscuistf.dll" AS INTEGER
DECLARE FUNCTION CpuSpeed LIB "mscuistf.dll" AS INTEGER
DECLARE FUNCTION CpuMhz LIB "mscuistf.dll" (speed%, chip%) AS INTEGER
DECLARE FUNCTION WhichModemClass LIB "mscuistf.dll" (szStr$) AS INTEGER

DECLARE SUB AddOptFilesToCopyList (ftype%)
DECLARE SUB AddFRMFilesToCopyList (ftype%)
DECLARE SUB RecalcOptFiles (ftype%)
DECLARE SUB RecalcFRMFiles (ftype%)
DECLARE SUB RecalcPath
DECLARE SUB SetDriveStatus
DECLARE SUB BCWriteToLogFile (szstr$)
DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING
DECLARE FUNCTION MakeDir (szDir$, szSub$) AS STRING
DECLARE FUNCTION StripFileName (szPath$) AS STRING
DECLARE FUNCTION PortType (t%) AS STRING
DECLARE FUNCTION ModeType (t%) AS STRING
DECLARE SUB CopyIni (tag$)

INIT:
  CUIDLL$ = "mscuistf.dll"
  HELPPROC$ = "FHelpDlgProc"

  SetTitle "Delrina Setup"
  BCInitInstall HinstFrame(), HwndFrame()
  BCMaxWindow HwndFrame()
  SetBitmap CUIDLL$, LOGO

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

  LOGOPEN% = 0

  WINDIR$   = GetWindowsDir
  WINDRIVE$ = MID$(WINDIR$, 1, 1)
  WINDISK%  = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
  SYSDIR$   = GetWindowsSysDir

  LOGFILE$ = MakePath(WINDIR$, "winfax.log")
  OpenLogfile LOGFILE$, 0
  LOGOPEN% = 1

  STARS$ = "***********************************************"

  BCWriteToLogFile STARS$
  BCWriteToLogFile "INITIALIZATION"
  BCWriteToLogFile STARS$

  VON$ = "ON"
  VOFF$ = "OFF"

  DEST$ = "C:\WINFAX"
  IO$ = DEST$
  WININI$ = "WIN.INI"
  SYSINI$ = MakePath(WINDIR$, "SYSTEM.INI")
  FAXGRP$ = "WINFAX"

  bDATDIR% = PATHOK
  bCVPDIR% = PATHOK

  GOSUB BUILDDIRS

  bInstallWinDLL% = 0
  bWin31% = 0
  bRestart% = 0
  bPromptIni% = 0
  bNoPhoneBook% = 0
  bByPassComm% = 0
  bRegister% = 0

  WinMinor% = GetWindowsMinorVersion
  IF WinMinor% < 10 THEN
    bInstallWinDLL% = 1
  ELSE
    bWin31% = 1
  ENDIF

  WHICHINSTALL% = INSTFULL
  WHICHVER% = 2
  UPDATENEW% = INSTNEW

  LISTIN$ = "ListItemsIn"
  LISTOUT$ = "ListItemsOut"

  DEVIN$ = "ListDevicesIn"
  DEVOUT$ = "ListDevicesOut"
  DEVIN2$ = "ListDevicesIn2"
  DEVOUT2$ = "ListDevicesOut2"

  PORTTYPES$ = "PortTypes"
  INISTR$ = "IniStr"
  TMPSTR$ = "TmpStr"
  LASTSEND$ = "lastsend"
  LASTRESP$ = "lastresp"

  PATHTEXT$   = "PathStatusText"

  BCWriteToLogFile "Checking for "+FAXGRP$+" in "+WININI$
  ini% = DoesIniSectionExist(WININI$, FAXGRP$)
  IF ini% = 1 THEN
    BCWriteToLogFile "Checking for Faxmng in the Path"
    TMP$ = FindTargetOnEnvVar("faxmng.exe", "PATH")
    IF TMP$ <> "" THEN
      BCWriteToLogFile "Found Faxmng ="+TMP$
      OLDDEST$ = StripFileName(TMP$)
    ENDIF
    IF TMP$ = "" THEN
      OLDDEST$ = DEST$
    ENDIF

    BCWriteToLogFile "Found "+FAXGRP$+" in "+WININI$
    BCWriteToLogFile "Checking for Fax Path in "+WININI$
    TMP$ = GetIniKeyString(WININI$, FAXGRP$, "Fax Path")
    IF TMP$ <> "" THEN
      BCWriteToLogFile "Found Fax Path ="+TMP$
      OLDDAT$ = StripFileName(TMP$)
      DATDIR$ = OLDDAT$
      bDATDIR% = PATHUCHANGE
    ENDIF

    TMP$ = GetIniKeyString(WININI$, FAXGRP$, "Fax Device")
    BCWriteToLogFile "Found Fax Device ="+TMP$
    OLDCLASS$ = TMP$

    TMP$ = GetIniKeyString(WININI$, FAXGRP$, "modem")
    BCWriteToLogFile "Found modem ="+TMP$
    OLDINIT$ = TMP$
    OLDMODEM$ = ""

    TMP$ = GetIniKeyString(WININI$, "devices", FAXGRP$)
    BCWriteToLogFile "Found device ="+TMP$
    IF TMP$ <> "" THEN
      OLDCOM$ = MID$(TMP$, (LEN(TMP$)-4), 4)
    ELSE
      OLDCOM$ = ""
    ENDIF
    BCWriteToLogFile "Found Comport ="+OLDCOM$

    UPDATENEW% = INSTUPDATE
    WHICHVER% = 1
    BCWriteToLogFile "Could be Updating Winfax Version 1 or 2"


    TMP$ = GetIniKeyString(WININI$,FAXGRP$,"VERSION")
    IF TMP$ = "3.0" THEN

      TMP$ = GetIniKeyString(WININI$,FAXGRP$,"ExePath")
      IF TMP$ <> "" THEN
        BCWriteToLogFile "Found ExePath ="+TMP$
        OLDDEST$ = StripFileName(TMP$)
      ENDIF

      TMP$ = GetIniKeyString(WININI$, FAXGRP$, "Fax Path")
      IF TMP$ <> "" THEN
        BCWriteToLogFile "Found Fax Path ="+TMP$
        OLDDAT$ = StripFileName(TMP$)
        DATDIR$ = OLDDAT$
        bDATDIR% = PATHUCHANGE
      ENDIF

      TMP$ = GetIniKeyString(WININI$, FAXGRP$, "Cover Path")
      IF TMP$ <> "" THEN
        BCWriteToLogFile "Found Cover Path ="+TMP$
        OLDCVP$ = StripFileName(TMP$)
        CVPDIR$ = OLDCVP$
        bCVPDIR% = PATHUCHANGE
      ENDIF

      TMP$ = GetIniKeyString(WININI$, FAXGRP$, "imodemdesc")
      BCWriteToLogFile "Found Modem Description ="+TMP$
      OLDMODEM$ = TMP$

      TMP$ = GetIniKeyString(WININI$, FAXGRP$, "imodeminit")
      BCWriteToLogFile "Found Modem Init String ="+TMP$
      OLDINIT$ = TMP$

      TMP$ = GetIniKeyString(WININI$, FAXGRP$, "imodemclass")
      BCWriteToLogFile "Found Modem Class ="+TMP$
      OLDCLASS$ = TMP$

      TMP$ = GetIniKeyString(WININI$, "devices", FAXGRP$)
      BCWriteToLogFile "Found device ="+TMP$
      IF TMP$ <> "" THEN
        OLDCOM$ = MID$(TMP$, (LEN(TMP$)-4), 4)
      ELSE
        OLDCOM$ = ""
      ENDIF
      BCWriteToLogFile "Found Comport ="+OLDCOM$

      UPDATENEW% = INSTUPDATE
      WHICHVER% = 2
      BCWriteToLogFile "Could be Updating Winfax Version 3"
    ENDIF

  ENDIF

  BCWriteToLogFile STARS$
  BCWriteToLogFile "WELCOME/UPDATE SCREENS"
  BCWriteToLogFile STARS$



WELCOME:
  sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", 7001, HELPPROC$)
  IF sz$ = "CONTINUE" THEN
    BCWriteToLogFile "Continue from WELCOME Screen"
    UIPop 1
  ELSE
    GOSUB ASKQUIT
    GOTO WELCOME
  ENDIF

  bPromptIni% = 1

  IF UPDATENEW% = INSTNEW THEN
    GOTO FLCST
  ENDIF

  IF UPDATENEW% = INSTUPDATE THEN
    IF WHICHVER% = 2 THEN
      GOTO NOTNEWL2
    ENDIF
  ENDIF



NOTNEWL:
  sz$ = UIStartDlg(CUIDLL$, NOTNEW, "FInfoDlgProc", 7002, HELPPROC$)
  IF sz$ = "UPDATE" THEN
    BCWriteToLogFile "Continue from NEW/UPDATE Screen (Update Selected)"
    UIPop 1
    UPDATENEW% = INSTUPDATE
    bRestart% = 1
    DEST$ = OLDDEST$
    bCVPDIR%  = PATHOK
    GOSUB BUILDDIRS
    GOTO FLCST

  ELSEIF sz$ = "NEW" THEN
    BCWriteToLogFile "Continue from NEW/UPDATE Screen (New Selected)"
    UIPop 1
    UPDATENEW% = INSTNEW
    bDATDIR%  = PATHOK
    bCVPDIR%  = PATHOK
    GOSUB BUILDDIRS
    GOTO FLCST
  ELSE
    GOSUB ASKQUIT
    GOTO NOTNEWL
  ENDIF


NOTNEWL2:
  sz$ = UIStartDlg(CUIDLL$, NOTNEW2, "FInfoDlgProc", 7003, HELPPROC$)
  IF sz$ = "UPDATE" THEN
    BCWriteToLogFile "Continue from NEW/UPDATE/MODEM Screen (Update Selected)"
    UIPop 1
    UPDATENEW% = INSTUPDATE
    bRestart% = 1
    DEST$ = OLDDEST$
    GOSUB BUILDDIRS
    GOTO FLCST

  ELSEIF sz$ = "NEW" THEN
    BCWriteToLogFile "Continue from NEW/UPDATE/MODEM Screen (New Selected)"
    UIPop 1
    UPDATENEW% = INSTNEW
    bDATDIR%  = PATHOK
    bCVPDIR%   = PATHOK
    GOSUB BUILDDIRS
    GOTO FLCST

  ELSEIF sz$ = "MODEM" THEN
    BCWriteToLogFile "Continue from NEW/UPDATE/MODEM Screen (Modem Selected)"
    UIPop 1
    UPDATENEW% = INSTMDM
    DEST$ = OLDDEST$
    GOTO CALCIT
  ELSE
    GOSUB ASKQUIT
    GOTO NOTNEWL2
  ENDIF



FLCST:

  sz$ = UIStartDlg(CUIDLL$, FULLCUST, "FFullCustDlgProc", 7004, HELPPROC$)
  IF sz$ = "EXIT" THEN
    UIPop 1
    GOSUB ASKQUIT
    GOTO FLCST

  ELSEIF sz$ = "FULL" THEN
    UIPop 1
    BCWriteToLogFile "FULL Install Selected"
    IO$ = DEST$
    GOSUB GETFPATH
    DEST$ = IO$
    GOSUB BUILDDIRS
    WHICHINSTALL% = INSTFULL
    GOTO CALCIT

  ELSEIF sz$ = "MIN" THEN
    UIPop 1
    BCWriteToLogFile "MINIMUM Install Selected"
    IO$ = DEST$
    GOSUB GETFPATH
    DEST$ = IO$
    GOSUB BUILDDIRS
    WHICHINSTALL% = INSTMIN
    GOTO CALCIT

  ELSEIF sz$ = "CUST" THEN
    UIPop 1
    BCWriteToLogFile "CUSTOM Install Selected"
    IO$ = DEST$
    GOSUB GETFPATH
    DEST$ = IO$
    GOSUB BUILDDIRS
    WHICHINSTALL% = INSTCUST
    GOTO CALCIT

  ELSE
    UIPop 1
    GOTO FLCST
  ENDIF


CALCIT:

  CHECKSTATES$ = "CheckItemsState"
  STATUSTEXT$  = "StatusItemsText"
  DRIVETEXT$   = "DriveStatusText"
  FRMCHECKSTATES$ = "FRMItemsState"
  FRMSTATUSTEXT$  = "FRMItemsText"
  FRMDRIVETEXT$   = "FRMStatusText"

  FOR i% = 1 TO FILEGROUPS STEP 1
    AddListItem STATUSTEXT$, ""
  NEXT i%

  FOR i% = 1 TO FRMGROUPS STEP 1
    AddListItem FRMSTATUSTEXT$, ""
  NEXT i%

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

  ReplaceListItem DRIVETEXT$, 7, DEST$

  SPACEAPP$ = "AppNeeds"
  SPACEOCR$ = "Opt1Needs"
  SPACECVP$ = "Opt2Needs"
  SPACEDIST$ = "Opt8Needs"

  SPACEFR1$ = "Frm1Needs"
  SPACEFR2$ = "Frm2Needs"
  SPACEFR3$ = "Frm3Needs"
  SPACEFR4$ = "Frm4Needs"
  SPACEFR5$ = "Frm5Needs"
  SPACEFR6$ = "Frm6Needs"
  SPACEFR7$ = "Frm7Needs"
  SPACEFR8$ = "Frm8Needs"
  SPACEFR9$ = "Frm9Needs"
  SPACEFR10$ = "Frm10Needs"

  SPACEGRP$ = "GrpNeeds"

  FOR i% = 1 TO FILEGROUPS STEP 1
    AddListItem SPACEGRP$, "0"
  NEXT i%

  EXTRACOSTS$  = "ExtraCosts"
  BIGLIST$     = "BigList"

  FOR i% = 1 TO FILEGROUPS STEP 1
    AddListItem BIGLIST$, ""
  NEXT i%

  FOR i% = 1 TO 26 STEP 1
    AddListItem EXTRACOSTS$, "0"
  NEXT i%

  FOR i% = 1 TO FILEGROUPS STEP 1
    AddListItem CHECKSTATES$, VON$
  NEXT i%

  FOR i% = 1 TO FRMGROUPS STEP 1
    AddListItem FRMCHECKSTATES$, VON$
  NEXT i%

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

  ReplaceListItem PATHTEXT$, 1, DEST$

  IF bInstallWinDLL% = 0 THEN
    ReplaceListItem CHECKSTATES$, FILESDIST, VOFF$
  ENDIF

  IF UPDATENEW% = INSTMDM THEN
    IF WHICHVER% = 2 THEN
      FOR i% = 1 TO FILEGROUPS STEP 1
        ReplaceListItem CHECKSTATES$, i%, VOFF$
      NEXT i%
      GOTO MACHINE
    ENDIF
  ENDIF


  BCWriteToLogFile STARS$
  BCWriteToLogFile "Calculating File Sizes"
  BCWriteToLogFile STARS$
  sz$ = UIStartDlg(CUIDLL$, SIZENOTE, "FModelessCentreDlgProc", 0, "")

  BCFreeMem

  IF WHICHINSTALL% = INSTFULL THEN
    GOTO CALCSPACE
  ELSEIF WHICHINSTALL% = INSTCUST THEN
    GOTO CALCSPACE
  ELSE
    GOTO CALCMIN
  ENDIF


CALCMIN:
  ReplaceListItem CHECKSTATES$, FILESOCR, VOFF$
  ReplaceListItem CHECKSTATES$, FILESCVP, VOFF$

  ReplaceListItem FRMCHECKSTATES$, FRMTOW,  VOFF$
  ReplaceListItem FRMCHECKSTATES$, FRMMEM,  VOFF$
  ReplaceListItem FRMCHECKSTATES$, FRMOVE,  VOFF$
  ReplaceListItem FRMCHECKSTATES$, FRMMEE,  VOFF$
  ReplaceListItem FRMCHECKSTATES$, FRMNUT,  VOFF$
  ReplaceListItem FRMCHECKSTATES$, FRMMON,  VOFF$
  ReplaceListItem FRMCHECKSTATES$, FRMOOP,  VOFF$
  ReplaceListItem FRMCHECKSTATES$, FRMSER,  VOFF$
  ReplaceListItem FRMCHECKSTATES$, FRMCON,  VOFF$
  ReplaceListItem FRMCHECKSTATES$, FRMETC,  VOFF$

CALCSPACE:
  RecalcPath
  SetDriveStatus
  UIPop 1

  IF WHICHINSTALL% = INSTFULL THEN
    IF TOBIG& = 1 THEN
      GOSUB TOOBIG
      GOTO CUSTI
    ELSE
      GOTO MACHINE
    ENDIF
  ENDIF

  IF WHICHINSTALL% = INSTMIN THEN
    IF TOBIG& = 1 THEN
      GOSUB TOOBIG
      GOTO CUSTI
    ELSE
      GOTO MACHINE
    ENDIF
  ENDIF

CUSTI:
  BCWriteToLogFile "Custom Install Screen"

CUSTINST:
  sz$ = UIStartDlg(CUIDLL$, CUSTINST, "FCustInstDlgProc", 7005, HELPPROC$)
  IF sz$ = "CONTINUE" THEN
    IF TOBIG& = 1 THEN
      GOSUB TOOBIG
      GOTO CUSTINST
    ENDIF
    UIPop 1
    IF GetListItem(CHECKSTATES$, FILESAPP) <> VON$ THEN
      GOTO INSTALL
    ENDIF
    GOTO MACHINE

  ELSEIF sz$ = "PATH" THEN
    IO$ = DEST$
    GOSUB GETFPATH
    IF IO$ <> DEST$ THEN
      DEST$ = IO$
      ReplaceListItem DRIVETEXT$, 7, DEST$
      GOSUB BUILDDIRS
      BCWriteToLogFile "Changed Install Directory to "+DEST$
      BCWriteToLogFile "Changed Data    Directory to "+DATDIR$
      BCWriteToLogFile "Changed Cover   Directory to "+CVPDIR$
      RecalcPath
      SetDriveStatus
    ENDIF
    GOTO CUSTINST

  ELSEIF sz$ = "CHK1" THEN
    RecalcOptFiles FILESAPP
    SetDriveStatus
    GOTO CUSTINST

  ELSEIF sz$ = "CHK2" THEN
    RecalcOptFiles FILESOCR
    SetDriveStatus
    GOTO CUSTINST

  ELSEIF sz$ = "CHK3" THEN
    RecalcOptFiles FILESCVP
    SetDriveStatus
    GOTO CUSTINST

  ELSEIF sz$ = "BTN1" THEN
    GOTO DODATA
  ELSEIF sz$ = "BTN3" THEN
    GOTO DOCVP

  ELSEIF sz$ = "REACTIVATE" THEN
    RecalcPath
    SetDriveStatus
    GOTO CUSTINST
  ELSE
    GOSUB ASKQUIT
    GOTO CUSTINST
  ENDIF


DODATA:
  ReplaceListItem PATHTEXT$, 1, DATDIR$
  sz$ = UIStartDlg(CUIDLL$, CUSTSEC, "FCustSecDlgProc", 7006, HELPPROC$)
  IF sz$ = "CONTINUE" THEN
    UIPop 1
    GOTO CUSTINST

  ELSEIF sz$ = "PATH" THEN
    IO$ = DATDIR$
    GOSUB GETFPATH
    IF IO$ <> DATDIR$ THEN
      DATDIR$ = IO$
      bDATDIR% = PATHUCHANGE
      RecalcOptFiles FILESAPP
      SetDriveStatus
    ENDIF
    GOTO DODATA

  ELSEIF sz$ = "REACTIVATE" THEN
    RecalcPath
    SetDriveStatus
    GOTO DODATA
  ELSE
    GOSUB ASKQUIT
    GOTO DODATA
  ENDIF


DOCVP:
  ReplaceListItem PATHTEXT$, 1, CVPDIR$
  sz$ = UIStartDlg(CUIDLL$, CUSTFRM, "FCustFrmDlgProc", 7007, HELPPROC$)
  IF sz$ = "CONTINUE" THEN
    UIPop 1
    GOTO CUSTINST

  ELSEIF sz$ = "PATH" THEN
    IO$ = CVPDIR$
    GOSUB GETFPATH
    IF IO$ <> CVPDIR$ THEN
      CVPDIR$ = IO$
      bCVPDIR% = PATHUCHANGE
      RecalcFRMFiles FRMTOW
      RecalcFRMFiles FRMMEM
      RecalcFRMFiles FRMOVE
      RecalcFRMFiles FRMMEE
      RecalcFRMFiles FRMMON
      RecalcFRMFiles FRMOOP
      RecalcFRMFiles FRMSER
      RecalcFRMFiles FRMCON
      RecalcFRMFiles FRMETC
      RecalcOptFiles FILESCVP
      SetDriveStatus
    ENDIF
    GOTO DOCVP

  ELSEIF sz$ = "CHK1" THEN
    RecalcFRMFiles FRMTOW
    RecalcOptFiles FILESCVP
    SetDriveStatus
    GOTO DOCVP

  ELSEIF sz$ = "CHK2" THEN
    RecalcFRMFiles FRMMEM
    RecalcOptFiles FILESCVP
    SetDriveStatus
    GOTO DOCVP

  ELSEIF sz$ = "CHK3" THEN
    RecalcFRMFiles FRMOVE
    RecalcOptFiles FILESCVP
    SetDriveStatus
    GOTO DOCVP

  ELSEIF sz$ = "CHK4" THEN
    RecalcFRMFiles FRMMEE
    RecalcOptFiles FILESCVP
    SetDriveStatus
    GOTO DOCVP

  ELSEIF sz$ = "CHK5" THEN
    RecalcFRMFiles FRMNUT
    RecalcOptFiles FILESCVP
    SetDriveStatus
    GOTO DOCVP

  ELSEIF sz$ = "CHK6" THEN
    RecalcFRMFiles FRMMON
    RecalcOptFiles FILESCVP
    SetDriveStatus
    GOTO DOCVP

  ELSEIF sz$ = "CHK7" THEN
    RecalcFRMFiles FRMOOP
    RecalcOptFiles FILESCVP
    SetDriveStatus
    GOTO DOCVP

  ELSEIF sz$ = "CHK8" THEN
    RecalcFRMFiles FRMSER
    RecalcOptFiles FILESCVP
    SetDriveStatus
    GOTO DOCVP

  ELSEIF sz$ = "CHK9" THEN
    RecalcFRMFiles FRMCON
    RecalcOptFiles FILESCVP
    SetDriveStatus
    GOTO DOCVP

  ELSEIF sz$ = "CHK10" THEN
    RecalcFRMFiles FRMETC
    RecalcOptFiles FILESCVP
    SetDriveStatus
    GOTO DOCVP

  ELSEIF sz$ = "REACTIVATE" THEN
    RecalcPath
    SetDriveStatus
    GOTO DOCVP
  ELSE
    GOSUB ASKQUIT
    GOTO DOCVP
  ENDIF


MACHINE:
  CursorSave% = ShowWaitCursor()
  sz$ = UIStartDlg(CUIDLL$, MACHNOTE, "FModelessCentreDlgProc", 0, "")
  BCWriteToLogFile STARS$
  BCWriteToLogFile "MACHINE CONFIGURATION"
  BCWriteToLogFile STARS$

  WinMinor% = GetWindowsMinorVersion
  IF WinMinor% < 10 THEN
    bInstallWinDLL% = 1
    BCWriteToLogFile "Windows 3.0 detected"
  ELSE
    bWin31% = 1
    BCWriteToLogFile "Windows 3.1+ detected"
  ENDIF

  CPU% = GetProcessorType
  IF CPU% = 4 THEN
     CPUT% = 486
  ELSEIF CPU% = 3 THEN
     CPUT% = 386
  ELSEIF CPU% = 2 THEN
     CPUT% = 286
  ELSE
     CPUT% = 186
  ENDIF
  BCWriteToLogFile "CPU Type = "+STR$(CPUT%)

  SPEED% = CpuSpeed
  MHZ% = CpuMhz(SPEED%, CPUT%)

  MODE% = GetWindowsMode
  TMP$ = ModeType(MODE%)
  BCWriteToLogFile "Windows is running in "+TMP$+" mode."

  UIPop 1

  sz$ = UIStartDlg(CUIDLL$, ININOTE, "FModelessCentreDlgProc", 0, "")

  bCommDrv% = 0
  b$ = "boot"
  c$ = "comm.drv"
  ct$ = "turbocom.drv"
  ini% = DoesIniKeyExist(SYSINI$,b$,c$)
  IF ini% = 1 THEN
    BCWriteToLogFile "Found "+c$+" in "+SYSINI$
    TMP$ = GetIniKeyString(SYSINI$,b$,c$)
    IF (IsEQ(TMP$,c$) = 1) OR (IsEQ(TMP$,ct$) = 1) THEN
      BCWriteToLogFile c$+" is correct = "+TMP$
      bCommDrv% = 0
    ELSE
      BCWriteToLogFile c$+" is not correct = "+TMP$
      bCommDrv% = 1
    ENDIF
  ELSE
    BCWriteToLogFile "Could not find "+c$+" in "+SYSINI$
    bCommDrv% = 2
  ENDIF

  bScrnSave% = 0
  c$ = "SCRNSAVE.EXE"
  ini% = DoesIniKeyExist(SYSINI$,b$,c$)
  IF ini% = 1 THEN
    TMP$ = GetIniKeyString(SYSINI$,b$,c$)
    BCWriteToLogFile "Found SCRNSAVE.EXE in "+SYSINI$+" = "+TMP$
    bScrnSave% = 1
  ENDIF

  bBadShell% = 0
  c$ = "SHELL"
  ini% = DoesIniKeyExist(SYSINI$,b$,c$)
  IF ini% = 1 THEN
    TMP$ = GetIniKeyString(SYSINI$,b$,c$)
    BCWriteToLogFile "Shell Found in "+SYSINI$+" = "+TMP$
    IF (IsEQ(TMP$,"progman.exe") = 0) THEN
      bBadShell% = 1
    ENDIF
  ELSE
    BCWriteToLogFile "No Shell Found"
    bBadShell% = 1
  ENDIF

  bBadSysdr% = 0
  b$ = "boot"
  c$ = "system.drv"
  ini% = DoesIniKeyExist(SYSINI$,b$,c$)
  IF ini% = 1 THEN
    BCWriteToLogFile "Found "+c$+" in "+SYSINI$
    TMP$ = GetIniKeyString(SYSINI$,b$,c$)
    IF (IsEQ(TMP$,c$) = 1) THEN
      BCWriteToLogFile c$+" is correct = "+TMP$
      bBadSysdr% = 0
    ELSE
      BCWriteToLogFile c$+" is not correct = "+TMP$
      bBadSysdr% = 1
    ENDIF
  ELSE
    BCWriteToLogFile "Could not find "+c$+" in "+SYSINI$
    bBadSysdr% = 0
  ENDIF

  bWinfaxDefault% = 0
  WFDRV$ = GetIniKeyString(WININI$, "Windows", "device")
  WFD$ = MID$(WFDRV$, 1, 6)
  IF (IsEQ(WFD$,FAXGRP$) = 1) THEN
     bWinfaxDefault% = 1
     BCWriteToLogFile "Found WinFax as Default Driver"
     bRestart% = 1
     bRegister% = 1
  ENDIF

  UIPop 1


  IF UPDATENEW% = INSTUPDATE THEN
    IF WHICHVER% = 1 THEN
      IF OLDCOM$ = "" THEN
        GOTO MACH1
      ENDIF
      COMOPT$ = OLDCOM$
      DEVOPT$ = OLDCLASS$
      DEVOPTI$ = OLDINIT$
      DEVOPT2$ = ""
      IF (OLDCLASS$ = "Class2") OR (OLDCLASS$ = "class2") OR (OLDCLASS$ = "") THEN
        GOTO MACH1
      ENDIF
      bByPassComm% = 1
      GOTO MACH2
    ELSEIF WHICHVER% = 2 THEN
      COMOPT$ = OLDCOM$
      DEVOPT$ = OLDCLASS$
      DEVOPTI$ = OLDINIT$
      DEVOPT2$ = OLDMODEM$
      bByPassComm% = 1
      GOTO MACH2
    ENDIF

  ELSEIF UPDATENEW% = INSTMDM THEN
      COMOPT$ = OLDCOM$
      DEVOPT$ = OLDCLASS$
      DEVOPTI$ = OLDINIT$
      DEVOPT2$ = OLDMODEM$
      bByPassComm% = 2
      GOTO MACH1
  ENDIF

MACH1:
  sz$ = UIStartDlg(CUIDLL$, PORTNOTE, "FModelessCentreDlgProc", 0, "")

  bCasInstalled% = IsCASInstalled
  IF bCasInstalled% = 1 THEN
     BCWriteToLogFile "CAS Installed"
  ELSE
     BCWriteToLogFile "No CAS Installed"
  ENDIF

  BCGetSerialPortsList LISTIN$, 4
  ser% = GetListLength(LISTIN$)
  IF ser% > 0 THEN

    COMOPT$ = GetListItem(LISTIN$, 1)
    BCWriteToLogFile "ComPorts Available in System"

    FOR i% = 1 TO ser% STEP 1
        typ$ = PortType(0)
        AddListItem PORTTYPES$, typ$
        AddListItem LASTSEND$, " "
        AddListItem LASTRESP$, " "
        tim$ = GetListItem(LISTIN$, i%)
        BCWriteToLogFile tim$
    NEXT i%

    BCWriteToLogFile "Testing the Available Ports"
    FOR i% = 1 TO ser% STEP 1
        tim$ = GetListItem(LISTIN$, i%)
        pok% = WhichModemClass(tim$)
        IF pok% > 0 THEN
           typ$ = PortType(pok%)
           GetLastSend TMPSTR$
           snd$ = GetSymbolValue(TMPSTR$)
           GetLastResp TMPSTR$
           rsp$ = GetSymbolValue(TMPSTR$)
           ReplaceListItem PORTTYPES$, i%, typ$
           ReplaceListItem LASTSEND$, i%, snd$
           ReplaceListItem LASTRESP$, i%, rsp$
           BCWriteToLogFile "Checking "+tim$+" is OK, Type = "+typ$
        ELSE
           BCWriteToLogFile "Checking "+tim$+" Type cannot be determined."
        ENDIF
    NEXT i%

    bFoundModem% = 0
    BCWriteToLogFile "State of Ports and Modem Types"
    FOR i% = 1 TO ser% STEP 1
        tim$ = GetListItem(LISTIN$, i%)
        typ$ = GetListItem(PORTTYPES$, i%)
        BCWriteToLogFile "Port = "+tim$+" is Type = "+typ$
        IF (typ$ <> PortType(0)) AND (bFoundModem% = 0) THEN
           bFoundModem% = i%
        ENDIF
    NEXT i%

    IF bFoundModem% = 1 THEN
      tim$ = GetListItem(LISTIN$, bFoundModem%)
      pok% = WhichModemClass(tim$)
      IF pok% > 0 THEN
         i% = bFoundModem%
         typ$ = PortType(pok%)
         GetLastSend TMPSTR$
         snd$ = GetSymbolValue(TMPSTR$)
         GetLastResp TMPSTR$
         rsp$ = GetSymbolValue(TMPSTR$)
         ReplaceListItem PORTTYPES$, i%, typ$
         ReplaceListItem LASTSEND$, i%, snd$
         ReplaceListItem LASTRESP$, i%, rsp$
      ENDIF
    ENDIF

  ELSE
    BCWriteToLogFile "NO ComPorts Available in System"
    AddListItem LISTIN$, "<none>"
    COMOPT$ = "<none>"
    typ$ = PortType(0)
    AddListItem PORTTYPES$, typ$
    AddListItem LASTSEND$, " "
    AddListItem LASTRESP$, " "
  ENDIF

  UIPop 1

MACH2:

  IF bByPassComm% = 1 THEN
    RestoreCursor CursorSave%
    GOTO INSTALL
  ENDIF

  LoadModems

  IF bByPassComm% = 2 THEN
    t% = FindModems(DEVOPT2$, DEVOPT$)
    IF t% > -1 THEN
      IF DEVOPTI$ <> "" THEN
        SetSymbolValue INISTR$, DEVOPTI$
        SetModemsIniString INISTR$, t%
      ENDIF
    ENDIF
  ENDIF

  AddListItem DEVIN$, "Class1"
  AddListItem DEVIN$, "Class2"
  AddListItem DEVIN$, "Worldport"
  AddListItem DEVIN$, "Sendfax"
  AddListItem DEVIN$, "CAS"

  IF (bCasInstalled% = 0) AND (bFoundModem% = 0) THEN
    AddListItem DEVIN$, "Unknown"
  ENDIF

  BCWriteToLogFile STARS$
  BCWriteToLogFile "SELECTION SCREENS"
  BCWriteToLogFile STARS$
  RestoreCursor CursorSave%


OPTCOM:

  BCWriteToLogFile "ComPort Selection Screen"
  IF bFoundModem% > 0 THEN
    COMOPT$ = GetListItem(LISTIN$, bFoundModem%)
  ELSEIF bCasInstalled% = 1 THEN
    COMOPT$ = "CAS"
  ENDIF

  IF UPDATENEW% = INSTMDM THEN
    COMOPT$ = OLDCOM$
  ENDIF
  SetSymbolValue LISTOUT$, COMOPT$

OPTCOM1:
  IF (bCasInstalled% = 1) AND (bFoundModem% = 0) THEN
    BCWriteToLogFile "CAS Installed and NO modems found, going to Devices Screen."
    GOTO DEVOPT
  ENDIF

  sz$ = UIStartDlg(CUIDLL$, COMPORTL, "FListDlgProc", 7008, HELPPROC$)

  IF sz$ = "CONTINUE" THEN
     UIPop 1
     tmp$ = GetSymbolValue(LISTOUT$)
     IF tmp$ <> COMOPT$ THEN
        COMOPT$ = tmp$
     ENDIF
     BCWriteToLogFile "Com Port selected = "+COMOPT$
     tmp$ = ""
     GOTO DEVOPT

  ELSEIF sz$ = "REACTIVATE" THEN
     GOTO OPTCOM1

  ELSEIF sz$ = "TEST" THEN
     tmp$ = GetSymbolValue(LISTOUT$)
     IF tmp$ <> COMOPT$ THEN
        COMOPT$ = tmp$
     ENDIF

     IF COMOPT$ = "<none>" THEN
        GOTO OPTCOM1
     ELSEIF COMOPT$ = "CAS" THEN
        GOTO OPTCOM1
     ENDIF

     CursorSave% = ShowWaitCursor()
     ser% = GetListLength(LISTIN$)
     IF ser% > 0 THEN

       cdx% = 0
       FOR i% = 1 TO ser% STEP 1
           typ$ = GetListItem(LISTIN$, i%)
           IF (typ$ = COMOPT$) AND (cdx = 0) THEN
              cdx% = i%
              tim$ = typ$
           ENDIF
       NEXT i%

       IF cdx% > 0 THEN
         BCWriteToLogFile "ReTesting Port = "+COMOPT$
         pok% = WhichModemClass(tim$)
         typ$ = PortType(pok%)
         GetLastSend TMPSTR$
         snd$ = GetSymbolValue(TMPSTR$)
         GetLastResp TMPSTR$
         rsp$ = GetSymbolValue(TMPSTR$)
         GetLastI3 TMPSTR$
         i3$ = GetSymbolValue(TMPSTR$)
         ReplaceListItem PORTTYPES$, cdx%, typ$
         ReplaceListItem LASTSEND$, cdx%, snd$
         ReplaceListItem LASTRESP$, cdx%, rsp$
         BCWriteToLogFile "Retesting Found ["+tim$+"] is Type ["+typ$+"]"
         bRetest% = 1
       ENDIF
     ENDIF
     RestoreCursor CursorSave%
     d% = BCOkOnly(HwndFrame(),"Re-Testing is complete.","Q7030")
     GOTO OPTCOM1

  ELSEIF sz$ = "DETAIL" THEN
    msgtxt$ = "Port "+COMOPT$+": appears to be a "+typ$+" device."
    msgtxt$ = msgtxt$ + " Modem Command ["+snd$+"]"
    IF rsp$ <> "" THEN
      msgtxt$ = msgtxt$ + ", Response was ["+rsp$+"]."
    ELSE
      msgtxt$ = msgtxt$ + ", No Response was received."
    ENDIF
    IF i3$ <> "" THEN
      msgtxt$ = msgtxt$ + "  ID Response was ["+i3$+"]"
    ENDIF
    d% = BCOkOnly(HwndFrame(), msgtxt$,"Q7030")
    GOTO OPTCOM1

  ELSEIF sz$ = "EXIT" THEN
     GOSUB ASKQUIT
     GOTO OPTCOM1
  ELSE
     GOSUB ASKQUIT
     GOTO OPTCOM1
  ENDIF



DEVOPT:

  IF bFoundModem% > 0 THEN
     DEVOPT$ = GetListItem(PORTTYPES$, bFoundModem%)
  ELSEIF bCasInstalled% = 1 THEN
     DEVOPT$ = "CAS"
  ELSE
     DEVOPT$ = PortType(0)
  ENDIF

  ser% = GetListLength(LISTIN$)
  FOR i% = 1 TO ser% STEP 1
      typ$ = GetListItem(LISTIN$, i%)
      IF COMOPT$ = "CAS" THEN
         DEVOPT$ = "CAS"
      ELSEIF typ$ = COMOPT$ THEN
         DEVOPT$ = GetListItem(PORTTYPES$, i%)
      ENDIF
  NEXT i%

  DEVOPT2$ = ""

OPTDEV:

  BCWriteToLogFile "Device Selection Screen"

  SetSymbolValue DEVOUT$, DEVOPT$
  SetSymbolValue DEVOUT2$, DEVOPT2$

OPTDEV1:
  sz$ = UIStartDlg(CUIDLL$, DEVICE2, "FDevDlgProc", 7009, HELPPROC$)

  IF sz$ = "CONTINUE" THEN
     UIPop 1
     tmp$ = GetSymbolValue(DEVOUT$)
     IF tmp$ <> DEVOPT$ THEN
        DEVOPT$ = tmp$
     ENDIF

     tmp$ = GetSymbolValue(DEVOUT2$)
     IF tmp$ <> DEVOPT2$ THEN
        DEVOPT2$ = tmp$
     ENDIF

     t% = FindModems(DEVOPT2$, DEVOPT$)
     IF t% > -1 THEN
       GetModemsIniString INISTR$, t%
       DEVOPTI$ = GetSymbolValue(INISTR$)
     ELSE
       DEVOPTI$ = ""
     ENDIF

     BCWriteToLogFile "Device Selected = "+DEVOPT$
     BCWriteToLogFile "Modem  Selected = "+DEVOPT2$
     BCWriteToLogFile "Init String Selected = "+DEVOPTI$
     tmp$ = ""
     GOTO FREEMDM

  ELSEIF sz$ = "REACTIVATE" THEN
     GOTO OPTDEV1

  ELSEIF sz$ = "BACK" THEN
     BCWriteToLogFile "Going back to Com Ports"
     UIPop 1
     GOTO OPTCOM

  ELSEIF sz$ = "EXIT" THEN
     GOSUB ASKQUIT
     GOTO OPTDEV1
  ELSE
     GOSUB ASKQUIT
     GOTO OPTDEV1
  ENDIF



FREEMDM:
  FreeModems



INSTALL:
  BCWriteToLogFile STARS$
  BCWriteToLogFile "Starting Installation"
  BCWriteToLogFile STARS$
  LR$ = "FModelessLRDlgProc"
  LC$ = "FModelessLCDlgProc"
  LL$ = "FModelessLLDlgProc"

  BCWriteToLogFile STARS$
  BCWriteToLogFile "Making Directories"
  BCWriteToLogFile STARS$

  IF WHICHINSTALL% = INSTFULL THEN
    AddToBillBoardList CUIDLL$,8001,LR$,10
    AddToBillBoardList CUIDLL$,8002,LR$,15
    AddToBillBoardList CUIDLL$,8003,LR$,10
    AddToBillBoardList CUIDLL$,8004,LR$,10
    AddToBillBoardList CUIDLL$,8005,LR$,10
    AddToBillBoardList CUIDLL$,8006,LR$,10
    AddToBillBoardList CUIDLL$,8007,LR$,10
  ENDIF

  IF WHICHINSTALL% = INSTMIN THEN
    AddToBillBoardList CUIDLL$,8001,LR$,10
    AddToBillBoardList CUIDLL$,8002,LR$,15
    AddToBillBoardList CUIDLL$,8003,LR$,10
    AddToBillBoardList CUIDLL$,8004,LR$,10
    AddToBillBoardList CUIDLL$,8007,LR$,10
  ENDIF

  IF WHICHINSTALL% = INSTCUST THEN
    IF GetListItem(CHECKSTATES$, FILESAPP) = VON$ THEN
      AddToBillBoardList CUIDLL$,8001,LR$,10
      AddToBillBoardList CUIDLL$,8002,LR$,15
      AddToBillBoardList CUIDLL$,8003,LR$,10
      AddToBillBoardList CUIDLL$,8004,LR$,10
    ENDIF
    IF GetListItem(CHECKSTATES$, FILESOCR) = VON$ THEN
      AddToBillBoardList CUIDLL$,8005,LR$,10
    ENDIF
    IF GetListItem(CHECKSTATES$, FILESCVP) = VON$ THEN
      AddToBillBoardList CUIDLL$,8006,LR$,10
    ENDIF
    IF GetListItem(CHECKSTATES$, FILESAPP) = VON$ THEN
      AddToBillBoardList CUIDLL$,8007,LR$,10
    ENDIF
  ENDIF

  SetCopyGaugePosition 10, 20
  ClearCopyList

  IF GetListItem(CHECKSTATES$, FILESAPP) = VON$ THEN
    IF bNoPhoneBook% = 1 THEN
      i% = BCYesNo(HwndFrame(), "Keep your existing Default Phonebook and Phonebook List?","Q7020")
      IF i% = 7 THEN
        bNoPhoneBook% = 0
      ENDIF
    ENDIF
    AddOptFilesToCopyList FILESAPP
    BCWriteToLogFile "Selecting WinFax Files"
    IF GetListItem(CHECKSTATES$, FILESDIST) = VON$ THEN
      BCWriteToLogFile "Selecting Windows 3.1 DLLs for Windows 3.0"
      AddOptFilesToCopyList FILESDIST
    ENDIF
    CreateDir DEST$, cmoNone
    CreateDir DATDIR$, cmoNone
    CreateDir CVPDIR$, cmoNone
    CreateDir MACDIR$, cmoNone
  ENDIF

  IF GetListItem(CHECKSTATES$, FILESOCR) = VON$ THEN
    BCWriteToLogFile "Selecting OCR Files"
    AddOptFilesToCopyList FILESOCR
  ENDIF

  IF GetListItem(CHECKSTATES$, FILESCVP) = VON$ THEN
    AddOptFilesToCopyList FILESCVP
    BCWriteToLogFile "Selecting WinFax Cover Page Files"
    CreateDir CVPDIR$, cmoNone
  ENDIF


  IF UPDATENEW% = INSTUPDATE THEN
    IF WHICHVER% = 1 THEN
      BCWriteToLogFile "Removing Version 1 or 2 Files"
      RemoveFile MakePath(DEST$,"FAXMNG.EXE"),cmoForce
      RemoveFile MakePath(DEST$,"RXDLL.DLL"),cmoForce
      RemoveFile MakePath(DEST$,"MOD.EXE"),cmoForce
      RemoveFile MakePath(DEST$,"VIEWER.DLL"),cmoForce
      RemoveFile MakePath(DEST$,"HELPHK.DLL"),cmoForce
      RemoveFile MakePath(DEST$,"WINFAX.HLP"),cmoForce
      RemoveFile MakePath(DATDIR$,"LOGO.FXS"),cmoForce
      RemoveFile MakePath(DATDIR$,"WINFAX.EXE"),cmoForce
      RemoveFile MakePath(DATDIR$,"WFXCFG.DAT"),cmoForce
    ENDIF
  ENDIF


  IF UPDATENEW% = INSTMDM THEN
    IF WHICHVER% = 2 THEN
      ReplaceListItem CHECKSTATES$, FILESAPP, VON$
    ENDIF
  ELSE
    BCWriteToLogFile STARS$
    BCWriteToLogFile "Copying Files"
    BCWriteToLogFile STARS$
    CloseLogFile
    LOGOPEN% = 0
    CopyFilesInCopyList

    IF GetListItem(CHECKSTATES$, FILESCVP) = VON$ THEN
      sz$ = UIStartDlg(CUIDLL$, UPNOTE, "FModelessCentreDlgProc", 0, "")
      CursorSave% = ShowWaitCursor()

      IF GetListItem(FRMCHECKSTATES$, FRMTOW) = VON$ THEN
         d% = BCUnPackLSZ(CVPDIR$, "towhom")
         RemoveFile MakePath(CVPDIR$,"towhom.lsz"),cmoForce
      ENDIF

      IF GetListItem(FRMCHECKSTATES$, FRMMEM) = VON$ THEN
         d% = BCUnPackLSZ(CVPDIR$, "memorept")
         RemoveFile MakePath(CVPDIR$,"memorept.lsz"),cmoForce
      ENDIF

      IF GetListItem(FRMCHECKSTATES$, FRMOVE) = VON$ THEN
         d% = BCUnPackLSZ(CVPDIR$, "over2yout")
         RemoveFile MakePath(CVPDIR$,"over2you.lsz"),cmoForce
      ENDIF

      IF GetListItem(FRMCHECKSTATES$, FRMMEE) = VON$ THEN
         d% = BCUnPackLSZ(CVPDIR$, "meeting")
         RemoveFile MakePath(CVPDIR$,"meeting.lsz"),cmoForce
      ENDIF

      IF GetListItem(FRMCHECKSTATES$, FRMNUT) = VON$ THEN
         d% = BCUnPackLSZ(CVPDIR$, "nutsbolt")
         RemoveFile MakePath(CVPDIR$,"nutsbolt.lsz"),cmoForce
      ENDIF

      IF GetListItem(FRMCHECKSTATES$, FRMMON) = VON$ THEN
         d% = BCUnPackLSZ(CVPDIR$, "moneymtr")
         RemoveFile MakePath(CVPDIR$,"moneymtr.lsz"),cmoForce
      ENDIF

      IF GetListItem(FRMCHECKSTATES$, FRMOOP) = VON$ THEN
         d% = BCUnPackLSZ(CVPDIR$, "oops")
         RemoveFile MakePath(CVPDIR$,"oops.lsz"),cmoForce
      ENDIF

      IF GetListItem(FRMCHECKSTATES$, FRMSER) = VON$ THEN
         d% = BCUnPackLSZ(CVPDIR$, "service")
         RemoveFile MakePath(CVPDIR$,"service.lsz"),cmoForce
      ENDIF

      IF GetListItem(FRMCHECKSTATES$, FRMCON) = VON$ THEN
         d% = BCUnPackLSZ(CVPDIR$, "congrats")
         RemoveFile MakePath(CVPDIR$,"congrats.lsz"),cmoForce
      ENDIF

      IF GetListItem(FRMCHECKSTATES$, FRMETC) = VON$ THEN
         d% = BCUnPackLSZ(CVPDIR$, "etc")
         RemoveFile MakePath(CVPDIR$,"etc.lsz"),cmoForce
      ENDIF
      RestoreCursor CursorSave%
      UIPop 1
    ENDIF

    OpenLogfile LOGFILE$, 1
    LOGOPEN% = 1
  ENDIF


  grp$ = "WinFax PRO 3"
  PROINI$ = MakePath(DEST$, "winfax.ini")

  IF GetListItem(CHECKSTATES$, FILESAPP) = VON$ THEN
    COM$ = COMOPT$ + ":"
  ENDIF

  BCWriteToLogFile STARS$
  BCWriteToLogFile "Updating INI Files"
  BCWriteToLogFile STARS$

  gen$ = "General"
  coma$ = ","
  bs$ = "\"
  devs$ = "devices"
  dev$ = "device"
  pp$ = "PrinterPorts"
  epath$ = "ExePath"
  fpath$ = "Fax Path"
  cpath$ = "Cover Path"
  phbk$ = "PhoneBook"
  fdev$ = "Fax Device"
  modem$ = "Modem"
  windows$ = "Windows"

  IF GetListItem(CHECKSTATES$, FILESAPP) = VON$ THEN

    CreateIniKeyValue WININI$, FAXGRP$, epath$, DEST$+bs$, cmoOverwrite
    CreateIniKeyValue WININI$, FAXGRP$, fpath$, DATDIR$+bs$, cmoOverwrite
    IF UPDATENEW% <> INSTMDM THEN
      CreateIniKeyValue WININI$, FAXGRP$, phbk$, "Default", cmoOverwrite
    ENDIF
    CreateIniKeyValue WININI$, FAXGRP$, cpath$, CVPDIR$+bs$, cmoOverwrite
    CreateIniKeyValue WININI$, FAXGRP$, "VERSION", "3.0", cmoOverwrite

    CreateIniKeyValue PROINI$, gen$, fdev$, DEVOPT$, cmoOverwrite
    CreateIniKeyValue PROINI$, gen$, modem$, DEVOPTI$, cmoOverwrite

    IF DEVOPT$ = "CAS" THEN
      CreateIniKeyValue WININI$, devs$, FAXGRP$, FAXGRP$+coma$+DEVOPT$, cmoOverwrite
      CreateIniKeyValue WININI$, pp$, FAXGRP$, FAXGRP$+coma$+DEVOPT$+",15,45", cmoOverwrite
    ELSE
      CreateIniKeyValue WININI$, devs$, FAXGRP$, FAXGRP$+coma$+COM$, cmoOverwrite
      CreateIniKeyValue WININI$, pp$, FAXGRP$, FAXGRP$+coma$+COM$+",15,45", cmoOverwrite
    ENDIF

    'IF UPDATENEW% <> INSTMDM THEN
      CreateIniKeyValue WININI$, FAXGRP$, "imodemclass", DEVOPT$, cmoOverwrite
      CreateIniKeyValue WININI$, FAXGRP$, "imodemdesc", DEVOPT2$, cmoOverwrite
      CreateIniKeyValue WININI$, FAXGRP$, "imodeminit", DEVOPTI$, cmoOverwrite
    'ENDIF

    IF bWinfaxDefault% = 1 THEN
      IF DEVOPT$ = "CAS" THEN
        CreateIniKeyValue WININI$, windows$, dev$, FAXGRP$+coma$+FAXGRP$+coma$+DEVOPT$, cmoOverwrite
      ELSE
        CreateIniKeyValue WININI$, windows$, dev$, FAXGRP$+coma$+FAXGRP$+coma$+COM$, cmoOverwrite
      ENDIF
    ELSE
      i% = BCYesNo(HwndFrame(), "Select WinFax as your default printer driver?","Q7021")
      IF i% = 6 THEN
        IF DEVOPT$ = "CAS" THEN
          CreateIniKeyValue WININI$, windows$, dev$, FAXGRP$+coma$+FAXGRP$+coma$+DEVOPT$, cmoOverwrite
        ELSE
          CreateIniKeyValue WININI$, windows$, dev$, FAXGRP$+coma$+FAXGRP$+coma$+COM$, cmoOverwrite
        ENDIF
        bRestart = 1
      ENDIF
    ENDIF

    b$ = "boot"
    c$ = "comm.drv"
    IF bCommDrv% = 1 THEN
      IF DoesFileExist(MakePath(SYSDIR$,c$),femExist) = 1 THEN
        i% = BCYesNo(HwndFrame(), "You have a non-standard Com Driver installed, Change to Windows Standard Com Driver?","Q7022")
        IF i% = 6 THEN
          CreateIniKeyValue SYSINI$, b$, c$, c$, cmoOverwrite
          BCWriteToLogFile "Changing comm.drv back to = "+c$
          bRestart = 1
        ENDIF
      ENDIF
    ENDIF

    IF UPDATENEW% = INSTUPDATE THEN
      IF WHICHVER% = 1 THEN
        CopyIni "Dial Prefix"
        CopyIni "Dial Mode"
        CopyIni "Retries"
        CopyIni "Call Progress"
        CopyIni "CSID"
        CopyIni "Sender"
        CopyIni "Retry Time"
        CopyIni "Dial Control"
        CopyIni "Volume"
        CopyIni "Speaker Mode"
        CopyIni "Pulse"
      ENDIF
    ENDIF


    IF UPDATENEW% <> INSTMDM THEN

      CreateIniKeyValue WININI$, "Extensions", "cvp", MakePath(DEST$,"wfcover.exe")+" ^.cvp", cmoOverwrite
      CreateIniKeyValue WININI$, "Extensions", "fxs", MakePath(DEST$,"wfview.exe")+" ^.fxs", cmoOverwrite
      CreateIniKeyValue WININI$, "Extensions", "fxd", MakePath(DEST$,"wfview.exe")+" ^.fxd", cmoOverwrite
      CreateIniKeyValue WININI$, "Extensions", "fxr", MakePath(DEST$,"wfview.exe")+" ^.fxr", cmoOverwrite

      IF MODE% = 1 THEN
        doit% = 0
        IF bPromptIni% = 1 THEN
          i% = BCYesNo(HwndFrame(), "Make changes to your "+SYSINI$+" for more stable communications in Windows Standard Mode?","Q7024")
          IF i% = 6 THEN
            doit% = 1
          ENDIF
        ENDIF
        IF doit% = 1 THEN
          CreateIniKeyValue SYSINI$, "standard", "FasterModeSwitch", "1", cmoOverwrite
          bRestart = 1
        ENDIF
      ENDIF

      IF MODE% = 2 THEN
        IF MHZ% <= 20 AND CPUT% = 386 THEN
          doit% = 0
          IF bPromptIni% = 1 THEN
            i% = BCYesNo(HwndFrame(), "Make changes to your "+SYSINI$+" for more stable communications in Windows Enhanced Mode?","Q7025")
            IF i% = 6 THEN
              doit% = 1
            ENDIF
          ENDIF
          IF doit% = 1 THEN
            eh$ = "386Enh"
            CreateIniKeyValue SYSINI$, eh$, "COMBOOSTTIME", "20", cmoOverwrite
            CreateIniKeyValue SYSINI$, eh$, "COM1BUFFER", "256", cmoOverwrite
            CreateIniKeyValue SYSINI$, eh$, "COM2BUFFER", "256", cmoOverwrite
            CreateIniKeyValue SYSINI$, eh$, "COM3BUFFER", "256", cmoOverwrite
            CreateIniKeyValue SYSINI$, eh$, "COM4BUFFER", "256", cmoOverwrite
            bRestart = 1
          ENDIF
        ENDIF
      ENDIF

    ENDIF

  ENDIF

  IF GetListItem(CHECKSTATES$, FILESOCR) = VON$ THEN
    af$ = "AnyFax"
    CreateIniKeyValue WININI$, af$, "OP30", DEST$+bs$, cmoOverwrite
    CreateIniKeyValue WININI$, af$, "FileView", MakePath(DEST$, "ocrlink.dll"), cmoOverwrite
    CreateIniKeyValue WININI$, af$, "Autoloadocr", "NEVER", cmoOverwrite
    CreateIniKeyValue WININI$, af$, "Memsize_200", "1000", cmoOverwrite
    CreateIniKeyValue WININI$, af$, "Memsize_300", "1800", cmoOverwrite
    CreateIniKeyValue WININI$, af$, "Memsize_400", "2800", cmoOverwrite
  ENDIF

  IF GetListItem(CHECKSTATES$, FILESCVP) = VON$ THEN
    CreateIniKeyValue WININI$, FAXGRP$, cpath$, CVPDIR$+bs$, cmoOverwrite
  ENDIF

  IF UPDATENEW% = INSTMDM THEN
    IF WHICHVER% = 2 THEN
      ReplaceListItem CHECKSTATES$, FILESAPP, VOFF$
    ENDIF
  ENDIF


  BCWriteToLogFile STARS$
  BCWriteToLogFile "Creating PROGMAN Entries"
  BCWriteToLogFile STARS$


  IF GetListItem(CHECKSTATES$, FILESAPP) = VON$ THEN
    CreateProgmanGroup grp$, "", cmoNone
    CreateProgmanItem grp$, "WinFax PRO", MakePath(DEST$,"faxmng.exe"), "", cmoOverwrite
    CreateProgmanItem grp$, "Fax Viewer", MakePath(DEST$,"wfview.exe"), "", cmoOverwrite
    CreateProgmanItem grp$, "Cover Page Designer", MakePath(DEST$,"wfcover.exe"), "", cmoOverwrite
  ENDIF

  IF GetListItem(CHECKSTATES$, FILESOCR) = VON$ THEN
  ENDIF

  IF GetListItem(CHECKSTATES$, FILESAPP) = VON$ THEN
    CreateProgmanItem grp$, "Read Me", "notepad.exe "+MakePath(DEST$,"readme."), "", cmoOverwrite
    CreateProgmanItem grp$, "Install Log", "notepad.exe "+LOGFILE$, "", cmoOverwrite
  ENDIF

  IF GetListItem(CHECKSTATES$, FILESAPP) = VON$ THEN
    IF WHICHVER% = 1 THEN
      i% = BCPbkThere(OLDDAT$)
      IF i% = 1 THEN
        i% = BCYesNo(HwndFrame(), "Would you like to convert your old Phonebooks?","Q7026")
        IF i% = 6 THEN
          i% = BCPbkConv(DEST$, OLDDAT$, DATDIR$, "1 1")
        ENDIF
      ENDIF
    ENDIF
  ENDIF

  BCWriteToLogFile STARS$
  BCWriteToLogFile "END Setup Processing"
  BCWriteToLogFile STARS$

QUIT:
  IF LOGOPEN% = 0 THEN
    OpenLogfile LOGFILE$, 1
    LOGOPEN% = 1
  ENDIF

  ON ERROR GOTO ERRQUIT
  IF ERR = 0 THEN
    dlg% = EXITSUCCESS
  ELSEIF ERR = STFQUIT THEN
    dlg% = EXITQUIT
    BCWriteToLogFile "User Canceled out of Setup"
  ELSE
    dlg% = EXITFAILURE
    BCWriteToLogFile "Setup Failed"
  ENDIF

QUITL1:

  IF ERR = 0 THEN
    IF GetListItem(CHECKSTATES$, FILESAPP) = VON$ THEN
      i% = BCLaunchWait(MakePath(DEST$,"faxmng.exe"), "-s")

      IF bRegister% = 0 THEN
        msg$ = "Would you like to run the Online Registration? The Fax will be held in the queue until WinFax PRO is started."
        i% = BCYesNo(HwndFrame(), msg$,"Q7027")
        IF i% = 6 THEN
          i% = BCLaunchWait(MakePath(DEST$,"faxmng.exe"), "-r")
        ENDIF
      ENDIF
    ENDIF

    IF GetListItem(CHECKSTATES$, FILESAPP) = VON$ THEN
      sz$ = UIStartDlg(CUIDLL$, MACROINF, "FInfo0DlgProc", 0, "")
      UIPop 1
    ENDIF

  ENDIF


  sz$ = UIStartDlg(CUIDLL$, dlg%, "FInfo0DlgProc", 0, "")
  IF sz$ = "REACTIVATE" THEN
    GOTO QUITL1
  ENDIF
  UIPop 1

  IF ERR = 0 THEN
    BCWriteToLogFile "Setup Completed Successfully"

    IF bRestart% = 1 THEN
      BCWriteToLogFile "Ask for Windows Restart"
      i% = BCYesNo(HwndFrame(), "Please Exit and Restart Windows for the changes to take effect. Would you like to Exit Windows now?","Q7031")
      IF i% = 6 THEN
        CloseLogFile
        LOGOPEN% = 0
        j% = BCExit
        i% = BCOkOnly(HwndFrame(), "Windows could not close. Please close your applications and restart Windows.","Q7031")
      ENDIF
    ENDIF
  ENDIF

  IF LOGOPEN% = 1 THEN
    CloseLogFile
  ENDIF
  END

ERRQUIT:
  sz$ = "Setup sources were corrupted, call Delrina Technology Inc.!"
  i% = BCOkOnly(HwndFrame(), sz$,"Q7032")
  BCWriteToLogFile sz$
  CloseLogFile
  END

GETPATH:
  SetSymbolValue "EditTextIn", IO$
  SetSymbolValue "EditFocus", "END"
GETPATHL1:
  sz$ = UIStartDlg(CUIDLL$, DESTPATH, "FEditDlgProc", 7010, HELPPROC$)
  IF sz$ = "CONTINUE" THEN
    olddest$ = IO$
    IO$ = GetSymbolValue("EditTextOut")

    IF IsDirWritable(IO$) = 0 THEN
      GOSUB BADPATH
      GOTO GETPATHL1
    ENDIF
    UIPop 1

    IF LEN(IO$) > 23 THEN
      ReplaceListItem DRIVETEXT$, 7, MID$(IO$, 1, 23)+"..."
    ELSE
      ReplaceListItem DRIVETEXT$, 7, IO$
    ENDIF

    IF (olddest$ <> IO$) AND (olddest$ <> IO$+"\") AND (olddest$+"\" <> IO$) THEN
      RecalcPath
      SetDriveStatus
    ENDIF

    olddest$ = ""
    DEST$ = IO$
    GOTO CUSTINST
  ELSEIF sz$ = "REACTIVATE" THEN
    RecalcPath
    SetDriveStatus
    GOTO GETPATHL1
  ELSEIF sz$ = "EXIT" THEN
    GOSUB ASKQUIT
    GOTO GETPATHL1
  ELSE
    UIPop 1
    DEST$ = IO$
    GOTO CUSTINST
  ENDIF

TOOBIG:
  sz$ = UIStartDlg(CUIDLL$, TOOBIG, "FInfo0DlgProc", 0, "")
  IF sz$ = "REACTIVATE" THEN
    RecalcPath
    SetDriveStatus
    GOTO TOOBIG
  ENDIF
  BCWriteToLogFile "Not Enough Disk Space for Selected Files"
  UIPop 1
  RETURN

BADPATH:
  sz$ = UIStartDlg(CUIDLL$, BADPATH, "FInfo0DlgProc", 0, "")
  IF sz$ = "REACTIVATE" THEN
    RecalcPath
    SetDriveStatus
    GOTO BADPATH
  ENDIF
  BCWriteToLogFile "Invalid Directory Path was entered"
  UIPop 1
  RETURN

BUILDDIRS:
  IF bDATDIR% = PATHOK THEN
    DATDIR$ = MakeDir(DEST$,"DATA")
  ENDIF
  IF bCVPDIR% = PATHOK THEN
    CVPDIR$ = MakeDir(DEST$,"COVER")
  ENDIF
  IF DoesFileExist(MakePath(DATDIR$,"phonelst.dat"),femExist) = 1 THEN
    bNoPhoneBook% = 1
  ELSE
    bNoPhoneBook% = 0
  ENDIF
  MACDIR$ = MakeDir(DEST$,"MACROS")
  RETURN

ASKQUIT:
  sz$ = UIStartDlg(CUIDLL$, ASKQUIT, "FQuitDlgProc", 0, "")
  IF sz$ = "EXIT" THEN
    UIPopAll
    ERR = STFQUIT
    GOTO QUIT
  ELSEIF sz$ = "REACTIVATE" THEN
    GOTO ASKQUIT
  ELSE
    UIPop 1
  ENDIF
  RETURN

GETFPATH:
  SetSymbolValue "EditTextIn", IO$
  SetSymbolValue "EditFocus", "END"
GETFP1:
  sz$ = UIStartDlg(CUIDLL$, DESTPATH, "FEditDlgProc", 7010, HELPPROC$)
  IF sz$ = "CONTINUE" THEN
    olddest$ = IO$
    IO$ = GetSymbolValue("EditTextOut")

    IF IsDirWritable(IO$) = 0 THEN
      GOSUB BADPATH
      GOTO GETFP1
    ENDIF
    UIPop 1

  ELSEIF sz$ = "EXIT" THEN
    GOSUB ASKQUIT
    GOTO GETFP1
  ELSE
    GOTO GETFP1
  ENDIF

  UIPop 1
  RETURN


SUB AddOptFilesToCopyList (ftype%) STATIC

  IF GetListItem(CHECKSTATES$, ftype%) = VON$ THEN
     SrcDir$ = GetSymbolValue("STF_SRCDIR")

     IF ftype% = FILESAPP THEN
        AddSectionFilesToCopyList "Files", SrcDir$, DEST$
        AddSectionFilesToCopyList "Winword", SrcDir$, MACDIR$
        AddSectionFilesToCopyList "Amipro", SrcDir$, MACDIR$
        AddSectionFilesToCopyList "Excel3", SrcDir$, MACDIR$
        AddSectionFilesToCopyList "Excel4", SrcDir$, MACDIR$
        AddSectionFilesToCopyList "DRIVER", SrcDir$, SYSDIR$
        AddSectionFilesToCopyList "Twain", SrcDir$, WINDIR$
        AddSectionFilesToCopyList "basic", SrcDir$, CVPDIR$
        IF bNoPhoneBook% = 0 THEN
          AddSectionFilesToCopyList "phone", SrcDir$, DATDIR$
        ENDIF

     ELSEIF ftype% = FILESDIST THEN
        AddSectionFilesToCopyList "Win30DLL", SrcDir$, SYSDIR$

     ELSEIF ftype% = FILESOCR THEN
        AddSectionFilesToCopyList "OCR", SrcDir$, DEST$

     ELSEIF ftype% = FILESCVP THEN

        IF GetListItem(FRMCHECKSTATES$, FRMTOW) = VON$ THEN
           AddSectionKeyFileToCopyList "cvp", "towhom", SrcDir$, CVPDIR$
        ENDIF

        IF GetListItem(FRMCHECKSTATES$, FRMMEM) = VON$ THEN
           AddSectionKeyFileToCopyList "cvp", "memorept", SrcDir$, CVPDIR$
        ENDIF

        IF GetListItem(FRMCHECKSTATES$, FRMOVE) = VON$ THEN
           AddSectionKeyFileToCopyList "cvp", "over2you", SrcDir$, CVPDIR$
        ENDIF

        IF GetListItem(FRMCHECKSTATES$, FRMMEE) = VON$ THEN
           AddSectionKeyFileToCopyList "cvp", "meeting", SrcDir$, CVPDIR$
        ENDIF

        IF GetListItem(FRMCHECKSTATES$, FRMNUT) = VON$ THEN
           AddSectionKeyFileToCopyList "cvp", "nutsbolt", SrcDir$, CVPDIR$
        ENDIF

        IF GetListItem(FRMCHECKSTATES$, FRMMON) = VON$ THEN
           AddSectionKeyFileToCopyList "cvp", "moneymtr", SrcDir$, CVPDIR$
        ENDIF

        IF GetListItem(FRMCHECKSTATES$, FRMOOP) = VON$ THEN
           AddSectionKeyFileToCopyList "cvp", "oops", SrcDir$, CVPDIR$
        ENDIF

        IF GetListItem(FRMCHECKSTATES$, FRMSER) = VON$ THEN
           AddSectionKeyFileToCopyList "cvp", "service", SrcDir$, CVPDIR$
        ENDIF

        IF GetListItem(FRMCHECKSTATES$, FRMCON) = VON$ THEN
           AddSectionKeyFileToCopyList "cvp", "congrats", SrcDir$, CVPDIR$
        ENDIF

        IF GetListItem(FRMCHECKSTATES$, FRMETC) = VON$ THEN
           AddSectionKeyFileToCopyList "cvp", "etc", SrcDir$, CVPDIR$
        ENDIF

     ENDIF
     SrcDir$ = ""
  ENDIF
END SUB

SUB AddFRMFilesToCopyList (ftype%) STATIC

  IF GetListItem(FRMCHECKSTATES$, ftype%) = VON$ THEN
     SrcDir$ = GetSymbolValue("STF_SRCDIR")

     IF ftype% = FRMTOW THEN
        AddSectionKeyFileToCopyList "cvp", "towhom", SrcDir$, CVPDIR$

     ELSEIF ftype% = FRMMEM THEN
        AddSectionKeyFileToCopyList "cvp", "memorept", SrcDir$, CVPDIR$

     ELSEIF ftype% = FRMOVE THEN
        AddSectionKeyFileToCopyList "cvp", "over2you", SrcDir$, CVPDIR$

     ELSEIF ftype% = FRMMEE THEN
        AddSectionKeyFileToCopyList "cvp", "meeting", SrcDir$, CVPDIR$

     ELSEIF ftype% = FRMNUT THEN
        AddSectionKeyFileToCopyList "cvp", "nutsbolt", SrcDir$, CVPDIR$

     ELSEIF ftype% = FRMMON THEN
        AddSectionKeyFileToCopyList "cvp", "moneymtr", SrcDir$, CVPDIR$

     ELSEIF ftype% = FRMOOP THEN
        AddSectionKeyFileToCopyList "cvp", "oops", SrcDir$, CVPDIR$

     ELSEIF ftype% = FRMSER THEN
        AddSectionKeyFileToCopyList "cvp", "service", SrcDir$, CVPDIR$

     ELSEIF ftype% = FRMCON THEN
        AddSectionKeyFileToCopyList "cvp", "congrats", SrcDir$, CVPDIR$

     ELSEIF ftype% = FRMETC THEN
        AddSectionKeyFileToCopyList "cvp", "etc", SrcDir$, CVPDIR$

     ENDIF
     SrcDir$ = ""
  ENDIF
END SUB



SUB RecalcOptFiles (ftype%) STATIC
  CursorSave% = ShowWaitCursor()
  ClearCopyList
  AddOptFilesToCopyList ftype%
  fExtra% = 0

  IF ftype% = FILESAPP THEN
      ListSym$ = SPACEAPP$
      IF GetListItem(CHECKSTATES$, FILESAPP) = VON$ THEN
         ReplaceListItem EXTRACOSTS$, WINDISK%, "10240"
         fExtra% = 1
      ENDIF

  ELSEIF ftype% = FILESDIST THEN
      ListSym$ = SPACEDIST$
      IF bInstallWinDLL% = 1 THEN
         exc& = 0
         IF GetListItem(CHECKSTATES$, FILESAPP) = VON$ THEN
            StillNeed& = GetCopyListCost(EXTRACOSTS$, ListSym$, "")
            FOR i% = 1 TO 26 STEP 1
                exc&  = exc& + VAL(GetListItem(ListSym$, i%))
            NEXT i%
            fExtra% = 1
         ENDIF
         exc& = exc& + 10240
         ReplaceListItem EXTRACOSTS$, WINDISK%, STR$(exc&)
      ENDIF

  ELSEIF ftype% = FILESOCR THEN
      ListSym$ = SPACEOCR$

  ELSEIF ftype% = FILESCVP THEN
      ListSym$ = SPACECVP$

  ENDIF

  StillNeed& = GetCopyListCost(EXTRACOSTS$, ListSym$, "")

  cost& = 0

  FOR i% = 1 TO 26 STEP 1
      cost&  = cost& + VAL(GetListItem(ListSym$, i%))
  NEXT i%

  IF ListSym$ = SPACECVP$ THEN
    cost& = cost& * 2
  ENDIF

  ReplaceListItem STATUSTEXT$, ftype%, STR$(cost& / 1024) + " K"

  IF StillNeed& > 0 THEN
      ReplaceListItem BIGLIST$, ftype%, "YES"
  ELSE
      ReplaceListItem BIGLIST$, ftype%, ""
  ENDIF

  IF fExtra% THEN
      ReplaceListItem EXTRACOSTS$, WINDISK%, "0"
  ENDIF

  RestoreCursor CursorSave%
  ListSym$ = ""
END SUB

SUB RecalcFRMFiles (ftype%) STATIC
  CursorSave% = ShowWaitCursor()
  ClearCopyList
  AddFRMFilesToCopyList ftype%
  fExtra% = 0

  IF ftype% = FRMTOW THEN
      ListSym$ = SPACEFR1$

  ELSEIF ftype% = FRMMEM THEN
      ListSym$ = SPACEFR2$

  ELSEIF ftype% = FRMOVE THEN
      ListSym$ = SPACEFR3$

  ELSEIF ftype% = FRMMEE THEN
      ListSym$ = SPACEFR4$

  ELSEIF ftype% = FRMNUT THEN
      ListSym$ = SPACEFR5$

  ELSEIF ftype% = FRMMON THEN
      ListSym$ = SPACEFR6$

  ELSEIF ftype% = FRMOOP THEN
      ListSym$ = SPACEFR7$

  ELSEIF ftype% = FRMSER THEN
      ListSym$ = SPACEFR8$

  ELSEIF ftype% = FRMCON THEN
      ListSym$ = SPACEFR9$

  ELSEIF ftype% = FRMETC THEN
      ListSym$ = SPACEFR10$

  ENDIF

  StillNeed& = GetCopyListCost(EXTRACOSTS$, ListSym$, "")

  cost& = 0

  FOR i% = 1 TO 26 STEP 1
      cost&  = cost& + VAL(GetListItem(ListSym$, i%))
  NEXT i%

  cost& = cost& * 2

  ReplaceListItem FRMSTATUSTEXT$, ftype%, STR$(cost& / 1024) + " K"

  RestoreCursor CursorSave%
  ListSym$ = ""
END SUB

SUB BCWriteToLogFile (szstr$) STATIC
  IF LOGOPEN% = 1 THEN
    WriteToLogFile szstr$
  ENDIF
END SUB


SUB RecalcPath STATIC
  CursorSave% = ShowWaitCursor()

  RecalcOptFiles FILESAPP
  RecalcOptFiles FILESOCR
  RecalcOptFiles FILESCVP
  RecalcOptFiles FILESDIST

  RecalcFRMFiles FRMTOW
  RecalcFRMFiles FRMMEM
  RecalcFRMFiles FRMOVE
  RecalcFRMFiles FRMMEE
  RecalcFRMFiles FRMNUT
  RecalcFRMFiles FRMMON
  RecalcFRMFiles FRMOOP
  RecalcFRMFiles FRMSER
  RecalcFRMFiles FRMCON
  RecalcFRMFiles FRMETC

  RestoreCursor CursorSave%
END SUB


SUB SetDriveStatus STATIC
  CursorSave% = ShowWaitCursor()

  drives$ = MID$(DEST$, 1, 1)
  drives$ = drives$ + MID$(DATDIR$, 1, 1)
  drives$ = drives$ + MID$(CVPDIR$, 1, 1)
  drives$ = drives$ + WINDRIVE$

  TOBIG& = 0

  FOR i% = 1 TO 4 STEP 1
    drive$ = MID$(drives$, i%, 1)
    ndrive% = ASC(ucase$(drive$)) - ASC("A") + 1
    c1& = VAL(GetListItem(SPACEAPP$, ndrive%))
    c2& = VAL(GetListItem(SPACEOCR$, ndrive%))
    c3& = VAL(GetListItem(SPACECVP$, ndrive%))
    c3& = c3& * 2
    c4& = VAL(GetListItem(SPACEDIST$, WINDISK%))
    cost& = c1& + c2& + c3& + c4& + (300 * 1024)

    free& = GetFreeSpaceForDrive(drive$)
    IF cost& > free& THEN
       TOBIG& = 1
    ENDIF
  NEXT i%

  drive$ = MID$(DEST$, 1, 1)
  ndrive% = ASC(ucase$(drive$)) - ASC("A") + 1

  c1& = VAL(GetListItem(SPACEAPP$, ndrive%))
  c2& = VAL(GetListItem(SPACEOCR$, ndrive%))
  c3& = VAL(GetListItem(SPACECVP$, ndrive%))
  c3& = c3& * 2
  c4& = VAL(GetListItem(SPACEDIST$, WINDISK%))

  cost& = c1& + c2& + c3& + c4& + (300 * 1024)
  free& = GetFreeSpaceForDrive(drive$)
  IF cost& > free& THEN
     TOBIG& = 1
  ENDIF
  ReplaceListItem DRIVETEXT$, 1, drive$ + ":"
  ReplaceListItem DRIVETEXT$, 2, STR$(cost& / 1024) + " K"
  ReplaceListItem DRIVETEXT$, 3, STR$(free& / 1024) + " K"

  IF drive$ = WINDRIVE$ THEN
      ReplaceListItem DRIVETEXT$, 4, ""
      ReplaceListItem DRIVETEXT$, 5, ""
      ReplaceListItem DRIVETEXT$, 6, ""
  ELSE
      ndrive% = ASC(ucase$(WINDRIVE$)) - ASC("A") + 1
      c1& = VAL(GetListItem(SPACEAPP$, ndrive%))
      c3& = VAL(GetListItem(SPACEDIST$, WINDISK%))

      cost& = c1& + c3& + (20 * 1024)
      IF cost& = 0 THEN
          ReplaceListItem DRIVETEXT$, 4, ""
          ReplaceListItem DRIVETEXT$, 5, ""
          ReplaceListItem DRIVETEXT$, 6, ""
      ELSE
          free& = GetFreeSpaceForDrive(WINDRIVE$)
          IF cost& > free& THEN
             TOBIG& = 1
          ENDIF
          ReplaceListItem DRIVETEXT$, 4, WINDRIVE$ + ":"
          ReplaceListItem DRIVETEXT$, 5, STR$(cost& / 1024) + " K"
          ReplaceListItem DRIVETEXT$, 6, STR$(free& / 1024) + " K"
      ENDIF
  ENDIF
  RestoreCursor CursorSave%
END SUB

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$
  ENDIF
END FUNCTION

FUNCTION MakeDir (szDir$, szSub$) STATIC AS STRING
  IF szDir$ = "" THEN
      MakeDir = szSub$
  ELSEIF szSub$ = "" THEN
      MakeDir = szDir$
  ELSEIF MID$(szDir$, LEN(szDir$), 1) = "\" THEN
      MakeDir = szDir$ + szSub$
  ELSE
      MakeDir = szDir$ + "\" + szSub$
  ENDIF
END FUNCTION

FUNCTION StripFileName (szPath$) STATIC AS STRING
  ln% = LEN(szPath$)
  ii% = 0
  FOR i% = ln% TO 1 STEP -1
    IF MID$(szPath$, i%, 1) = "\" THEN
      ii% = i% - 1
      i% = 1
    ENDIF
  NEXT i%

  IF ii% = 0 THEN
    StripFileName = szPath$
  ELSE
    StripFileName = MID$(szPath$, 1, ii%)
  ENDIF
END FUNCTION

FUNCTION PortType (t%) STATIC AS STRING
  IF t% = 1 THEN
     PortType = "CLASS2"
  ELSEIF t% = 2 THEN
     PortType = "WORLDPORT"
  ELSEIF t% = 3 THEN
     PortType = "CLASS1"
  ELSEIF t% = 4 THEN
     PortType = "CAS"
  ELSEIF t% = 5 THEN
     PortType = "SENDFAX"
  ELSE
     PortType = "Unknown"
  ENDIF
END FUNCTION

FUNCTION ModeType (t%) STATIC AS STRING
  IF t% = 0 THEN
     ModeType = "REAL"
  ELSEIF t% = 1 THEN
     ModeType = "STANDARD"
  ELSEIF t% = 2 THEN
     ModeType = "ENHANCED"
  ELSE
     ModeType = "Unknown"
  ENDIF
END FUNCTION

SUB CopyIni (tag$) STATIC
  w$ = "WIN.INI"
  p$ = MakePath(DEST$, "winfax.ini")
  t$ = GetIniKeyString(w$, "WINFAX", tag$)
  CreateIniKeyValue p$, "General", tag$, t$, cmoOverwrite
END SUB



