/* check prereqs               */

parse arg objectid caller   /* caller="precheck" if called by precheck.cmd */
 /* caller will help determine if this function has already been called */

/* The following block is the only set of messages that needs to be translated */
message1="您系統上的 OS/2 版本與安裝 Java 的先決條件不符，安裝程式即將終止。相關詳細內容，請參閱 Readme。"

/* End of translation */

/********** EDIT HERE TO DISABLE FIXPACK CHECKING. SET DISABLECHECK ="YES"  *******/

disablecheck="NO"

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

continue = RexxInstResolveVariables( objectid, "{Continue}", 1)
path = RexxInstResolveVariables( objectid, "{UserExitPath}", 1)

 if (caller <> "PRECHECK" & continue <> "UNATTENDED") then exit
 /* Not CID Install -- so must have already been called by precheck.cmd once --
    No need to repeat the following steps  */

 if disablecheck <> "NO" then exit(0)  /* customer overrides fixpack checking */


WSOD3 = RexxInstResolveVariables(objectid,"{WSOD3}",1)

if WSOD3 <> "NO" then exit(0)  /* It's a WSOD3 system, no fixpak checking */

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


/* Disable Syslevel checking if Env. variable JAVANOFPK is set */
if value(JAVANOFPK,,OS2ENVIRONMENT) = '' then do

 /* Check if Java 1.1 is installed. If not, should be at Fixpak 32 or Fixpak 5 */

 if substr(RexxInstResolveVariables(objectid, "{INV_Runtime:VersionNumber}", 0),1,3) <> 1.1 then do
  /* Java 1.1 not installed */

     if (stream(bootdrive"\os2\install\syslevel.fpk", 'C','query exists')) <> '' then do  /* SBCS Fixpak? */
       call ReadSysLevel(bootdrive"\os2\install\syslevel.fpk")
      /* trace ?R */
       fixlvl = substr(st.achCsdLevel,5,3)
       if (warp = 4 & aurora =0) & fixlvl < 005 then
          call oldFixpak objectid continue path message1
       if warp = 3 & fixlvl < 032 then
          call oldFixpak objectid continue path message1
     end /* SBCS Fixpak */

     else    /* Check for Aurora */
      if aurora = 0 then do
       /* Not Aurora -- So Check for DBCS Fixpak */
       if (stream(bootdrive"\os2\install\csdlevel.os2", 'C','query exists')) <> '' then do  /* DBCS Fixpak? */
         call ReadSysLevel(bootdrive"\os2\install\csdlevel.os2")
         fixlvl = substr(st.achCsdLevel,3,3)
         if warp = 4 & fixlvl < 005 then
            call oldFixpak objectid continue path message1
         fixlvl = substr(st.achCsdLevel,3,5)
         if warp = 3 & fixlvl < 03006 then
            call oldFixpak objectid continue path message1
       end /* DBCS Fixpak */
       else  /* not aurora, and no fixpacks at all installed */
         call oldFixpak objectid continue path message1
      end

   /* If we got here, means system meets pre-requisites */
 end  /* Java 1.1 installed */
end /* JAVANOFPK was not set */

newdir = directory(userexitpath"\..")
return 0


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



oldFixpak: procedure
parse arg objectid continue path message1
/* trace ?R */
 rc = RexxInstDeselect(objectid, "Java131")
   if continue <> "UNATTENDED" then do
     rc = RexxInstSetVariable(objectid, "Java131", "MB_VAR", 0);
     path'\..\message ' bootdrive objectid message1
   end
  exit (255)
