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