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