1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Completely erase old cache on mod repo checkout

This allows to remove any outdated data that might be present:
- mods removed from repository
- mods that came from no longer used repository
- fields that were removed from mod.json's
This commit is contained in:
Ivan Savenko 2024-12-13 17:24:48 +00:00
parent b39e8dc1ef
commit b0c66ae69b
6 changed files with 18 additions and 14 deletions

View File

@ -43,7 +43,7 @@ void CModListView::setupModModel()
modStateModel = std::make_shared<ModStateModel>();
if (!cachedRepositoryData.isNull())
modStateModel->appendRepositories(cachedRepositoryData);
modStateModel->setRepositoryData(cachedRepositoryData);
modModel = new ModStateItemModel(modStateModel, this);
manager = std::make_unique<ModStateController>(modStateModel);
@ -151,6 +151,8 @@ void CModListView::reload()
void CModListView::loadRepositories()
{
accumulatedRepositoryData.clear();
QStringList repositories;
if (settings["launcher"]["defaultRepositoryEnabled"].Bool())
@ -731,7 +733,7 @@ void CModListView::installFiles(QStringList files)
QStringList maps;
QStringList images;
QStringList exe;
JsonNode repository;
bool repositoryFilesEnqueued = false;
// TODO: some better way to separate zip's with mods and downloaded repository files
for(QString filename : files)
@ -754,9 +756,12 @@ void CModListView::installFiles(QStringList files)
auto modNameLower = boost::algorithm::to_lower_copy(modName);
auto modJsonUrl = modJson["mod"];
if(!modJsonUrl.isNull())
{
downloadFile(QString::fromStdString(modName + ".json"), QString::fromStdString(modJsonUrl.String()), tr("mods repository index"));
repositoryFilesEnqueued = true;
}
repository[modNameLower] = modJson;
accumulatedRepositoryData[modNameLower] = modJson;
}
}
else
@ -764,16 +769,16 @@ void CModListView::installFiles(QStringList files)
// This is json of a single mod. Extract name of mod and add it to repo
auto modName = QFileInfo(filename).baseName().toStdString();
auto modNameLower = boost::algorithm::to_lower_copy(modName);
repository[modNameLower] = repoData;
accumulatedRepositoryData[modNameLower] = repoData;
}
}
else if(filename.endsWith(".png", Qt::CaseInsensitive))
images.push_back(filename);
}
if (!repository.isNull())
if (!accumulatedRepositoryData.isNull() && !repositoryFilesEnqueued)
{
manager->appendRepositories(repository);
manager->setRepositoryData(accumulatedRepositoryData);
modModel->reloadRepositories();
static const QString repositoryCachePath = CLauncherDirs::downloadsPath() + "/repositoryCache.json";

View File

@ -36,6 +36,7 @@ class CModListView : public QWidget
ModStateItemModel * modModel;
CModFilterModel * filterModel;
CDownloadManager * dlManager;
JsonNode accumulatedRepositoryData;
QStringList enqueuedModDownloads;

View File

@ -72,9 +72,9 @@ ModStateController::ModStateController(std::shared_ptr<ModStateModel> modList)
ModStateController::~ModStateController() = default;
void ModStateController::appendRepositories(const JsonNode & repomap)
void ModStateController::setRepositoryData(const JsonNode & repomap)
{
modList->appendRepositories(repomap);
modList->setRepositoryData(repomap);
}
bool ModStateController::addError(QString modname, QString message)

View File

@ -37,7 +37,7 @@ public:
ModStateController(std::shared_ptr<ModStateModel> modList);
~ModStateController();
void appendRepositories(const JsonNode & repositoriesList);
void setRepositoryData(const JsonNode & repositoriesList);
QStringList getErrors();

View File

@ -11,7 +11,6 @@
#include "modstatemodel.h"
#include "../../lib/filesystem/Filesystem.h"
#include "../../lib/json/JsonUtils.h"
#include "../../lib/modding/ModManager.h"
ModStateModel::ModStateModel()
@ -22,10 +21,9 @@ ModStateModel::ModStateModel()
ModStateModel::~ModStateModel() = default;
void ModStateModel::appendRepositories(const JsonNode & repositoriesList)
void ModStateModel::setRepositoryData(const JsonNode & repositoriesList)
{
JsonUtils::mergeCopy(*repositoryData, repositoriesList);
*repositoryData = repositoriesList;
modManager = std::make_unique<ModManager>(*repositoryData);
}

View File

@ -27,7 +27,7 @@ public:
ModStateModel();
~ModStateModel();
void appendRepositories(const JsonNode & repositoriesList);
void setRepositoryData(const JsonNode & repositoriesList);
void reloadLocalState();
const JsonNode & getRepositoryData() const;