]>
Dogcows Code - chaz/yoink/blob - src/moof/resource.cc
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #include <boost/algorithm/string.hpp>
15 #include "resource.hh"
22 std::vector
<std::string
> resource::search_paths_
;
25 void resource::add_search_paths(const std::string
& paths
)
27 std::vector
<std::string
> pathList
;
28 boost::split(pathList
, paths
, boost::is_any_of(":"));
30 add_search_paths(pathList
);
33 void resource::add_search_paths(const std::vector
<std::string
>& pathList
)
35 std::vector
<std::string
>::const_iterator it
;
36 for (it
= pathList
.begin(); it
!= pathList
.end(); ++it
)
38 std::string
path(*it
);
40 ASSERT(!path
.empty() && "empty search path string");
42 // add a slash if there isn't one already
43 if (*path
.rbegin() != '/') path
+= '/';
46 boost::replace_all(path
, "/", "\\");
49 search_paths_
.push_back(path
);
50 log_info
<< "added search path " << path
<< std::endl
;
55 bool resource::find_path(std::string
& path
,
56 const std::string
& prefix
,
57 const std::string
& extension
)
59 FILE* file
= open_file(path
, prefix
, extension
);
69 FILE* resource::open_file(std::string
& path
,
70 const std::string
& prefix
,
71 const std::string
& extension
,
72 const std::string
& mode
)
75 // windows always has to be a little different
76 boost::replace_all(path
, "/", "\\");
77 std::string
temp_prefix(prefix
);
78 boost::replace_all(temp_prefix
, "/", "\\");
79 std::vector
<std::string
> preList
;
80 boost::split(preList
, temp_prefix
, boost::is_any_of(":"));
82 std::vector
<std::string
> preList
;
83 boost::split(preList
, prefix
, boost::is_any_of(":"));
86 std::vector
<std::string
> postList
;
87 boost::split(postList
, extension
, boost::is_any_of(":"));
89 std::vector
<std::string
>::iterator it
;
90 for (it
= search_paths_
.begin(); it
!= search_paths_
.end(); ++it
)
92 std::vector
<std::string
>::iterator jt
;
93 for (jt
= preList
.begin(); jt
!= preList
.end(); ++jt
)
95 std::vector
<std::string
>::iterator kt
;
96 for (kt
= postList
.begin(); kt
!= postList
.end(); ++kt
)
98 std::string
realPath(*it
);
104 FILE* file
= fopen(realPath
.c_str(), mode
.c_str());
113 // check path relative to search path
114 std::string
realPath(*it
);
117 FILE* file
= fopen(realPath
.c_str(), mode
.c_str());
125 // last ditch effort; maybe it's already a path to a valid resource
126 return fopen(path
.c_str(), mode
.c_str());
This page took 0.043596 seconds and 5 git commands to generate.