19780544fSAndrew Rist#**************************************************************
29780544fSAndrew Rist#
39780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
49780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
59780544fSAndrew Rist#  distributed with this work for additional information
69780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
79780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
89780544fSAndrew Rist#  "License"); you may not use this file except in compliance
99780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
109780544fSAndrew Rist#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
129780544fSAndrew Rist#
139780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
149780544fSAndrew Rist#  software distributed under the License is distributed on an
159780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
179780544fSAndrew Rist#  specific language governing permissions and limitations
189780544fSAndrew Rist#  under the License.
199780544fSAndrew Rist#
209780544fSAndrew Rist#**************************************************************
219780544fSAndrew Rist
229780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::windows::inifile;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse installer::existence;
27cdf0e10cSrcweiruse installer::files;
28cdf0e10cSrcweiruse installer::globals;
29cdf0e10cSrcweiruse installer::windows::idtglobal;
30cdf0e10cSrcweir
31cdf0e10cSrcweir####################################################
32cdf0e10cSrcweir# Setting the profile for a special profileitem
33cdf0e10cSrcweir####################################################
34cdf0e10cSrcweir
35cdf0e10cSrcweirsub get_profile_for_profileitem
36cdf0e10cSrcweir{
37cdf0e10cSrcweir	my ($profileid, $filesref) = @_;
38cdf0e10cSrcweir
39cdf0e10cSrcweir	my $profile = installer::existence::get_specified_file($filesref, $profileid);
40cdf0e10cSrcweir
41cdf0e10cSrcweir	return $profile;
42cdf0e10cSrcweir}
43cdf0e10cSrcweir
44cdf0e10cSrcweir####################################################
45cdf0e10cSrcweir# Checking whether profile is included in patch
46cdf0e10cSrcweir####################################################
47cdf0e10cSrcweir
48cdf0e10cSrcweirsub profile_has_patch_flag
49cdf0e10cSrcweir{
50cdf0e10cSrcweir	my ($profile) = @_;
51cdf0e10cSrcweir
52cdf0e10cSrcweir	my $in_patch = 0;
53cdf0e10cSrcweir
54cdf0e10cSrcweir	my $styles = "";
55cdf0e10cSrcweir	if ( $profile->{'Styles'} ) { $styles = $profile->{'Styles'}; }
56cdf0e10cSrcweir	if ( $styles =~ /\bPATCH\b/ ) { $in_patch = 1; }
57cdf0e10cSrcweir
58cdf0e10cSrcweir	return $in_patch;
59cdf0e10cSrcweir}
60cdf0e10cSrcweir
61cdf0e10cSrcweir####################################################
62cdf0e10cSrcweir# Checking whether profile is part of product
63cdf0e10cSrcweir####################################################
64cdf0e10cSrcweir
65cdf0e10cSrcweirsub file_is_part_of_product
66cdf0e10cSrcweir{
67cdf0e10cSrcweir	my ($profilegid, $filesref) = @_;
68cdf0e10cSrcweir
69cdf0e10cSrcweir	my $part_of_product = 0;
70cdf0e10cSrcweir
71cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
72cdf0e10cSrcweir	{
73cdf0e10cSrcweir		$onefile = ${$filesref}[$i];
74cdf0e10cSrcweir		my $filegid = $onefile->{'gid'};
75cdf0e10cSrcweir
76cdf0e10cSrcweir		if ( $filegid eq $profilegid )
77cdf0e10cSrcweir		{
78cdf0e10cSrcweir			$part_of_product = 1;
79cdf0e10cSrcweir			last;
80cdf0e10cSrcweir		}
81cdf0e10cSrcweir	}
82cdf0e10cSrcweir
83cdf0e10cSrcweir	return $part_of_product;
84cdf0e10cSrcweir}
85cdf0e10cSrcweir
86cdf0e10cSrcweir###########################################################################################################
87cdf0e10cSrcweir# Creating the file IniFile.idt dynamically
88cdf0e10cSrcweir# Content:
89cdf0e10cSrcweir# IniFile\tFileName\tDirProperty\tSection\tKey\tValue\tAction\tComponent_
90cdf0e10cSrcweir###########################################################################################################
91cdf0e10cSrcweir
92cdf0e10cSrcweirsub create_inifile_table
93cdf0e10cSrcweir{
94cdf0e10cSrcweir	my ($inifiletableentries, $filesref, $basedir) = @_;
95cdf0e10cSrcweir
96cdf0e10cSrcweir	my @inifiletable = ();
97cdf0e10cSrcweir
98cdf0e10cSrcweir	installer::windows::idtglobal::write_idt_header(\@inifiletable, "inifile");
99cdf0e10cSrcweir
100cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$inifiletableentries}; $i++ )
101cdf0e10cSrcweir	{
102cdf0e10cSrcweir		my $profileitem = ${$inifiletableentries}[$i];
103cdf0e10cSrcweir
104cdf0e10cSrcweir		my $profileid = $profileitem->{'ProfileID'};
105cdf0e10cSrcweir
106cdf0e10cSrcweir		# Is this profile part of the product? This is not sure, for example in patch process.
107cdf0e10cSrcweir		# If the profile is not part of the product, this ProfileItem must be ignored.
108cdf0e10cSrcweir
109cdf0e10cSrcweir		if ( ! file_is_part_of_product($profileid, $filesref) ) { next; }
110cdf0e10cSrcweir
111cdf0e10cSrcweir		my $profile = get_profile_for_profileitem($profileid, $filesref);
112cdf0e10cSrcweir
113cdf0e10cSrcweir		if (( $installer::globals::patch ) && ( ! profile_has_patch_flag($profile) )) { next; }
114cdf0e10cSrcweir
115cdf0e10cSrcweir		my %inifile = ();
116cdf0e10cSrcweir
117cdf0e10cSrcweir		$inifile{'IniFile'} = $profileitem->{'Inifiletablekey'};
118cdf0e10cSrcweir		$inifile{'FileName'} = $profile->{'Name'};
119cdf0e10cSrcweir		$inifile{'DirProperty'} = $profile->{'uniquedirname'};
120cdf0e10cSrcweir		$inifile{'Section'} = $profileitem->{'Section'};
121cdf0e10cSrcweir		$inifile{'Key'} = $profileitem->{'Key'};
122cdf0e10cSrcweir		$inifile{'Value'} = $profileitem->{'Value'};
123cdf0e10cSrcweir		$inifile{'Action'} = $profileitem->{'Inifiletableaction'};
124cdf0e10cSrcweir		$inifile{'Component_'} = $profile->{'componentname'};
125cdf0e10cSrcweir
126cdf0e10cSrcweir		my $oneline = $inifile{'IniFile'} . "\t" . $inifile{'FileName'} . "\t" . $inifile{'DirProperty'} . "\t"
127cdf0e10cSrcweir		 		. $inifile{'Section'} . "\t" . $inifile{'Key'} . "\t" . $inifile{'Value'} . "\t"
128cdf0e10cSrcweir		 		. $inifile{'Action'} . "\t" . $inifile{'Component_'} . "\n";
129cdf0e10cSrcweir
130cdf0e10cSrcweir		push(@inifiletable, $oneline);
131cdf0e10cSrcweir	}
132cdf0e10cSrcweir
133cdf0e10cSrcweir	# Saving the file
134cdf0e10cSrcweir
135cdf0e10cSrcweir	my $inifiletablename = $basedir . $installer::globals::separator . "IniFile.idt";
136cdf0e10cSrcweir	installer::files::save_file($inifiletablename ,\@inifiletable);
137*b274bc22SAndre Fischer    $installer::logger::Lang->printf("Created idt file: %s\n", $inifiletablename);
138cdf0e10cSrcweir}
139cdf0e10cSrcweir
140cdf0e10cSrcweir1;
141