]>
Commit | Line | Data |
---|---|---|
23c9e63c DD |
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 | ||
23c9e63c | 28 | |
35addac4 | 29 | #include "String++.h" |
23c9e63c | 30 | #include "find.h" |
5072c0bb | 31 | #include "ini.h" |
23c9e63c | 32 | |
6899a29f | 33 | #include "FindVisitor.h" |
b401ef47 | 34 | #include "IniDBBuilderPackage.h" |
67829ce0 | 35 | #include "IniParseFeedback.h" |
21f325d7 | 36 | |
b401ef47 RC |
37 | class SetupFindVisitor : public FindVisitor |
38 | { | |
39 | public: | |
35addac4 AG |
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 | { | |
35addac4 AG |
48 | if (inidir && |
49 | (theFile->nFileSizeLow || theFile->nFileSizeHigh)) | |
50 | { | |
35addac4 AG |
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 | { | |
35addac4 AG |
56 | if (!casecompare (SetupBaseName + "." + *ext, theFile->cFileName)) |
57 | *fi = true; | |
58 | } | |
35addac4 | 59 | } |
35addac4 AG |
60 | } |
61 | virtual void visitDirectory (const std::string& basePath, | |
62 | WIN32_FIND_DATA const *aDir, int level) | |
63 | { | |
35addac4 AG |
64 | if (level <= 0) |
65 | return; | |
66 | inidir = !casecompare (SetupArch, aDir->cFileName); | |
67 | if (level == 1 && !inidir) | |
68 | return; | |
35addac4 AG |
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) | |
cd748b30 AG |
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 | } | |
35addac4 AG |
93 | } |
94 | found_ini.assign (setup_ext_list.size (), false); | |
95 | } | |
b401ef47 | 96 | virtual ~ SetupFindVisitor (){} |
35addac4 AG |
97 | operator bool () const |
98 | { | |
99 | return !found_ini_list.empty (); | |
100 | } | |
b401ef47 RC |
101 | protected: |
102 | SetupFindVisitor (SetupFindVisitor const &); | |
103 | SetupFindVisitor & operator= (SetupFindVisitor const &); | |
104 | private: | |
35addac4 AG |
105 | bool inidir; |
106 | std::vector<bool> found_ini; | |
b401ef47 | 107 | }; |
35addac4 AG |
108 | |
109 | IniList found_ini_list; | |
110 | ||
55c6e691 | 111 | bool |
7cc4d95e | 112 | do_from_local_dir (HINSTANCE h, HWND owner, std::string &local_dir) |
23c9e63c | 113 | { |
35addac4 AG |
114 | SetupFindVisitor found; |
115 | // single mirror? | |
116 | Find (local_dir.c_str ()).accept (found, 1); | |
117 | if (found) | |
55c6e691 | 118 | return true; |
35addac4 AG |
119 | // multi-mirror? |
120 | Find (local_dir.c_str ()).accept (found, 2); | |
121 | if (found) | |
122 | return true; | |
55c6e691 | 123 | return false; |
23c9e63c | 124 | } |