mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-07-18 22:48:12 +00:00
refactor: extract LocalizationManager, ArchiveManager, SkinManager from Game
This commit is contained in:
128
targets/app/common/ArchiveManager.cpp
Normal file
128
targets/app/common/ArchiveManager.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "app/common/ArchiveManager.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "app/common/UI/All Platforms/ArchiveFile.h"
|
||||
#include "app/linux/LinuxGame.h"
|
||||
#include "java/File.h"
|
||||
#include "minecraft/client/Minecraft.h"
|
||||
#include "minecraft/client/skins/TexturePack.h"
|
||||
#include "minecraft/client/skins/TexturePackRepository.h"
|
||||
#include "platform/PlatformServices.h"
|
||||
#include "platform/PlatformTypes.h"
|
||||
|
||||
ArchiveManager::ArchiveManager()
|
||||
: m_mediaArchive(nullptr), m_dwRequiredTexturePackID(0) {}
|
||||
|
||||
void ArchiveManager::loadMediaArchive() {
|
||||
std::wstring mediapath = L"";
|
||||
|
||||
#if _WINDOWS64
|
||||
mediapath = L"Common\\Media\\MediaWindows64.arc";
|
||||
#elif __linux__
|
||||
mediapath = L"app/common/Media/MediaLinux.arc";
|
||||
#endif
|
||||
|
||||
if (!mediapath.empty()) {
|
||||
#if defined(__linux__)
|
||||
std::wstring exeDirW = PlatformFileIO.getBasePath().wstring();
|
||||
std::wstring candidate = exeDirW + File::pathSeparator + mediapath;
|
||||
if (File(candidate).exists()) {
|
||||
m_mediaArchive = new ArchiveFile(File(candidate));
|
||||
} else {
|
||||
m_mediaArchive = new ArchiveFile(File(mediapath));
|
||||
}
|
||||
#else
|
||||
m_mediaArchive = new ArchiveFile(File(mediapath));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int ArchiveManager::getArchiveFileSize(const std::wstring& filename) {
|
||||
TexturePack* tPack = nullptr;
|
||||
Minecraft* pMinecraft = Minecraft::GetInstance();
|
||||
if (pMinecraft && pMinecraft->skins)
|
||||
tPack = pMinecraft->skins->getSelected();
|
||||
if (tPack && tPack->hasData() && tPack->getArchiveFile() &&
|
||||
tPack->getArchiveFile()->hasFile(filename)) {
|
||||
return tPack->getArchiveFile()->getFileSize(filename);
|
||||
} else
|
||||
return m_mediaArchive->getFileSize(filename);
|
||||
}
|
||||
|
||||
bool ArchiveManager::hasArchiveFile(const std::wstring& filename) {
|
||||
TexturePack* tPack = nullptr;
|
||||
Minecraft* pMinecraft = Minecraft::GetInstance();
|
||||
if (pMinecraft && pMinecraft->skins)
|
||||
tPack = pMinecraft->skins->getSelected();
|
||||
if (tPack && tPack->hasData() && tPack->getArchiveFile() &&
|
||||
tPack->getArchiveFile()->hasFile(filename))
|
||||
return true;
|
||||
else
|
||||
return m_mediaArchive->hasFile(filename);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> ArchiveManager::getArchiveFile(
|
||||
const std::wstring& filename) {
|
||||
TexturePack* tPack = nullptr;
|
||||
Minecraft* pMinecraft = Minecraft::GetInstance();
|
||||
if (pMinecraft && pMinecraft->skins)
|
||||
tPack = pMinecraft->skins->getSelected();
|
||||
if (tPack && tPack->hasData() && tPack->getArchiveFile() &&
|
||||
tPack->getArchiveFile()->hasFile(filename)) {
|
||||
return tPack->getArchiveFile()->getFile(filename);
|
||||
} else
|
||||
return m_mediaArchive->getFile(filename);
|
||||
}
|
||||
|
||||
void ArchiveManager::addMemoryTPDFile(int iConfig, std::uint8_t* pbData,
|
||||
unsigned int byteCount) {
|
||||
std::lock_guard<std::mutex> lock(csMemTPDLock);
|
||||
PMEMDATA pData = nullptr;
|
||||
auto it = m_MEM_TPD.find(iConfig);
|
||||
if (it == m_MEM_TPD.end()) {
|
||||
pData = new MEMDATA();
|
||||
pData->pbData = pbData;
|
||||
pData->byteCount = byteCount;
|
||||
pData->ucRefCount = 1;
|
||||
|
||||
m_MEM_TPD[iConfig] = pData;
|
||||
}
|
||||
}
|
||||
|
||||
void ArchiveManager::removeMemoryTPDFile(int iConfig) {
|
||||
std::lock_guard<std::mutex> lock(csMemTPDLock);
|
||||
PMEMDATA pData = nullptr;
|
||||
auto it = m_MEM_TPD.find(iConfig);
|
||||
if (it != m_MEM_TPD.end()) {
|
||||
pData = m_MEM_TPD[iConfig];
|
||||
delete pData;
|
||||
m_MEM_TPD.erase(iConfig);
|
||||
}
|
||||
}
|
||||
|
||||
int ArchiveManager::getTPConfigVal(wchar_t* pwchDataFile) { return -1; }
|
||||
|
||||
bool ArchiveManager::isFileInTPD(int iConfig) {
|
||||
bool val = false;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(csMemTPDLock);
|
||||
auto it = m_MEM_TPD.find(iConfig);
|
||||
if (it != m_MEM_TPD.end()) val = true;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void ArchiveManager::getTPD(int iConfig, std::uint8_t** ppbData,
|
||||
unsigned int* pByteCount) {
|
||||
std::lock_guard<std::mutex> lock(csMemTPDLock);
|
||||
auto it = m_MEM_TPD.find(iConfig);
|
||||
if (it != m_MEM_TPD.end()) {
|
||||
PMEMDATA pData = (*it).second;
|
||||
*ppbData = pData->pbData;
|
||||
*pByteCount = pData->byteCount;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user