summaryrefslogtreecommitdiffstats
path: root/libmultimc/include/library.h
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-07-27 11:41:45 +0200
committerPetr Mrázek <peterix@gmail.com>2013-07-27 11:41:45 +0200
commita7a84d4dbb58565f108cb0886da6cb786e34d10d (patch)
tree1337bc6c5f428fe1bc8c1c7bac209cb10fa7a0ab /libmultimc/include/library.h
parent97cf08f964ceebf4cb98b46f473bf952007a8a21 (diff)
downloadMultiMC-a7a84d4dbb58565f108cb0886da6cb786e34d10d.tar
MultiMC-a7a84d4dbb58565f108cb0886da6cb786e34d10d.tar.gz
MultiMC-a7a84d4dbb58565f108cb0886da6cb786e34d10d.tar.lz
MultiMC-a7a84d4dbb58565f108cb0886da6cb786e34d10d.tar.xz
MultiMC-a7a84d4dbb58565f108cb0886da6cb786e34d10d.zip
Parsing the version files, part III
Diffstat (limited to 'libmultimc/include/library.h')
-rw-r--r--libmultimc/include/library.h178
1 files changed, 131 insertions, 47 deletions
diff --git a/libmultimc/include/library.h b/libmultimc/include/library.h
index 30270bc1..8d97b4a6 100644
--- a/libmultimc/include/library.h
+++ b/libmultimc/include/library.h
@@ -19,33 +19,6 @@
class Library;
-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;
- };
-};
-
enum OpSys
{
Os_Windows,
@@ -73,6 +46,33 @@ OpSys OpSys_fromString(QString);
#endif
+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;
+ };
+};
+
class OsRule : public Rule
{
private:
@@ -85,9 +85,13 @@ protected:
{
return (m_system == currentSystem);
}
-public:
OsRule(RuleAction result, OpSys system, QString version_regexp)
: Rule(result), m_system(system), m_version_regexp(version_regexp) {}
+public:
+ static QSharedPointer<OsRule> create(RuleAction result, OpSys system, QString version_regexp)
+ {
+ return QSharedPointer<OsRule> (new OsRule(result, system, version_regexp));
+ }
};
class ImplicitRule : public Rule
@@ -97,39 +101,119 @@ protected:
{
return true;
}
-public:
ImplicitRule(RuleAction result)
: Rule(result) {}
+public:
+ static QSharedPointer<ImplicitRule> create(RuleAction result)
+ {
+ return QSharedPointer<ImplicitRule> (new ImplicitRule(result));
+ }
};
class Library
{
+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;
public:
- QString base_url;
- QString name;
- QList<QSharedPointer<Rule> > rules;
- QMap<OpSys, QString> natives;
QStringList extract_excludes;
- void AddRule(RuleAction result)
+public:
+ /// finalize the library, processing the input values into derived values and state
+ void finalize()
{
- rules.append(QSharedPointer<Rule>(new ImplicitRule(result)));
+ QStringList parts = m_name.split(':');
+ QString relative = parts[0];
+ relative.replace('.','/');
+ relative += '/' + parts[1] + '/' + parts[2] + '/' + parts[1] + '-' + parts[2];
+ if(!m_is_native)
+ relative += ".jar";
+ else
+ {
+ if(m_native_suffixes.contains(currentSystem))
+ {
+ relative += "-" + m_native_suffixes[currentSystem] + ".jar";
+ }
+ else
+ {
+ // really, bad.
+ relative += ".jar";
+ }
+ }
+ m_storage_path = relative;
+ m_download_path = m_base_url + relative;
+
+ if(m_rules.empty())
+ {
+ m_is_active = true;
+ }
+ else
+ {
+ RuleAction result = Disallow;
+ for(auto rule: m_rules)
+ {
+ RuleAction temp = rule->apply( this );
+ if(temp != Defer)
+ result = temp;
+ }
+ m_is_active = (result == Allow);
+ }
+ if(m_is_native)
+ {
+ m_is_active = m_is_active && m_native_suffixes.contains(currentSystem);
+ }
+ };
+
+ Library(QString name)
+ {
+ m_is_native = false;
+ m_is_native = false;
+ m_name = name;
+ m_base_url = "https://s3.amazonaws.com/Minecraft.Download/libraries/";
+ }
+
+ void setName(QString name)
+ {
+ m_name = name;
}
- void AddRule(RuleAction result, OpSys system, QString version_regexp)
+
+ void setBaseUrl(QString base_url)
{
- rules.append(QSharedPointer<Rule>(new OsRule(result, system, version_regexp)));
+ m_base_url = base_url;
}
+
+ void setIsNative()
+ {
+ m_is_native = true;
+ }
+
+ void addNative(OpSys os, QString suffix)
+ {
+ m_is_native = true;
+ m_native_suffixes[os] = suffix;
+ }
+
+ void setRules(QList<QSharedPointer<Rule> > rules)
+ {
+ m_rules = rules;
+ }
+
bool applies()
{
- if(rules.empty())
- return true;
- RuleAction result = Disallow;
- for(auto rule: rules)
- {
- RuleAction temp = rule->apply( this );
- if(temp != Defer)
- result = temp;
- }
- return result == Allow;
+ return m_is_active;
}
};