Improved pack initialization algorithm, archive types are now configurable in the Index file.

This commit is contained in:
2025-04-12 07:00:29 +03:00
parent c21c99393d
commit 830e47b00b
6 changed files with 279 additions and 303 deletions

View File

@ -183,10 +183,22 @@ bool CEterPackManager::isExist(const char * c_szFileName)
return isExistInPack(c_szFileName);
}
bool CEterPackManager::RegisterPack(const char * c_szName, const char * c_szDirectory, const BYTE* c_pbIV)
bool CEterPackManager::PackExists(const std::string& name, const std::string& container)
{
auto it = m_PackMap.find(c_szName);
if (container == "FOLDER") {
return _access(name.c_str(), 0) == 0;
}
else if (container == "ZIP") {
std::string zipName = name + ".zip";
return _access(zipName.c_str(), 0) == 0;
}
throw std::runtime_error("Unexpected container type: " + container + "!");
}
bool CEterPackManager::RegisterPack(const std::string& name, const std::string& container)
{
auto it = m_PackMap.find(name);
if (it != m_PackMap.end())
return true;
@ -196,24 +208,28 @@ bool CEterPackManager::RegisterPack(const char * c_szName, const char * c_szDire
std::shared_ptr<FileProvider> pack;
// TODO: allow configurable containers
//pack = std::make_shared<Folder>(c_szName);
pack = std::make_shared<ZIP>(std::string(c_szName) + ".zip");
// Determine requested container type
if (container == "FOLDER")
pack = std::make_shared<Folder>(name);
else if (container == "ZIP")
pack = std::make_shared<ZIP>(name + ".zip");
else
throw std::runtime_error("Unexpected container type: " + container + "!");
// Load container data
auto packFiles = pack->listFiles();
for (auto const& fileName : packFiles)
m_FileMap.insert({ fileName, pack });
m_PackMap.insert({ c_szName, pack });
m_PackMap.insert({ name, pack });
return true;
}
catch (std::exception& e)
{
#ifdef _DEBUG
Tracef("Unable to load file provider '%s': %s\n", c_szName, e.what());
Tracef("Unable to load file provider '%s': %s\n", name.c_str(), e.what());
#endif
return false;