]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000, Red Hat, Inc. | |
3 | * | |
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. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by DJ Delorie <dj@cygnus.com> | |
13 | * | |
14 | */ | |
15 | ||
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. */ | |
27 | ||
28 | ||
29 | #include "String++.h" | |
30 | #include "find.h" | |
31 | #include "ini.h" | |
32 | ||
33 | #include "FindVisitor.h" | |
34 | #include "IniDBBuilderPackage.h" | |
35 | #include "IniParseFeedback.h" | |
36 | ||
37 | class SetupFindVisitor : public FindVisitor | |
38 | { | |
39 | public: | |
40 | SetupFindVisitor () : inidir (false) | |
41 | { | |
42 | found_ini.resize (setup_ext_list.size ()); | |
43 | found_ini.assign (setup_ext_list.size (), false); | |
44 | } | |
45 | virtual void visitFile (const std::string& basePath, | |
46 | const WIN32_FIND_DATA *theFile) | |
47 | { | |
48 | if (inidir && | |
49 | (theFile->nFileSizeLow || theFile->nFileSizeHigh)) | |
50 | { | |
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 (); | |
54 | ext++, fi++) | |
55 | { | |
56 | if (!casecompare (SetupBaseName + "." + *ext, theFile->cFileName)) | |
57 | *fi = true; | |
58 | } | |
59 | } | |
60 | } | |
61 | virtual void visitDirectory (const std::string& basePath, | |
62 | WIN32_FIND_DATA const *aDir, int level) | |
63 | { | |
64 | if (level <= 0) | |
65 | return; | |
66 | inidir = !casecompare (SetupArch, aDir->cFileName); | |
67 | if (level == 1 && !inidir) | |
68 | return; | |
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 (); | |
74 | ext++, fi++) | |
75 | { | |
76 | if (*fi) | |
77 | { | |
78 | found_ini_list.push_back (basePath + SetupArch + "/" | |
79 | + SetupBaseName + "." + *ext); | |
80 | /* | |
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 | |
84 | * same directory. | |
85 | * | |
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. | |
90 | */ | |
91 | break; | |
92 | } | |
93 | } | |
94 | found_ini.assign (setup_ext_list.size (), false); | |
95 | } | |
96 | virtual ~ SetupFindVisitor (){} | |
97 | operator bool () const | |
98 | { | |
99 | return !found_ini_list.empty (); | |
100 | } | |
101 | protected: | |
102 | SetupFindVisitor (SetupFindVisitor const &); | |
103 | SetupFindVisitor & operator= (SetupFindVisitor const &); | |
104 | private: | |
105 | bool inidir; | |
106 | std::vector<bool> found_ini; | |
107 | }; | |
108 | ||
109 | IniList found_ini_list; | |
110 | ||
111 | bool | |
112 | do_from_local_dir (HINSTANCE h, HWND owner, std::string &local_dir) | |
113 | { | |
114 | SetupFindVisitor found; | |
115 | // single mirror? | |
116 | Find (local_dir.c_str ()).accept (found, 1); | |
117 | if (found) | |
118 | return true; | |
119 | // multi-mirror? | |
120 | Find (local_dir.c_str ()).accept (found, 2); | |
121 | if (found) | |
122 | return true; | |
123 | return false; | |
124 | } |