Merge pull request #839 from flowln/modrinth_packs_bug_hunt

This commit is contained in:
Sefa Eyeoglu 2022-07-08 16:25:35 +02:00 committed by GitHub
commit 08989bde5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 108 additions and 30 deletions

View File

@ -412,12 +412,8 @@ void InstanceImportTask::processFlame()
"You will need to manually download them and add them to the modpack"), "You will need to manually download them and add them to the modpack"),
text); text);
message_dialog->setModal(true); message_dialog->setModal(true);
message_dialog->show();
connect(message_dialog, &QDialog::rejected, [&]() { if (message_dialog->exec()) {
m_modIdResolver.reset();
emitFailed("Canceled");
});
connect(message_dialog, &QDialog::accepted, [&]() {
m_filesNetJob = new NetJob(tr("Mod download"), APPLICATION->network()); m_filesNetJob = new NetJob(tr("Mod download"), APPLICATION->network());
for (const auto &result: m_modIdResolver->getResults().files) { for (const auto &result: m_modIdResolver->getResults().files) {
QString filename = result.fileName; QString filename = result.fileName;
@ -469,7 +465,10 @@ void InstanceImportTask::processFlame()
}); });
setStatus(tr("Downloading mods...")); setStatus(tr("Downloading mods..."));
m_filesNetJob->start(); m_filesNetJob->start();
}); } else {
m_modIdResolver.reset();
emitFailed("Canceled");
}
} else { } else {
//TODO extract to function ? //TODO extract to function ?
m_filesNetJob = new NetJob(tr("Mod download"), APPLICATION->network()); m_filesNetJob = new NetJob(tr("Mod download"), APPLICATION->network());

View File

@ -167,6 +167,9 @@ void ModFolderModel::finishUpdate()
{ {
QSet<QString> added = newSet; QSet<QString> added = newSet;
added.subtract(currentSet); added.subtract(currentSet);
// When you have a Qt build with assertions turned on, proceeding here will abort the application
if (added.size() > 0) {
beginInsertRows(QModelIndex(), mods.size(), mods.size() + added.size() - 1); beginInsertRows(QModelIndex(), mods.size(), mods.size() + added.size() - 1);
for (auto& addedMod : added) { for (auto& addedMod : added) {
mods.append(newMods[addedMod]); mods.append(newMods[addedMod]);
@ -174,6 +177,7 @@ void ModFolderModel::finishUpdate()
} }
endInsertRows(); endInsertRows();
} }
}
// update index // update index
{ {

View File

@ -10,7 +10,7 @@ Flame::FileResolvingTask::FileResolvingTask(const shared_qobject_ptr<QNetworkAcc
void Flame::FileResolvingTask::executeTask() void Flame::FileResolvingTask::executeTask()
{ {
setStatus(tr("Resolving mod IDs...")); setStatus(tr("Resolving mod IDs..."));
setProgress(0, m_toProcess.files.size()); setProgress(0, 3);
m_dljob = new NetJob("Mod id resolver", m_network); m_dljob = new NetJob("Mod id resolver", m_network);
result.reset(new QByteArray()); result.reset(new QByteArray());
//build json data to send //build json data to send
@ -29,6 +29,7 @@ void Flame::FileResolvingTask::executeTask()
void Flame::FileResolvingTask::netJobFinished() void Flame::FileResolvingTask::netJobFinished()
{ {
setProgress(1, 3);
int index = 0; int index = 0;
// job to check modrinth for blocked projects // job to check modrinth for blocked projects
auto job = new NetJob("Modrinth check", m_network); auto job = new NetJob("Modrinth check", m_network);
@ -63,6 +64,7 @@ void Flame::FileResolvingTask::netJobFinished()
} }
void Flame::FileResolvingTask::modrinthCheckFinished() { void Flame::FileResolvingTask::modrinthCheckFinished() {
setProgress(2, 3);
qDebug() << "Finished with blocked mods : " << blockedProjects.size(); qDebug() << "Finished with blocked mods : " << blockedProjects.size();
for (auto it = blockedProjects.keyBegin(); it != blockedProjects.keyEnd(); it++) { for (auto it = blockedProjects.keyBegin(); it != blockedProjects.keyEnd(); it++) {

View File

@ -219,6 +219,10 @@ void ListModel::searchRequestFinished(QJsonDocument& doc)
searchState = CanPossiblyFetchMore; searchState = CanPossiblyFetchMore;
} }
// When you have a Qt build with assertions turned on, proceeding here will abort the application
if (newList.size() == 0)
return;
beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size() + newList.size() - 1); beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size() + newList.size() - 1);
modpacks.append(newList); modpacks.append(newList);
endInsertRows(); endInsertRows();

View File

@ -57,6 +57,17 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
return QVariant(); return QVariant();
} }
bool ListModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
int pos = index.row();
if (pos >= modpacks.size() || pos < 0 || !index.isValid())
return false;
modpacks[pos] = value.value<Flame::IndexedPack>();
return true;
}
void ListModel::logoLoaded(QString logo, QIcon out) void ListModel::logoLoaded(QString logo, QIcon out)
{ {
m_loadingLogos.removeAll(logo); m_loadingLogos.removeAll(logo);
@ -210,6 +221,11 @@ void Flame::ListModel::searchRequestFinished()
nextSearchOffset += 25; nextSearchOffset += 25;
searchState = CanPossiblyFetchMore; searchState = CanPossiblyFetchMore;
} }
// When you have a Qt build with assertions turned on, proceeding here will abort the application
if (newList.size() == 0)
return;
beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size() + newList.size() - 1); beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size() + newList.size() - 1);
modpacks.append(newList); modpacks.append(newList);
endInsertRows(); endInsertRows();

View File

@ -34,6 +34,7 @@ public:
int rowCount(const QModelIndex &parent) const override; int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
Qt::ItemFlags flags(const QModelIndex &index) const override; Qt::ItemFlags flags(const QModelIndex &index) const override;
bool canFetchMore(const QModelIndex & parent) const override; bool canFetchMore(const QModelIndex & parent) const override;
void fetchMore(const QModelIndex & parent) override; void fetchMore(const QModelIndex & parent) override;

View File

@ -107,18 +107,18 @@ void FlamePage::triggerSearch()
listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex()); listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex());
} }
void FlamePage::onSelectionChanged(QModelIndex first, QModelIndex second) void FlamePage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
{ {
ui->versionSelectionBox->clear(); ui->versionSelectionBox->clear();
if (!first.isValid()) { if (!curr.isValid()) {
if (isOpened) { if (isOpened) {
dialog->setSuggestedPack(); dialog->setSuggestedPack();
} }
return; return;
} }
current = listModel->data(first, Qt::UserRole).value<Flame::IndexedPack>(); current = listModel->data(curr, Qt::UserRole).value<Flame::IndexedPack>();
if (current.versionsLoaded == false) { if (current.versionsLoaded == false) {
qDebug() << "Loading flame modpack versions"; qDebug() << "Loading flame modpack versions";
@ -127,7 +127,7 @@ void FlamePage::onSelectionChanged(QModelIndex first, QModelIndex second)
int addonId = current.addonId; int addonId = current.addonId;
netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.curseforge.com/v1/mods/%1/files").arg(addonId), response)); netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.curseforge.com/v1/mods/%1/files").arg(addonId), response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, addonId] { QObject::connect(netJob, &NetJob::succeeded, this, [this, response, addonId, curr] {
if (addonId != current.addonId) { if (addonId != current.addonId) {
return; // wrong request return; // wrong request
} }
@ -151,6 +151,16 @@ void FlamePage::onSelectionChanged(QModelIndex first, QModelIndex second)
ui->versionSelectionBox->addItem(version.version, QVariant(version.downloadUrl)); ui->versionSelectionBox->addItem(version.version, QVariant(version.downloadUrl));
} }
QVariant current_updated;
current_updated.setValue(current);
if (!listModel->setData(curr, current_updated, Qt::UserRole))
qWarning() << "Failed to cache versions for the current pack!";
// TODO: Check whether it's a connection issue or the project disabled 3rd-party distribution.
if (current.versionsLoaded && ui->versionSelectionBox->count() < 1) {
ui->versionSelectionBox->addItem(tr("No version is available!"), -1);
}
suggestCurrent(); suggestCurrent();
}); });
QObject::connect(netJob, &NetJob::finished, this, [response, netJob] { QObject::connect(netJob, &NetJob::finished, this, [response, netJob] {
@ -166,6 +176,11 @@ void FlamePage::onSelectionChanged(QModelIndex first, QModelIndex second)
suggestCurrent(); suggestCurrent();
} }
// TODO: Check whether it's a connection issue or the project disabled 3rd-party distribution.
if (current.versionsLoaded && ui->versionSelectionBox->count() < 1) {
ui->versionSelectionBox->addItem(tr("No version is available!"), -1);
}
updateUi(); updateUi();
} }
@ -175,7 +190,7 @@ void FlamePage::suggestCurrent()
return; return;
} }
if (selectedVersion.isEmpty()) { if (selectedVersion.isEmpty() || selectedVersion == "-1") {
dialog->setSuggestedPack(); dialog->setSuggestedPack();
return; return;
} }

