diff options
author | Petr Mrázek <peterix@gmail.com> | 2013-09-11 23:43:17 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2013-09-11 23:43:17 +0200 |
commit | 7721c57e5e1093a3d8597b6b6f30c97d2aa3d8a5 (patch) | |
tree | 5b8e5d3401d535c9f429d1bcdaa51e6968998470 /logic | |
parent | 108a5a677c4bf248b70e77046502ea96bd9cfe65 (diff) | |
download | MultiMC-7721c57e5e1093a3d8597b6b6f30c97d2aa3d8a5.tar MultiMC-7721c57e5e1093a3d8597b6b6f30c97d2aa3d8a5.tar.gz MultiMC-7721c57e5e1093a3d8597b6b6f30c97d2aa3d8a5.tar.lz MultiMC-7721c57e5e1093a3d8597b6b6f30c97d2aa3d8a5.tar.xz MultiMC-7721c57e5e1093a3d8597b6b6f30c97d2aa3d8a5.zip |
Split OneSixVersion into parts.
Diffstat (limited to 'logic')
-rw-r--r-- | logic/OneSixInstance_p.h | 1 | ||||
-rw-r--r-- | logic/OneSixLibrary.cpp | 84 | ||||
-rw-r--r-- | logic/OneSixLibrary.h | 68 | ||||
-rw-r--r-- | logic/OneSixRule.cpp | 10 | ||||
-rw-r--r-- | logic/OneSixRule.h | 70 | ||||
-rw-r--r-- | logic/OneSixUpdate.cpp | 1 | ||||
-rw-r--r-- | logic/OneSixVersion.cpp | 112 | ||||
-rw-r--r-- | logic/OneSixVersion.h | 153 | ||||
-rw-r--r-- | logic/OpSys.cpp | 12 | ||||
-rw-r--r-- | logic/OpSys.h | 21 | ||||
-rw-r--r-- | logic/VersionFactory.cpp | 3 |
11 files changed, 278 insertions, 257 deletions
diff --git a/logic/OneSixInstance_p.h b/logic/OneSixInstance_p.h index c098c9e2..7b1ca82e 100644 --- a/logic/OneSixInstance_p.h +++ b/logic/OneSixInstance_p.h @@ -2,6 +2,7 @@ #include "BaseInstance_p.h" #include "OneSixVersion.h" +#include "OneSixLibrary.h" #include "ModList.h" struct OneSixInstancePrivate: public BaseInstancePrivate diff --git a/logic/OneSixLibrary.cpp b/logic/OneSixLibrary.cpp new file mode 100644 index 00000000..a109a7f0 --- /dev/null +++ b/logic/OneSixLibrary.cpp @@ -0,0 +1,84 @@ +#include "OneSixLibrary.h" +#include "OneSixRule.h" + +void OneSixLibrary::finalize() +{ + 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 ); + } +} + +void OneSixLibrary::setName ( QString name ) +{ + m_name = name; +} +void OneSixLibrary::setBaseUrl ( QString base_url ) +{ + m_base_url = base_url; +} +void OneSixLibrary::setIsNative() +{ + m_is_native = true; +} +void OneSixLibrary::addNative ( OpSys os, QString suffix ) +{ + m_is_native = true; + m_native_suffixes[os] = suffix; +} +void OneSixLibrary::setRules ( QList< QSharedPointer< Rule > > rules ) +{ + m_rules = rules; +} +bool OneSixLibrary::isActive() +{ + return m_is_active; +} +bool OneSixLibrary::isNative() +{ + return m_is_native; +} +QString OneSixLibrary::downloadPath() +{ + return m_download_path; +} +QString OneSixLibrary::storagePath() +{ + return m_storage_path; +} diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h new file mode 100644 index 00000000..856e409c --- /dev/null +++ b/logic/OneSixLibrary.h @@ -0,0 +1,68 @@ +#pragma once +#include <QString> +#include <QStringList> +#include <QMap> +#include <QSharedPointer> +#include "OpSys.h" + +class Rule; + +class OneSixLibrary +{ +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 actually active on the current OS? + bool m_is_active; + /// is the library a native? + bool m_is_native; + /// native suffixes per OS + QMap<OpSys, QString> m_native_suffixes; +public: + QStringList extract_excludes; + +public: + /// Constructor + OneSixLibrary(QString name) + { + m_is_native = false; + m_is_active = false; + m_name = name; + m_base_url = "https://s3.amazonaws.com/Minecraft.Download/libraries/"; + } + + /** + * 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 + void setName(QString name); + /// Set the url base for downloads + void setBaseUrl(QString base_url); + /// Call this to mark the library as 'native' (it's a zip archive with DLLs) + void setIsNative(); + /// Attach a name suffix to the specified OS native + void addNative(OpSys os, QString suffix); + /// Set the load rules + void setRules(QList<QSharedPointer<Rule> > rules); + + /// Returns true if the library should be loaded (or extracted, in case of natives) + bool isActive(); + /// Returns true if the library is native + bool isNative(); + /// Get the URL to download the library from + QString downloadPath(); + /// Get the relative path where the library should be saved + QString storagePath(); +}; diff --git a/logic/OneSixRule.cpp b/logic/OneSixRule.cpp new file mode 100644 index 00000000..85f7d434 --- /dev/null +++ b/logic/OneSixRule.cpp @@ -0,0 +1,10 @@ +#include "OneSixRule.h" + +RuleAction RuleAction_fromString(QString name) +{ + if(name == "allow") + return Allow; + if(name == "disallow") + return Disallow; + return Defer; +}
\ No newline at end of file diff --git a/logic/OneSixRule.h b/logic/OneSixRule.h new file mode 100644 index 00000000..465c963f --- /dev/null +++ b/logic/OneSixRule.h @@ -0,0 +1,70 @@ +#pragma once +#include <QString> +#include <QSharedPointer> + +class OneSixLibrary; +#include "OneSixLibrary.h" + +enum RuleAction +{ + Allow, + Disallow, + Defer +}; + +RuleAction RuleAction_fromString(QString); + +class Rule +{ +protected: + RuleAction m_result; + virtual bool applies(OneSixLibrary * parent) = 0; +public: + Rule(RuleAction result) + :m_result(result) {} + virtual ~Rule(){}; + RuleAction apply(OneSixLibrary * parent) + { + if(applies(parent)) + return m_result; + else + return Defer; + }; +}; + +class OsRule : public Rule +{ +private: + // the OS + OpSys m_system; + // the OS version regexp + QString m_version_regexp; +protected: + virtual bool applies ( OneSixLibrary* ) + { + return (m_system == currentSystem); + } + 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 +{ +protected: + virtual bool applies ( OneSixLibrary* ) + { + return true; + } + ImplicitRule(RuleAction result) + : Rule(result) {} +public: + static QSharedPointer<ImplicitRule> create(RuleAction result) + { + return QSharedPointer<ImplicitRule> (new ImplicitRule(result)); + } +}; diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp index ce71bde0..a58a9626 100644 --- a/logic/OneSixUpdate.cpp +++ b/logic/OneSixUpdate.cpp @@ -28,6 +28,7 @@ #include "lists/MinecraftVersionList.h" #include "VersionFactory.h" #include "OneSixVersion.h" +#include "OneSixLibrary.h" #include "OneSixInstance.h" #include "pathutils.h" diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp index 56e272e2..7ffe9a94 100644 --- a/logic/OneSixVersion.cpp +++ b/logic/OneSixVersion.cpp @@ -1,111 +1,9 @@ #include "OneSixVersion.h" +#include "OneSixLibrary.h" -RuleAction RuleAction_fromString(QString name) +QList<QSharedPointer<OneSixLibrary> > OneSixVersion::getActiveNormalLibs() { - if(name == "allow") - return Allow; - if(name == "disallow") - return Disallow; - return Defer; -} - -OpSys OpSys_fromString(QString name) -{ - if(name == "linux") - return Os_Linux; - if(name == "windows") - return Os_Windows; - if(name == "osx") - return Os_OSX; - return Os_Other; -} - -void Library::finalize() -{ - 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 ); - } -} - -void Library::setName ( QString name ) -{ - m_name = name; -} -void Library::setBaseUrl ( QString base_url ) -{ - m_base_url = base_url; -} -void Library::setIsNative() -{ - m_is_native = true; -} -void Library::addNative ( OpSys os, QString suffix ) -{ - m_is_native = true; - m_native_suffixes[os] = suffix; -} -void Library::setRules ( QList< QSharedPointer< Rule > > rules ) -{ - m_rules = rules; -} -bool Library::isActive() -{ - return m_is_active; -} -bool Library::isNative() -{ - return m_is_native; -} -QString Library::downloadPath() -{ - return m_download_path; -} -QString Library::storagePath() -{ - return m_storage_path; -} - - -QList<QSharedPointer<Library> > OneSixVersion::getActiveNormalLibs() -{ - QList<QSharedPointer<Library> > output; + QList<QSharedPointer<OneSixLibrary> > output; for ( auto lib: libraries ) { if (lib->isActive() && !lib->isNative()) @@ -116,9 +14,9 @@ QList<QSharedPointer<Library> > OneSixVersion::getActiveNormalLibs() return output; } -QList<QSharedPointer<Library> > OneSixVersion::getActiveNativeLibs() +QList<QSharedPointer<OneSixLibrary> > OneSixVersion::getActiveNativeLibs() { - QList<QSharedPointer<Library> > output; + QList<QSharedPointer<OneSixLibrary> > output; for ( auto lib: libraries ) { if (lib->isActive() && lib->isNative()) diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h index 89b7c911..8f01f82d 100644 --- a/logic/OneSixVersion.h +++ b/logic/OneSixVersion.h @@ -1,151 +1,6 @@ #pragma once #include <QtCore> - -class Library; - -enum OpSys -{ - Os_Windows, - Os_Linux, - Os_OSX, - Os_Other -}; - -OpSys OpSys_fromString(QString); - -#ifdef Q_OS_WIN32 - #define currentSystem Os_Windows -#else - #ifdef Q_OS_MAC - #define currentSystem Os_OSX - #else - #define currentSystem Os_Linux - #endif -#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: - // 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) {} -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 -{ -protected: - virtual bool applies ( Library* ) - { - return true; - } - 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 actually active on the current OS? - bool m_is_active; - /// is the library a native? - bool m_is_native; - /// native suffixes per OS - QMap<OpSys, QString> m_native_suffixes; -public: - QStringList extract_excludes; - -public: - /// Constructor - Library(QString name) - { - m_is_native = false; - m_is_native = false; - m_name = name; - m_base_url = "https://s3.amazonaws.com/Minecraft.Download/libraries/"; - } - - /** - * 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 - void setName(QString name); - /// Set the url base for downloads - void setBaseUrl(QString base_url); - /// Call this to mark the library as 'native' (it's a zip archive with DLLs) - void setIsNative(); - /// Attach a name suffix to the specified OS native - void addNative(OpSys os, QString suffix); - /// Set the load rules - void setRules(QList<QSharedPointer<Rule> > rules); - - /// Returns true if the library should be loaded (or extracted, in case of natives) - bool isActive(); - /// Returns true if the library is native - bool isNative(); - /// Get the URL to download the library from - QString downloadPath(); - /// Get the relative path where the library should be saved - QString storagePath(); -}; - +class OneSixLibrary; class OneSixVersion { @@ -180,7 +35,7 @@ public: QString mainClass; /// the list of libs - both active and inactive, native and java - QList<QSharedPointer<Library> > libraries; + QList<QSharedPointer<OneSixLibrary> > libraries; /* FIXME: add support for those rules here? Looks like a pile of quick hacks to me though. @@ -208,6 +63,6 @@ public: minimumLauncherVersion = 0xDEADBEEF; } - QList<QSharedPointer<Library> > getActiveNormalLibs(); - QList<QSharedPointer<Library> > getActiveNativeLibs(); + QList<QSharedPointer<OneSixLibrary> > getActiveNormalLibs(); + QList<QSharedPointer<OneSixLibrary> > getActiveNativeLibs(); };
\ No newline at end of file diff --git a/logic/OpSys.cpp b/logic/OpSys.cpp new file mode 100644 index 00000000..559479fd --- /dev/null +++ b/logic/OpSys.cpp @@ -0,0 +1,12 @@ +#include "OpSys.h" + +OpSys OpSys_fromString(QString name) +{ + if(name == "linux") + return Os_Linux; + if(name == "windows") + return Os_Windows; + if(name == "osx") + return Os_OSX; + return Os_Other; +}
\ No newline at end of file diff --git a/logic/OpSys.h b/logic/OpSys.h new file mode 100644 index 00000000..c68c437a --- /dev/null +++ b/logic/OpSys.h @@ -0,0 +1,21 @@ +#pragma once +#include <QString> +enum OpSys +{ + Os_Windows, + Os_Linux, + Os_OSX, + Os_Other +}; + +OpSys OpSys_fromString(QString); + +#ifdef Q_OS_WIN32 + #define currentSystem Os_Windows +#else + #ifdef Q_OS_MAC + #define currentSystem Os_OSX + #else + #define currentSystem Os_Linux + #endif +#endif
\ No newline at end of file diff --git a/logic/VersionFactory.cpp b/logic/VersionFactory.cpp index 71c4d747..4fa5ad3f 100644 --- a/logic/VersionFactory.cpp +++ b/logic/VersionFactory.cpp @@ -1,5 +1,6 @@ #include "VersionFactory.h" #include "OneSixVersion.h" +#include "OneSixRule.h" // Library rules (if any) QList<QSharedPointer<Rule> > FullVersionFactory::parse4rules(QJsonObject & baseObj) @@ -103,7 +104,7 @@ QSharedPointer<OneSixVersion> FullVersionFactory::parse4(QJsonObject root, QShar auto nameVal = libObj.value("name"); if(!nameVal.isString()) continue; - QSharedPointer<Library> library(new Library(nameVal.toString())); + QSharedPointer<OneSixLibrary> library(new OneSixLibrary(nameVal.toString())); auto urlVal = libObj.value("url"); if(urlVal.isString()) |