/* rexx */

/* Load external FI API
*/


call RxFuncAdd 'RexxInstSetVariable', 'WPINSTAL', 'RexxInstSetVariable'
call RxFuncAdd 'RexxInstResolveVariables', 'WPINSTAL', 'RexxInstResolveVariables'
call RxFuncAdd 'RexxInstDeselect', 'WPINSTAL', 'RexxInstDeselect'
call RxFuncAdd 'RexxInstSelect', 'WPINSTAL', 'RexxInstSelect'
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'sysLoadFuncs'
call SysLoadFuncs


/* Get the objectid (feature handle), and the current package from the arguments
*/
parse arg objectid userexitpath

package=userexitpath"\.."

/* Variables for Java Version
*/
ver=13
modify=1


bootdrive = RexxInstResolveVariables(objectid,"{BootDrive}",0)
call ReadSysLevel(bootdrive"\os2\install\syslevel.os2")
if st.bSysVersion < 40 then warp=3
else warp=4
if st.bSysVersion > 40 then aurora=1  /* OS/2 versions after Merlin */
else aurora=0

prerqdir = directory(userexitpath)
rc = check(objectid precheck)

if (rc <> 0) then exit

/* continue:  */
call RexxInstSetVariable objectid,"Java131","Warp",warp

/* Determine if we will check the runtime checkbox and feature
*/
RTChecked = 0

/* Check for a syslevel file and the correct version
*/

if ReadSysLevel(package"\syslevel.jav")  then do
   if st.bSysVersion = ver & st.bSysModify = modify then do
      call RexxInstSetVariable objectid,"JV131Runtime" ,"CheckableRT","1"
      call RexxInstSelect objectid,"JV131Runtime"
      call RexxInstSelect objectid,"JV131RuntimeConfig"
      call RexxInstSelect objectid,"JV131NSFiles"
      call RexxInstSelect objectid,"JAVA131NSFiles"
      call RexxInstSelect objectid,"JV131MZFiles"
      call RexxInstSelect objectid,"JAVA131MZFiles"

      call RexxInstSetVariable objectid,"JV131Runtime.Visible" ,"CheckableRT","1"
      call RexxInstSelect objectid,"JV131Runtime.Visible"
      call RexxInstDeSelect objectid,"JV131DefaultJVM"
      call RexxInstSetVariable objectid,"Java131" ,"CheckableJVM","1"
      RTChecked = 1
      if warp=4 then do
        call RexxInstSelect objectid,"JV131RuntimeUrls"
      end
      else do
        call RexxInstDeSelect objectid,"JV131RuntimeUrls"
      end

   end
   else do
      call RexxInstSetVariable objectid,"JV131Runtime" ,"CheckableRT","0"
      call RexxInstDeSelect objectid,"JV131Runtime"
      call RexxInstDeSelect objectid,"JV131RuntimeConfig"
      call RexxInstDeSelect objectid,"JV131NSFiles"
      call RexxInstDeSelect objectid,"JAVA131NSFiles"
      call RexxInstDeSelect objectid,"JV131MZFiles"
      call RexxInstDeSelect objectid,"JAVA131MZFiles"

      call RexxInstSetVariable objectid,"JV131Runtime.Visible" ,"CheckableRT","0"
      call RexxInstDeSelect objectid,"JV131Runtime.Visible"
      call RexxInstDeSelect objectid,"JV131RuntimeUrls"
      call RexxInstDeSelect objectid,"JV131DefaultJVM"
      call RexxInstSetVariable objectid,"Java131" ,"CheckableJVM","0"

   end
