/* Copyright (c) Oracle Corporation 1994.  All Rights Reserved */

/********************************************************************
  NAME
    instloc.usr - executable file that determines the installation
                  path for the products

  DESCRIPTION
    This script determines the installation path for a product.

  MODIFIED    MM/DD/YY    Reason
   rbansal    05/12/95  Created.
*********************************************************************/

{
    install_loc_file = "%installer_home%\varfile.tmp";   
    if (not(exists(install_loc_file)))
        create_file(install_loc_file);

    if(DEVELOPER2000_RELEASE)
    {
        {product_label = product_interface_label(product_parent(current_product));}
        ['PARENT_NOT_FOUND: product_label = product_interface_label(current_product);]
    }

    {section_heading = product_filename(product_parent(current_product));}            /* determine the section heading for translate/modify */
    ['PARENT_NOT_FOUND: section_heading = product_filename(current_product);]

    /**************************
    Determine installation path
    ***************************/
    home_variable = "";               
    prompt_path = FALSE;
    modify_oracle_ini = TRUE;

    {
        home_variable = translate(install_variable, ora_config, section_heading);     /* check for existence of install variable */
        modify_oracle_ini = FALSE;
    }
    [
            'OS_ERROR,'INVALID_FILE_NAME,
            'PERMISSION_DENIED,'UNBOUND_ENVIRONMENT_VARIABLE, 'FILE_NOT_FOUND:

    {
            {
                home_variable = translate(install_variable, ora_config, "CDE");
                modify(install_variable, "", ora_config, "CDE");  
                modify(install_variable, home_variable, install_loc_file);    
            }
                [
                        'OS_ERROR,'INVALID_FILE_NAME,
                        'PERMISSION_DENIED,'UNBOUND_ENVIRONMENT_VARIABLE, 'FILE_NOT_FOUND:
                {
                    if(OLD_SECTION_HEADING_EXISTS)
                    {
                        home_variable = translate(install_variable, ora_config, OLD_SECTION_HEADING);     /* check old .ini location */
                        modify(install_variable, "", ora_config, OLD_SECTION_HEADING);    /* remove variable from old location */
                        modify(install_variable, home_variable, install_loc_file);     /* write the install location variable to the temporary file */
                    }
                        [
                                'OS_ERROR,'INVALID_FILE_NAME,
                                'PERMISSION_DENIED,'UNBOUND_ENVIRONMENT_VARIABLE, 'FILE_NOT_FOUND:
                        {home_variable = translate(install_variable, install_loc_file);}     /* check if the variable has already been written to the temporary file. If it is, it means the location has already been prompted for */
                        ]

                    home_variable = translate(install_variable, install_loc_file);     /* check if the variable has already been written to the temporary file. If it is, it means the location has already been prompted for */
                }
                    [
                            'OS_ERROR,'INVALID_FILE_NAME,'PERMISSION_DENIED,
                        'UNBOUND_ENVIRONMENT_VARIABLE, 'FILE_NOT_FOUND: prompt_path = TRUE;
                    ]
                ]
        }
    ]

    if(prompt_path)
    {
        home_variable = default_home;
/*        if (quick_install)  */  /* Disabling this feature because not requried for custom install */ /* if quick_install variable is user.avf is set, don't prompt for location */
            prompt_path = FALSE;

        makedir_default_dir          = home_variable;
        makedir_select_dir_prompt = install_product;                                /* NLS string for installation location */
        makedir_root_allowed      = TRUE;                                            /* allow installation to root level */

        /***************************************
        Make sure CDE1 and CDE2 products are not
        installed at the same location
        ****************************************/
        valid_path = FALSE;

        while(not(valid_path))
        {
            if (prompt_path)
                home_variable = execute("%installer_home%\makedir.vrf");            /* prompt for location */

            if(CDE1_PRODUCT_EXISTS)                                                    /* check for CDE1 and CDE2 location conflict only if the product was released with CDE1 */
            {
                {cde1_loc = translate(cde1_variable, ora_config, "CDE");}
                ['INVALID_FILE_NAME, 'UNBOUND_ENVIRONMENT_VARIABLE, 'FILE_NOT_FOUND: valid_path = TRUE;]    /* oracle.ini or variable doesn't exist */

                if(not(valid_path))
                {
                    if(cde1_loc==home_variable)
                    {
                        makedir_select_dir_prompt = install_loc_conflict;            /* NLS string for installation location conflict between cde1 and cde2 */
                         prompt_path = TRUE;                                            /* if quick_install variable in user.avf is set but the default location points to a conflicting location, prompt for location */
                     }
                     else
                         valid_path = TRUE;
                }
            }
            else
                valid_path = TRUE;
        }
        /****************************************/

        modify(install_variable, home_variable, install_loc_file);                     /* write the install location variable to the temporary file */
    }

    product_label = product_interface_label(current_product);
    return(home_variable);
}
