diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-05-03 12:35:41 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-05-03 12:35:41 +0100 |
| commit | 450edeeb94ff755b2a6c6588138256ad2894ead7 (patch) | |
| tree | 215cb3db3d0812e36ee627aa64b208aa2ab60b90 /src | |
| parent | 671779298e79f8f3bba46156a2b4cdf551b704d1 (diff) | |
Support file:// URI-style file specifiers in asset map.
Allow DCP reads to continue in the face of some errors (currently
just missing assets).
Diffstat (limited to 'src')
| -rw-r--r-- | src/dcp.cc | 29 | ||||
| -rw-r--r-- | src/dcp.h | 6 |
2 files changed, 29 insertions, 6 deletions
@@ -55,8 +55,10 @@ using std::ostream; using std::make_pair; using std::map; using std::cout; +using std::exception; using boost::shared_ptr; using boost::lexical_cast; +using boost::algorithm::starts_with; using namespace dcp; DCP::DCP (boost::filesystem::path directory) @@ -66,8 +68,18 @@ DCP::DCP (boost::filesystem::path directory) _directory = boost::filesystem::canonical (_directory); } +template<class T> void +survivable_error (bool keep_going, list<string>* errors, T const & e) +{ + if (keep_going && errors) { + errors->push_back (e.what ()); + } else { + throw e; + } +} + void -DCP::read () +DCP::read (bool keep_going, list<string>* errors) { /* Read the ASSETMAP */ @@ -88,15 +100,22 @@ DCP::read () if ((*i)->node_child("ChunkList")->node_children("Chunk").size() != 1) { boost::throw_exception (XMLError ("unsupported asset chunk count")); } - paths.insert (make_pair ( - (*i)->string_child ("Id"), - (*i)->node_child("ChunkList")->node_child("Chunk")->string_child ("Path") - )); + string p = (*i)->node_child("ChunkList")->node_child("Chunk")->string_child ("Path"); + if (starts_with (p, "file://")) { + p = p.substr (7); + } + paths.insert (make_pair ((*i)->string_child ("Id"), p)); } /* Read all the assets from the asset map */ for (map<string, boost::filesystem::path>::const_iterator i = paths.begin(); i != paths.end(); ++i) { boost::filesystem::path path = _directory / i->second; + + if (!boost::filesystem::exists (path)) { + survivable_error (keep_going, errors, FileError ("file not found", path, -1)); + continue; + } + if (boost::algorithm::ends_with (path.string(), ".xml")) { xmlpp::DomParser* p = new xmlpp::DomParser; try { @@ -68,7 +68,11 @@ public: */ DCP (boost::filesystem::path directory); - void read (); + /** Read the DCP's structure into this object. + * @param keep_going true to try to keep going in the face of (some) errors. + * @param notes List of errors that will be added to if keep_going is true. + */ + void read (bool keep_going = false, std::list<std::string>* errors = 0); /** Compare this DCP with another, according to various options. * @param other DCP to compare this one to. |
