Give a better error when opening a DCP with File -> Open by mistake (#1723). v2.14.32
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:23:11 +0000 (20:23 +0000)
src/lib/exceptions.cc
src/lib/exceptions.h
src/lib/film.cc
src/tools/dcpomatic.cc

index bf474e3ead2067ef5e6d1319b8a6ca5a2f27d827..4b518e73a5157aeb2eec10487498c68d7c310744 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 99f0a5d8735e83c9fca7a57f8b4f2fafc40846ba..bd94fb92b1514dd28d62300670976efed91d6f08 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 ede367ded490d4125d467030a8efd5f13b55e627..70142dcf38f1ac36dcdcbea4317cb84e65b08025 100644 (file)
@@ -454,6 +454,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 4edfe4cd1b997afd916a9c6e81c10fdde8123f75..9d40ff3bde4bd90b01d4ffc67fbf9636779a2a9c 100644 (file)
@@ -439,10 +439,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)