Confirm overwrite of existing DCP when creating a new one.
authorCarl Hetherington <cth@carlh.net>
Mon, 3 Apr 2017 22:41:24 +0000 (23:41 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 3 Apr 2017 22:41:24 +0000 (23:41 +0100)
src/lib/film.cc
src/lib/film.h
src/lib/writer.cc
src/tools/dcpomatic.cc

index dd31388b6fd7adf58210cd49fa72e3432822830e..56dce56e596bd9ac3e7ae9a516d47d06ecee7c46 100644 (file)
@@ -509,10 +509,11 @@ Film::read_metadata (optional<boost::filesystem::path> path)
 }
 
 /** Given a directory name, return its full path within the Film's directory.
 }
 
 /** Given a directory name, return its full path within the Film's directory.
- *  The directory (and its parents) will be created if they do not exist.
+ *  @param d directory name within the Filn's directory.
+ *  @param create true to create the directory (and its parents) if they do not exist.
  */
 boost::filesystem::path
  */
 boost::filesystem::path
-Film::dir (boost::filesystem::path d) const
+Film::dir (boost::filesystem::path d, bool create) const
 {
        DCPOMATIC_ASSERT (_directory);
 
 {
        DCPOMATIC_ASSERT (_directory);
 
@@ -520,7 +521,9 @@ Film::dir (boost::filesystem::path d) const
        p /= _directory.get();
        p /= d;
 
        p /= _directory.get();
        p /= d;
 
-       boost::filesystem::create_directories (p);
+       if (create) {
+               boost::filesystem::create_directories (p);
+       }
 
        return p;
 }
 
        return p;
 }
index 2b700b00752834cc48e803d61404932a8f7e9783..1d8af39d81b043ee6a7f16b9fed8893f86ec9bb9 100644 (file)
@@ -89,7 +89,7 @@ public:
        }
 
        boost::filesystem::path file (boost::filesystem::path f) const;
        }
 
        boost::filesystem::path file (boost::filesystem::path f) const;
-       boost::filesystem::path dir (boost::filesystem::path d) const;
+       boost::filesystem::path dir (boost::filesystem::path d, bool create = true) const;
 
        void use_template (std::string name);
        std::list<std::string> read_metadata (boost::optional<boost::filesystem::path> path = boost::optional<boost::filesystem::path> ());
 
        void use_template (std::string name);
        std::list<std::string> read_metadata (boost::optional<boost::filesystem::path> path = boost::optional<boost::filesystem::path> ());
index ccd6d74d1847aa3560a9fb1af04262942794fabb..595915883228021dd49f86ce920ea9aa4f9492c0 100644 (file)
@@ -79,9 +79,6 @@ Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> j)
        , _repeat_written (0)
        , _pushed_to_disk (0)
 {
        , _repeat_written (0)
        , _pushed_to_disk (0)
 {
-       /* Remove any old DCP */
-       boost::filesystem::remove_all (_film->dir (_film->dcp_name ()));
-
        shared_ptr<Job> job = _job.lock ();
        DCPOMATIC_ASSERT (job);
 
        shared_ptr<Job> job = _job.lock ();
        DCPOMATIC_ASSERT (job);
 
index 92de9a1f0a0d3d49d4720abc2a466977a5707f3e..f94c2ac547209a2118927779d1355723d2d8eb72 100644 (file)
@@ -496,6 +496,16 @@ private:
                        }
                }
 
                        }
                }
 
+
+               /* Remove any existing DCP if the user agrees */
+               boost::filesystem::path const dcp_dir = _film->dir (_film->dcp_name(), false);
+               if (boost::filesystem::exists (dcp_dir)) {
+                       if (!confirm_dialog (this, wxString::Format (_("Do you want to overwrite the existing DCP %s?"), std_to_wx(dcp_dir.string()).data()))) {
+                               return;
+                       }
+                       boost::filesystem::remove_all (dcp_dir);
+               }
+
                try {
                        /* It seems to make sense to auto-save metadata here, since the make DCP may last
                           a long time, and crashes/power failures are moderately likely.
                try {
                        /* It seems to make sense to auto-save metadata here, since the make DCP may last
                           a long time, and crashes/power failures are moderately likely.