swaroop: take ownership of config file if we're run as root.
[dcpomatic.git] / src / lib / screen_kdm.cc
index 5d8409ea746b6e30ff1cf4667f4d20f6e0aecb9e..3515af8a6644f1b6ed70377e1474652577b0fc88 100644 (file)
@@ -25,6 +25,7 @@
 #include <boost/foreach.hpp>
 
 using std::string;
+using std::cout;
 using std::list;
 using boost::shared_ptr;
 
@@ -45,10 +46,25 @@ ScreenKDM::write_files (
 {
        int written = 0;
 
+       if (directory == "-") {
+               /* Write KDMs to the stdout */
+               BOOST_FOREACH (ScreenKDM const & i, screen_kdms) {
+                       cout << i.kdm.as_xml ();
+                       ++written;
+               }
+
+               return written;
+       }
+
+       if (!boost::filesystem::exists (directory)) {
+               boost::filesystem::create_directories (directory);
+       }
+
        /* Write KDMs to the specified directory */
        BOOST_FOREACH (ScreenKDM const & i, screen_kdms) {
                name_values['c'] = i.screen->cinema->name;
                name_values['s'] = i.screen->name;
+               name_values['i'] = i.kdm.id ();
                boost::filesystem::path out = directory / (name_format.get(name_values, ".xml"));
                if (!boost::filesystem::exists (out) || confirm_overwrite (out)) {
                        i.kdm.as_xml (out);