#include <unistd.h>
+#include <boost/algorithm/string.hpp>
+
+#include "Log.hh"
#include "Resource.hh"
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::getPathToResource(const std::string& name)
+std::string Resource::getPath(const std::string& name)
{
std::vector<std::string>::iterator it;
- for (it = searchPaths_.begin(); it != searchPaths_.end(); 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;
}
}