1*cdf0e10cSrcweir#*************************************************************************
2*cdf0e10cSrcweir#
3*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir#
5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir#
7*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir#
9*cdf0e10cSrcweir# This file is part of OpenOffice.org.
10*cdf0e10cSrcweir#
11*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir# only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir#
15*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir#
21*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir# for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir#
26*cdf0e10cSrcweir#*************************************************************************
27*cdf0e10cSrcweir
28*cdf0e10cSrcweirpackage installer::windows::upgrade;
29*cdf0e10cSrcweir
30*cdf0e10cSrcweiruse installer::exiter;
31*cdf0e10cSrcweiruse installer::files;
32*cdf0e10cSrcweiruse installer::globals;
33*cdf0e10cSrcweiruse installer::windows::idtglobal;
34*cdf0e10cSrcweir
35*cdf0e10cSrcweir####################################################################################
36*cdf0e10cSrcweir# Creating the file Upgrade.idt dynamically
37*cdf0e10cSrcweir# Content:
38*cdf0e10cSrcweir# UpgradeCode VersionMin VersionMax Language Attributes Remove ActionProperty
39*cdf0e10cSrcweir####################################################################################
40*cdf0e10cSrcweir
41*cdf0e10cSrcweirsub create_upgrade_table
42*cdf0e10cSrcweir{
43*cdf0e10cSrcweir	my ($basedir, $allvariableshashref) = @_;
44*cdf0e10cSrcweir
45*cdf0e10cSrcweir	my @upgradetable = ();
46*cdf0e10cSrcweir
47*cdf0e10cSrcweir	# fix for problematic OOo 1.9 versions
48*cdf0e10cSrcweir	my $include_ooo_fix = 0;
49*cdf0e10cSrcweir	my $ooomaxnew = "";
50*cdf0e10cSrcweir	if (($installer::globals::product =~ /^\s*OpenOffice/i ) && ( ! ( $installer::globals::product =~ /SDK/i )) && ( ! $installer::globals::languagepack ))
51*cdf0e10cSrcweir	{
52*cdf0e10cSrcweir		$include_ooo_fix = 1;
53*cdf0e10cSrcweir		$ooomaxnew = "34.0.0";
54*cdf0e10cSrcweir	}
55*cdf0e10cSrcweir
56*cdf0e10cSrcweir	installer::windows::idtglobal::write_idt_header(\@upgradetable, "upgrade");
57*cdf0e10cSrcweir
58*cdf0e10cSrcweir	# Setting also $installer::globals::msimajorproductversion, that is for example "3.0.0", to differ between old products for OOo 2.x and
59*cdf0e10cSrcweir	# older products from OOo 3.x. The latter must be removed always, the removal of the first is controlled with a checkbox.
60*cdf0e10cSrcweir	my $newline = $installer::globals::upgradecode . "\t" . "\t" . $installer::globals::msimajorproductversion . "\t" . "\t" . "0" . "\t" . "\t" . "OLDPRODUCTS" . "\n";
61*cdf0e10cSrcweir	push(@upgradetable, $newline);
62*cdf0e10cSrcweir
63*cdf0e10cSrcweir	# Setting all products, that must be removed.
64*cdf0e10cSrcweir	$newline = $installer::globals::upgradecode . "\t" . $installer::globals::msimajorproductversion . "\t" . $installer::globals::msiproductversion . "\t" . "\t" . "257" . "\t" . "\t" . "OLDPRODUCTSSAMEMAJOR" . "\n";
65*cdf0e10cSrcweir	push(@upgradetable, $newline);
66*cdf0e10cSrcweir
67*cdf0e10cSrcweir	if ( ! $installer::globals::patch )
68*cdf0e10cSrcweir	{
69*cdf0e10cSrcweir		# preventing downgrading
70*cdf0e10cSrcweir		$newline = $installer::globals::upgradecode . "\t" . $installer::globals::msiproductversion . "\t" . $ooomaxnew . "\t" . "\t" . "2" . "\t" . "\t" . "NEWPRODUCTS" . "\n";
71*cdf0e10cSrcweir		push(@upgradetable, $newline);
72*cdf0e10cSrcweir
73*cdf0e10cSrcweir		$newline = $installer::globals::upgradecode . "\t" . $installer::globals::msiproductversion . "\t" . $ooomaxnew . "\t" . "\t" . "258" . "\t" . "\t" . "SAMEPRODUCTS" . "\n";
74*cdf0e10cSrcweir		push(@upgradetable, $newline);
75*cdf0e10cSrcweir
76*cdf0e10cSrcweir		if ( $include_ooo_fix )
77*cdf0e10cSrcweir		{
78*cdf0e10cSrcweir			$newline = $installer::globals::upgradecode . "\t" . "35.0.0" . "\t" . "36.0.0" . "\t" . "\t" . "1" . "\t" . "\t" . "OLDPRODUCTS2" . "\n";
79*cdf0e10cSrcweir			push(@upgradetable, $newline);
80*cdf0e10cSrcweir		}
81*cdf0e10cSrcweir
82*cdf0e10cSrcweir		# if (( $allvariableshashref->{'PATCHUPGRADECODE'} ) && ( ! $installer::globals::languagepack ))
83*cdf0e10cSrcweir		# {
84*cdf0e10cSrcweir		#	$newline = $allvariableshashref->{'PATCHUPGRADECODE'} . "\t" . "\t" . $installer::globals::msiproductversion . "\t" . "\t" . "1" . "\t" . "\t" . "OLDPRODUCTSPATCH" . "\n";
85*cdf0e10cSrcweir		#	push(@upgradetable, $newline);
86*cdf0e10cSrcweir		#
87*cdf0e10cSrcweir		#	$newline = $allvariableshashref->{'PATCHUPGRADECODE'} . "\t" . $installer::globals::msiproductversion . "\t" . "\t" . "\t" . "2" . "\t" . "\t" . "NEWPRODUCTSPATCH" . "\n";
88*cdf0e10cSrcweir		#	push(@upgradetable, $newline);
89*cdf0e10cSrcweir		#
90*cdf0e10cSrcweir		#	$newline = $allvariableshashref->{'PATCHUPGRADECODE'} . "\t" . $installer::globals::msiproductversion . "\t" . "\t" . "\t" . "258" . "\t" . "\t" . "SAMEPRODUCTSPATCH" . "\n";
91*cdf0e10cSrcweir		#	push(@upgradetable, $newline);
92*cdf0e10cSrcweir		# }
93*cdf0e10cSrcweir
94*cdf0e10cSrcweir		# also searching for the beta
95*cdf0e10cSrcweir
96*cdf0e10cSrcweir		if (( $allvariableshashref->{'BETAUPGRADECODE'} ) && ( ! $installer::globals::languagepack ))
97*cdf0e10cSrcweir		{
98*cdf0e10cSrcweir			$newline = $allvariableshashref->{'BETAUPGRADECODE'} . "\t" . "1.0" . "\t" . "\t" . "\t" . "1" . "\t" . "\t" . "BETAPRODUCTS" . "\n";
99*cdf0e10cSrcweir			push(@upgradetable, $newline);
100*cdf0e10cSrcweir		}
101*cdf0e10cSrcweir
102*cdf0e10cSrcweir		# also searching for the stub
103*cdf0e10cSrcweir
104*cdf0e10cSrcweir		if (( $allvariableshashref->{'STUBUPGRADECODE'} ) && ( ! $installer::globals::languagepack ))
105*cdf0e10cSrcweir		{
106*cdf0e10cSrcweir			$newline = $allvariableshashref->{'STUBUPGRADECODE'} . "\t" . "1.0" . "\t" . "\t" . "\t" . "1" . "\t" . "\t" . "STUBPRODUCTS" . "\n";
107*cdf0e10cSrcweir			push(@upgradetable, $newline);
108*cdf0e10cSrcweir		}
109*cdf0e10cSrcweir
110*cdf0e10cSrcweir		# searching for all older patches and languagepacks (defined in a extra file)
111*cdf0e10cSrcweir
112*cdf0e10cSrcweir		if (( $allvariableshashref->{'REMOVE_UPGRADE_CODE_FILE'} ) && ( ! $installer::globals::languagepack ))
113*cdf0e10cSrcweir		{
114*cdf0e10cSrcweir			my $filename = $allvariableshashref->{'REMOVE_UPGRADE_CODE_FILE'};
115*cdf0e10cSrcweir			my $langpackcodefilename = $installer::globals::idttemplatepath  . $installer::globals::separator . $filename;
116*cdf0e10cSrcweir			if ( ! -f $langpackcodefilename ) { installer::exiter::exit_program("ERROR: Could not find file \"$langpackcodefilename\".", "create_upgrade_table"); }
117*cdf0e10cSrcweir
118*cdf0e10cSrcweir			my $filecontent = installer::files::read_file($langpackcodefilename);
119*cdf0e10cSrcweir			my $newlines = analyze_file_for_upgrade_table($filecontent);
120*cdf0e10cSrcweir
121*cdf0e10cSrcweir			for ( my $i = 0; $i <= $#{$newlines}; $i++ ) { push(@upgradetable, ${$newlines}[$i]); }
122*cdf0e10cSrcweir		}
123*cdf0e10cSrcweir	}
124*cdf0e10cSrcweir
125*cdf0e10cSrcweir	# No upgrade for Beta versions!
126*cdf0e10cSrcweir
127*cdf0e10cSrcweir	if (( $allvariableshashref->{'PRODUCTEXTENSION'} eq "Beta" ) && ( ! $installer::globals::patch ) && ( ! $installer::globals::languagepack ))
128*cdf0e10cSrcweir	{
129*cdf0e10cSrcweir		@upgradetable = ();
130*cdf0e10cSrcweir		installer::windows::idtglobal::write_idt_header(\@upgradetable, "upgrade");
131*cdf0e10cSrcweir		my $infoline = "Beta product -> empty Upgrade table\n";
132*cdf0e10cSrcweir		push(@installer::globals::logfileinfo, $infoline);
133*cdf0e10cSrcweir	}
134*cdf0e10cSrcweir
135*cdf0e10cSrcweir	# Saving the file
136*cdf0e10cSrcweir
137*cdf0e10cSrcweir	my $upgradetablename = $basedir . $installer::globals::separator . "Upgrade.idt";
138*cdf0e10cSrcweir	installer::files::save_file($upgradetablename ,\@upgradetable);
139*cdf0e10cSrcweir	my $infoline = "Created idt file: $upgradetablename\n";
140*cdf0e10cSrcweir	push(@installer::globals::logfileinfo, $infoline);
141*cdf0e10cSrcweir}
142*cdf0e10cSrcweir
143*cdf0e10cSrcweir##############################################################
144*cdf0e10cSrcweir# Reading the file with UpgradeCodes of old products,
145*cdf0e10cSrcweir# that can be removed, if the user wants to remove them.
146*cdf0e10cSrcweir##############################################################
147*cdf0e10cSrcweir
148*cdf0e10cSrcweirsub analyze_file_for_upgrade_table
149*cdf0e10cSrcweir{
150*cdf0e10cSrcweir	my ($filecontent) = @_;
151*cdf0e10cSrcweir
152*cdf0e10cSrcweir	my @allnewlines = ();
153*cdf0e10cSrcweir
154*cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filecontent}; $i++ )
155*cdf0e10cSrcweir	{
156*cdf0e10cSrcweir		my $line = ${$filecontent}[$i];
157*cdf0e10cSrcweir		if ( $line =~ /^\s*$/ ) { next; } # empty lines can be ignored
158*cdf0e10cSrcweir		if ( $line =~ /^\s*\#/ ) { next; } # comment lines starting with a hash
159*cdf0e10cSrcweir
160*cdf0e10cSrcweir		if ( $line =~ /^(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)\t(.*)$/ ) { push(@allnewlines, $line); }
161*cdf0e10cSrcweir		else { installer::exiter::exit_program("ERROR: Wrong syntax in file for upgrade table", "analyze_file_for_upgrade_table"); }
162*cdf0e10cSrcweir	}
163*cdf0e10cSrcweir
164*cdf0e10cSrcweir	return \@allnewlines;
165*cdf0e10cSrcweir}
166*cdf0e10cSrcweir
167*cdf0e10cSrcweir1;
168