diff options
Diffstat (limited to 'src/parsersettings.cc')
-rw-r--r-- | src/parsersettings.cc | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/parsersettings.cc b/src/parsersettings.cc index 134514c..53b34f4 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -1,30 +1,42 @@ #include "parsersettings.h" #include <boost/filesystem.hpp> - -using namespace boost::filesystem; +#include <boost/foreach.hpp> #include "boosty.h" +#include <qglobal.h> // Needed for Q_ defines - move the offending code somewhere else + +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; -#ifdef __APPLE__ + fs::path libdir(applicationpath); + fs::path tmpdir; +#ifdef Q_WS_MAC libdir /= "../Resources"; // Libraries can be bundled if (!is_directory(libdir / "libraries")) libdir /= "../../.."; -#elif !defined(WIN32) +#elif defined(Q_OS_UNIX) if (is_directory(tmpdir = libdir / "../share/openscad/libraries")) { librarydir = boosty::stringy( tmpdir ); } else if (is_directory(tmpdir = libdir / "../../share/openscad/libraries")) { @@ -36,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); } |