/* Copyright (c) Oracle Corporation 1996.  All Rights Reserved */

/*****************************************************************************
  NAME
    orainst.ins - Windows 32-bit V3 Installation Install Script

  DESCRIPTION
    This script installs the Windows 32-bit installer.

  CREATED
    Siddhartha Agarwal, July 11, 1996

  MODIFIED   MM/DD/YY REASON
  zzerhoun   05/18/98 Added backup marker code
  zzerhoun   06/03/97 remove old wshus.wmf from installer home
  njagathe   01/31/97 Moved copying of executable to after all other files
		      Test deletability of oiexec.dll before copying files, and
		      fail installation if use of the dll is detected.
  vrajkuma   12/27/96 Made OCSM compliant.

*****************************************************************************/

{
  if (doit)
    {
      overwrite_mode = 'ALWAYS;
      permit_retry_operations = TRUE;

      ui_product(product_label);

      backup_dir = "%installer_home%\backup";
      backup_marker = "%installer_home%\backup.mk";

      copy_list = list("WIN32.AVF", "WIN32.VRF", "WIN32.PVF",
	   	       "WIN32.INS", "WIN32.DEI", "WIN32.PIN", 
		       "WIN32.SHD","WIN32.RSP", 
                       "%OS_NAME%.AVF", "%OS_NAME%.VRF", "%OS_NAME%.PVF",
	               "%OS_NAME%.INS", "%OS_NAME%.DEI", "%OS_NAME%.PIN", 
		       "%OS_NAME%.SHD","%OS_NAME%.RSP", 
                       "%OS_NAME%.US","%OS_NAME%.%nls_abbreviation%",
                       "MOHCVRT.VRF","MAKEDIR.VRF");
                     
       if (os_name == "nt")
       {
        add(copy_list,"SERVICES.VRF");
        add(copy_list,"STOPSRVC.VRF");
      }
      else 
        add(copy_list,"PATH.VRF");

      if (exists(backup_marker))
      {
        if (exists(backup_dir))
        {
	  a_list = copy_list;
	  {
	    while (not(empty(a_list))) 
	      {
		the_file = first(a_list);
		a_list = rest(a_list);
		{ remove_file("%backup_dir%\%the_file%"); }
                [ 'default: continue(); ]
 	      }
	    remove_directory(backup_dir);
	  } 
	}

        remove_file(backup_marker);
      }

      /* Remove any resource files from %oracle_home%\DBS */

      old_resources = files("%oracle_home%\DBS\OI*.RES");

      while (not(empty(old_resources)))
	{
	  the_file = first(old_resources);
	  remove_file(the_file);
	  old_resources = rest(old_resources);
	}

      /* remove wshus.wmf from installer home,
	 since we will now use wshus.bmp instead */
      { remove_file("%installer_home%\wshus.wmf"); }
      ['file_not_found: continue(); ]

      { remove_file("%installer_home%\wsh%nls_abbreviation%.wmf"); }
      ['file_not_found: continue(); ]

      ui_action(instantiate(installing_resources));
      copy(res, nls_abbreviation);
      copy(dll, nls_abbreviation);

      /* ui_action(instantiate(installing_nlsdata)); */
      copy(nlb);
  /* If target home is default home, also update software\oracle key structure */
      if (oracle_home_info == default_home_info)
      {
        multiple_home_aware = FALSE;
        modify("OI_NLS32", "%INSTALLER_HOME%\NLB", "$ORACLE");
      }
      multiple_home_aware = TRUE;
      modify("OI_NLS32", "%INSTALLER_HOME%\NLB", "$ORACLE");

      ui_action(instantiate(installing_scripts));
      copy(script, nls_abbreviation);
      if (platform() == "nt")
	/* copy the nt.* scripts for backward compatibility */
	copy(ntcompat);
      else
	/* copy the win95.* scripts for backward compatibility */
	copy(win95compat);

      copy(deinstl);

      copy(prodmsg, nls_abbreviation);

      /* Narain : Moved this down here so that icon modification happens only 
	  after all other files are copied */
      ui_action(instantiate(installing_executables));

      backup_retry_permit = permit_retry_operations;
      permit_retry_operations = FALSE;

      space_in_dest = free_space("%ORACLE_HOME%\BIN");
      space_reqd = sum(exec);

      {
	copy(exec);
      } ['WRITE_ERROR: 
	  { /* Write error might have occurred due to 
	       (a) Insufficient space
	       (b) Other applications using the installer's binaries 
	    */
	    if(space_reqd > space_in_dest)
	      signal('FAILURE, installer_insufficient_space);
	    else
	      signal('FAILURE, installer_ocsa_in_use);
	  }
	'default(a,b) : signal(a,b);
	]

      copy(homesel,nls_abbreviation);
      copy(doc,"moh");

      permit_retry_operations = backup_retry_permit;

      /* MOH and OCSM registrations */
      reg_list = moh_icon_groups;
      while( not(empty(reg_list)) )
      {
	gp_sp = first(reg_list);
	if( not(empty(rest(gp_sp))) )
		win32_register_moh_icongroup(first(gp_sp), first(rest(gp_sp)));
	      else
		win32_register_moh_icongroup(first(gp_sp));
	      reg_list = rest(reg_list);
      }
      
      reg_list = min_ocsm_groups;
      while( not(empty(reg_list)) )
      {
	gp_sp = first(reg_list);
	      if( not(empty(rest(gp_sp))) )
		win32_register_ocsm_group(first(gp_sp), first(rest(gp_sp)), 'MINMODE);
	      else
	  win32_register_ocsm_group(first(gp_sp), 'MINMODE);
	      reg_list = rest(reg_list);
      }

      reg_list = max_ocsm_groups;
      while( not(empty(reg_list)) )
      {
	gp_sp = first(reg_list);
	      if( not(empty(rest(gp_sp))) )
		win32_register_ocsm_group(first(gp_sp), first(rest(gp_sp)), 'MAXMODE);
	      else
	  win32_register_ocsm_group(first(gp_sp), 'MAXMODE);
	      reg_list = rest(reg_list);
      }
      
      register(current_product);

      win32_register_ocsm_product();
      reference(current_product);
      
      permit_retry_operations = FALSE;

    }
}
