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