X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FResource.cc;h=6f09601bf0d36d07f0dc820523e388ed13334868;hp=e21c834e869ce4bc78debe11c0c57d618ab7313e;hb=71bd9dbaf1c1e3c55a9f63392a73865d8aeee7d4;hpb=493ddb59a8620b49dfa0ff62ce93395ebfd02e86 diff --git a/src/Moof/Resource.cc b/src/Moof/Resource.cc index e21c834..6f09601 100644 --- a/src/Moof/Resource.cc +++ b/src/Moof/Resource.cc @@ -28,6 +28,9 @@ #include +#include + +#include "Log.hh" #include "Resource.hh" @@ -38,38 +41,45 @@ namespace Mf { std::vector Resource::searchPaths_; -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__) + boost::replace_all(path, "/", "\\"); +#endif + + searchPaths_.push_back(path); } -std::string Resource::getPathToResource(const std::string& name) +std::string Resource::getPath(const std::string& name) { std::vector::iterator it; + std::string path(name); + +#if defined(_WIN32) || defined(__WIN32__) + boost::replace_all(path, "/", "\\"); +#endif + for (it = searchPaths_.begin(); it != searchPaths_.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 %s", name.c_str()); + // empty string return std::string(); }