Give a better error when opening a DCP with File -> Open by mistake (#1723).
authorCarl Hetherington <cth@carlh.net>
Wed, 11 Mar 2020 20:23:11 +0000 (20:23 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 11 Mar 2020 20:24:28 +0000 (21:24 +0100)
src/lib/exceptions.cc
src/lib/exceptions.h
src/lib/film.cc
src/tools/dcpomatic.cc

index 99d4c3979a602dc5e1a84c0673e29c10c1e9d4e5..ba3d4a05cd68bacbefd4d446fa4e2b3fbfaa87c0 100644 (file)
@@ -40,6 +40,13 @@ OpenFileError::OpenFileError (boost::filesystem::path f, int error, Mode mode)
 
 }
 
+FileNotFoundError::FileNotFoundError (boost::filesystem::path f)
+       : runtime_error(String::compose("File %1 not found", f.string()))
+       , _file (f)
+{
+
+}
+
 ReadFileError::ReadFileError (boost::filesystem::path f, int e)
        : FileError (String::compose (_("could not read from file %1 (%2)"), f.string(), strerror (e)), f)
 {
index 391258bd51bba7303fb7033266da0250e7444974..73b8cc85a7876259c594f5d1fee92acd9cd85897 100644 (file)
@@ -117,6 +117,22 @@ public:
        OpenFileError (boost::filesystem::path f, int error, Mode mode);
 };
 
+class FileNotFoundError : public std::runtime_error
+{
+public:
+       FileNotFoundError (boost::filesystem::path f);
+       virtual ~FileNotFoundError () throw () {}
+
+       /** @return name of the file that this exception concerns */
+       boost::filesystem::path file () const {
+               return _file;
+       }
+
+private:
+       /** name of the file that this exception concerns */
+       boost::filesystem::path _file;
+};
+
 /** @class ReadFileError.
  *  @brief Indicates that some error occurred when trying to read from a file
  */
index 90b18ea707eb3e20c043160e482b18a8704c9688..691ef58dab1012f0b2dfb8c96d7b141e7b34ffc2 100644 (file)
@@ -475,6 +475,10 @@ Film::read_metadata (optional<boost::filesystem::path> path)
                path = file (metadata_file);
        }
 
+       if (!boost::filesystem::exists(*path)) {
+               throw FileNotFoundError(*path);
+       }
+
        cxml::Document f ("Metadata");
        f.read_file (path.get ());
 
index ea3cfbe32c7697665208917074d1365285e5c57a..aea058d8048c72f50d969ce5f67385ad1b83f846 100644 (file)
@@ -447,10 +447,21 @@ public:
 
                JobManager::instance()->add(shared_ptr<Job>(new CheckContentChangeJob(film)));
        }
-       catch (std::exception& e) {
-               wxString p = std_to_wx (file.string ());
-               wxCharBuffer b = p.ToUTF8 ();
-               error_dialog (this, wxString::Format (_("Could not open film at %s"), p.data()), std_to_wx (e.what()));
+       catch (FileNotFoundError& e) {
+               boost::filesystem::path const dir = e.file().parent_path();
+               if (boost::filesystem::exists(dir / "ASSETMAP") || boost::filesystem::exists(dir / "ASSETMAP.xml")) {
+                       error_dialog (
+                               this, _("Could not open this folder as a DCP-o-matic project."),
+                               _("It looks like you are trying to open a DCP.  File -> Open is for loading DCP-o-matic projects, not DCPs.  To import a DCP, create a new project with File -> New and then click the \"Add DCP...\" button.")
+                               );
+               } else {
+                       wxString const p = std_to_wx(file.string ());
+                       error_dialog (this, wxString::Format(_("Could not open film at %s"), p.data()), std_to_wx(e.what()));
+               }
+
+       } catch (std::exception& e) {
+               wxString const p = std_to_wx (file.string());
+               error_dialog (this, wxString::Format(_("Could not open film at %s"), p.data()), std_to_wx(e.what()));
        }
 
        void set_film (shared_ptr<Film> film)