/* Copyright (c) Oracle Corporation 1995.  All Rights Reserved */
/*****************************************************************************
  NAME
    rsf80.ins - WinNT V3 installation script for ORACLE Required Support Files.

  DESCRIPTION
    This script installs the RSF files.

  OWNER
    Tony Rodgers

  MODIFIED    DD-MMM-YY Reason
    rxfernan  4/98      OCSM Compliance.
    ekhor     11/24/97  reboot to complete install for WIN_95 if msvc dlls are in used
    snakai    08/18/97  8.0.4
    rpingte   12/11/96  Add trace
    mmacdona  03/13/96  Make Win32 Common
    ljiang    07/20/95  7.2
    syau      07/01/94  7.1.3
    HA!       04/28/94  7.1.2 and 3.0.10.2
    trodgers  10-APR-92 Created.
*****************************************************************************/
{
  /**************************************************************************
      Start main logic...
   **************************************************************************/
  if (doit)
    {
      ins_ratchet = "8.0.5.0.0";

  /* OCSM Compliance */
  {
    Win32_register_OCSM_product();
  }
  [
    'default: win32_ocsm_register_product();
  ]

  /* Copy shrdll group. */
  copy(shrdll);

  /* Register the groups in the map file and specify which should get
     copied over under the three OCSM installation modes. */
  win32_register_ocsm_group(deinstl,    'MAXMODE);
  win32_register_ocsm_group(msvcdll,    'MAXMODE);
  win32_register_ocsm_group(mfcdll,     'MAXMODE);
  win32_register_ocsm_group(commdll,    'MAXMODE);
  win32_register_ocsm_group(dll,        'MAXMODE);
  win32_register_ocsm_group(msg,        'MAXMODE);
  win32_register_ocsm_group(sql,        'MAXMODE);
  win32_register_ocsm_group(nlsdata,    'MAXMODE);
  win32_register_ocsm_group(user,       'MAXMODE);
  win32_register_ocsm_group(shrdll,     'MAXMODE);

  win32_register_ocsm_group(deinstl,    'MEDMODE);
  win32_register_ocsm_group(msvcdll,    'MEDMODE);
  win32_register_ocsm_group(mfcdll,     'MEDMODE);
  win32_register_ocsm_group(commdll,    'MEDMODE);
  win32_register_ocsm_group(dll,        'MEDMODE);
  win32_register_ocsm_group(msg,        'MEDMODE);
  win32_register_ocsm_group(sql,        'MEDMODE);
  win32_register_ocsm_group(nlsdata,    'MEDMODE);
  win32_register_ocsm_group(user,       'MEDMODE);
  win32_register_ocsm_group(shrdll,     'MEDMODE);

  win32_register_ocsm_group(deinstl,    'MINMODE);
  win32_register_ocsm_group(msvcdll,    'MINMODE);
  win32_register_ocsm_group(mfcdll,     'MINMODE);
  win32_register_ocsm_group(commdll,    'MINMODE);
  win32_register_ocsm_group(dll,        'MINMODE);
  win32_register_ocsm_group(msg,        'MINMODE);
  win32_register_ocsm_group(sql,        'MINMODE);
  win32_register_ocsm_group(nlsdata,    'MINMODE);
  win32_register_ocsm_group(user,       'MINMODE);
  win32_register_ocsm_group(shrdll,     'MINMODE);

  /* Register the deinst groups depending on whether 7.0.x or 7.1.x */
  /* of RSF has been installed.                                     */
  if(registered("ntrsf70"))
  {
        win32_register_ocsm_group(deinstl70, nls_abbreviation, 'MAXMODE);
        win32_register_ocsm_group(deinstl70, nls_abbreviation, 'MEDMODE);
        win32_register_ocsm_group(deinstl70, nls_abbreviation, 'MINMODE);
  }
  if(registered("ntrsf71"))
  {
        win32_register_ocsm_group(deinstl71, nls_abbreviation, 'MAXMODE);
        win32_register_ocsm_group(deinstl71, nls_abbreviation, 'MEDMODE);
        win32_register_ocsm_group(deinstl71, nls_abbreviation, 'MINMODE);
  }

  /* Register any variables in the map file that are not Installer variables. */
  win32_register_map_variable("CORE40");
  win32_register_map_variable("NLSRTL33");
  win32_register_map_variable("OTRACE80");
  win32_register_map_variable("PLSQL80");
  win32_register_map_variable("PRO80");
  win32_register_map_variable("RDBMS80");
  win32_register_map_variable("WINSYS");

  /* Register product variables or keys created in the Windows registry by this INS script. */
  /* Associated with calls to: modify(...) later on in the code.                            */

  /* First, define the key and subkey. */
  okey    = "HKEY_LOCAL_MACHINE";
  osubkey = "SOFTWARE\ORACLE";

  win32_register_key(okey, osubkey, "RDBMS80",   'REPLICATE);
  win32_register_key(okey, osubkey, "PLSQL80",   'REPLICATE);
  win32_register_key(okey, osubkey, "CORE40",    'REPLICATE);
  win32_register_key(okey, osubkey, "NLSRTL33",  'REPLICATE);
  win32_register_key(okey, osubkey, "ORA_NLS33", 'REPLICATE);
  win32_register_key(okey, osubkey, "PRO80",     'REPLICATE);
  win32_register_key(okey, osubkey, "OTRACE80",  'REPLICATE);

  /* End OCSM Compliance */

      execute("%installer_home%\%operating_system%.ins");

      permit_retry_operations = TRUE;

      ui_product(product_label);

      ui_action(instantiate(installing_scripts));
      copy(deinstl, nls_abbreviation);
      if (registered("ntrsf70"))
        copy(deinstl70, nls_abbreviation);
      if (registered("ntrsf71"))
        copy(deinstl71, nls_abbreviation);

      ui_action(instantiate(installing_dlls));

      /*** Set permit_retry_operations to FALSE first, so that we don't get cryptic error ***/
      permit_retry_operations = FALSE;

      /* rsf_in_use is a boolean which is true until the copy(*) command is succesful. */
      /* This is how we allow the user to stop services and/or applications using RSF and continue installing */
      rsf_in_use = TRUE;
      while(rsf_in_use)
      {
         write_error_occured = FALSE;
         { copy(dll);
           overwrite_mode = 'UPDATE;
           copy(olddll);
         }
         [  'WRITE_ERROR:
            {
               /* If in silent mode signal an error to avoid an infinite loop. */
               if(silent_mode)
                signal('CANCEL, inUse_prompt);

               information_dialog(inUse_prompt, inUse_content, inUse_help);
               write_error_occured = TRUE;
               continue();
            }
         ]
         if(not(write_error_occured))
         {
            rsf_in_use = FALSE;
         }
      }


      /* Copy only if earlier version exists or it doesn't exist at all. */
      overwrite_mode = 'UPDATE;

      /* rsf_in_use is a boolean which is true until the copy(*) command is succesful. */
      /* This is how we allow the user to stop services and/or applications using RSF and continue installing */
      rsf_in_use = TRUE;
      while(rsf_in_use)
      {
         write_error_occured = FALSE;
         { copy(commdll); }
         [  'WRITE_ERROR:
            {
               /* If in silent mode signal an error to avoid an infinite loop. */
               if(silent_mode)
                signal('CANCEL, inUse_prompt);

               information_dialog(inUse_prompt, inUse_content, inUse_help);
               write_error_occured = TRUE;
               continue();
            }
         ]
         if(not(write_error_occured))
         {
            rsf_in_use = FALSE;
         }
      }

      /*** Now set permit_retry_operations back to TRUE ***/
      #if (platform() == "nt")
       permit_retry_operations = FALSE;


      wininit = "%windir%\wininit.ini";
      rename_group = "rename";
      copy_msft_dlls = true;

      /* Set back to default. */
      overwrite_mode = 'ALWAYS;

      copy(msvcdll);

      copy(mfcdll);

      msvcrt40 = "%winsys%\msvcrt40.dll";
      msvcrt40new = "%winsys%\msvcrt40.new";
      msvcrt40old = "%winsys%\msvcrt40.old";
      if (not(exists(msvcrt40)))
      {
        { move_file(msvcrt40new, msvcrt40); }
        [ 'DEFAULT: copy_file(msvcrt40new, msvcrt40); ]
      }

      else
      {
        { version_no = windows_file_version(msvcrt40); }
        [ 'OS_ERROR: version_no = "0.0.0.0.0.0.0"; ]

        { version_new = windows_file_version(msvcrt40new); }
        [ 'OS_ERROR: version_new = "0.0.0.0.0.0.0"; ]

        if (earlier_version(version_no, version_new))
        {
          {
          move_file(msvcrt40, msvcrt40old);
          move_file(msvcrt40new, msvcrt40);
          }
          [ 'DEFAULT: { if (platform() == "nt")
                          copy_file(msvcrt40new, msvcrt40);
                        else
                        {
                          copy_msft_dlls = false;
                          modify(msvcrt40old,msvcrt40,wininit,rename_group);
                          modify(msvcrt40,msvcrt40new,wininit,rename_group);
                        }
                      }
          ]
        }
        else
        {
          { remove_file(msvcrt40new); }
          [ 'DEFAULT: continue(); ]
        }
      }

      msvcrt = "%winsys%\msvcrt.dll";
      msvcrtnew = "%winsys%\msvcrt.new";
      msvcrtold = "%winsys%\msvcrt.old";
      if (not(exists(msvcrt)))
      {
        { move_file(msvcrtnew, msvcrt); }
        [ 'DEFAULT: copy_file(msvcrtnew, msvcrt); ]
      }

      else
      {
        { version_no = windows_file_version(msvcrt); }
        [ 'OS_ERROR: version_no = "0.0.0.0.0.0.0"; ]

        { version_new = windows_file_version(msvcrtnew); }
        [ 'OS_ERROR: version_new = "0.0.0.0.0.0.0"; ]

        if (earlier_version(version_no, version_new))
        {
          {
          move_file(msvcrt, msvcrtold);
          move_file(msvcrtnew, msvcrt);
          }
          [ 'DEFAULT: { if (platform() == "nt")
                          copy_file(msvcrtnew, msvcrt);
                        else
                        {
                          copy_msft_dlls = false;
                          modify(msvcrtold,msvcrt,wininit,rename_group);
                          modify(msvcrt,msvcrtnew,wininit,rename_group);
                        }
                      }
          ]
        }
        else
        {
          { remove_file(msvcrtnew); }
          [ 'DEFAULT: continue(); ]
        }
      }

      msvcirt = "%winsys%\msvcirt.dll";
      msvcirtnew = "%winsys%\msvcirt.new";
      msvcirtold = "%winsys%\msvcirt.old";
      if (not(exists(msvcirt)))
      {
        { move_file(msvcirtnew, msvcirt); }
        [ 'DEFAULT: copy_file(msvcirtnew, msvcirt); ]
      }

      else
      {
        { version_no = windows_file_version(msvcirt); }
        [ 'OS_ERROR: version_no = "0.0.0.0.0.0.0"; ]

        { version_new = windows_file_version(msvcirtnew); }
        [ 'OS_ERROR: version_new = "0.0.0.0.0.0.0"; ]

        if (earlier_version(version_no, version_new))
        {
          {
          move_file(msvcirt, msvcirtold);
          move_file(msvcirtnew, msvcirt);
          }
          [ 'DEFAULT: { if (platform() == "nt")
                          copy_file(msvcirtnew, msvcirt);
                        else
                        {
                          copy_msft_dlls = false;
                          modify(msvcirtold,msvcirt,wininit,rename_group);
                          modify(msvcirt,msvcirtnew,wininit,rename_group);
                        }
                      }
          ]
        }
        else
        {
          { remove_file(msvcirtnew); }
          [ 'DEFAULT: continue(); ]
        }
      }

      mfc40 = "%winsys%\mfc40.dll";
      mfc40new = "%winsys%\mfc40.new";
      mfc40old = "%winsys%\mfc40.old";
      if (not(exists(mfc40)))
      {
        { move_file(mfc40new, mfc40); }
        [ 'DEFAULT: copy_file(mfc40new, mfc40); ]
      }

      else
      {
        { version_no = windows_file_version(mfc40); }
        [ 'OS_ERROR: version_no = "0.0.0.0.0.0.0"; ]

        { version_new = windows_file_version(mfc40new); }
        [ 'OS_ERROR: version_new = "0.0.0.0.0.0.0"; ]

        if (earlier_version(version_no, version_new))
        {
          {
          move_file(mfc40, mfc40old);
          move_file(mfc40new, mfc40);
          }
          [ 'DEFAULT: { if (platform() == "nt")
                          copy_file(mfc40new, mfc40);
                        else
                        {
                          copy_msft_dlls = false;
                          modify(mfc40old,mfc40,wininit,rename_group);
                          modify(mfc40,mfc40new,wininit,rename_group);
                        }
                      }
          ]
        }
        else
        {
          { remove_file(mfc40new); }
          [ 'DEFAULT: continue(); ]
        }
      }

      mfc42 = "%winsys%\mfc42.dll";
      mfc42new = "%winsys%\mfc42.new";
      mfc42old = "%winsys%\mfc42.old";
      if (not(exists(mfc42)))
      {
        { move_file(mfc42new, mfc42); }
        [ 'DEFAULT: copy_file(mfc42new, mfc42); ]
      }

      else
      {
        { version_no = windows_file_version(mfc42); }
        [ 'OS_ERROR: version_no = "0.0.0.0.0.0.0"; ]

        { version_new = windows_file_version(mfc42new); }
        [ 'OS_ERROR: version_new = "0.0.0.0.0.0.0"; ]

        if (earlier_version(version_no, version_new))
        {
          {
          move_file(mfc42, mfc42old);
          move_file(mfc42new, mfc42);
          }
          [ 'DEFAULT: { if (platform() == "nt")
                          copy_file(mfc42new, mfc42);
                        else
                        {
                          copy_msft_dlls = false;
                          modify(mfc42old,mfc42,wininit,rename_group);
                          modify(mfc42,mfc42new,wininit,rename_group);
                        }
                      }
          ]
        }
        else
        {
          { remove_file(mfc42new); }
          [ 'DEFAULT: continue(); ]
        }
      }

      olepro32 = "%winsys%\olepro32.dll";
      olepro32new = "%winsys%\olepro32.new";
      olepro32old = "%winsys%\olepro32.old";
      if (not(exists(olepro32)))
      {
        { move_file(olepro32new, olepro32); }
        [ 'DEFAULT: copy_file(olepro32new, olepro32); ]
      }

      else
      {
        { version_no = windows_file_version(olepro32); }
        [ 'OS_ERROR: version_no = "0.0.0.0.0.0.0"; ]

        { version_new = windows_file_version(olepro32new); }
        [ 'OS_ERROR: version_new = "0.0.0.0.0.0.0"; ]

        if (earlier_version(version_no, version_new))
        {
          {
          move_file(olepro32, olepro32old);
          move_file(olepro32new, olepro32);
          }
          [ 'DEFAULT: { if (platform() == "nt")
                          copy_file(olepro32new, olepro32);
                        else
                        {
                          copy_msft_dlls = false;
                          modify(olepro32old,olepro32,wininit,rename_group);
                          modify(olepro32,olepro32new,wininit,rename_group);
                        }
                      }
          ]
        }
        else
        {
          { remove_file(olepro32new); }
          [ 'DEFAULT: continue(); ]
        }
      }

      oleaut32 = "%winsys%\oleaut32.dll";
      oleaut32new = "%winsys%\oleaut32.new";
      oleaut32old = "%winsys%\oleaut32.old";
      if (not(exists(oleaut32)))
      {
        { move_file(oleaut32new, oleaut32); }
        [ 'DEFAULT: copy_file(oleaut32new, oleaut32); ]
      }

      else
      {
        { version_no = windows_file_version(oleaut32); }
        [ 'OS_ERROR: version_no = "0.0.0.0.0.0.0"; ]

        { version_new = windows_file_version(oleaut32new); }
        [ 'OS_ERROR: version_new = "0.0.0.0.0.0.0"; ]

        if (earlier_version(version_no, version_new))
        {
          {
          move_file(oleaut32, oleaut32old);
          move_file(oleaut32new, oleaut32);
          }
          [ 'DEFAULT: { if (platform() == "nt")
                          copy_file(oleaut32new, oleaut32);
                        else
                        {
                          copy_msft_dlls = false;
                          modify(oleaut32old,oleaut32,wininit,rename_group);
                          modify(oleaut32,oleaut32new,wininit,rename_group);
                        }
                      }
          ]
        }
        else
        {
          { remove_file(oleaut32new); }
          [ 'DEFAULT: continue(); ]
        }
      }


      /* Display an advertisement bitmap only in pkg installation of Enterprise Edition and Oracle8. */
      /* Catch unbound variable defined in user.stp and default to an empty value (rxfernan-JUN-97). */
      { install_type = install_type; }
      [ 'UNBOUND_VARIABLE: install_type = ""; ]

      if((install_type == "Oracle8 Enterprise Edition") || (install_type == "Oracle8"))
      {
         { ui_graphics("%product_home%\b2.bmp"); }
         [ 'DEFAULT : continue(); ]
      }
      /* End Display advertisement bitmap. */




      ui_action(instantiate(installing_msbs));
      copy(msg, nls_abbreviation);

      ui_action(instantiate(installing_sql));
      copy(sql);

      ui_action(instantiate(installing_nlsdata));
      copy(nlsdata);

      /* copy release notes */
      permit_retry_operations = false;

      { copy(user, user_release_grp) ;}
      [ 'DEFAULT : continue() ; ]
      permit_retry_operations = true;

      if (set_rdbms80)
        {
          ui_action(instantiate(modifying_config));
          modify("RDBMS80",RDBMS80,ora_config,product_filename(current_product));
        }

      if (set_plsql80)
        {
          ui_action(instantiate(modifying_config));
          modify("PLSQL80",PLSQL80,ora_config,product_filename(current_product));
        }

      if (set_core40)
        {
          ui_action(instantiate(modifying_config));
          modify("CORE40",CORE40,ora_config,product_filename(current_product));
        }


      if (set_nlsrtl33)
        {
          ui_action(instantiate(modifying_config));
          modify("NLSRTL33",NLSRTL33,ora_config,product_filename(current_product));
        }

      if (set_ora_nls)
        {
          ui_action(instantiate(modifying_config));
          modify("ORA_NLS33",ORA_NLS33,ora_config,product_filename(current_product));
        }

      if (set_pro80)
        {
          ui_action(instantiate(modifying_config));
          modify("PRO80",PRO80,ora_config,product_filename(current_product));
        }

      if (set_trace80)
        {
          ui_action(instantiate(modifying_config));
          modify("OTRACE80",OTRACE80,ora_config,product_filename(current_product));
        }


      /*** Force install sqlnet client and trace server ***/
      install(client_prod);
      install(trace_prod);

      if(registered(trace_name))
      {
         reference(trace_prod);
      }
      if(registered(client_name))
      {
         reference(client_prod);
      }


      ui_action(instantiate(registering));
      register(current_product);
      if (member(selected_products,current_product))
        reference(current_product);


      ui_action(instantiate(registering));
      register(current_product);
      if (member(selected_products,current_product))
        reference(current_product);

      if (not(copy_msft_dlls))
        if(not(member(remind_list, rsf_note)))
          add(remind_list, rsf_note);

      permit_retry_operations = FALSE;
    }
}
