| 114 | } |
| 115 | |
| 116 | void ExportPackDialog::done(int result) |
| 117 | { |
| 118 | auto settings = instance->settings(); |
| 119 | settings->set("ExportName", ui->name->text()); |
| 120 | settings->set("ExportVersion", ui->version->text()); |
| 121 | settings->set("ExportOptionalFiles", ui->optionalFiles->isChecked()); |
| 122 | |
| 123 | if (m_provider == ModPlatform::ResourceProvider::MODRINTH) |
| 124 | settings->set("ExportSummary", ui->summary->toPlainText()); |
| 125 | else |
| 126 | settings->set("ExportAuthor", ui->author->text()); |
| 127 | |
| 128 | if (result == Accepted) { |
| 129 | const QString name = ui->name->text().isEmpty() ? instance->name() : ui->name->text(); |
| 130 | const QString filename = FS::RemoveInvalidFilenameChars(name); |
| 131 | |
| 132 | QString output; |
| 133 | if (m_provider == ModPlatform::ResourceProvider::MODRINTH) { |
| 134 | output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(name), FS::PathCombine(QDir::homePath(), filename + ".mrpack"), |
| 135 | tr("Modrinth pack") + " (*.mrpack *.zip)", nullptr); |
| 136 | if (output.isEmpty()) |
| 137 | return; |
| 138 | if (!(output.endsWith(".zip") || output.endsWith(".mrpack"))) |
| 139 | output.append(".mrpack"); |
| 140 | } else { |
| 141 | output = QFileDialog::getSaveFileName(this, tr("Export %1").arg(name), FS::PathCombine(QDir::homePath(), filename + ".zip"), |
| 142 | tr("CurseForge pack") + " (*.zip)", nullptr); |
| 143 | if (output.isEmpty()) |
| 144 | return; |
| 145 | if (!output.endsWith(".zip")) |
| 146 | output.append(".zip"); |
| 147 | } |
| 148 | |
| 149 | Task* task; |
| 150 | if (m_provider == ModPlatform::ResourceProvider::MODRINTH) { |
| 151 | task = new ModrinthPackExportTask(name, ui->version->text(), ui->summary->toPlainText(), ui->optionalFiles->isChecked(), |
| 152 | instance, output, std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1)); |
| 153 | } else { |
| 154 | task = new FlamePackExportTask(name, ui->version->text(), ui->author->text(), ui->optionalFiles->isChecked(), instance, output, |
| 155 | std::bind(&FileIgnoreProxy::filterFile, proxy, std::placeholders::_1)); |
| 156 | } |
| 157 | |
| 158 | connect(task, &Task::failed, |
| 159 | [this](const QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); }); |
| 160 | connect(task, &Task::aborted, [this] { |
| 161 | CustomMessageBox::selectable(this, tr("Task aborted"), tr("The task has been aborted by the user."), QMessageBox::Information) |
| 162 | ->show(); |
| 163 | }); |
| 164 | connect(task, &Task::finished, [task] { task->deleteLater(); }); |
| 165 | |
| 166 | ProgressDialog progress(this); |
| 167 | progress.setSkipButton(true, tr("Abort")); |
| 168 | if (progress.execWithTask(task) != QDialog::Accepted) |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | QDialog::done(result); |
| 173 | } |
nothing calls this directly
no test coverage detected