X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FResource.cc;h=ec940257045ea6650bf479f197eed0df9f91b60c;hp=d958c3aa9e551cc584d9fe14fe02cf3275846041;hb=987971a961454d97082c6448fdc0bbeb540281bb;hpb=bfa6212d09d8735d8fd5e2638188e4a99f21ada4 diff --git a/src/Moof/Resource.cc b/src/Moof/Resource.cc index d958c3a..ec94025 100644 --- a/src/Moof/Resource.cc +++ b/src/Moof/Resource.cc @@ -28,6 +28,9 @@ #include +#include + +#include "Log.hh" #include "Resource.hh" @@ -35,41 +38,63 @@ namespace Mf { // static member -std::vector Resource::searchPaths_; +std::vector Resource::gSearchPaths; -Resource::~Resource() {} +void Resource::addSearchPaths(const std::string& path) +{ + std::vector paths; + boost::split(paths, path, boost::is_any_of(":")); + addSearchPaths(paths); +} -void Resource::addSearchPath(const std::string& directory) +void Resource::addSearchPaths(const std::vector& path) { - // add a slash if there isn't one already - if (directory[directory.length() - 1] != '/') - { - searchPaths_.push_back(directory + '/'); - } - else + std::vector::const_iterator it; + + for (it = path.begin(); it != path.end(); ++it) { - searchPaths_.push_back(directory); + std::string onePath(*it); + + ASSERT(!onePath.empty() && "empty search path string"); + + // add a slash if there isn't one already + if (*onePath.rbegin() != '/') + { + onePath += '/'; + } + +#if defined(_WIN32) || defined(__WIN32__) + boost::replace_all(onePath, "/", "\\"); +#endif + + gSearchPaths.push_back(onePath); + logInfo << "added search path " << onePath << std::endl; } } + std::string Resource::getPath(const std::string& name) { std::vector::iterator it; - for (it = searchPaths_.begin(); it != searchPaths_.end(); ++it) + std::string path(name); + +#if defined(_WIN32) || defined(__WIN32__) + boost::replace_all(path, "/", "\\"); +#endif + + for (it = gSearchPaths.begin(); it != gSearchPaths.end(); ++it) { std::string fullPath(*it); - fullPath += name; + fullPath += path; - // TODO this could be more portable - if (access(fullPath.c_str(), R_OK) == 0) - { - return fullPath; - } + if (access(fullPath.c_str(), R_OK) == 0) return fullPath; } + logWarning << "cannot find resource " << name << std::endl; + // empty string return std::string(); }