'**************************************************************************
'*                       WorldView Setup Script
'**************************************************************************

''$DEFINE DEBUG  ''Define for script development/debugging
''$DEFINE FONTSIZE

'$INCLUDE 'setupapi.inc'
'$INCLUDE 'msdetect.inc'

''Dialog ID's
CONST WELCOME       = 100
CONST ASKQUIT       = 200
CONST DESTPATH      = 300
CONST EXITFAILURE   = 400
CONST EXITQUIT      = 600
CONST EXITSUCCESS   = 700
CONST OPTIONS       = 800
CONST APPHELP       = 900
CONST BADPATH       = 6400
CONST MULTILIST	    = 5200
CONST LANG_SEL	    = 1100
CONST IDC_LANG_LIST = 1101
CONST HELP_SEL	    = 1200
CONST IDC_HELP_LIST = 1201
CONST IDC_LIST1	    = 429	''** Font list box number

CONST MB_YESNO	    = 4
CONST IDYES	    = 6
CONST IDNO	    = 7

''Bitmap ID
CONST LOGO = 1

GLOBAL APPLDIR$     ''Application directory.
GLOBAL FONTDIR$     ''Fonts directory.
GLOBAL HELPDIR$     ''Help directory.
GLOBAL OPTCUR$      ''Option selection from option dialog.
GLOBAL FONTLIST$    ''List of font names
GLOBAL DLLLIST$	    ''List of DLL Languages
GLOBAL HELPLANG$  ''Help Language of choice
GLOBAL CUIDLL$      ''Name of user dialogs DLL
GLOBAL SIZEKEYS$

DECLARE SUB Install
DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING
DECLARE FUNCTION FigureSectionSize( szSection$ ) AS LONG
DECLARE SUB FigureSizes
DECLARE SUB FigureFontSizes
DECLARE SUB FontSelect
DECLARE SUB HelpSelect
DECLARE SUB DllSelect
DECLARE SUB AskQuitDlg
DECLARE SUB FixIniFile

