mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-12-12 12:25:59 +03:00
feat(client): add PatchFiles class
This commit is contained in:
parent
4a74c722a4
commit
8d54e8ad0b
@ -376,18 +376,17 @@ int32_t InitializeGlobal() {
|
|||||||
CheckAvailableLocales(existingLocale);
|
CheckAvailableLocales(existingLocale);
|
||||||
locale->Set(existingLocale, true, false, false, true);
|
locale->Set(existingLocale, true, false, false, true);
|
||||||
|
|
||||||
|
char path[STORM_MAX_PATH];
|
||||||
|
SStrPrintf(path, sizeof(path), "%s%s", "Data\\", locale->GetString());
|
||||||
|
SFile::SetDataPathAlternate(path);
|
||||||
|
SFile::RebuildHash();
|
||||||
|
|
||||||
|
|
||||||
OpenArchives();
|
OpenArchives();
|
||||||
|
|
||||||
// TODO: This method should be placed inside OpenArchives
|
// TODO: This method should be placed inside OpenArchives
|
||||||
ClientServices::InitLoginServerCVars(1, locale->GetString());
|
ClientServices::InitLoginServerCVars(1, locale->GetString());
|
||||||
|
|
||||||
// SStrPrintf(dest, 260, "%s%s", *(_DWORD *)off_AB6158, v2->m_stringValue.m_str);
|
|
||||||
|
|
||||||
// sub_421B50(dest);
|
|
||||||
|
|
||||||
// sub_423D70();
|
|
||||||
|
|
||||||
// sub_405DD0();
|
// sub_405DD0();
|
||||||
|
|
||||||
// CVar* v3 = CVar::Register(
|
// CVar* v3 = CVar::Register(
|
||||||
|
|||||||
@ -14,6 +14,8 @@ namespace Client {
|
|||||||
|
|
||||||
void ClientPostClose(int32_t a1);
|
void ClientPostClose(int32_t a1);
|
||||||
|
|
||||||
|
const char* UpdateInstallLocation();
|
||||||
|
|
||||||
void CommonMain();
|
void CommonMain();
|
||||||
|
|
||||||
void StormInitialize();
|
void StormInitialize();
|
||||||
|
|||||||
65
src/client/Patch.cpp
Normal file
65
src/client/Patch.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#include "client/Patch.hpp"
|
||||||
|
|
||||||
|
#include <storm/String.hpp>
|
||||||
|
|
||||||
|
#include "client/Client.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
PatchFiles::PatchFiles() {
|
||||||
|
this->path = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PatchFiles::SearchArchives(const char* locale, int32_t a3) {
|
||||||
|
char fullPath[256] = {};
|
||||||
|
char pattern[256] = {};
|
||||||
|
char path[256] = {};
|
||||||
|
|
||||||
|
const size_t listSize = 12;
|
||||||
|
|
||||||
|
ListEntry list[listSize] = {
|
||||||
|
{ 0, 0, false, "Data\\", "patch-?.MPQ" },
|
||||||
|
{ 0, 0, false, "Data\\%s\\", "patch-%s-?.MPQ" },
|
||||||
|
{ 1, 0, false, "Data\\", "patch.MPQ" },
|
||||||
|
{ 1, 0, false, "Data\\%s\\", "patch-%s.MPQ" },
|
||||||
|
{ 1, 1, false, "Data\\", "patch-4.MPQ" },
|
||||||
|
{ 1, 1, false, "Data\\%s\\", "patch-%s-4.MPQ" },
|
||||||
|
{ 1, 1, false, "Data\\", "patch-3.MPQ" },
|
||||||
|
{ 1, 1, false, "Data\\%s\\", "patch-%s-3.MPQ" },
|
||||||
|
{ 1, 1, false, "..\\Data\\", "patch-2.MPQ" },
|
||||||
|
{ 1, 1, false, "..\\Data\\%s\\", "patch-%s-2.MPQ" },
|
||||||
|
{ 1, 1, false, "..\\Data\\", "patch.MPQ" },
|
||||||
|
{ 1, 1, false, "..\\Data\\%s\\", "patch-%s.MPQ" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const char* installRoot = UpdateInstallLocation();
|
||||||
|
|
||||||
|
// Warning: assigning pointer to a temporary variable
|
||||||
|
// Need this for OsFileList's callback
|
||||||
|
this->path = path;
|
||||||
|
|
||||||
|
for (size_t i = 0; i <= 2; ++i) {
|
||||||
|
for (size_t j = 0; j < listSize; ++j) {
|
||||||
|
auto entry = &list[j];
|
||||||
|
if (entry->num1 != i || entry->num2 != (a3 != 0)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SStrPrintf(path, sizeof(path), entry->dataDir, locale);
|
||||||
|
SStrPrintf(pattern, sizeof(pattern), entry->pattern, locale);
|
||||||
|
if (entry->absolute && installRoot && installRoot[0]) {
|
||||||
|
SStrPrintf(fullPath, sizeof(fullPath), "%s%s", installRoot, path);
|
||||||
|
SStrCopy(path, fullPath, sizeof(path));
|
||||||
|
|
||||||
|
}
|
||||||
|
// TODO: OsFileList(this->path, pattern, PatchFiles::EnumPatchArchives, this, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 0) {
|
||||||
|
std::qsort(this->files.Ptr(), this->files.Count(), sizeof(char*), &PatchFiles::qsortpatchfiles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int PatchFiles::qsortpatchfiles(const void* a1, const void* a2) {
|
||||||
|
return -SStrCmpI(*((const char**) a1), *((const char**) a2), STORM_MAX_STR);
|
||||||
|
}
|
||||||
33
src/client/Patch.hpp
Normal file
33
src/client/Patch.hpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef CLIENT_PATCH_HPP
|
||||||
|
#define CLIENT_PATCH_HPP
|
||||||
|
|
||||||
|
|
||||||
|
#include <storm/Array.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
class PatchFiles {
|
||||||
|
public:
|
||||||
|
PatchFiles();
|
||||||
|
|
||||||
|
void SearchArchives(const char* locale, int32_t a3);
|
||||||
|
|
||||||
|
public:
|
||||||
|
char* path;
|
||||||
|
TSGrowableArray<char*> files;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static int qsortpatchfiles(const void* a1, const void* a2);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct ListEntry {
|
||||||
|
uint32_t num1;
|
||||||
|
uint32_t num2;
|
||||||
|
bool absolute;
|
||||||
|
const char* dataDir;
|
||||||
|
const char* pattern;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -8,8 +8,9 @@
|
|||||||
#include <bc/file/File.hpp>
|
#include <bc/file/File.hpp>
|
||||||
#include "util/Filesystem.hpp"
|
#include "util/Filesystem.hpp"
|
||||||
|
|
||||||
static char s_basepath[STORM_MAX_PATH] = {0};
|
static char s_basepath[STORM_MAX_PATH] = { 0 };
|
||||||
static char s_datapath[STORM_MAX_PATH] = {0};
|
static char s_datapath[STORM_MAX_PATH] = { 0 };
|
||||||
|
static char s_datapath2[STORM_MAX_PATH] = { 0 };
|
||||||
|
|
||||||
// TODO Proper implementation
|
// TODO Proper implementation
|
||||||
int32_t SFile::Close(SFile* file) {
|
int32_t SFile::Close(SFile* file) {
|
||||||
@ -279,3 +280,17 @@ int32_t SFile::GetDataPath(char* buffer, size_t bufferchars) {
|
|||||||
SStrCopy(buffer, s_datapath, bufferchars);
|
SStrCopy(buffer, s_datapath, bufferchars);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t SFile::SetDataPathAlternate(const char* path) {
|
||||||
|
SStrCopy(s_datapath2, path, STORM_MAX_PATH);
|
||||||
|
size_t length = SStrLen(s_datapath2);
|
||||||
|
if (length && s_datapath2[length - 1] != '\\' && s_datapath2[length - 1] != '/') {
|
||||||
|
SStrPack(s_datapath2, "\\", STORM_MAX_PATH);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t SFile::RebuildHash() {
|
||||||
|
// TODO
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|||||||
@ -39,6 +39,8 @@ class SFile {
|
|||||||
static int32_t SetDataPath(const char* path);
|
static int32_t SetDataPath(const char* path);
|
||||||
static int32_t GetBasePath(char* path, size_t capacity);
|
static int32_t GetBasePath(char* path, size_t capacity);
|
||||||
static int32_t GetDataPath(char* path, size_t capacity);
|
static int32_t GetDataPath(char* path, size_t capacity);
|
||||||
|
static int32_t SetDataPathAlternate(const char* path);
|
||||||
|
static int32_t RebuildHash();
|
||||||
|
|
||||||
// Member variables
|
// Member variables
|
||||||
SFILE_TYPE m_type;
|
SFILE_TYPE m_type;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user