2016-03-07 01:01:28 +00:00
|
|
|
#include "Library.h"
|
2015-10-04 23:47:27 +00:00
|
|
|
#include <FileSystem.h>
|
2014-05-09 15:16:25 +00:00
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
QStringList Library::files() const
|
2014-07-26 21:00:35 +00:00
|
|
|
{
|
|
|
|
QStringList retval;
|
2015-05-26 23:30:18 +00:00
|
|
|
QString storage = storageSuffix();
|
2014-07-26 21:00:35 +00:00
|
|
|
if (storage.contains("${arch}"))
|
|
|
|
{
|
|
|
|
QString cooked_storage = storage;
|
|
|
|
cooked_storage.replace("${arch}", "32");
|
|
|
|
retval.append(cooked_storage);
|
|
|
|
cooked_storage = storage;
|
|
|
|
cooked_storage.replace("${arch}", "64");
|
|
|
|
retval.append(cooked_storage);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
retval.append(storage);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
bool Library::filesExist(const QDir &base) const
|
2014-07-26 21:00:35 +00:00
|
|
|
{
|
|
|
|
auto libFiles = files();
|
|
|
|
for(auto file: libFiles)
|
|
|
|
{
|
|
|
|
QFileInfo info(base, file);
|
2015-02-02 01:14:14 +00:00
|
|
|
qWarning() << info.absoluteFilePath() << "doesn't exist";
|
2014-07-26 21:00:35 +00:00
|
|
|
if (!info.exists())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-31 17:24:39 +00:00
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
QString Library::url() const
|
2014-07-26 21:00:35 +00:00
|
|
|
{
|
2015-05-26 23:30:18 +00:00
|
|
|
if (!m_absolute_url.isEmpty())
|
|
|
|
{
|
2014-07-26 21:00:35 +00:00
|
|
|
return m_absolute_url;
|
2015-05-26 23:30:18 +00:00
|
|
|
}
|
2014-07-26 21:00:35 +00:00
|
|
|
|
|
|
|
if (m_base_url.isEmpty())
|
|
|
|
{
|
2015-05-26 23:30:18 +00:00
|
|
|
return QString("https://" + URLConstants::LIBRARY_BASE) + storageSuffix();
|
2014-07-26 21:00:35 +00:00
|
|
|
}
|
|
|
|
|
2015-05-31 15:51:20 +00:00
|
|
|
if(m_base_url.endsWith('/'))
|
|
|
|
{
|
|
|
|
return m_base_url + storageSuffix();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_base_url + QChar('/') + storageSuffix();
|
|
|
|
}
|
2014-07-26 21:00:35 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
bool Library::isActive() const
|
2014-07-26 21:00:35 +00:00
|
|
|
{
|
|
|
|
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_native_classifiers.contains(currentSystem);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
void Library::setStoragePrefix(QString prefix)
|
2015-05-26 23:30:18 +00:00
|
|
|
{
|
|
|
|
m_storagePrefix = prefix;
|
|
|
|
}
|
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
QString Library::defaultStoragePrefix()
|
2015-05-26 23:30:18 +00:00
|
|
|
{
|
|
|
|
return "libraries/";
|
|
|
|
}
|
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
QString Library::storagePrefix() const
|
2015-05-26 23:30:18 +00:00
|
|
|
{
|
|
|
|
if(m_storagePrefix.isEmpty())
|
|
|
|
{
|
|
|
|
return defaultStoragePrefix();
|
|
|
|
}
|
|
|
|
return m_storagePrefix;
|
|
|
|
}
|
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
QString Library::storageSuffix() const
|
2014-05-11 10:37:21 +00:00
|
|
|
{
|
2014-07-26 21:00:35 +00:00
|
|
|
// non-native? use only the gradle specifier
|
|
|
|
if (!isNative())
|
|
|
|
{
|
|
|
|
return m_name.toPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise native, override classifiers. Mojang HACK!
|
|
|
|
GradleSpecifier nativeSpec = m_name;
|
2015-05-26 23:30:18 +00:00
|
|
|
if (m_native_classifiers.contains(currentSystem))
|
2014-07-26 21:00:35 +00:00
|
|
|
{
|
|
|
|
nativeSpec.setClassifier(m_native_classifiers[currentSystem]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nativeSpec.setClassifier("INVALID");
|
|
|
|
}
|
|
|
|
return nativeSpec.toPath();
|
2014-05-11 10:37:21 +00:00
|
|
|
}
|
2015-05-26 23:30:18 +00:00
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
QString Library::storagePath() const
|
2015-05-26 23:30:18 +00:00
|
|
|
{
|
2015-10-04 23:47:27 +00:00
|
|
|
return FS::PathCombine(storagePrefix(), storageSuffix());
|
2015-05-26 23:30:18 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
bool Library::storagePathIsDefault() const
|
2015-05-26 23:30:18 +00:00
|
|
|
{
|
|
|
|
return m_storagePrefix.isEmpty();
|
|
|
|
}
|