INIT:
    CUIDLL$ = "mscuistf.dll"            ''Custom user interface dll
    HELPPROC$ = "FHelpDlgProc"          ''Help dialog procedure
    FONTLIST$ = "FontList"		''List of desired fonts
    HELPLANG$ = "HelpLang"		''Language for Help Collection
    DLLLIST$ = "DLLList"		''Languages for DLLs
    
    SetBitmap CUIDLL$, LOGO
    SetTitle "WorldView Setup"

    SrcDir$ = GetSymbolValue("STF_SRCDIR")

    szInf$ = GetSymbolValue("STF_SRCINFPATH")
    IF szInf$ = "" THEN
        szInf$ = GetSymbolValue("STF_CWDDIR") + "IVIEW.INF"
    END IF
    ReadInfFile szInf$

    OPTCUR$ = "1"
    APPLDIR$ = "C:\IVIEW2\"
    FONTDIR$ = MakePath(APPLDIR$, "FONTS\")
    HELPDIR$ = MakePath(APPLDIR$, "HELP\")

    MakeListFromSectionKeys FONTLIST$, "Font-List"

    ''** Let's assume we aren't going to install any Language DLLs at first
    ''**MakeListFromSectionKeys DLLLIST$, "Languages"

    ''** Let's assume we'll install the english help files
    AddListItem HELPLANG$, "English"

    ''** Figure out how big the directories are
    FigureSizes
    
'$IFDEF DEBUG
    i% = SetSizeCheckMode(scmOnIgnore)    '' could use scmOff; def = scmOnFatal
    WinDrive$ = MID$(GetWindowsDir, 1, 1)
    IF IsDriveValid(WinDrive$) = 0 THEN
        i% = DoMsgBox("Windows drive ('"+WinDrive$+"') is not a valid drive.", "DEBUG", MB_TASKMODAL+MB_ICONHAND+MB_OK)
        GOTO QUIT
    END IF
'$ENDIF ''DEBUG

WELCOME:
    sz$ = UIStartDlg(CUIDLL$, WELCOME, "FInfoDlgProc", APPHELP, HELPPROC$)
    IF sz$ = "CONTINUE" THEN
        UIPop 1
    ELSE
        AskQuitDlg
        GOTO WELCOME
    END IF

OPTION:
    SetSymbolValue "ApplDirIn", APPLDIR$
    SetSymbolValue "FontDirIn", FONTDIR$
    SetSymbolValue "HelpDirIn", HELPDIR$

    ''** Get free space list
    GetLocalHardDrivesList "DrivesList"

    ''** Add network drives
    GetNetworkDrivesList "workDrivesList"
       
    szList% = GetListLength( "workDrivesList" )
    FOR i% = 1 TO szList% STEP 1
	AddListItem "DrivesList", GetListItem( "workDrivesList", i% )
    NEXT i%
    RemoveSymbol "workDrivesList"
	
    ''** Add removable drives (I know, it's a little silly, but
    ''** Bernoulli drives are considered removable)
    GetRemovableDrivesList "workDrivesList"
       
    szList% = GetListLength( "workDrivesList" )
    ''** Skip over first two (hopefully, A & B)
    FOR i% = 3 TO szList% STEP 1
	AddListItem "DrivesList", GetListItem( "workDrivesList", i% )
    NEXT i%
    RemoveSymbol "workDrivesList"
       
    szList% = GetListLength( "DrivesList" )
    FOR i% = 1 TO szList% STEP 1
	szFname$ = GetListItem( "DrivesList", i% )
	AddListItem "DrivesFreeSpaceList", STR$((GetFreeSpaceForDrive(szFname$)/1024))+"K"
    NEXT i%

OPTL1:
    sz$ = UIStartDlg(CUIDLL$, OPTIONS, "WVOptionsDlgProc", APPHELP, HELPPROC$)

    IF sz$ = "CONTINUE" THEN
        i% = DoMsgBox("Are you ready to begin the installation?", "Ready?", MB_YESNO )
        IF i% = IDNO THEN
	   GOTO OPTL1
	ENDIF			   			   			   
        UIPop(1)
    ELSEIF sz$ = "REACTIVATE" THEN
        GOTO OPTL1
    ELSEIF sz$ = "FONTSELECT" THEN
	FontSelect
	GOTO OPTL1
    ELSEIF sz$ = "HELPSELECT" THEN
	HelpSelect
	GOTO OPTL1
    ELSEIF sz$ = "DLLSELECT" THEN
	DllSelect
	GOTO OPTL1
    ELSE	
        AskQuitDlg
        GOTO OPTION
    END IF


    Install


QUIT:
    ON ERROR GOTO ERRQUIT

    IF ERR = 0 THEN
        dlg% = EXITSUCCESS
    ELSEIF ERR = STFQUIT THEN
        dlg% = EXITQUIT
    ELSE
        dlg% = EXITFAILURE
    END IF
QUITL1:
    sz$ = UIStartDlg(CUIDLL$, dlg%, "FInfo0DlgProc", 0, "")
    IF sz$ = "REACTIVATE" THEN
        GOTO QUITL1
    END IF
    UIPop 1

    END

ERRQUIT:
    i% = DoMsgBox("Setup sources were corrupted!", "Setup Message", 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



'**
'** Purpose:
'**     Builds the copy list and performs all installation operations.
'** Arguments:
'**     none.
'** Returns:
'**     none.
'*************************************************************************
SUB Install STATIC

    SrcDir$ = GetSymbolValue("STF_SRCDIR")
    OptChkd$ = GetSymbolValue("OptionsChecked")
    APPLDIR$ = GetSymbolValue("ApplDirOut")
    FONTDIR$ = GetSymbolValue("FontDirOut")
    HELPDIR$ = GetSymbolValue("HelpDirOut")

    IF LEN(APPLDIR$) > 0 THEN
     CreateDir APPLDIR$, cmoNone

     OpenLogFile MakePath(APPLDIR$, "LOGFILE.OUT"), 0
 '    OpenLogFile "H:\LOGFILE.OUT", 0
     WriteToLogFile ""
     WriteToLogFile "'" + OptChkd$ + "'"
     WriteToLogFile "'" + APPLDIR$ + "'"
     WriteToLogFile "'" + HELPDIR$ + "'"
     WriteToLogFile "'" + FONTDIR$ + "'"

     WriteToLogFile "  User chose as destination directory: '" + APPLDIR$ + "'"
     WriteToLogFile "  User chose option: '" + OPTCUR$ + "'"
     WriteToLogFile ""
     WriteToLogFile "May have had to create the directory: " + APPLDIR$
     WriteToLogFile ""

     AddSectionFilesToCopyList "Iview", SrcDir$, APPLDIR$

     ''** Figure out which Language DLLs to copy over
     langListLen% = GetListLength( DLLLIST$ )
     FOR i% = 1 TO langListLen% STEP 1
	 szLangName$ = GetListItem( DLLLIST$, i% )
	 AddSectionKeyFileToCopyList "Languages", szLangName$, SrcDir$, APPLDIR$
     NEXT i%

     TheDir$ = MakePath(APPLDIR$, "ps")
     ''** Createdir TheDir$, cmoNone
     AddSectionFilesToCopyList "Ps", SrcDir$, APPLDIR$

     ''** Get the CLIDemo stuff
     CliDir$ = MakePath(APPLDIR$, "cli")
     ''** Createdir CliDir$, cmoNone

     TheDir$ = MakePath(CliDir$, "help")
     ''** Createdir TheDir$, cmoNone
     AddSectionFilesToCopyList "Cli-Help", SrcDir$, APPLDIR$

     TheDir$ = MakePath(TheDir$, "clihelp")
     ''** Createdir TheDir$, cmoNone
     AddSectionFilesToCopyList "Cli-Help-Clihelp", SrcDir$, APPLDIR$
     
     TheDir$ = MakePath(CliDir$, "DEMO")
     ''** Createdir TheDir$, cmoNone
     AddSectionFilesToCopyList "Cli-Demo", SrcDir$, APPLDIR$

     ''** Copy Windows files to both \Windows & \APPLDIR
     AddSectionFilesToCopyList "Windows", SrcDir$, APPLDIR$
     TheDir$ = GetWindowsDir()
     AddSectionFilesToCopyList "Windows", SrcDir$, TheDir$

    ENDIF
    
    IF LEN(FONTDIR$) > 0 THEN
     ''** Pick up family indepedent font files
     
     ''** Createdir FONTDIR$, cmoNone
     AddSectionFilesToCopyList "Fonts", SrcDir$, APPLDIR$

     TheDir$ = MakePath(FONTDIR$, "dev")
     ''** Createdir TheDir$, cmoNone
     AddSectionFilesToCopyList "Fonts-Dev", SrcDir$, APPLDIR$

     TheDir$ = MakePath(FONTDIR$, "families")
     ''** Createdir TheDir$, cmoNone
     AddSectionFilesToCopyList "Fonts-Families", SrcDir$, APPLDIR$

     TheDir$ = MakePath(FONTDIR$, "outlines")
     ''** Createdir TheDir$, cmoNone
     TheDir$ = MakePath(FONTDIR$, "outlines\maps")
     ''** Createdir TheDir$, cmoNone
     AddSectionFilesToCopyList "Fonts-Outlines-Maps", SrcDir$, APPLDIR$

     TheBitmapDir$ = MakePath(FONTDIR$, "bitmap")
     ''** Createdir TheBitmapDir$, cmoNone
     TheSpeedoDir$ = MakePath(FONTDIR$, "outlines\sp")
     ''** Createdir TheSpeedoDir$, cmoNone
     AddSectionFilesToCopyList "Fonts-Outlines-Sp", SrcDir$, APPLDIR$

     ''** Get sections for each family
     szList% = GetListLength( FONTLIST$ )
    
     FOR i% = 1 TO szList% STEP 1
	szFamName$ = GetListItem( FONTLIST$, i% )

	''** Replace blanks with - to find section name
	startIdx = 1
	blankIdx = INSTR( startIdx, szFamName$, " ")
	WHILE blankIdx <> 0
	      szFamName$ = MID$( szFamName$, 1, blankIdx-1 ) + "-" + MID$( szFamName$, blankIdx+1 )
	      startIdx = blankIdx + 1
	      blankIdx = INSTR( startIdx, szFamName$, " ")
	WEND
	
	szName$ = "Font-Bitmap-" + szFamName$
	MakeListFromSectionKeys "FamKeys", szName$
	szFamList% = GetListLength( "FamKeys" )
	IF ( szFamList% > 0 ) THEN
	   AddSectionFilesToCopyList szName$, SrcDir$, APPLDIR$
	ENDIF	   

	szName$ = "Font-Speedo-" + szFamName$
	MakeListFromSectionKeys "FamKeys", szName$
	szFamList% = GetListLength( "FamKeys" )
	IF ( szFamList% > 0 ) THEN
	   AddSectionFilesToCopyList szName$, SrcDir$, APPLDIR$
	ENDIF	   
     NEXT i%
    ENDIF

    IF LEN(HELPDIR$) > 0 THEN
      ''** Figure out which Help Language docs to copy over
      langListLen% = GetListLength( HELPLANG$ )
      ''** Createdir HELPDIR$, cmoNone
      FOR i% = 1 TO langListLen% STEP 1
         szLangName$ = GetListItem( HELPLANG$, i% )
         TheDir$ = MakePath( HELPDIR$, szLangName$ )
         ''** Createdir ThEDir$, cmoNone
         AddSectionFilesToCopyList "Help-"+szLangName$, SrcDir$, APPLDIR$
         TheDir$ = MakePath( TheDir$, "DOCFILES" )
         ''** Createdir TheDir$, cmoNone
         AddSectionFilesToCopyList "Help-"+szLangName$+"-Docfiles", SrcDir$, APPLDIR$
         xDir$ = MakePath( TheDir$, "ACCESS" )
         ''** Createdir xDir$, cmoNone
         AddSectionFilesToCopyList "Help-"+szLangName$+"-Docfiles-Access", SrcDir$, APPLDIR$
         xDir$ = MakePath( TheDir$, "navigate" )
         ''** Createdir xDir$, cmoNone
         AddSectionFilesToCopyList "Help-"+szLangName$+"-Docfiles-Navigate", SrcDir$, APPLDIR$
         xDir$ = MakePath( TheDir$, "SEARCH" )
         ''** Createdir xDir$, cmoNone
         AddSectionFilesToCopyList "Help-"+szLangName$+"-Docfiles-Search", SrcDir$, APPLDIR$
         xDir$ = MakePath( TheDir$, "NOTES" )
         ''** Createdir xDir$, cmoNone
         AddSectionFilesToCopyList "Help-"+szLangName$+"-Docfiles-Notes", SrcDir$, APPLDIR$
         xDir$ = MakePath( TheDir$, "DOCDIS" )
         ''** Createdir xDir$, cmoNone
         AddSectionFilesToCopyList "Help-"+szLangName$+"-Docfiles-Docdis", SrcDir$, APPLDIR$
         xDir$ = MakePath( TheDir$, "OPTIONS" )
         ''** Createdir xDir$, cmoNone
         AddSectionFilesToCopyList "Help-"+szLangName$+"-Docfiles-Options", SrcDir$, APPLDIR$
      NEXT i%
    ENDIF
      
    CopyFilesInCopyList
  
    IF LEN(APPLDIR$) > 0 THEN
       ''** Only do this if we installed an application
       ''** I'd love to find out if it existed first, but it's not possible
       ''** Actually, it seems to be doing the right thing.....
       CreateProgmanGroup "Interleaf", "", cmoNone
       ThePath$ = MakePath(APPLDIR$, "iview.exe")
       CreateProgmanItem "Interleaf", "WorldView 2.0.1", ThePath$, "", cmoVital
       FixIniFile
    ENDIF
    
    CloseLogFile

END SUB

FUNCTION FigureSectionSize( szSection$ ) STATIC AS LONG
    SIZEKEYS$ = "SizeKeys"

    fsize& = 0

    MakeListFromSectionKeys SIZEKEYS$, szSection$
    szList% = GetListLength( SIZEKEYS$ )
    FOR i% = 1 TO szList% STEP 1
	szFname$ = GetListItem( SIZEKEYS$, i% )
	fsize& = GetSectionKeySize( szSection$, szFname$ ) + fsize&
    NEXT i%

    FigureSectionSize = fsize&
END FUNCTION
    

'** Figure out sizes of all the interesting sections

SUB FigureSizes STATIC
    hPrev% = ShowWaitCursor()

    fsize& = 0

    ''** Get size of the Iview files
    fsize& = fsize& + FigureSectionSize( "Iview" )
    
    ''** Get size of the CLI Demo files
    fsize& = fsize& + FigureSectionSize( "Cli-Demo" )
    fsize& = fsize& + FigureSectionSize( "Cli-Help" )
    fsize& = fsize& + FigureSectionSize( "Cli-Help-Clihelp" )

    ''** Get size of the PS files
    fsize& = fsize& + FigureSectionSize( "PostScript" )

    ''** Figure out sizes of the selected language DLLs
    langListLen% = GetListLength( DLLLIST$ )
    FOR i% = 1 TO langListLen% STEP 1
	szLangName$ = GetListItem( DLLLIST$, i% )
	fsize& = GetSectionKeySize( "Languages", szLangName$ ) + fsize&
    NEXT i%
    SetSymbolValue "IviewSizeIn", STR$((fsize&/1024))+"K"
    
    FigureFontSizes

    ''** Get size of the Help files
    fsize& = 0
    langListLen% = GetListLength( HELPLANG$ )
    FOR i% = 1 TO langListLen% STEP 1
       szLangName$ = GetListItem( HELPLANG$, i% )
       Fsize& = Fsize& + FigureSectionSize( "Help-"+szLangName$ )
       Fsize& = Fsize& + FigureSectionSize( "Help-"+szLangName$+"-Docfiles" )
       Fsize& = Fsize& + FigureSectionSize( "Help-"+szLangName$+"-Docfiles-Access" )
       Fsize& = Fsize& + FigureSectionSize( "Help-"+szLangName$+"-Docfiles-Navigate" )
       Fsize& = Fsize& + FigureSectionSize( "Help-"+szLangName$+"-Docfiles-Search" )
       Fsize& = Fsize& + FigureSectionSize( "Help-"+szLangName$+"-Docfiles-Notes" )
       Fsize& = Fsize& + FigureSectionSize( "Help-"+szLangName$+"-Docfiles-Docdis" )
       Fsize& = Fsize& + FigureSectionSize( "Help-"+szLangName$+"-Docfiles-Options" )
    NEXT i%
    SetSymbolValue "HelpSizeIn", STR$((fsize&/1024))+"K"

    RestoreCursor( hPrev% )
END SUB

SUB FigureFontSizes STATIC
    ''** Get size of the Font files
    fsize& = FigureSectionSize( "Fonts" )
    fsize& = fsize& + FigureSectionSize( "Fonts-Dev" )
    fsize& = fsize& + FigureSectionSize( "Fonts-Families")
    fsize& = fsize& + FigureSectionSize( "Fonts-Outlines-Map")

    ''** Get sizes for each family
    szList% = GetListLength( FONTLIST$ )
    FOR i% = 1 TO szList% STEP 1
	szFamName$ = GetListItem( FONTLIST$, i% )

	''** Replace blanks with - to find section name
	startIdx = 1
	blankIdx = INSTR( startIdx, szFamName$, " ")
	WHILE blankIdx <> 0
	      szFamName$ = MID$( szFamName$, 1, blankIdx-1 ) + "-" + MID$( szFamName$, blankIdx+1 )
	      startIdx = blankIdx + 1
	      blankIdx = INSTR( startIdx, szFamName$, " ")
	WEND
	
	''** Check for both bitmap and speedo font files
	szName$ = "Font-Bitmap-" + szFamName$
	fsize& = fsize& + FigureSectionSize(szName$)
	szName$ = "Font-Speedo-" + szFamName$
	fsize& = fsize& + FigureSectionSize(szName$)
    NEXT i%
    
    SetSymbolValue "FontsSizeIn", STR$((fsize&/1024))+"K"
END SUB

SUB FontSelect STATIC
FONTSEL:
    ''** Set up font list
    szList% = GetListLength( FONTLIST$ )
    RemoveSymbol "ListItemsOut"
    FOR i% = 1 TO szList% STEP 1
	szFname$ = GetListItem( FONTLIST$, i% )
	AddListItem "ListItemsOut", szFname$
    NEXT i%
    
    ''** This gets all the possibilities
    MakeListFromSectionKeys "ListItemsIn", "Font-List"
    SetSymbolValue "ListID", STR$( IDC_LIST1 )
    
    sz$ = UIStartDlg(CUIDLL$, MULTILIST, "FMultiDlgProc", APPHELP, HELPPROC$)
    IF sz$ = "CONTINUE" THEN
       ''* Set new font list
       RemoveSymbol FONTLIST$
       szList% = GetListLength( "ListItemsOut" )
       FOR i% = 1 TO szList% STEP 1
	   szFname$ = GetListItem( "ListItemsOut", i% )
	   AddListItem FONTLIST$, szFname$
       NEXT i%
       FigureFontSizes
    ELSEIF sz$ = "REACTIVATE" THEN
        GOTO FONTSEL
    ELSEIF sz$ = "EXIT" THEN
        AskQuitDlg
        GOTO FONTSEL
    END IF

    UIPop 1
END SUB

''** Select the Help document lanaguage
SUB HelpSelect STATIC
HELPSEL:
    ''** Set up current selections for help language list
    szList% = GetListLength( HELPLANG$ )
    RemoveSymbol "ListItemsOut"
    FOR i% = 1 TO szList% STEP 1
	szFname$ = GetListItem( HELPLANG$, i% )
	AddListItem "ListItemsOut", szFname$
    NEXT i%
    
    ''** This gets all the possibilities
    MakeListFromSectionKeys "ListItemsIn", "Help-Languages"
    SetSymbolValue "ListID", STR$( IDC_HELP_LIST )

    sz$ = UIStartDlg(CUIDLL$, HELP_SEL, "FMultiDlgProc", APPHELP, HELPPROC$)

    IF sz$ = "CONTINUE" THEN
       ''* Set new help language list
       RemoveSymbol HELPLANG$
       szList% = GetListLength( "ListItemsOut" )
       FOR i% = 1 TO szList% STEP 1
	   szFname$ = GetListItem( "ListItemsOut", i% )
	   AddListItem HELPLANG$, szFname$
       NEXT i%
       FigureSizes
    ELSEIF sz$ = "REACTIVATE" THEN
        GOTO HELPSEL
    ELSEIF sz$ = "EXIT" THEN
        AskQuitDlg
        GOTO HELPSEL
    END IF

    UIPop 1
END SUB

SUB DllSelect STATIC
DLLSEL:
    ''** Set up current selections for Language list
    szList% = GetListLength( DLLLIST$ )
    RemoveSymbol "ListItemsOut"
    FOR i% = 1 TO szList% STEP 1
	szFname$ = GetListItem( DLLLIST$, i% )
	AddListItem "ListItemsOut", szFname$
    NEXT i%
    
    ''** This gets all the possibilities
    MakeListFromSectionKeys "ListItemsIn", "Languages"
    SetSymbolValue "ListID", STR$( IDC_LANG_LIST )

    sz$ = UIStartDlg(CUIDLL$, LANG_SEL, "FMultiDlgProc", APPHELP, HELPPROC$)
    IF sz$ = "CONTINUE" THEN
       ''* Set new language list
       RemoveSymbol DLLLIST$
       szList% = GetListLength( "ListItemsOut" )
       FOR i% = 1 TO szList% STEP 1
	   szFname$ = GetListItem( "ListItemsOut", i% )
	   AddListItem DLLLIST$, szFname$
       NEXT i%
       FigureSizes
    ELSEIF sz$ = "REACTIVATE" THEN
        GOTO DLLSEL
    ELSEIF sz$ = "EXIT" THEN
        AskQuitDlg
        GOTO DLLSEL
    END IF

    UIPop 1
END SUB

SUB FixIniFile STATIC
    hPrev% = ShowWaitCursor()
    
    iview_work$ = APPLDIR$ + "iview.ini"
    iview_win$ = GetWindowsDir() + "iview.ini"

    ''** i% = DoMsgBox("ini files:"+iview_work$+iview_win$, "Ini Paths", MB_OK)

    iview_work_h% = FREEFILE
    OPEN iview_work$ FOR INPUT AS # iview_work_h%

    iview_win_h% = FREEFILE
    OPEN iview_win$ FOR OUTPUT AS # iview_win_h%

    ''** Look for the following special characters in the ini file
    ''**  '!' = Font directory prefix
    ''**  '@' = Help directory prefix
    ''**  '#' = Main application directory prefix
    FONT_PREFIX$ = "!"
    HELP_PREFIX$ = "@"
    MAIN_PREFIX$ = "#"

    ''** Make sure we have the FONT and HELP dir
    IF LEN(FONTDIR$) = 0 THEN
       FONTDIR$ = MakePath(APPLDIR$, "FONTS\")
    ENDIF
    IF LEN(HELPDIR$) = 0 THEN
       HELPDIR$ = MakePath(APPLDIR$, "HELP\")
    ENDIF
    
    ''** Go thru each line looking for PREFIX characters
    WHILE NOT EOF(iview_work_h%)
      LINE INPUT # iview_work_h%, iline$
      pos% = INSTR(iline$, HELP_PREFIX$)
      IF pos% > 0 THEN
        ''** We have a help directory
        iline$ = MID$(iline$, 1, pos%-1) + HELPDIR$ + MID$(iline$,pos%+1)
      ELSE
        pos% = INSTR(iline$, FONT_PREFIX$)
        IF pos% > 0 THEN
          ''** We have a font directory
          iline$ = MID$(iline$, 1, pos%-1) + FONTDIR$ + MID$(iline$,pos%+1)
        ELSE
          pos% = INSTR(iline$, MAIN_PREFIX$)
          IF pos% > 0 THEN
            ''** We have a main directory
            iline$ = MID$(iline$, 1, pos%-1) + APPLDIR$ + MID$(iline$,pos%+1)
          ENDIF
        ENDIF
      ENDIF

      ''** Now print out the line
      PRINT # iview_win_h%, iline$
    WEND

    CLOSE iview_work_h%
    CLOSE iview_win_h%

    RestoreCursor( hPrev% )
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

SUB AskQuitDlg STATIC
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
END SUB
