cleanup: pull out data object so I'm not repeating myself
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
parent
9957aeb003
commit
149bc8e9ce
@ -1085,29 +1085,29 @@ void MainWindow::processURLs(QList<QUrl> urls)
|
|||||||
|
|
||||||
QString resource_name;
|
QString resource_name;
|
||||||
|
|
||||||
|
|
||||||
connect(job.get(), &Task::failed, this,
|
connect(job.get(), &Task::failed, this,
|
||||||
[this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
|
[this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
|
||||||
connect(job.get(), &Task::succeeded, this, [this, array, addonId, fileId, &dl_url, &resource_name] {
|
connect(job.get(), &Task::succeeded, this, [this, array, addonId, fileId, &dl_url, &resource_name] {
|
||||||
qDebug() << "Returned CFURL Json:\n" << array->toStdString().c_str();
|
qDebug() << "Returned CFURL Json:\n" << array->toStdString().c_str();
|
||||||
auto doc = Json::requireDocument(*array);
|
auto doc = Json::requireDocument(*array);
|
||||||
|
auto data = Json::ensureObject(Json::ensureObject(doc.object()), "data");
|
||||||
// No way to find out if it's a mod or a modpack before here
|
// No way to find out if it's a mod or a modpack before here
|
||||||
// And also we need to check if it ends with .zip, instead of any better way
|
// And also we need to check if it ends with .zip, instead of any better way
|
||||||
auto fileName = Json::ensureString(Json::ensureObject(Json::ensureObject(doc.object()), "data"), "fileName");
|
auto fileName = Json::ensureString(data, "fileName");
|
||||||
|
|
||||||
// Have to use ensureString then use QUrl to get proper url encoding
|
// Have to use ensureString then use QUrl to get proper url encoding
|
||||||
dl_url = QUrl(Json::ensureString(Json::ensureObject(Json::ensureObject(doc.object()), "data"), "downloadUrl",
|
dl_url = QUrl(Json::ensureString(data, "downloadUrl", "", "downloadUrl"));
|
||||||
"", "downloadUrl"));
|
|
||||||
if (!dl_url.isValid()) {
|
if (!dl_url.isValid()) {
|
||||||
CustomMessageBox::selectable(this, tr("Error"), tr("The modpack, mod, or resource is blocked for third-parties! Please download it manually at: \n%1").arg(dl_url.toDisplayString()),
|
CustomMessageBox::selectable(
|
||||||
QMessageBox::Critical)
|
this, tr("Error"),
|
||||||
|
tr("The modpack, mod, or resource %1 is blocked for third-parties! Please download it manually.").arg(fileName),
|
||||||
|
QMessageBox::Critical)
|
||||||
->show();
|
->show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo dl_file(dl_url.fileName());
|
QFileInfo dl_file(dl_url.fileName());
|
||||||
resource_name = Json::ensureString(Json::ensureObject(Json::ensureObject(doc.object()), "data"), "displayName",
|
resource_name = Json::ensureString(data, "displayName", dl_file.completeBaseName(), "displayName");
|
||||||
dl_file.completeBaseName(), "displayName");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
{ // drop stack
|
{ // drop stack
|
||||||
|
@ -144,23 +144,24 @@ void ImportPage::updateState()
|
|||||||
connect(job.get(), &NetJob::succeeded, this, [this, array, addonId, fileId] {
|
connect(job.get(), &NetJob::succeeded, this, [this, array, addonId, fileId] {
|
||||||
qDebug() << "Returned CFURL Json:\n" << array->toStdString().c_str();
|
qDebug() << "Returned CFURL Json:\n" << array->toStdString().c_str();
|
||||||
auto doc = Json::requireDocument(*array);
|
auto doc = Json::requireDocument(*array);
|
||||||
|
auto data = Json::ensureObject(Json::ensureObject(doc.object()), "data");
|
||||||
// No way to find out if it's a mod or a modpack before here
|
// No way to find out if it's a mod or a modpack before here
|
||||||
// And also we need to check if it ends with .zip, instead of any better way
|
// And also we need to check if it ends with .zip, instead of any better way
|
||||||
auto fileName = Json::ensureString(Json::ensureObject(Json::ensureObject(doc.object()), "data"), "fileName");
|
auto fileName = Json::ensureString(data, "fileName");
|
||||||
if (fileName.endsWith(".zip")) {
|
if (fileName.endsWith(".zip")) {
|
||||||
// Have to use ensureString then use QUrl to get proper url encoding
|
// Have to use ensureString then use QUrl to get proper url encoding
|
||||||
auto dl_url = QUrl(
|
auto dl_url = QUrl(Json::ensureString(data, "downloadUrl", "", "downloadUrl"));
|
||||||
Json::ensureString(Json::ensureObject(Json::ensureObject(doc.object()), "data"), "downloadUrl", "", "downloadUrl"));
|
|
||||||
if (!dl_url.isValid()) {
|
if (!dl_url.isValid()) {
|
||||||
CustomMessageBox::selectable(this, tr("Error"), tr("The modpack is blocked ! Please download it manually"),
|
CustomMessageBox::selectable(
|
||||||
QMessageBox::Critical)
|
this, tr("Error"),
|
||||||
|
tr("The modpack %1 is blocked for third-parties! Please download it manually.").arg(fileName),
|
||||||
|
QMessageBox::Critical)
|
||||||
->show();
|
->show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo dl_file(dl_url.fileName());
|
QFileInfo dl_file(dl_url.fileName());
|
||||||
QString pack_name = Json::ensureString(Json::ensureObject(Json::ensureObject(doc.object()), "data"), "displayName",
|
QString pack_name = Json::ensureString(data, "displayName", dl_file.completeBaseName(), "displayName");
|
||||||
dl_file.completeBaseName(), "displayName");
|
|
||||||
|
|
||||||
QMap<QString, QString> extra_info;
|
QMap<QString, QString> extra_info;
|
||||||
extra_info.insert("pack_id", addonId);
|
extra_info.insert("pack_id", addonId);
|
||||||
@ -201,7 +202,7 @@ void ImportPage::setUrl(const QString& url)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ImportPage::setExtraInfo(const QMap<QString, QString>& extra_info) {
|
void ImportPage::setExtraInfo(const QMap<QString, QString>& extra_info) {
|
||||||
m_extra_info = QMap(extra_info); // copy
|
m_extra_info = extra_info;
|
||||||
updateState();
|
updateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user