19780544fSAndrew Rist#************************************************************** 29780544fSAndrew Rist# 39780544fSAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 49780544fSAndrew Rist# or more contributor license agreements. See the NOTICE file 59780544fSAndrew Rist# distributed with this work for additional information 69780544fSAndrew Rist# regarding copyright ownership. The ASF licenses this file 79780544fSAndrew Rist# to you under the Apache License, Version 2.0 (the 89780544fSAndrew Rist# "License"); you may not use this file except in compliance 99780544fSAndrew Rist# with the License. You may obtain a copy of the License at 109780544fSAndrew Rist# 119780544fSAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 129780544fSAndrew Rist# 139780544fSAndrew Rist# Unless required by applicable law or agreed to in writing, 149780544fSAndrew Rist# software distributed under the License is distributed on an 159780544fSAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169780544fSAndrew Rist# KIND, either express or implied. See the License for the 179780544fSAndrew Rist# specific language governing permissions and limitations 189780544fSAndrew Rist# under the License. 199780544fSAndrew Rist# 209780544fSAndrew Rist#************************************************************** 219780544fSAndrew Rist 229780544fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweirpackage installer::profiles; 25cdf0e10cSrcweir 26cdf0e10cSrcweiruse installer::converter; 27cdf0e10cSrcweiruse installer::existence; 28cdf0e10cSrcweiruse installer::exiter; 29cdf0e10cSrcweiruse installer::files; 30cdf0e10cSrcweiruse installer::globals; 31cdf0e10cSrcweiruse installer::logger; 32cdf0e10cSrcweiruse installer::remover; 33cdf0e10cSrcweiruse installer::systemactions; 34cdf0e10cSrcweir 35cdf0e10cSrcweir############################# 36cdf0e10cSrcweir# Profiles 37cdf0e10cSrcweir############################# 38cdf0e10cSrcweir 39cdf0e10cSrcweir####################################################### 40cdf0e10cSrcweir# Sorting the content of a profile 41cdf0e10cSrcweir####################################################### 42cdf0e10cSrcweir 43cdf0e10cSrcweirsub sorting_profile 44cdf0e10cSrcweir{ 45cdf0e10cSrcweir my ($profilesref) = @_; 46cdf0e10cSrcweir 47cdf0e10cSrcweir my @profile = (); 48cdf0e10cSrcweir my @definedsections = (); 49cdf0e10cSrcweir 50cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$profilesref}; $i++ ) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir my $line = ${$profilesref}[$i]; 53cdf0e10cSrcweir 54cdf0e10cSrcweir if ( $line =~ /^\s*(\[.*\])\s*$/ ) # this is a section (every second line) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir my $section = $1; 57cdf0e10cSrcweir 58cdf0e10cSrcweir if (!(installer::existence::exists_in_array($section, \@definedsections))) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir my $sectionline = $section . "\n"; 61cdf0e10cSrcweir push(@definedsections, $section); 62cdf0e10cSrcweir push(@profile, $sectionline); 63cdf0e10cSrcweir 64cdf0e10cSrcweir for ( my $j = 0; $j <= $#{$profilesref}; $j++ ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir my $oneline = ${$profilesref}[$j]; 67cdf0e10cSrcweir installer::remover::remove_leading_and_ending_whitespaces(\$oneline); 68cdf0e10cSrcweir 69cdf0e10cSrcweir if ( $oneline eq $section ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir my $nextline = ${$profilesref}[$j+1]; 72cdf0e10cSrcweir push(@profile, $nextline); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir } 75cdf0e10cSrcweir } 76cdf0e10cSrcweir } 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir return \@profile; 80cdf0e10cSrcweir} 81cdf0e10cSrcweir 82cdf0e10cSrcweir##################################################################### 83cdf0e10cSrcweir# Adding the newly created profile into the file list 84cdf0e10cSrcweir##################################################################### 85cdf0e10cSrcweir 86cdf0e10cSrcweirsub add_profile_into_filelist 87cdf0e10cSrcweir{ 88cdf0e10cSrcweir my ($filesarrayref, $oneprofile, $completeprofilename, $allvariables) = @_; 89cdf0e10cSrcweir 90cdf0e10cSrcweir my %profile = (); 91cdf0e10cSrcweir 92cdf0e10cSrcweir # Taking the base data from the "gid_File_Lib_Vcl" 93cdf0e10cSrcweir 94cdf0e10cSrcweir my $vclgid = "gid_File_Lib_Vcl"; 95cdf0e10cSrcweir if ( $allvariables->{'GLOBALFILEGID'} ) { $vclgid = $allvariables->{'GLOBALFILEGID'}; } 96cdf0e10cSrcweir my $vclfile = installer::existence::get_specified_file($filesarrayref, $vclgid); 97cdf0e10cSrcweir 98cdf0e10cSrcweir # copying all base data 99cdf0e10cSrcweir installer::converter::copy_item_object($vclfile, \%profile); 100cdf0e10cSrcweir 101cdf0e10cSrcweir # and overriding all new values 102cdf0e10cSrcweir 103cdf0e10cSrcweir $profile{'ismultilingual'} = 0; 104cdf0e10cSrcweir $profile{'sourcepath'} = $completeprofilename; 105cdf0e10cSrcweir $profile{'Name'} = $oneprofile->{'Name'}; 106cdf0e10cSrcweir $profile{'UnixRights'} = "444"; 107cdf0e10cSrcweir $profile{'gid'} = $oneprofile->{'gid'}; 108cdf0e10cSrcweir $profile{'Dir'} = $oneprofile->{'Dir'}; 109cdf0e10cSrcweir $profile{'destination'} = $oneprofile->{'destination'}; 110cdf0e10cSrcweir $profile{'Styles'} = ""; 111cdf0e10cSrcweir if ( $oneprofile->{'Styles'} ) { $profile{'Styles'} = $oneprofile->{'Styles'}; } 112cdf0e10cSrcweir $profile{'modules'} = $oneprofile->{'ModuleID'}; # Profiles can only be added completely to a module 113cdf0e10cSrcweir 114cdf0e10cSrcweir push(@{$filesarrayref}, \%profile); 115cdf0e10cSrcweir} 116cdf0e10cSrcweir 117cdf0e10cSrcweir################################################### 118cdf0e10cSrcweir# Including Windows line ends in ini files 119cdf0e10cSrcweir# Profiles on Windows shall have \r\n line ends 120cdf0e10cSrcweir################################################### 121cdf0e10cSrcweir 122cdf0e10cSrcweirsub include_windows_lineends 123cdf0e10cSrcweir{ 124cdf0e10cSrcweir my ($onefile) = @_; 125cdf0e10cSrcweir 126cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$onefile}; $i++ ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir ${$onefile}[$i] =~ s/\r?\n$/\r\n/; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir} 131cdf0e10cSrcweir 132cdf0e10cSrcweir#################################### 133cdf0e10cSrcweir# Create profiles 134cdf0e10cSrcweir#################################### 135cdf0e10cSrcweir 136cdf0e10cSrcweirsub create_profiles 137cdf0e10cSrcweir{ 138cdf0e10cSrcweir my ($profilesref, $profileitemsref, $filesarrayref, $languagestringref, $allvariables) = @_; 139cdf0e10cSrcweir 140cdf0e10cSrcweir my $infoline; 141cdf0e10cSrcweir 142cdf0e10cSrcweir my $profilesdir = installer::systemactions::create_directories("profiles", $languagestringref); 143cdf0e10cSrcweir 144cdf0e10cSrcweir installer::logger::include_header_into_logfile("Creating profiles:"); 145cdf0e10cSrcweir 146cdf0e10cSrcweir # Attention: The module dependencies from ProfileItems have to be ignored, because 147cdf0e10cSrcweir # the Profile has to be installed completely with all of its content and the correct name. 148cdf0e10cSrcweir # Only complete profiles can belong to a specified module, but not ProfileItems! 149cdf0e10cSrcweir 150cdf0e10cSrcweir # iterating over all files 151cdf0e10cSrcweir 152cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$profilesref}; $i++ ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir my $oneprofile = ${$profilesref}[$i]; 155cdf0e10cSrcweir my $dir = $oneprofile->{'Dir'}; 156cdf0e10cSrcweir if ( $dir eq "PREDEFINED_CONFIGDIR" ) { next; } # ignoring the profile sversion file 157cdf0e10cSrcweir 158cdf0e10cSrcweir my $profilegid = $oneprofile->{'gid'}; 159cdf0e10cSrcweir my $profilename = $oneprofile->{'Name'}; 160cdf0e10cSrcweir 161cdf0e10cSrcweir my $localprofilesdir = $profilesdir . $installer::globals::separator . $profilegid; # uniqueness guaranteed by gid 162cdf0e10cSrcweir if ( ! -d $localprofilesdir ) { installer::systemactions::create_directory($localprofilesdir); } 163cdf0e10cSrcweir 164cdf0e10cSrcweir my @onefile = (); 165cdf0e10cSrcweir my $profileempty = 1; 166cdf0e10cSrcweir 167cdf0e10cSrcweir for ( my $j = 0; $j <= $#{$profileitemsref}; $j++ ) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir my $oneprofileitem = ${$profileitemsref}[$j]; 170cdf0e10cSrcweir 171cdf0e10cSrcweir my $styles = ""; 172cdf0e10cSrcweir if ( $oneprofileitem->{'Styles'} ) { $styles = $oneprofileitem->{'Styles'}; } 173cdf0e10cSrcweir if ( $styles =~ /\bINIFILETABLE\b/ ) { next; } # these values are written during installation, not during packing 174cdf0e10cSrcweir 175cdf0e10cSrcweir my $profileid = $oneprofileitem->{'ProfileID'}; 176cdf0e10cSrcweir 177cdf0e10cSrcweir if ( $profileid eq $profilegid ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir my $section = $oneprofileitem->{'Section'}; 180cdf0e10cSrcweir my $key = $oneprofileitem->{'Key'}; 181cdf0e10cSrcweir my $value = $oneprofileitem->{'Value'}; 182cdf0e10cSrcweir for (my $pk = 1; $pk <= 50; $pk++) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir my $key = "ValueList" . $pk; 185cdf0e10cSrcweir if ( $oneprofileitem->{$key} ) 186cdf0e10cSrcweir { $value = $value . " " . $oneprofileitem->{$key} } 187cdf0e10cSrcweir } 188cdf0e10cSrcweir my $order = $oneprofileitem->{'Order'}; # ignoring order at the moment 189cdf0e10cSrcweir 190cdf0e10cSrcweir my $line = "[" . $section . "]" . "\n"; 191cdf0e10cSrcweir push(@onefile, $line); 192cdf0e10cSrcweir $line = $key . "=" . $value . "\n"; 193cdf0e10cSrcweir push(@onefile, $line); 194cdf0e10cSrcweir 195cdf0e10cSrcweir $profileempty = 0; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir if ( $profileempty ) { next; } # ignoring empty profiles 200cdf0e10cSrcweir 201cdf0e10cSrcweir # Sorting the array @onefile 202cdf0e10cSrcweir my $onefileref = sorting_profile(\@onefile); 203cdf0e10cSrcweir 204cdf0e10cSrcweir if ( $installer::globals::iswin && $installer::globals::plat =~ /cygwin/i) # Windows line ends only for Cygwin 205cdf0e10cSrcweir { 206cdf0e10cSrcweir include_windows_lineends($onefileref); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir # Saving the profile as a file 210cdf0e10cSrcweir $completeprofilename = $localprofilesdir . $installer::globals::separator . $profilename; 211cdf0e10cSrcweir 212cdf0e10cSrcweir installer::files::save_file($completeprofilename, $onefileref); 213cdf0e10cSrcweir 214cdf0e10cSrcweir # Adding the file to the filearray 215cdf0e10cSrcweir # Some data are set now, others are taken from the file "soffice.exe" ("soffice.bin") 216cdf0e10cSrcweir add_profile_into_filelist($filesarrayref, $oneprofile, $completeprofilename, $allvariables); 217cdf0e10cSrcweir 218*b274bc22SAndre Fischer $installer::logger::Lang->printf("Created Profile: %s\n", $completeprofilename); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221*b274bc22SAndre Fischer $installer::logger::Lang->printf("\n"); 222cdf0e10cSrcweir} 223cdf0e10cSrcweir 224cdf0e10cSrcweir 225cdf0e10cSrcweir1; 226