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