From a23323a01ee2713209619ad99d8859616aa99cdb Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 7 Jul 2013 18:12:09 +0200 Subject: 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()); -- cgit From ee5583251d92d47f96b03c3b447c115bab901c17 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 7 Jul 2013 23:51:26 +0200 Subject: Legacy versions downloaded from the new location are treated as legacy versions! --- libmultimc/include/gameupdatetask.h | 72 ++++--------- libmultimc/src/gameupdatetask.cpp | 196 ++++++++++++++++++------------------ libutil/include/dlqueue.h | 2 +- libutil/src/dlqueue.cpp | 12 +-- 4 files changed, 122 insertions(+), 160 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,16 +50,6 @@ void GameUpdateTask::executeTask() return; } - // Make directories - QDir binDir(m_inst->binDir()); - if (!binDir.exists() && !binDir.mkpath(".")) - { - error("Failed to create bin folder."); - return; - } - - - ///////////////////////// // BUILD DOWNLOAD LIST // ///////////////////////// @@ -72,90 +57,116 @@ void GameUpdateTask::executeTask() 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"))); - - - - //////////////////// - // DOWNLOAD FILES // - //////////////////// - setState(StateDownloadFiles); - for (int i = 0; i < m_downloadList.length(); i++) { - m_currentDownload = i; - if (!downloadFile(m_downloadList[i])) - return; + 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(); - /////////////////// - // INSTALL FILES // - /////////////////// - setState(StateInstall); - - // Nothing to do here yet - + QString args = root.value("processArguments").toString("legacy"); + if(args == "legacy") + { + getLegacyJar(); + return; + } - ////////////// - // FINISHED // - ////////////// - setState(StateFinished); - emit gameUpdateComplete(m_response); + error("MC 1.6 isn't supported yet..."); + exit(0); } -bool GameUpdateTask::downloadFile( const FileToDownloadPtr file ) +void GameUpdateTask::versionFileFailed() { - 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) + 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(".")) { - 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(); + error("Failed to create bin folder."); + return; } - else + + // 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"; + if (targetVersion->launcherVersion() == MinecraftVersion::Launcher16) { - error("Can't download " + file->url().toString() + ": " + reply->errorString()); - return false; + jarFilename = targetVersion->descriptor(); } - // TODO: Check file integrity after downloading. + QUrl mcJarURL = targetVersion->downloadURL() + jarFilename + ".jar"; + qDebug() << mcJarURL.toString(); + 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))); - return true; + download_queue.enqueue(legacyDownloadJob); +} + + +void GameUpdateTask::legacyJarFinished() +{ + 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)); -} - -FileToDownloadPtr FileToDownload::Create(const QUrl &url, const QString &path, QObject *parent) -{ - return FileToDownloadPtr(new FileToDownload (url, path, parent)); + float currentDLProgress = (float) current / (float) total; + setProgress((int)(currentDLProgress * 100)); // convert to percentage } -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 ) -- cgit From dd86061f0ff6d19482e9a43af99156a55e60cf00 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Tue, 9 Jul 2013 00:52:03 +0200 Subject: 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 ) ) { /* -- cgit From c96ac2460522b9567a10831bcd1d8a6bc9f36d9d Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Tue, 9 Jul 2013 22:46:33 +0200 Subject: 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); } -- cgit From 33b9b25da7d3d29f949c9418295de257d437c9f8 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 14 Jul 2013 18:33:31 +0200 Subject: 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() ); } } -- cgit From ce253ded0e0d2ae90a971c2e074d561f5e7baeb2 Mon Sep 17 00:00:00 2001 From: Stiepen Date: Sun, 14 Jul 2013 20:26:53 +0200 Subject: 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; +} -- cgit From b5450042b5f9ddaad7585f644591b7d009aeb5cb Mon Sep 17 00:00:00 2001 From: Stiepen Date: Sun, 14 Jul 2013 22:01:30 +0200 Subject: 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 -- cgit From e2ee6d6d254285284f07b07cb60409fbda0bf7ad Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Tue, 16 Jul 2013 00:30:32 +0200 Subject: Finalize the instance settings dialog, add setting reset mechanism --- gui/instancesettings.cpp | 209 +++++++++++++++++++++----------- gui/instancesettings.h | 19 +-- gui/instancesettings.ui | 35 +++++- gui/mainwindow.cpp | 22 ++-- 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, 271 insertions(+), 94 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() { + applySettings(); + accept(); +} - // 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()); +void InstanceSettings::on_buttonBox_rejected() +{ + reject(); } -void InstanceSettings::loadSettings(SettingsObject *s) + +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"); +