| 146 | } |
| 147 | |
| 148 | void InstanceImportTask::processZipPack() |
| 149 | { |
| 150 | setStatus(tr("Attempting to determine instance type")); |
| 151 | QDir extractDir(m_stagingPath); |
| 152 | qDebug() << "Attempting to create instance from" << m_archivePath; |
| 153 | |
| 154 | // open the zip and find relevant files in it |
| 155 | auto packZip = std::make_shared<QuaZip>(m_archivePath); |
| 156 | if (!packZip->open(QuaZip::mdUnzip)) { |
| 157 | emitFailed(tr("Unable to open supplied modpack zip file.")); |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | QuaZipDir packZipDir(packZip.get()); |
| 162 | qDebug() << "Attempting to determine instance type"; |
| 163 | |
| 164 | QString root; |
| 165 | |
| 166 | // NOTE: Prioritize modpack platforms that aren't searched for recursively. |
| 167 | // Especially Flame has a very common filename for its manifest, which may appear inside overrides for example |
| 168 | // https://docs.modrinth.com/docs/modpacks/format_definition/#storage |
| 169 | if (packZipDir.exists("/modrinth.index.json")) { |
| 170 | // process as Modrinth pack |
| 171 | qDebug() << "Modrinth:" << true; |
| 172 | m_modpackType = ModpackType::Modrinth; |
| 173 | } else if (packZipDir.exists("/bin/modpack.jar") || packZipDir.exists("/bin/version.json")) { |
| 174 | // process as Technic pack |
| 175 | qDebug() << "Technic:" << true; |
| 176 | extractDir.mkpath("minecraft"); |
| 177 | extractDir.cd("minecraft"); |
| 178 | m_modpackType = ModpackType::Technic; |
| 179 | } else { |
| 180 | root = getRootFromZip(packZip.get()); |
| 181 | setDetails(""); |
| 182 | } |
| 183 | if (m_modpackType == ModpackType::Unknown) { |
| 184 | emitFailed(tr("Archive does not contain a recognized modpack type.")); |
| 185 | return; |
| 186 | } |
| 187 | setStatus(tr("Extracting modpack")); |
| 188 | |
| 189 | // make sure we extract just the pack |
| 190 | auto zipTask = makeShared<MMCZip::ExtractZipTask>(packZip, extractDir, root); |
| 191 | |
| 192 | auto progressStep = std::make_shared<TaskStepProgress>(); |
| 193 | connect(zipTask.get(), &Task::finished, this, [this, progressStep] { |
| 194 | progressStep->state = TaskStepState::Succeeded; |
| 195 | stepProgress(*progressStep); |
| 196 | }); |
| 197 | |
| 198 | connect(zipTask.get(), &Task::succeeded, this, &InstanceImportTask::extractFinished, Qt::QueuedConnection); |
| 199 | connect(zipTask.get(), &Task::aborted, this, &InstanceImportTask::emitAborted); |
| 200 | connect(zipTask.get(), &Task::failed, this, [this, progressStep](QString reason) { |
| 201 | progressStep->state = TaskStepState::Failed; |
| 202 | stepProgress(*progressStep); |
| 203 | emitFailed(reason); |
| 204 | }); |
| 205 | connect(zipTask.get(), &Task::stepProgress, this, &InstanceImportTask::propagateStepProgress); |