added error message for import skin from user

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-05-30 16:21:08 +03:00
parent 75fbdc2df5
commit eaccdca02d
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
3 changed files with 33 additions and 15 deletions

View File

@ -148,12 +148,13 @@ void NetJob::updateState()
void NetJob::emitFailed(QString reason) void NetJob::emitFailed(QString reason)
{ {
#if defined(LAUNCHER_APPLICATION) #if defined(LAUNCHER_APPLICATION)
if (m_ask_retry) {
auto response = CustomMessageBox::selectable(nullptr, "Confirm retry", auto response = CustomMessageBox::selectable(nullptr, "Confirm retry",
"The tasks failed\n" "The tasks failed.\n"
"Failed urls\n" + "Failed urls\n" +
getFailedFiles().join("\n\t") + getFailedFiles().join("\n\t") +
"\n" ".\n"
"If this continues to happen please check the logs of the application" "If this continues to happen please check the logs of the application.\n"
"Do you want to retry?", "Do you want to retry?",
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
->exec(); ->exec();
@ -163,6 +164,12 @@ void NetJob::emitFailed(QString reason)
executeNextSubTask(); executeNextSubTask();
return; return;
} }
}
#endif #endif
ConcurrentTask::emitFailed(reason); ConcurrentTask::emitFailed(reason);
} }
void NetJob::setAskRetry(bool askRetry)
{
m_ask_retry = askRetry;
}

View File

@ -62,6 +62,7 @@ class NetJob : public ConcurrentTask {
auto getFailedActions() -> QList<Net::NetRequest*>; auto getFailedActions() -> QList<Net::NetRequest*>;
auto getFailedFiles() -> QList<QString>; auto getFailedFiles() -> QList<QString>;
void setAskRetry(bool askRetry);
public slots: public slots:
// Qt can't handle auto at the start for some reason? // Qt can't handle auto at the start for some reason?
@ -78,4 +79,5 @@ class NetJob : public ConcurrentTask {
shared_qobject_ptr<QNetworkAccessManager> m_network; shared_qobject_ptr<QNetworkAccessManager> m_network;
int m_try = 1; int m_try = 1;
bool m_ask_retry = true;
}; };

View File

@ -345,9 +345,9 @@ void SkinManageDialog::on_urlBtn_clicked()
CustomMessageBox::selectable(this, tr("Invalid url"), tr("Invalid url"), QMessageBox::Critical)->show(); CustomMessageBox::selectable(this, tr("Invalid url"), tr("Invalid url"), QMessageBox::Critical)->show();
return; return;
} }
ui->urlLine->setText("");
NetJob::Ptr job{ new NetJob(tr("Download skin"), APPLICATION->network()) }; NetJob::Ptr job{ new NetJob(tr("Download skin"), APPLICATION->network()) };
job->setAskRetry(false);
auto path = FS::PathCombine(m_list.getDir(), url.fileName()); auto path = FS::PathCombine(m_list.getDir(), url.fileName());
job->addNetAction(Net::Download::makeFile(url, path)); job->addNetAction(Net::Download::makeFile(url, path));
@ -361,6 +361,7 @@ void SkinManageDialog::on_urlBtn_clicked()
QFile::remove(path); QFile::remove(path);
return; return;
} }
ui->urlLine->setText("");
if (QFileInfo(path).suffix().isEmpty()) { if (QFileInfo(path).suffix().isEmpty()) {
QFile::rename(path, path + ".png"); QFile::rename(path, path + ".png");
} }
@ -397,11 +398,11 @@ void SkinManageDialog::on_userBtn_clicked()
if (user.isEmpty()) { if (user.isEmpty()) {
return; return;
} }
ui->urlLine->setText("");
MinecraftProfile mcProfile; MinecraftProfile mcProfile;
auto path = FS::PathCombine(m_list.getDir(), user + ".png"); auto path = FS::PathCombine(m_list.getDir(), user + ".png");
NetJob::Ptr job{ new NetJob(tr("Download user skin"), APPLICATION->network(), 1) }; NetJob::Ptr job{ new NetJob(tr("Download user skin"), APPLICATION->network(), 1) };
job->setAskRetry(false);
auto uuidOut = std::make_shared<QByteArray>(); auto uuidOut = std::make_shared<QByteArray>();
auto profileOut = std::make_shared<QByteArray>(); auto profileOut = std::make_shared<QByteArray>();
@ -459,6 +460,14 @@ void SkinManageDialog::on_userBtn_clicked()
dlg.execWithTask(job.get()); dlg.execWithTask(job.get());
SkinModel s(path); SkinModel s(path);
if (!s.isValid()) {
CustomMessageBox::selectable(this, tr("Usename not found"), tr("Unable to find the skin for '%1'.").arg(user),
QMessageBox::Critical)
->show();
QFile::remove(path);
return;
}
ui->urlLine->setText("");
s.setModel(mcProfile.skin.variant.toUpper() == "SLIM" ? SkinModel::SLIM : SkinModel::CLASSIC); s.setModel(mcProfile.skin.variant.toUpper() == "SLIM" ? SkinModel::SLIM : SkinModel::CLASSIC);
s.setURL(mcProfile.skin.url); s.setURL(mcProfile.skin.url);
if (m_capes.contains(mcProfile.currentCape)) { if (m_capes.contains(mcProfile.currentCape)) {