Fix bad indentation in verify tool help.
[libdcp.git] / tools / dcpverify.cc
index 2ba4f5c885fd9ece3840c9972440bbc29d8e6dbc..6e8e5f0d87624cd24000b1f0f278b6a0ab7ab2d7 100644 (file)
     files in the program, then also delete it here.
 */
 
-#include "verify.h"
-#include "compose.hpp"
+
 #include "common.h"
-#include <boost/bind.hpp>
-#include <boost/optional.hpp>
+#include "compose.hpp"
+#include "filesystem.h"
+#include "raw_convert.h"
+#include "verify.h"
+#include "version.h"
+#include <boost/bind/bind.hpp>
 #include <boost/filesystem.hpp>
-#include <boost/foreach.hpp>
+#include <boost/optional.hpp>
 #include <getopt.h>
 #include <iostream>
 #include <cstdlib>
 
-using std::cout;
+
 using std::cerr;
+using std::cout;
+using std::list;
 using std::string;
 using std::vector;
-using std::list;
 using boost::bind;
 using boost::optional;
+#if BOOST_VERSION >= 106100
+using namespace boost::placeholders;
+#endif
+
 
 static void
 help (string n)
 {
        cerr << "Syntax: " << n << " [OPTION] <DCP>\n"
-            << "  -V, --version           show libdcp version\n"
-            << "  -h, --help              show this help\n"
-            << "  --ignore-missing-assets don't give errors about missing assets\n"
-            << "  --ignore-bv21-smpte     don't give the SMPTE Bv2.1 error about a DCP not being SMPTE\n"
-            << "  -q, --quiet             don't report progress\n";
+            << "  -V, --version                                show libdcp version\n"
+            << "  -h, --help                                   show this help\n"
+            << "  --ignore-missing-assets                      don't give errors about missing assets\n"
+            << "  --ignore-bv21-smpte                          don't give the SMPTE Bv2.1 error about a DCP not being SMPTE\n"
+            << "  --no-asset-hash-check                        don't check asset hashes\n"
+            << "  --asset-hash-check-maximum-size <size-in-MB> only check hashes for assets smaller than this size (in MB)\n"
+            << "  -q, --quiet                                  don't report progress\n";
 }
 
-void
-stage (bool quiet, string s, optional<boost::filesystem::path> path)
-{
-       if (quiet) {
-               return;
-       }
-
-       if (path) {
-               cout << s << ": " << path->string() << "\n";
-       } else {
-               cout << s << "\n";
-       }
-}
-
-void
-progress ()
-{
-
-}
 
 int
 main (int argc, char* argv[])
@@ -90,6 +81,8 @@ main (int argc, char* argv[])
        bool ignore_bv21_smpte = false;
        bool quiet = false;
 
+       dcp::VerificationOptions verification_options;
+
        int option_index = 0;
        while (true) {
                static struct option long_options[] = {
@@ -97,19 +90,23 @@ main (int argc, char* argv[])
                        { "help", no_argument, 0, 'h' },
                        { "ignore-missing-assets", no_argument, 0, 'A' },
                        { "ignore-bv21-smpte", no_argument, 0, 'B' },
+                       { "no-asset-hash-check", no_argument, 0, 'C' },
+                       { "asset-hash-check-maximum-size", required_argument, 0, 'D' },
                        { "quiet", no_argument, 0, 'q' },
                        { 0, 0, 0, 0 }
                };
 
-               int c = getopt_long (argc, argv, "VhABq", long_options, &option_index);
+               int c = getopt_long (argc, argv, "VhABCD:q", long_options, &option_index);
 
                if (c == -1) {
                        break;
+               } else if (c == '?' || c == ':') {
+                       exit(EXIT_FAILURE);
                }
 
                switch (c) {
                case 'V':
-                       cout << "dcpverify version " << LIBDCP_VERSION << "\n";
+                       cout << "dcpverify version " << dcp::version << "\n";
                        exit (EXIT_SUCCESS);
                case 'h':
                        help (argv[0]);
@@ -120,6 +117,12 @@ main (int argc, char* argv[])
                case 'B':
                        ignore_bv21_smpte = true;
                        break;
+               case 'C':
+                       verification_options.check_asset_hashes = false;
+                       break;
+               case 'D':
+                       verification_options.maximum_asset_size_for_hash_check = dcp::raw_convert<int>(optarg) * 1000000LL;
+                       break;
                case 'q':
                        quiet = true;
                        break;
@@ -131,17 +134,55 @@ main (int argc, char* argv[])
                exit (EXIT_FAILURE);
        }
 
-       if (!boost::filesystem::exists (argv[optind])) {
+       if (!dcp::filesystem::exists(argv[optind])) {
                cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
                exit (EXIT_FAILURE);
        }
 
+       auto stage = [quiet](string s, optional<boost::filesystem::path> path) {
+               if (quiet) {
+                       return;
+               }
+
+               if (path) {
+                       cout << s << ": " << path->string() << "\n";
+               } else {
+                       cout << s << "\n";
+               }
+       };
+
+       auto progress = [quiet](float amount) {
+               if (quiet) {
+                       return;
+               }
+               int const width = 60;
+               int const index = std::rint(amount * width);
+               cout << "[";
+               for (int i = 0; i < width; ++i) {
+                       if (i < index) {
+                               std::cout << "=";
+                       } else if (i == index) {
+                               std::cout << ">";
+                       } else {
+                               std::cout << " ";
+                       }
+               }
+               cout << "] " << std::rint(amount * 100) << "%\r";
+               cout.flush();
+       };
+
        vector<boost::filesystem::path> directories;
        directories.push_back (argv[optind]);
-       auto notes = dcp::verify (directories, bind(&stage, quiet, _1, _2), bind(&progress), "xsd");
+       auto notes = dcp::verify(directories, {}, stage, progress, verification_options);
        dcp::filter_notes (notes, ignore_missing_assets);
 
+       if (!quiet) {
+               cout << "\n";
+       }
+
        bool failed = false;
+       bool bv21_failed = false;
+       bool warned = false;
        for (auto i: notes) {
                if (ignore_bv21_smpte && i.code() == dcp::VerificationNote::Code::INVALID_STANDARD) {
                        continue;
@@ -153,15 +194,25 @@ main (int argc, char* argv[])
                        break;
                case dcp::VerificationNote::Type::BV21_ERROR:
                        cout << "Bv2.1 error: " << note_to_string(i) << "\n";
+                       bv21_failed = true;
                        break;
                case dcp::VerificationNote::Type::WARNING:
                        cout << "Warning: " << note_to_string(i) << "\n";
+                       warned = true;
                        break;
                }
        }
 
        if (!failed && !quiet) {
-               cout << "DCP verified OK.\n";
+               if (bv21_failed && warned) {
+                       cout << "\nDCP verified OK (but with Bv2.1 errors and warnings).\n";
+               } else if (bv21_failed) {
+                       cout << "\nDCP verified OK (but with Bv2.1 errors).\n";
+               } else if (warned) {
+                       cout << "\nDCP verified OK (but with warnings).\n";
+               } else {
+                       cout << "DCP verified OK.\n";
+               }
        }
 
        exit (failed ? EXIT_FAILURE : EXIT_SUCCESS);