-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDataPack.h
More file actions
70 lines (57 loc) · 2.77 KB
/
DataPack.h
File metadata and controls
70 lines (57 loc) · 2.77 KB
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
#pragma once
#include "Core.h"
#include <string>
#include <vector>
#include <functional>
#include <atomic>
#include <windows.h>
class DataPack {
public:
enum class PackType { Unknown, Encrypted, Decrypted };
DataPack(const std::wstring& path);
~DataPack();
DataPack(const DataPack&) = delete;
DataPack& operator=(const DataPack&) = delete;
PackType GetType() const { return type; }
const Core::FileNode& GetFileTree() const { return root_node; }
std::wstring GetPackPath() const { return pack_path; }
uint32_t GetParsedFileCount() const { return parsed_file_count.load(); }
uint64_t GetParsedTotalSize() const { return parsed_total_size.load(); }
void Scan(std::atomic<float>& progress);
void Extract(const Core::FileNode& node, const std::wstring& output_path, std::atomic<float>& progress, bool convert_sct_to_png = false, bool convert_db_to_json = false);
void ExtractAll(const std::wstring& output_path, std::atomic<float>& progress, bool convert_sct_to_png = false, bool convert_db_to_json = false);
std::vector<uint8_t> GetFileData(const Core::FileNode& node);
private:
// this maps only a portion of file at a time.
struct SlidingView {
const uint8_t* data = nullptr; // pointer returned by MapViewOfFile
uint64_t offset = 0; // file offset this view starts at
size_t size = 0; // number of bytes mapped in this view
};
struct PackPart {
HANDLE hFile = INVALID_HANDLE_VALUE;
HANDLE hMapFile = NULL;
uint64_t fileSize = 0;
SlidingView view;
};
// default sliding window size: 64 MB.
static constexpr size_t WINDOW_SIZE = 64ULL * 1024 * 1024;
// queried once in constructor
DWORD alloc_granularity = 65536;
void ScanEncrypted(std::atomic<float>& progress);
void ScanDecrypted(std::atomic<float>& progress);
void AddFileToTree(const std::string& path, uint64_t offset, uint64_t size);
void ExtractNode(const Core::FileNode& node, const std::wstring& current_path, std::atomic<uint64_t>& extracted_size, const uint64_t total_size, std::atomic<float>& progress, bool convert_sct_to_png, bool convert_db_to_json);
std::vector<std::wstring> FindPackParts(const std::wstring& basePath);
bool LoadPackPart(const std::wstring& path, size_t partIndex);
bool EnsureWindow(PackPart& part, uint64_t offset, size_t needed);
const uint8_t* GetDataAtOffset(uint64_t offset, size_t& outSize);
size_t ReadBytes(uint64_t offset, void* dest, size_t count);
std::wstring pack_path;
std::atomic<uint32_t> parsed_file_count{0};
std::atomic<uint64_t> parsed_total_size{0};
std::vector<PackPart> parts;
uint64_t total_file_size = 0;
PackType type;
Core::FileNode root_node;
};