Change end() to only do one thing, and copy the required stuff into pause()
[dcpomatic.git] / src / lib / zipper.cc
index 005e152483a496c250e85b986ddd2acb86d36965..625f3049a52a76df41c13d5bd94a49cfa6f6f3af 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
-#include "zipper.h"
-#include "exceptions.h"
+
 #include "dcpomatic_assert.h"
+#include "exceptions.h"
+#include "zipper.h"
+#include <dcp/filesystem.h>
 #include <zip.h>
 #include <boost/filesystem.hpp>
 #include <stdexcept>
 
-using std::string;
+
 using std::runtime_error;
 using std::shared_ptr;
+using std::string;
 
 
 Zipper::Zipper (boost::filesystem::path file)
 {
        int error;
-       _zip = zip_open (file.string().c_str(), ZIP_CREATE | ZIP_EXCL, &error);
+       _zip = zip_open(dcp::filesystem::fix_long_path(file).string().c_str(), ZIP_CREATE | ZIP_EXCL, &error);
        if (!_zip) {
                if (error == ZIP_ER_EXISTS) {
                        throw FileError ("ZIP file already exists", file);
@@ -49,13 +52,17 @@ Zipper::add (string name, string content)
        shared_ptr<string> copy(new string(content));
        _store.push_back (copy);
 
-       struct zip_source* source = zip_source_buffer (_zip, copy->c_str(), copy->length(), 0);
+       auto source = zip_source_buffer (_zip, copy->c_str(), copy->length(), 0);
        if (!source) {
                throw runtime_error ("could not create ZIP source");
        }
 
+#ifdef DCPOMATIC_HAVE_ZIP_FILE_ADD
+       if (zip_file_add(_zip, name.c_str(), source, ZIP_FL_ENC_GUESS) == -1) {
+#else
        if (zip_add(_zip, name.c_str(), source) == -1) {
-               throw runtime_error ("failed to add data to ZIP archive");
+#endif
+               throw runtime_error(String::compose("failed to add data to ZIP archive (%1)", zip_strerror(_zip)));
        }
 }