1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file incorporates work covered by the following license notice:
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed
# with this work for additional information regarding copyright
# ownership. The ASF licenses this file to you under the Apache
# License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
#
package installer::profiles;
use strict;
use warnings;
use installer::converter;
use installer::files;
use installer::globals;
use installer::logger;
use installer::remover;
use installer::systemactions;
#############################
# Profiles
#############################
#######################################################
# Sorting the content of a profile
#######################################################
sub sorting_profile {
my ($profilesref) = @_;
my @sections;
my %section_content;
for ( my $i = 0; $i < @{$profilesref}; $i++ ) {
my $line = ${$profilesref}[$i];
# Skip unless this is a section (every second line)
next unless ( $line =~ /^\s*(\[.*\])\s*$/ );
my $section = $1;
my $next_line = ${$profilesref}[$i+1];
if ( ! exists $section_content{$section} ) {
push @sections, $section;
}
push @{ $section_content{$section} }, $next_line;
}
my @profile;
for my $section (@sections) {
push @profile, "$section\n";
push @profile, @{ $section_content{$section} };
}
return \@profile;
}
#####################################################################
# Adding the newly created profile into the file list
#####################################################################
sub add_profile_into_filelist
{
my ($filesarrayref, $oneprofile, $completeprofilename, $allvariables) = @_;
my %profile = ();
# Taking the base data from a file in the root module
if ( ! $allvariables->{'ROOTMODULEGID'} ) { installer::exiter::exit_program("ERROR: ROOTMODULEGID must be defined in list file!", "add_profile_into_filelist"); }
my $rootmodulegid = $allvariables->{'ROOTMODULEGID'};
my $rootfile;
foreach my $file (@{$filesarrayref}) {
if ($file->{'modules'} eq $rootmodulegid)
{
$rootfile = $file;
last;
}
}
if (! defined $rootfile) {
die "Could not find any file from module $rootmodulegid in list of files!";
}
# copying all base data
installer::converter::copy_item_object($rootfile, \%profile);
# and overriding all new values
$profile{'ismultilingual'} = 0;
$profile{'sourcepath'} = $completeprofilename;
$profile{'Name'} = $oneprofile->{'Name'};
$profile{'UnixRights'} = "644";
$profile{'gid'} = $oneprofile->{'gid'};
$profile{'Dir'} = $oneprofile->{'Dir'};
$profile{'destination'} = $oneprofile->{'destination'};
$profile{'Styles'} = "";
if ( $oneprofile->{'Styles'} ) { $profile{'Styles'} = $oneprofile->{'Styles'}; }
$profile{'modules'} = $oneprofile->{'ModuleID'}; # Profiles can only be added completely to a module
push(@{$filesarrayref}, \%profile);
}
###################################################
# Including Windows line ends in ini files
# Profiles on Windows shall have \r\n line ends
###################################################
sub include_windows_lineends
{
my ($onefile) = @_;
for ( my $i = 0; $i <= $#{$onefile}; $i++ )
{
${$onefile}[$i] =~ s/\r?\n$/\r\n/;
}
}
####################################
# Create profiles
####################################
sub create_profiles
{
my ($profilesref, $profileitemsref, $filesarrayref, $languagestringref, $allvariables) = @_;
my $infoline;
my $profilesdir = installer::systemactions::create_directories("profiles", $languagestringref);
installer::logger::include_header_into_logfile("Creating profiles:");
# Attention: The module dependencies from ProfileItems have to be ignored, because
# the Profile has to be installed completely with all of its content and the correct name.
# Only complete profiles can belong to a specified module, but not ProfileItems!
# iterating over all files
for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
{
my $oneprofile = ${$profilesref}[$i];
my $dir = $oneprofile->{'Dir'};
if ( $dir eq "PREDEFINED_CONFIGDIR" ) { next; } # ignoring the profile sversion file
my $profilegid = $oneprofile->{'gid'};
my $profilename = $oneprofile->{'Name'};
my $localprofilesdir = $profilesdir . $installer::globals::separator . $profilegid; # uniqueness guaranteed by gid
if ( ! -d $localprofilesdir ) { installer::systemactions::create_directory($localprofilesdir); }
my @onefile = ();
my $profileempty = 1;
for ( my $j = 0; $j <= $#{$profileitemsref}; $j++ )
{
my $oneprofileitem = ${$profileitemsref}[$j];
my $styles = "";
if ( $oneprofileitem->{'Styles'} ) { $styles = $oneprofileitem->{'Styles'}; }
if ( $styles =~ /\bINIFILETABLE\b/ ) { next; } # these values are written during installation, not during packing
my $profileid = $oneprofileitem->{'ProfileID'};
if ( $profileid eq $profilegid )
{
my $section = $oneprofileitem->{'Section'};
my $key = $oneprofileitem->{'Key'};
my $value = $oneprofileitem->{'Value'};
for (my $pk = 1; $pk <= 50; $pk++)
{
my $key = "ValueList" . $pk;
if ( $oneprofileitem->{$key} )
{ $value = $value . " " . $oneprofileitem->{$key} }
}
my $order = $oneprofileitem->{'Order'}; # ignoring order at the moment
my $line = "[" . $section . "]" . "\n";
push(@onefile, $line);
$line = $key . "=" . $value . "\n";
push(@onefile, $line);
$profileempty = 0;
}
}
if ( $profileempty ) { next; } # ignoring empty profiles
# Sorting the array @onefile
my $onefileref = sorting_profile(\@onefile);
if ( $installer::globals::iswin && $^O =~ /cygwin/i) # Windows line ends only for Cygwin
{
include_windows_lineends($onefileref);
}
# Saving the profile as a file
my $completeprofilename = $localprofilesdir . $installer::globals::separator . $profilename;
installer::files::save_file($completeprofilename, $onefileref);
# Adding the file to the filearray
# Some data are set now, others are taken from the file "soffice.exe" ("soffice.bin")
add_profile_into_filelist($filesarrayref, $oneprofile, $completeprofilename, $allvariables);
$infoline = "Created Profile: $completeprofilename\n";
push( @installer::globals::logfileinfo, $infoline);
}
$infoline = "\n";
push( @installer::globals::logfileinfo, $infoline);
}
1;
|