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::createfolder;
25
26use installer::existence;
27use installer::exiter;
28use installer::files;
29use installer::globals;
30use installer::windows::idtglobal;
31
32##############################################################
33# Returning directory for createfolder table.
34##############################################################
35
36sub get_createfolder_directory
37{
38	my ($onedir) = @_;
39
40	my $uniquename = $onedir->{'uniquename'};
41
42	return $uniquename;
43}
44
45##############################################################
46# Searching the correct file for language pack directories.
47##############################################################
48
49sub get_languagepack_file
50{
51	my ($filesref, $onedir) = @_;
52
53	my $language = $onedir->{'specificlanguage'};
54	my $foundfile = 0;
55	my $onefile = "";
56
57	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
58	{
59		$onefile = ${$filesref}[$i];
60
61		if ( $onefile->{'specificlanguage'} eq $onedir->{'specificlanguage'} )
62		{
63			$foundfile = 1;
64			last;
65		}
66	}
67
68	if ( ! $foundfile ) { installer::exiter::exit_program("ERROR: No file with correct language found (language pack build)!", "get_languagepack_file"); }
69
70	return $onefile;
71}
72
73##############################################################
74# Returning component for createfolder table.
75##############################################################
76
77sub get_createfolder_component
78{
79	my ($onedir, $filesref, $allvariableshashref) = @_;
80
81	# Directories do not belong to a module.
82	# Therefore they can only belong to the root module and
83	# will be added to a component at the root module.
84	# All directories will be added to the component
85	# containing the file $allvariableshashref->{'GLOBALFILEGID'}
86
87	if ( ! $allvariableshashref->{'GLOBALFILEGID'} ) { installer::exiter::exit_program("ERROR: GLOBALFILEGID must be defined in list file!", "get_createfolder_component"); }
88	if (( $installer::globals::patch ) && ( ! $allvariableshashref->{'GLOBALFILEGID'} )) { installer::exiter::exit_program("ERROR: GLOBALPATCHFILEGID must be defined in list file!", "get_createfolder_component"); }
89
90	my $globalfilegid = $allvariableshashref->{'GLOBALFILEGID'};
91	if ( $installer::globals::patch ) { $globalfilegid = $allvariableshashref->{'GLOBALPATCHFILEGID'}; }
92
93	my $onefile = "";
94	if ( $installer::globals::languagepack ) { $onefile = get_languagepack_file($filesref, $onedir); }
95	else { $onefile = installer::existence::get_specified_file($filesref, $globalfilegid); }
96
97	return $onefile->{'componentname'};
98}
99
100####################################################################################
101# Creating the file CreateFo.idt dynamically for creation of empty directories
102# Content:
103# Directory_ Component_
104####################################################################################
105
106sub create_createfolder_table
107{
108	my ($dirref, $filesref, $basedir, $allvariableshashref) = @_;
109
110	my @createfoldertable = ();
111
112	my $infoline;
113
114	installer::windows::idtglobal::write_idt_header(\@createfoldertable, "createfolder");
115
116	for ( my $i = 0; $i <= $#{$dirref}; $i++ )
117	{
118		my $onedir = ${$dirref}[$i];
119
120		# language packs get only language dependent directories
121		if (( $installer::globals::languagepack ) && ( $onedir->{'specificlanguage'} eq "" )) { next };
122
123		my $styles = "";
124
125		if ( $onedir->{'Styles'} ) { $styles = $onedir->{'Styles'}; }
126
127		if ( $styles =~ /\bCREATE\b/ )
128		{
129			my %directory = ();
130
131			$directory{'Directory_'} = get_createfolder_directory($onedir);
132			$directory{'Component_'} = get_createfolder_component($onedir, $filesref, $allvariableshashref);
133
134			my $oneline = $directory{'Directory_'} . "\t" . $directory{'Component_'} . "\n";
135
136			push(@createfoldertable, $oneline);
137		}
138	}
139
140	# Saving the file
141
142	my $createfoldertablename = $basedir . $installer::globals::separator . "CreateFo.idt";
143	installer::files::save_file($createfoldertablename ,\@createfoldertable);
144    $installer::logger::Lang->printf("Created idt file: %s\n", $createfoldertablename);
145}
146
1471;
148