X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fresource.cc;h=d22ae217a28d81269460fa8fda3201764bccc37d;hp=5cd75360d85d5c8c5041d76da80987bc830cccf0;hb=bc795376d093ee097040f029b891b5435eb3bd21;hpb=e0fb747f2e647115d0b8953615c254d25c045345 diff --git a/src/moof/resource.cc b/src/moof/resource.cc index 5cd7536..d22ae21 100644 --- a/src/moof/resource.cc +++ b/src/moof/resource.cc @@ -9,8 +9,15 @@ * **************************************************************************/ +#include "../config.h" + #include +#ifdef USE_HOTLOADING +#include +#include +#endif + #include #include @@ -19,14 +26,6 @@ #include "hash.hh" #include "resource.hh" -#if HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef USE_HOTLOADING -#include -#include -#endif #ifndef BUF_SIZE #define BUF_SIZE 4096 @@ -36,7 +35,7 @@ namespace moof { -static std::vector search_paths_; +static std::string search_paths_; typedef boost::weak_ptr resource_weakptr; static hash resource_table_; @@ -185,66 +184,19 @@ void resource::reload() void resource::add_search_paths(const std::string& paths) { - std::vector pathList; - boost::split(pathList, paths, boost::is_any_of(":")); - - add_search_paths(pathList); -} - -void resource::add_search_paths(const std::vector& pathList) -{ - std::vector::const_iterator it; - for (it = pathList.begin(); it != pathList.end(); ++it) - { - std::string path(*it); - - ASSERT(!path.empty() && "empty search path string"); - - // add a slash if there isn't one already - if (*path.rbegin() != '/') path += '/'; - -#if defined(_WIN32) - //boost::replace_all(path, "/", "\\"); -#endif - - search_paths_.push_back(path); - log_info << "added search path " << path << std::endl; - } + search_paths_ = paths; } bool resource::find(const std::string& path) { - FILE* file = open_file(path); - if (file) - { - fclose(file); - return true; - } - - return false; + return !stlplus::lookup(path, search_paths_, ":").empty(); } FILE* resource::open_file(const std::string& path, const std::string& mode) { -#if defined(_WIN32) - // windows always has to be a little different - //boost::replace_all(path, "/", "\\"); -#endif - - std::vector::iterator it; - for (it = search_paths_.begin(); it != search_paths_.end(); ++it) - { - // check path relative to search path - std::string complete_path(*it); - complete_path += path; - - FILE* file = fopen(complete_path.c_str(), mode.c_str()); - if (file) return file; - } - - // last ditch effort; maybe it's already a path to a valid resource - return fopen(path.c_str(), mode.c_str()); + std::string file = stlplus::lookup(path, search_paths_, ":"); + return fopen(file.c_str(), mode.c_str()); }