2 * Copyright (c) 2000, Red Hat, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
16 /* The purpose of this file is to handle the case where we're
17 installing from files that already exist in the current directory.
18 If a setup.ini file is present, we set the mirror site to "." and
19 pretend we're installing from the `internet' ;-) else we have to
20 find all the .tar.gz files, deduce their versions, and try to
21 compare versions in the case where the current directory contains
22 multiple versions of any given package. We do *not* try to compare
23 versions with already installed packages; we always choose a
24 package in the current directory over one that's already installed
25 (otherwise, why would you have asked to install it?). Note
26 that we search recursively. */
33 #include "FindVisitor.h"
34 #include "IniDBBuilderPackage.h"
35 #include "IniParseFeedback.h"
37 class SetupFindVisitor
: public FindVisitor
40 SetupFindVisitor () : inidir (false)
42 found_ini
.resize (setup_ext_list
.size ());
43 found_ini
.assign (setup_ext_list
.size (), false);
45 virtual void visitFile (const std::string
& basePath
,
46 const WIN32_FIND_DATA
*theFile
)
49 (theFile
->nFileSizeLow
|| theFile
->nFileSizeHigh
))
51 std::vector
<bool>::iterator fi
= found_ini
.begin ();
52 for (std::vector
<std::string
>::const_iterator ext
= setup_ext_list
.begin ();
53 ext
!= setup_ext_list
.end ();
56 if (!casecompare (SetupBaseName
+ "." + *ext
, theFile
->cFileName
))
61 virtual void visitDirectory (const std::string
& basePath
,
62 WIN32_FIND_DATA
const *aDir
, int level
)
66 inidir
= !casecompare (SetupArch
, aDir
->cFileName
);
67 if (level
== 1 && !inidir
)
69 Find
aFinder (basePath
+ aDir
->cFileName
);
70 aFinder
.accept (*this, inidir
? 0 : --level
);
71 std::vector
<bool>::const_iterator fi
= found_ini
.begin ();
72 for (std::vector
<std::string
>::const_iterator ext
= setup_ext_list
.begin ();
73 ext
!= setup_ext_list
.end ();
78 found_ini_list
.push_back (basePath
+ SetupArch
+ "/"
79 + SetupBaseName
+ "." + *ext
);
81 * Terminate the search after the first setup file
82 * found, which shadows any setup files with
83 * extensions later in the preference order in the
86 * FIXME: It would probably be more sensible to return
87 * all matches (perhaps one list per directory) and
88 * let do_local_ini pick the first one that parses
89 * correctly, just like do_remote_ini does.
94 found_ini
.assign (setup_ext_list
.size (), false);
96 virtual ~ SetupFindVisitor (){}
97 operator bool () const
99 return !found_ini_list
.empty ();
102 SetupFindVisitor (SetupFindVisitor
const &);
103 SetupFindVisitor
& operator= (SetupFindVisitor
const &);
106 std::vector
<bool> found_ini
;
109 IniList found_ini_list
;
112 do_from_local_dir (HINSTANCE h
, HWND owner
, std::string
&local_dir
)
114 SetupFindVisitor found
;
116 Find (local_dir
.c_str ()).accept (found
, 1);
120 Find (local_dir
.c_str ()).accept (found
, 2);