MCPcopy Create free account
hub / github.com/PrismLauncher/PrismLauncher / downloadJava

Method downloadJava

launcher/java/download/ManifestDownloadTask.cpp:74–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74void 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
128bool ManifestDownloadTask::abort()
129{

Callers

nothing calls this directly

Calls 13

ensureFolderPathExistsFunction · 0.85
PathCombineFunction · 0.85
QUrlClass · 0.85
QFileClass · 0.85
objectMethod · 0.80
networkMethod · 0.80
addNetActionMethod · 0.80
toStringMethod · 0.45
isEmptyMethod · 0.45
isValidMethod · 0.45
addValidatorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected