'               *******************************************
'               *  Add-in Developer's Kit Install Script  *
'               *******************************************

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

CONST True%  = 1
CONST False% = 0

''Dialog ID's
CONST WELCOME     =  100
CONST EXITFAILURE =  400
CONST EXITQUIT    =  600
CONST EXITSUCCESS =  700
CONST APPHELP     =  900
CONST OVERWRITE   = 1000
CONST INSTALL_ADK = 1100
CONST TOOBIG      = 6300
CONST BADPATH     = 6400

''Bitmap ID
CONST LOGO         = 2

GLOBAL ADK_Dir$
GLOBAL TADK_123_Dir$
GLOBAL DRIVE$
GLOBAL DIR$
GLOBAL EXT$
GLOBAL FILENAME$
GLOBAL ADK_123_Dir$
GLOBAL W123_Dir$
GLOBAL ADKHelpIcon$
GLOBAL ADKHelpFile$
GLOBAL ADKReadmeFile$
GLOBAL ADKHelpPath$
GLOBAL ADKGroup$
GLOBAL Install_Optional_Dos_Files%
GLOBAL Install_Optional_Exe_Files%
GLOBAL Install_Optional_Help_Files%
GLOBAL Install_Optional_Sample_Files%
GLOBAL CUIDLL$
GLOBAL HELPPROC$
GLOBAL OK%

DECLARE FUNCTION Do_File_Copy AS INTEGER

DECLARE SUB Get_Install_Info
DECLARE SUB Read_In_INF_File
DECLARE SUB Update_ADK_Group
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



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

   SetBitmap CUIDLL$, LOGO
   SetTitle "Lotus Add-in Development Kit"

   Read_In_INF_File

Try_Again:
   Get_Install_Info
   i% = Do_File_Copy 
   IF i% = False% THEN
       GOTO Try_Again
   END IF
   Update_ADK_Group
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 files were corrupted!", "Setup Message", MB_OK+MB_TASKMODAL+MB_ICONHAND)
   END
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
STATIC SUB Get_Install_Info

 Try_It_Again:
   W123_Dir$ = FindTargetOnEnvVar("lotus.ini","PATH")
   IF W123_Dir$ = "" THEN
         W123_ADK_Dir$ = "C:\ADK5"
   ELSE 
        OK% = DoesIniKeyExist(W123_Dir$,"Lotus Applications","123w")
        IF OK% = 1 THEN 
                TADK_123_Dir$ = GetIniKeyString(W123_Dir$,"Lotus Applications","123w")
                SplitPath TADK_123_Dir$,DRIVE$,DIR$,FILENAME$,EXT$
                WADK_123_Dir$ = DRIVE$+DIR$+"ADK5"
        ENDIF
   ENDIF
   SetSymbolValue "EditTextIn", WADK_123_Dir$
   SetSymbolValue "CheckBoxState2", "ON"
   SetSymbolValue "CheckBoxState3", "ON"
   SetSymbolValue "CheckBoxState4", "ON"
   SetSymbolValue "CheckBoxState5", "OFF"
   SetSymbolValue "EditTextOut", ""

   loop_control% = 1
   WHILE loop_control%
       sz$ = UIStartDlg( CUIDLL$, INSTALL_ADK, "ADK_Install_Dlg", APPHELP, HELPPROC$ )
       ADKHelpIcon$ = GetSymbolValue( "EditTextOut" ) + "\HELP\ADKREF.ICO,,,," + GetSymbolValue( "EditTextOut" ) + "\HELP"
       ADKHelpPath$ = GetSymbolValue( "EditTextOut" ) + "\HELP"
       ADKHelpFile$ = "WINHELP.EXE " + GetSymbolValue( "EditTextOut" ) + "\HELP\ADKREF.HLP"
       ADKReadmeFile$ = "notepad.EXE " + GetSymbolValue( "EditTextOut" ) + "\READ.ME"

       SELECT CASE sz$
           CASE "CONTINUE"
               ADK_Dir$ = GetSymbolValue( "EditTextOut" )
               IF IsDirWritable(ADK_Dir$) = 0 THEN
                   BADPATH_MSG:
                       sz$ = UIStartDlg(CUIDLL$, BADPATH, "FInfo0DlgProc", 0, "")
                       IF sz$ = "REACTIVATE" THEN
                           GOTO BADPATH_MSG
                       END IF
               ELSE
                   loop_control% = 0
               END IF

               check_state$ = GetSymbolValue( "CheckBoxState2" )
               IF check_state$ = "ON" THEN
                   Install_Optional_Exe_Files% = True%
               END IF
               check_state$ = GetSymbolValue( "CheckBoxState3" )
               IF check_state$ = "ON" THEN
                   Install_Optional_Sample_Files% = True%
               END IF
               check_state$ = GetSymbolValue( "CheckBoxState4" )
               IF check_state$ = "ON" THEN
                   Install_Optional_Help_Files% = True%
               END IF
               check_state$ = GetSymbolValue( "CheckBoxState5" )
               IF check_state$ = "ON" THEN
                   Install_Optional_Dos_Files% = True%
               END IF

               UIPOP 1

           CASE "EXIT"  'Bail out of the Script NOW
               UIPopAll
               END

       END SELECT

   WEND

   file_exists$ = FindFileUsingFileOpen( ADK_Dir$ + "\include\lcicomn.h" )
   if file_exists$ = "" THEN
       EXIT SUB
   END IF

 Should_We_Overwrite:
   sz$ = UIStartDlg( CUIDLL$, OVERWRITE, "FInfoDlgProc", 0, "" )
   SELECT CASE sz$
       CASE "REACTIVATE"
           GOTO Should_We_Overwrite
       CASE "EXIT"
           UIPop 1
           GOTO Try_It_Again
       CASE "CONTINUE"
           UIPop 1
   END SELECT

