xref: /trunk/main/solenv/bin/modules/installer/windows/featurecomponent.pm (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1#*************************************************************************
2#
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# Copyright 2000, 2010 Oracle and/or its affiliates.
6#
7# OpenOffice.org - a multi-platform office productivity suite
8#
9# This file is part of OpenOffice.org.
10#
11# OpenOffice.org is free software: you can redistribute it and/or modify
12# it under the terms of the GNU Lesser General Public License version 3
13# only, as published by the Free Software Foundation.
14#
15# OpenOffice.org is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU Lesser General Public License version 3 for more details
19# (a copy is included in the LICENSE file that accompanied this code).
20#
21# You should have received a copy of the GNU Lesser General Public License
22# version 3 along with OpenOffice.org.  If not, see
23# <http://www.openoffice.org/license.html>
24# for a copy of the LGPLv3 License.
25#
26#*************************************************************************
27
28package installer::windows::featurecomponent;
29
30use installer::converter;
31use installer::existence;
32use installer::exiter;
33use installer::files;
34use installer::globals;
35use installer::windows::idtglobal;
36
37#################################################################################
38# Collecting all pairs of features and components from the files collector
39#################################################################################
40
41sub create_featurecomponent_table_from_files_collector
42{
43    my ($featurecomponenttableref, $filesref) = @_;
44
45    for ( my $i = 0; $i <= $#{$filesref}; $i++ )
46    {
47        my $onefile = ${$filesref}[$i];
48
49        my $filecomponent = $onefile->{'componentname'};
50        my $filemodules = $onefile->{'modules'};
51
52        if ( $filecomponent eq "" )
53        {
54            installer::exiter::exit_program("ERROR: No component defined for file $onefile->{'Name'}", "create_featurecomponent_table_from_files_collector");
55        }
56        if ( $filemodules eq "" )
57        {
58            installer::exiter::exit_program("ERROR: No modules found for file $onefile->{'Name'}", "create_featurecomponent_table_from_files_collector");
59        }
60
61        my $filemodulesarrayref = installer::converter::convert_stringlist_into_array(\$filemodules, ",");
62
63        for ( my $j = 0; $j <= $#{$filemodulesarrayref}; $j++ )
64        {
65            my %featurecomponent = ();
66
67            my $onemodule = ${$filemodulesarrayref}[$j];
68            $onemodule =~ s/\s*$//;
69            $featurecomponent{'Feature'} = $onemodule;
70            $featurecomponent{'Component'} = $filecomponent;
71
72            # Attention: Features are renamed, because the maximum length is 38.
73            # But in the files collector ($filesref), the original names are saved.
74
75            installer::windows::idtglobal::shorten_feature_gid(\$featurecomponent{'Feature'});
76
77            $oneline = "$featurecomponent{'Feature'}\t$featurecomponent{'Component'}\n";
78
79            # control of uniqueness
80
81            if (! installer::existence::exists_in_array($oneline, $featurecomponenttableref))
82            {
83                push(@{$featurecomponenttableref}, $oneline);
84            }
85        }
86    }
87}
88
89#################################################################################
90# Collecting all pairs of features and components from the registry collector
91#################################################################################
92
93sub create_featurecomponent_table_from_registry_collector
94{
95    my ($featurecomponenttableref, $registryref) = @_;
96
97    for ( my $i = 0; $i <= $#{$registryref}; $i++ )
98    {
99        my $oneregistry = ${$registryref}[$i];
100
101        my $registrycomponent = $oneregistry->{'componentname'};
102        my $registrymodule = $oneregistry->{'ModuleID'};
103
104        if ( $registrycomponent eq "" )
105        {
106            installer::exiter::exit_program("ERROR: No component defined for registry $oneregistry->{'gid'}", "create_featurecomponent_table_from_registry_collector");
107        }
108        if ( $registrymodule eq "" )
109        {
110            installer::exiter::exit_program("ERROR: No modules found for registry $oneregistry->{'gid'}", "create_featurecomponent_table_from_registry_collector");
111        }
112
113        my %featurecomponent = ();
114
115        $featurecomponent{'Feature'} = $registrymodule;
116        $featurecomponent{'Component'} = $registrycomponent;
117
118        # Attention: Features are renamed, because the maximum length is 38.
119        # But in the files collector ($filesref), the original names are saved.
120
121        installer::windows::idtglobal::shorten_feature_gid(\$featurecomponent{'Feature'});
122
123        $oneline = "$featurecomponent{'Feature'}\t$featurecomponent{'Component'}\n";
124
125        # control of uniqueness
126
127        if (! installer::existence::exists_in_array($oneline, $featurecomponenttableref))
128        {
129            push(@{$featurecomponenttableref}, $oneline);
130        }
131    }
132}
133
134#################################################################################
135# Collecting all feature that are listed in the featurecomponent table.
136#################################################################################
137
138sub collect_all_feature
139{
140    my ($featurecomponenttable) = @_;
141
142    my @allfeature = ();
143
144    for ( my $i = 3; $i <= $#{$featurecomponenttable}; $i++ )   # beginning in line 4
145    {
146        my $oneline = ${$featurecomponenttable}[$i];
147
148        if ( $oneline =~ /^\s*(\S+)\s+(\S+)\s*$/ )
149        {
150            my $feature = $1;
151
152            if (! installer::existence::exists_in_array($feature, \@allfeature)) { push(@allfeature, $feature); }
153        }
154    }
155
156    return \@allfeature;
157}
158
159#################################################################################
160# On Win98 and Win Me there seems to be the problem, that maximum 817
161# components can be added to a feature. Even if Windows Installer 2.0
162# is used.
163#################################################################################
164
165sub check_number_of_components_at_feature
166{
167    my ($featurecomponenttable) = @_;
168
169    my $infoline = "\nChecking number of components at features. Maximum is 817 (for Win 98 and Win Me)\n";
170    push(@installer::globals::logfileinfo, $infoline);
171
172    my $allfeature = collect_all_feature($featurecomponenttable);
173
174    for ( my $i = 0; $i <= $#{$allfeature}; $i++ )
175    {
176        my $onefeature = ${$allfeature}[$i];
177        my $featurecomponents = 0;
178
179        for ( my $j = 0; $j <= $#{$featurecomponenttable}; $j++ )
180        {
181            if ( ${$featurecomponenttable}[$j] =~ /^\s*\Q$onefeature\E\s+(\S+)\s*$/ ) { $featurecomponents++; }
182        }
183
184        if ( $featurecomponents > 816 )
185        {
186            installer::exiter::exit_program("ERROR: More than 816 components ($featurecomponents) at feature $onefeature. This causes problems on Win 98 and Win Me!", "check_number_of_components_at_feature");
187        }
188
189        # Logging the result
190
191        $infoline = "Number of components at feature $onefeature : $featurecomponents\n";
192        push(@installer::globals::logfileinfo, $infoline);
193    }
194
195    $infoline = "\n";
196    push(@installer::globals::logfileinfo, $infoline);
197}
198
199#################################################################################
200# Creating the file FeatureC.idt dynamically
201# Content:
202# Feature Component
203#################################################################################
204
205sub create_featurecomponent_table
206{
207    my ($filesref, $registryref, $basedir) = @_;
208
209    my @featurecomponenttable = ();
210    my $infoline;
211
212    installer::windows::idtglobal::write_idt_header(\@featurecomponenttable, "featurecomponent");
213
214    # This is the first time, that features and componentes are related
215    # Problem: How about created profiles, configurationfiles, services.rdb
216    # -> simple solution: putting them all to the root module
217    # Otherwise profiles and configurationfiles cannot be created the way, they are now created
218    # -> especially a problem for the configurationfiles! # ToDo
219    # Very good: All ProfileItems belong to the root
220    # services.rdb belongs to the root anyway.
221
222    # At the moment only the files are related to components (and the files know their modules).
223    # The component for each file is written into the files collector $filesinproductlanguageresolvedarrayref
224
225    create_featurecomponent_table_from_files_collector(\@featurecomponenttable, $filesref);
226
227    create_featurecomponent_table_from_registry_collector(\@featurecomponenttable, $registryref);
228
229    # Additional components have to be added here
230
231    # Checking, whether there are more than 817 components at a feature
232
233    check_number_of_components_at_feature(\@featurecomponenttable);
234
235    # Saving the file
236
237    my $featurecomponenttablename = $basedir . $installer::globals::separator . "FeatureC.idt";
238    installer::files::save_file($featurecomponenttablename ,\@featurecomponenttable);
239    $infoline = "Created idt file: $featurecomponenttablename\n";
240    push(@installer::globals::logfileinfo, $infoline);
241
242}
243
2441;