end
else do
   call RexxInstSetVariable objectid,"JV131Runtime" ,"CheckableRT","0"
   call RexxInstDeSelect    objectid,"JV131Runtime"
   call RexxInstDeSelect    objectid,"JV131RuntimeConfig"
   call RexxInstDeSelect    objectid,"JV131NSFiles"
   call RexxInstDeSelect    objectid,"JAVA131NSFiles"
   call RexxInstDeSelect    objectid,"JV131MZFiles"
   call RexxInstDeSelect    objectid,"JAVA131MZFiles"

   call RexxInstSetVariable objectid,"JV131Runtime.Visible" ,"CheckableRT","0"
   call RexxInstDeSelect    objectid,"JV131Runtime.Visible"
   call RexxInstDeSelect objectid,"JV131RuntimeUrls"
   call RexxInstDeSelect objectid,"JV131DefaultJVM"
   call RexxInstSetVariable objectid,"Java131" ,"CheckableJVM","0"
end

/* See if the user already has the correct Runtime installed
*/

RTInstalled = 0
InstalledVersion = RexxInstResolveVariables(objectid, "{INV_JV131Runtime:VersionNumber}", 0)
CurrentVersion   = RexxInstResolveVariables(objectid, "{JV131Runtime:VersionNumber}", 0)
if InstalledVersion = CurrentVersion then do
   RTInstalled = 1
end
/* Set variable for response file dependency checking */
call RexxInstSetVariable objectid, "Java131" ,"RTInstalled", RTInstalled


   /* Checkable NS implementation 9605  */
if RTChecked  then
do
   call RexxInstSetVariable objectid, "JV131NSFiles" , "CheckableNS", "1"
   rc = CheckforMozilla(objectid)
   if (rc == 1) then
     call RexxInstSetVariable objectid, "JV131MZFiles" , "CheckableMZ", "1"
   else
   do
     call RexxInstSetVariable objectid, "JV131MZFiles" , "CheckableMZ", "0"
     call RexxInstDeSelect objectid,"JV131MZFiles"
   end

end
else
do
   call RexxInstSetVariable objectid,"JV131NSFiles" ,"CheckableNS","0"
   call RexxInstSetVariable objectid,"JV131MZFiles" ,"CheckableMZ","0"
end
/* Determine if we will check the toolkit, samples and debugger checkboxs and features
*/
/* Check for a syslevel file and the correct version
*/
if ReadSysLevel(package"\syslevel.jtk")  then do
   if (st.bSysVersion = ver) & (st.bSysModify = modify) & (RTChecked | RTInstalled) then do
      if RTChecked then do
         call RexxInstSetVariable objectid,"JV131Toolkit" ,"CheckableTK","1"
         call RexxInstSelect      objectid,"JV131Toolkit"
         call RexxInstSelect      objectid,"JV131ToolkitConfig"
      end

      call RexxInstSetVariable objectid,"JV131Samples" ,"CheckableSM","1"
      call RexxInstSelect      objectid,"JV131Samples"
      call RexxInstSelect      objectid,"JV131SamplesConfig"

      call RexxInstSetVariable objectid,"JV131Debugger","CheckableIC","1"
      call RexxInstSelect      objectid,"JV131Debugger"

      if (warp=4) then do

          call RexxInstSelect objectid,"JV131SamplesUrls"
          call RexxInstSelect objectid,"JV131DebuggerUrls"
     end
      else do
           call RexxInstDeselect objectid,"JV131SamplesUrls"
           call RexxInstDeselect objectid,"JV131DebuggerUrls"
       end
   end
   else do
      call RexxInstSetVariable objectid,"JV131Toolkit" ,"CheckableTK","0"
      call RexxInstDeselect    objectid,"JV131Toolkit"
      call RexxInstDeselect    objectid,"JV131ToolkitConfig"

      call RexxInstSetVariable objectid,"JV131Samples" ,"CheckableSM","0"
      call RexxInstDeselect    objectid,"JV131Samples"
      call RexxInstDeselect    objectid,"JV131SamplesConfig"
      call RexxInstDeselect    objectid,"JV131SamplesUrls"

      call RexxInstSetVariable objectid,"JV131Debugger","CheckableIC","0"
      call RexxInstDeselect    objectid,"JV131Debugger"
      call RexxInstDeselect    objectid,"JV131DebuggerUrls"
   end
