1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Cache archive files

This commit is contained in:
nordsoft
2023-09-09 02:16:00 +02:00
parent 0db51e0517
commit 18c44fc006

View File

@@ -22,15 +22,15 @@
namespace namespace
{ {
QString detectModArchive(QString path, QString modName) QString detectModArchive(QString path, QString modName, std::vector<std::string> & filesToExtract)
{ {
auto files = ZipArchive::listFiles(qstringToPath(path)); filesToExtract = ZipArchive::listFiles(qstringToPath(path));
QString modDirName; QString modDirName;
for(int folderLevel : {0, 1}) //search in subfolder if there is no mod.json in the root for(int folderLevel : {0, 1}) //search in subfolder if there is no mod.json in the root
{ {
for(auto file : files) for(auto file : filesToExtract)
{ {
QString filename = QString::fromUtf8(file.c_str()); QString filename = QString::fromUtf8(file.c_str());
modDirName = filename.section('/', 0, folderLevel); modDirName = filename.section('/', 0, folderLevel);
@@ -275,11 +275,12 @@ bool CModManager::doInstallMod(QString modname, QString archivePath)
if(localMods.contains(modname)) if(localMods.contains(modname))
return addError(modname, "Mod with such name is already installed"); return addError(modname, "Mod with such name is already installed");
QString modDirName = ::detectModArchive(archivePath, modname); std::vector<std::string> filesToExtract;
QString modDirName = ::detectModArchive(archivePath, modname, filesToExtract);
if(!modDirName.size()) if(!modDirName.size())
return addError(modname, "Mod archive is invalid or corrupted"); return addError(modname, "Mod archive is invalid or corrupted");
if(!ZipArchive::extract(qstringToPath(archivePath), qstringToPath(destDir))) if(!ZipArchive::extract(qstringToPath(archivePath), qstringToPath(destDir), filesToExtract))
{ {
removeModDir(destDir + modDirName); removeModDir(destDir + modDirName);
return addError(modname, "Failed to extract mod data"); return addError(modname, "Failed to extract mod data");