summaryrefslogtreecommitdiffhomepage
path: root/ArchiveEx/Archive.h
blob: e9a49c54fd85e65dd26a93bce1a056db5613c698 (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
#pragma once

#include <cstddef>
#include <cstdint>
#include <vector>


namespace Archive
{


static constexpr std::size_t NAMELEN {64};


struct Header
{
	std::uint32_t version;
	std::uint32_t total_entries;
	struct {
		std::uint32_t total_blocks;
		std::uint32_t compressed_size;
		std::uint32_t offset;
	} directory;
};


struct Entry
{
	char name[NAMELEN];
	std::uint32_t original_size;
	std::uint32_t compressed_size;
	std::uint32_t offset;
};


class Archive
{
public:
	explicit Archive(const char* path);
	int Extract(int index, std::uint8_t*& buffer, bool null_terminated=false) const;
	int Extract(const char* filepath, std::uint8_t*& buffer, bool null_terminated=false) const;
	int Find(const char* filepath) const;
	int Insert(const char* filepath);
	void WriteMeta();
	void UpdateBlockMap();
	std::size_t FindFreeSpot(std::size_t bytes) const;
	void PrintNamesOfEntries() const;
	void PrintBlocks() const;
	std::size_t DirectoryBlocks() const;
private:
	const char* path;
	Header header;
	std::vector<Entry> entries;
	std::vector<int> blocks;
};


}  // namespace Archive