2014-05-09 20:46:25 +05:30
|
|
|
#include "RawLibrary.h"
|
2015-10-05 05:17:27 +05:30
|
|
|
#include <FileSystem.h>
|
2014-05-09 20:46:25 +05:30
|
|
|
|
2014-07-27 02:30:35 +05:30
|
|
|
QStringList RawLibrary::files() const
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RawLibrary::filesExist(const QDir &base) const
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2015-05-31 21:21:20 +05:30
|
|
|
QString RawLibrary::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
|
|
|
}
|
|
|
|
|
|
|
|
bool RawLibrary::isActive() const
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-05-27 05:00:18 +05:30
|
|
|
void RawLibrary::setStoragePrefix(QString prefix)
|
|
|
|
{
|
|
|
|
m_storagePrefix = prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RawLibrary::defaultStoragePrefix()
|
|
|
|
{
|
|
|
|
return "libraries/";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RawLibrary::storagePrefix() const
|
|
|
|
{
|
|
|
|
if(m_storagePrefix.isEmpty())
|
|
|
|
{
|
|
|
|
return defaultStoragePrefix();
|
|
|
|
}
|
|
|
|
return m_storagePrefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RawLibrary::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
|
|
|
|
|
|
|
QString RawLibrary::storagePath() const
|
|
|
|
{
|
2015-10-05 05:17:27 +05:30
|
|
|
return FS::PathCombine(storagePrefix(), storageSuffix());
|
2015-05-27 05:00:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool RawLibrary::storagePathIsDefault() const
|
|
|
|
{
|
|
|
|
return m_storagePrefix.isEmpty();
|
|
|
|
}
|