From 7721c57e5e1093a3d8597b6b6f30c97d2aa3d8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 11 Sep 2013 23:43:17 +0200 Subject: Split OneSixVersion into parts. --- CMakeLists.txt | 11 +++- logic/OneSixInstance_p.h | 1 + logic/OneSixLibrary.cpp | 84 ++++++++++++++++++++++++++ logic/OneSixLibrary.h | 68 +++++++++++++++++++++ logic/OneSixRule.cpp | 10 ++++ logic/OneSixRule.h | 70 ++++++++++++++++++++++ logic/OneSixUpdate.cpp | 1 + logic/OneSixVersion.cpp | 112 ++-------------------------------- logic/OneSixVersion.h | 153 ++--------------------------------------------- logic/OpSys.cpp | 12 ++++ logic/OpSys.h | 21 +++++++ logic/VersionFactory.cpp | 3 +- 12 files changed, 287 insertions(+), 259 deletions(-) create mode 100644 logic/OneSixLibrary.cpp create mode 100644 logic/OneSixLibrary.h create mode 100644 logic/OneSixRule.cpp create mode 100644 logic/OneSixRule.h create mode 100644 logic/OpSys.cpp create mode 100644 logic/OpSys.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 62f878c7..feb46278 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,7 +205,11 @@ logic/OneSixInstance.h logic/OneSixInstance_p.h logic/OneSixUpdate.h logic/OneSixVersion.h +logic/OneSixLibrary.h +logic/OneSixRule.h logic/VersionFactory.h +logic/OpSys.h + # Nostalgia logic/NostalgiaInstance.h @@ -272,9 +276,12 @@ logic/LegacyForge.cpp # 1.6 instances logic/OneSixAssets.cpp logic/OneSixInstance.cpp -logic/OneSixVersion.cpp logic/OneSixUpdate.cpp +logic/OneSixVersion.cpp +logic/OneSixLibrary.cpp +logic/OneSixRule.cpp logic/VersionFactory.cpp +logic/OpSys.cpp # Nostalgia logic/NostalgiaInstance.cpp @@ -497,4 +504,4 @@ endif (UPDATE_TRANSLATIONS) add_custom_target (translations_target DEPENDS ${QM_FILES}) -install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/translations) \ No newline at end of file +install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/translations) 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 +#include +#include +#include +#include "OpSys.h" + +class Rule; + +class OneSixLibrary +{ +private: + // basic values used internally (so far) + QString m_name; + QString m_base_url; + QList > 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 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 > 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 +#include + +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 create(RuleAction result, OpSys system, QString version_regexp) + { + return QSharedPointer (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 create(RuleAction result) + { + return QSharedPointer (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 > 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 > OneSixVersion::getActiveNormalLibs() -{ - QList > output; + QList > output; for ( auto lib: libraries ) { if (lib->isActive() && !lib->isNative()) @@ -116,9 +14,9 @@ QList > OneSixVersion::getActiveNormalLibs() return output; } -QList > OneSixVersion::getActiveNativeLibs() +QList > OneSixVersion::getActiveNativeLibs() { - QList > output; + QList > 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 - -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 create(RuleAction result, OpSys system, QString version_regexp) - { - return QSharedPointer (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 create(RuleAction result) - { - return QSharedPointer (new ImplicitRule(result)); - } -}; - -class Library -{ -private: - // basic values used internally (so far) - QString m_name; - QString m_base_url; - QList > 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 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 > 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 > libraries; + QList > 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 > getActiveNormalLibs(); - QList > getActiveNativeLibs(); + QList > getActiveNormalLibs(); + QList > 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 +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 > FullVersionFactory::parse4rules(QJsonObject & baseObj) @@ -103,7 +104,7 @@ QSharedPointer FullVersionFactory::parse4(QJsonObject root, QShar auto nameVal = libObj.value("name"); if(!nameVal.isString()) continue; - QSharedPointer library(new Library(nameVal.toString())); + QSharedPointer library(new OneSixLibrary(nameVal.toString())); auto urlVal = libObj.value("url"); if(urlVal.isString()) -- cgit v1.2.3