| 72 | } |
| 73 | |
| 74 | void ManifestDownloadTask::downloadJava(const QJsonDocument& doc) |
| 75 | { |
| 76 | // valid json doc, begin making jre spot |
| 77 | FS::ensureFolderPathExists(m_final_path); |
| 78 | std::vector<File> toDownload; |
| 79 | auto list = doc.object()["files"].toObject(); |
| 80 | for (const auto& paths : list.keys()) { |
| 81 | auto file = FS::PathCombine(m_final_path, paths); |
| 82 | |
| 83 | const QJsonObject& meta = list[paths].toObject(); |
| 84 | auto type = meta["type"].toString(); |
| 85 | if (type == "directory") { |
| 86 | FS::ensureFolderPathExists(file); |
| 87 | } else if (type == "link") { |
| 88 | // this is *nix only ! |
| 89 | auto path = meta["target"].toString(); |
| 90 | if (!path.isEmpty()) { |
| 91 | QFile::link(path, file); |
| 92 | } |
| 93 | } else if (type == "file") { |
| 94 | // TODO download compressed version if it exists ? |
| 95 | auto raw = meta["downloads"].toObject()["raw"].toObject(); |
| 96 | auto isExec = meta["executable"].toBool(); |
| 97 | auto url = raw["url"].toString(); |
| 98 | if (!url.isEmpty() && QUrl(url).isValid()) { |
| 99 | auto f = File{ file, url, QByteArray::fromHex(raw["sha1"].toString().toLatin1()), isExec }; |
| 100 | toDownload.push_back(f); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | auto elementDownload = makeShared<NetJob>("JRE::FileDownload", APPLICATION->network()); |
| 105 | for (const auto& file : toDownload) { |
| 106 | auto dl = Net::Download::makeFile(file.url, file.path); |
| 107 | if (!file.hash.isEmpty()) { |
| 108 | dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, file.hash)); |
| 109 | } |
| 110 | if (file.isExec) { |
| 111 | connect(dl.get(), &Net::Download::succeeded, |
| 112 | [file] { QFile(file.path).setPermissions(QFile(file.path).permissions() | QFileDevice::Permissions(0x1111)); }); |
| 113 | } |
| 114 | elementDownload->addNetAction(dl); |
| 115 | } |
| 116 | |
| 117 | connect(elementDownload.get(), &Task::failed, this, &ManifestDownloadTask::emitFailed); |
| 118 | connect(elementDownload.get(), &Task::progress, this, &ManifestDownloadTask::setProgress); |
| 119 | connect(elementDownload.get(), &Task::stepProgress, this, &ManifestDownloadTask::propagateStepProgress); |
| 120 | connect(elementDownload.get(), &Task::status, this, &ManifestDownloadTask::setStatus); |
| 121 | connect(elementDownload.get(), &Task::details, this, &ManifestDownloadTask::setDetails); |
| 122 | |
| 123 | connect(elementDownload.get(), &Task::succeeded, this, &ManifestDownloadTask::emitSucceeded); |
| 124 | m_task = elementDownload; |
| 125 | m_task->start(); |
| 126 | } |
| 127 | |
| 128 | bool ManifestDownloadTask::abort() |
| 129 | { |
nothing calls this directly
no test coverage detected