/* rexx */

parse UPPER arg fHandle bootdrive  PATH COMPONENT

/* translation strings: */
message1R = "The Java Runtime on the system is newer than the version being installed.  Do you still wish to install the Java Runtime?"
message2R = "You are about to install over an old Beta or Alpha level of Java Runtime.  Do you still wish to install the Java Runtime?"
message1S = "The version of Samples on the system is newer than the version being installed.  Do you still wish to install the Samples component?"
message2S = "You are about to install over an old Beta or Alpha level of Samples.  Do you still wish to install the Samples component?"
message1T = "The version of the Toolkit (JDK) on the system is newer than the version being installed.  Do you still wish to install the Toolkit component?"
message2T = "You are about to install over an old Beta or Alpha level of the Toolkit (JDK).  Do you still wish to install the Toolkit component?"
message1D = "The version of ICATJAVA for OS/2 on the system is newer than the version being installed.  Do you still wish to install the ICATJAVA component?"
message2D = "You are about to install over an old Beta or Alpha level of ICATJAVA for OS/2.  Do you still wish to install the ICATJAVA component?"

call RxFuncAdd 'RexxInstResolveVariables', 'WPINSTAL', 'RexxInstResolveVariables'
call RxFuncAdd 'RexxInstSetVariable', 'WPINSTAL', 'RexxInstSetVariable'
call RxFuncAdd 'RexxInstDeselect', 'WPINSTAL', 'RexxInstDeselect'

continue = RexxInstResolveVariables( fHandle, "{Continue}", 1)
if continue = "UNATTENDED" then EXIT

if ReadSysLevel(PATH"\syslevel."COMPONENT) then do
      if substr(st.achCsdLevel, 4, 4) = 9999 then CALL 9999;
      else if substr(st.achCsdLevel, 4, 4)>> 5000 then CALL LOWER
      exit /* current syslevel at equal or higher level */
      end
EXIT   /*  none found  */


9999:   /* ALPHA/BETA level exists:    */
        path = RexxInstResolveVariables( fHandle, "{UserExitPath}", 1)
         if (COMPONENT == "JAV") then
             path'\..\message' bootdrive fHandle message2R
         else
         if (COMPONENT == "JSP") then
             path'\..\message' bootdrive fHandle message2S
         else
         if (COMPONENT == "JTK") then
             path'\..\message' bootdrive fHandle message2T
         else
         if (COMPONENT == "ICA") then
             path'\..\message' bootdrive fHandle message2D
         continue = RexxInstResolveVariables( fHandle, "{Continue}", 1)
         if continue = "QUIT" then CALL STOP; else EXIT


LOWER:   /* installing version lower than current version  */
        path = RexxInstResolveVariables( fHandle, "{UserExitPath}", 1)
         if (COMPONENT == "JAV") then
             path'\..\message' bootdrive fHandle message1R
         else
         if (COMPONENT == "JSP") then
             path'\..\message' bootdrive fHandle message1S
         else
         if (COMPONENT == "JTK") then
             path'\..\message' bootdrive fHandle message1T
         else
         if (COMPONENT == "ICA") then
             path'\..\message' bootdrive fHandle message1D
         continue = RexxInstResolveVariables( fHandle, "{Java131:Continue}", 1)
         if continue = "QUIT" then CALL STOP; else EXIT



STOP:
         if (COMPONENT == "JAV") then
         DO
             rc = RexxInstDeselect( fHandle, JV131Runtime);
             rc = RexxInstDeselect( fHandle, JV131Uninstal );
         END;
         else
         if (COMPONENT == "JSP") then
             rc = RexxInstDeselect( fHandle, JV131Samples);
         else
         if (COMPONENT == "JTK") then
             rc = RexxInstDeselect( fHandle, JV131Toolkit);
         else
         if (COMPONENT == "ICA") then
             rc = RexxInstDeselect( fHandle, JV131Debugger);
EXIT


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
