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::windows::upgrade;
25
26use installer::exiter;
27use installer::files;
28use installer::globals;
29use installer::windows::idtglobal;
30
31####################################################################################
32# Creating the file Upgrade.idt dynamically
33# Content:
34# UpgradeCode VersionMin VersionMax Language Attributes Remove ActionProperty
35####################################################################################
36
37sub create_upgrade_table
38{
39	my ($basedir, $allvariableshashref) = @_;
40
41	my @upgradetable = ();
42
43	# fix for problematic OOo 1.9 versions
44	my $include_ooo_fix = 0;
45	my $ooomaxnew = "";
46	if (($installer::globals::product =~ /^\s*OpenOffice/i ) && ( ! ( $installer::globals::product =~ /SDK/i )) && ( ! $installer::globals::languagepack ))
47	{
48		$include_ooo_fix = 1;
49		$ooomaxnew = "34.0.0";
50	}
51
52	installer::windows::idtglobal::write_idt_header(\@upgradetable, "upgrade");
53
54	# Setting also $installer::globals::msimajorproductversion, that is for example "3.0.0", to differ between old products for OOo 2.x and
55	# older products from OOo 3.x. The latter must be removed always, the removal of the first is controlled with a checkbox.
56	my $newline = $installer::globals::upgradecode . "\t" . "\t" . $installer::globals::msimajorproductversion . "\t" . "\t" . "0" . "\t" . "\t" . "OLDPRODUCTS" . "\n";
57	push(@upgradetable, $newline);
58
59	# Setting all products, that must be removed.
60	$newline = $installer::globals::upgradecode . "\t" . $installer::globals::msimajorproductversion . "\t" . $installer::globals::msiproductversion . "\t" . "\t" . "257" . "\t" . "\t" . "OLDPRODUCTSSAMEMAJOR" . "\n";
61	push(@upgradetable, $newline);
62
63	if ( ! $installer::globals::patch )
64	{
65		# preventing downgrading
66		$newline = $installer::globals::upgradecode . "\t" . $installer::globals::msiproductversion . "\t" . $ooomaxnew . "\t" . "\t" . "2" . "\t" . "\t" . "NEWPRODUCTS" . "\n";
67		push(@upgradetable, $newline);
68
69		$newline = $installer::globals::upgradecode . "\t" . $installer::globals::msiproductversion . "\t" . $ooomaxnew . "\t" . "\t" . "258" . "\t" . "\t" . "SAMEPRODUCTS" . "\n";
70		push(@upgradetable, $newline);
71
72		if ( $include_ooo_fix )
73		{
74			$newline = $installer::globals::upgradecode . "\t" . "35.0.0" . "\t" . "36.0.0" . "\t" . "\t" . "1" . "\t" . "\t" . "OLDPRODUCTS2" . "\n";
75			push(@upgradetable, $newline);
76		}
77
78		# if (( $allvariableshashref->{'PATCHUPGRADECODE'} ) && ( ! $installer::globals::languagepack ))
79		# {
80		#	$newline = $allvariableshashref->{'PATCHUPGRADECODE'} . "\t" . "\t" . $installer::globals::msiproductversion . "\t" . "\t" . "1" . "\t" . "\t" . "OLDPRODUCTSPATCH" . "\n";
81		#	push(@upgradetable, $newline);
82		#
83		#	$newline = $allvariableshashref->{'PATCHUPGRADECODE'} . "\t" . $installer::globals::msiproductversion . "\t" . "\t" . "\t" . "2" . "\t" . "\t" . "NEWPRODUCTSPATCH" . "\n";
84		#	push(@upgradetable, $newline);
85		#
86		#	$newline = $allvariableshashref->{'PATCHUPGRADECODE'} . "\t" . $installer::globals::msiproductversion . "\t" . "\t" . "\t" . "258" . "\t" . "\t" . "SAMEPRODUCTSPATCH" . "\n";
87		#	push(@upgradetable, $newline);
88		# }
89
90		# also searching for the beta
91
92		if (( $allvariableshashref->{'BETAUPGRADECODE'} ) && ( ! $installer::globals::languagepack ))
93		{
94			$newline = $allvariableshashref->{'BETAUPGRADECODE'} . "\t" . "1.0" . "\t" . "\t" . "\t" . "1" . "\t" . "\t" . "BETAPRODUCTS" . "\n";
95			push(@upgradetable, $newline);
96		}
97
98		# also searching for the stub
99
100		if (( $allvariableshashref->{'STUBUPGRADECODE'} ) && ( ! $installer::globals::languagepack ))
101		{
102			$newline = $allvariableshashref->{'STUBUPGRADECODE'} . "\t" . "1.0" . "\t" . "\t" . "\t" . "1" . "\t" . "\t" . "STUBPRODUCTS" . "\n";
103			push(@upgradetable, $newline);
104		}
105
106		# searching for all older patches and languagepacks (defined in a extra file)
107
108		if (( $allvariableshashref->{'REMOVE_UPGRADE_CODE_FILE'} ) && ( ! $installer::globals::languagepack ))
109		{
110			my $filename = $allvariableshashref->{'REMOVE_UPGRADE_CODE_FILE'};
111			my $langpackcodefilename = $installer::globals::idttemplatepath  . $installer::globals::separator . $filename;
112			if ( ! -f $langpackcodefilename ) { installer::exiter::exit_program("ERROR: Could not find file \"$langpackcodefilename\".", "create_upgrade_table"); }
113
114			my $filecontent = installer::files::read_file($langpackcodefilename);
115			my $newlines = analyze_file_for_upgrade_table($filecontent);
116
117			for ( my $i = 0; $i <= $#{$newlines}; $i++ ) { push(@upgradetable, ${$newlines}[$i]); }
118		}
119	}
120
121	# No upgrade for Beta versions!
122
123	if (( $allvariableshashref->{'PRODUCTEXTENSION'} eq "Beta" ) && ( ! $installer::globals::patch ) && ( ! $installer::globals::languagepack ))
124	{
125		@upgradetable = ();
126		installer::windows::idtglobal::write_idt_header(\@upgradetable, "upgrade");
127		my $infoline = "Beta product -> empty Upgrade table\n";
128		push(@installer::globals::logfileinfo, $infoline);
129	}
130
131	# Saving the file
132
133	my $upgradetablename = $basedir . $installer::globals::separator . "Upgrade.idt";
134	installer::files::save_file($upgradetablename ,\@upgradetable);
135	my $infoline = "Created idt file: $upgradetablename\n";
136	push(@installer::globals::logfileinfo, $infoline);
137}
138
139##############################################################
140# Reading the file with UpgradeCodes of old products,
141# that can be removed, if the user wants to remove them.
142##############################################################
143
144sub analyze_file_for_upgrade_table
145{
146	my ($filecontent) = @_;
147
148	my @allnewlines = ();
149
150	for ( my $i = 0; $i <= $#{$filecontent}; $i++ )
151	{
152		my $line = ${$filecontent}[$i];
153		if ( $line =~ /^\s*$/ ) { next; } # empty lines can be ignored
154		if ( $line =~ /^\s*\#/ ) { next; } # comment lines starting with a hash
155
156		if ( $line =~ /^(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)$/ ) { push(@allnewlines, $line); }
157		else { installer::exiter::exit_program("ERROR: Wrong syntax in file for upgrade table", "analyze_file_for_upgrade_table"); }
158	}
159
160	return \@allnewlines;
161}
162
1631;
164