2013-07-22 00:01:56 +00:00
|
|
|
/* Copyright 2013 MultiMC Contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-07-24 21:44:00 +00:00
|
|
|
#include <QtCore>
|
2013-07-22 00:01:56 +00:00
|
|
|
|
2013-07-24 21:44:00 +00:00
|
|
|
class Library;
|
|
|
|
|
|
|
|
enum OpSys
|
|
|
|
{
|
|
|
|
Os_Windows,
|
|
|
|
Os_Linux,
|
|
|
|
Os_OSX,
|
|
|
|
Os_Other
|
|
|
|
};
|
|
|
|
|
|
|
|
OpSys OpSys_fromString(QString);
|
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
#define currentSystem Os_OSX
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
#define currentSystem Os_Linux
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
#define currentSystem Os_Windows
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef currentSystem
|
|
|
|
#define currentSystem Os_Other
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-07-27 09:41:45 +00:00
|
|
|
enum RuleAction
|
|
|
|
{
|
|
|
|
Allow,
|
|
|
|
Disallow,
|
|
|
|
Defer
|
|
|
|
};
|
|
|
|
|
|
|
|
RuleAction RuleAction_fromString(QString);
|
|
|
|
|
|
|
|
class Rule
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
RuleAction m_result;
|
|
|
|
virtual bool applies(Library * parent) = 0;
|
|
|
|
public:
|
|
|
|
Rule(RuleAction result)
|
|
|
|
:m_result(result) {}
|
|
|
|
virtual ~Rule(){};
|
|
|
|
RuleAction apply(Library * parent)
|
|
|
|
{
|
|
|
|
if(applies(parent))
|
|
|
|
return m_result;
|
|
|
|
else
|
|
|
|
return Defer;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-07-24 21:44:00 +00:00
|
|
|
class OsRule : public Rule
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// the OS
|
|
|
|
OpSys m_system;
|
|
|
|
// the OS version regexp
|
|
|
|
QString m_version_regexp;
|
|
|
|
protected:
|
|
|
|
virtual bool applies ( Library* )
|
|
|
|
{
|
|
|
|
return (m_system == currentSystem);
|
|
|
|
}
|
|
|
|
OsRule(RuleAction result, OpSys system, QString version_regexp)
|
|
|
|
: Rule(result), m_system(system), m_version_regexp(version_regexp) {}
|
2013-07-27 09:41:45 +00:00
|
|
|
public:
|
|
|
|
static QSharedPointer<OsRule> create(RuleAction result, OpSys system, QString version_regexp)
|
|
|
|
{
|
|
|
|
return QSharedPointer<OsRule> (new OsRule(result, system, version_regexp));
|
|
|
|
}
|
2013-07-24 21:44:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ImplicitRule : public Rule
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual bool applies ( Library* )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ImplicitRule(RuleAction result)
|
|
|
|
: Rule(result) {}
|
2013-07-27 09:41:45 +00:00
|
|
|
public:
|
|
|
|
static QSharedPointer<ImplicitRule> create(RuleAction result)
|
|
|
|
{
|
|
|
|
return QSharedPointer<ImplicitRule> (new ImplicitRule(result));
|
|
|
|
}
|
2013-07-24 21:44:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Library
|
|
|
|
{
|
2013-07-27 09:41:45 +00:00
|
|
|
private:
|
|
|
|
// basic values used internally (so far)
|
|
|
|
QString m_name;
|
|
|
|
QString m_base_url;
|
|
|
|
QList<QSharedPointer<Rule> > m_rules;
|
|
|
|
|
|
|
|
// derived values used for real things
|
|
|
|
/// where to store the lib locally
|
|
|
|
QString m_storage_path;
|
|
|
|
/// where to download the lib from
|
|
|
|
QString m_download_path;
|
|
|
|
/// is this lib actuall active on the current OS?
|
|
|
|
bool m_is_active;
|
|
|
|
|
|
|
|
// native lib?
|
|
|
|
bool m_is_native;
|
|
|
|
QMap<OpSys, QString> m_native_suffixes;
|
2013-07-24 21:44:00 +00:00
|
|
|
public:
|
|
|
|
QStringList extract_excludes;
|
|
|
|
|
2013-07-27 09:41:45 +00:00
|
|
|
public:
|
2013-07-28 06:40:15 +00:00
|
|
|
/// Constructor
|
2013-07-27 09:41:45 +00:00
|
|
|
Library(QString name)
|
|
|
|
{
|
|
|
|
m_is_native = false;
|
|
|
|
m_is_native = false;
|
|
|
|
m_name = name;
|
|
|
|
m_base_url = "https://s3.amazonaws.com/Minecraft.Download/libraries/";
|
|
|
|
}
|
|
|
|
|
2013-07-28 06:40:15 +00:00
|
|
|
/**
|
|
|
|
* finalize the library, processing the input values into derived values and state
|
|
|
|
*
|
|
|
|
* This SHALL be called after all the values are parsed or after any further change.
|
|
|
|
*/
|
|
|
|
void finalize();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the library composite name
|
|
|
|
*/
|
2013-07-27 09:41:45 +00:00
|
|
|
void setName(QString name)
|
|
|
|
{
|
|
|
|
m_name = name;
|
2013-07-24 21:44:00 +00:00
|
|
|
}
|
2013-07-27 09:41:45 +00:00
|
|
|
|
2013-07-28 06:40:15 +00:00
|
|
|
/**
|
|
|
|
* Set the url base for downloads
|
|
|
|
*/
|
2013-07-27 09:41:45 +00:00
|
|
|
void setBaseUrl(QString base_url)
|
2013-07-24 21:44:00 +00:00
|
|
|
{
|
2013-07-27 09:41:45 +00:00
|
|
|
m_base_url = base_url;
|
2013-07-24 21:44:00 +00:00
|
|
|
}
|
2013-07-27 09:41:45 +00:00
|
|
|
|
2013-07-28 06:40:15 +00:00
|
|
|
/**
|
|
|
|
* Call this to mark the library as 'native' (it's a zip archive with DLLs)
|
|
|
|
*/
|
2013-07-27 09:41:45 +00:00
|
|
|
void setIsNative()
|
|
|
|
{
|
|
|
|
m_is_native = true;
|
|
|
|
}
|
|
|
|
|
2013-07-28 06:40:15 +00:00
|
|
|
/**
|
|
|
|
* Attach a name suffix to the specified OS native
|
|
|
|
*/
|
2013-07-27 09:41:45 +00:00
|
|
|
void addNative(OpSys os, QString suffix)
|
|
|
|
{
|
|
|
|
m_is_native = true;
|
|
|
|
m_native_suffixes[os] = suffix;
|
|
|
|
}
|
|
|
|
|
2013-07-28 06:40:15 +00:00
|
|
|
/**
|
|
|
|
* Set the load rules
|
|
|
|
*/
|
2013-07-27 09:41:45 +00:00
|
|
|
void setRules(QList<QSharedPointer<Rule> > rules)
|
|
|
|
{
|
|
|
|
m_rules = rules;
|
|
|
|
}
|
|
|
|
|
2013-07-28 06:40:15 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the library should be loaded (or extracted, in case of natives)
|
|
|
|
*/
|
|
|
|
bool getIsActive()
|
2013-07-24 21:44:00 +00:00
|
|
|
{
|
2013-07-27 09:41:45 +00:00
|
|
|
return m_is_active;
|
2013-07-24 21:44:00 +00:00
|
|
|
}
|
2013-07-28 06:40:15 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the library is native
|
|
|
|
*/
|
|
|
|
bool getIsNative()
|
|
|
|
{
|
|
|
|
return m_is_native;
|
|
|
|
}
|
2013-07-24 21:44:00 +00:00
|
|
|
};
|