#include "EterBase/StdAfx.h" #include "EterBase/MappedFile.h" #include "EterPack/EterPackManager.h" #include "UserInterface/UserInterface.h" #include "PackBackend.h" #include #if defined(_WIN32) #include // _access; elsewhere the 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 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 lock(g_init_mutex); return g_ready; } bool read(const std::string& name, std::vector& 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(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