X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fresource.cc;h=16b5f213489ae39ed9448901e5f06d0b2a901160;hp=758827cada59d731bea82a6387c7657fabf33cdc;hb=7d15b919681bb9ec0088b4b27c6abf62d6dfb9b1;hpb=0fffd0097d7b496454413e57b398c903ecc252e4 diff --git a/src/resource.cc b/src/resource.cc index 758827c..16b5f21 100644 --- a/src/resource.cc +++ b/src/resource.cc @@ -37,26 +37,12 @@ namespace dc { std::vector resource::searchPaths_; -resource::resource(const std::string& name) throw(exception) -{ - filePath_ = getPathToResource(name); - - if (!filePath_.empty()) - { - throw exception("cannot find resource file " + name); - } -} - resource::~resource() {} -const std::string& resource::getPathToFile() -{ - return filePath_; -} - void resource::addSearchPath(const std::string& directory) { + // add a slash if there isn't one already if (directory[directory.length() - 1] != '/') { searchPaths_.push_back(directory + '/'); @@ -73,16 +59,22 @@ std::string resource::getPathToResource(const std::string& name) for (i = searchPaths_.begin(); i != searchPaths_.end(); i++) { - const char* fullPath = ((*i) + name).c_str(); - if (access(fullPath, R_OK) == 0) + std::string fullPath(*i); + fullPath += name; + + // TODO access(2) is not all that portable + if (access(fullPath.c_str(), R_OK) == 0) { - return std::string(fullPath); + return fullPath; } } + // empty string return std::string(); } } // namespace dc +/** vim: set ts=4 sw=4 tw=80: *************************************************/ +