X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FResource.cc;h=a9ff22da9eb68c1300055fca4337bbcbf62d848e;hp=d958c3aa9e551cc584d9fe14fe02cf3275846041;hb=8ad81a8282ce6e9e488a453e6bcd05fbc09715dc;hpb=50c1239917f5e443b8ec91773c85ceb3db7da67b diff --git a/src/Moof/Resource.cc b/src/Moof/Resource.cc index d958c3a..a9ff22d 100644 --- a/src/Moof/Resource.cc +++ b/src/Moof/Resource.cc @@ -28,6 +28,9 @@ #include +#include + +#include "Log.hh" #include "Resource.hh" @@ -43,29 +46,43 @@ Resource::~Resource() {} void Resource::addSearchPath(const std::string& directory) { + std::string path(directory); + + ASSERT(path.length() > 0 && "empty search path string"); + // add a slash if there isn't one already - if (directory[directory.length() - 1] != '/') - { - searchPaths_.push_back(directory + '/'); - } - else + if (*path.rbegin() != '/') { - searchPaths_.push_back(directory); + path += '/'; } + +#if defined(__WIN32__) || defined(_WIN32) || defined(_WIN64) + boost::replace_all(path, "/", "\\"); +#endif + + searchPaths_.push_back(path); } std::string Resource::getPath(const std::string& name) { std::vector::iterator it; + std::string path(name); + +#if defined(__WIN32__) || defined(_WIN32) || defined(_WIN64) + boost::replace_all(path, "/", "\\"); +#endif + for (it = searchPaths_.begin(); it != searchPaths_.end(); ++it) { std::string fullPath(*it); - fullPath += name; + fullPath += path; + + logDebug("looking for resource %s at %s", name.c_str(), path.c_str()); - // TODO this could be more portable if (access(fullPath.c_str(), R_OK) == 0) { + logDebug("found resource %s at %s", name.c_str(), path.c_str()); return fullPath; } }