From a23323a01ee2713209619ad99d8859616aa99cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 7 Jul 2013 18:12:09 +0200 Subject: [PATCH 01/11] Small tweaks to the assets - delete extra files --- asset_test.cpp | 44 +++++++++++++++++++++---------- libmultimc/src/gameupdatetask.cpp | 8 +++++- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/asset_test.cpp b/asset_test.cpp index fb797b97..90da314f 100644 --- a/asset_test.cpp +++ b/asset_test.cpp @@ -13,19 +13,11 @@ inline QDomElement getDomElementByTagName(QDomElement parent, QString tagname) return QDomElement(); } -// a job that removes all files from the base folder that don't match the whitelist -// runs in whatever thread owns the queue. it is fast though. -class NukeAndPaveJob: public Job +class ThreadedDeleter : public QThread { + Q_OBJECT public: - explicit NukeAndPaveJob(QString base, QStringList whitelist) - :Job() - { - QDir dir(base); - m_base = dir.absolutePath(); - m_whitelist = whitelist; - }; - virtual void start() + void run() { QDirIterator iter(m_base, QDirIterator::Subdirectories); QStringList nuke_list; @@ -51,13 +43,37 @@ public: f.remove(); } } - emit finish(); }; -private: QString m_base; QStringList m_whitelist; }; +class NukeAndPaveJob: public Job +{ + Q_OBJECT +public: + + explicit NukeAndPaveJob(QString base, QStringList whitelist) + :Job() + { + QDir dir(base); + deleterThread.m_base = dir.absolutePath(); + deleterThread.m_whitelist = whitelist; + }; +public slots: + virtual void start() + { + connect(&deleterThread, SIGNAL(finished()), SLOT(threadFinished())); + deleterThread.start(); + }; + void threadFinished() + { + emit finish(); + } +private: + ThreadedDeleter deleterThread; +}; + class DlMachine : public QObject { Q_OBJECT @@ -84,7 +100,7 @@ public slots: qDebug() << "Failed to process s3.amazonaws.com/Minecraft.Resources. XML error:" << xmlErrorMsg << ba; } - QRegExp etag_match(".*([a-f0-9]{32}).*"); + //QRegExp etag_match(".*([a-f0-9]{32}).*"); QDomNodeList contents = doc.elementsByTagName("Contents"); JobList *job = new JobList(); diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index c718ce71..49f9335f 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -47,7 +47,13 @@ void GameUpdateTask::executeTask() // Get a pointer to the version object that corresponds to the instance's version. MinecraftVersion *targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList(). findVersion(m_inst->intendedVersion()); - Q_ASSERT_X(targetVersion != NULL, "game update", "instance's intended version is not an actual version"); + if(targetVersion == NULL) + { + //Q_ASSERT_X(targetVersion != NULL, "game update", "instance's intended version is not an actual version"); + setState(StateFinished); + emit gameUpdateComplete(m_response); + return; + } // Make directories QDir binDir(m_inst->binDir()); From ee5583251d92d47f96b03c3b447c115bab901c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 7 Jul 2013 23:51:26 +0200 Subject: [PATCH 02/11] Legacy versions downloaded from the new location are treated as legacy versions! --- libmultimc/include/gameupdatetask.h | 72 +++------- libmultimc/src/gameupdatetask.cpp | 200 ++++++++++++++-------------- libutil/include/dlqueue.h | 2 +- libutil/src/dlqueue.cpp | 12 +- 4 files changed, 124 insertions(+), 162 deletions(-) diff --git a/libmultimc/include/gameupdatetask.h b/libmultimc/include/gameupdatetask.h index c3f84356..f607db6b 100644 --- a/libmultimc/include/gameupdatetask.h +++ b/libmultimc/include/gameupdatetask.h @@ -22,47 +22,15 @@ #include #include +#include "dlqueue.h" #include "task.h" #include "loginresponse.h" #include "instance.h" #include "libmmc_config.h" -class FileToDownload; -typedef QSharedPointer 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,12 @@ 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(); signals: /*! @@ -143,23 +117,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 m_downloadList; - int m_currentDownload; - - - //////////////////////////// // STATE AND STATUS STUFF // //////////////////////////// @@ -184,6 +143,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/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index 49f9335f..fee2aa29 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -27,25 +27,20 @@ #include "minecraftversionlist.h" #include "pathutils.h" -#include "netutils.h" GameUpdateTask::GameUpdateTask(const LoginResponse &response, Instance *inst, QObject *parent) : Task(parent), m_response(response) { m_inst = inst; m_updateState = StateInit; - m_currentDownload = 0; } void GameUpdateTask::executeTask() { updateStatus(); - QNetworkAccessManager networkMgr; - netMgr = &networkMgr; - // Get a pointer to the version object that corresponds to the instance's version. - MinecraftVersion *targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList(). + targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList(). findVersion(m_inst->intendedVersion()); if(targetVersion == NULL) { @@ -55,6 +50,81 @@ void GameUpdateTask::executeTask() return; } + ///////////////////////// + // BUILD DOWNLOAD LIST // + ///////////////////////// + // Build a list of URLs that will need to be downloaded. + + setState(StateDetermineURLs); + + if (targetVersion->launcherVersion() == MinecraftVersion::Launcher16) + { + determineNewVersion(); + } + else + { + getLegacyJar(); + } + QEventLoop loop; + loop.exec(); +} + +void GameUpdateTask::determineNewVersion() +{ + QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); + urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".json"; + auto dljob = DownloadJob::create(QUrl(urlstr)); + specificVersionDownloadJob.reset(new JobList()); + specificVersionDownloadJob->add(dljob); + connect(specificVersionDownloadJob.data(), SIGNAL(finished()), SLOT(versionFileFinished())); + connect(specificVersionDownloadJob.data(), SIGNAL(failed()), SLOT(versionFileFailed())); + connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + download_queue.enqueue(specificVersionDownloadJob); +} + +void GameUpdateTask::versionFileFinished() +{ + JobPtr firstJob = specificVersionDownloadJob->getFirstJob(); + auto DlJob = firstJob.dynamicCast(); + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(DlJob->m_data, &jsonError); + + if (jsonError.error != QJsonParseError::NoError) + { + error(QString( "Error reading version file :") + " " + jsonError.errorString()); + exit(0); + } + + Q_ASSERT_X(jsonDoc.isObject(), "loadFromVList", "jsonDoc is not an object"); + if(!jsonDoc.isObject()) + { + error("Error reading version file."); + exit(0); + } + QJsonObject root = jsonDoc.object(); + + QString args = root.value("processArguments").toString("legacy"); + if(args == "legacy") + { + getLegacyJar(); + return; + } + + + error("MC 1.6 isn't supported yet..."); + exit(0); +} + +void GameUpdateTask::versionFileFailed() +{ + error("Failed to download the version description. Try again."); + exit(0); +} + + +// this is legacy minecraft... +void GameUpdateTask::getLegacyJar() +{ // Make directories QDir binDir(m_inst->binDir()); if (!binDir.exists() && !binDir.mkpath(".")) @@ -63,99 +133,40 @@ void GameUpdateTask::executeTask() return; } - - - ///////////////////////// - // BUILD DOWNLOAD LIST // - ///////////////////////// - // Build a list of URLs that will need to be downloaded. - - setState(StateDetermineURLs); - - // Add the URL for minecraft.jar - // This will be either 'minecraft' or the version number, depending on where // we're downloading from. QString jarFilename = "minecraft"; - - // FIXME: this is NOT enough if (targetVersion->launcherVersion() == MinecraftVersion::Launcher16) + { jarFilename = targetVersion->descriptor(); + } QUrl mcJarURL = targetVersion->downloadURL() + jarFilename + ".jar"; qDebug() << mcJarURL.toString(); - m_downloadList.append(FileToDownload::Create(mcJarURL, PathCombine(m_inst->minecraftDir(), "bin/minecraft.jar"))); + auto dljob = DownloadJob::create(mcJarURL, PathCombine(m_inst->minecraftDir(), "bin/minecraft.jar")); + legacyDownloadJob.reset(new JobList()); + legacyDownloadJob->add(dljob); + connect(legacyDownloadJob.data(), SIGNAL(finished()), SLOT(legacyJarFinished())); + connect(legacyDownloadJob.data(), SIGNAL(failed()), SLOT(legacyJarFailed())); + connect(legacyDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); - - //////////////////// - // DOWNLOAD FILES // - //////////////////// - setState(StateDownloadFiles); - for (int i = 0; i < m_downloadList.length(); i++) - { - m_currentDownload = i; - if (!downloadFile(m_downloadList[i])) - return; - } - - - - /////////////////// - // INSTALL FILES // - /////////////////// - setState(StateInstall); - - // Nothing to do here yet - - - - ////////////// - // FINISHED // - ////////////// - setState(StateFinished); - emit gameUpdateComplete(m_response); + download_queue.enqueue(legacyDownloadJob); } -bool GameUpdateTask::downloadFile( const FileToDownloadPtr file ) + +void GameUpdateTask::legacyJarFinished() { - setSubStatus("Downloading " + file->url().toString()); - QNetworkReply *reply = netMgr->get(QNetworkRequest(file->url())); - - this->connect(reply, SIGNAL(downloadProgress(qint64,qint64)), - SLOT(updateDownloadProgress(qint64,qint64))); - - NetUtils::waitForNetRequest(reply); - - if (reply->error() == QNetworkReply::NoError) - { - QString filePath = file->path(); - QFile outFile(filePath); - if (outFile.exists() && !outFile.remove()) - { - error("Can't delete old file " + file->path() + ": " + outFile.errorString()); - return false; - } - - if (!outFile.open(QIODevice::WriteOnly)) - { - error("Can't write to " + file->path() + ": " + outFile.errorString()); - return false; - } - - outFile.write(reply->readAll()); - outFile.close(); - } - else - { - error("Can't download " + file->url().toString() + ": " + reply->errorString()); - return false; - } - - // TODO: Check file integrity after downloading. - - return true; + setState(StateFinished); + emit gameUpdateComplete(m_response); + exit(1); +} + +void GameUpdateTask::legacyJarFailed() +{ + emit gameUpdateError("failed to download the minecraft.jar"); + exit(0); } int GameUpdateTask::state() const @@ -229,22 +240,7 @@ void GameUpdateTask::error(const QString &msg) void GameUpdateTask::updateDownloadProgress(qint64 current, qint64 total) { // The progress on the current file is current / total - float currentDLProgress = (float) current / (float) total; // Cast ALL the values! - - // The overall progress is (current progress + files downloaded) / total files to download - float overallDLProgress = ((currentDLProgress + m_currentDownload) / (float) m_downloadList.length()); - - // Multiply by 100 to make it a percentage. - setProgress((int)(overallDLProgress * 100)); + float currentDLProgress = (float) current / (float) total; + setProgress((int)(currentDLProgress * 100)); // convert to percentage } -FileToDownloadPtr FileToDownload::Create(const QUrl &url, const QString &path, QObject *parent) -{ - return FileToDownloadPtr(new FileToDownload (url, path, parent)); -} - -FileToDownload::FileToDownload(const QUrl &url, const QString &path, QObject *parent) : - QObject(parent), m_dlURL(url), m_dlPath(path) -{ - -} diff --git a/libutil/include/dlqueue.h b/libutil/include/dlqueue.h index 9041e762..5fb9409c 100644 --- a/libutil/include/dlqueue.h +++ b/libutil/include/dlqueue.h @@ -38,7 +38,7 @@ public: /// save to file? bool m_save_to_file; /// if saving to file, use the one specified in this string - QString m_rel_target_path; + QString m_target_path; /// this is the output file, if any QFile m_output_file; /// if not saving to file, downloaded data is placed here diff --git a/libutil/src/dlqueue.cpp b/libutil/src/dlqueue.cpp index dfc51f36..7e4d47eb 100644 --- a/libutil/src/dlqueue.cpp +++ b/libutil/src/dlqueue.cpp @@ -1,20 +1,20 @@ #include "include/dlqueue.h" -DownloadJob::DownloadJob ( QUrl url, QString rel_target_path, QString expected_md5 ) +DownloadJob::DownloadJob ( QUrl url, QString target_path, QString expected_md5 ) :Job() { m_url = url; - m_rel_target_path = rel_target_path; + m_target_path = target_path; m_expected_md5 = expected_md5; m_check_md5 = m_expected_md5.size(); - m_save_to_file = m_rel_target_path.size(); + m_save_to_file = m_target_path.size(); m_status = Job_NotStarted; } -JobPtr DownloadJob::create ( QUrl url, QString rel_target_path, QString expected_md5 ) +JobPtr DownloadJob::create ( QUrl url, QString target_path, QString expected_md5 ) { - return JobPtr ( new DownloadJob ( url, rel_target_path, expected_md5 ) ); + return JobPtr ( new DownloadJob ( url, target_path, expected_md5 ) ); } void DownloadJob::start() @@ -22,7 +22,7 @@ void DownloadJob::start() m_manager.reset ( new QNetworkAccessManager() ); if ( m_save_to_file ) { - QString filename = m_rel_target_path; + QString filename = m_target_path; m_output_file.setFileName ( filename ); // if there already is a file and md5 checking is in effect if ( m_output_file.exists() && m_check_md5 ) From dd86061f0ff6d19482e9a43af99156a55e60cf00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 9 Jul 2013 00:52:03 +0200 Subject: [PATCH 03/11] Piddle-farting with 1.6 instances. Now with more json! --- libmultimc/src/gameupdatetask.cpp | 25 ++++++++++++++++++-- libutil/include/dlqueue.h | 5 +++- libutil/include/jobqueue.h | 7 +++--- libutil/src/dlqueue.cpp | 39 +++++++++++++++---------------- 4 files changed, 50 insertions(+), 26 deletions(-) diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index fee2aa29..54e47410 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -95,7 +95,6 @@ void GameUpdateTask::versionFileFinished() exit(0); } - Q_ASSERT_X(jsonDoc.isObject(), "loadFromVList", "jsonDoc is not an object"); if(!jsonDoc.isObject()) { error("Error reading version file."); @@ -103,6 +102,10 @@ void GameUpdateTask::versionFileFinished() } QJsonObject root = jsonDoc.object(); + /* + * FIXME: this distinction is pretty weak. The only other option + * is to have a list of all the legacy versions. + */ QString args = root.value("processArguments").toString("legacy"); if(args == "legacy") { @@ -110,8 +113,26 @@ void GameUpdateTask::versionFileFinished() return; } + // save the version file in $instanceId/version.json and versions/$version/$version.json + QString version_id = targetVersion->descriptor(); + QString mc_dir = m_inst->minecraftDir(); + QString inst_dir = m_inst->rootDir(); + QString version1 = PathCombine(inst_dir, "/version.json"); + QString version2 = QString("versions/") + version_id + "/" + version_id + ".json"; + DownloadJob::ensurePathExists(version1); + DownloadJob::ensurePathExists(version2); + QFile vfile1 (version1); + QFile vfile2 (version2); + vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly ); + vfile2.open(QIODevice::Truncate | QIODevice::WriteOnly ); + vfile1.write(DlJob->m_data); + vfile2.write(DlJob->m_data); + vfile1.close(); + vfile2.close(); + + // download the right jar, save it in versions/$version/$version.jar + // determine and download all the libraries, save them in libraries/whatever... - error("MC 1.6 isn't supported yet..."); exit(0); } diff --git a/libutil/include/dlqueue.h b/libutil/include/dlqueue.h index 5fb9409c..14fa6e60 100644 --- a/libutil/include/dlqueue.h +++ b/libutil/include/dlqueue.h @@ -5,13 +5,16 @@ /** * A single file for the downloader/cache to process. */ -class DownloadJob : public Job +class LIBUTIL_EXPORT DownloadJob : public Job { Q_OBJECT public: DownloadJob(QUrl url, QString rel_target_path = QString(), QString expected_md5 = QString()); static JobPtr create(QUrl url, QString rel_target_path = QString(), QString expected_md5 = QString()); + +public: + static bool ensurePathExists(QString filenamepath); public slots: virtual void start(); diff --git a/libutil/include/jobqueue.h b/libutil/include/jobqueue.h index 061686f6..26f49307 100644 --- a/libutil/include/jobqueue.h +++ b/libutil/include/jobqueue.h @@ -1,5 +1,6 @@ #pragma once #include +#include "libutil_config.h" enum JobStatus { @@ -11,7 +12,7 @@ enum JobStatus class JobList; -class Job : public QObject +class LIBUTIL_EXPORT Job : public QObject { Q_OBJECT protected: @@ -30,7 +31,7 @@ typedef QSharedPointer JobPtr; /** * A list of jobs, to be processed one by one. */ -class JobList : public QObject +class LIBUTIL_EXPORT JobList : public QObject { friend class JobListQueue; Q_OBJECT @@ -127,7 +128,7 @@ typedef QSharedPointer JobListPtr; /** * A queue of job lists! The job lists fail or finish as units. */ -class JobListQueue : public QObject +class LIBUTIL_EXPORT JobListQueue : public QObject { Q_OBJECT public: diff --git a/libutil/src/dlqueue.cpp b/libutil/src/dlqueue.cpp index 7e4d47eb..9a080c17 100644 --- a/libutil/src/dlqueue.cpp +++ b/libutil/src/dlqueue.cpp @@ -17,6 +17,13 @@ JobPtr DownloadJob::create ( QUrl url, QString target_path, QString expected_md5 return JobPtr ( new DownloadJob ( url, target_path, expected_md5 ) ); } +bool DownloadJob::ensurePathExists(QString filenamepath) +{ + QFileInfo a ( filenamepath ); + QDir dir; + return (dir.mkpath ( a.path() )); +} + void DownloadJob::start() { m_manager.reset ( new QNetworkAccessManager() ); @@ -24,34 +31,26 @@ void DownloadJob::start() { QString filename = m_target_path; m_output_file.setFileName ( filename ); - // if there already is a file and md5 checking is in effect - if ( m_output_file.exists() && m_check_md5 ) + // if there already is a file and md5 checking is in effect and it can be opened + if ( m_check_md5 && m_output_file.exists() && m_output_file.open ( QIODevice::ReadOnly ) ) { - // and it can be opened - if ( m_output_file.open ( QIODevice::ReadOnly ) ) + // check the md5 against the expected one + QString hash = QCryptographicHash::hash ( m_output_file.readAll(), QCryptographicHash::Md5 ).toHex().constData(); + m_output_file.close(); + // skip this file if they match + if ( hash == m_expected_md5 ) { - // check the md5 against the expected one - QString hash = QCryptographicHash::hash ( m_output_file.readAll(), QCryptographicHash::Md5 ).toHex().constData(); - m_output_file.close(); - // skip this file if they match - if ( hash == m_expected_md5 ) - { - qDebug() << "Skipping " << m_url.toString() << ": md5 match."; - emit finish(); - return; - } + qDebug() << "Skipping " << m_url.toString() << ": md5 match."; + emit finish(); + return; } } - QFileInfo a ( filename ); - QDir dir; - if ( !dir.mkpath ( a.path() ) ) + if(!ensurePathExists(filename)) { - /* - * error when making the folder structure - */ emit fail(); return; } + if ( !m_output_file.open ( QIODevice::WriteOnly ) ) { /* From c96ac2460522b9567a10831bcd1d8a6bc9f36d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 9 Jul 2013 22:46:33 +0200 Subject: [PATCH 04/11] Replace one line. Get downloading of 1.6 jars working. Yay. --- libmultimc/include/gameupdatetask.h | 3 +++ libmultimc/src/gameupdatetask.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libmultimc/include/gameupdatetask.h b/libmultimc/include/gameupdatetask.h index f607db6b..b56c448b 100644 --- a/libmultimc/include/gameupdatetask.h +++ b/libmultimc/include/gameupdatetask.h @@ -98,6 +98,9 @@ private slots: void versionFileFinished(); void versionFileFailed(); + void jarlibFinished(); + void jarlibFailed(); + signals: /*! * \brief Signal emitted when the game update is complete. diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index 54e47410..a8abb0b6 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -131,8 +131,32 @@ void GameUpdateTask::versionFileFinished() vfile2.close(); // download the right jar, save it in versions/$version/$version.jar - // determine and download all the libraries, save them in libraries/whatever... + QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); + urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".jar"; + QString targetstr ("versions/"); + targetstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".jar"; + auto dljob = DownloadJob::create(QUrl(urlstr), targetstr); + jarlibDownloadJob.reset(new JobList()); + jarlibDownloadJob->add(dljob); + connect(jarlibDownloadJob.data(), SIGNAL(finished()), SLOT(jarlibFinished())); + connect(jarlibDownloadJob.data(), SIGNAL(failed()), SLOT(jarlibFailed())); + connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); + // determine and download all the libraries, save them in libraries/whatever... + download_queue.enqueue(jarlibDownloadJob); +} + +void GameUpdateTask::jarlibFinished() +{ + exit(1); + // YAYAYAYAYYAYAAUAYAYYAYYY!!!! + // WEE DID IT! + // YESSSSS! +} + +void GameUpdateTask::jarlibFailed() +{ + error("Failed to download the binary garbage. Try again. Maybe. IF YOU DARE"); exit(0); } From 33b9b25da7d3d29f949c9418295de257d437c9f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 14 Jul 2013 18:33:31 +0200 Subject: [PATCH 05/11] More work on the downloader and 1.6 instance creation --- gui/mainwindow.cpp | 2 +- libmultimc/include/instance.h | 30 +++++++----------- libmultimc/src/gameupdatetask.cpp | 51 ++++++++++++++++++++++++++++-- libmultimc/src/instance.cpp | 2 +- libsettings/src/settingsobject.cpp | 2 +- libutil/include/dlqueue.h | 2 ++ libutil/src/dlqueue.cpp | 34 +++++++++++++------- 7 files changed, 87 insertions(+), 36 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 5336b12c..8ba988c5 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -416,7 +416,7 @@ void MainWindow::onLoginComplete(LoginResponse response) { Q_ASSERT_X(m_activeInst != NULL, "onLoginComplete", "no active instance is set"); - if (!m_activeInst->shouldUpdateGame()) + if (!m_activeInst->shouldUpdate()) { launchInstance(m_activeInst, response); } diff --git a/libmultimc/include/instance.h b/libmultimc/include/instance.h index 717f8816..526025be 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. @@ -236,14 +227,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(); } diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index a8abb0b6..b6c1f936 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -112,6 +112,52 @@ void GameUpdateTask::versionFileFinished() getLegacyJar(); return; } + /* + // Iterate through the list. + QJsonObject groupList = root.value("libraries").toObject(); + + for (QJsonObject::iterator iter = groupList.begin(); + iter != groupList.end(); iter++) + { + QString groupName = iter.key(); + + // If not an object, complain and skip to the next one. + if (!iter.value().isObject()) + { + qWarning(QString("Group '%1' in the group list should " + "be an object.").arg(groupName).toUtf8()); + continue; + } + + QJsonObject groupObj = iter.value().toObject(); + + // Create the group object. + InstanceGroup *group = new InstanceGroup(groupName, this); + groups.push_back(group); + + // If 'hidden' isn't a bool value, just assume it's false. + if (groupObj.value("hidden").isBool() && groupObj.value("hidden").toBool()) + { + group->setHidden(groupObj.value("hidden").toBool()); + } + + if (!groupObj.value("instances").isArray()) + { + qWarning(QString("Group '%1' in the group list is invalid. " + "It should contain an array " + "called 'instances'.").arg(groupName).toUtf8()); + continue; + } + + // Iterate through the list of instances in the group. + QJsonArray instancesArray = groupObj.value("instances").toArray(); + + for (QJsonArray::iterator iter2 = instancesArray.begin(); + iter2 != instancesArray.end(); iter2++) + { + groupMap[(*iter2).toString()] = groupName; + } + }*/ // save the version file in $instanceId/version.json and versions/$version/$version.json QString version_id = targetVersion->descriptor(); @@ -148,10 +194,9 @@ void GameUpdateTask::versionFileFinished() void GameUpdateTask::jarlibFinished() { + m_inst->setCurrentVersion(targetVersion->descriptor()); + m_inst->setShouldUpdate(false); exit(1); - // YAYAYAYAYYAYAAUAYAYYAYYY!!!! - // WEE DID IT! - // YESSSSS! } void GameUpdateTask::jarlibFailed() diff --git a/libmultimc/src/instance.cpp b/libmultimc/src/instance.cpp index 08cd6605..fde31cf3 100644 --- a/libmultimc/src/instance.cpp +++ b/libmultimc/src/instance.cpp @@ -34,7 +34,7 @@ Instance::Instance(const QString &rootDir, QObject *parent) : settings().registerSetting(new Setting("iconKey", "default")); settings().registerSetting(new Setting("notes", "")); settings().registerSetting(new Setting("NeedsRebuild", true)); - settings().registerSetting(new Setting("ShouldForceUpdate", false)); + settings().registerSetting(new Setting("ShouldUpdate", false)); settings().registerSetting(new Setting("JarVersion", "Unknown")); settings().registerSetting(new Setting("LwjglVersion", "2.9.0")); settings().registerSetting(new Setting("IntendedJarVersion", "")); diff --git a/libsettings/src/settingsobject.cpp b/libsettings/src/settingsobject.cpp index 98c7b479..f94a6552 100644 --- a/libsettings/src/settingsobject.cpp +++ b/libsettings/src/settingsobject.cpp @@ -49,7 +49,7 @@ bool SettingsObject::registerSetting(Setting *setting) // Connect signals. connectSignals(*setting); - qDebug(QString("Registered setting %1.").arg(setting->id()).toUtf8()); + // qDebug(QString("Registered setting %1.").arg(setting->id()).toUtf8()); return true; } diff --git a/libutil/include/dlqueue.h b/libutil/include/dlqueue.h index 14fa6e60..69fc22a6 100644 --- a/libutil/include/dlqueue.h +++ b/libutil/include/dlqueue.h @@ -40,6 +40,8 @@ public: /// save to file? bool m_save_to_file; + /// is the saving file already open? + bool m_opened_for_saving; /// if saving to file, use the one specified in this string QString m_target_path; /// this is the output file, if any diff --git a/libutil/src/dlqueue.cpp b/libutil/src/dlqueue.cpp index 9a080c17..1ef8e212 100644 --- a/libutil/src/dlqueue.cpp +++ b/libutil/src/dlqueue.cpp @@ -10,6 +10,7 @@ DownloadJob::DownloadJob ( QUrl url, QString target_path, QString expected_md5 ) m_check_md5 = m_expected_md5.size(); m_save_to_file = m_target_path.size(); m_status = Job_NotStarted; + m_opened_for_saving = false; } JobPtr DownloadJob::create ( QUrl url, QString target_path, QString expected_md5 ) @@ -32,36 +33,32 @@ void DownloadJob::start() QString filename = m_target_path; m_output_file.setFileName ( filename ); // if there already is a file and md5 checking is in effect and it can be opened - if ( m_check_md5 && m_output_file.exists() && m_output_file.open ( QIODevice::ReadOnly ) ) + if ( m_output_file.exists() && m_output_file.open ( QIODevice::ReadOnly ) ) { // check the md5 against the expected one QString hash = QCryptographicHash::hash ( m_output_file.readAll(), QCryptographicHash::Md5 ).toHex().constData(); m_output_file.close(); // skip this file if they match - if ( hash == m_expected_md5 ) + if ( m_check_md5 && hash == m_expected_md5 ) { qDebug() << "Skipping " << m_url.toString() << ": md5 match."; emit finish(); return; } + else + { + m_expected_md5 = hash; + } } if(!ensurePathExists(filename)) { emit fail(); return; } - - if ( !m_output_file.open ( QIODevice::WriteOnly ) ) - { - /* - * Can't open the file... the job failed - */ - emit fail(); - return; - } } qDebug() << "Downloading " << m_url.toString(); QNetworkRequest request ( m_url ); + request.setRawHeader(QString("If-None-Match").toLatin1(), m_expected_md5.toLatin1()); QNetworkReply * rep = m_manager->get ( request ); m_reply = QSharedPointer ( rep, &QObject::deleteLater ); connect ( rep, SIGNAL ( downloadProgress ( qint64,qint64 ) ), SLOT ( downloadProgress ( qint64,qint64 ) ) ); @@ -120,8 +117,21 @@ void DownloadJob::downloadFinished() void DownloadJob::downloadReadyRead() { - if ( m_save_to_file ) + if( m_save_to_file ) { + if(!m_opened_for_saving) + { + if ( !m_output_file.open ( QIODevice::WriteOnly ) ) + { + /* + * Can't open the file... the job failed + */ + m_reply->abort(); + emit fail(); + return; + } + m_opened_for_saving = true; + } m_output_file.write ( m_reply->readAll() ); } } From ce253ded0e0d2ae90a971c2e074d561f5e7baeb2 Mon Sep 17 00:00:00 2001 From: Stiepen Date: Sun, 14 Jul 2013 20:26:53 +0200 Subject: [PATCH 06/11] Added Per-Instance settings --- MultiMC.pro | 9 +- gui/instancesettings.cpp | 89 +++++++++ gui/instancesettings.h | 32 ++++ gui/instancesettings.ui | 386 +++++++++++++++++++++++++++++++++++++++ gui/mainwindow.cpp | 16 ++ 5 files changed, 529 insertions(+), 3 deletions(-) create mode 100644 gui/instancesettings.cpp create mode 100644 gui/instancesettings.h create mode 100644 gui/instancesettings.ui diff --git a/MultiMC.pro b/MultiMC.pro index 3f480529..6af1ec0d 100644 --- a/MultiMC.pro +++ b/MultiMC.pro @@ -21,7 +21,8 @@ SOURCES += main.cpp\ data/inifile.cpp \ gui/settingsdialog.cpp \ gui/modeditwindow.cpp \ - util/appsettings.cpp + util/appsettings.cpp \ + gui/instancesettings.cpp HEADERS += gui/mainwindow.h \ data/instancebase.h \ @@ -32,11 +33,13 @@ HEADERS += gui/mainwindow.h \ gui/settingsdialog.h \ gui/modeditwindow.h \ util/apputils.h \ - util/appsettings.h + util/appsettings.h \ + gui/instancesettings.h FORMS += gui/mainwindow.ui \ gui/settingsdialog.ui \ - gui/modeditwindow.ui + gui/modeditwindow.ui \ + gui/instancesettings.ui RESOURCES += \ multimc.qrc diff --git a/gui/instancesettings.cpp b/gui/instancesettings.cpp new file mode 100644 index 00000000..7e82e1d6 --- /dev/null +++ b/gui/instancesettings.cpp @@ -0,0 +1,89 @@ +#include "instancesettings.h" +#include "ui_instancesettings.h" + +InstanceSettings::InstanceSettings(QWidget *parent) : + QDialog(parent), + ui(new Ui::InstanceSettings) +{ + ui->setupUi(this); +} + +InstanceSettings::~InstanceSettings() +{ + delete ui; +} + +void InstanceSettings::on_customCommandsGroupBox_toggled(bool state) +{ + ui->labelCustomCmdsDescription->setEnabled(state); +} + + +void InstanceSettings::applySettings(SettingsObject *s) +{ + + // Console + s->set("ShowConsole", ui->showConsoleCheck->isChecked()); + s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked()); + s->set("OverrideConsole", ui->consoleSettingsBox->isChecked()); + + // Window Size + s->set("LaunchCompatMode", ui->compatModeCheckBox->isChecked()); + s->set("LaunchMaximized", ui->maximizedCheckBox->isChecked()); + s->set("MinecraftWinWidth", ui->windowWidthSpinBox->value()); + s->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); + s->set("OverrideWindow", ui->windowSizeGroupBox->isChecked()); + + // Auto Login + s->set("AutoLogin", ui->autoLoginCheckBox->isChecked()); + s->set("OverrideLogin", ui->accountSettingsGroupBox->isChecked()); + + // Memory + s->set("MinMemAlloc", ui->minMemSpinBox->value()); + s->set("MaxMemAlloc", ui->maxMemSpinBox->value()); + s->set("OverrideMemory", ui->memoryGroupBox->isChecked()); + + // Java Settings + s->set("JavaPath", ui->javaPathTextBox->text()); + s->set("JvmArgs", ui->jvmArgsTextBox->text()); + s->set("OverrideJava", ui->javaSettingsGroupBox->isChecked()); + + // Custom Commands + s->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text()); + s->set("PostExitCommand", ui->postExitCmdTextBox->text()); + s->set("OverrideCommands", ui->customCommandsGroupBox->isChecked()); +} + +void InstanceSettings::loadSettings(SettingsObject *s) +{ + // Console + ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool()); + ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool()); + ui->consoleSettingsBox->setChecked(s->get("OverrideConsole").toBool()); + + // Window Size + ui->compatModeCheckBox->setChecked(s->get("LaunchCompatMode").toBool()); + ui->maximizedCheckBox->setChecked(s->get("LaunchMaximized").toBool()); + ui->windowWidthSpinBox->setValue(s->get("MinecraftWinWidth").toInt()); + ui->windowHeightSpinBox->setValue(s->get("MinecraftWinHeight").toInt()); + ui->windowSizeGroupBox->setChecked(s->get("OverrideWindow").toBool()); + + // Auto Login + ui->autoLoginCheckBox->setChecked(s->get("AutoLogin").toBool()); + ui->accountSettingsGroupBox->setChecked(s->get("OverrideLogin").toBool()); + + // Memory + ui->minMemSpinBox->setValue(s->get("MinMemAlloc").toInt()); + ui->maxMemSpinBox->setValue(s->get("MaxMemAlloc").toInt()); + ui->memoryGroupBox->setChecked(s->get("OverrideMemory").toBool()); + + // Java Settings + ui->javaPathTextBox->setText(s->get("JavaPath").toString()); + ui->jvmArgsTextBox->setText(s->get("JvmArgs").toString()); + ui->javaSettingsGroupBox->setChecked(s->get("OverrideJava").toBool()); + + // Custom Commands + ui->preLaunchCmdTextBox->setText(s->get("PreLaunchCommand").toString()); + ui->postExitCmdTextBox->setText(s->get("PostExitCommand").toString()); + ui->customCommandsGroupBox->setChecked(s->get("OverrideCommands").toBool()); +} diff --git a/gui/instancesettings.h b/gui/instancesettings.h new file mode 100644 index 00000000..af75a0f1 --- /dev/null +++ b/gui/instancesettings.h @@ -0,0 +1,32 @@ +#ifndef INSTANCESETTINGS_H +#define INSTANCESETTINGS_H + +#include + +namespace Ui { +class InstanceSettings; +} + +class InstanceSettings : public QDialog +{ + Q_OBJECT + +public: + explicit InstanceSettings(QWidget *parent = 0); + ~InstanceSettings(); + + void updateCheckboxStuff(); + + void applySettings(SettingsObject *s); + void loadSettings(SettingsObject* s); + +private slots: + void on_overrideGlobalMcCheck_clicked(bool checked); + + void on_customCommandsGroupBox_toggled(bool arg1); + +private: + Ui::InstanceSettings *ui; +}; + +#endif // INSTANCESETTINGS_H diff --git a/gui/instancesettings.ui b/gui/instancesettings.ui new file mode 100644 index 00000000..1fb8b023 --- /dev/null +++ b/gui/instancesettings.ui @@ -0,0 +1,386 @@ + + + InstanceSettings + + + + 0 + 0 + 453 + 563 + + + + Dialog + + + + + 9 + 9 + 435 + 516 + + + + QTabWidget::Rounded + + + 0 + + + + Minecraft + + + + + + true + + + Window Size + + + true + + + false + + + + + + Compatibility mode? + + + + + + + Start Minecraft maximized? + + + + + + + + + Window height: + + + + + + + Window width: + + + + + + + 854 + + + 65536 + + + 1 + + + 854 + + + + + + + 480 + + + 65536 + + + 480 + + + + + + + + + + + + true + + + Console Settings + + + true + + + false + + + + + + Show console while the game is running? + + + + + + + Automatically close console when the game quits? + + + + + + + + + + true + + + Account Settings + + + true + + + false + + + + + + false + + + Login automatically when an instance icon is double clicked? + + + false + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Java + + + + + + true + + + Memory + + + true + + + false + + + + + + 512 + + + 65536 + + + 128 + + + 1024 + + + + + + + Minimum memory allocation: + + + + + + + Maximum memory allocation: + + + + + + + 256 + + + 65536 + + + 128 + + + 256 + + + + + + + + + + true + + + Java Settings + + + true + + + false + + + + + + Java path: + + + + + + + + + + JVM arguments: + + + + + + + Auto-detect + + + + + + + + + + + + + true + + + Custom Commands + + + true + + + false + + + + + + Post-exit command: + + + + + + + Pre-launch command: + + + + + + + + + + + + + + + + false + + + + 0 + 0 + + + + Pre-launch command runs before the instance launches and post-exit command runs after it exits. Both will be run in MultiMC's working directory with INST_ID, INST_DIR, and INST_NAME as environment variables. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + + + + 270 + 530 + 166 + 23 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 8ba988c5..0b592cf0 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -553,3 +553,19 @@ void MainWindow::on_actionChangeInstLWJGLVersion_triggered() } } + +void MainWindow::on_actionInstanceSettings_triggered() +{ + if (view->selectionModel()->selectedIndexes().count() < 1) + return; + + Instance *inst = selectedInstance(); + SettingsObject *s; + s = &inst->settings(); + InstanceSettings *settings = new InstanceSettings (this); + settings->loadSettings(s); + if (settings->exec()) { + settings->applySettings(s); + } + delete settings; +} From b5450042b5f9ddaad7585f644591b7d009aeb5cb Mon Sep 17 00:00:00 2001 From: Stiepen Date: Sun, 14 Jul 2013 22:01:30 +0200 Subject: [PATCH 07/11] Broke instance loading(?), also attempted to make Toolbar grayed out when no instance is selected. For debug purposes it is initially not grayed out --- CMakeLists.txt | 3 +++ gui/instancesettings.cpp | 24 ++++++++++++++++++++++-- gui/instancesettings.h | 3 +-- gui/instancesettings.ui | 11 +++++++---- gui/mainwindow.cpp | 9 +++++++++ gui/mainwindow.h | 4 ++++ gui/mainwindow.ui | 5 ++++- 7 files changed, 50 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0a2123e..7463e063 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,6 +175,7 @@ gui/instancedelegate.h gui/versionselectdialog.h gui/lwjglselectdialog.h gui/iconcache.h +gui/instancesettings.h multimc_pragma.h @@ -206,6 +207,7 @@ gui/instancedelegate.cpp gui/versionselectdialog.cpp gui/lwjglselectdialog.cpp gui/iconcache.cpp +gui/instancesettings.cpp java/javautils.cpp java/annotations.cpp @@ -225,6 +227,7 @@ gui/aboutdialog.ui gui/consolewindow.ui gui/versionselectdialog.ui gui/lwjglselectdialog.ui +gui/instancesettings.ui ) diff --git a/gui/instancesettings.cpp b/gui/instancesettings.cpp index 7e82e1d6..d0e02b8e 100644 --- a/gui/instancesettings.cpp +++ b/gui/instancesettings.cpp @@ -1,3 +1,22 @@ +/* Copyright 2013 MultiMC Contributors + * + * Authors: Andrew Okin + * Peterix + * Orochimarufan + * + * 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. + */ + #include "instancesettings.h" #include "ui_instancesettings.h" @@ -35,7 +54,7 @@ void InstanceSettings::applySettings(SettingsObject *s) s->set("OverrideWindow", ui->windowSizeGroupBox->isChecked()); // Auto Login - s->set("AutoLogin", ui->autoLoginCheckBox->isChecked()); + s->set("AutoLogin", ui->autoLoginChecBox->isChecked()); s->set("OverrideLogin", ui->accountSettingsGroupBox->isChecked()); // Memory @@ -56,6 +75,7 @@ void InstanceSettings::applySettings(SettingsObject *s) void InstanceSettings::loadSettings(SettingsObject *s) { + // Console ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool()); ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool()); @@ -69,7 +89,7 @@ void InstanceSettings::loadSettings(SettingsObject *s) ui->windowSizeGroupBox->setChecked(s->get("OverrideWindow").toBool()); // Auto Login - ui->autoLoginCheckBox->setChecked(s->get("AutoLogin").toBool()); + ui->autoLoginChecBox->setChecked(s->get("AutoLogin").toBool()); ui->accountSettingsGroupBox->setChecked(s->get("OverrideLogin").toBool()); // Memory diff --git a/gui/instancesettings.h b/gui/instancesettings.h index af75a0f1..abd63199 100644 --- a/gui/instancesettings.h +++ b/gui/instancesettings.h @@ -2,6 +2,7 @@ #define INSTANCESETTINGS_H #include +#include "settingsobject.h" namespace Ui { class InstanceSettings; @@ -21,8 +22,6 @@ public: void loadSettings(SettingsObject* s); private slots: - void on_overrideGlobalMcCheck_clicked(bool checked); - void on_customCommandsGroupBox_toggled(bool arg1); private: diff --git a/gui/instancesettings.ui b/gui/instancesettings.ui index 1fb8b023..187275de 100644 --- a/gui/instancesettings.ui +++ b/gui/instancesettings.ui @@ -11,7 +11,7 @@ - Dialog + @@ -162,7 +162,7 @@ - false + true Login automatically when an instance icon is double clicked? @@ -370,12 +370,15 @@ - 270 + 9 530 - 166 + 435 23 + + Qt::Horizontal + QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 0b592cf0..4326431e 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -43,6 +43,7 @@ #include "gui/lwjglselectdialog.h" #include "gui/consolewindow.h" #include "gui/modeditwindow.h" +#include "gui/instancesettings.h" #include "kcategorizedview.h" #include "kcategorydrawer.h" @@ -130,6 +131,9 @@ MainWindow::MainWindow ( QWidget *parent ) : view->setModel ( proxymodel ); connect(view, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(instanceActivated(const QModelIndex &))); + + connect(view, SIGNAL(clicked(const QModelIndex &)), + this, SLOT(instanceChanged(const QModelIndex &))); // Load the instances. instList.loadList(); @@ -563,9 +567,14 @@ void MainWindow::on_actionInstanceSettings_triggered() SettingsObject *s; s = &inst->settings(); InstanceSettings *settings = new InstanceSettings (this); + settings->setWindowTitle(QString("Instance settings")); settings->loadSettings(s); if (settings->exec()) { settings->applySettings(s); } delete settings; } + +void MainWindow::instanceChanged(QModelIndex idx) { + ui->instanceToolBar->setEnabled(idx.isValid()); +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index f13d9395..a10d570c 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -108,8 +108,12 @@ private slots: void on_actionChangeInstLWJGLVersion_triggered(); + void on_actionInstanceSettings_triggered(); + public slots: void instanceActivated ( QModelIndex ); + + void instanceChanged ( QModelIndex ); void startTask(Task *task); diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index 771e7096..e6a82635 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -65,6 +65,9 @@ + + true + Instance Toolbar @@ -300,7 +303,7 @@ - false + true Settings From e2ee6d6d254285284f07b07cb60409fbda0bf7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 16 Jul 2013 00:30:32 +0200 Subject: [PATCH 08/11] Finalize the instance settings dialog, add setting reset mechanism --- gui/instancesettings.cpp | 213 ++++++++++++++++-------- gui/instancesettings.h | 19 ++- gui/instancesettings.ui | 35 +++- gui/mainwindow.cpp | 20 +-- libmultimc/src/instance.cpp | 12 ++ libsettings/include/inisettingsobject.h | 1 + libsettings/include/setting.h | 13 ++ libsettings/include/settingsobject.h | 22 +++ libsettings/src/inisettingsobject.cpp | 9 + libsettings/src/setting.cpp | 5 + libsettings/src/settingsobject.cpp | 18 ++ 11 files changed, 272 insertions(+), 95 deletions(-) diff --git a/gui/instancesettings.cpp b/gui/instancesettings.cpp index d0e02b8e..eea61ce8 100644 --- a/gui/instancesettings.cpp +++ b/gui/instancesettings.cpp @@ -20,90 +20,161 @@ #include "instancesettings.h" #include "ui_instancesettings.h" -InstanceSettings::InstanceSettings(QWidget *parent) : - QDialog(parent), - ui(new Ui::InstanceSettings) +InstanceSettings::InstanceSettings( SettingsObject * obj, QWidget *parent) : + m_obj(obj), + QDialog(parent), + ui(new Ui::InstanceSettings) { - ui->setupUi(this); + ui->setupUi(this); + loadSettings(); } InstanceSettings::~InstanceSettings() { - delete ui; + delete ui; } void InstanceSettings::on_customCommandsGroupBox_toggled(bool state) { - ui->labelCustomCmdsDescription->setEnabled(state); + ui->labelCustomCmdsDescription->setEnabled(state); } - -void InstanceSettings::applySettings(SettingsObject *s) +void InstanceSettings::on_buttonBox_accepted() { - - // Console - s->set("ShowConsole", ui->showConsoleCheck->isChecked()); - s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked()); - s->set("OverrideConsole", ui->consoleSettingsBox->isChecked()); - - // Window Size - s->set("LaunchCompatMode", ui->compatModeCheckBox->isChecked()); - s->set("LaunchMaximized", ui->maximizedCheckBox->isChecked()); - s->set("MinecraftWinWidth", ui->windowWidthSpinBox->value()); - s->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); - s->set("OverrideWindow", ui->windowSizeGroupBox->isChecked()); - - // Auto Login - s->set("AutoLogin", ui->autoLoginChecBox->isChecked()); - s->set("OverrideLogin", ui->accountSettingsGroupBox->isChecked()); - - // Memory - s->set("MinMemAlloc", ui->minMemSpinBox->value()); - s->set("MaxMemAlloc", ui->maxMemSpinBox->value()); - s->set("OverrideMemory", ui->memoryGroupBox->isChecked()); - - // Java Settings - s->set("JavaPath", ui->javaPathTextBox->text()); - s->set("JvmArgs", ui->jvmArgsTextBox->text()); - s->set("OverrideJava", ui->javaSettingsGroupBox->isChecked()); - - // Custom Commands - s->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text()); - s->set("PostExitCommand", ui->postExitCmdTextBox->text()); - s->set("OverrideCommands", ui->customCommandsGroupBox->isChecked()); + applySettings(); + accept(); } -void InstanceSettings::loadSettings(SettingsObject *s) +void InstanceSettings::on_buttonBox_rejected() { - - // Console - ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool()); - ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool()); - ui->consoleSettingsBox->setChecked(s->get("OverrideConsole").toBool()); - - // Window Size - ui->compatModeCheckBox->setChecked(s->get("LaunchCompatMode").toBool()); - ui->maximizedCheckBox->setChecked(s->get("LaunchMaximized").toBool()); - ui->windowWidthSpinBox->setValue(s->get("MinecraftWinWidth").toInt()); - ui->windowHeightSpinBox->setValue(s->get("MinecraftWinHeight").toInt()); - ui->windowSizeGroupBox->setChecked(s->get("OverrideWindow").toBool()); - - // Auto Login - ui->autoLoginChecBox->setChecked(s->get("AutoLogin").toBool()); - ui->accountSettingsGroupBox->setChecked(s->get("OverrideLogin").toBool()); - - // Memory - ui->minMemSpinBox->setValue(s->get("MinMemAlloc").toInt()); - ui->maxMemSpinBox->setValue(s->get("MaxMemAlloc").toInt()); - ui->memoryGroupBox->setChecked(s->get("OverrideMemory").toBool()); - - // Java Settings - ui->javaPathTextBox->setText(s->get("JavaPath").toString()); - ui->jvmArgsTextBox->setText(s->get("JvmArgs").toString()); - ui->javaSettingsGroupBox->setChecked(s->get("OverrideJava").toBool()); - - // Custom Commands - ui->preLaunchCmdTextBox->setText(s->get("PreLaunchCommand").toString()); - ui->postExitCmdTextBox->setText(s->get("PostExitCommand").toString()); - ui->customCommandsGroupBox->setChecked(s->get("OverrideCommands").toBool()); + reject(); +} + + +void InstanceSettings::applySettings() +{ + // Console + bool console = ui->consoleSettingsBox->isChecked(); + m_obj->set("OverrideConsole", console); + if(console) + { + m_obj->set("ShowConsole", ui->showConsoleCheck->isChecked()); + m_obj->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked()); + } + else + { + m_obj->reset("ShowConsole"); + m_obj->reset("AutoCloseConsole"); + } + + // Window Size + bool window = ui->windowSizeGroupBox->isChecked(); + m_obj->set("OverrideWindow", window); + if(window) + { + m_obj->set("LaunchCompatMode", ui->compatModeCheckBox->isChecked()); + m_obj->set("LaunchMaximized", ui->maximizedCheckBox->isChecked()); + m_obj->set("MinecraftWinWidth", ui->windowWidthSpinBox->value()); + m_obj->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); + } + else + { + m_obj->reset("LaunchCompatMode"); + m_obj->reset("LaunchMaximized"); + m_obj->reset("MinecraftWinWidth"); + m_obj->reset("MinecraftWinHeight"); + } + + + // Auto Login + bool login = ui->accountSettingsGroupBox->isChecked(); + m_obj->set("OverrideLogin", login); + if(login) + { + m_obj->set("AutoLogin", ui->autoLoginChecBox->isChecked()); + } + else + { + m_obj->reset("AutoLogin"); + } + + + // Memory + bool memory = ui->memoryGroupBox->isChecked(); + m_obj->set("OverrideMemory", memory); + if(memory) + { + m_obj->set("MinMemAlloc", ui->minMemSpinBox->value()); + m_obj->set("MaxMemAlloc", ui->maxMemSpinBox->value()); + } + else + { + m_obj->reset("MinMemAlloc"); + m_obj->reset("MaxMemAlloc"); + } + + + // Java Settings + bool java = ui->javaSettingsGroupBox->isChecked(); + m_obj->set("OverrideJava", java); + if(java) + { + m_obj->set("JavaPath", ui->javaPathTextBox->text()); + m_obj->set("JvmArgs", ui->jvmArgsTextBox->text()); + } + else + { + m_obj->reset("JavaPath"); + m_obj->reset("JvmArgs"); + } + + + // Custom Commands + bool custcmd = ui->customCommandsGroupBox->isChecked(); + m_obj->set("OverrideCommands", custcmd); + if(custcmd) + { + m_obj->set("PreLaunchCommand", ui->preLaunchCmdTextBox->text()); + m_obj->set("PostExitCommand", ui->postExitCmdTextBox->text()); + } + else + { + m_obj->reset("PreLaunchCommand"); + m_obj->reset("PostExitCommand"); + } + +} + +void InstanceSettings::loadSettings() +{ + // Console + ui->showConsoleCheck->setChecked(m_obj->get("ShowConsole").toBool()); + ui->autoCloseConsoleCheck->setChecked(m_obj->get("AutoCloseConsole").toBool()); + ui->consoleSettingsBox->setChecked(m_obj->get("OverrideConsole").toBool()); + + // Window Size + ui->compatModeCheckBox->setChecked(m_obj->get("LaunchCompatMode").toBool()); + ui->maximizedCheckBox->setChecked(m_obj->get("LaunchMaximized").toBool()); + ui->windowWidthSpinBox->setValue(m_obj->get("MinecraftWinWidth").toInt()); + ui->windowHeightSpinBox->setValue(m_obj->get("MinecraftWinHeight").toInt()); + ui->windowSizeGroupBox->setChecked(m_obj->get("OverrideWindow").toBool()); + + // Auto Login + ui->autoLoginChecBox->setChecked(m_obj->get("AutoLogin").toBool()); + ui->accountSettingsGroupBox->setChecked(m_obj->get("OverrideLogin").toBool()); + + // Memory + ui->minMemSpinBox->setValue(m_obj->get("MinMemAlloc").toInt()); + ui->maxMemSpinBox->setValue(m_obj->get("MaxMemAlloc").toInt()); + ui->memoryGroupBox->setChecked(m_obj->get("OverrideMemory").toBool()); + + // Java Settings + ui->javaPathTextBox->setText(m_obj->get("JavaPath").toString()); + ui->jvmArgsTextBox->setText(m_obj->get("JvmArgs").toString()); + ui->javaSettingsGroupBox->setChecked(m_obj->get("OverrideJava").toBool()); + + // Custom Commands + ui->preLaunchCmdTextBox->setText(m_obj->get("PreLaunchCommand").toString()); + ui->postExitCmdTextBox->setText(m_obj->get("PostExitCommand").toString()); + ui->customCommandsGroupBox->setChecked(m_obj->get("OverrideCommands").toBool()); } diff --git a/gui/instancesettings.h b/gui/instancesettings.h index abd63199..afbd0c16 100644 --- a/gui/instancesettings.h +++ b/gui/instancesettings.h @@ -10,22 +10,25 @@ class InstanceSettings; class InstanceSettings : public QDialog { - Q_OBJECT + Q_OBJECT public: - explicit InstanceSettings(QWidget *parent = 0); - ~InstanceSettings(); + explicit InstanceSettings(SettingsObject *s, QWidget *parent = 0); + ~InstanceSettings(); - void updateCheckboxStuff(); + void updateCheckboxStuff(); - void applySettings(SettingsObject *s); - void loadSettings(SettingsObject* s); + void applySettings(); + void loadSettings(); private slots: - void on_customCommandsGroupBox_toggled(bool arg1); + void on_customCommandsGroupBox_toggled(bool arg1); + void on_buttonBox_accepted(); + void on_buttonBox_rejected(); private: - Ui::InstanceSettings *ui; + Ui::InstanceSettings *ui; + SettingsObject * m_obj; }; #endif // INSTANCESETTINGS_H diff --git a/gui/instancesettings.ui b/gui/instancesettings.ui index 187275de..16e64100 100644 --- a/gui/instancesettings.ui +++ b/gui/instancesettings.ui @@ -162,7 +162,7 @@ - true + false Login automatically when an instance icon is double clicked? @@ -319,6 +319,9 @@ false + + + @@ -333,9 +336,6 @@ - - - @@ -362,6 +362,9 @@ true + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + @@ -384,6 +387,30 @@ + + settingsTabs + windowSizeGroupBox + compatModeCheckBox + maximizedCheckBox + windowWidthSpinBox + windowHeightSpinBox + consoleSettingsBox + showConsoleCheck + autoCloseConsoleCheck + accountSettingsGroupBox + autoLoginChecBox + memoryGroupBox + minMemSpinBox + maxMemSpinBox + javaSettingsGroupBox + javaPathTextBox + pushButton + jvmArgsTextBox + customCommandsGroupBox + preLaunchCmdTextBox + postExitCmdTextBox + buttonBox + diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 4326431e..4bf38424 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -560,19 +560,15 @@ void MainWindow::on_actionChangeInstLWJGLVersion_triggered() void MainWindow::on_actionInstanceSettings_triggered() { - if (view->selectionModel()->selectedIndexes().count() < 1) - return; + if (view->selectionModel()->selectedIndexes().count() < 1) + return; - Instance *inst = selectedInstance(); - SettingsObject *s; - s = &inst->settings(); - InstanceSettings *settings = new InstanceSettings (this); - settings->setWindowTitle(QString("Instance settings")); - settings->loadSettings(s); - if (settings->exec()) { - settings->applySettings(s); - } - delete settings; + Instance *inst = selectedInstance(); + SettingsObject *s; + s = &inst->settings(); + InstanceSettings settings(s, this); + settings.setWindowTitle(QString("Instance settings")); + settings.exec(); } void MainWindow::instanceChanged(QModelIndex idx) { diff --git a/libmultimc/src/instance.cpp b/libmultimc/src/instance.cpp index fde31cf3..c1506a02 100644 --- a/libmultimc/src/instance.cpp +++ b/libmultimc/src/instance.cpp @@ -62,6 +62,18 @@ Instance::Instance(const QString &rootDir, QObject *parent) : // Auto login settings().registerSetting(new OverrideSetting("AutoLogin", globalSettings->getSetting("AutoLogin"))); + + // Console + settings().registerSetting(new OverrideSetting("ShowConsole", globalSettings->getSetting("ShowConsole"))); + settings().registerSetting(new OverrideSetting("AutoCloseConsole", globalSettings->getSetting("AutoCloseConsole"))); + + // Overrides + settings().registerSetting(new Setting("OverrideConsole", false)); + settings().registerSetting(new Setting("OverrideWindow", false)); + settings().registerSetting(new Setting("OverrideLogin", false)); + settings().registerSetting(new Setting("OverrideMemory", false)); + settings().registerSetting(new Setting("OverrideJava", false)); + settings().registerSetting(new Setting("OverrideCommands", false)); } QString Instance::id() const diff --git a/libsettings/include/inisettingsobject.h b/libsettings/include/inisettingsobject.h index 36c8e4bd..03d6fe05 100644 --- a/libsettings/include/inisettingsobject.h +++ b/libsettings/include/inisettingsobject.h @@ -47,6 +47,7 @@ public: protected slots: virtual void changeSetting(const Setting &setting, QVariant value); + virtual void resetSetting ( const Setting& setting ); protected: virtual QVariant retrieveValue(const Setting &setting); diff --git a/libsettings/include/setting.h b/libsettings/include/setting.h index 36709729..a161ab50 100644 --- a/libsettings/include/setting.h +++ b/libsettings/include/setting.h @@ -84,6 +84,12 @@ signals: */ void settingChanged(const Setting &setting, QVariant value); + /*! + * \brief Signal emitted when this Setting object's value resets to default. + * \param setting A reference to the Setting that changed. + */ + void settingReset(const Setting &setting); + public slots: /*! * \brief Changes the setting's value. @@ -93,6 +99,13 @@ public slots: */ virtual void set(QVariant value); + /*! + * \brief Reset the setting to default + * This is done by emitting the settingReset() signal which will then be + * handled by the SettingsObject object and cause the setting to change. + * \param value The new value. + */ + virtual void reset(); protected: QString m_id; QVariant m_defVal; diff --git a/libsettings/include/settingsobject.h b/libsettings/include/settingsobject.h index 23f0d644..a2f03699 100644 --- a/libsettings/include/settingsobject.h +++ b/libsettings/include/settingsobject.h @@ -100,6 +100,11 @@ public: */ virtual bool set(const QString &id, QVariant value); + /*! + * \brief Reverts the setting with the given ID to default. + * \param id The ID of the setting to reset. + */ + virtual void reset(const QString &id) const; /*! * \brief Gets a QList with pointers to all of the registered settings. @@ -125,6 +130,14 @@ signals: */ void settingChanged(const Setting &setting, QVariant value); + /*! + * \brief Signal emitted when one of this SettingsObject object's settings resets. + * This is usually just connected directly to each Setting object's + * settingReset() signals. + * \param setting A reference to the Setting object that changed. + */ + void settingReset(const Setting &setting); + protected slots: /*! * \brief Changes a setting. @@ -136,6 +149,15 @@ protected slots: */ virtual void changeSetting(const Setting &setting, QVariant value) = 0; + /*! + * \brief Resets a setting. + * This slot is usually connected to each Setting object's + * settingReset() signal. The signal is emitted, causing this slot + * to update the setting's value in the config file. + * \param setting A reference to the Setting object that changed. + */ + virtual void resetSetting(const Setting &setting) = 0; + protected: /*! * \brief Connects the necessary signals to the given Setting. diff --git a/libsettings/src/inisettingsobject.cpp b/libsettings/src/inisettingsobject.cpp index 17b132a3..854421b6 100644 --- a/libsettings/src/inisettingsobject.cpp +++ b/libsettings/src/inisettingsobject.cpp @@ -40,6 +40,15 @@ void INISettingsObject::changeSetting(const Setting &setting, QVariant value) } } +void INISettingsObject::resetSetting ( const Setting& setting ) +{ + if (contains(setting.id())) + { + m_ini.remove(setting.configKey()); + m_ini.saveFile(m_filePath); + } +} + QVariant INISettingsObject::retrieveValue(const Setting &setting) { if (contains(setting.id())) diff --git a/libsettings/src/setting.cpp b/libsettings/src/setting.cpp index 1a4f9e13..8e60af06 100644 --- a/libsettings/src/setting.cpp +++ b/libsettings/src/setting.cpp @@ -47,3 +47,8 @@ void Setting::set(QVariant value) { emit settingChanged(*this, value); } + +void Setting::reset() +{ + emit settingReset(*this); +} diff --git a/libsettings/src/settingsobject.cpp b/libsettings/src/settingsobject.cpp index f94a6552..bf7b8825 100644 --- a/libsettings/src/settingsobject.cpp +++ b/libsettings/src/settingsobject.cpp @@ -98,6 +98,14 @@ bool SettingsObject::set(const QString &id, QVariant value) } } +void SettingsObject::reset(const QString &id) const +{ + Setting *setting = getSetting(id); + if(setting) + setting->reset(); +} + + QList SettingsObject::getSettings() { return m_settings.values(); @@ -115,6 +123,11 @@ void SettingsObject::connectSignals(const Setting &setting) SLOT(changeSetting(const Setting &, QVariant))); connect(&setting, SIGNAL(settingChanged(const Setting &, QVariant)), SIGNAL(settingChanged(const Setting &, QVariant))); + + connect(&setting, SIGNAL(settingReset(Setting)), + SLOT(resetSetting(const Setting &))); + connect(&setting, SIGNAL(settingReset(Setting)), + SIGNAL(settingReset(const Setting &))); } void SettingsObject::disconnectSignals(const Setting &setting) @@ -123,4 +136,9 @@ void SettingsObject::disconnectSignals(const Setting &setting) this, SLOT(changeSetting(const Setting &, QVariant))); setting.disconnect(SIGNAL(settingChanged(const Setting &, QVariant)), this, SIGNAL(settingChanged(const Setting &, QVariant))); + + setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)), + this, SLOT(resetSetting(const Setting &, QVariant))); + setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)), + this, SIGNAL(settingReset(const Setting &, QVariant))); } From 18853ca3fa185f5fe5288a1d0c8ed6cf8c678007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 22 Jul 2013 02:01:56 +0200 Subject: [PATCH 09/11] Parsing the version files, part I --- libmultimc/CMakeLists.txt | 6 ++ libmultimc/include/fullversion.h | 68 ++++++++++++++ libmultimc/include/fullversionfactory.h | 23 +++++ libmultimc/include/library.h | 18 ++++ libmultimc/src/fullversion.cpp | 4 + libmultimc/src/fullversionfactory.cpp | 113 ++++++++++++++++++++++++ libmultimc/src/gameupdatetask.cpp | 71 ++------------- libmultimc/src/library.cpp | 18 ++++ 8 files changed, 258 insertions(+), 63 deletions(-) create mode 100644 libmultimc/include/fullversion.h create mode 100644 libmultimc/include/fullversionfactory.h create mode 100644 libmultimc/include/library.h create mode 100644 libmultimc/src/fullversion.cpp create mode 100644 libmultimc/src/fullversionfactory.cpp create mode 100644 libmultimc/src/library.cpp diff --git a/libmultimc/CMakeLists.txt b/libmultimc/CMakeLists.txt index 0209f8a4..8adee1ec 100644 --- a/libmultimc/CMakeLists.txt +++ b/libmultimc/CMakeLists.txt @@ -32,6 +32,9 @@ include/instversionlist.h include/minecraftversion.h include/minecraftversionlist.h +include/library.h +include/fullversion.h +include/fullversionfactory.h # Tasks include/task.h @@ -63,6 +66,9 @@ src/instversionlist.cpp src/minecraftversion.cpp src/minecraftversionlist.cpp +src/library.cpp +src/fullversion.cpp +src/fullversionfactory.cpp # Tasks src/task.cpp diff --git a/libmultimc/include/fullversion.h b/libmultimc/include/fullversion.h new file mode 100644 index 00000000..b1de02a3 --- /dev/null +++ b/libmultimc/include/fullversion.h @@ -0,0 +1,68 @@ +#pragma once +#include +#include + +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! + QStringList 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 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..673a6a72 --- /dev/null +++ b/libmultimc/include/fullversionfactory.h @@ -0,0 +1,23 @@ +#pragma once +#include + +struct FullVersion; + +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 parse(QByteArray data); +private: + QSharedPointer parse4(QJsonObject root, QSharedPointer product); + QStringList legacyWhitelist; +}; \ No newline at end of file diff --git a/libmultimc/include/library.h b/libmultimc/include/library.h new file mode 100644 index 00000000..10ecb9f3 --- /dev/null +++ b/libmultimc/include/library.h @@ -0,0 +1,18 @@ +/* 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 + + diff --git a/libmultimc/src/fullversion.cpp b/libmultimc/src/fullversion.cpp new file mode 100644 index 00000000..d66ce5bb --- /dev/null +++ b/libmultimc/src/fullversion.cpp @@ -0,0 +1,4 @@ +#include "fullversion.h" + + +// ECHO, echo, echo, .... \ No newline at end of file diff --git a/libmultimc/src/fullversionfactory.cpp b/libmultimc/src/fullversionfactory.cpp new file mode 100644 index 00000000..8873ee2d --- /dev/null +++ b/libmultimc/src/fullversionfactory.cpp @@ -0,0 +1,113 @@ +#include "fullversionfactory.h" +#include "fullversion.h" + +QSharedPointer FullVersionFactory::parse4(QJsonObject root, QSharedPointer product) +{ + product->id = root.value("id").toString(); + + // if it's on our legacy list, it's legacy + if(legacyWhitelist.contains(product->id)) + product->isLegacy = true; + + product->mainClass = root.value("mainClass").toString(); + auto procArgsValue = root.value("processArguments"); + if(procArgsValue.isString()) + { + product->processArguments = procArgsValue.toString(); + QString toCompare = product->processArguments.toLower(); + if(toCompare == "legacy") + { + product->minecraftArguments = " ${auth_player_name} ${auth_session}"; + product->isLegacy = true; + } + else if(toCompare == "username_session") + { + product->minecraftArguments = "--username ${auth_player_name} --session ${auth_session}"; + } + else if(toCompare == "username_session_version") + { + product->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}"; + } + } + + auto minecraftArgsValue = root.value("minecraftArguments"); + if(minecraftArgsValue.isString()) + { + product->minecraftArguments = minecraftArgsValue.toString(); + } + + product->releaseTime = root.value("releaseTime").toString(); + product->time = root.value("time").toString(); + + // Iterate through the list. + auto librariesValue = root.value("libraries"); + if(librariesValue.isArray()) + { + QJsonArray libList = root.value("libraries").toArray(); + for (auto lib : libList) + { + if (!lib.isObject()) + { + continue; + } + + QJsonObject libObj = lib.toObject(); + + QString crud = libObj.value("name").toString(); + product->libraries.append(crud); + + // TODO: improve! + /* + auto parts = crud.split(':'); + int zz = parts.size(); + */ + } + } + return product; +} + +QSharedPointer FullVersionFactory::parse(QByteArray data) +{ + QSharedPointer readVersion(new FullVersion()); + + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); + + if (jsonError.error != QJsonParseError::NoError) + { + error_string = QString( "Error reading version file :") + " " + jsonError.errorString(); + m_error = FullVersionFactory::ParseError; + return QSharedPointer(); + } + + if(!jsonDoc.isObject()) + { + error_string = "Error reading version file."; + m_error = FullVersionFactory::ParseError; + return QSharedPointer(); + } + QJsonObject root = jsonDoc.object(); + + readVersion->minimumLauncherVersion = root.value("minimumLauncherVersion").toDouble(); + switch(readVersion->minimumLauncherVersion) + { + case 1: + case 2: + case 3: + case 4: + return parse4(root, readVersion); + // ADD MORE HERE :D + default: + error_string = "Version file was for an unrecognized launcher version. RIP"; + m_error = FullVersionFactory::UnsupportedVersion; + return QSharedPointer(); + } +} + + +FullVersionFactory::FullVersionFactory() +{ + m_error = FullVersionFactory::AllOK; + legacyWhitelist.append("1.5.1"); + legacyWhitelist.append("1.5.2"); +} diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index b6c1f936..61880118 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -25,9 +25,12 @@ #include #include "minecraftversionlist.h" +#include "fullversionfactory.h" +#include #include "pathutils.h" + GameUpdateTask::GameUpdateTask(const LoginResponse &response, Instance *inst, QObject *parent) : Task(parent), m_response(response) { @@ -86,78 +89,20 @@ void GameUpdateTask::versionFileFinished() { JobPtr firstJob = specificVersionDownloadJob->getFirstJob(); auto DlJob = firstJob.dynamicCast(); - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(DlJob->m_data, &jsonError); + FullVersionFactory parser; + auto version = parser.parse(DlJob->m_data); - if (jsonError.error != QJsonParseError::NoError) + if(!version) { - error(QString( "Error reading version file :") + " " + jsonError.errorString()); + error(parser.error_string); exit(0); } - if(!jsonDoc.isObject()) - { - error("Error reading version file."); - exit(0); - } - QJsonObject root = jsonDoc.object(); - - /* - * FIXME: this distinction is pretty weak. The only other option - * is to have a list of all the legacy versions. - */ - QString args = root.value("processArguments").toString("legacy"); - if(args == "legacy") + if(version->isLegacy) { getLegacyJar(); return; } - /* - // Iterate through the list. - QJsonObject groupList = root.value("libraries").toObject(); - - for (QJsonObject::iterator iter = groupList.begin(); - iter != groupList.end(); iter++) - { - QString groupName = iter.key(); - - // If not an object, complain and skip to the next one. - if (!iter.value().isObject()) - { - qWarning(QString("Group '%1' in the group list should " - "be an object.").arg(groupName).toUtf8()); - continue; - } - - QJsonObject groupObj = iter.value().toObject(); - - // Create the group object. - InstanceGroup *group = new InstanceGroup(groupName, this); - groups.push_back(group); - - // If 'hidden' isn't a bool value, just assume it's false. - if (groupObj.value("hidden").isBool() && groupObj.value("hidden").toBool()) - { - group->setHidden(groupObj.value("hidden").toBool()); - } - - if (!groupObj.value("instances").isArray()) - { - qWarning(QString("Group '%1' in the group list is invalid. " - "It should contain an array " - "called 'instances'.").arg(groupName).toUtf8()); - continue; - } - - // Iterate through the list of instances in the group. - QJsonArray instancesArray = groupObj.value("instances").toArray(); - - for (QJsonArray::iterator iter2 = instancesArray.begin(); - iter2 != instancesArray.end(); iter2++) - { - groupMap[(*iter2).toString()] = groupName; - } - }*/ // save the version file in $instanceId/version.json and versions/$version/$version.json QString version_id = targetVersion->descriptor(); diff --git a/libmultimc/src/library.cpp b/libmultimc/src/library.cpp new file mode 100644 index 00000000..b0490616 --- /dev/null +++ b/libmultimc/src/library.cpp @@ -0,0 +1,18 @@ +/* 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. + */ + +#include "include/library.h" + +// default url for lib: https://s3.amazonaws.com/Minecraft.Download/libraries/ From 97cf08f964ceebf4cb98b46f473bf952007a8a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 24 Jul 2013 23:44:00 +0200 Subject: [PATCH 10/11] Parsing the version files, part II --- libmultimc/include/fullversion.h | 5 +- libmultimc/include/library.h | 117 ++++++++++++++++++++++ libmultimc/src/fullversion.cpp | 2 +- libmultimc/src/fullversionfactory.cpp | 137 ++++++++++++++++++++------ libmultimc/src/library.cpp | 19 ++++ 5 files changed, 246 insertions(+), 34 deletions(-) diff --git a/libmultimc/include/fullversion.h b/libmultimc/include/fullversion.h index b1de02a3..523ac87c 100644 --- a/libmultimc/include/fullversion.h +++ b/libmultimc/include/fullversion.h @@ -1,6 +1,7 @@ #pragma once #include -#include + +class Library; class FullVersion { @@ -40,7 +41,7 @@ public: QString mainClass; // the list of libs. just the names for now. expand to full-blown strutures! - QStringList libraries; + QList > libraries; // is this actually a legacy version? if so, none of the other stuff here will be ever used. // added by FullVersionFactory diff --git a/libmultimc/include/library.h b/libmultimc/include/library.h index 10ecb9f3..30270bc1 100644 --- a/libmultimc/include/library.h +++ b/libmultimc/include/library.h @@ -15,4 +15,121 @@ #pragma once +#include +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, + 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 + + +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); + } +public: + OsRule(RuleAction result, OpSys system, QString version_regexp) + : Rule(result), m_system(system), m_version_regexp(version_regexp) {} +}; + +class ImplicitRule : public Rule +{ +protected: + virtual bool applies ( Library* ) + { + return true; + } +public: + ImplicitRule(RuleAction result) + : Rule(result) {} +}; + +class Library +{ +public: + QString base_url; + QString name; + QList > rules; + QMap natives; + QStringList extract_excludes; + + void AddRule(RuleAction result) + { + rules.append(QSharedPointer(new ImplicitRule(result))); + } + void AddRule(RuleAction result, OpSys system, QString version_regexp) + { + rules.append(QSharedPointer(new OsRule(result, system, version_regexp))); + } + 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; + } +}; diff --git a/libmultimc/src/fullversion.cpp b/libmultimc/src/fullversion.cpp index d66ce5bb..6f4662b4 100644 --- a/libmultimc/src/fullversion.cpp +++ b/libmultimc/src/fullversion.cpp @@ -1,4 +1,4 @@ +#include #include "fullversion.h" - // ECHO, echo, echo, .... \ No newline at end of file diff --git a/libmultimc/src/fullversionfactory.cpp b/libmultimc/src/fullversionfactory.cpp index 8873ee2d..9b4ae266 100644 --- a/libmultimc/src/fullversionfactory.cpp +++ b/libmultimc/src/fullversionfactory.cpp @@ -1,69 +1,144 @@ #include "fullversionfactory.h" #include "fullversion.h" +#include -QSharedPointer FullVersionFactory::parse4(QJsonObject root, QSharedPointer product) +QSharedPointer FullVersionFactory::parse4(QJsonObject root, QSharedPointer fullVersion) { - product->id = root.value("id").toString(); + fullVersion->id = root.value("id").toString(); // if it's on our legacy list, it's legacy - if(legacyWhitelist.contains(product->id)) - product->isLegacy = true; + if(legacyWhitelist.contains(fullVersion->id)) + fullVersion->isLegacy = true; - product->mainClass = root.value("mainClass").toString(); + fullVersion->mainClass = root.value("mainClass").toString(); auto procArgsValue = root.value("processArguments"); if(procArgsValue.isString()) { - product->processArguments = procArgsValue.toString(); - QString toCompare = product->processArguments.toLower(); + fullVersion->processArguments = procArgsValue.toString(); + QString toCompare = fullVersion->processArguments.toLower(); if(toCompare == "legacy") { - product->minecraftArguments = " ${auth_player_name} ${auth_session}"; - product->isLegacy = true; + fullVersion->minecraftArguments = " ${auth_player_name} ${auth_session}"; + fullVersion->isLegacy = true; } else if(toCompare == "username_session") { - product->minecraftArguments = "--username ${auth_player_name} --session ${auth_session}"; + fullVersion->minecraftArguments = "--username ${auth_player_name} --session ${auth_session}"; } else if(toCompare == "username_session_version") { - product->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}"; + fullVersion->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}"; } } auto minecraftArgsValue = root.value("minecraftArguments"); if(minecraftArgsValue.isString()) { - product->minecraftArguments = minecraftArgsValue.toString(); + fullVersion->minecraftArguments = minecraftArgsValue.toString(); } - product->releaseTime = root.value("releaseTime").toString(); - product->time = root.value("time").toString(); + fullVersion->releaseTime = root.value("releaseTime").toString(); + fullVersion->time = root.value("time").toString(); - // Iterate through the list. + // Iterate through the list, if it's a list. auto librariesValue = root.value("libraries"); - if(librariesValue.isArray()) + if(!librariesValue.isArray()) + return fullVersion; + + QJsonArray libList = root.value("libraries").toArray(); + for (auto libVal : libList) { - QJsonArray libList = root.value("libraries").toArray(); - for (auto lib : libList) + QSharedPointer library(new Library()); + if (!libVal.isObject()) { - if (!lib.isObject()) + continue; + } + + QJsonObject libObj = libVal.toObject(); + + // Library name + auto nameVal = libObj.value("name"); + if(!nameVal.isString()) + continue; + library->name = nameVal.toString(); + + // Extract excludes (if any) + auto extractVal = libObj.value("extract"); + if(extractVal.isObject()) + { + QStringList excludes; + auto extractObj = extractVal.toObject(); + auto excludesVal = extractObj.value("exclude"); + if(!excludesVal.isArray()) + goto SKIP_EXTRACTS; + auto excludesList = excludesVal.toArray(); + for(auto excludeVal : excludesList) { - continue; + if(excludeVal.isString()) + excludes.append(excludeVal.toString()); } + library->extract_excludes = excludes; + } + SKIP_EXTRACTS: + + auto nativesVal = libObj.value("natives"); + if(nativesVal.isObject()) + { + auto nativesObj = nativesVal.toObject(); + auto iter = nativesObj.begin(); + while(iter != nativesObj.end()) + { + auto osType = OpSys_fromString(iter.key()); + if(osType == Os_Other) + continue; + if(!iter.value().isString()) + continue; + library->natives[osType] = iter.value().toString(); + iter++; + } + } + + // Library rules (if any) + auto rulesVal = libObj.value("rules"); + if(rulesVal.isArray()) + { + QList > rules; - QJsonObject libObj = lib.toObject(); - - QString crud = libObj.value("name").toString(); - product->libraries.append(crud); - - // TODO: improve! - /* - auto parts = crud.split(':'); - int zz = parts.size(); - */ + QJsonArray ruleList = rulesVal.toArray(); + for(auto ruleVal : ruleList) + { + QSharedPointer rule; + if(!ruleVal.isObject()) + continue; + auto ruleObj = ruleVal.toObject(); + auto actionVal = ruleObj.value("action"); + if(!actionVal.isString()) + continue; + auto action = RuleAction_fromString(actionVal.toString()); + if(action == Defer) + continue; + + auto osVal = ruleObj.value("os"); + if(!osVal.isObject()) + { + rule.reset(new ImplicitRule(action)); + } + else + { + auto osObj = osVal.toObject(); + auto osNameVal = osObj.value("name"); + if(!osNameVal.isString()) + continue; + OpSys requiredOs = OpSys_fromString(osNameVal.toString()); + QString versionRegex = osObj.value("version").toString(); + rule.reset(new OsRule(action, requiredOs, versionRegex)); + } + rules.append(rule); + } + library->rules = rules; } } - return product; + return fullVersion; } QSharedPointer FullVersionFactory::parse(QByteArray data) diff --git a/libmultimc/src/library.cpp b/libmultimc/src/library.cpp index b0490616..0fb4f9d3 100644 --- a/libmultimc/src/library.cpp +++ b/libmultimc/src/library.cpp @@ -15,4 +15,23 @@ #include "include/library.h" +RuleAction RuleAction_fromString(QString name) +{ + 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; +} // default url for lib: https://s3.amazonaws.com/Minecraft.Download/libraries/ From a7a84d4dbb58565f108cb0886da6cb786e34d10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 27 Jul 2013 11:41:45 +0200 Subject: [PATCH 11/11] Parsing the version files, part III --- libmultimc/include/fullversionfactory.h | 2 + libmultimc/include/instance.h | 16 ++- libmultimc/include/library.h | 180 +++++++++++++++++------- libmultimc/src/fullversion.cpp | 1 + libmultimc/src/fullversionfactory.cpp | 104 ++++++++------ libmultimc/src/gameupdatetask.cpp | 2 + libmultimc/src/instance.cpp | 1 + libmultimc/src/library.cpp | 2 +- 8 files changed, 214 insertions(+), 94 deletions(-) diff --git a/libmultimc/include/fullversionfactory.h b/libmultimc/include/fullversionfactory.h index 673a6a72..60e5c983 100644 --- a/libmultimc/include/fullversionfactory.h +++ b/libmultimc/include/fullversionfactory.h @@ -2,6 +2,7 @@ #include struct FullVersion; +class Rule; class FullVersionFactory { @@ -19,5 +20,6 @@ public: QSharedPointer parse(QByteArray data); private: QSharedPointer parse4(QJsonObject root, QSharedPointer product); + QList > parse4rules(QJsonObject & baseObj); QStringList legacyWhitelist; }; \ No newline at end of file diff --git a/libmultimc/include/instance.h b/libmultimc/include/instance.h index 526025be..f6857cd8 100644 --- a/libmultimc/include/instance.h +++ b/libmultimc/include/instance.h @@ -116,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) @@ -250,6 +253,15 @@ public: virtual qint64 lastCurrentVersionUpdate() const { return settings().get("lastVersionUpdate").value(); } virtual void setLastCurrentVersionUpdate(qint64 val) { settings().set("lastVersionUpdate", val); } + virtual bool isForNewLauncher() + { + return settings().get("IsForNewLauncher").value(); + } + + 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 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 create(RuleAction result, OpSys system, QString version_regexp) + { + return QSharedPointer (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 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 actuall active on the current OS? + bool m_is_active; + + // native lib? + bool m_is_native; + QMap m_native_suffixes; public: - QString base_url; - QString name; - QList > rules; - QMap 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(new ImplicitRule(result))); - } - void AddRule(RuleAction result, OpSys system, QString version_regexp) + 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) { - rules.append(QSharedPointer(new OsRule(result, system, version_regexp))); + 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 > 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; } }; diff --git a/libmultimc/src/fullversion.cpp b/libmultimc/src/fullversion.cpp index 6f4662b4..53664c2a 100644 --- a/libmultimc/src/fullversion.cpp +++ b/libmultimc/src/fullversion.cpp @@ -1,4 +1,5 @@ #include #include "fullversion.h" +#include // ECHO, echo, echo, .... \ No newline at end of file diff --git a/libmultimc/src/fullversionfactory.cpp b/libmultimc/src/fullversionfactory.cpp index 9b4ae266..bb55b4a9 100644 --- a/libmultimc/src/fullversionfactory.cpp +++ b/libmultimc/src/fullversionfactory.cpp @@ -2,6 +2,61 @@ #include "fullversion.h" #include +class LibraryFinalizer +{ +public: + LibraryFinalizer(QSharedPointer library) + { + m_library = library; + } + + QSharedPointer m_library; +}; + +// Library rules (if any) +QList > FullVersionFactory::parse4rules(QJsonObject & baseObj) +{ + QList > rules; + auto rulesVal = baseObj.value("rules"); + if(rulesVal.isArray()) + { + QJsonArray ruleList = rulesVal.toArray(); + for(auto ruleVal : ruleList) + { + QSharedPointer rule; + if(!ruleVal.isObject()) + continue; + auto ruleObj = ruleVal.toObject(); + auto actionVal = ruleObj.value("action"); + if(!actionVal.isString()) + continue; + auto action = RuleAction_fromString(actionVal.toString()); + if(action == Defer) + continue; + + auto osVal = ruleObj.value("os"); + if(!osVal.isObject()) + { + // add a new implicit action rule + rules.append(ImplicitRule::create(action)); + } + else + { + auto osObj = osVal.toObject(); + auto osNameVal = osObj.value("name"); + if(!osNameVal.isString()) + continue; + OpSys requiredOs = OpSys_fromString(osNameVal.toString()); + QString versionRegex = osObj.value("version").toString(); + // add a new OS rule + rules.append(OsRule::create(action, requiredOs, versionRegex)); + } + } + } + return rules; +} + + QSharedPointer FullVersionFactory::parse4(QJsonObject root, QSharedPointer fullVersion) { fullVersion->id = root.value("id").toString(); @@ -48,7 +103,6 @@ QSharedPointer FullVersionFactory::parse4(QJsonObject root, QShared QJsonArray libList = root.value("libraries").toArray(); for (auto libVal : libList) { - QSharedPointer library(new Library()); if (!libVal.isObject()) { continue; @@ -60,7 +114,7 @@ QSharedPointer FullVersionFactory::parse4(QJsonObject root, QShared auto nameVal = libObj.value("name"); if(!nameVal.isString()) continue; - library->name = nameVal.toString(); + QSharedPointer library(new Library(nameVal.toString())); // Extract excludes (if any) auto extractVal = libObj.value("extract"); @@ -84,6 +138,7 @@ QSharedPointer FullVersionFactory::parse4(QJsonObject root, QShared auto nativesVal = libObj.value("natives"); if(nativesVal.isObject()) { + library->setIsNative(); auto nativesObj = nativesVal.toObject(); auto iter = nativesObj.begin(); while(iter != nativesObj.end()) @@ -93,50 +148,13 @@ QSharedPointer FullVersionFactory::parse4(QJsonObject root, QShared continue; if(!iter.value().isString()) continue; - library->natives[osType] = iter.value().toString(); + library->addNative(osType, iter.value().toString()); iter++; } } - - // Library rules (if any) - auto rulesVal = libObj.value("rules"); - if(rulesVal.isArray()) - { - QList > rules; - - QJsonArray ruleList = rulesVal.toArray(); - for(auto ruleVal : ruleList) - { - QSharedPointer rule; - if(!ruleVal.isObject()) - continue; - auto ruleObj = ruleVal.toObject(); - auto actionVal = ruleObj.value("action"); - if(!actionVal.isString()) - continue; - auto action = RuleAction_fromString(actionVal.toString()); - if(action == Defer) - continue; - - auto osVal = ruleObj.value("os"); - if(!osVal.isObject()) - { - rule.reset(new ImplicitRule(action)); - } - else - { - auto osObj = osVal.toObject(); - auto osNameVal = osObj.value("name"); - if(!osNameVal.isString()) - continue; - OpSys requiredOs = OpSys_fromString(osNameVal.toString()); - QString versionRegex = osObj.value("version").toString(); - rule.reset(new OsRule(action, requiredOs, versionRegex)); - } - rules.append(rule); - } - library->rules = rules; - } + library->setRules(parse4rules(libObj)); + library->finalize(); + fullVersion->libraries.append(library); } return fullVersion; } diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp index 61880118..bae85c17 100644 --- a/libmultimc/src/gameupdatetask.cpp +++ b/libmultimc/src/gameupdatetask.cpp @@ -141,6 +141,7 @@ void GameUpdateTask::jarlibFinished() { m_inst->setCurrentVersion(targetVersion->descriptor()); m_inst->setShouldUpdate(false); + m_inst->setIsForNewLauncher(true); exit(1); } @@ -195,6 +196,7 @@ void GameUpdateTask::legacyJarFinished() { setState(StateFinished); emit gameUpdateComplete(m_response); + m_inst->setIsForNewLauncher(true); exit(1); } diff --git a/libmultimc/src/instance.cpp b/libmultimc/src/instance.cpp index c1506a02..5fdb5064 100644 --- a/libmultimc/src/instance.cpp +++ b/libmultimc/src/instance.cpp @@ -34,6 +34,7 @@ Instance::Instance(const QString &rootDir, QObject *parent) : settings().registerSetting(new Setting("iconKey", "default")); settings().registerSetting(new Setting("notes", "")); settings().registerSetting(new Setting("NeedsRebuild", true)); + settings().registerSetting(new Setting("IsForNewLauncher", false)); settings().registerSetting(new Setting("ShouldUpdate", false)); settings().registerSetting(new Setting("JarVersion", "Unknown")); settings().registerSetting(new Setting("LwjglVersion", "2.9.0")); diff --git a/libmultimc/src/library.cpp b/libmultimc/src/library.cpp index 0fb4f9d3..9d4cc6e3 100644 --- a/libmultimc/src/library.cpp +++ b/libmultimc/src/library.cpp @@ -34,4 +34,4 @@ OpSys OpSys_fromString(QString name) return Os_OSX; return Os_Other; } -// default url for lib: https://s3.amazonaws.com/Minecraft.Download/libraries/ +// default url for lib: