Add new LocalTime constructor.
[libdcp.git] / src / asset.cc
index 4cdbcc08222f77db6b08d233b713db1be1a6c073..81321d4da8325962d9c505054ebbf76e76b602ee 100644 (file)
@@ -58,10 +58,22 @@ Asset::Asset (string id, boost::filesystem::path file)
 }
 
 void
-Asset::write_to_pkl (xmlpp::Node* node, Standard standard) const
+Asset::write_to_pkl (xmlpp::Node* node, boost::filesystem::path root, Standard standard) const
 {
        DCP_ASSERT (!_file.empty ());
 
+       optional<boost::filesystem::path> path = relative_to_root (
+               boost::filesystem::canonical (root),
+               boost::filesystem::canonical (_file)
+               );
+
+       if (!path) {
+               /* The path of this asset is not within our DCP, so we assume it's an external
+                  (referenced) one.
+               */
+               return;
+       }
+
        xmlpp::Node* asset = node->add_child ("Asset");
        asset->add_child("Id")->add_child_text ("urn:uuid:" + _id);
        asset->add_child("AnnotationText")->add_child_text (_id);
@@ -75,26 +87,29 @@ Asset::write_to_assetmap (xmlpp::Node* node, boost::filesystem::path root) const
 {
        DCP_ASSERT (!_file.empty ());
 
-       xmlpp::Node* asset = node->add_child ("Asset");
-       asset->add_child("Id")->add_child_text ("urn:uuid:" + _id);
-       xmlpp::Node* chunk_list = asset->add_child ("ChunkList");
-       xmlpp::Node* chunk = chunk_list->add_child ("Chunk");
-
        optional<boost::filesystem::path> path = relative_to_root (
                boost::filesystem::canonical (root),
                boost::filesystem::canonical (_file)
                );
 
        if (!path) {
-               throw MiscError (String::compose ("Asset %1 is not within the directory %2", _file, root));
+               /* The path of this asset is not within our DCP, so we assume it's an external
+                  (referenced) one.
+               */
+               return;
        }
 
+       xmlpp::Node* asset = node->add_child ("Asset");
+       asset->add_child("Id")->add_child_text ("urn:uuid:" + _id);
+       xmlpp::Node* chunk_list = asset->add_child ("ChunkList");
+       xmlpp::Node* chunk = chunk_list->add_child ("Chunk");
+
        /* On Windows path.string() will contain back-slashes; replace these with
           forward-slashes.  XXX: perhaps there is a nicer way to do this with boost.
        */
 
        string path_string = path.get().string ();
-       boost::replace_all (path_string, "\\/", "/");
+       boost::replace_all (path_string, "\\", "/");
 
        chunk->add_child("Path")->add_child_text (path_string);
        chunk->add_child("VolumeIndex")->add_child_text ("1");