blob: d8464e59a8593302a09107d977beafa808c5603e (
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
|
#ifndef ARCHIVE_HPP
#define ARCHIVE_HPP
#include "result.hpp"
#include <QtWidgets>
#include <cstdlib>
#include <string>
#include <vector>
#include <zip.h>
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;
};
class ZipArchive : public Archive {
public:
explicit ZipArchive(const QString& filename);
virtual ~ZipArchive() override;
virtual ArchiveResult getPage(size_t page) override;
virtual size_t numPages() const override;
private:
void 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
|