| 80 | } |
| 81 | |
| 82 | QList<NetAction::Ptr> Library::getDownloads( |
| 83 | const RuntimeContext & runtimeContext, |
| 84 | class HttpMetaCache* cache, |
| 85 | QStringList& failedLocalFiles, |
| 86 | const QString & overridePath |
| 87 | ) const |
| 88 | { |
| 89 | QList<NetAction::Ptr> out; |
| 90 | bool stale = isAlwaysStale(); |
| 91 | bool local = isLocal(); |
| 92 | |
| 93 | auto check_local_file = [&](QString storage) |
| 94 | { |
| 95 | QFileInfo fileinfo(storage); |
| 96 | QString fileName = fileinfo.fileName(); |
| 97 | auto fullPath = FS::PathCombine(overridePath, fileName); |
| 98 | QFileInfo localFileInfo(fullPath); |
| 99 | if(!localFileInfo.exists()) |
| 100 | { |
| 101 | failedLocalFiles.append(localFileInfo.filePath()); |
| 102 | return false; |
| 103 | } |
| 104 | return true; |
| 105 | }; |
| 106 | |
| 107 | auto add_download = [&](QString storage, QString url, QString sha1) |
| 108 | { |
| 109 | if(local) |
| 110 | { |
| 111 | return check_local_file(storage); |
| 112 | } |
| 113 | auto entry = cache->resolveEntry("libraries", storage); |
| 114 | if(stale) |
| 115 | { |
| 116 | entry->setStale(true); |
| 117 | } |
| 118 | if (!entry->isStale()) |
| 119 | return true; |
| 120 | Net::Download::Options options; |
| 121 | if(stale) |
| 122 | { |
| 123 | options |= Net::Download::Option::AcceptLocalFiles; |
| 124 | } |
| 125 | |
| 126 | // Don't add a time limit for the libraries cache entry validity |
| 127 | options |= Net::Download::Option::MakeEternal; |
| 128 | |
| 129 | if(sha1.size()) |
| 130 | { |
| 131 | auto rawSha1 = QByteArray::fromHex(sha1.toLatin1()); |
| 132 | auto dl = Net::Download::makeCached(url, entry, options); |
| 133 | dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1)); |
| 134 | qDebug() << "Checksummed Download for:" << rawName().serialize() << "storage:" << storage << "url:" << url; |
| 135 | out.append(dl); |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | out.append(Net::Download::makeCached(url, entry, options)); |