diff options
author | Marius Kintel <marius@kintel.net> | 2012-06-24 14:29:28 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2012-06-24 14:29:28 (GMT) |
commit | 22c5f37424e42b69442ef6b020b650c0e685a8c3 (patch) | |
tree | 4246e75e0c9b133df4513d13186a3ece3c288118 /src/parsersettings.cc | |
parent | 0e6b80015504b36363c5545744b6627554c4d10b (diff) |
Search for libraries from a list of paths. Preparations for issue #125
Diffstat (limited to 'src/parsersettings.cc')
-rw-r--r-- | src/parsersettings.cc | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/parsersettings.cc b/src/parsersettings.cc index a3a02b7..53b34f4 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -1,27 +1,38 @@ #include "parsersettings.h" #include <boost/filesystem.hpp> +#include <boost/foreach.hpp> +#include "boosty.h" #include <qglobal.h> // Needed for Q_ defines - move the offending code somewhere else -using namespace boost::filesystem; -#include "boosty.h" +namespace fs = boost::filesystem; -std::string librarydir; +std::vector<std::string> librarypath; -void set_librarydir(const std::string &libdir) +void add_librarydir(const std::string &libdir) { - librarydir = libdir; + librarypath.push_back(libdir); } -const std::string &get_librarydir() +/*! + Searces for the given file in library paths and returns the full path if found. + Returns an empty path if file cannot be found. +*/ +std::string locate_file(const std::string &filename) { - return librarydir; + BOOST_FOREACH(const std::string &dir, librarypath) { + fs::path usepath = fs::path(dir) / filename; + if (fs::exists(usepath)) return usepath.string(); + } + return std::string(); } void parser_init(const std::string &applicationpath) { + // FIXME: Append paths from OPENSCADPATH before adding built-in paths + std::string librarydir; - path libdir(applicationpath); - path tmpdir; + fs::path libdir(applicationpath); + fs::path tmpdir; #ifdef Q_WS_MAC libdir /= "../Resources"; // Libraries can be bundled if (!is_directory(libdir / "libraries")) libdir /= "../../.."; @@ -37,5 +48,5 @@ void parser_init(const std::string &applicationpath) if (is_directory(tmpdir = libdir / "libraries")) { librarydir = boosty::stringy( tmpdir ); } - set_librarydir(librarydir); + if (!librarydir.empty()) add_librarydir(librarydir); } |