-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSevenZ.h
75 lines (50 loc) · 1.99 KB
/
SevenZ.h
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
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef INC_7Z_EXTRACTOR_SEVEN_Z_ARCHIVE_H
#define INC_7Z_EXTRACTOR_SEVEN_Z_ARCHIVE_H
#include <string>
#include <filesystem>
#include <functional>
#include <utility>
#include <vector>
namespace fs = std::filesystem;
class SevenZArchive;
class SevenZFileEntry {
public:
[[maybe_unused]] const std::size_t fileSize;
[[maybe_unused]] const std::time_t creationTime;
[[maybe_unused]] const fs::path fileName;
protected:
SevenZFileEntry(const std::size_t fileSize,
const std::time_t creationTime,
fs::path fileName,
const unsigned int fileIndex) : creationTime(creationTime),
fileIndex(fileIndex),
fileSize(fileSize),
fileName(std::move(fileName)) {}
const unsigned int fileIndex;
friend class SevenZArchive;
};
class SevenZArchive {
public:
explicit SevenZArchive(const std::string &path);
virtual ~SevenZArchive();
void extractInFile(const SevenZFileEntry &file, const fs::path &path);
void getData(const SevenZFileEntry &file, std::vector<unsigned char> &outBuffer);
unsigned int nbFiles();
using iterator = SevenZFileEntry *;
using const_iterator = SevenZFileEntry const *;
iterator begin() { return files.data(); }
iterator end() { return files.data() + files.size(); }
[[nodiscard]] const_iterator begin() const { return files.data(); }
[[nodiscard]] const_iterator end() const { return files.data() + files.size(); }
private:
struct MyCFileInStream;
struct MyCLookToRead2;
struct MyCSzArEx;
std::unique_ptr<MyCFileInStream> archiveStream;
std::unique_ptr<MyCLookToRead2> lookStream;
std::unique_ptr<MyCSzArEx> db;
std::vector<SevenZFileEntry> files;
void check_error(int err) const;
void check_errno(int err, const std::string &res) const;
};
#endif //INC_7Z_EXTRACTOR_SEVEN_Z_ARCHIVE_H