From 450edeeb94ff755b2a6c6588138256ad2894ead7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 3 May 2014 12:35:41 +0100 Subject: Support file:// URI-style file specifiers in asset map. Allow DCP reads to continue in the face of some errors (currently just missing assets). --- src/dcp.cc | 29 ++++++++++++++++++++++++----- src/dcp.h | 6 +++++- 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/dcp.cc b/src/dcp.cc index d383eeac..c0d148c5 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -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 void +survivable_error (bool keep_going, list* 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* 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::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 { diff --git a/src/dcp.h b/src/dcp.h index 450a3c00..48b2df3c 100644 --- a/src/dcp.h +++ b/src/dcp.h @@ -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* errors = 0); /** Compare this DCP with another, according to various options. * @param other DCP to compare this one to. -- cgit v1.2.3