2016-03-07 06:31:28 +05:30
|
|
|
#include "Library.h"
|
2016-10-02 03:56:10 +05:30
|
|
|
#include "MinecraftInstance.h"
|
|
|
|
|
2016-05-28 23:24:17 +05:30
|
|
|
#include <net/Download.h>
|
|
|
|
#include <net/ChecksumValidator.h>
|
2015-10-05 05:17:27 +05:30
|
|
|
#include <FileSystem.h>
|
2020-07-18 19:48:02 +05:30
|
|
|
#include <BuildConfig.h>
|
2014-05-09 20:46:25 +05:30
|
|
|
|
2016-10-02 03:56:10 +05:30
|
|
|
|
|
|
|
void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& native, QStringList& native32,
|
2018-07-15 18:21:05 +05:30
|
|
|
QStringList& native64, const QString &overridePath) const
|
2014-07-27 02:30:35 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
bool local = isLocal();
|
|
|
|
auto actualPath = [&](QString relPath)
|
|
|
|
{
|
|
|
|
QFileInfo out(FS::PathCombine(storagePrefix(), relPath));
|
|
|
|
if(local && !overridePath.isEmpty())
|
|
|
|
{
|
|
|
|
QString fileName = out.fileName();
|
2018-11-12 04:20:36 +05:30
|
|
|
return QFileInfo(FS::PathCombine(overridePath, fileName)).absoluteFilePath();
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
return out.absoluteFilePath();
|
|
|
|
};
|
|
|
|
QString raw_storage = storageSuffix(system);
|
|
|
|
if(isNative())
|
|
|
|
{
|
|
|
|
if (raw_storage.contains("${arch}"))
|
|
|
|
{
|
|
|
|
auto nat32Storage = raw_storage;
|
|
|
|
nat32Storage.replace("${arch}", "32");
|
|
|
|
auto nat64Storage = raw_storage;
|
|
|
|
nat64Storage.replace("${arch}", "64");
|
|
|
|
native32 += actualPath(nat32Storage);
|
|
|
|
native64 += actualPath(nat64Storage);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
native += actualPath(raw_storage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
jar += actualPath(raw_storage);
|
|
|
|
}
|
2014-07-27 02:30:35 +05:30
|
|
|
}
|
2015-05-31 22:54:39 +05:30
|
|
|
|
2021-11-22 03:51:12 +05:30
|
|
|
QList<NetAction::Ptr> Library::getDownloads(
|
2018-11-26 07:36:58 +05:30
|
|
|
OpSys system,
|
|
|
|
class HttpMetaCache* cache,
|
|
|
|
QStringList& failedLocalFiles,
|
|
|
|
const QString & overridePath
|
|
|
|
) const
|
2014-07-27 02:30:35 +05:30
|
|
|
{
|
2021-11-22 03:51:12 +05:30
|
|
|
QList<NetAction::Ptr> out;
|
2018-11-26 07:36:58 +05:30
|
|
|
bool stale = isAlwaysStale();
|
2018-07-15 18:21:05 +05:30
|
|
|
bool local = isLocal();
|
2018-11-26 07:36:58 +05:30
|
|
|
|
|
|
|
auto check_local_file = [&](QString storage)
|
|
|
|
{
|
|
|
|
QFileInfo fileinfo(storage);
|
|
|
|
QString fileName = fileinfo.fileName();
|
|
|
|
auto fullPath = FS::PathCombine(overridePath, fileName);
|
|
|
|
QFileInfo localFileInfo(fullPath);
|
|
|
|
if(!localFileInfo.exists())
|
|
|
|
{
|
|
|
|
failedLocalFiles.append(localFileInfo.filePath());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2014-07-27 02:30:35 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
auto add_download = [&](QString storage, QString url, QString sha1)
|
|
|
|
{
|
2018-11-26 07:36:58 +05:30
|
|
|
if(local)
|
|
|
|
{
|
|
|
|
return check_local_file(storage);
|
|
|
|
}
|
2018-07-15 18:21:05 +05:30
|
|
|
auto entry = cache->resolveEntry("libraries", storage);
|
2018-11-26 07:36:58 +05:30
|
|
|
if(stale)
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
|
|
|
entry->setStale(true);
|
|
|
|
}
|
|
|
|
if (!entry->isStale())
|
|
|
|
return true;
|
|
|
|
Net::Download::Options options;
|
2018-11-26 07:36:58 +05:30
|
|
|
if(stale)
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
|
|
|
options |= Net::Download::Option::AcceptLocalFiles;
|
|
|
|
}
|
2020-05-19 18:43:16 +05:30
|
|
|
|
|
|
|
if(sha1.size())
|
2018-07-15 18:21:05 +05:30
|
|
|
{
|
2020-05-19 18:43:16 +05:30
|
|
|
auto rawSha1 = QByteArray::fromHex(sha1.toLatin1());
|
|
|
|
auto dl = Net::Download::makeCached(url, entry, options);
|
|
|
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
|
2021-04-01 07:20:28 +05:30
|
|
|
qDebug() << "Checksummed Download for:" << rawName().serialize() << "storage:" << storage << "url:" << url;
|
2020-05-19 18:43:16 +05:30
|
|
|
out.append(dl);
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-19 18:43:16 +05:30
|
|
|
out.append(Net::Download::makeCached(url, entry, options));
|
2021-04-01 07:20:28 +05:30
|
|
|
qDebug() << "Download for:" << rawName().serialize() << "storage:" << storage << "url:" << url;
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2014-07-27 02:30:35 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
QString raw_storage = storageSuffix(system);
|
|
|
|
if(m_mojangDownloads)
|
|
|
|
{
|
|
|
|
if(isNative())
|
|
|
|
{
|
|
|
|
if(m_nativeClassifiers.contains(system))
|
|
|
|
{
|
|
|
|
auto nativeClassifier = m_nativeClassifiers[system];
|
|
|
|
if(nativeClassifier.contains("${arch}"))
|
|
|
|
{
|
|
|
|
auto nat32Classifier = nativeClassifier;
|
|
|
|
nat32Classifier.replace("${arch}", "32");
|
|
|
|
auto nat64Classifier = nativeClassifier;
|
|
|
|
nat64Classifier.replace("${arch}", "64");
|
|
|
|
auto nat32info = m_mojangDownloads->getDownloadInfo(nat32Classifier);
|
|
|
|
if(nat32info)
|
|
|
|
{
|
|
|
|
auto cooked_storage = raw_storage;
|
|
|
|
cooked_storage.replace("${arch}", "32");
|
|
|
|
add_download(cooked_storage, nat32info->url, nat32info->sha1);
|
|
|
|
}
|
|
|
|
auto nat64info = m_mojangDownloads->getDownloadInfo(nat64Classifier);
|
|
|
|
if(nat64info)
|
|
|
|
{
|
|
|
|
auto cooked_storage = raw_storage;
|
|
|
|
cooked_storage.replace("${arch}", "64");
|
|
|
|
add_download(cooked_storage, nat64info->url, nat64info->sha1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto info = m_mojangDownloads->getDownloadInfo(nativeClassifier);
|
|
|
|
if(info)
|
|
|
|
{
|
|
|
|
add_download(raw_storage, info->url, info->sha1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-01 07:20:28 +05:30
|
|
|
qDebug() << "Ignoring native library" << m_name.serialize() << "because it has no classifier for current OS";
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(m_mojangDownloads->artifact)
|
|
|
|
{
|
|
|
|
auto artifact = m_mojangDownloads->artifact;
|
|
|
|
add_download(raw_storage, artifact->url, artifact->sha1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-01 07:20:28 +05:30
|
|
|
qDebug() << "Ignoring java library" << m_name.serialize() << "because it has no artifact";
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-26 07:36:58 +05:30
|
|
|
auto raw_dl = [&]()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if (!m_absoluteURL.isEmpty())
|
|
|
|
{
|
|
|
|
return m_absoluteURL;
|
|
|
|
}
|
2016-03-26 21:26:57 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
if (m_repositoryURL.isEmpty())
|
|
|
|
{
|
2020-07-18 19:48:02 +05:30
|
|
|
return BuildConfig.LIBRARY_BASE + raw_storage;
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
2016-03-26 21:26:57 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
if(m_repositoryURL.endsWith('/'))
|
|
|
|
{
|
|
|
|
return m_repositoryURL + raw_storage;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_repositoryURL + QChar('/') + raw_storage;
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
if (raw_storage.contains("${arch}"))
|
|
|
|
{
|
|
|
|
QString cooked_storage = raw_storage;
|
|
|
|
QString cooked_dl = raw_dl;
|
|
|
|
add_download(cooked_storage.replace("${arch}", "32"), cooked_dl.replace("${arch}", "32"), QString());
|
|
|
|
cooked_storage = raw_storage;
|
|
|
|
cooked_dl = raw_dl;
|
|
|
|
add_download(cooked_storage.replace("${arch}", "64"), cooked_dl.replace("${arch}", "64"), QString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
add_download(raw_storage, raw_dl, QString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
2014-07-27 02:30:35 +05:30
|
|
|
}
|
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
bool Library::isActive() const
|
2014-07-27 02:30:35 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
bool result = true;
|
|
|
|
if (m_rules.empty())
|
|
|
|
{
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RuleAction ruleResult = Disallow;
|
|
|
|
for (auto rule : m_rules)
|
|
|
|
{
|
|
|
|
RuleAction temp = rule->apply(this);
|
|
|
|
if (temp != Defer)
|
|
|
|
ruleResult = temp;
|
|
|
|
}
|
|
|
|
result = result && (ruleResult == Allow);
|
|
|
|
}
|
|
|
|
if (isNative())
|
|
|
|
{
|
|
|
|
result = result && m_nativeClassifiers.contains(currentSystem);
|
|
|
|
}
|
|
|
|
return result;
|
2014-07-27 02:30:35 +05:30
|
|
|
}
|
|
|
|
|
2017-04-18 02:21:30 +05:30
|
|
|
bool Library::isLocal() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return m_hint == "local";
|
2017-04-18 02:21:30 +05:30
|
|
|
}
|
|
|
|
|
2018-11-26 07:36:58 +05:30
|
|
|
bool Library::isAlwaysStale() const
|
|
|
|
{
|
|
|
|
return m_hint == "always-stale";
|
|
|
|
}
|
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
void Library::setStoragePrefix(QString prefix)
|
2015-05-27 05:00:18 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
m_storagePrefix = prefix;
|
2015-05-27 05:00:18 +05:30
|
|
|
}
|
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
QString Library::defaultStoragePrefix()
|
2015-05-27 05:00:18 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return "libraries/";
|
2015-05-27 05:00:18 +05:30
|
|
|
}
|
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
QString Library::storagePrefix() const
|
2015-05-27 05:00:18 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(m_storagePrefix.isEmpty())
|
|
|
|
{
|
|
|
|
return defaultStoragePrefix();
|
|
|
|
}
|
|
|
|
return m_storagePrefix;
|
2015-05-27 05:00:18 +05:30
|
|
|
}
|
|
|
|
|
2017-04-18 02:21:30 +05:30
|
|
|
QString Library::filename(OpSys system) const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(!m_filename.isEmpty())
|
|
|
|
{
|
|
|
|
return m_filename;
|
|
|
|
}
|
|
|
|
// non-native? use only the gradle specifier
|
|
|
|
if (!isNative())
|
|
|
|
{
|
|
|
|
return m_name.getFileName();
|
|
|
|
}
|
2017-04-18 02:21:30 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
// otherwise native, override classifiers. Mojang HACK!
|
|
|
|
GradleSpecifier nativeSpec = m_name;
|
|
|
|
if (m_nativeClassifiers.contains(system))
|
|
|
|
{
|
|
|
|
nativeSpec.setClassifier(m_nativeClassifiers[system]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nativeSpec.setClassifier("INVALID");
|
|
|
|
}
|
|
|
|
return nativeSpec.getFileName();
|
2017-04-18 02:21:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
QString Library::displayName(OpSys system) const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
if(!m_displayname.isEmpty())
|
|
|
|
return m_displayname;
|
|
|
|
return filename(system);
|
2017-04-18 02:21:30 +05:30
|
|
|
}
|
|
|
|
|
2016-03-26 21:26:57 +05:30
|
|
|
QString Library::storageSuffix(OpSys system) const
|
2014-05-11 16:07:21 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
// non-native? use only the gradle specifier
|
|
|
|
if (!isNative())
|
|
|
|
{
|
|
|
|
return m_name.toPath(m_filename);
|
|
|
|
}
|
2014-07-27 02:30:35 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
// otherwise native, override classifiers. Mojang HACK!
|
|
|
|
GradleSpecifier nativeSpec = m_name;
|
|
|
|
if (m_nativeClassifiers.contains(system))
|
|
|
|
{
|
|
|
|
nativeSpec.setClassifier(m_nativeClassifiers[system]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nativeSpec.setClassifier("INVALID");
|
|
|
|
}
|
|
|
|
return nativeSpec.toPath(m_filename);
|
2014-05-11 16:07:21 +05:30
|
|
|
}
|