15
15
extern bool SFileCheckWildCard (const char * szString, const char * szWildCard);
16
16
17
17
namespace LUS {
18
- ArchiveManager::ArchiveManager () : ArchiveManager(std::vector<std::string>()) {
18
+ ArchiveManager::ArchiveManager () {
19
19
}
20
20
21
- ArchiveManager::ArchiveManager (const std::vector<std::string>& archivePaths) : ArchiveManager(archivePaths, {}) {
21
+ void ArchiveManager::Init (const std::vector<std::string>& archivePaths) {
22
+ Init (archivePaths, {});
22
23
}
23
24
24
- ArchiveManager::ArchiveManager (const std::vector<std::string>& archivePaths,
25
- const std::unordered_set<uint32_t >& validGameVersions)
26
- : mValidGameVersions (validGameVersions) {
25
+ void ArchiveManager::Init (const std::vector<std::string>& archivePaths,
26
+ const std::unordered_set<uint32_t >& validGameVersions) {
27
+ mValidGameVersions = validGameVersions;
27
28
auto archives = GetArchiveListInPaths (archivePaths);
28
29
for (const auto archive : archives) {
29
30
AddArchive (archive);
@@ -39,6 +40,10 @@ bool ArchiveManager::IsArchiveLoaded() {
39
40
}
40
41
41
42
std::shared_ptr<File> ArchiveManager::LoadFile (const std::string& filePath) {
43
+ if (filePath == " " ) {
44
+ return nullptr ;
45
+ }
46
+
42
47
const auto archive = mFileToArchive [CRC64 (filePath.c_str ())];
43
48
if (archive == nullptr ) {
44
49
return nullptr ;
@@ -56,6 +61,28 @@ std::shared_ptr<File> ArchiveManager::LoadFile(uint64_t hash) {
56
61
return archive->LoadFile (hash);
57
62
}
58
63
64
+ std::shared_ptr<File> ArchiveManager::LoadFileRaw (const std::string& filePath) {
65
+ if (filePath == " " ) {
66
+ return nullptr ;
67
+ }
68
+
69
+ const auto archive = mFileToArchive [CRC64 (filePath.c_str ())];
70
+ if (archive == nullptr ) {
71
+ return nullptr ;
72
+ }
73
+
74
+ return archive->LoadFileRaw (filePath);
75
+ }
76
+
77
+ std::shared_ptr<File> ArchiveManager::LoadFileRaw (uint64_t hash) {
78
+ const auto archive = mFileToArchive [hash];
79
+ if (archive == nullptr ) {
80
+ return nullptr ;
81
+ }
82
+
83
+ return archive->LoadFileRaw (hash);
84
+ }
85
+
59
86
bool ArchiveManager::HasFile (const std::string& filePath) {
60
87
return HasFile (CRC64 (filePath.c_str ()));
61
88
}
@@ -105,9 +132,9 @@ void ArchiveManager::SetArchives(const std::vector<std::shared_ptr<Archive>>& ar
105
132
}
106
133
}
107
134
108
- const std::string& ArchiveManager::HashToString (uint64_t hash) {
135
+ const std::string* ArchiveManager::HashToString (uint64_t hash) const {
109
136
auto it = mHashes .find (hash);
110
- return it != mHashes .end () ? it->second : " " ;
137
+ return it != mHashes .end () ? & it->second : nullptr ;
111
138
}
112
139
113
140
std::vector<std::string> ArchiveManager::GetArchiveListInPaths (const std::vector<std::string>& archivePaths) {
@@ -154,6 +181,7 @@ std::shared_ptr<Archive> ArchiveManager::AddArchive(const std::string& archivePa
154
181
archive = std::make_shared<O2rArchive>(archivePath);
155
182
}
156
183
184
+ archive->Load ();
157
185
return AddArchive (archive);
158
186
}
159
187
@@ -172,12 +200,12 @@ std::shared_ptr<Archive> ArchiveManager::AddArchive(std::shared_ptr<Archive> arc
172
200
SPDLOG_INFO (" Adding Archive {} to Archive Manager" , archive->GetPath ());
173
201
174
202
mArchives .push_back (archive);
175
- mGameVersions .push_back (archive->GetGameVersion ());
203
+ if (archive->HasGameVersion ()) {
204
+ mGameVersions .push_back (archive->GetGameVersion ());
205
+ }
176
206
const auto fileList = archive->ListFiles ();
177
- for (size_t i = 0 ; i < fileList->size (); i++) {
178
- const auto file = fileList->operator [](i);
179
- const auto hash = CRC64 (file.c_str ());
180
- mHashes [hash] = file;
207
+ for (auto & [hash, filename] : *fileList.get ()) {
208
+ mHashes [hash] = filename;
181
209
mFileToArchive [hash] = archive;
182
210
}
183
211
return archive;
0 commit comments