Files
mtgodot-poc/extension/src/platform/PackBackend.cpp
T
shenleiandClaude Opus 5 5a26e93f07 port 2D step 5b: PackInitialize + pack:// asset_io backend over the ported EterPackManager
Platform UserInterface PackInitialize/PackSingletons (40250 bootstrap, on-disk dbname
resolution), EterBase/FileLoader.cpp mirror, mtpack40250 backend behind asset_io's
pack:// scheme and a Metin2Pack node. port_eterpack_test now registers through
PackInitialize. Nothing reads pack:// at runtime yet; port-map stays TODO.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-23 01:31:17 +09:00

61 lines
1.4 KiB
C++

#include "EterBase/StdAfx.h"
#include "EterBase/MappedFile.h"
#include "EterPack/EterPackManager.h"
#include "UserInterface/UserInterface.h"
#include "PackBackend.h"
#include <mutex>
#if defined(_WIN32)
#include <io.h> // _access; elsewhere the <windows.h> shim declares it
#endif
namespace mtpack40250 {
namespace {
std::mutex g_init_mutex;
bool g_initialized = false;
bool g_ready = false;
}
bool initialize(const std::string& client_dir)
{
std::lock_guard<std::mutex> lock(g_init_mutex);
if (g_initialized)
return g_ready;
const std::string folder = client_dir + "/pack";
if (_access((folder + "/Index").c_str(), 0) != 0)
return false; // nothing registered; a later call with the right directory may still succeed
g_initialized = true;
PackSingletons();
g_ready = PackInitialize(folder.c_str());
return g_ready;
}
bool ready()
{
std::lock_guard<std::mutex> lock(g_init_mutex);
return g_ready;
}
bool read(const std::string& name, std::vector<uint8_t>& out)
{
out.clear();
if (!ready())
return false;
CMappedFile file;
LPCVOID data = nullptr;
if (!CEterPackManager::Instance().Get(file, name.c_str(), &data))
return false;
const BYTE* bytes = static_cast<const BYTE*>(data);
out.assign(bytes, bytes + file.Size());
return true;
}
bool exists(const std::string& name)
{
return ready() && CEterPackManager::Instance().isExist(name.c_str());
}
} // namespace mtpack40250