1*9780544fSAndrew Rist#**************************************************************
2*9780544fSAndrew Rist#
3*9780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
4*9780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
5*9780544fSAndrew Rist#  distributed with this work for additional information
6*9780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
7*9780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
8*9780544fSAndrew Rist#  "License"); you may not use this file except in compliance
9*9780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
10*9780544fSAndrew Rist#
11*9780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12*9780544fSAndrew Rist#
13*9780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
14*9780544fSAndrew Rist#  software distributed under the License is distributed on an
15*9780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
17*9780544fSAndrew Rist#  specific language governing permissions and limitations
18*9780544fSAndrew Rist#  under the License.
19*9780544fSAndrew Rist#
20*9780544fSAndrew Rist#**************************************************************
21*9780544fSAndrew Rist
22*9780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::windows::removefile;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse installer::files;
27cdf0e10cSrcweiruse installer::globals;
28cdf0e10cSrcweiruse installer::windows::idtglobal;
29cdf0e10cSrcweir
30cdf0e10cSrcweir########################################################################
31cdf0e10cSrcweir# Returning the FileKey for a folderitem for removefile table.
32cdf0e10cSrcweir########################################################################
33cdf0e10cSrcweir
34cdf0e10cSrcweirsub get_removefile_filekey
35cdf0e10cSrcweir{
36cdf0e10cSrcweir	my ($folderitem) = @_;
37cdf0e10cSrcweir
38cdf0e10cSrcweir	# returning the unique identifier
39cdf0e10cSrcweir
40cdf0e10cSrcweir	my $identifier = "remove_" . $folderitem->{'directory'};
41cdf0e10cSrcweir
42cdf0e10cSrcweir	$identifier = lc($identifier);
43cdf0e10cSrcweir
44cdf0e10cSrcweir	return $identifier;
45cdf0e10cSrcweir}
46cdf0e10cSrcweir
47cdf0e10cSrcweir########################################################################
48cdf0e10cSrcweir# Returning the Component for a folderitem for removefile table.
49cdf0e10cSrcweir########################################################################
50cdf0e10cSrcweir
51cdf0e10cSrcweirsub get_removefile_component
52cdf0e10cSrcweir{
53cdf0e10cSrcweir	my ($folderitem) = @_;
54cdf0e10cSrcweir
55cdf0e10cSrcweir	return $folderitem->{'component'};
56cdf0e10cSrcweir}
57cdf0e10cSrcweir
58cdf0e10cSrcweir########################################################################
59cdf0e10cSrcweir# Returning the FileName for a folderitem for removefile table.
60cdf0e10cSrcweir########################################################################
61cdf0e10cSrcweir
62cdf0e10cSrcweirsub get_removefile_filename
63cdf0e10cSrcweir{
64cdf0e10cSrcweir	my ($folderitem) = @_;
65cdf0e10cSrcweir
66cdf0e10cSrcweir	 # return nothing: The assigned directory will be removed
67cdf0e10cSrcweir
68cdf0e10cSrcweir	return "";
69cdf0e10cSrcweir}
70cdf0e10cSrcweir
71cdf0e10cSrcweir########################################################################
72cdf0e10cSrcweir# Returning the DirProperty for a folderitem for removefile table.
73cdf0e10cSrcweir########################################################################
74cdf0e10cSrcweir
75cdf0e10cSrcweirsub get_removefile_dirproperty
76cdf0e10cSrcweir{
77cdf0e10cSrcweir	my ($folderitem) = @_;
78cdf0e10cSrcweir
79cdf0e10cSrcweir	return $folderitem->{'directory'};
80cdf0e10cSrcweir}
81cdf0e10cSrcweir
82cdf0e10cSrcweir########################################################################
83cdf0e10cSrcweir# Returning the InstallMode for a folderitem for removefile table.
84cdf0e10cSrcweir########################################################################
85cdf0e10cSrcweir
86cdf0e10cSrcweirsub get_removefile_installmode
87cdf0e10cSrcweir{
88cdf0e10cSrcweir	my ($folderitem) = @_;
89cdf0e10cSrcweir
90cdf0e10cSrcweir	# always returning "2": The file is only removed, if the assigned
91cdf0e10cSrcweir	# component is removed. Name: msidbRemoveFileInstallModeOnRemove
92cdf0e10cSrcweir
93cdf0e10cSrcweir	return 2;
94cdf0e10cSrcweir}
95cdf0e10cSrcweir
96cdf0e10cSrcweir###########################################################################################################
97cdf0e10cSrcweir# Creating the file RemoveFi.idt dynamically
98cdf0e10cSrcweir# Content:
99cdf0e10cSrcweir# FileKey Component_ FileName DirProperty InstallMode
100cdf0e10cSrcweir###########################################################################################################
101cdf0e10cSrcweir
102cdf0e10cSrcweirsub create_removefile_table
103cdf0e10cSrcweir{
104cdf0e10cSrcweir	my ($folderitemsref, $basedir) = @_;
105cdf0e10cSrcweir
106cdf0e10cSrcweir	my @removefiletable = ();
107cdf0e10cSrcweir
108cdf0e10cSrcweir	installer::windows::idtglobal::write_idt_header(\@removefiletable, "removefile");
109cdf0e10cSrcweir
110cdf0e10cSrcweir	# Only the directories created for the FolderItems have to be deleted
111cdf0e10cSrcweir	# with the information in the table RemoveFile
112cdf0e10cSrcweir
113cdf0e10cSrcweir	my @directorycollector = ();
114cdf0e10cSrcweir
115cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$folderitemsref}; $i++ )
116cdf0e10cSrcweir	{
117cdf0e10cSrcweir		my $onelink = ${$folderitemsref}[$i];
118cdf0e10cSrcweir
119cdf0e10cSrcweir		if ( $onelink->{'used'} == 0 ) { next; }
120cdf0e10cSrcweir
121cdf0e10cSrcweir		if ( installer::existence::exists_in_array($onelink->{'directory'}, \@directorycollector)) { next; }
122cdf0e10cSrcweir
123cdf0e10cSrcweir		push(@directorycollector, $onelink->{'directory'});
124cdf0e10cSrcweir
125cdf0e10cSrcweir		my %removefile = ();
126cdf0e10cSrcweir
127cdf0e10cSrcweir		$removefile{'FileKey'} = get_removefile_filekey($onelink);
128cdf0e10cSrcweir		$removefile{'Component_'} = get_removefile_component($onelink);
129cdf0e10cSrcweir		$removefile{'FileName'} = get_removefile_filename($onelink);
130cdf0e10cSrcweir		$removefile{'DirProperty'} = get_removefile_dirproperty($onelink);
131cdf0e10cSrcweir		$removefile{'InstallMode'} = get_removefile_installmode($onelink);
132cdf0e10cSrcweir
133cdf0e10cSrcweir		my $oneline = $removefile{'FileKey'} . "\t" . $removefile{'Component_'} . "\t" . $removefile{'FileName'} . "\t"
134cdf0e10cSrcweir					. $removefile{'DirProperty'} . "\t" . $removefile{'InstallMode'} . "\n";
135cdf0e10cSrcweir
136cdf0e10cSrcweir		push(@removefiletable, $oneline);
137cdf0e10cSrcweir	}
138cdf0e10cSrcweir
139cdf0e10cSrcweir	# Saving the file
140cdf0e10cSrcweir
141cdf0e10cSrcweir	my $removefiletablename = $basedir . $installer::globals::separator . "RemoveFi.idt";
142cdf0e10cSrcweir	installer::files::save_file($removefiletablename ,\@removefiletable);
143cdf0e10cSrcweir	my $infoline = "Created idt file: $removefiletablename\n";
144cdf0e10cSrcweir	push(@installer::globals::logfileinfo, $infoline);
145cdf0e10cSrcweir
146cdf0e10cSrcweir}
147cdf0e10cSrcweir
148cdf0e10cSrcweir1;