Allow to run on Windows lacking CreateSymbolicLinkW()
[cygwin-setup.git] / fromcwd.cc
blob3e77ad37b88480318eed28a5550f421f1cc99a6a
1 /*
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
10 * http://www.gnu.org/
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. */
29 #include "String++.h"
30 #include "find.h"
31 #include "ini.h"
33 #include "FindVisitor.h"
34 #include "IniDBBuilderPackage.h"
35 #include "IniParseFeedback.h"
37 class SetupFindVisitor : public FindVisitor
39 public:
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)
48 if (inidir &&
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 ();
54 ext++, fi++)
56 if (!casecompare (SetupBaseName + "." + *ext, theFile->cFileName))
57 *fi = true;
61 virtual void visitDirectory (const std::string& basePath,
62 WIN32_FIND_DATA const *aDir, int level)
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++)
76 if (*fi)
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.
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.
91 break;
94 found_ini.assign (setup_ext_list.size (), false);
96 virtual ~ SetupFindVisitor (){}
97 operator bool () const
99 return !found_ini_list.empty ();
101 protected:
102 SetupFindVisitor (SetupFindVisitor const &);
103 SetupFindVisitor & operator= (SetupFindVisitor const &);
104 private:
105 bool inidir;
106 std::vector<bool> found_ini;
109 IniList found_ini_list;
111 bool
112 do_from_local_dir (HINSTANCE h, HWND owner, std::string &local_dir)
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;