#!/usr/bin/perl
#
# $Header: //sapdb/V74/c_03/b_49/sys/src/install/perl/packages/pcr/instpcr#1 $
# $DateTime: 2007/03/29 16:08:42 $
# $Change: 148882 $
#
# Desc:


import SAPDB::Install::StdIO;
import SAPDB::Install::System;
import SAPDB::Install::Registry;
import SAPDB::Install::Tools;
import SAPDB::Install::SetUser;


$path{'name'} = 'precompiler 7403 path';
$path{'default'} = getSysProgPath().'/sapdb/indep_data';
$path{'mode'}=0775;
$path{'opt'}='pcr_7403=s';

unless($SAPDB::Install::StartInstall::opt_INSTANCE){ # these option makes no sense while instance upgrade
	$usage= " [-pcr_7403 <precompiler runtime 7403 path>]";
	$usage_desc = "\t-pcr_7403 <precompiler runtime 7403 path>\tinstallation root for pcr 7403\n";
}

@paths = (\%path);
$main_path=\%path;
@opts=();

my $data;
my $prog;

sub preinstall{
    local @ARGV=@_;
    ($data,$prog)=readIndepPath();
	$prog !~ /\S/ and $prog = $SAPDB::Install::Values::indep_prog_path;
	$prog !~ /\S/ and print2stderr("independent program path not found\n") and diesoft($SAPDB::Install::Values::diemsg);
	$data !~ /\S/ and $data = $SAPDB::Install::Values::indep_data_path;
 	$path{'value'}=$prog;
}

sub postinstall{
}

sub registerWin{
	my $path = $prog{'value'};
	$prog=~s/\//\\/g;

	my $callstring =
	(7403 >= 7404) ?
		"\"$prog\\runtime\\7403\\bin\\irconf\" -g -i -p \"$prog\\runtime\\7403\"" :
		"\"$prog\\runtime\\7403\\bin\\irconf\" -i -p \"$prog\\runtime\\7403\"";

	$callstring=~s/\//\\/g;
	$callstring=~s/%/\\/g;
	callsystem($callstring);
}

sub registerUX{
	my $callstring =
	(7403 >= 7404) ?
		"$prog/runtime/7403/bin/irconf -g -i -p $prog/runtime/7403" :
		"$prog/runtime/7403/bin/irconf -i -p $prog/runtime/7403";

	callsystem($callstring);
}


*register =             $^O =~ /^MsWin/i ? \&registerWin :
        \&registerUX;



sub unregisterWin{
	($data,$prog)=readIndepPath();
	$prog=~s/\//\\/g;

	my $callstring =
	(7403 >= 7404) ?
		"\"$prog\\runtime\\7403\\bin\\irconf\" -g -r -p \"$prog\\runtime\\7403\"" :
		"\"$prog\\runtime\\7403\\bin\\irconf\" -r -p \"$prog\\runtime\\7403\"";

	$callstring=~s/\//\\/g;
	callsystem($callstring,undef,1);

}

sub unregisterUX{
	($data,$prog)=readIndepPath();

	my $callstring =
	(7403 >= 7404) ?
		"$prog/runtime/7403/bin/irconf -g -r -p $prog/runtime/7403" :
		"$prog/runtime/7403/bin/irconf -r -p $prog/runtime/7403";

	callsystem($callstring,undef,1);

}

*unregister =           $^O =~ /^MsWin/i ? \&unregisterWin :
        \&unregisterUX;

sub preuninstall{

}

sub postuninstall{

}


sub verify{
	my %runtimes = readRuntimes();
	my ($found,$version_ok) = (0,0);
	foreach my $pcr_path (keys(%runtimes)){
		if(normalizePath($regpackobj->Path.'/runtime/7403') eq normalizePath($pcr_path)){
			$found = 1;
			if(release2num($regpackobj->Version) == release2num($runtimes{$pcr_path})){
				$version_ok = 1;
			}
			else{
				$SAPDB::Install::Values::log->SetMsg("version dont match: ".$regpackobj->Version." != ".$runtimes{$pcr_path}."\n");
			}
			last;
		}
	}
	$SAPDB::Install::Values::log->SetMsg("registration not found\n") unless $found;
	return ($found && $version_ok);
}


1;