View File

@ -104,6 +104,17 @@ auto ModpackListModel::data(const QModelIndex& index, int role) const -> QVarian
return {}; return {};
} }
bool ModpackListModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
int pos = index.row();
if (pos >= modpacks.size() || pos < 0 || !index.isValid())
return false;
modpacks[pos] = value.value<Modrinth::Modpack>();
return true;
}
void ModpackListModel::performPaginatedSearch() void ModpackListModel::performPaginatedSearch()
{ {
// TODO: Move to standalone API // TODO: Move to standalone API
@ -279,6 +290,10 @@ void ModpackListModel::searchRequestFinished(QJsonDocument& doc_all)
searchState = CanPossiblyFetchMore; searchState = CanPossiblyFetchMore;
} }
// When you have a Qt build with assertions turned on, proceeding here will abort the application
if (newList.size() == 0)
return;
beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size() + newList.size() - 1); beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size() + newList.size() - 1);
modpacks.append(newList); modpacks.append(newList);
endInsertRows(); endInsertRows();

View File

@ -64,6 +64,7 @@ class ModpackListModel : public QAbstractListModel {
/* Retrieve information from the model at a given index with the given role */ /* Retrieve information from the model at a given index with the given role */
auto data(const QModelIndex& index, int role) const -> QVariant override; auto data(const QModelIndex& index, int role) const -> QVariant override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
inline void setActiveJob(NetJob::Ptr ptr) { jobPtr = ptr; } inline void setActiveJob(NetJob::Ptr ptr) { jobPtr = ptr; }

View File

@ -101,18 +101,18 @@ bool ModrinthPage::eventFilter(QObject* watched, QEvent* event)
return QObject::eventFilter(watched, event); return QObject::eventFilter(watched, event);
} }
void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) void ModrinthPage::onSelectionChanged(QModelIndex curr, QModelIndex prev)
{ {
ui->versionSelectionBox->clear(); ui->versionSelectionBox->clear();
if (!first.isValid()) { if (!curr.isValid()) {
if (isOpened) { if (isOpened) {
dialog->setSuggestedPack(); dialog->setSuggestedPack();
} }
return; return;
} }
current = m_model->data(first, Qt::UserRole).value<Modrinth::Modpack>(); current = m_model->data(curr, Qt::UserRole).value<Modrinth::Modpack>();
auto name = current.name; auto name = current.name;
if (!current.extraInfoLoaded) { if (!current.extraInfoLoaded) {
@ -125,7 +125,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
netJob->addNetAction(Net::Download::makeByteArray(QString("%1/project/%2").arg(BuildConfig.MODRINTH_PROD_URL, id), response)); netJob->addNetAction(Net::Download::makeByteArray(QString("%1/project/%2").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, id] { QObject::connect(netJob, &NetJob::succeeded, this, [this, response, id, curr] {
if (id != current.id) { if (id != current.id) {
return; // wrong request? return; // wrong request?
} }
@ -149,6 +149,13 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
} }
updateUI(); updateUI();
QVariant current_updated;
current_updated.setValue(current);
if (!m_model->setData(curr, current_updated, Qt::UserRole))
qWarning() << "Failed to cache extra info for the current pack!";
suggestCurrent(); suggestCurrent();
}); });
QObject::connect(netJob, &NetJob::finished, this, [response, netJob] { QObject::connect(netJob, &NetJob::finished, this, [response, netJob] {
@ -170,7 +177,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
netJob->addNetAction( netJob->addNetAction(
Net::Download::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response)); Net::Download::makeByteArray(QString("%1/project/%2/version").arg(BuildConfig.MODRINTH_PROD_URL, id), response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, response, id] { QObject::connect(netJob, &NetJob::succeeded, this, [this, response, id, curr] {
if (id != current.id) { if (id != current.id) {
return; // wrong request? return; // wrong request?
} }
@ -192,9 +199,18 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
} }
for (auto version : current.versions) { for (auto version : current.versions) {
ui->versionSelectionBox->addItem(version.version, QVariant(version.id)); if (!version.name.contains(version.version))
ui->versionSelectionBox->addItem(QString("%1 — %2").arg(version.name, version.version), QVariant(version.id));
else
ui->versionSelectionBox->addItem(version.name, QVariant(version.id));
} }
QVariant current_updated;
current_updated.setValue(current);
if (!m_model->setData(curr, current_updated, Qt::UserRole))
qWarning() << "Failed to cache versions for the current pack!";
suggestCurrent(); suggestCurrent();
}); });
QObject::connect(netJob, &NetJob::finished, this, [response, netJob] { QObject::connect(netJob, &NetJob::finished, this, [response, netJob] {
@ -205,7 +221,10 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
} else { } else {
for (auto version : current.versions) { for (auto version : current.versions) {
if (!version.name.contains(version.version))
ui->versionSelectionBox->addItem(QString("%1 - %2").arg(version.name, version.version), QVariant(version.id)); ui->versionSelectionBox->addItem(QString("%1 - %2").arg(version.name, version.version), QVariant(version.id));
else
ui->versionSelectionBox->addItem(version.name, QVariant(version.id));
} }
suggestCurrent(); suggestCurrent();

View File

@ -63,9 +63,6 @@
<height>48</height> <height>48</height>
</size> </size>
</property> </property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>

View File

@ -217,6 +217,11 @@ void Technic::ListModel::searchRequestFinished()
return; return;
} }
searchState = Finished; searchState = Finished;
// When you have a Qt build with assertions turned on, proceeding here will abort the application
if (newList.size() == 0)
return;
beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size() + newList.size() - 1); beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size() + newList.size() - 1);
modpacks.append(newList); modpacks.append(newList);
endInsertRows(); endInsertRows();