xref: /AOO41X/main/solenv/bin/modules/installer/profiles.pm (revision fe22d2cfc602815794415026f1317bd625db6f83)
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::profiles;
25
26use installer::converter;
27use installer::existence;
28use installer::exiter;
29use installer::files;
30use installer::globals;
31use installer::logger;
32use installer::remover;
33use installer::systemactions;
34
35#############################
36# Profiles
37#############################
38
39#######################################################
40# Sorting the content of a profile
41#######################################################
42
43sub sorting_profile
44{
45    my ($profilesref) = @_;
46
47    my @profile = ();
48    my @definedsections = ();
49
50    for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
51    {
52        my $line = ${$profilesref}[$i];
53
54        if ( $line =~ /^\s*(\[.*\])\s*$/ )  # this is a section (every second line)
55        {
56            my $section = $1;
57
58            if (!(installer::existence::exists_in_array($section, \@definedsections)))
59            {
60                my $sectionline = $section . "\n";
61                push(@definedsections, $section);
62                push(@profile, $sectionline);
63
64                for ( my $j = 0; $j <= $#{$profilesref}; $j++ )
65                {
66                    my $oneline = ${$profilesref}[$j];
67                    installer::remover::remove_leading_and_ending_whitespaces(\$oneline);
68
69                    if ( $oneline eq $section )
70                    {
71                        my $nextline = ${$profilesref}[$j+1];
72                        push(@profile, $nextline);
73                    }
74                }
75            }
76        }
77    }
78
79    return \@profile;
80}
81
82#####################################################################
83# Adding the newly created profile into the file list
84#####################################################################
85
86sub add_profile_into_filelist
87{
88    my ($filesarrayref, $oneprofile, $completeprofilename, $allvariables) = @_;
89
90    my %profile = ();
91
92    # Taking the base data from the "gid_File_Lib_Vcl"
93
94    my $vclgid = "gid_File_Lib_Vcl";
95    if ( $allvariables->{'GLOBALFILEGID'} ) { $vclgid = $allvariables->{'GLOBALFILEGID'}; }
96    my $vclfile = installer::existence::get_specified_file($filesarrayref, $vclgid);
97
98    # copying all base data
99    installer::converter::copy_item_object($vclfile, \%profile);
100
101    # and overriding all new values
102
103    $profile{'ismultilingual'} = 0;
104    $profile{'sourcepath'} = $completeprofilename;
105    $profile{'Name'} = $oneprofile->{'Name'};
106    $profile{'UnixRights'} = "444";
107    $profile{'gid'} = $oneprofile->{'gid'};
108    $profile{'Dir'} = $oneprofile->{'Dir'};
109    $profile{'destination'} = $oneprofile->{'destination'};
110    $profile{'Styles'} = "";
111    if ( $oneprofile->{'Styles'} ) { $profile{'Styles'} = $oneprofile->{'Styles'}; }
112    $profile{'modules'} = $oneprofile->{'ModuleID'};    # Profiles can only be added completely to a module
113
114    push(@{$filesarrayref}, \%profile);
115}
116
117###################################################
118# Including Windows line ends in ini files
119# Profiles on Windows shall have \r\n line ends
120###################################################
121
122sub include_windows_lineends
123{
124    my ($onefile) = @_;
125
126    for ( my $i = 0; $i <= $#{$onefile}; $i++ )
127    {
128        ${$onefile}[$i] =~ s/\r?\n$/\r\n/;
129    }
130}
131
132####################################
133# Create profiles
134####################################
135
136sub create_profiles
137{
138    my ($profilesref, $profileitemsref, $filesarrayref, $languagestringref, $allvariables) = @_;
139
140    my $infoline;
141
142    my $profilesdir = installer::systemactions::create_directories("profiles", $languagestringref);
143
144    installer::logger::include_header_into_logfile("Creating profiles:");
145
146    # Attention: The module dependencies from ProfileItems have to be ignored, because
147    # the Profile has to be installed completely with all of its content and the correct name.
148    # Only complete profiles can belong to a specified module, but not ProfileItems!
149
150    # iterating over all files
151
152    for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
153    {
154        my $oneprofile = ${$profilesref}[$i];
155        my $dir = $oneprofile->{'Dir'};
156        if ( $dir eq "PREDEFINED_CONFIGDIR" ) { next; }     # ignoring the profile sversion file
157
158        my $profilegid = $oneprofile->{'gid'};
159        my $profilename = $oneprofile->{'Name'};
160
161        my $localprofilesdir = $profilesdir . $installer::globals::separator . $profilegid; # uniqueness guaranteed by gid
162        if ( ! -d $localprofilesdir ) { installer::systemactions::create_directory($localprofilesdir); }
163
164        my @onefile = ();
165        my $profileempty = 1;
166
167        for ( my $j = 0; $j <= $#{$profileitemsref}; $j++ )
168        {
169            my $oneprofileitem = ${$profileitemsref}[$j];
170
171            my $styles = "";
172            if ( $oneprofileitem->{'Styles'} ) { $styles = $oneprofileitem->{'Styles'}; }
173            if ( $styles =~ /\bINIFILETABLE\b/ ) { next; }  # these values are written during installation, not during packing
174
175            my $profileid = $oneprofileitem->{'ProfileID'};
176
177            if ( $profileid eq $profilegid )
178            {
179                my $section = $oneprofileitem->{'Section'};
180                my $key = $oneprofileitem->{'Key'};
181                my $value = $oneprofileitem->{'Value'};
182                for (my $pk = 1; $pk <= 50; $pk++)
183                {
184                    my $key = "ValueList" . $pk;
185                    if ( $oneprofileitem->{$key} )
186                        { $value = $value . " " . $oneprofileitem->{$key} }
187                }
188                my $order = $oneprofileitem->{'Order'}; # ignoring order at the moment
189
190                my $line = "[" . $section . "]" . "\n";
191                push(@onefile, $line);
192                $line = $key . "=" . $value . "\n";
193                push(@onefile, $line);
194
195                $profileempty = 0;
196            }
197        }
198
199        if ( $profileempty ) { next; }  # ignoring empty profiles
200
201        # Sorting the array @onefile
202        my $onefileref = sorting_profile(\@onefile);
203
204        if ( $installer::globals::iswin && $installer::globals::plat =~ /cygwin/i)      # Windows line ends only for Cygwin
205        {
206            include_windows_lineends($onefileref);
207        }
208
209        # Saving the profile as a file
210        $completeprofilename = $localprofilesdir . $installer::globals::separator . $profilename;
211
212        installer::files::save_file($completeprofilename, $onefileref);
213
214        # Adding the file to the filearray
215        # Some data are set now, others are taken from the file "soffice.exe" ("soffice.bin")
216        add_profile_into_filelist($filesarrayref, $oneprofile, $completeprofilename, $allvariables);
217
218        $installer::logger::Lang->printf("Created Profile: %s\n", $completeprofilename);
219    }
220
221    $installer::logger::Lang->printf("\n");
222}
223
224
2251;
226