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:
parent
b39e8dc1ef
commit
b0c66ae69b
@ -43,7 +43,7 @@ void CModListView::setupModModel()
|
|||||||
|
|
||||||
modStateModel = std::make_shared<ModStateModel>();
|
modStateModel = std::make_shared<ModStateModel>();
|
||||||
if (!cachedRepositoryData.isNull())
|
if (!cachedRepositoryData.isNull())
|
||||||
modStateModel->appendRepositories(cachedRepositoryData);
|
modStateModel->setRepositoryData(cachedRepositoryData);
|
||||||
|
|
||||||
modModel = new ModStateItemModel(modStateModel, this);
|
modModel = new ModStateItemModel(modStateModel, this);
|
||||||
manager = std::make_unique<ModStateController>(modStateModel);
|
manager = std::make_unique<ModStateController>(modStateModel);
|
||||||
@ -151,6 +151,8 @@ void CModListView::reload()
|
|||||||
|
|
||||||
void CModListView::loadRepositories()
|
void CModListView::loadRepositories()
|
||||||
{
|
{
|
||||||
|
accumulatedRepositoryData.clear();
|
||||||
|
|
||||||
QStringList repositories;
|
QStringList repositories;
|
||||||
|
|
||||||
if (settings["launcher"]["defaultRepositoryEnabled"].Bool())
|
if (settings["launcher"]["defaultRepositoryEnabled"].Bool())
|
||||||
@ -731,7 +733,7 @@ void CModListView::installFiles(QStringList files)
|
|||||||
QStringList maps;
|
QStringList maps;
|
||||||
QStringList images;
|
QStringList images;
|
||||||
QStringList exe;
|
QStringList exe;
|
||||||
JsonNode repository;
|
bool repositoryFilesEnqueued = false;
|
||||||
|
|
||||||
// TODO: some better way to separate zip's with mods and downloaded repository files
|
// TODO: some better way to separate zip's with mods and downloaded repository files
|
||||||
for(QString filename : files)
|
for(QString filename : files)
|
||||||
@ -754,9 +756,12 @@ void CModListView::installFiles(QStringList files)
|
|||||||
auto modNameLower = boost::algorithm::to_lower_copy(modName);
|
auto modNameLower = boost::algorithm::to_lower_copy(modName);
|
||||||
auto modJsonUrl = modJson["mod"];
|
auto modJsonUrl = modJson["mod"];
|
||||||
if(!modJsonUrl.isNull())
|
if(!modJsonUrl.isNull())
|
||||||
|
{
|
||||||
downloadFile(QString::fromStdString(modName + ".json"), QString::fromStdString(modJsonUrl.String()), tr("mods repository index"));
|
downloadFile(QString::fromStdString(modName + ".json"), QString::fromStdString(modJsonUrl.String()), tr("mods repository index"));
|
||||||
|
repositoryFilesEnqueued = true;
|
||||||
|
}
|
||||||
|
|
||||||
repository[modNameLower] = modJson;
|
accumulatedRepositoryData[modNameLower] = modJson;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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
|
// This is json of a single mod. Extract name of mod and add it to repo
|
||||||
auto modName = QFileInfo(filename).baseName().toStdString();
|
auto modName = QFileInfo(filename).baseName().toStdString();
|
||||||
auto modNameLower = boost::algorithm::to_lower_copy(modName);
|
auto modNameLower = boost::algorithm::to_lower_copy(modName);
|
||||||
repository[modNameLower] = repoData;
|
accumulatedRepositoryData[modNameLower] = repoData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(filename.endsWith(".png", Qt::CaseInsensitive))
|
else if(filename.endsWith(".png", Qt::CaseInsensitive))
|
||||||
images.push_back(filename);
|
images.push_back(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!repository.isNull())
|
if (!accumulatedRepositoryData.isNull() && !repositoryFilesEnqueued)
|
||||||
{
|
{
|
||||||
manager->appendRepositories(repository);
|
manager->setRepositoryData(accumulatedRepositoryData);
|
||||||
modModel->reloadRepositories();
|
modModel->reloadRepositories();
|
||||||
|
|
||||||
static const QString repositoryCachePath = CLauncherDirs::downloadsPath() + "/repositoryCache.json";
|
static const QString repositoryCachePath = CLauncherDirs::downloadsPath() + "/repositoryCache.json";
|
||||||
|
@ -36,6 +36,7 @@ class CModListView : public QWidget
|
|||||||
ModStateItemModel * modModel;
|
ModStateItemModel * modModel;
|
||||||
CModFilterModel * filterModel;
|
CModFilterModel * filterModel;
|
||||||
CDownloadManager * dlManager;
|
CDownloadManager * dlManager;
|
||||||
|
JsonNode accumulatedRepositoryData;
|
||||||
|
|
||||||
QStringList enqueuedModDownloads;
|
QStringList enqueuedModDownloads;
|
||||||
|
|
||||||
|
@ -72,9 +72,9 @@ ModStateController::ModStateController(std::shared_ptr<ModStateModel> modList)
|
|||||||
|
|
||||||
ModStateController::~ModStateController() = default;
|
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)
|
bool ModStateController::addError(QString modname, QString message)
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
ModStateController(std::shared_ptr<ModStateModel> modList);
|
ModStateController(std::shared_ptr<ModStateModel> modList);
|
||||||
~ModStateController();
|
~ModStateController();
|
||||||
|
|
||||||
void appendRepositories(const JsonNode & repositoriesList);
|
void setRepositoryData(const JsonNode & repositoriesList);
|
||||||
|
|
||||||
QStringList getErrors();
|
QStringList getErrors();
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include "modstatemodel.h"
|
#include "modstatemodel.h"
|
||||||
|
|
||||||
#include "../../lib/filesystem/Filesystem.h"
|
#include "../../lib/filesystem/Filesystem.h"
|
||||||
#include "../../lib/json/JsonUtils.h"
|
|
||||||
#include "../../lib/modding/ModManager.h"
|
#include "../../lib/modding/ModManager.h"
|
||||||
|
|
||||||
ModStateModel::ModStateModel()
|
ModStateModel::ModStateModel()
|
||||||
@ -22,10 +21,9 @@ ModStateModel::ModStateModel()
|
|||||||
|
|
||||||
ModStateModel::~ModStateModel() = default;
|
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);
|
modManager = std::make_unique<ModManager>(*repositoryData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ public:
|
|||||||
ModStateModel();
|
ModStateModel();
|
||||||
~ModStateModel();
|
~ModStateModel();
|
||||||
|
|
||||||
void appendRepositories(const JsonNode & repositoriesList);
|
void setRepositoryData(const JsonNode & repositoriesList);
|
||||||
void reloadLocalState();
|
void reloadLocalState();
|
||||||
const JsonNode & getRepositoryData() const;
|
const JsonNode & getRepositoryData() const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user