/* Copyright (c) Oracle Corporation 1993.  All Rights Reserved */

/*****************************************************************************
  NAME
    path.vrf - V3 common add-to-path script for Windows products

  DESCRIPTION
    This script adds 'path_to_add' to the path variable in AUTOEXEC.BAT.
    If the path becomes too long with the addition of 'path_to_add',
    An information dialog is displayed.  Assuming there is no signal,
    this script returns TRUE if the path was modified or FALSE if it wasn't
    (i.e., if 'path_to_add' was already on the path).

  MODIFIED   MM/DD/YY REASON
  sagarwal   09/28/95 Do not check dos_version() if in Windows 95
  zzerhoun   09/17/95 Ported to 32 bit installer 
  zzerhoun   01/10/95 Create path_file if does not exist
  dgalatin   12/17/93 Created.
*****************************************************************************/

{
  { evaluate("boot_drive"); }
    [ 'UNBOUND_VARIABLE:
      {
   	ui_action(identifying_boot_drive);

        if (operating_system == "win95")
    	  boot_drive = dos_boot_drive();
        else 
         {
         { dosver = dos_version(); }
         ['default(a,b) : 
           { 
             if(operating_system == "win95")
               dosver = "7"; /* Guessing */
             else
               signal(a,b);
           }
         ]
         if (earlier_version(dosver,"4"))
    	  {
      	    mapped_drives = dos_mapped_drives();

      	    extract(mapped_drives,"A"); extract(mapped_drives,"B");

            boot_drive = single_selection_dialog(boot_drive_prompt,
						 mapped_drives,
						 boot_drive_content,
						 boot_drive_help);
    	  }
	else
    	  boot_drive = dos_boot_drive();
         }
      }
    ]

  path_variable = "SET PATH";
  path_separator = " = ";
  path_file = "%boot_drive%:\AUTOEXEC.BAT";
  if (not(exists(path_file)))
    create_file(path_file);

  { { path_in_file = translate(path_variable,path_file,path_separator); }
    [ 'UNBOUND_ENVIRONMENT_VARIABLE:
      { path_variable = "PATH";
	{ path_in_file = translate(path_variable,path_file,path_separator); }
	  [ 'UNBOUND_ENVIRONMENT_VARIABLE:
            { path_separator = " ";		   
	      { path_in_file = translate(path_variable,path_file,
					 path_separator); }
	        [ 'UNBOUND_ENVIRONMENT_VARIABLE:
		  { path_in_file = ""; continue(); } ] 
	    } ]
	} ]
  }

  exploded_path_in_file = explode(path_in_file,";");

  if (member(exploded_path_in_file,path_to_add))
    return(FALSE);

  path_in_file = "%path_to_add%;%path_in_file%";

  len = length(path_in_file);
  if (len > 127)
    information_dialog(instantiate(path_too_long_prompt),
                       path_too_long_content,
		       instantiate(path_too_long_help));

  modify(path_variable,path_in_file,path_file,path_separator);

  return(TRUE);
}
