-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.h
115 lines (98 loc) · 2.96 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef STO_MAIN_H
#define STO_MAIN_H
#include <bs_archive.h>
#include <string>
#include <utility>
#include <fstream>
#include <sstream>
#include <filesystem>
inline std::wstring shortToWide(const std::string &str) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring wide = converter.from_bytes(str);
return wide;
}
struct OptimizerSettings {
std::filesystem::path outputDirectory;
std::filesystem::path inputDirectory;
};
struct GameData {
char *data;
size_t length;
};
class GameResource {
public:
virtual GameData *getData() = 0;
virtual void freeData(GameData *data) = 0;
explicit GameResource(float size, std::wstring mesh) {
this->size = size;
this->mesh = std::move(mesh);
}
public:
float size;
std::wstring mesh;
};
class BSAResource : public GameResource {
private:
GameData gameData;
std::wstring path;
public:
BSAResource(GameData gameData, float size, std::wstring mesh) : GameResource(size, std::move(mesh)) {
// this->path = std::move(path);
this->gameData = gameData;
}
GameData *getData() override {
// bsa_result_message_t result = {0};
// bsa_archive_t archive = bsa_create();
//
// std::wcout << "loading" << this->archivePath << std::endl;
// result = bsa_load_from_file(archive, this->archivePath.wstring().c_str());
// if (result.code < 0) {
// std::wcerr << "Failed to load BSA " << result.text << std::endl;
// return nullptr;
// }
//
// auto data = bsa_extract_file_data_by_filename(archive, this->path.c_str());
// result = data.message;
// if (result.code < 0) {
// std::wcerr << "Failed to load BSA " << result.text << std::endl;
// return nullptr;
// }
// auto copy = new char[data.buffer.size];
// memcpy_s(copy, data.buffer.size, data.buffer.data, data.buffer.size);
//
// bsa_close(archive);
//
// return new GameData{
// copy,
// data.buffer.size
// };
return &this->gameData;
}
void freeData(GameData *data) override {
delete data->data;
// delete data;
}
};
class FileSystemResource : public GameResource {
private:
std::filesystem::path path;
public:
FileSystemResource(std::filesystem::path path, float size, std::wstring mesh) : GameResource(size, mesh) {
this->path = std::move(path);
}
GameData *getData() override {
std::ifstream in(this->path);
std::string contents((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
auto copy = new char[contents.size()];
memcpy_s(copy, contents.size(), contents.c_str(), contents.size());
return new GameData{
copy,
contents.size()
};
}
void freeData(GameData *data) override {
delete data->data;
delete data;
}
};
#endif //STO_MAIN_H