2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* cmodlistview_moc.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2013-08-22 17:22:49 +03:00
|
|
|
#include "StdInc.h"
|
2013-08-24 23:11:51 +03:00
|
|
|
#include "cmodlistview_moc.h"
|
|
|
|
#include "ui_cmodlistview_moc.h"
|
2014-03-29 15:46:41 +03:00
|
|
|
#include "imageviewer_moc.h"
|
2019-07-30 09:28:42 +02:00
|
|
|
#include "../mainwindow_moc.h"
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QCryptographicHash>
|
2022-05-28 15:32:20 +02:00
|
|
|
#include <QRegularExpression>
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2013-08-24 23:11:51 +03:00
|
|
|
#include "cmodlistmodel_moc.h"
|
2013-08-22 17:22:49 +03:00
|
|
|
#include "cmodmanager.h"
|
2013-08-24 23:11:51 +03:00
|
|
|
#include "cdownloadmanager_moc.h"
|
2013-09-02 20:26:52 +03:00
|
|
|
#include "../launcherdirs.h"
|
2022-09-29 15:38:03 +02:00
|
|
|
#include "../jsonutils.h"
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2013-09-02 20:26:52 +03:00
|
|
|
#include "../../lib/CConfigHandler.h"
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
void CModListView::setupModModel()
|
|
|
|
{
|
2018-04-28 10:56:01 +02:00
|
|
|
modModel = new CModListModel(this);
|
2022-12-07 23:36:20 +02:00
|
|
|
manager = std::make_unique<CModManager>(modModel);
|
2022-09-27 10:51:49 +02:00
|
|
|
|
|
|
|
connect(manager.get(), &CModManager::extraResolutionsEnabledChanged,
|
|
|
|
this, &CModListView::extraResolutionsEnabledChanged);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2022-12-25 13:19:16 +02:00
|
|
|
void CModListView::changeEvent(QEvent *event)
|
|
|
|
{
|
2022-12-29 16:37:38 +02:00
|
|
|
if(event->type() == QEvent::LanguageChange)
|
2022-12-25 13:19:16 +02:00
|
|
|
{
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
modModel->reloadRepositories();
|
|
|
|
}
|
2022-12-28 17:58:39 +02:00
|
|
|
QWidget::changeEvent(event);
|
2022-12-25 13:19:16 +02:00
|
|
|
}
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
void CModListView::setupFilterModel()
|
|
|
|
{
|
2018-04-28 10:56:01 +02:00
|
|
|
filterModel = new CModFilterModel(modModel, this);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
filterModel->setFilterKeyColumn(-1); // filter across all columns
|
|
|
|
filterModel->setSortCaseSensitivity(Qt::CaseInsensitive); // to make it more user-friendly
|
2014-03-20 20:06:25 +03:00
|
|
|
filterModel->setDynamicSortFilter(true);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::setupModsView()
|
|
|
|
{
|
|
|
|
ui->allModsView->setModel(filterModel);
|
|
|
|
// input data is not sorted - sort it before display
|
|
|
|
ui->allModsView->sortByColumn(ModFields::TYPE, Qt::AscendingOrder);
|
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
ui->allModsView->header()->setSectionResizeMode(ModFields::STATUS_ENABLED, QHeaderView::Fixed);
|
2018-04-13 07:34:58 +02:00
|
|
|
ui->allModsView->header()->setSectionResizeMode(ModFields::STATUS_UPDATE, QHeaderView::Fixed);
|
2014-03-20 20:06:25 +03:00
|
|
|
|
2019-07-30 09:28:42 +02:00
|
|
|
QSettings s(Ui::teamName, Ui::appName);
|
|
|
|
auto state = s.value("AllModsView/State").toByteArray();
|
2019-07-30 11:00:44 +02:00
|
|
|
if(!state.isNull()) //read last saved settings
|
2019-07-30 09:28:42 +02:00
|
|
|
{
|
|
|
|
ui->allModsView->header()->restoreState(state);
|
|
|
|
}
|
|
|
|
else //default //TODO: default high-DPI scaling
|
|
|
|
{
|
|
|
|
ui->allModsView->setColumnWidth(ModFields::NAME, 185);
|
|
|
|
ui->allModsView->setColumnWidth(ModFields::TYPE, 75);
|
|
|
|
ui->allModsView->setColumnWidth(ModFields::VERSION, 60);
|
|
|
|
}
|
2023-01-28 01:04:41 +02:00
|
|
|
ui->allModsView->setColumnWidth(ModFields::STATUS_ENABLED, 24);
|
|
|
|
ui->allModsView->setColumnWidth(ModFields::STATUS_UPDATE, 24);
|
2019-07-30 09:28:42 +02:00
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
ui->allModsView->setUniformRowHeights(true);
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
connect(ui->allModsView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex&,const QModelIndex&)),
|
|
|
|
this, SLOT(modSelected(const QModelIndex&,const QModelIndex&)));
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
connect(filterModel, SIGNAL(modelReset()),
|
|
|
|
this, SLOT(modelReset()));
|
2013-08-24 23:11:51 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
connect(modModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
|
|
this, SLOT(dataChanged(QModelIndex,QModelIndex)));
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
CModListView::CModListView(QWidget * parent)
|
|
|
|
: QWidget(parent), settingsListener(settings.listen["launcher"]["repositoryURL"]), ui(new Ui::CModListView)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2013-08-24 23:11:51 +03:00
|
|
|
settingsListener([&](const JsonNode &){ repositoriesChanged = true; });
|
2013-08-22 17:22:49 +03:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
2019-07-30 09:28:42 +02:00
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
setupModModel();
|
|
|
|
setupFilterModel();
|
|
|
|
setupModsView();
|
|
|
|
|
|
|
|
ui->progressWidget->setVisible(false);
|
|
|
|
dlManager = nullptr;
|
2023-03-11 00:57:55 +02:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(settings["launcher"]["autoCheckRepositories"].Bool())
|
2014-11-03 17:47:37 +02:00
|
|
|
{
|
|
|
|
loadRepositories();
|
|
|
|
}
|
2016-08-30 22:16:52 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
manager->resetRepositories();
|
|
|
|
}
|
2022-11-22 01:36:27 +02:00
|
|
|
|
|
|
|
#ifdef Q_OS_IOS
|
|
|
|
for(auto * scrollWidget : {
|
|
|
|
(QAbstractItemView*)ui->allModsView,
|
|
|
|
(QAbstractItemView*)ui->screenshotsList})
|
|
|
|
{
|
|
|
|
QScroller::grabGesture(scrollWidget, QScroller::LeftMouseButtonGesture);
|
|
|
|
scrollWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
|
|
|
scrollWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
}
|
|
|
|
#endif
|
2013-08-24 23:11:51 +03:00
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2013-08-24 23:11:51 +03:00
|
|
|
void CModListView::loadRepositories()
|
|
|
|
{
|
|
|
|
manager->resetRepositories();
|
2018-04-13 07:34:58 +02:00
|
|
|
for(auto entry : settings["launcher"]["repositoryURL"].Vector())
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
QString str = QString::fromUtf8(entry.String().c_str());
|
|
|
|
|
|
|
|
// URL must be encoded to something else to get rid of symbols illegal in file names
|
|
|
|
auto hashed = QCryptographicHash::hash(str.toUtf8(), QCryptographicHash::Md5);
|
|
|
|
auto hashedStr = QString::fromUtf8(hashed.toHex());
|
|
|
|
|
|
|
|
downloadFile(hashedStr + ".json", str, "repository index");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CModListView::~CModListView()
|
|
|
|
{
|
2019-07-30 09:28:42 +02:00
|
|
|
QSettings s(Ui::teamName, Ui::appName);
|
|
|
|
s.setValue("AllModsView/State", ui->allModsView->header()->saveState());
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2013-08-24 23:11:51 +03:00
|
|
|
void CModListView::showEvent(QShowEvent * event)
|
|
|
|
{
|
|
|
|
QWidget::showEvent(event);
|
2018-04-13 07:34:58 +02:00
|
|
|
if(repositoriesChanged)
|
2013-08-24 23:11:51 +03:00
|
|
|
{
|
|
|
|
repositoriesChanged = false;
|
2018-04-13 07:34:58 +02:00
|
|
|
if(settings["launcher"]["autoCheckRepositories"].Bool())
|
2014-11-03 17:47:37 +02:00
|
|
|
{
|
|
|
|
loadRepositories();
|
|
|
|
}
|
2013-08-24 23:11:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
static QString replaceIfNotEmpty(QVariant value, QString pattern)
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(value.canConvert<QStringList>())
|
2013-08-22 17:22:49 +03:00
|
|
|
return pattern.arg(value.toStringList().join(", "));
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(value.canConvert<QString>())
|
2013-08-22 17:22:49 +03:00
|
|
|
return pattern.arg(value.toString());
|
|
|
|
|
|
|
|
// all valid types of data should have been filtered by code above
|
|
|
|
assert(!value.isValid());
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString replaceIfNotEmpty(QStringList value, QString pattern)
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!value.empty())
|
2013-08-22 17:22:49 +03:00
|
|
|
return pattern.arg(value.join(", "));
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
QString CModListView::genChangelogText(CModEntry & mod)
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
QString headerTemplate = "<p><span style=\" font-weight:600;\">%1: </span></p>";
|
|
|
|
QString entryBegin = "<p align=\"justify\"><ul>";
|
|
|
|
QString entryEnd = "</ul></p>";
|
|
|
|
QString entryLine = "<li>%1</li>";
|
|
|
|
//QString versionSeparator = "<hr/>";
|
|
|
|
|
|
|
|
QString result;
|
|
|
|
|
|
|
|
QVariantMap changelog = mod.getValue("changelog").toMap();
|
|
|
|
QList<QString> versions = changelog.keys();
|
|
|
|
|
|
|
|
std::sort(versions.begin(), versions.end(), [](QString lesser, QString greater)
|
|
|
|
{
|
|
|
|
return !CModEntry::compareVersions(lesser, greater);
|
|
|
|
});
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(auto & version : versions)
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
result += headerTemplate.arg(version);
|
|
|
|
result += entryBegin;
|
2018-04-13 07:34:58 +02:00
|
|
|
for(auto & line : changelog.value(version).toStringList())
|
2014-03-23 15:08:01 +03:00
|
|
|
result += entryLine.arg(line);
|
|
|
|
result += entryEnd;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
QString CModListView::genModInfoText(CModEntry & mod)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
QString prefix = "<p><span style=\" font-weight:600;\">%1: </span>"; // shared prefix
|
2022-09-29 16:21:29 +02:00
|
|
|
QString redPrefix = "<p><span style=\" font-weight:600; color:red\">%1: </span>"; // shared prefix
|
2013-08-22 17:22:49 +03:00
|
|
|
QString lineTemplate = prefix + "%2</p>";
|
2018-04-13 07:34:58 +02:00
|
|
|
QString urlTemplate = prefix + "<a href=\"%2\">%3</a></p>";
|
2013-08-22 17:22:49 +03:00
|
|
|
QString textTemplate = prefix + "</p><p align=\"justify\">%2</p>";
|
2014-03-20 20:06:25 +03:00
|
|
|
QString listTemplate = "<p align=\"justify\">%1: %2</p>";
|
|
|
|
QString noteTemplate = "<p align=\"justify\">%1</p>";
|
2022-12-25 13:19:16 +02:00
|
|
|
QString compatibleString = prefix + tr("Mod is compatible") + "</p>";
|
|
|
|
QString incompatibleString = redPrefix + tr("Mod is incompatible") + "</p>";
|
2022-09-29 16:21:29 +02:00
|
|
|
QString supportedVersions = redPrefix + "%2 %3 %4</p>";
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
QString result;
|
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
result += replaceIfNotEmpty(mod.getValue("name"), lineTemplate.arg(tr("Mod name")));
|
|
|
|
result += replaceIfNotEmpty(mod.getValue("installedVersion"), lineTemplate.arg(tr("Installed version")));
|
|
|
|
result += replaceIfNotEmpty(mod.getValue("latestVersion"), lineTemplate.arg(tr("Latest version")));
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(mod.getValue("size").isValid())
|
2014-03-20 20:06:25 +03:00
|
|
|
result += replaceIfNotEmpty(CModEntry::sizeToString(mod.getValue("size").toDouble()), lineTemplate.arg(tr("Download size")));
|
|
|
|
result += replaceIfNotEmpty(mod.getValue("author"), lineTemplate.arg(tr("Authors")));
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(mod.getValue("licenseURL").isValid())
|
2014-03-23 15:08:01 +03:00
|
|
|
result += urlTemplate.arg(tr("License")).arg(mod.getValue("licenseURL").toString()).arg(mod.getValue("licenseName").toString());
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(mod.getValue("contact").isValid())
|
2023-01-26 01:01:41 +02:00
|
|
|
result += urlTemplate.arg(tr("Contact")).arg(mod.getValue("contact").toString()).arg(mod.getValue("contact").toString());
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2022-09-29 16:21:29 +02:00
|
|
|
//compatibility info
|
|
|
|
if(mod.isCompatible())
|
|
|
|
result += compatibleString.arg(tr("Compatibility"));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto compatibilityInfo = mod.getValue("compatibility").toMap();
|
|
|
|
auto minStr = compatibilityInfo.value("min").toString();
|
|
|
|
auto maxStr = compatibilityInfo.value("max").toString();
|
|
|
|
|
|
|
|
result += incompatibleString.arg(tr("Compatibility"));
|
|
|
|
if(minStr == maxStr)
|
|
|
|
result += supportedVersions.arg(tr("Required VCMI version"), minStr, "", "");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(minStr.isEmpty() || maxStr.isEmpty())
|
|
|
|
{
|
|
|
|
if(minStr.isEmpty())
|
|
|
|
result += supportedVersions.arg(tr("Supported VCMI version"), maxStr, ", ", "please upgrade mod");
|
|
|
|
else
|
|
|
|
result += supportedVersions.arg(tr("Required VCMI version"), minStr, " ", "or above");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result += supportedVersions.arg(tr("Supported VCMI versions"), minStr, " - ", maxStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
result += replaceIfNotEmpty(mod.getValue("depends"), lineTemplate.arg(tr("Required mods")));
|
|
|
|
result += replaceIfNotEmpty(mod.getValue("conflicts"), lineTemplate.arg(tr("Conflicting mods")));
|
|
|
|
result += replaceIfNotEmpty(mod.getValue("description"), textTemplate.arg(tr("Description")));
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
result += "<p></p>"; // to get some empty space
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
QString unknownDeps = tr("This mod can not be installed or enabled because following dependencies are not present");
|
2014-03-20 20:06:25 +03:00
|
|
|
QString blockingMods = tr("This mod can not be enabled because following mods are incompatible with this mod");
|
|
|
|
QString hasActiveDependentMods = tr("This mod can not be disabled because it is required to run following mods");
|
|
|
|
QString hasDependentMods = tr("This mod can not be uninstalled or updated because it is required to run following mods");
|
|
|
|
QString thisIsSubmod = tr("This is submod and it can not be installed or uninstalled separately from parent mod");
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
QString notes;
|
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
notes += replaceIfNotEmpty(findInvalidDependencies(mod.getName()), listTemplate.arg(unknownDeps));
|
|
|
|
notes += replaceIfNotEmpty(findBlockingMods(mod.getName()), listTemplate.arg(blockingMods));
|
2018-04-13 07:34:58 +02:00
|
|
|
if(mod.isEnabled())
|
2014-03-20 20:06:25 +03:00
|
|
|
notes += replaceIfNotEmpty(findDependentMods(mod.getName(), true), listTemplate.arg(hasActiveDependentMods));
|
2018-04-13 07:34:58 +02:00
|
|
|
if(mod.isInstalled())
|
2014-03-20 20:06:25 +03:00
|
|
|
notes += replaceIfNotEmpty(findDependentMods(mod.getName(), false), listTemplate.arg(hasDependentMods));
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(mod.getName().contains('.'))
|
2014-03-20 20:06:25 +03:00
|
|
|
notes += noteTemplate.arg(thisIsSubmod);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(notes.size())
|
2014-03-20 20:06:25 +03:00
|
|
|
result += textTemplate.arg(tr("Notes")).arg(notes);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::disableModInfo()
|
|
|
|
{
|
2014-08-04 14:03:57 +03:00
|
|
|
ui->disableButton->setVisible(false);
|
|
|
|
ui->enableButton->setVisible(false);
|
|
|
|
ui->installButton->setVisible(false);
|
|
|
|
ui->uninstallButton->setVisible(false);
|
|
|
|
ui->updateButton->setVisible(false);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
void CModListView::dataChanged(const QModelIndex & topleft, const QModelIndex & bottomRight)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
selectMod(ui->allModsView->currentIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::selectMod(const QModelIndex & index)
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!index.isValid())
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
disableModInfo();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
auto mod = modModel->getMod(index.data(ModRoles::ModNameRole).toString());
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2014-03-23 15:08:01 +03:00
|
|
|
ui->modInfoBrowser->setHtml(genModInfoText(mod));
|
|
|
|
ui->changelogBrowser->setHtml(genChangelogText(mod));
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2014-03-20 20:06:25 +03:00
|
|
|
bool hasInvalidDeps = !findInvalidDependencies(index.data(ModRoles::ModNameRole).toString()).empty();
|
|
|
|
bool hasBlockingMods = !findBlockingMods(index.data(ModRoles::ModNameRole).toString()).empty();
|
|
|
|
bool hasDependentMods = !findDependentMods(index.data(ModRoles::ModNameRole).toString(), true).empty();
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
ui->disableButton->setVisible(mod.isEnabled());
|
|
|
|
ui->enableButton->setVisible(mod.isDisabled());
|
2014-03-20 20:06:25 +03:00
|
|
|
ui->installButton->setVisible(mod.isAvailable() && !mod.getName().contains('.'));
|
|
|
|
ui->uninstallButton->setVisible(mod.isInstalled() && !mod.getName().contains('.'));
|
2013-08-22 17:22:49 +03:00
|
|
|
ui->updateButton->setVisible(mod.isUpdateable());
|
|
|
|
|
|
|
|
// Block buttons if action is not allowed at this time
|
|
|
|
// TODO: automate handling of some of these cases instead of forcing player
|
|
|
|
// to resolve all conflicts manually.
|
2022-09-10 18:30:41 +02:00
|
|
|
ui->disableButton->setEnabled(!hasDependentMods && !mod.isEssential());
|
2013-08-22 17:22:49 +03:00
|
|
|
ui->enableButton->setEnabled(!hasBlockingMods && !hasInvalidDeps);
|
|
|
|
ui->installButton->setEnabled(!hasInvalidDeps);
|
2022-09-10 18:30:41 +02:00
|
|
|
ui->uninstallButton->setEnabled(!hasDependentMods && !mod.isEssential());
|
2013-08-22 17:22:49 +03:00
|
|
|
ui->updateButton->setEnabled(!hasInvalidDeps && !hasDependentMods);
|
2014-03-23 15:08:01 +03:00
|
|
|
|
|
|
|
loadScreenshots();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-27 10:51:49 +02:00
|
|
|
bool CModListView::isExtraResolutionsModEnabled() const
|
|
|
|
{
|
|
|
|
return manager->isExtraResolutionsModEnabled();
|
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
void CModListView::modSelected(const QModelIndex & current, const QModelIndex &)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
selectMod(current);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
void CModListView::on_allModsView_activated(const QModelIndex & index)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
selectMod(index);
|
2023-01-26 01:01:41 +02:00
|
|
|
loadScreenshots();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
void CModListView::on_lineEdit_textChanged(const QString & arg1)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2022-05-28 15:32:20 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
auto baseStr = QRegularExpression::wildcardToRegularExpression(arg1, QRegularExpression::UnanchoredWildcardConversion);
|
|
|
|
#else
|
|
|
|
auto baseStr = QRegularExpression::wildcardToRegularExpression(arg1);
|
|
|
|
//Hack due to lack QRegularExpression::UnanchoredWildcardConversion in Qt5
|
|
|
|
baseStr.chop(3);
|
|
|
|
baseStr.remove(0,5);
|
|
|
|
#endif
|
|
|
|
QRegularExpression regExp{baseStr, QRegularExpression::CaseInsensitiveOption};
|
|
|
|
filterModel->setFilterRegularExpression(regExp);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::on_comboBox_currentIndexChanged(int index)
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
switch(index)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
case 0:
|
|
|
|
filterModel->setTypeFilter(ModStatus::MASK_NONE, ModStatus::MASK_NONE);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
filterModel->setTypeFilter(ModStatus::MASK_NONE, ModStatus::INSTALLED);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
filterModel->setTypeFilter(ModStatus::INSTALLED, ModStatus::INSTALLED);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
filterModel->setTypeFilter(ModStatus::UPDATEABLE, ModStatus::UPDATEABLE);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
filterModel->setTypeFilter(ModStatus::ENABLED | ModStatus::INSTALLED, ModStatus::ENABLED | ModStatus::INSTALLED);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
filterModel->setTypeFilter(ModStatus::INSTALLED, ModStatus::ENABLED | ModStatus::INSTALLED);
|
|
|
|
break;
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList CModListView::findInvalidDependencies(QString mod)
|
|
|
|
{
|
|
|
|
QStringList ret;
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString requrement : modModel->getRequirements(mod))
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!modModel->hasMod(requrement))
|
2013-08-22 17:22:49 +03:00
|
|
|
ret += requrement;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-29 17:56:14 +02:00
|
|
|
QStringList CModListView::findBlockingMods(QString modUnderTest)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
QStringList ret;
|
2018-10-29 17:56:14 +02:00
|
|
|
auto required = modModel->getRequirements(modUnderTest);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString name : modModel->getModList())
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
auto mod = modModel->getMod(name);
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(mod.isEnabled())
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
// one of enabled mods have requirement (or this mod) marked as conflict
|
2018-04-13 07:34:58 +02:00
|
|
|
for(auto conflict : mod.getValue("conflicts").toStringList())
|
|
|
|
{
|
|
|
|
if(required.contains(conflict))
|
2013-08-22 17:22:49 +03:00
|
|
|
ret.push_back(name);
|
2018-04-13 07:34:58 +02:00
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList CModListView::findDependentMods(QString mod, bool excludeDisabled)
|
|
|
|
{
|
|
|
|
QStringList ret;
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString modName : modModel->getModList())
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
auto current = modModel->getMod(modName);
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!current.isInstalled())
|
2013-09-08 16:02:34 +03:00
|
|
|
continue;
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(current.getValue("depends").toStringList().contains(mod))
|
|
|
|
{
|
|
|
|
if(!(current.isDisabled() && excludeDisabled))
|
|
|
|
ret += modName;
|
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::on_enableButton_clicked()
|
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
2022-12-26 02:34:10 +02:00
|
|
|
|
|
|
|
enableModByName(modName);
|
|
|
|
|
|
|
|
checkManagerErrors();
|
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2022-12-26 02:34:10 +02:00
|
|
|
void CModListView::enableModByName(QString modName)
|
|
|
|
{
|
2013-08-22 17:22:49 +03:00
|
|
|
assert(findBlockingMods(modName).empty());
|
|
|
|
assert(findInvalidDependencies(modName).empty());
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(auto & name : modModel->getRequirements(modName))
|
|
|
|
{
|
|
|
|
if(modModel->getMod(name).isDisabled())
|
2013-08-22 17:22:49 +03:00
|
|
|
manager->enableMod(name);
|
2018-04-13 07:34:58 +02:00
|
|
|
}
|
2022-12-26 02:34:10 +02:00
|
|
|
emit modsChanged();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::on_disableButton_clicked()
|
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2022-12-26 02:34:10 +02:00
|
|
|
disableModByName(modName);
|
|
|
|
|
|
|
|
checkManagerErrors();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::disableModByName(QString modName)
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(modModel->hasMod(modName) && modModel->getMod(modName).isEnabled())
|
|
|
|
manager->disableMod(modName);
|
2013-09-08 21:35:09 +03:00
|
|
|
|
2022-12-26 02:34:10 +02:00
|
|
|
emit modsChanged();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::on_updateButton_clicked()
|
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
assert(findInvalidDependencies(modName).empty());
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(auto & name : modModel->getRequirements(modName))
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
auto mod = modModel->getMod(name);
|
|
|
|
// update required mod, install missing (can be new dependency)
|
2018-04-13 07:34:58 +02:00
|
|
|
if(mod.isUpdateable() || !mod.isInstalled())
|
2013-08-22 17:22:49 +03:00
|
|
|
downloadFile(name + ".zip", mod.getValue("download").toString(), "mods");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::on_uninstallButton_clicked()
|
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
2013-08-22 17:22:49 +03:00
|
|
|
// NOTE: perhaps add "manually installed" flag and uninstall those dependencies that don't have it?
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(modModel->hasMod(modName) && modModel->getMod(modName).isInstalled())
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(modModel->getMod(modName).isEnabled())
|
2013-11-14 16:21:09 +03:00
|
|
|
manager->disableMod(modName);
|
2013-08-22 17:22:49 +03:00
|
|
|
manager->uninstallMod(modName);
|
|
|
|
}
|
2022-12-26 02:34:10 +02:00
|
|
|
|
|
|
|
emit modsChanged();
|
2013-09-06 00:25:03 +03:00
|
|
|
checkManagerErrors();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::on_installButton_clicked()
|
|
|
|
{
|
2014-03-20 20:06:25 +03:00
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
assert(findInvalidDependencies(modName).empty());
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(auto & name : modModel->getRequirements(modName))
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
auto mod = modModel->getMod(name);
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!mod.isInstalled())
|
2013-08-22 17:22:49 +03:00
|
|
|
downloadFile(name + ".zip", mod.getValue("download").toString(), "mods");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::downloadFile(QString file, QString url, QString description)
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!dlManager)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
dlManager = new CDownloadManager();
|
|
|
|
ui->progressWidget->setVisible(true);
|
|
|
|
connect(dlManager, SIGNAL(downloadProgress(qint64,qint64)),
|
2018-04-13 07:34:58 +02:00
|
|
|
this, SLOT(downloadProgress(qint64,qint64)));
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
connect(dlManager, SIGNAL(finished(QStringList,QStringList,QStringList)),
|
2018-04-13 07:34:58 +02:00
|
|
|
this, SLOT(downloadFinished(QStringList,QStringList,QStringList)));
|
2022-09-10 18:30:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
connect(modModel, &CModListModel::dataChanged, filterModel, &QAbstractItemModel::dataChanged);
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
QString progressBarFormat = "Downloading %s%. %p% (%v KB out of %m KB) finished";
|
|
|
|
|
|
|
|
progressBarFormat.replace("%s%", description);
|
|
|
|
ui->progressBar->setFormat(progressBarFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
dlManager->downloadFile(QUrl(url), file);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::downloadProgress(qint64 current, qint64 max)
|
|
|
|
{
|
|
|
|
// display progress, in kilobytes
|
2018-04-13 07:34:58 +02:00
|
|
|
ui->progressBar->setValue(current / 1024);
|
|
|
|
ui->progressBar->setMaximum(max / 1024);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::downloadFinished(QStringList savedFiles, QStringList failedFiles, QStringList errors)
|
|
|
|
{
|
|
|
|
QString title = "Download failed";
|
|
|
|
QString firstLine = "Unable to download all files.\n\nEncountered errors:\n\n";
|
|
|
|
QString lastLine = "\n\nInstall successfully downloaded?";
|
2022-09-29 15:38:03 +02:00
|
|
|
bool doInstallFiles = false;
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
// if all files were d/loaded there should be no errors. And on failure there must be an error
|
|
|
|
assert(failedFiles.empty() == errors.empty());
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(savedFiles.empty())
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
// no successfully downloaded mods
|
2018-04-13 07:34:58 +02:00
|
|
|
QMessageBox::warning(this, title, firstLine + errors.join("\n"), QMessageBox::Ok, QMessageBox::Ok);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
2018-04-13 07:34:58 +02:00
|
|
|
else if(!failedFiles.empty())
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
// some mods were not downloaded
|
|
|
|
int result = QMessageBox::warning (this, title, firstLine + errors.join("\n") + lastLine,
|
|
|
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No );
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(result == QMessageBox::Yes)
|
2022-09-29 15:38:03 +02:00
|
|
|
doInstallFiles = true;
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// everything OK
|
2022-09-29 15:38:03 +02:00
|
|
|
doInstallFiles = true;
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove progress bar after some delay so user can see that download was complete and not interrupted.
|
2018-04-13 07:34:58 +02:00
|
|
|
QTimer::singleShot(1000, this, SLOT(hideProgressBar()));
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
dlManager->deleteLater();
|
|
|
|
dlManager = nullptr;
|
2022-09-29 15:38:03 +02:00
|
|
|
|
|
|
|
if(doInstallFiles)
|
|
|
|
installFiles(savedFiles);
|
2022-12-26 02:34:10 +02:00
|
|
|
|
|
|
|
emit modsChanged();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::hideProgressBar()
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(dlManager == nullptr) // it was not recreated meanwhile
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
ui->progressWidget->setVisible(false);
|
|
|
|
ui->progressBar->setMaximum(0);
|
|
|
|
ui->progressBar->setValue(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::installFiles(QStringList files)
|
|
|
|
{
|
|
|
|
QStringList mods;
|
2014-03-23 15:08:01 +03:00
|
|
|
QStringList images;
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
// TODO: some better way to separate zip's with mods and downloaded repository files
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString filename : files)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(filename.endsWith(".zip"))
|
2013-08-22 17:22:49 +03:00
|
|
|
mods.push_back(filename);
|
2018-04-13 07:34:58 +02:00
|
|
|
if(filename.endsWith(".json"))
|
2022-09-29 15:38:03 +02:00
|
|
|
{
|
|
|
|
//download and merge additional files
|
|
|
|
auto repodata = JsonUtils::JsonFromFile(filename).toMap();
|
|
|
|
if(repodata.value("name").isNull())
|
|
|
|
{
|
|
|
|
for(const auto & key : repodata.keys())
|
|
|
|
{
|
|
|
|
auto modjson = repodata[key].toMap().value("mod");
|
|
|
|
if(!modjson.isNull())
|
|
|
|
{
|
|
|
|
downloadFile(key + ".json", modjson.toString(), "mod json");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto modn = QFileInfo(filename).baseName();
|
|
|
|
QVariantMap temp;
|
|
|
|
temp[modn] = repodata;
|
|
|
|
repodata = temp;
|
|
|
|
}
|
|
|
|
manager->loadRepository(repodata);
|
|
|
|
}
|
2018-04-13 07:34:58 +02:00
|
|
|
if(filename.endsWith(".png"))
|
2014-03-23 15:08:01 +03:00
|
|
|
images.push_back(filename);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!mods.empty())
|
2013-08-22 17:22:49 +03:00
|
|
|
installMods(mods);
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
if(!images.empty())
|
2014-03-23 15:08:01 +03:00
|
|
|
loadScreenshots();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::installMods(QStringList archives)
|
|
|
|
{
|
|
|
|
QStringList modNames;
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString archive : archives)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
// get basename out of full file name
|
|
|
|
// remove path remove extension
|
|
|
|
QString modName = archive.section('/', -1, -1).section('.', 0, 0);
|
|
|
|
|
|
|
|
modNames.push_back(modName);
|
|
|
|
}
|
|
|
|
|
2013-12-08 13:07:06 +03:00
|
|
|
QStringList modsToEnable;
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
// disable mod(s), to properly recalculate dependencies, if changed
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString mod : boost::adaptors::reverse(modNames))
|
2013-09-06 00:25:03 +03:00
|
|
|
{
|
2013-12-08 13:07:06 +03:00
|
|
|
CModEntry entry = modModel->getMod(mod);
|
2018-04-13 07:34:58 +02:00
|
|
|
if(entry.isInstalled())
|
2013-12-08 13:07:06 +03:00
|
|
|
{
|
|
|
|
// enable mod if installed and enabled
|
2018-04-13 07:34:58 +02:00
|
|
|
if(entry.isEnabled())
|
2013-12-08 13:07:06 +03:00
|
|
|
modsToEnable.push_back(mod);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// enable mod if m
|
2018-04-13 07:34:58 +02:00
|
|
|
if(settings["launcher"]["enableInstalledMods"].Bool())
|
2013-12-08 13:07:06 +03:00
|
|
|
modsToEnable.push_back(mod);
|
|
|
|
}
|
2013-09-06 00:25:03 +03:00
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
// uninstall old version of mod, if installed
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString mod : boost::adaptors::reverse(modNames))
|
2013-09-06 00:25:03 +03:00
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(modModel->getMod(mod).isInstalled())
|
2013-09-06 00:25:03 +03:00
|
|
|
manager->uninstallMod(mod);
|
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(int i = 0; i < modNames.size(); i++)
|
2013-08-22 17:22:49 +03:00
|
|
|
manager->installMod(modNames[i], archives[i]);
|
|
|
|
|
2014-03-23 19:36:16 +03:00
|
|
|
std::function<void(QString)> enableMod;
|
|
|
|
|
|
|
|
enableMod = [&](QString modName)
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
auto mod = modModel->getMod(modName);
|
2018-04-13 07:34:58 +02:00
|
|
|
if(mod.isInstalled() && !mod.getValue("keepDisabled").toBool())
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
2022-09-10 18:30:41 +02:00
|
|
|
if(mod.isDisabled() && manager->enableMod(modName))
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString child : modModel->getChildren(modName))
|
2014-03-23 15:08:01 +03:00
|
|
|
enableMod(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString mod : modsToEnable)
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
enableMod(mod);
|
|
|
|
}
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString archive : archives)
|
2013-08-22 17:22:49 +03:00
|
|
|
QFile::remove(archive);
|
2013-09-06 00:25:03 +03:00
|
|
|
|
|
|
|
checkManagerErrors();
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2014-11-03 17:47:37 +02:00
|
|
|
void CModListView::on_refreshButton_clicked()
|
|
|
|
{
|
|
|
|
loadRepositories();
|
|
|
|
}
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
void CModListView::on_pushButton_clicked()
|
|
|
|
{
|
|
|
|
delete dlManager;
|
|
|
|
dlManager = nullptr;
|
|
|
|
hideProgressBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::modelReset()
|
|
|
|
{
|
2023-01-26 01:01:41 +02:00
|
|
|
selectMod(filterModel->rowCount() > 0 ? filterModel->index(0, 0) : QModelIndex());
|
2013-08-24 23:11:51 +03:00
|
|
|
}
|
2013-09-06 00:25:03 +03:00
|
|
|
|
|
|
|
void CModListView::checkManagerErrors()
|
|
|
|
{
|
|
|
|
QString errors = manager->getErrors().join('\n');
|
2018-04-13 07:34:58 +02:00
|
|
|
if(errors.size() != 0)
|
2013-09-06 00:25:03 +03:00
|
|
|
{
|
|
|
|
QString title = "Operation failed";
|
|
|
|
QString description = "Encountered errors:\n" + errors;
|
2018-04-13 07:34:58 +02:00
|
|
|
QMessageBox::warning(this, title, description, QMessageBox::Ok, QMessageBox::Ok);
|
2013-09-06 00:25:03 +03:00
|
|
|
}
|
|
|
|
}
|
2014-03-23 15:08:01 +03:00
|
|
|
|
|
|
|
void CModListView::on_tabWidget_currentChanged(int index)
|
|
|
|
{
|
|
|
|
loadScreenshots();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModListView::loadScreenshots()
|
|
|
|
{
|
2023-01-26 01:01:41 +02:00
|
|
|
if(ui->tabWidget->currentIndex() == 2)
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
ui->screenshotsList->clear();
|
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
|
|
|
assert(modModel->hasMod(modName)); //should be filtered out by check above
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString & url : modModel->getMod(modName).getValue("screenshots").toStringList())
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
// URL must be encoded to something else to get rid of symbols illegal in file names
|
|
|
|
auto hashed = QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5);
|
|
|
|
auto hashedStr = QString::fromUtf8(hashed.toHex());
|
|
|
|
|
|
|
|
QString fullPath = CLauncherDirs::get().downloadsPath() + '/' + hashedStr + ".png";
|
|
|
|
QPixmap pixmap(fullPath);
|
2018-04-13 07:34:58 +02:00
|
|
|
if(pixmap.isNull())
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
// image file not exists or corrupted - try to redownload
|
|
|
|
downloadFile(hashedStr + ".png", url, "screenshots");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// managed to load cached image
|
|
|
|
QIcon icon(pixmap);
|
|
|
|
QListWidgetItem * item = new QListWidgetItem(icon, QString(tr("Screenshot %1")).arg(ui->screenshotsList->count() + 1));
|
|
|
|
ui->screenshotsList->addItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
void CModListView::on_screenshotsList_clicked(const QModelIndex & index)
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(index.isValid())
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
QIcon icon = ui->screenshotsList->item(index.row())->icon();
|
|
|
|
auto pixmap = icon.pixmap(icon.availableSizes()[0]);
|
|
|
|
ImageViewer::showPixmap(pixmap, this);
|
|
|
|
}
|
|
|
|
}
|
2014-08-04 14:03:57 +03:00
|
|
|
|
2022-11-16 21:53:54 +02:00
|
|
|
const CModList & CModListView::getModList() const
|
|
|
|
{
|
|
|
|
assert(modModel);
|
|
|
|
return *modModel;
|
|
|
|
}
|
2023-03-11 00:57:55 +02:00
|
|
|
|
|
|
|
void CModListView::doInstallMod(const QString & modName)
|
|
|
|
{
|
|
|
|
assert(findInvalidDependencies(modName).empty());
|
|
|
|
|
|
|
|
for(auto & name : modModel->getRequirements(modName))
|
|
|
|
{
|
|
|
|
auto mod = modModel->getMod(name);
|
|
|
|
if(!mod.isInstalled())
|
|
|
|
downloadFile(name + ".zip", mod.getValue("download").toString(), "mods");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModListView::isModInstalled(const QString & modName)
|
|
|
|
{
|
|
|
|
auto mod = modModel->getMod(modName);
|
|
|
|
return mod.isInstalled();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CModListView::getTranslationModName(const QString & language)
|
|
|
|
{
|
|
|
|
for (auto const & modName : modModel->getModList())
|
|
|
|
{
|
|
|
|
auto mod = modModel->getMod(modName);
|
|
|
|
|
|
|
|
if (mod.getValue("type") != "localization")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mod.getValue("language") != language)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return modName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|