| 47 | } |
| 48 | |
| 49 | void Flame::FileResolvingTask::executeTask() |
| 50 | { |
| 51 | if (m_manifest.files.isEmpty()) { // no file to resolve so leave it empty and emit success immediately |
| 52 | emitSucceeded(); |
| 53 | return; |
| 54 | } |
| 55 | setStatus(tr("Resolving mod IDs...")); |
| 56 | setProgress(0, 3); |
| 57 | m_result.reset(new QByteArray()); |
| 58 | |
| 59 | QStringList fileIds; |
| 60 | for (auto file : m_manifest.files) { |
| 61 | fileIds.push_back(QString::number(file.fileId)); |
| 62 | } |
| 63 | m_task = flameAPI.getFiles(fileIds, m_result); |
| 64 | |
| 65 | auto step_progress = std::make_shared<TaskStepProgress>(); |
| 66 | connect(m_task.get(), &Task::finished, this, [this, step_progress]() { |
| 67 | step_progress->state = TaskStepState::Succeeded; |
| 68 | stepProgress(*step_progress); |
| 69 | netJobFinished(); |
| 70 | }); |
| 71 | connect(m_task.get(), &Task::failed, this, [this, step_progress](QString reason) { |
| 72 | step_progress->state = TaskStepState::Failed; |
| 73 | stepProgress(*step_progress); |
| 74 | emitFailed(reason); |
| 75 | }); |
| 76 | connect(m_task.get(), &Task::stepProgress, this, &FileResolvingTask::propagateStepProgress); |
| 77 | connect(m_task.get(), &Task::progress, this, [this, step_progress](qint64 current, qint64 total) { |
| 78 | qDebug() << "Resolve slug progress" << current << total; |
| 79 | step_progress->update(current, total); |
| 80 | stepProgress(*step_progress); |
| 81 | }); |
| 82 | connect(m_task.get(), &Task::status, this, [this, step_progress](QString status) { |
| 83 | step_progress->status = status; |
| 84 | stepProgress(*step_progress); |
| 85 | }); |
| 86 | |
| 87 | m_task->start(); |
| 88 | } |
| 89 | |
| 90 | void Flame::FileResolvingTask::netJobFinished() |
| 91 | { |