/* Copyright (c) Oracle Corporation 1992.  All Rights Reserved */
/*****************************************************************************
  NAME
    v2back.ins - V3.0.9.2 installation script for V2 Backward Compatibility

  DESCRIPTION
    This script installs a V2 Product.

  OWNER
    Kush Deepak Jain

  MODIFIED    DD-MM-YY	Reason
    ekabatch  01-30-92	Made NLS Compliant.
    kjain     01-15-92	Created.
*****************************************************************************/
{
  if (doit)
    {
      ui_product(product_label);

      ui_action(instantiate(installing_product));

      /* Make REGISTER.ORA and FILELIST.ORA files */
      create_file("%oracle_home%\DBS\FILELIST.ORA");
      all_registries = all_registrations();
      final_registries = list();
      while(not(empty(all_registries)))
        { 
	  regis = first(all_registries);
	  if(contains(registry_name(regis),"v2"))
	     add(final_registries,regis);
	  all_registries = rest(all_registries);
	}
      
      
      dos_write_v2_registry(final_registries,
			    "%oracle_home%\DBS\REGISTER.ORA");

      /* Make the Backward Compatibility BIN directori(es) */
      copy(bin);

      /* Spawn V2 Installer */
      return_code = dos_v2_spawn("%oracle_home%\XBIN\ORAINST2.EXE",
				 "%oracle_home%");

      if (return_code == 0)
	{
	  v2_number = product_number(child); 

	  ui_action(instantiate(migrating_product_with_name));

	  if (exists("%oracle_home%\CONFIG.ORA"))
	    {
	      append_file("%oracle_home%\CONFIG.ORA",ora_config);
	      remove_file("%oracle_home%\CONFIG.ORA");
	    }

	  { files = translate("%v2_number%","%oracle_home%\DBS\FILELIST.ORA",
			      " ",TRUE);}
	   [ 'UNBOUND_ENVIRONMENT_VARIABLE:
	       {
		 remove_file("%oracle_home%\DBS\FILELIST.ORA");
		 remove_file("%oracle_home%\DBS\REGISTER.ORA");
		 signal('FAILURE,installation_terminated);
	       }
	   ]

	  pre_file_list = explode(files," ");
	  file_list = list();
	  while(not(empty(pre_file_list)))
	    {
	      the_file = first(pre_file_list);
	      if(exists(the_file))
	      add(file_list,the_file);
	      pre_file_list = rest(pre_file_list);
            }

	  if (v2_number == 1)
	    {
	      s_product = "%ORACLE_HOME%\BIN\ORACLE6.EXE";
	      d_product = "%ORACLE_HOME%\XBIN\ORACLE6.EXE";
	      if(exists(s_product))
		{
		  copy_file(s_product,d_product);
		  extract(file_list,s_product);
		  add(file_list,d_product);
		}
	    }

	  created_directories = list("%oracle_home%","%oracle_home%\XBIN",
				     "%oracle_home%\DBS","%oracle_home%\BIN",
				     "%oracle_home%\DLL",
				     "%oracle_home%\ORAINST");

	  exe = make_group("exe",child);

	  while (not(empty(file_list)))
	    {
	      file = first(file_list);

	      { file_size = size(file); }
		[ 'FILE_NOT_FOUND: file_size = 0; ]

	      the_file_name = file_name(file);

	      the_directory_name = directory_name(file);

	      new_directories = list();

	      {
		while (contains(the_directory_name,oracle_home))
		  {
		    if (member(created_directories,the_directory_name))
		      signal('ENOUGH_ALREADY);

		    new_directories = cons(the_directory_name,new_directories);

		    the_directory_name = directory_name(the_directory_name);
		  }
	      }
		[ 'ENOUGH_ALREADY: continue(); ]

	      union(created_directories,new_directories);

	      while (not(empty(new_directories)))
		{
		  add_component(exe,"DIRECTORY","",first(new_directories),0);

		  new_directories = rest(new_directories);
		}

	      the_directory_name = directory_name(file);

	      if(( the_directory_name == "%ORACLE_HOME%\XBIN") ||
		 (not(contains(the_directory_name,"%ORACLE_HOME%\BIN"))))
		subgroup = "OTHER";
	      else if (contains(the_file_name,".EXE") ||
		  contains(the_file_name,".CMD"))
		{
		  subgroup = "EXE";

		  add_component(exe,"STUB",the_file_name,"%oracle_home%\XBIN\",
				dos_stub_size);
		}
	      else
		subgroup = "OTHER";

	      add_component(exe,subgroup,the_file_name,"%the_directory_name%\",
			    file_size);

	      file_list = rest(file_list);
	    }

	  copy(deinstl);

	  v2_deinstl = make_group("deinstl",child);

	  { file_size = size("%installer_home%\%v2_filename%.DEI"); }
	    [ 'FILE_NOT_FOUND: file_size = 0; ]

	  add_component(v2_deinstl,"","%v2_filename%.MAP",
			"%%installer_home%%\",0);
	  add_component(v2_deinstl,"","%v2_filename%.DEI",
			"%%installer_home%%\",file_size);

	  ui_action(instantiate(creating_stubs));

	  /* Create the stubs */
	  {
	    { dos_stubify("",exe,"EXE"); }
	      [ 'FILE_NOT_FOUND: signal('INVALID_FILE_NAME); ]
	  }
	    [ 'INVALID_FILE_NAME: signal('FAILURE,installation_corrupted); ]

	  /* Write .map file */
	  write_map(list(exe,v2_deinstl),"%installer_home%\%v2_filename%.MAP");

	  register(child);
	  reference(child);

	  remove_file("%oracle_home%\DBS\FILELIST.ORA");
	  remove_file("%oracle_home%\DBS\REGISTER.ORA");
	}
      else if (return_code == 1)
	signal('FAILURE,installation_terminated);
    }
}x