Add secure m2p loader with runtime key enforcement
Some checks failed
build / Windows Build (push) Has been cancelled
Some checks failed
build / Windows Build (push) Has been cancelled
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "PackManager.h"
|
||||
#include "EterLib/BufferPool.h"
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include "EterBase/Debug.h"
|
||||
|
||||
CPackManager::CPackManager()
|
||||
@@ -22,6 +23,25 @@ CPackManager::~CPackManager()
|
||||
|
||||
bool CPackManager::AddPack(const std::string& path)
|
||||
{
|
||||
const std::filesystem::path packPath(path);
|
||||
if (packPath.extension() == ".m2p")
|
||||
{
|
||||
std::shared_ptr<CM2Pack> pack = std::make_shared<CM2Pack>();
|
||||
if (!pack->Load(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
const auto& index = pack->GetIndex();
|
||||
for (const auto& entry : index)
|
||||
{
|
||||
m_m2_entries[entry.path] = std::make_pair(pack, entry);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<CPack> pack = std::make_shared<CPack>();
|
||||
|
||||
if (!pack->Load(path))
|
||||
@@ -51,6 +71,11 @@ bool CPackManager::GetFileWithPool(std::string_view path, TPackFile& result, CBu
|
||||
|
||||
// First try to load from pack
|
||||
if (m_load_from_pack) {
|
||||
auto m2it = m_m2_entries.find(buf);
|
||||
if (m2it != m_m2_entries.end()) {
|
||||
return m2it->second.first->GetFileWithPool(m2it->second.second, result, pPool);
|
||||
}
|
||||
|
||||
auto it = m_entries.find(buf);
|
||||
if (it != m_entries.end()) {
|
||||
return it->second.first->GetFileWithPool(it->second.second, result, pPool);
|
||||
@@ -86,6 +111,11 @@ bool CPackManager::IsExist(std::string_view path) const
|
||||
|
||||
// First check in pack entries
|
||||
if (m_load_from_pack) {
|
||||
auto m2it = m_m2_entries.find(buf);
|
||||
if (m2it != m_m2_entries.end()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto it = m_entries.find(buf);
|
||||
if (it != m_entries.end()) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user