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