|
|
@@ -50,24 +50,22 @@ void CModListView::setupModsView()
|
|
|
ui->allModsView->setColumnWidth(ModFields::VERSION, 60);
|
|
|
|
|
|
ui->allModsView->header()->setSectionResizeMode(ModFields::STATUS_ENABLED, QHeaderView::Fixed);
|
|
|
- ui->allModsView->header()->setSectionResizeMode(ModFields::STATUS_UPDATE, QHeaderView::Fixed);
|
|
|
+ ui->allModsView->header()->setSectionResizeMode(ModFields::STATUS_UPDATE, QHeaderView::Fixed);
|
|
|
|
|
|
ui->allModsView->setUniformRowHeights(true);
|
|
|
|
|
|
- connect( ui->allModsView->selectionModel(), SIGNAL( currentRowChanged( const QModelIndex &, const QModelIndex & )),
|
|
|
- this, SLOT( modSelected( const QModelIndex &, const QModelIndex & )));
|
|
|
+ connect(ui->allModsView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex&,const QModelIndex&)),
|
|
|
+ this, SLOT(modSelected(const QModelIndex&,const QModelIndex&)));
|
|
|
|
|
|
- connect( filterModel, SIGNAL( modelReset()),
|
|
|
- this, SLOT( modelReset()));
|
|
|
+ connect(filterModel, SIGNAL(modelReset()),
|
|
|
+ this, SLOT(modelReset()));
|
|
|
|
|
|
- connect( modModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
|
- this, SLOT(dataChanged(QModelIndex,QModelIndex)));
|
|
|
+ connect(modModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
|
+ this, SLOT(dataChanged(QModelIndex,QModelIndex)));
|
|
|
}
|
|
|
|
|
|
-CModListView::CModListView(QWidget *parent) :
|
|
|
- QWidget(parent),
|
|
|
- settingsListener(settings.listen["launcher"]["repositoryURL"]),
|
|
|
- ui(new Ui::CModListView)
|
|
|
+CModListView::CModListView(QWidget * parent)
|
|
|
+ : QWidget(parent), settingsListener(settings.listen["launcher"]["repositoryURL"]), ui(new Ui::CModListView)
|
|
|
{
|
|
|
settingsListener([&](const JsonNode &){ repositoriesChanged = true; });
|
|
|
ui->setupUi(this);
|
|
|
@@ -79,7 +77,7 @@ CModListView::CModListView(QWidget *parent) :
|
|
|
ui->progressWidget->setVisible(false);
|
|
|
dlManager = nullptr;
|
|
|
disableModInfo();
|
|
|
- if (settings["launcher"]["autoCheckRepositories"].Bool())
|
|
|
+ if(settings["launcher"]["autoCheckRepositories"].Bool())
|
|
|
{
|
|
|
loadRepositories();
|
|
|
}
|
|
|
@@ -92,7 +90,7 @@ CModListView::CModListView(QWidget *parent) :
|
|
|
void CModListView::loadRepositories()
|
|
|
{
|
|
|
manager->resetRepositories();
|
|
|
- for (auto entry : settings["launcher"]["repositoryURL"].Vector())
|
|
|
+ for(auto entry : settings["launcher"]["repositoryURL"].Vector())
|
|
|
{
|
|
|
QString str = QString::fromUtf8(entry.String().c_str());
|
|
|
|
|
|
@@ -112,10 +110,10 @@ CModListView::~CModListView()
|
|
|
void CModListView::showEvent(QShowEvent * event)
|
|
|
{
|
|
|
QWidget::showEvent(event);
|
|
|
- if (repositoriesChanged)
|
|
|
+ if(repositoriesChanged)
|
|
|
{
|
|
|
repositoriesChanged = false;
|
|
|
- if (settings["launcher"]["autoCheckRepositories"].Bool())
|
|
|
+ if(settings["launcher"]["autoCheckRepositories"].Bool())
|
|
|
{
|
|
|
loadRepositories();
|
|
|
}
|
|
|
@@ -141,10 +139,10 @@ void CModListView::hideModInfo()
|
|
|
|
|
|
static QString replaceIfNotEmpty(QVariant value, QString pattern)
|
|
|
{
|
|
|
- if (value.canConvert<QStringList>())
|
|
|
+ if(value.canConvert<QStringList>())
|
|
|
return pattern.arg(value.toStringList().join(", "));
|
|
|
|
|
|
- if (value.canConvert<QString>())
|
|
|
+ if(value.canConvert<QString>())
|
|
|
return pattern.arg(value.toString());
|
|
|
|
|
|
// all valid types of data should have been filtered by code above
|
|
|
@@ -155,12 +153,12 @@ static QString replaceIfNotEmpty(QVariant value, QString pattern)
|
|
|
|
|
|
static QString replaceIfNotEmpty(QStringList value, QString pattern)
|
|
|
{
|
|
|
- if (!value.empty())
|
|
|
+ if(!value.empty())
|
|
|
return pattern.arg(value.join(", "));
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
-QString CModListView::genChangelogText(CModEntry &mod)
|
|
|
+QString CModListView::genChangelogText(CModEntry & mod)
|
|
|
{
|
|
|
QString headerTemplate = "<p><span style=\" font-weight:600;\">%1: </span></p>";
|
|
|
QString entryBegin = "<p align=\"justify\"><ul>";
|
|
|
@@ -178,22 +176,22 @@ QString CModListView::genChangelogText(CModEntry &mod)
|
|
|
return !CModEntry::compareVersions(lesser, greater);
|
|
|
});
|
|
|
|
|
|
- for (auto & version : versions)
|
|
|
+ for(auto & version : versions)
|
|
|
{
|
|
|
result += headerTemplate.arg(version);
|
|
|
result += entryBegin;
|
|
|
- for (auto & line : changelog.value(version).toStringList())
|
|
|
+ for(auto & line : changelog.value(version).toStringList())
|
|
|
result += entryLine.arg(line);
|
|
|
result += entryEnd;
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-QString CModListView::genModInfoText(CModEntry &mod)
|
|
|
+QString CModListView::genModInfoText(CModEntry & mod)
|
|
|
{
|
|
|
QString prefix = "<p><span style=\" font-weight:600;\">%1: </span>"; // shared prefix
|
|
|
QString lineTemplate = prefix + "%2</p>";
|
|
|
- QString urlTemplate = prefix + "<a href=\"%2\">%3</a></p>";
|
|
|
+ QString urlTemplate = prefix + "<a href=\"%2\">%3</a></p>";
|
|
|
QString textTemplate = prefix + "</p><p align=\"justify\">%2</p>";
|
|
|
QString listTemplate = "<p align=\"justify\">%1: %2</p>";
|
|
|
QString noteTemplate = "<p align=\"justify\">%1</p>";
|
|
|
@@ -204,14 +202,14 @@ QString CModListView::genModInfoText(CModEntry &mod)
|
|
|
result += replaceIfNotEmpty(mod.getValue("installedVersion"), lineTemplate.arg(tr("Installed version")));
|
|
|
result += replaceIfNotEmpty(mod.getValue("latestVersion"), lineTemplate.arg(tr("Latest version")));
|
|
|
|
|
|
- if (mod.getValue("size").isValid())
|
|
|
+ if(mod.getValue("size").isValid())
|
|
|
result += replaceIfNotEmpty(CModEntry::sizeToString(mod.getValue("size").toDouble()), lineTemplate.arg(tr("Download size")));
|
|
|
result += replaceIfNotEmpty(mod.getValue("author"), lineTemplate.arg(tr("Authors")));
|
|
|
|
|
|
- if (mod.getValue("licenseURL").isValid())
|
|
|
+ if(mod.getValue("licenseURL").isValid())
|
|
|
result += urlTemplate.arg(tr("License")).arg(mod.getValue("licenseURL").toString()).arg(mod.getValue("licenseName").toString());
|
|
|
|
|
|
- if (mod.getValue("contact").isValid())
|
|
|
+ if(mod.getValue("contact").isValid())
|
|
|
result += urlTemplate.arg(tr("Home")).arg(mod.getValue("contact").toString()).arg(mod.getValue("contact").toString());
|
|
|
|
|
|
result += replaceIfNotEmpty(mod.getValue("depends"), lineTemplate.arg(tr("Required mods")));
|
|
|
@@ -220,7 +218,7 @@ QString CModListView::genModInfoText(CModEntry &mod)
|
|
|
|
|
|
result += "<p></p>"; // to get some empty space
|
|
|
|
|
|
- QString unknownDeps = tr("This mod can not be installed or enabled because following dependencies are not present");
|
|
|
+ QString unknownDeps = tr("This mod can not be installed or enabled because following dependencies are not present");
|
|
|
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");
|
|
|
@@ -230,15 +228,15 @@ QString CModListView::genModInfoText(CModEntry &mod)
|
|
|
|
|
|
notes += replaceIfNotEmpty(findInvalidDependencies(mod.getName()), listTemplate.arg(unknownDeps));
|
|
|
notes += replaceIfNotEmpty(findBlockingMods(mod.getName()), listTemplate.arg(blockingMods));
|
|
|
- if (mod.isEnabled())
|
|
|
+ if(mod.isEnabled())
|
|
|
notes += replaceIfNotEmpty(findDependentMods(mod.getName(), true), listTemplate.arg(hasActiveDependentMods));
|
|
|
- if (mod.isInstalled())
|
|
|
+ if(mod.isInstalled())
|
|
|
notes += replaceIfNotEmpty(findDependentMods(mod.getName(), false), listTemplate.arg(hasDependentMods));
|
|
|
|
|
|
- if (mod.getName().contains('.'))
|
|
|
+ if(mod.getName().contains('.'))
|
|
|
notes += noteTemplate.arg(thisIsSubmod);
|
|
|
|
|
|
- if (notes.size())
|
|
|
+ if(notes.size())
|
|
|
result += textTemplate.arg(tr("Notes")).arg(notes);
|
|
|
|
|
|
return result;
|
|
|
@@ -270,7 +268,7 @@ void CModListView::dataChanged(const QModelIndex & topleft, const QModelIndex &
|
|
|
|
|
|
void CModListView::selectMod(const QModelIndex & index)
|
|
|
{
|
|
|
- if (!index.isValid())
|
|
|
+ if(!index.isValid())
|
|
|
{
|
|
|
disableModInfo();
|
|
|
}
|
|
|
@@ -308,7 +306,7 @@ void CModListView::selectMod(const QModelIndex & index)
|
|
|
|
|
|
void CModListView::keyPressEvent(QKeyEvent * event)
|
|
|
{
|
|
|
- if (event->key() == Qt::Key_Escape && ui->modInfoWidget->isVisible() )
|
|
|
+ if(event->key() == Qt::Key_Escape && ui->modInfoWidget->isVisible())
|
|
|
{
|
|
|
hideModInfo();
|
|
|
}
|
|
|
@@ -318,26 +316,26 @@ void CModListView::keyPressEvent(QKeyEvent * event)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void CModListView::modSelected(const QModelIndex & current, const QModelIndex & )
|
|
|
+void CModListView::modSelected(const QModelIndex & current, const QModelIndex &)
|
|
|
{
|
|
|
selectMod(current);
|
|
|
}
|
|
|
|
|
|
void CModListView::on_hideModInfoButton_clicked()
|
|
|
{
|
|
|
- if (ui->modInfoWidget->isVisible())
|
|
|
+ if(ui->modInfoWidget->isVisible())
|
|
|
hideModInfo();
|
|
|
else
|
|
|
showModInfo();
|
|
|
}
|
|
|
|
|
|
-void CModListView::on_allModsView_activated(const QModelIndex &index)
|
|
|
+void CModListView::on_allModsView_activated(const QModelIndex & index)
|
|
|
{
|
|
|
showModInfo();
|
|
|
selectMod(index);
|
|
|
}
|
|
|
|
|
|
-void CModListView::on_lineEdit_textChanged(const QString &arg1)
|
|
|
+void CModListView::on_lineEdit_textChanged(const QString & arg1)
|
|
|
{
|
|
|
QRegExp regExp(arg1, Qt::CaseInsensitive, QRegExp::Wildcard);
|
|
|
filterModel->setFilterRegExp(regExp);
|
|
|
@@ -345,23 +343,35 @@ void CModListView::on_lineEdit_textChanged(const QString &arg1)
|
|
|
|
|
|
void CModListView::on_comboBox_currentIndexChanged(int index)
|
|
|
{
|
|
|
- switch (index)
|
|
|
+ switch(index)
|
|
|
{
|
|
|
- break; 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);
|
|
|
+ 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;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
QStringList CModListView::findInvalidDependencies(QString mod)
|
|
|
{
|
|
|
QStringList ret;
|
|
|
- for (QString requrement : modModel->getRequirements(mod))
|
|
|
+ for(QString requrement : modModel->getRequirements(mod))
|
|
|
{
|
|
|
- if (!modModel->hasMod(requrement))
|
|
|
+ if(!modModel->hasMod(requrement))
|
|
|
ret += requrement;
|
|
|
}
|
|
|
return ret;
|
|
|
@@ -372,16 +382,18 @@ QStringList CModListView::findBlockingMods(QString mod)
|
|
|
QStringList ret;
|
|
|
auto required = modModel->getRequirements(mod);
|
|
|
|
|
|
- for (QString name : modModel->getModList())
|
|
|
+ for(QString name : modModel->getModList())
|
|
|
{
|
|
|
auto mod = modModel->getMod(name);
|
|
|
|
|
|
- if (mod.isEnabled())
|
|
|
+ if(mod.isEnabled())
|
|
|
{
|
|
|
// one of enabled mods have requirement (or this mod) marked as conflict
|
|
|
- for (auto conflict : mod.getValue("conflicts").toStringList())
|
|
|
- if (required.contains(conflict))
|
|
|
+ for(auto conflict : mod.getValue("conflicts").toStringList())
|
|
|
+ {
|
|
|
+ if(required.contains(conflict))
|
|
|
ret.push_back(name);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -391,16 +403,18 @@ QStringList CModListView::findBlockingMods(QString mod)
|
|
|
QStringList CModListView::findDependentMods(QString mod, bool excludeDisabled)
|
|
|
{
|
|
|
QStringList ret;
|
|
|
- for (QString modName : modModel->getModList())
|
|
|
+ for(QString modName : modModel->getModList())
|
|
|
{
|
|
|
auto current = modModel->getMod(modName);
|
|
|
|
|
|
- if (!current.isInstalled())
|
|
|
+ if(!current.isInstalled())
|
|
|
continue;
|
|
|
|
|
|
- if (current.getValue("depends").toStringList().contains(mod) &&
|
|
|
- !(current.isDisabled() && excludeDisabled))
|
|
|
- ret += modName;
|
|
|
+ if(current.getValue("depends").toStringList().contains(mod))
|
|
|
+ {
|
|
|
+ if(!(current.isDisabled() && excludeDisabled))
|
|
|
+ ret += modName;
|
|
|
+ }
|
|
|
}
|
|
|
return ret;
|
|
|
}
|
|
|
@@ -412,9 +426,11 @@ void CModListView::on_enableButton_clicked()
|
|
|
assert(findBlockingMods(modName).empty());
|
|
|
assert(findInvalidDependencies(modName).empty());
|
|
|
|
|
|
- for (auto & name : modModel->getRequirements(modName))
|
|
|
- if (modModel->getMod(name).isDisabled())
|
|
|
+ for(auto & name : modModel->getRequirements(modName))
|
|
|
+ {
|
|
|
+ if(modModel->getMod(name).isDisabled())
|
|
|
manager->enableMod(name);
|
|
|
+ }
|
|
|
checkManagerErrors();
|
|
|
}
|
|
|
|
|
|
@@ -422,9 +438,8 @@ void CModListView::on_disableButton_clicked()
|
|
|
{
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
|
|
|
|
|
- if (modModel->hasMod(modName) &&
|
|
|
- modModel->getMod(modName).isEnabled())
|
|
|
- manager->disableMod(modName);
|
|
|
+ if(modModel->hasMod(modName) && modModel->getMod(modName).isEnabled())
|
|
|
+ manager->disableMod(modName);
|
|
|
|
|
|
checkManagerErrors();
|
|
|
}
|
|
|
@@ -435,11 +450,11 @@ void CModListView::on_updateButton_clicked()
|
|
|
|
|
|
assert(findInvalidDependencies(modName).empty());
|
|
|
|
|
|
- for (auto & name : modModel->getRequirements(modName))
|
|
|
+ for(auto & name : modModel->getRequirements(modName))
|
|
|
{
|
|
|
auto mod = modModel->getMod(name);
|
|
|
// update required mod, install missing (can be new dependency)
|
|
|
- if (mod.isUpdateable() || !mod.isInstalled())
|
|
|
+ if(mod.isUpdateable() || !mod.isInstalled())
|
|
|
downloadFile(name + ".zip", mod.getValue("download").toString(), "mods");
|
|
|
}
|
|
|
}
|
|
|
@@ -449,10 +464,9 @@ void CModListView::on_uninstallButton_clicked()
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
|
|
// NOTE: perhaps add "manually installed" flag and uninstall those dependencies that don't have it?
|
|
|
|
|
|
- if (modModel->hasMod(modName) &&
|
|
|
- modModel->getMod(modName).isInstalled())
|
|
|
+ if(modModel->hasMod(modName) && modModel->getMod(modName).isInstalled())
|
|
|
{
|
|
|
- if (modModel->getMod(modName).isEnabled())
|
|
|
+ if(modModel->getMod(modName).isEnabled())
|
|
|
manager->disableMod(modName);
|
|
|
manager->uninstallMod(modName);
|
|
|
}
|
|
|
@@ -465,25 +479,25 @@ void CModListView::on_installButton_clicked()
|
|
|
|
|
|
assert(findInvalidDependencies(modName).empty());
|
|
|
|
|
|
- for (auto & name : modModel->getRequirements(modName))
|
|
|
+ for(auto & name : modModel->getRequirements(modName))
|
|
|
{
|
|
|
auto mod = modModel->getMod(name);
|
|
|
- if (!mod.isInstalled())
|
|
|
+ if(!mod.isInstalled())
|
|
|
downloadFile(name + ".zip", mod.getValue("download").toString(), "mods");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void CModListView::downloadFile(QString file, QString url, QString description)
|
|
|
{
|
|
|
- if (!dlManager)
|
|
|
+ if(!dlManager)
|
|
|
{
|
|
|
dlManager = new CDownloadManager();
|
|
|
ui->progressWidget->setVisible(true);
|
|
|
connect(dlManager, SIGNAL(downloadProgress(qint64,qint64)),
|
|
|
- this, SLOT(downloadProgress(qint64,qint64)));
|
|
|
+ this, SLOT(downloadProgress(qint64,qint64)));
|
|
|
|
|
|
connect(dlManager, SIGNAL(finished(QStringList,QStringList,QStringList)),
|
|
|
- this, SLOT(downloadFinished(QStringList,QStringList,QStringList)));
|
|
|
+ this, SLOT(downloadFinished(QStringList,QStringList,QStringList)));
|
|
|
|
|
|
|
|
|
QString progressBarFormat = "Downloading %s%. %p% (%v KB out of %m KB) finished";
|
|
|
@@ -498,8 +512,8 @@ void CModListView::downloadFile(QString file, QString url, QString description)
|
|
|
void CModListView::downloadProgress(qint64 current, qint64 max)
|
|
|
{
|
|
|
// display progress, in kilobytes
|
|
|
- ui->progressBar->setValue(current/1024);
|
|
|
- ui->progressBar->setMaximum(max/1024);
|
|
|
+ ui->progressBar->setValue(current / 1024);
|
|
|
+ ui->progressBar->setMaximum(max / 1024);
|
|
|
}
|
|
|
|
|
|
void CModListView::downloadFinished(QStringList savedFiles, QStringList failedFiles, QStringList errors)
|
|
|
@@ -511,18 +525,18 @@ void CModListView::downloadFinished(QStringList savedFiles, QStringList failedFi
|
|
|
// if all files were d/loaded there should be no errors. And on failure there must be an error
|
|
|
assert(failedFiles.empty() == errors.empty());
|
|
|
|
|
|
- if (savedFiles.empty())
|
|
|
+ if(savedFiles.empty())
|
|
|
{
|
|
|
// no successfully downloaded mods
|
|
|
- QMessageBox::warning(this, title, firstLine + errors.join("\n"), QMessageBox::Ok, QMessageBox::Ok );
|
|
|
+ QMessageBox::warning(this, title, firstLine + errors.join("\n"), QMessageBox::Ok, QMessageBox::Ok);
|
|
|
}
|
|
|
- else if (!failedFiles.empty())
|
|
|
+ else if(!failedFiles.empty())
|
|
|
{
|
|
|
// some mods were not downloaded
|
|
|
int result = QMessageBox::warning (this, title, firstLine + errors.join("\n") + lastLine,
|
|
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No );
|
|
|
|
|
|
- if (result == QMessageBox::Yes)
|
|
|
+ if(result == QMessageBox::Yes)
|
|
|
installFiles(savedFiles);
|
|
|
}
|
|
|
else
|
|
|
@@ -532,7 +546,7 @@ void CModListView::downloadFinished(QStringList savedFiles, QStringList failedFi
|
|
|
}
|
|
|
|
|
|
// remove progress bar after some delay so user can see that download was complete and not interrupted.
|
|
|
- QTimer::singleShot(1000, this, SLOT(hideProgressBar()));
|
|
|
+ QTimer::singleShot(1000, this, SLOT(hideProgressBar()));
|
|
|
|
|
|
dlManager->deleteLater();
|
|
|
dlManager = nullptr;
|
|
|
@@ -540,7 +554,7 @@ void CModListView::downloadFinished(QStringList savedFiles, QStringList failedFi
|
|
|
|
|
|
void CModListView::hideProgressBar()
|
|
|
{
|
|
|
- if (dlManager == nullptr) // it was not recreated meanwhile
|
|
|
+ if(dlManager == nullptr) // it was not recreated meanwhile
|
|
|
{
|
|
|
ui->progressWidget->setVisible(false);
|
|
|
ui->progressBar->setMaximum(0);
|
|
|
@@ -554,19 +568,19 @@ void CModListView::installFiles(QStringList files)
|
|
|
QStringList images;
|
|
|
|
|
|
// TODO: some better way to separate zip's with mods and downloaded repository files
|
|
|
- for (QString filename : files)
|
|
|
+ for(QString filename : files)
|
|
|
{
|
|
|
- if (filename.endsWith(".zip"))
|
|
|
+ if(filename.endsWith(".zip"))
|
|
|
mods.push_back(filename);
|
|
|
- if (filename.endsWith(".json"))
|
|
|
+ if(filename.endsWith(".json"))
|
|
|
manager->loadRepository(filename);
|
|
|
- if (filename.endsWith(".png"))
|
|
|
+ if(filename.endsWith(".png"))
|
|
|
images.push_back(filename);
|
|
|
}
|
|
|
- if (!mods.empty())
|
|
|
+ if(!mods.empty())
|
|
|
installMods(mods);
|
|
|
|
|
|
- if (!images.empty())
|
|
|
+ if(!images.empty())
|
|
|
loadScreenshots();
|
|
|
}
|
|
|
|
|
|
@@ -574,7 +588,7 @@ void CModListView::installMods(QStringList archives)
|
|
|
{
|
|
|
QStringList modNames;
|
|
|
|
|
|
- for (QString archive : archives)
|
|
|
+ for(QString archive : archives)
|
|
|
{
|
|
|
// get basename out of full file name
|
|
|
// remove path remove extension
|
|
|
@@ -586,31 +600,31 @@ void CModListView::installMods(QStringList archives)
|
|
|
QStringList modsToEnable;
|
|
|
|
|
|
// disable mod(s), to properly recalculate dependencies, if changed
|
|
|
- for (QString mod : boost::adaptors::reverse(modNames))
|
|
|
+ for(QString mod : boost::adaptors::reverse(modNames))
|
|
|
{
|
|
|
CModEntry entry = modModel->getMod(mod);
|
|
|
- if (entry.isInstalled())
|
|
|
+ if(entry.isInstalled())
|
|
|
{
|
|
|
// enable mod if installed and enabled
|
|
|
- if (entry.isEnabled())
|
|
|
+ if(entry.isEnabled())
|
|
|
modsToEnable.push_back(mod);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// enable mod if m
|
|
|
- if (settings["launcher"]["enableInstalledMods"].Bool())
|
|
|
+ if(settings["launcher"]["enableInstalledMods"].Bool())
|
|
|
modsToEnable.push_back(mod);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// uninstall old version of mod, if installed
|
|
|
- for (QString mod : boost::adaptors::reverse(modNames))
|
|
|
+ for(QString mod : boost::adaptors::reverse(modNames))
|
|
|
{
|
|
|
- if (modModel->getMod(mod).isInstalled())
|
|
|
+ if(modModel->getMod(mod).isInstalled())
|
|
|
manager->uninstallMod(mod);
|
|
|
}
|
|
|
|
|
|
- for (int i=0; i<modNames.size(); i++)
|
|
|
+ for(int i = 0; i < modNames.size(); i++)
|
|
|
manager->installMod(modNames[i], archives[i]);
|
|
|
|
|
|
std::function<void(QString)> enableMod;
|
|
|
@@ -618,22 +632,22 @@ void CModListView::installMods(QStringList archives)
|
|
|
enableMod = [&](QString modName)
|
|
|
{
|
|
|
auto mod = modModel->getMod(modName);
|
|
|
- if (mod.isInstalled() && !mod.getValue("keepDisabled").toBool())
|
|
|
+ if(mod.isInstalled() && !mod.getValue("keepDisabled").toBool())
|
|
|
{
|
|
|
- if (manager->enableMod(modName))
|
|
|
+ if(manager->enableMod(modName))
|
|
|
{
|
|
|
- for (QString child : modModel->getChildren(modName))
|
|
|
+ for(QString child : modModel->getChildren(modName))
|
|
|
enableMod(child);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- for (QString mod : modsToEnable)
|
|
|
+ for(QString mod : modsToEnable)
|
|
|
{
|
|
|
enableMod(mod);
|
|
|
}
|
|
|
|
|
|
- for (QString archive : archives)
|
|
|
+ for(QString archive : archives)
|
|
|
QFile::remove(archive);
|
|
|
|
|
|
checkManagerErrors();
|
|
|
@@ -653,18 +667,18 @@ void CModListView::on_pushButton_clicked()
|
|
|
|
|
|
void CModListView::modelReset()
|
|
|
{
|
|
|
- if (ui->modInfoWidget->isVisible())
|
|
|
- selectMod(filterModel->rowCount() > 0 ? filterModel->index(0,0) : QModelIndex());
|
|
|
+ if(ui->modInfoWidget->isVisible())
|
|
|
+ selectMod(filterModel->rowCount() > 0 ? filterModel->index(0, 0) : QModelIndex());
|
|
|
}
|
|
|
|
|
|
void CModListView::checkManagerErrors()
|
|
|
{
|
|
|
QString errors = manager->getErrors().join('\n');
|
|
|
- if (errors.size() != 0)
|
|
|
+ if(errors.size() != 0)
|
|
|
{
|
|
|
QString title = "Operation failed";
|
|
|
QString description = "Encountered errors:\n" + errors;
|
|
|
- QMessageBox::warning(this, title, description, QMessageBox::Ok, QMessageBox::Ok );
|
|
|
+ QMessageBox::warning(this, title, description, QMessageBox::Ok, QMessageBox::Ok);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -675,13 +689,13 @@ void CModListView::on_tabWidget_currentChanged(int index)
|
|
|
|
|
|
void CModListView::loadScreenshots()
|
|
|
{
|
|
|
- if (ui->tabWidget->currentIndex() == 2 && ui->modInfoWidget->isVisible())
|
|
|
+ if(ui->tabWidget->currentIndex() == 2 && ui->modInfoWidget->isVisible())
|
|
|
{
|
|
|
ui->screenshotsList->clear();
|
|
|
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
|
|
|
assert(modModel->hasMod(modName)); //should be filtered out by check above
|
|
|
|
|
|
- for (QString & url : modModel->getMod(modName).getValue("screenshots").toStringList())
|
|
|
+ for(QString & url : modModel->getMod(modName).getValue("screenshots").toStringList())
|
|
|
{
|
|
|
// URL must be encoded to something else to get rid of symbols illegal in file names
|
|
|
auto hashed = QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5);
|
|
|
@@ -689,7 +703,7 @@ void CModListView::loadScreenshots()
|
|
|
|
|
|
QString fullPath = CLauncherDirs::get().downloadsPath() + '/' + hashedStr + ".png";
|
|
|
QPixmap pixmap(fullPath);
|
|
|
- if (pixmap.isNull())
|
|
|
+ if(pixmap.isNull())
|
|
|
{
|
|
|
// image file not exists or corrupted - try to redownload
|
|
|
downloadFile(hashedStr + ".png", url, "screenshots");
|
|
|
@@ -705,9 +719,9 @@ void CModListView::loadScreenshots()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void CModListView::on_screenshotsList_clicked(const QModelIndex &index)
|
|
|
+void CModListView::on_screenshotsList_clicked(const QModelIndex & index)
|
|
|
{
|
|
|
- if (index.isValid())
|
|
|
+ if(index.isValid())
|
|
|
{
|
|
|
QIcon icon = ui->screenshotsList->item(index.row())->icon();
|
|
|
auto pixmap = icon.pixmap(icon.availableSizes()[0]);
|