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>
|
2016-03-26 21:26:57 +05:30
|
|
|
#include <minecraft/forge/ForgeXzDownload.h>
|
|
|
|
#include <Env.h>
|
2015-10-05 05:17:27 +05:30
|
|
|
#include <FileSystem.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,
|
|
|
|
QStringList& native64, const QString &overridePath) const
|
2014-07-27 02:30:35 +05:30
|
|
|
{
|
2016-10-02 03:56:10 +05:30
|
|
|
bool isLocal = (hint() == "local");
|
2016-03-26 21:26:57 +05:30
|
|
|
auto actualPath = [&](QString relPath)
|
2014-07-27 02:30:35 +05:30
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
QFileInfo out(FS::PathCombine(storagePrefix(), relPath));
|
2016-10-02 03:56:10 +05:30
|
|
|
if(isLocal && !overridePath.isEmpty())
|
|
|
|
{
|
|
|
|
QString fileName = out.fileName();
|
|
|
|
auto fullPath = FS::PathCombine(overridePath, fileName);
|
|
|
|
qDebug() << fullPath;
|
|
|
|
QFileInfo fileinfo(fullPath);
|
|
|
|
if(fileinfo.exists())
|
|
|
|
{
|
|
|
|
return fileinfo.absoluteFilePath();
|
|
|
|
}
|
|
|
|
}
|
2016-03-26 21:26:57 +05:30
|
|
|
return out.absoluteFilePath();
|
|
|
|
};
|
2017-04-15 15:10:22 +05:30
|
|
|
QString raw_storage = storageSuffix(system);
|
|
|
|
if(isNative())
|
2016-03-26 21:26:57 +05:30
|
|
|
{
|
2017-04-15 15:10:22 +05:30
|
|
|
if (raw_storage.contains("${arch}"))
|
2016-03-26 21:26:57 +05:30
|
|
|
{
|
2017-04-15 15:10:22 +05:30
|
|
|
auto nat32Storage = raw_storage;
|
|
|
|
nat32Storage.replace("${arch}", "32");
|
|
|
|
auto nat64Storage = raw_storage;
|
|
|
|
nat64Storage.replace("${arch}", "64");
|
|
|
|
native32 += actualPath(nat32Storage);
|
|
|
|
native64 += actualPath(nat64Storage);
|
2016-03-26 21:26:57 +05:30
|
|
|
}
|
2017-04-15 15:10:22 +05:30
|
|
|
else
|
2016-03-26 21:26:57 +05:30
|
|
|
{
|
2017-04-15 15:10:22 +05:30
|
|
|
native += actualPath(raw_storage);
|
2016-03-26 21:26:57 +05:30
|
|
|
}
|
2014-07-27 02:30:35 +05:30
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-15 15:10:22 +05:30
|
|
|
jar += actualPath(raw_storage);
|
2014-07-27 02:30:35 +05:30
|
|
|
}
|
|
|
|
}
|
2015-05-31 22:54:39 +05:30
|
|
|
|
2016-10-02 03:56:10 +05:30
|
|
|
QList< std::shared_ptr< NetAction > > Library::getDownloads(OpSys system, class HttpMetaCache* cache,
|
|
|
|
QStringList& failedFiles, const QString & overridePath) const
|
2014-07-27 02:30:35 +05:30
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
QList<NetActionPtr> out;
|
2016-06-14 01:23:56 +05:30
|
|
|
bool isAlwaysStale = (hint() == "always-stale");
|
2016-03-26 21:26:57 +05:30
|
|
|
bool isLocal = (hint() == "local");
|
|
|
|
bool isForge = (hint() == "forge-pack-xz");
|
2014-07-27 02:30:35 +05:30
|
|
|
|
2016-05-28 23:24:17 +05:30
|
|
|
auto add_download = [&](QString storage, QString url, QString sha1 = QString())
|
2014-07-27 02:30:35 +05:30
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
auto entry = cache->resolveEntry("libraries", storage);
|
2016-06-14 01:23:56 +05:30
|
|
|
if(isAlwaysStale)
|
|
|
|
{
|
|
|
|
entry->setStale(true);
|
|
|
|
}
|
2016-03-26 21:26:57 +05:30
|
|
|
if (!entry->isStale())
|
|
|
|
return true;
|
|
|
|
if(isLocal)
|
|
|
|
{
|
2016-10-02 03:56:10 +05:30
|
|
|
if(!overridePath.isEmpty())
|
|
|
|
{
|
|
|
|
QString fileName;
|
|
|
|
int position = storage.lastIndexOf('/');
|
|
|
|
if(position == -1)
|
|
|
|
{
|
|
|
|
fileName = storage;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fileName = storage.mid(position);
|
|
|
|
}
|
|
|
|
auto fullPath = FS::PathCombine(overridePath, fileName);
|
|
|
|
QFileInfo fileinfo(fullPath);
|
|
|
|
if(fileinfo.exists())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-03-26 21:26:57 +05:30
|
|
|
QFileInfo fileinfo(entry->getFullPath());
|
|
|
|
if(!fileinfo.exists())
|
|
|
|
{
|
|
|
|
failedFiles.append(entry->getFullPath());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-10-28 05:49:19 +05:30
|
|
|
Net::Download::Options options;
|
|
|
|
if(isAlwaysStale)
|
|
|
|
{
|
|
|
|
options |= Net::Download::Option::AcceptLocalFiles;
|
|
|
|
}
|
2016-03-26 21:26:57 +05:30
|
|
|
if (isForge)
|
|
|
|
{
|
|
|
|
out.append(ForgeXzDownload::make(storage, entry));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-28 23:24:17 +05:30
|
|
|
if(sha1.size())
|
|
|
|
{
|
|
|
|
auto rawSha1 = QByteArray::fromHex(sha1.toLatin1());
|
2016-10-28 05:49:19 +05:30
|
|
|
auto dl = Net::Download::makeCached(url, entry, options);
|
2016-05-28 23:24:17 +05:30
|
|
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
|
|
|
|
out.append(dl);
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2016-10-28 05:49:19 +05:30
|
|
|
out.append(Net::Download::makeCached(url, entry, options));
|
2016-03-26 21:26:57 +05:30
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2014-07-27 02:30:35 +05:30
|
|
|
|
2017-04-15 15:10:22 +05:30
|
|
|
QString raw_storage = storageSuffix(system);
|
2016-03-26 21:26:57 +05:30
|
|
|
if(m_mojangDownloads)
|
2015-05-31 21:21:20 +05:30
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
if(m_mojangDownloads->artifact)
|
|
|
|
{
|
|
|
|
auto artifact = m_mojangDownloads->artifact;
|
2017-04-15 15:10:22 +05:30
|
|
|
add_download(raw_storage, artifact->url, artifact->sha1);
|
2016-03-26 21:26:57 +05:30
|
|
|
}
|
|
|
|
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)
|
2017-04-15 15:10:22 +05:30
|
|
|
{
|
|
|
|
auto cooked_storage = raw_storage;
|
|
|
|
cooked_storage.replace("${arch}", "32");
|
|
|
|
add_download(cooked_storage, nat32info->url, nat32info->sha1);
|
|
|
|
}
|
2016-03-26 21:26:57 +05:30
|
|
|
auto nat64info = m_mojangDownloads->getDownloadInfo(nat64Classifier);
|
|
|
|
if(nat64info)
|
2017-04-15 15:10:22 +05:30
|
|
|
{
|
|
|
|
auto cooked_storage = raw_storage;
|
|
|
|
cooked_storage.replace("${arch}", "64");
|
|
|
|
add_download(cooked_storage, nat64info->url, nat64info->sha1);
|
|
|
|
}
|
2016-03-26 21:26:57 +05:30
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto info = m_mojangDownloads->getDownloadInfo(nativeClassifier);
|
|
|
|
if(info)
|
|
|
|
{
|
2017-04-15 15:10:22 +05:30
|
|
|
add_download(raw_storage, info->url, info->sha1);
|
2016-03-26 21:26:57 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-31 21:21:20 +05:30
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
auto raw_dl = [&](){
|
|
|
|
if (!m_absoluteURL.isEmpty())
|
|
|
|
{
|
|
|
|
return m_absoluteURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_repositoryURL.isEmpty())
|
|
|
|
{
|
|
|
|
return QString("https://" + URLConstants::LIBRARY_BASE) + raw_storage;
|
|
|
|
}
|
|
|
|
|
|
|
|
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"));
|
|
|
|
cooked_storage = raw_storage;
|
|
|
|
cooked_dl = raw_dl;
|
|
|
|
add_download(cooked_storage.replace("${arch}", "64"), cooked_dl.replace("${arch}", "64"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
add_download(raw_storage, raw_dl);
|
|
|
|
}
|
2015-05-31 21:21:20 +05:30
|
|
|
}
|
2016-03-26 21:26:57 +05:30
|
|
|
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
|
|
|
{
|
|
|
|
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())
|
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
result = result && m_nativeClassifiers.contains(currentSystem);
|
2014-07-27 02:30:35 +05:30
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
void Library::setStoragePrefix(QString prefix)
|
2015-05-27 05:00:18 +05:30
|
|
|
{
|
|
|
|
m_storagePrefix = prefix;
|
|
|
|
}
|
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
QString Library::defaultStoragePrefix()
|
2015-05-27 05:00:18 +05:30
|
|
|
{
|
|
|
|
return "libraries/";
|
|
|
|
}
|
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
QString Library::storagePrefix() const
|
2015-05-27 05:00:18 +05:30
|
|
|
{
|
|
|
|
if(m_storagePrefix.isEmpty())
|
|
|
|
{
|
|
|
|
return defaultStoragePrefix();
|
|
|
|
}
|
|
|
|
return m_storagePrefix;
|
|
|
|
}
|
|
|
|
|
2016-03-26 21:26:57 +05:30
|
|
|
QString Library::storageSuffix(OpSys system) const
|
2014-05-11 16:07:21 +05:30
|
|
|
{
|
2014-07-27 02:30:35 +05:30
|
|
|
// non-native? use only the gradle specifier
|
|
|
|
if (!isNative())
|
|
|
|
{
|
|
|
|
return m_name.toPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise native, override classifiers. Mojang HACK!
|
|
|
|
GradleSpecifier nativeSpec = m_name;
|
2016-03-26 21:26:57 +05:30
|
|
|
if (m_nativeClassifiers.contains(system))
|
2014-07-27 02:30:35 +05:30
|
|
|
{
|
2016-03-26 21:26:57 +05:30
|
|
|
nativeSpec.setClassifier(m_nativeClassifiers[system]);
|
2014-07-27 02:30:35 +05:30
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nativeSpec.setClassifier("INVALID");
|
|
|
|
}
|
|
|
|
return nativeSpec.toPath();
|
2014-05-11 16:07:21 +05:30
|
|
|
}
|