diff options
author | TakSuyu <taksuyu@gmail.com> | 2013-07-27 12:55:51 -0700 |
---|---|---|
committer | TakSuyu <taksuyu@gmail.com> | 2013-07-27 12:55:51 -0700 |
commit | dc39d093396c9a0ed4f03d81f95fcc8fa5705b65 (patch) | |
tree | b88bf5fa692de82ce3418bdf5c55e9cd9eff37bc /libmultimc/include | |
parent | 44498f98945b7501486da35c5fdc32f94a2be080 (diff) | |
parent | a7a84d4dbb58565f108cb0886da6cb786e34d10d (diff) | |
download | PrismLauncher-dc39d093396c9a0ed4f03d81f95fcc8fa5705b65.tar.gz PrismLauncher-dc39d093396c9a0ed4f03d81f95fcc8fa5705b65.tar.bz2 PrismLauncher-dc39d093396c9a0ed4f03d81f95fcc8fa5705b65.zip |
Merge remote-tracking branch 'upstream/master'
Conflicts:
gui/mainwindow.cpp
Diffstat (limited to 'libmultimc/include')
-rw-r--r-- | libmultimc/include/fullversion.h | 69 | ||||
-rw-r--r-- | libmultimc/include/fullversionfactory.h | 25 | ||||
-rw-r--r-- | libmultimc/include/gameupdatetask.h | 75 | ||||
-rw-r--r-- | libmultimc/include/instance.h | 46 | ||||
-rw-r--r-- | libmultimc/include/library.h | 219 |
5 files changed, 361 insertions, 73 deletions
diff --git a/libmultimc/include/fullversion.h b/libmultimc/include/fullversion.h new file mode 100644 index 00000000..523ac87c --- /dev/null +++ b/libmultimc/include/fullversion.h @@ -0,0 +1,69 @@ +#pragma once +#include <QString> + +class Library; + +class FullVersion +{ +public: + FullVersion() + { + minimumLauncherVersion = 0xDEADBEEF; + isLegacy = false; + } + // the ID - determines which jar to use! ACTUALLY IMPORTANT! + QString id; + // do we actually care about parsing this? + QString time; + // I don't think we do. + QString releaseTime; + // eh, not caring - "release" or "snapshot" + QString type; + /* + * DEPRECATED: Old versions of the new vanilla launcher used this + * ex: "username_session_version" + */ + QString processArguments; + /* + * arguments that should be used for launching minecraft + * + * ex: "--username ${auth_player_name} --session ${auth_session} + * --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets}" + */ + QString minecraftArguments; + /* + * the minimum launcher version required by this version ... current is 4 (at point of writing) + */ + int minimumLauncherVersion; + /* + * The main class to load first + */ + QString mainClass; + + // the list of libs. just the names for now. expand to full-blown strutures! + QList<QSharedPointer<Library> > libraries; + + // is this actually a legacy version? if so, none of the other stuff here will be ever used. + // added by FullVersionFactory + bool isLegacy; + +/* +FIXME: add support for those rules here? Looks like a pile of quick hacks to me though. + + "rules": [ + { + "action": "allow" + }, + { + "action": "disallow", + "os": { + "name": "osx", + "version": "^10\\.5\\.\\d$" + } + } + ], + "incompatibilityReason": "There is a bug in LWJGL which makes it incompatible with OSX 10.5.8. Please go to New Profile and use 1.5.2 for now. Sorry!" +} +*/ + // QList<Rule> rules; +};
\ No newline at end of file diff --git a/libmultimc/include/fullversionfactory.h b/libmultimc/include/fullversionfactory.h new file mode 100644 index 00000000..60e5c983 --- /dev/null +++ b/libmultimc/include/fullversionfactory.h @@ -0,0 +1,25 @@ +#pragma once +#include <QtCore> + +struct FullVersion; +class Rule; + +class FullVersionFactory +{ +public: + enum Error + { + AllOK, // all parsed OK + ParseError, // the file was corrupted somehow + UnsupportedVersion // the file was meant for a launcher version we don't support (yet) + } m_error; + QString error_string; + +public: + FullVersionFactory(); + QSharedPointer<FullVersion> parse(QByteArray data); +private: + QSharedPointer<FullVersion> parse4(QJsonObject root, QSharedPointer<FullVersion> product); + QList<QSharedPointer<Rule> > parse4rules(QJsonObject & baseObj); + QStringList legacyWhitelist; +};
\ No newline at end of file diff --git a/libmultimc/include/gameupdatetask.h b/libmultimc/include/gameupdatetask.h index c3f84356..b56c448b 100644 --- a/libmultimc/include/gameupdatetask.h +++ b/libmultimc/include/gameupdatetask.h @@ -22,47 +22,15 @@ #include <QNetworkAccessManager> #include <QUrl> +#include "dlqueue.h" #include "task.h" #include "loginresponse.h" #include "instance.h" #include "libmmc_config.h" -class FileToDownload; -typedef QSharedPointer<FileToDownload> FileToDownloadPtr; - -class FileToDownload : public QObject -{ - Q_OBJECT - - /*! - * The URL to download the file from. - */ - Q_PROPERTY(QUrl url READ url WRITE setURL) - - /*! - * The path to download to. - * This path is relative to the instance's root directory. - */ - Q_PROPERTY(QString path READ path WRITE setPath) - -private: - FileToDownload(const QUrl &url, const QString &path, QObject *parent = 0); -public: - static FileToDownloadPtr Create(const QUrl &url, const QString &path, QObject *parent = 0); - - virtual QUrl url() const { return m_dlURL; } - virtual void setURL(const QUrl &url) { m_dlURL = url; } - - virtual QString path() const { return m_dlPath; } - virtual void setPath(const QString &path) { m_dlPath = path; } - -private: - QUrl m_dlURL; - QString m_dlPath; -}; - +class MinecraftVersion; /*! * The game update task is the task that handles downloading instances' files. @@ -92,9 +60,6 @@ public: virtual void executeTask(); - virtual bool downloadFile(const FileToDownloadPtr file); - - ////////////////////// // STATE AND STATUS // ////////////////////// @@ -110,6 +75,10 @@ public: */ virtual QString getStateMessage(int state); +private: + void getLegacyJar(); + void determineNewVersion(); + public slots: /*! @@ -122,7 +91,15 @@ public slots: private slots: - virtual void updateDownloadProgress(qint64 current, qint64 total); + void updateDownloadProgress(qint64 current, qint64 total); + void legacyJarFinished(); + void legacyJarFailed(); + + void versionFileFinished(); + void versionFileFailed(); + + void jarlibFinished(); + void jarlibFailed(); signals: /*! @@ -143,23 +120,8 @@ private: /////////// Instance *m_inst; - LoginResponse m_response; - QNetworkAccessManager *netMgr; - - - - //////////////////////// - // FILE DOWNLOAD LIST // - //////////////////////// - - // List of URLs that the game updater will need to download. - QList<FileToDownloadPtr> m_downloadList; - int m_currentDownload; - - - //////////////////////////// // STATE AND STATUS STUFF // //////////////////////////// @@ -184,6 +146,13 @@ private: // Finished StateFinished }; + JobListPtr legacyDownloadJob; + JobListPtr specificVersionDownloadJob; + JobListPtr jarlibDownloadJob; + JobListQueue download_queue; + + // target version, determined during this task + MinecraftVersion *targetVersion; }; diff --git a/libmultimc/include/instance.h b/libmultimc/include/instance.h index 717f8816..f6857cd8 100644 --- a/libmultimc/include/instance.h +++ b/libmultimc/include/instance.h @@ -80,16 +80,7 @@ class LIBMULTIMC_EXPORT Instance : public QObject * This returns true if shouldForceUpdate game is true or if the intended and * current versions don't match. */ - Q_PROPERTY(bool shouldUpdateGame READ shouldUpdateGame STORED false) - - /*! - * Whether or not the game will be forced to update on the next launch. - * If this is set to true, shouldUpdateGame will be true, regardless of whether or not - * the current and intended versions match. - * It should be noted that this is set to false automatically when game updates are run. - */ - Q_PROPERTY(bool shouldForceUpdateGame READ shouldForceUpdateGame WRITE setShouldForceUpdateGame) - + Q_PROPERTY(bool shouldUpdate READ shouldUpdate WRITE setShouldUpdate) /*! * The instance's current version. @@ -125,8 +116,11 @@ class LIBMULTIMC_EXPORT Instance : public QObject */ Q_PROPERTY(qint64 lastCurrentVersionUpdate READ lastCurrentVersionUpdate WRITE setLastCurrentVersionUpdate) - - + /*! + * Is the instance a new launcher instance? Get/Set + */ + Q_PROPERTY(bool isForNewLauncher READ isForNewLauncher WRITE setIsForNewLauncher) + // Dirs //! Path to the instance's .minecraft folder. Q_PROPERTY(QString minecraftDir READ minecraftDir STORED false) @@ -236,14 +230,17 @@ public: virtual QString intendedVersion() const { return settings().get("IntendedJarVersion").toString(); } virtual void setIntendedVersion(QString val) { settings().set("IntendedJarVersion", val); } - virtual bool shouldUpdateGame() const - { return shouldForceUpdateGame() || intendedVersion() != currentVersion(); } - - virtual bool shouldForceUpdateGame() const { return settings().get("ShouldForceUpdate").toBool(); } - virtual void setShouldForceUpdateGame(bool val) { settings().set("ShouldForceUpdate", val); } - - - + virtual bool shouldUpdate() const + { + QVariant var = settings().get("ShouldUpdate"); + if(!var.isValid() || var.toBool() == false) + { + return intendedVersion() != currentVersion(); + } + return true; + } + virtual void setShouldUpdate(bool val) { settings().set("ShouldUpdate", val); } + //// Timestamps //// virtual qint64 lastLaunch() const { return settings().get("lastLaunchTime").value<qint64>(); } @@ -256,6 +253,15 @@ public: virtual qint64 lastCurrentVersionUpdate() const { return settings().get("lastVersionUpdate").value<qint64>(); } virtual void setLastCurrentVersionUpdate(qint64 val) { settings().set("lastVersionUpdate", val); } + virtual bool isForNewLauncher() + { + return settings().get("IsForNewLauncher").value<bool>(); + } + + virtual void setIsForNewLauncher(bool value = true) + { + settings().set("IsForNewLauncher", value); + } ////// Directories ////// QString minecraftDir() const; diff --git a/libmultimc/include/library.h b/libmultimc/include/library.h new file mode 100644 index 00000000..8d97b4a6 --- /dev/null +++ b/libmultimc/include/library.h @@ -0,0 +1,219 @@ +/* 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 + +#include <QtCore> + +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 + + +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 actuall active on the current OS? + bool m_is_active; + + // native lib? + bool m_is_native; + QMap<OpSys, QString> m_native_suffixes; +public: + QStringList extract_excludes; + +public: + /// finalize the library, processing the input values into derived values and state + void 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); + } + }; + + 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 setBaseUrl(QString base_url) + { + 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() + { + return m_is_active; + } +}; |