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

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


namespace ArchiveEx
{


static constexpr std::size_t NAMELEN {64};


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, bool create=false);
	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(bool create=false);
	void GenerateBlockMap();
	std::size_t FindFreeSpot(std::size_t bytes) const;
	void ForEachEntry(std::function<void(const char*)> func) const;
	void ForEachBlock(std::function<void(const char*)> func) const;
	std::size_t DirectoryBlocks() const;
private:
	const char* path;
	std::size_t directory_offset;
	std::vector<Entry> entries;
	std::vector<int> blocks;
};


}  // namespace ArchiveEx