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)
_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 */
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 {
*/
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.