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::existence;
29
30#############################
31# Test of existence
32#############################
33
34sub exists_in_array
35{
36	my ($searchstring, $arrayref) = @_;
37
38	my $alreadyexists = 0;
39
40	for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
41	{
42		if ( ${$arrayref}[$i] eq $searchstring)
43		{
44			$alreadyexists = 1;
45			last;
46		}
47	}
48
49	return $alreadyexists;
50}
51
52sub exists_in_array_of_hashes
53{
54	my ($searchkey, $searchvalue, $arrayref) = @_;
55
56	my $valueexists = 0;
57
58	for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
59	{
60		my $hashref = ${$arrayref}[$i];
61
62		if ( $hashref->{$searchkey} eq $searchvalue )
63		{
64			$valueexists = 1;
65			last;
66		}
67	}
68
69	return $valueexists;
70}
71
72#####################################################################
73# Returning a specified file as base for the new
74# configuration file, defined by its "gid"
75#####################################################################
76
77sub get_specified_file
78{
79	my ($filesarrayref, $searchgid) = @_;
80
81	my $foundfile = 0;
82	my $onefile;
83
84	for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
85	{
86		$onefile = ${$filesarrayref}[$i];
87		my $filegid = $onefile->{'gid'};
88
89		if ( $filegid eq $searchgid )
90		{
91			$foundfile = 1;
92			last;
93		}
94	}
95
96	my $errorline = "ERROR: Could not find file $searchgid in list of files!";
97
98	if ( $installer::globals::patch) { $errorline = "ERROR: Could not find file $searchgid in list of files! intro.bmp must be part of every patch. Please assign the flag PATCH in scp2 project."; }
99
100	if (!($foundfile))
101	{
102		installer::exiter::exit_program($errorline, "get_specified_file");
103	}
104
105	return $onefile;
106}
107
108#####################################################################
109# Returning a specified file as base for a new file,
110# defined by its "Name"
111#####################################################################
112
113sub get_specified_file_by_name
114{
115	my ($filesarrayref, $searchname) = @_;
116
117	my $foundfile = 0;
118	my $onefile;
119
120	for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
121	{
122		$onefile = ${$filesarrayref}[$i];
123		my $filename = $onefile->{'Name'};
124
125		if ( $filename eq $searchname )
126		{
127			$foundfile = 1;
128			last;
129		}
130	}
131
132	if (!($foundfile))
133	{
134		installer::exiter::exit_program("ERROR: Could not find file $searchname in list of files!", "get_specified_file_by_name");
135	}
136
137	return $onefile;
138}
139
140#####################################################################
141# Checking existence of a specific file, defined by its "Name"
142#####################################################################
143
144sub filename_exists_in_filesarray
145{
146	my ($filesarrayref, $searchname) = @_;
147
148	my $foundfile = 0;
149
150	for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
151	{
152		my $onefile = ${$filesarrayref}[$i];
153		my $filename = $onefile->{'Name'};
154
155		if ( $filename eq $searchname )
156		{
157			$foundfile = 1;
158			last;
159		}
160	}
161
162	return $foundfile;
163}
164
165#####################################################################
166# Checking existence of a specific file, defined by its "gid"
167#####################################################################
168
169sub filegid_exists_in_filesarray
170{
171	my ($filesarrayref, $searchgid) = @_;
172
173	my $foundfile = 0;
174
175	for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
176	{
177		my $onefile = ${$filesarrayref}[$i];
178		my $filegid = $onefile->{'gid'};
179
180		if ( $filegid eq $searchgid )
181		{
182			$foundfile = 1;
183			last;
184		}
185	}
186
187	return $foundfile;
188}
189
1901;
191