| 214 | } |
| 215 | |
| 216 | void PackInstallTask::downloadPack() |
| 217 | { |
| 218 | setStatus(tr("Downloading mods...")); |
| 219 | |
| 220 | auto* jobPtr = new NetJob(tr("Mod download"), APPLICATION->network()); |
| 221 | for (auto const& file : m_version.files) { |
| 222 | if (file.serverOnly || file.url.isEmpty()) |
| 223 | continue; |
| 224 | |
| 225 | QFileInfo file_info(file.name); |
| 226 | auto cacheName = file_info.completeBaseName() + "-" + file.sha1 + "." + file_info.suffix(); |
| 227 | |
| 228 | auto entry = APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", cacheName); |
| 229 | entry->setStale(true); |
| 230 | |
| 231 | auto relpath = FS::PathCombine("minecraft", file.path, file.name); |
| 232 | auto path = FS::PathCombine(m_stagingPath, relpath); |
| 233 | |
| 234 | if (m_files_to_copy.contains(path)) { |
| 235 | qWarning() << "Ignoring" << file.url << "as a file of that path is already downloading."; |
| 236 | continue; |
| 237 | } |
| 238 | |
| 239 | qDebug() << "Will download" << file.url << "to" << path; |
| 240 | m_files_to_copy[path] = entry->getFullPath(); |
| 241 | |
| 242 | auto dl = Net::Download::makeCached(file.url, entry); |
| 243 | if (!file.sha1.isEmpty()) { |
| 244 | auto rawSha1 = QByteArray::fromHex(file.sha1.toLatin1()); |
| 245 | dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1)); |
| 246 | } |
| 247 | |
| 248 | jobPtr->addNetAction(dl); |
| 249 | } |
| 250 | |
| 251 | connect(jobPtr, &NetJob::succeeded, this, &PackInstallTask::onModDownloadSucceeded); |
| 252 | connect(jobPtr, &NetJob::failed, this, &PackInstallTask::onModDownloadFailed); |
| 253 | connect(jobPtr, &NetJob::progress, this, &PackInstallTask::setProgress); |
| 254 | |
| 255 | m_net_job = jobPtr; |
| 256 | jobPtr->start(); |
| 257 | |
| 258 | m_abortable = true; |
| 259 | } |
| 260 | |
| 261 | void PackInstallTask::onModDownloadSucceeded() |
| 262 | { |
nothing calls this directly
no test coverage detected