END SUB
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
STATIC SUB Update_ADK_Group
    ADKGroup$ = "Lotus 1-2-3 R5 ADK"
    IF Install_Optional_Exe_Files% = True% THEN
        CreateProgmanGroup ADKGroup$,"",cmoNone
        CreateProgmanItem ADKGroup$,"ADK README",ADKReadmeFile$,"NOTEPAD.EXE",cmoOverwrite
            IF Install_Optional_Help_Files% = True% THEN
                CreateProgmanGroup ADKGroup$,"",cmoNone
                CreateProgmanItem ADKGroup$,"ADK Help",ADKHelpFile$,"WINHELP.EXE",cmoOverwrite
            ENDIF
     ELSEIF Install_Optional_Help_Files% = True% THEN
              CreateProgmanGroup ADKGroup$,"",cmoNone
              CreateProgmanItem ADKGroup$,"ADK Help",ADKHelpFile$,"WINHELP.EXE",cmoOverwrite
    ENDIF
END SUB
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
STATIC FUNCTION Do_File_Copy AS INTEGER

   SrcDir$ = GetSymbolValue( "STF_SRCDIR" )

   IF Install_Optional_Dos_Files% = True% THEN
      AddSectionFilesToCopyList "Include Optional", SrcDir$, ADK_Dir$ + "\INCLUDE"
      AddSectionFilesToCopyList "Lib Optional",     SrcDir$, ADK_Dir$ + "\LIB"
   END IF
   IF Install_Optional_Sample_Files% = True% THEN
      AddSectionFilesToCopyList "SAMPLES addmenu", SrcDir$, ADK_Dir$ + "\SAMPLES\addmenu"
      AddSectionFilesToCopyList "SAMPLES adndlg", SrcDir$, ADK_Dir$ + "\SAMPLES\adndlg"
      AddSectionFilesToCopyList "SAMPLES adnmdi", SrcDir$, ADK_Dir$ + "\SAMPLES\adnmdi"
      AddSectionFilesToCopyList "SAMPLES afhello", SrcDir$, ADK_Dir$ + "\SAMPLES\afhello"
      AddSectionFilesToCopyList "SAMPLES amort", SrcDir$, ADK_Dir$ + "\SAMPLES\amort"
      AddSectionFilesToCopyList "SAMPLES colors", SrcDir$, ADK_Dir$ + "\SAMPLES\colors"
      AddSectionFilesToCopyList "SAMPLES dowhen", SrcDir$, ADK_Dir$ + "\SAMPLES\dowhen"
      AddSectionFilesToCopyList "SAMPLES filememo", SrcDir$, ADK_Dir$ + "\SAMPLES\filememo"
      AddSectionFilesToCopyList "SAMPLES lmbcs", SrcDir$, ADK_Dir$ + "\SAMPLES\lmbcs"
      AddSectionFilesToCopyList "SAMPLES mysum", SrcDir$, ADK_Dir$ + "\SAMPLES\mysum"
      AddSectionFilesToCopyList "SAMPLES mchello", SrcDir$, ADK_Dir$ + "\SAMPLES\mchello"
      AddSectionFilesToCopyList "SAMPLES navigate", SrcDir$, ADK_Dir$ + "\SAMPLES\navigate"
      AddSectionFilesToCopyList "SAMPLES newstyle", SrcDir$, ADK_Dir$ + "\SAMPLES\newstyle"
      AddSectionFilesToCopyList "SAMPLES undoex", SrcDir$, ADK_Dir$ + "\SAMPLES\undoex"
      AddSectionFilesToCopyList "SAMPLES wecycle", SrcDir$, ADK_Dir$ + "\SAMPLES\wecycle"
      AddSectionFilesToCopyList "SAMPLES widthx2", SrcDir$, ADK_Dir$ + "\SAMPLES\widthx2"
      AddSectionFilesToCopyList "SAMPLES", SrcDir$, ADK_Dir$ + "\SAMPLES"
      AddSectionFilesToCopyList "SAMPLES demo", SrcDir$, ADK_Dir$ + "\SAMPLES\demo"
   END IF
   IF Install_Optional_Help_Files% = True% THEN
      AddSectionFilesToCopyList "Help", SrcDir$, ADK_Dir$ + "\HELP"
   END IF
   IF Install_Optional_Exe_Files% = True% THEN
      AddSectionFilesToCopyList "Binb", SrcDir$, ADK_Dir$ + "\BINB"
      AddSectionFilesToCopyList "ADK_ROOT", SrcDir$, ADK_Dir$
      AddSectionFilesToCopyList "Lib", SrcDir$, ADK_Dir$ + "\LIB"
      AddSectionFilesToCopyList "Include", SrcDir$, ADK_Dir$ + "\INCLUDE"
   END IF

   l& = GetCopyListCost( Extra$, Cost$, Needed$ )
   IF l& <> 0 THEN
       No_Space_Msg:
           sz$ = UIStartDlg( CUIDLL$, TOOBIG, "FInfo0DlgProc", 0, "" )
           IF sz$ = "REACTIVATE" THEN
               GOTO No_Space_Msg
           END IF
       UIPop 1
       Do_File_Copy = False
       EXIT FUNCTION
   END IF

   IF Install_Optional_Exe_Files% = True% THEN
           CreateDir ADK_Dir$ + "\INCLUDE", cmoNone
           CreateDir ADK_Dir$ + "\LIB",     cmoNone
           CreateDir ADK_Dir$ + "\BINB",    cmoNone
   ENDIF
   IF Install_Optional_Help_Files% = True% THEN
           CreateDir ADK_Dir$ + "\HELP",    cmoNone
   ENDIF
   IF Install_Optional_Sample_Files% = True% THEN
           CreateDir ADK_Dir$ + "\SAMPLES", cmoNone
   ENDIF

   CopyFilesInCopyList

   Do_File_Copy = True

END FUNCTION
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
STATIC SUB Read_In_INF_File
    szInf$ = GetSymbolValue("STF_SRCINFPATH")
    IF szInf$ = "" THEN
        szInf$ = GetSymbolValue("STF_CWDDIR") + "ADK.INF"
    END IF
    ReadInfFile szInf$
END SUB
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
