archive.hpp (2098B)
1 /* ReaPack: Package manager for REAPER 2 * Copyright (C) 2015-2025 Christian Fillion 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef REAPACK_ARCHIVE_HPP 19 #define REAPACK_ARCHIVE_HPP 20 21 #include "path.hpp" 22 #include "thread.hpp" 23 24 class ThreadPool; 25 26 typedef void *zipFile; 27 28 namespace Archive { 29 void import(const std::string &path); 30 }; 31 32 class ArchiveReader { 33 public: 34 ArchiveReader(const Path &path); 35 ~ArchiveReader(); 36 int extractFile(const Path &); 37 int extractFile(const Path &, std::ostream &) noexcept; 38 39 private: 40 zipFile m_zip; 41 }; 42 43 typedef std::shared_ptr<ArchiveReader> ArchiveReaderPtr; 44 45 class ArchiveWriter { 46 public: 47 ArchiveWriter(const Path &path); 48 ~ArchiveWriter(); 49 int addFile(const Path &fn); 50 int addFile(const Path &fn, std::istream &) noexcept; 51 52 private: 53 zipFile m_zip; 54 }; 55 56 typedef std::shared_ptr<ArchiveWriter> ArchiveWriterPtr; 57 58 class FileExtractor : public ThreadTask { 59 public: 60 FileExtractor(const Path &target, const ArchiveReaderPtr &); 61 const TempPath &path() const { return m_path; } 62 63 bool concurrent() const override { return false; } 64 bool run() override; 65 66 private: 67 TempPath m_path; 68 ArchiveReaderPtr m_reader; 69 }; 70 71 class FileCompressor : public ThreadTask { 72 public: 73 FileCompressor(const Path &target, const ArchiveWriterPtr &); 74 const Path &path() const { return m_path; } 75 76 bool concurrent() const override { return false; } 77 bool run() override; 78 79 private: 80 Path m_path; 81 ArchiveWriterPtr m_writer; 82 }; 83 84 #endif