blob: e803bd203f00505060e46ad1a13d94054e1f0cab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#ifndef ARCHIVE_HPP
#define ARCHIVE_HPP
#include "result.hpp"
#include <QtWidgets>
#include <cstdlib>
#include <string>
#include <vector>
#include <zip.h>
#include <fud_status.hpp>
namespace getsuyomi {
enum class ArchiveError
{
BadIndex,
ZipError,
BadData,
Unimplemented
};
using ArchiveResult = Result<std::reference_wrapper<const QImage>, ArchiveError>;
class Archive {
public:
virtual ~Archive() = default;
virtual ArchiveResult getPage(size_t page) = 0;
virtual size_t numPages() const = 0;
virtual bool valid() const = 0;
};
class ZipArchive : public Archive {
public:
explicit ZipArchive(const QString& filename);
ZipArchive(const ZipArchive&) = delete;
ZipArchive(ZipArchive&&);
virtual ~ZipArchive() override;
ZipArchive& operator=(const ZipArchive&) = delete;
ZipArchive& operator=(ZipArchive&& rhs);
virtual ArchiveResult getPage(size_t page) override;
virtual size_t numPages() const override;
bool valid() const override;
private:
void cleanup();
fud::FudStatus populate();
zip_t* m_archive{nullptr};
std::vector<size_t> m_sortedIndices{};
std::vector<std::string> m_filenames{};
std::vector<size_t> m_fileSizes{};
std::vector<std::optional<QImage>> m_pages{};
};
} // namespace getsuyomi
#endif
|