2016-03-07 06:31:28 +05:30
|
|
|
#include "Library.h"
|
2015-10-05 05:17:27 +05:30
|
|
|
#include <FileSystem.h>
|
2014-05-09 20:46:25 +05:30
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
QStringList Library::files() const
|
2014-07-27 02:30:35 +05:30
|
|
|
{
|
|
|
|
QStringList retval;
|
2015-05-27 05:00:18 +05:30
|
|
|
QString storage = storageSuffix();
|
2014-07-27 02:30:35 +05:30
|
|
|
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 06:31:28 +05:30
|
|
|
bool Library::filesExist(const QDir &base) const
|
2014-07-27 02:30:35 +05:30
|
|
|
{
|
|
|
|
auto libFiles = files();
|
|
|
|
for(auto file: libFiles)
|
|
|
|
{
|
|
|
|
QFileInfo info(base, file);
|
2015-02-02 06:44:14 +05:30
|
|
|
qWarning() << info.absoluteFilePath() << "doesn't exist";
|
2014-07-27 02:30:35 +05:30
|
|
|
if (!info.exists())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-31 22:54:39 +05:30
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
QString Library::url() const
|
2014-07-27 02:30:35 +05:30
|
|
|
{
|
2015-05-27 05:00:18 +05:30
|
|
|
if (!m_absolute_url.isEmpty())
|
|
|
|
{
|
2014-07-27 02:30:35 +05:30
|
|
|
return m_absolute_url;
|
2015-05-27 05:00:18 +05:30
|
|
|
}
|
2014-07-27 02:30:35 +05:30
|
|
|
|
|
|
|
if (m_base_url.isEmpty())
|
|
|
|
{
|
2015-05-27 05:00:18 +05:30
|
|
|
return QString("https://" + URLConstants::LIBRARY_BASE) + storageSuffix();
|
2014-07-27 02:30:35 +05:30
|
|
|
}
|
|
|
|
|
2015-05-31 21:21:20 +05:30
|
|
|
if(m_base_url.endsWith('/'))
|
|
|
|
{
|
|
|
|
return m_base_url + storageSuffix();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_base_url + QChar('/') + storageSuffix();
|
|
|
|
}
|
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())
|
|
|
|
{
|
|
|
|
result = result && m_native_classifiers.contains(currentSystem);
|
|
|
|
}
|
|
|
|
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-07 06:31:28 +05:30
|
|
|
QString Library::storageSuffix() 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;
|
2015-05-27 05:00:18 +05:30
|
|
|
if (m_native_classifiers.contains(currentSystem))
|
2014-07-27 02:30:35 +05:30
|
|
|
{
|
|
|
|
nativeSpec.setClassifier(m_native_classifiers[currentSystem]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nativeSpec.setClassifier("INVALID");
|
|
|
|
}
|
|
|
|
return nativeSpec.toPath();
|
2014-05-11 16:07:21 +05:30
|
|
|
}
|
2015-05-27 05:00:18 +05:30
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
QString Library::storagePath() const
|
2015-05-27 05:00:18 +05:30
|
|
|
{
|
2015-10-05 05:17:27 +05:30
|
|
|
return FS::PathCombine(storagePrefix(), storageSuffix());
|
2015-05-27 05:00:18 +05:30
|
|
|
}
|
|
|
|
|
2016-03-07 06:31:28 +05:30
|
|
|
bool Library::storagePathIsDefault() const
|
2015-05-27 05:00:18 +05:30
|
|
|
{
|
|
|
|
return m_storagePrefix.isEmpty();
|
|
|
|
}
|