xref: /AOO41X/main/solenv/bin/modules/installer/windows/inifile.pm (revision 1ba1fd998b3c63060b3efda26b9ecd3d52188c27)
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
31use strict;
32
33####################################################
34# Setting the profile for a special profileitem
35####################################################
36
37sub get_profile_for_profileitem
38{
39    my ($profileid, $filesref) = @_;
40
41    my $profile = installer::existence::get_specified_file($filesref, $profileid);
42
43    return $profile;
44}
45
46####################################################
47# Checking whether profile is included in patch
48####################################################
49
50sub profile_has_patch_flag
51{
52    my ($profile) = @_;
53
54    my $in_patch = 0;
55
56    my $styles = "";
57    if ( $profile->{'Styles'} ) { $styles = $profile->{'Styles'}; }
58    if ( $styles =~ /\bPATCH\b/ ) { $in_patch = 1; }
59
60    return $in_patch;
61}
62
63####################################################
64# Checking whether profile is part of product
65####################################################
66
67sub file_is_part_of_product
68{
69    my ($profilegid, $filesref) = @_;
70
71    foreach my $file (@$filesref)
72    {
73        my $filegid = $file->{'gid'};
74        next unless defined $filegid;
75
76        if ( $filegid eq $profilegid )
77        {
78            return 1;
79        }
80    }
81
82    return 0;
83}
84
85###########################################################################################################
86# Creating the file IniFile.idt dynamically
87# Content:
88# IniFile\tFileName\tDirProperty\tSection\tKey\tValue\tAction\tComponent_
89###########################################################################################################
90
91sub create_inifile_table
92{
93    my ($inifiletableentries, $filesref, $basedir) = @_;
94
95    my @inifiletable = ();
96
97    installer::windows::idtglobal::write_idt_header(\@inifiletable, "inifile");
98
99    for ( my $i = 0; $i <= $#{$inifiletableentries}; $i++ )
100    {
101        my $profileitem = ${$inifiletableentries}[$i];
102
103        my $profileid = $profileitem->{'ProfileID'};
104
105        # Is this profile part of the product? This is not sure, for example in patch process.
106        # If the profile is not part of the product, this ProfileItem must be ignored.
107
108        if ( ! file_is_part_of_product($profileid, $filesref) ) { next; }
109
110        my $profile = get_profile_for_profileitem($profileid, $filesref);
111
112        if (( $installer::globals::patch ) && ( ! profile_has_patch_flag($profile) )) { next; }
113
114        my %inifile = ();
115
116        $inifile{'IniFile'} = $profileitem->{'Inifiletablekey'};
117        $inifile{'FileName'} = $profile->{'Name'};
118        $inifile{'DirProperty'} = $profile->{'uniquedirname'};
119        $inifile{'Section'} = $profileitem->{'Section'};
120        $inifile{'Key'} = $profileitem->{'Key'};
121        $inifile{'Value'} = $profileitem->{'Value'};
122        $inifile{'Action'} = $profileitem->{'Inifiletableaction'};
123        $inifile{'Component_'} = $profile->{'componentname'};
124
125        my $oneline = $inifile{'IniFile'} . "\t" . $inifile{'FileName'} . "\t" . $inifile{'DirProperty'} . "\t"
126                . $inifile{'Section'} . "\t" . $inifile{'Key'} . "\t" . $inifile{'Value'} . "\t"
127                . $inifile{'Action'} . "\t" . $inifile{'Component_'} . "\n";
128
129        push(@inifiletable, $oneline);
130    }
131
132    # Saving the file
133
134    my $inifiletablename = $basedir . $installer::globals::separator . "IniFile.idt";
135    installer::files::save_file($inifiletablename ,\@inifiletable);
136    $installer::logger::Lang->printf("Created idt file: %s\n", $inifiletablename);
137}
138
1391;
140