end
else do
   call RexxInstSetVariable objectid,"JV131Toolkit" ,"CheckableTK","0"
   call RexxInstDeselect    objectid,"JV131Toolkit"
   call RexxInstDeselect    objectid,"JV131ToolkitConfig"

   call RexxInstSetVariable objectid,"JV131Samples" ,"CheckableSM","0"
   call RexxInstDeselect    objectid,"JV131Samples"
   call RexxInstDeselect    objectid,"JV131SamplesConfig"
   call RexxInstDeselect    objectid,"JV131SamplesUrls"

   call RexxInstSetVariable objectid,"JV131Debugger","CheckableIC","0"
   call RexxInstDeselect    objectid,"JV131Debugger"
   call RexxInstDeselect    objectid,"JV131DebuggerUrls"
end


return 0

/**************** Begin Subroutines *******************/

/* Subroutine: ReadSysLevel
*     Input: fs - filespec of a syslevel file
*    Output: 0 = File not readable
*            1 = File readable
*
* Side Effects: Structures st and slfh created:
*               st = Syslevel Table      ( see comments below )
*             slfh = Sysleve File Header ( see comments below )
*
*
*
*
*/


ReadSysLevel: procedure expose slfh. st.
call Trace OFF
parse arg fs

   res = 0
   if stream(fs,"C","Query Exists") <> "" then do
      data = charin(fs,1,chars(fs))
      slfh.usSignature   = c2x(reverse(substr(data,1,2)))     /* special # for id of syslevel file */
      slfh.achSignature  = substr(data,3,8)                   /* string to id slf file, must be 'SYSLEVEL' */
      slfh.achJulian     = substr(data,11,5)                  /* date of version */
      slfh.usSlfVersion  = c2x(reverse(substr(data,16,2)))    /* version of syslevel file, must be 1 */
      slfh.ausReserved   = c2x(substr(data,18,16))            /* reserved */
      slfh.ulTableOffset = c2d(reverse(substr(data,34,4)))    /* offset of SYSTABLE */

      /* Calculate table start
      */
      tblst = slfh.ulTableOffset+1

      st.usSysId       = c2x(reverse(substr(data, tblst+0,2))) /* identifies system /subsytem */
      st.bSysEdition   = c2x(substr(data, tblst+2,1))          /* edition of system, eg SE=00, EE=01 */
      st.bSysVersion   = c2x(substr(data, tblst+3,1))          /* version, eg 1.00=10, 1.10=11 */
      st.bSysModify    = c2x(substr(data, tblst+4,1))          /* modify, eg 1.00=00, 1.01=01 */
      st.usSysDate     = c2x(reverse(substr(data, tblst+5,2))) /* date of system */
      st.achCsdLevel   = substr(data, tblst+7,8)               /* subsytem CSD level, eg, XR?0000_ */
      st.achCsdPrev    = substr(data, tblst+15,8)              /* as above, except for prev system */
      st.achSysName    = substr(data, tblst+23,80)             /* Title of system / subsytem (ASCIIZ) */
      st.achCompId     = substr(data, tblst+103,9)             /* component ID of subsytem */
      st.bRefreshLevel = c2x(substr(data, tblst+112,1))
      st.achType       = substr(data, tblst+113,9)             /* Null terminated type (8 chars +'\0') */
      st.usReserved    = substr(data, tblst+122,12)            /* reserved, must be 0 */
      res = 1
      call stream fs,"C","Close"
   end
return res


CheckForMozilla:procedure
parse arg objectid

  path = SysIni(,'Netscape','ALL:',keys)

  mozillainstalled = 0
  do i = 1 to keys.0
  if (keys.i >= 6.0) then
     mozillainstalled = 1
  end

  if (mozillainstalled == 1) then
        res = 1
  else
        res = 0

  return res


