diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-08-12 23:26:10 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-08-12 23:26:10 +0100 |
| commit | a1a33941351365cc371f468c6c9c8f0cf8ca32d2 (patch) | |
| tree | 07291db383d88e512b09450b26199b046028dff2 /src | |
| parent | 916247147468aee47354ebb3088f47b8a56fcccf (diff) | |
Try to be recursive when examining DCP directories.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dcp.cc | 128 | ||||
| -rw-r--r-- | src/dcp.h | 8 |
2 files changed, 77 insertions, 59 deletions
@@ -237,89 +237,41 @@ DCP::write_assetmap (string cpl_uuid, int cpl_length, string pkl_uuid, int pkl_l DCP::DCP (string directory) : _directory (directory) { - string cpl_file; - string pkl_file; - string asset_map_file; + Files files; + scan (files, directory); - for (filesystem::directory_iterator i = filesystem::directory_iterator(directory); i != filesystem::directory_iterator(); ++i) { - - string const t = i->path().string (); - - if (ends_with (t, ".mxf")) { - continue; - } - - xmlpp::DomParser* p = new xmlpp::DomParser; - - try { - p->parse_file (t); - } catch (std::exception& e) { - delete p; - continue; - } - - if (!p) { - delete p; - continue; - } - - string const root = p->get_document()->get_root_node()->get_name (); - delete p; - - if (root == "CompositionPlaylist") { - if (cpl_file.empty ()) { - cpl_file = t; - } else { - throw DCPReadError ("duplicate CPLs found"); - } - } else if (root == "PackingList") { - if (pkl_file.empty ()) { - pkl_file = t; - } else { - throw DCPReadError ("duplicate PKLs found"); - } - } else if (root == "AssetMap") { - if (asset_map_file.empty ()) { - asset_map_file = t; - } else { - throw DCPReadError ("duplicate AssetMaps found"); - } - asset_map_file = t; - } - } - - if (cpl_file.empty ()) { + if (files.cpl.empty ()) { throw FileError ("no CPL file found", ""); } - if (pkl_file.empty ()) { + if (files.pkl.empty ()) { throw FileError ("no PKL file found", ""); } - if (asset_map_file.empty ()) { + if (files.asset_map.empty ()) { throw FileError ("no AssetMap file found", ""); } /* Read the XML */ shared_ptr<CPL> cpl; try { - cpl.reset (new CPL (cpl_file)); + cpl.reset (new CPL (files.cpl)); } catch (FileError& e) { - throw FileError ("could not load CPL file", cpl_file); + throw FileError ("could not load CPL file", files.cpl); } shared_ptr<PKL> pkl; try { - pkl.reset (new PKL (pkl_file)); + pkl.reset (new PKL (files.pkl)); } catch (FileError& e) { - throw FileError ("could not load PKL file", pkl_file); + throw FileError ("could not load PKL file", files.pkl); } shared_ptr<AssetMap> asset_map; try { - asset_map.reset (new AssetMap (asset_map_file)); + asset_map.reset (new AssetMap (files.asset_map)); } catch (FileError& e) { - throw FileError ("could not load AssetMap file", asset_map_file); + throw FileError ("could not load AssetMap file", files.asset_map); } /* Cross-check */ @@ -368,6 +320,64 @@ DCP::DCP (string directory) } } + +void +DCP::scan (Files& files, string directory) const +{ + for (filesystem::directory_iterator i = filesystem::directory_iterator(directory); i != filesystem::directory_iterator(); ++i) { + + string const t = i->path().string (); + + if (filesystem::is_directory (*i)) { + scan (files, t); + continue; + } + + if (ends_with (t, ".mxf")) { + continue; + } + + xmlpp::DomParser* p = new xmlpp::DomParser; + + try { + p->parse_file (t); + } catch (std::exception& e) { + delete p; + continue; + } + + if (!p) { + delete p; + continue; + } + + string const root = p->get_document()->get_root_node()->get_name (); + delete p; + + if (root == "CompositionPlaylist") { + if (files.cpl.empty ()) { + files.cpl = t; + } else { + throw DCPReadError ("duplicate CPLs found"); + } + } else if (root == "PackingList") { + if (files.pkl.empty ()) { + files.pkl = t; + } else { + throw DCPReadError ("duplicate PKLs found"); + } + } else if (root == "AssetMap") { + if (files.asset_map.empty ()) { + files.asset_map = t; + } else { + throw DCPReadError ("duplicate AssetMaps found"); + } + files.asset_map = t; + } + } +} + + list<string> DCP::equals (DCP const & other, EqualityOptions opt) const { @@ -145,6 +145,14 @@ private: */ void write_assetmap (std::string cpl_uuid, int cpl_length, std::string pkl_uuid, int pkl_length) const; + struct Files { + std::string cpl; + std::string pkl; + std::string asset_map; + }; + + void scan (Files& files, std::string directory) const; + /** the directory that we are writing to */ std::string _directory; /** the name of the DCP */ |
