summaryrefslogtreecommitdiffstats
path: root/libmultimc/src
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-07-29 00:59:35 +0200
committerPetr Mrázek <peterix@gmail.com>2013-07-29 00:59:35 +0200
commit2e0cbf393a5320dbf5448ca44a9b5905314b0be8 (patch)
tree4baac9cf015ca7b15d83de33c705e0d8d4497d30 /libmultimc/src
parent8808a8b108b82916eaf30f9aca50cd3ab16af230 (diff)
downloadMultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar
MultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar.gz
MultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar.lz
MultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.tar.xz
MultiMC-2e0cbf393a5320dbf5448ca44a9b5905314b0be8.zip
Massive renaming in the backend folder, all around restructure in the same.
Diffstat (limited to 'libmultimc/src')
-rw-r--r--libmultimc/src/appsettings.cpp69
-rw-r--r--libmultimc/src/fullversion.cpp29
-rw-r--r--libmultimc/src/fullversionfactory.cpp206
-rw-r--r--libmultimc/src/gameupdatetask.cpp283
-rw-r--r--libmultimc/src/instance.cpp205
-rw-r--r--libmultimc/src/instancelist.cpp233
-rw-r--r--libmultimc/src/instanceloader.cpp61
-rw-r--r--libmultimc/src/instversion.cpp67
-rw-r--r--libmultimc/src/instversionlist.cpp129
-rw-r--r--libmultimc/src/library.cpp81
-rw-r--r--libmultimc/src/loginresponse.cpp69
-rw-r--r--libmultimc/src/logintask.cpp121
-rw-r--r--libmultimc/src/lwjglversionlist.cpp204
-rw-r--r--libmultimc/src/minecraftprocess.cpp269
-rw-r--r--libmultimc/src/minecraftversion.cpp105
-rw-r--r--libmultimc/src/minecraftversionlist.cpp528
-rw-r--r--libmultimc/src/task.cpp83
-rw-r--r--libmultimc/src/userinfo.cpp49
-rw-r--r--libmultimc/src/version.cpp46
19 files changed, 0 insertions, 2837 deletions
diff --git a/libmultimc/src/appsettings.cpp b/libmultimc/src/appsettings.cpp
deleted file mode 100644
index 7c886fdb..00000000
--- a/libmultimc/src/appsettings.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/* 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 "appsettings.h"
-
-#include <setting.h>
-
-#include <QPoint>
-#include <QApplication>
-//#include <QColor>
-
-AppSettings::AppSettings(QObject *parent) :
- INISettingsObject(QApplication::applicationDirPath() + "/multimc.cfg",parent)
-{
- // Updates
- registerSetting(new Setting("UseDevBuilds", false));
- registerSetting(new Setting("AutoUpdate", true));
-
- // Folders
- registerSetting(new Setting("InstanceDir", "instances"));
- registerSetting(new Setting("CentralModsDir", "mods"));
- registerSetting(new Setting("LWJGLDir", "lwjgl"));
-
- // Console
- registerSetting(new Setting("ShowConsole", true));
- registerSetting(new Setting("AutoCloseConsole", true));
-
- // Toolbar settings
- registerSetting(new Setting("InstanceToolbarVisible", true));
- registerSetting(new Setting("InstanceToolbarPosition", QPoint()));
-
- // Console Colors
-// registerSetting(new Setting("SysMessageColor", QColor(Qt::blue)));
-// registerSetting(new Setting("StdOutColor", QColor(Qt::black)));
-// registerSetting(new Setting("StdErrColor", QColor(Qt::red)));
-
- // Window Size
- registerSetting(new Setting("LaunchCompatMode", false));
- registerSetting(new Setting("LaunchMaximized", false));
- registerSetting(new Setting("MinecraftWinWidth", 854));
- registerSetting(new Setting("MinecraftWinHeight", 480));
-
- // Auto login
- registerSetting(new Setting("AutoLogin", false));
-
- // Memory
- registerSetting(new Setting("MinMemAlloc", 512));
- registerSetting(new Setting("MaxMemAlloc", 1024));
-
- // Java Settings
- registerSetting(new Setting("JavaPath", "java"));
- registerSetting(new Setting("JvmArgs", ""));
-
- // Custom Commands
- registerSetting(new Setting("PreLaunchCommand", ""));
- registerSetting(new Setting("PostExitCommand", ""));
-}
diff --git a/libmultimc/src/fullversion.cpp b/libmultimc/src/fullversion.cpp
deleted file mode 100644
index 24047c9f..00000000
--- a/libmultimc/src/fullversion.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-#include <QtCore>
-#include "fullversion.h"
-#include <library.h>
-
-QList<QSharedPointer<Library> > FullVersion::getActiveNormalLibs()
-{
- QList<QSharedPointer<Library> > output;
- for ( auto lib: libraries )
- {
- if (lib->getIsActive() && !lib->getIsNative())
- {
- output.append(lib);
- }
- }
- return output;
-}
-
-QList<QSharedPointer<Library> > FullVersion::getActiveNativeLibs()
-{
- QList<QSharedPointer<Library> > output;
- for ( auto lib: libraries )
- {
- if (lib->getIsActive() && lib->getIsNative())
- {
- output.append(lib);
- }
- }
- return output;
-}
diff --git a/libmultimc/src/fullversionfactory.cpp b/libmultimc/src/fullversionfactory.cpp
deleted file mode 100644
index bb55b4a9..00000000
--- a/libmultimc/src/fullversionfactory.cpp
+++ /dev/null
@@ -1,206 +0,0 @@
-#include "fullversionfactory.h"
-#include "fullversion.h"
-#include <library.h>
-
-class LibraryFinalizer
-{
-public:
- LibraryFinalizer(QSharedPointer<Library> library)
- {
- m_library = library;
- }
-
- QSharedPointer<Library> m_library;
-};
-
-// Library rules (if any)
-QList<QSharedPointer<Rule> > FullVersionFactory::parse4rules(QJsonObject & baseObj)
-{
- QList<QSharedPointer<Rule> > rules;
- auto rulesVal = baseObj.value("rules");
- if(rulesVal.isArray())
- {
- QJsonArray ruleList = rulesVal.toArray();
- for(auto ruleVal : ruleList)
- {
- QSharedPointer<Rule> 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<FullVersion> FullVersionFactory::parse4(QJsonObject root, QSharedPointer<FullVersion> fullVersion)
-{
- fullVersion->id = root.value("id").toString();
-
- // if it's on our legacy list, it's legacy
- if(legacyWhitelist.contains(fullVersion->id))
- fullVersion->isLegacy = true;
-
- fullVersion->mainClass = root.value("mainClass").toString();
- auto procArgsValue = root.value("processArguments");
- if(procArgsValue.isString())
- {
- fullVersion->processArguments = procArgsValue.toString();
- QString toCompare = fullVersion->processArguments.toLower();
- if(toCompare == "legacy")
- {
- fullVersion->minecraftArguments = " ${auth_player_name} ${auth_session}";
- fullVersion->isLegacy = true;
- }
- else if(toCompare == "username_session")
- {
- fullVersion->minecraftArguments = "--username ${auth_player_name} --session ${auth_session}";
- }
- else if(toCompare == "username_session_version")
- {
- fullVersion->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}";
- }
- }
-
- auto minecraftArgsValue = root.value("minecraftArguments");
- if(minecraftArgsValue.isString())
- {
- fullVersion->minecraftArguments = minecraftArgsValue.toString();
- }
-
- fullVersion->releaseTime = root.value("releaseTime").toString();
- fullVersion->time = root.value("time").toString();
-
- // Iterate through the list, if it's a list.
- auto librariesValue = root.value("libraries");
- if(!librariesValue.isArray())
- return fullVersion;
-
- QJsonArray libList = root.value("libraries").toArray();
- for (auto libVal : libList)
- {
- if (!libVal.isObject())
- {
- continue;
- }
-
- QJsonObject libObj = libVal.toObject();
-
- // Library name
- auto nameVal = libObj.value("name");
- if(!nameVal.isString())
- continue;
- QSharedPointer<Library> library(new Library(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)
- {
- if(excludeVal.isString())
- excludes.append(excludeVal.toString());
- }
- library->extract_excludes = excludes;
- }
- SKIP_EXTRACTS:
-
- auto nativesVal = libObj.value("natives");
- if(nativesVal.isObject())
- {
- library->setIsNative();
- 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->addNative(osType, iter.value().toString());
- iter++;
- }
- }
- library->setRules(parse4rules(libObj));
- library->finalize();
- fullVersion->libraries.append(library);
- }
- return fullVersion;
-}
-
-QSharedPointer<FullVersion> FullVersionFactory::parse(QByteArray data)
-{
- QSharedPointer<FullVersion> 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<FullVersion>();
- }
-
- if(!jsonDoc.isObject())
- {
- error_string = "Error reading version file.";
- m_error = FullVersionFactory::ParseError;
- return QSharedPointer<FullVersion>();
- }
- 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<FullVersion>();
- }
-}
-
-
-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
deleted file mode 100644
index bae85c17..00000000
--- a/libmultimc/src/gameupdatetask.cpp
+++ /dev/null
@@ -1,283 +0,0 @@
-/* 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 "gameupdatetask.h"
-
-#include <QtNetwork>
-
-#include <QFile>
-#include <QFileInfo>
-#include <QTextStream>
-#include <QDataStream>
-
-#include <QDebug>
-
-#include "minecraftversionlist.h"
-#include "fullversionfactory.h"
-#include <fullversion.h>
-
-#include "pathutils.h"
-
-
-GameUpdateTask::GameUpdateTask(const LoginResponse &response, Instance *inst, QObject *parent) :
- Task(parent), m_response(response)
-{
- m_inst = inst;
- m_updateState = StateInit;
-}
-
-void GameUpdateTask::executeTask()
-{
- updateStatus();
-
- // Get a pointer to the version object that corresponds to the instance's version.
- targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList().
- findVersion(m_inst->intendedVersion());
- 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;
- }
-
- /////////////////////////
- // 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<DownloadJob>();
- FullVersionFactory parser;
- auto version = parser.parse(DlJob->m_data);
-
- if(!version)
- {
- error(parser.error_string);
- exit(0);
- }
-
- if(version->isLegacy)
- {
- getLegacyJar();
- 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
- 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()
-{
- m_inst->setCurrentVersion(targetVersion->descriptor());
- m_inst->setShouldUpdate(false);
- m_inst->setIsForNewLauncher(true);
- exit(1);
-}
-
-void GameUpdateTask::jarlibFailed()
-{
- error("Failed to download the binary garbage. Try again. Maybe. IF YOU DARE");
- 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("."))
- {
- error("Failed to create bin folder.");
- return;
- }
-
- // 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)
- {
- jarFilename = targetVersion->descriptor();
- }
-
- 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)));
-
- download_queue.enqueue(legacyDownloadJob);
-}
-
-
-void GameUpdateTask::legacyJarFinished()
-{
- setState(StateFinished);
- emit gameUpdateComplete(m_response);
- m_inst->setIsForNewLauncher(true);
- exit(1);
-}
-
-void GameUpdateTask::legacyJarFailed()
-{
- emit gameUpdateError("failed to download the minecraft.jar");
- exit(0);
-}
-
-int GameUpdateTask::state() const
-{
- return m_updateState;
-}
-
-void GameUpdateTask::setState(int state, bool resetSubStatus)
-{
- m_updateState = state;
- if (resetSubStatus)
- setSubStatus("");
- else // We only need to update if we're not resetting substatus becasue setSubStatus updates status for us.
- updateStatus();
-}
-
-QString GameUpdateTask::subStatus() const
-{
- return m_subStatusMsg;
-}
-
-void GameUpdateTask::setSubStatus(const QString &msg)
-{
- m_subStatusMsg = msg;
- updateStatus();
-}
-
-QString GameUpdateTask::getStateMessage(int state)
-{
- switch (state)
- {
- case StateInit:
- return "Initializing";
-
- case StateDetermineURLs:
- return "Determining files to download";
-
- case StateDownloadFiles:
- return "Downloading files";
-
- case StateInstall:
- return "Installing";
-
- case StateFinished:
- return "Finished";
-
- default:
- return "Downloading instance files";
- }
-}
-
-void GameUpdateTask::updateStatus()
-{
- QString newStatus;
-
- newStatus = getStateMessage(state());
- if (!subStatus().isEmpty())
- newStatus += ": " + subStatus();
- else
- newStatus += "...";
-
- setStatus(newStatus);
-}
-
-
-void GameUpdateTask::error(const QString &msg)
-{
- emit gameUpdateError(msg);
-}
-
-void GameUpdateTask::updateDownloadProgress(qint64 current, qint64 total)
-{
- // The progress on the current file is current / total
- float currentDLProgress = (float) current / (float) total;
- setProgress((int)(currentDLProgress * 100)); // convert to percentage
-}
-
diff --git a/libmultimc/src/instance.cpp b/libmultimc/src/instance.cpp
deleted file mode 100644
index 5fdb5064..00000000
--- a/libmultimc/src/instance.cpp
+++ /dev/null
@@ -1,205 +0,0 @@
-/* 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/instance.h"
-
-#include <QFileInfo>
-
-#include "inisettingsobject.h"
-#include "setting.h"
-#include "overridesetting.h"
-
-#include "pathutils.h"
-#include <minecraftversionlist.h>
-
-Instance::Instance(const QString &rootDir, QObject *parent) :
- QObject(parent)
-{
- m_rootDir = rootDir;
- m_settings = new INISettingsObject(configFile(), this);
-
- settings().registerSetting(new Setting("name", "Unnamed Instance"));
- 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"));
- settings().registerSetting(new Setting("IntendedJarVersion", ""));
- settings().registerSetting(new Setting("lastLaunchTime", 0));
-
- // Java Settings
- settings().registerSetting(new OverrideSetting("JavaPath", globalSettings->getSetting("JavaPath")));
- settings().registerSetting(new OverrideSetting("JvmArgs", globalSettings->getSetting("JvmArgs")));
-
- // Custom Commands
- settings().registerSetting(new OverrideSetting("PreLaunchCommand",
- globalSettings->getSetting("PreLaunchCommand")));
- settings().registerSetting(new OverrideSetting("PostExitCommand",
- globalSettings->getSetting("PostExitCommand")));
-
- // Window Size
- settings().registerSetting(new OverrideSetting("LaunchCompatMode", globalSettings->getSetting("LaunchCompatMode")));
- settings().registerSetting(new OverrideSetting("LaunchMaximized", globalSettings->getSetting("LaunchMaximized")));
- settings().registerSetting(new OverrideSetting("MinecraftWinWidth", globalSettings->getSetting("MinecraftWinWidth")));
- settings().registerSetting(new OverrideSetting("MinecraftWinHeight", globalSettings->getSetting("MinecraftWinHeight")));
-
- // Memory
- settings().registerSetting(new OverrideSetting("MinMemAlloc", globalSettings->getSetting("MinMemAlloc")));
- settings().registerSetting(new OverrideSetting("MaxMemAlloc", globalSettings->getSetting("MaxMemAlloc")));
-
- // 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
-{
- return QFileInfo(rootDir()).fileName();
-}
-
-QString Instance::rootDir() const
-{
- return m_rootDir;
-}
-
-InstanceList *Instance::instList() const
-{
- if (parent()->inherits("InstanceList"))
- return (InstanceList *)parent();
- else
- return NULL;
-}
-
-QString Instance::minecraftDir() const
-{
- QFileInfo mcDir(PathCombine(rootDir(), "minecraft"));
- QFileInfo dotMCDir(PathCombine(rootDir(), ".minecraft"));
-
- if (dotMCDir.exists() && !mcDir.exists())
- return dotMCDir.filePath();
- else
- return mcDir.filePath();
-}
-
-QString Instance::instModsDir() const
-{
- return PathCombine(rootDir(), "instMods");
-}
-
-QString Instance::binDir() const
-{
- return PathCombine(minecraftDir(), "bin");
-}
-
-QString Instance::savesDir() const
-{
- return PathCombine(minecraftDir(), "saves");
-}
-
-QString Instance::mlModsDir() const
-{
- return PathCombine(minecraftDir(), "mods");
-}
-
-QString Instance::coreModsDir() const
-{
- return PathCombine(minecraftDir(), "coremods");
-}
-
-QString Instance::resourceDir() const
-{
- return PathCombine(minecraftDir(), "resources");
-}
-
-QString Instance::screenshotsDir() const
-{
- return PathCombine(minecraftDir(), "screenshots");
-}
-
-QString Instance::texturePacksDir() const
-{
- return PathCombine(minecraftDir(), "texturepacks");
-}
-
-QString Instance::mcJar() const
-{
- return PathCombine(binDir(), "minecraft.jar");
-}
-
-QString Instance::mcBackup() const
-{
- return PathCombine(binDir(), "mcbackup.jar");
-}
-
-QString Instance::configFile() const
-{
- return PathCombine(rootDir(), "instance.cfg");
-}
-
-QString Instance::modListFile() const
-{
- return PathCombine(rootDir(), "modlist");
-}
-
-InstVersionList *Instance::versionList() const
-{
- return &MinecraftVersionList::getMainList();
-}
-
-bool Instance::shouldUpdateCurrentVersion() const
-{
- QFileInfo jar(mcJar());
- return jar.lastModified().toUTC().toMSecsSinceEpoch() != lastCurrentVersionUpdate();
-}
-
-void Instance::updateCurrentVersion(bool keepCurrent)
-{
- QFileInfo jar(mcJar());
-
- if(!jar.exists())
- {
- setLastCurrentVersionUpdate(0);
- setCurrentVersion("Unknown");
- return;
- }
-
- qint64 time = jar.lastModified().toUTC().toMSecsSinceEpoch();
-
- setLastCurrentVersionUpdate(time);
- if (!keepCurrent)
- {
- // TODO: Implement GetMinecraftJarVersion function.
- QString newVersion = "Unknown";//javautils::GetMinecraftJarVersion(jar.absoluteFilePath());
- setCurrentVersion(newVersion);
- }
-}
-
-SettingsObject &Instance::settings() const
-{
- return *m_settings;
-}
diff --git a/libmultimc/src/instancelist.cpp b/libmultimc/src/instancelist.cpp
deleted file mode 100644
index 1a7dc10d..00000000
--- a/libmultimc/src/instancelist.cpp
+++ /dev/null
@@ -1,233 +0,0 @@
-/* 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/instancelist.h"
-
-#include <QDir>
-#include <QFile>
-#include <QDirIterator>
-#include <QThread>
-#include <QTextStream>
-#include <QJsonDocument>
-#include <QJsonObject>
-#include <QJsonArray>
-
-#include "include/instance.h"
-#include "include/instanceloader.h"
-
-#include "pathutils.h"
-
-const static int GROUP_FILE_FORMAT_VERSION = 1;
-
-InstanceList::InstanceList(const QString &instDir, QObject *parent) :
- QObject(parent), m_instDir("instances")
-{
-
-}
-
-void InstanceList::loadGroupList(QMap<QString, QString> & groupMap)
-{
- QString groupFileName = m_instDir + "/instgroups.json";
-
- // if there's no group file, fail
- if(!QFileInfo(groupFileName).exists())
- return;
-
- QFile groupFile(groupFileName);
-
- // if you can't open the file, fail
- if (!groupFile.open(QIODevice::ReadOnly))
- {
- // An error occurred. Ignore it.
- qDebug("Failed to read instance group file.");
- return;
- }
-
- QTextStream in(&groupFile);
- QString jsonStr = in.readAll();
- groupFile.close();
-
- QJsonParseError error;
- QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonStr.toUtf8(), &error);
-
- // if the json was bad, fail
- if (error.error != QJsonParseError::NoError)
- {
- qWarning(QString("Failed to parse instance group file: %1 at offset %2").
- arg(error.errorString(), QString::number(error.offset)).toUtf8());
- return;
- }
-
- // if the root of the json wasn't an object, fail
- if (!jsonDoc.isObject())
- {
- qWarning("Invalid group file. Root entry should be an object.");
- return;
- }
-
- QJsonObject rootObj = jsonDoc.object();
-
- // Make sure the format version matches, otherwise fail.
- if (rootObj.value("formatVersion").toVariant().toInt() != GROUP_FILE_FORMAT_VERSION)
- return;
-
- // Get the groups. if it's not an object, fail
- if (!rootObj.value("groups").isObject())
- {
- qWarning("Invalid group list JSON: 'groups' should be an object.");
- return;
- }
-
- // Iterate through all the groups.
- QJsonObject groupMapping = rootObj.value("groups").toObject();
- for (QJsonObject::iterator iter = groupMapping.begin(); iter != groupMapping.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();
- 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;
- }
- }
-}
-
-InstanceList::InstListError InstanceList::loadList()
-{
- // load the instance groups
- QMap<QString, QString> groupMap;
- loadGroupList(groupMap);
-
- m_instances.clear();
- QDir dir(m_instDir);
- QDirIterator iter(dir);
- while (iter.hasNext())
- {
- QString subDir = iter.next();
- if (!QFileInfo(PathCombine(subDir, "instance.cfg")).exists())
- continue;
-
- Instance *instPtr = NULL;
- auto &loader = InstanceLoader::get();
- auto error = loader.loadInstance(instPtr, subDir);
-
- switch(error)
- {
- case InstanceLoader::NoLoadError:
- break;
- case InstanceLoader::NotAnInstance:
- break;
- }
-
- if (error != InstanceLoader::NoLoadError &&
- error != InstanceLoader::NotAnInstance)
- {
- QString errorMsg = QString("Failed to load instance %1: ").
- arg(QFileInfo(subDir).baseName()).toUtf8();
-
- switch (error)
- {
- default:
- errorMsg += QString("Unknown instance loader error %1").
- arg(error);
- break;
- }
- qDebug(errorMsg.toUtf8());
- }
- else if (!instPtr)
- {
- qDebug(QString("Error loading instance %1. Instance loader returned null.").
- arg(QFileInfo(subDir).baseName()).toUtf8());
- }
- else
- {
- QSharedPointer<Instance> inst(instPtr);
- auto iter = groupMap.find(inst->id());
- if(iter != groupMap.end())
- {
- inst->setGroup((*iter));
- }
- qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8());
- inst->setParent(this);
- m_instances.append(inst);
- connect(instPtr, SIGNAL(propertiesChanged(Instance*)),this, SLOT(propertiesChanged(Instance*)));
- }
- }
- emit invalidated();
- return NoError;
-}
-
-/// Clear all instances. Triggers notifications.
-void InstanceList::clear()
-{
- m_instances.clear();
- emit invalidated();
-};
-
-/// Add an instance. Triggers notifications, returns the new index
-int InstanceList::add(InstancePtr t)
-{
- m_instances.append(t);
- emit instanceAdded(count() - 1);
- return count() - 1;
-}
-
-InstancePtr InstanceList::getInstanceById(QString instId)
-{
- QListIterator<InstancePtr> iter(m_instances);
- InstancePtr inst;
- while(iter.hasNext())
- {
- inst = iter.next();
- if (inst->id() == instId)
- break;
- }
- if (inst->id() != instId)
- return InstancePtr();
- else
- return iter.peekPrevious();
-}
-
-void InstanceList::propertiesChanged(Instance * inst)
-{
- for(int i = 0; i < m_instances.count(); i++)
- {
- if(inst == m_instances[i].data())
- {
- emit instanceChanged(i);
- break;
- }
- }
-}
diff --git a/libmultimc/src/instanceloader.cpp b/libmultimc/src/instanceloader.cpp
deleted file mode 100644
index e30435a9..00000000
--- a/libmultimc/src/instanceloader.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/* 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/instanceloader.h"
-
-#include <QDir>
-#include <QFileInfo>
-
-#include "include/instance.h"
-
-#include "inifile.h"
-
-#include "pathutils.h"
-
-InstanceLoader InstanceLoader::loader;
-
-InstanceLoader::InstanceLoader() :
- QObject(NULL)
-{
-
-}
-
-InstanceLoader::InstLoadError InstanceLoader::loadInstance(Instance *&inst, const QString &instDir)
-{
- Instance *loadedInst = new Instance(instDir, this);
-
- // TODO: Sanity checks to verify that the instance is valid.
-
- inst = loadedInst;
-
- return NoLoadError;
-}
-
-
-InstanceLoader::InstCreateError InstanceLoader::createInstance(Instance *&inst, const QString &instDir)
-{
- QDir rootDir(instDir);
-
- qDebug(instDir.toUtf8());
- if (!rootDir.exists() && !rootDir.mkpath("."))
- {
- return InstanceLoader::CantCreateDir;
- }
-
- inst = new Instance(instDir, this);
-
- //FIXME: really, how do you even know?
- return InstanceLoader::NoCreateError;
-}
diff --git a/libmultimc/src/instversion.cpp b/libmultimc/src/instversion.cpp
deleted file mode 100644
index 4e42c364..00000000
--- a/libmultimc/src/instversion.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/* 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/instversion.h"
-#include "include/instversionlist.h"
-
-InstVersion::InstVersion(const QString &descriptor,
- const QString &name,
- qint64 timestamp,
- InstVersionList *parent) :
- QObject(parent), m_descriptor(descriptor), m_name(name), m_timestamp(timestamp)
-{
-
-}
-
-InstVersion::InstVersion(const InstVersion &other, QObject *parent) :
- QObject(parent ? parent : other.parent()),
- m_descriptor(other.descriptor()), m_name(other.name()), m_timestamp(other.timestamp())
-{
-
-}
-
-InstVersionList *InstVersion::versionList() const
-{
- // Parent should *always* be either an InstVersionList or NULL.
- if (!parent() || !parent()->inherits("InstVersionList"))
- return NULL;
- else
- return (InstVersionList *)parent();
-}
-
-bool InstVersion::isLessThan(const InstVersion &other) const
-{
- return timestamp() < other.timestamp();
-}
-
-bool InstVersion::isGreaterThan(const InstVersion &other) const
-{
- return timestamp() > other.timestamp();
-}
-
-QString InstVersion::descriptor() const
-{
- return m_descriptor;
-}
-
-QString InstVersion::name() const
-{
- return m_name;
-}
-
-qint64 InstVersion::timestamp() const
-{
- return m_timestamp;
-}
diff --git a/libmultimc/src/instversionlist.cpp b/libmultimc/src/instversionlist.cpp
deleted file mode 100644
index 74a8c898..00000000
--- a/libmultimc/src/instversionlist.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/* 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 "instversionlist.h"
-#include "instversion.h"
-
-InstVersionList::InstVersionList(QObject *parent) :
- QAbstractListModel(parent)
-{
-}
-
-const InstVersion *InstVersionList::findVersion(const QString &descriptor)
-{
- for (int i = 0; i < count(); i++)
- {
- if (at(i)->descriptor() == descriptor)
- return at(i);
- }
- return NULL;
-}
-
-const InstVersion *InstVersionList::getLatestStable() const
-{
- if (count() <= 0)
- return NULL;
- else
- return at(0);
-}
-
-QVariant InstVersionList::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid())
- return QVariant();
-
- if (index.row() > count())
- return QVariant();
-
-
- const InstVersion *version = at(index.row());
-
- switch (role)
- {
- case Qt::DisplayRole:
- switch (index.column())
- {
- case NameColumn:
- return version->name();
-
- case TypeColumn:
- return version->typeName();
-
- case TimeColumn:
- return version->timestamp();
-
- default:
- return QVariant();
- }
-
- case Qt::ToolTipRole:
- return version->descriptor();
-
- case VersionPointerRole:
- return qVariantFromValue((void *) version);
-
- default:
- return QVariant();
- }
-}
-
-QVariant InstVersionList::headerData(int section, Qt::Orientation orientation, int role) const
-{
- switch (role)
- {
- case Qt::DisplayRole:
- switch (section)
- {
- case NameColumn:
- return "Name";
-
- case TypeColumn:
- return "Type";
-
- case TimeColumn:
- return "Time";
-
- default:
- return QVariant();
- }
-
- case Qt::ToolTipRole:
- switch (section)
- {
- case NameColumn:
- return "The name of the version.";
-
- case TypeColumn:
- return "The version's type.";
-
- default:
- return QVariant();
- }
-
- default:
- return QVariant();
- }
-}
-
-int InstVersionList::rowCount(const QModelIndex &parent) const
-{
- // Return count
- return count();
-}
-
-int InstVersionList::columnCount(const QModelIndex &parent) const
-{
- return 2;
-}
diff --git a/libmultimc/src/library.cpp b/libmultimc/src/library.cpp
deleted file mode 100644
index 691786e8..00000000
--- a/libmultimc/src/library.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/* 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"
-
-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;
-}
-
-void Library::finalize()
-{
- QStringList parts = m_name.split ( ':' );
- QString relative = parts[0];
- relative.replace ( '.','/' );
- relative += '/' + parts[1] + '/' + parts[2] + '/' + parts[1] + '-' + parts[2];
- if ( !m_is_native )
- relative += ".jar";
- else
- {
- if ( m_native_suffixes.contains ( currentSystem ) )
- {
- relative += "-" + m_native_suffixes[currentSystem] + ".jar";
- }
- else
- {
- // really, bad.
- relative += ".jar";
- }
- }
- m_storage_path = relative;
- m_download_path = m_base_url + relative;
-
- if ( m_rules.empty() )
- {
- m_is_active = true;
- }
- else
- {
- RuleAction result = Disallow;
- for ( auto rule: m_rules )
- {
- RuleAction temp = rule->apply ( this );
- if ( temp != Defer )
- result = temp;
- }
- m_is_active = ( result == Allow );
- }
- if ( m_is_native )
- {
- m_is_active = m_is_active && m_native_suffixes.contains ( currentSystem );
- }
-}
-// default url for lib:
diff --git a/libmultimc/src/loginresponse.cpp b/libmultimc/src/loginresponse.cpp
deleted file mode 100644
index 99a618ad..00000000
--- a/libmultimc/src/loginresponse.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/* 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 "loginresponse.h"
-
-LoginResponse::LoginResponse(const QString& username, const QString& sessionID,
- qint64 latestVersion, QObject *parent) :
- QObject(parent)
-{
- this->m_username = username;
- this->m_sessionID = sessionID;
- this->m_latestVersion = latestVersion;
-}
-
-LoginResponse::LoginResponse()
-{
- this->m_username = "";
- this->m_sessionID = "";
- this->m_latestVersion = 0;
-}
-
-LoginResponse::LoginResponse(const LoginResponse &other)
-{
- this->m_username = other.username();
- this->m_sessionID = other.sessionID();
- this->m_latestVersion = other.latestVersion();
-}
-
-QString LoginResponse::username() const
-{
- return m_username;
-}
-
-void LoginResponse::setUsername(const QString& username)
-{
- this->m_username = username;
-}
-
-QString LoginResponse::sessionID() const
-{
- return m_sessionID;
-}
-
-void LoginResponse::setSessionID(const QString& sessionID)
-{
- this->m_sessionID = sessionID;
-}
-
-qint64 LoginResponse::latestVersion() const
-{
- return m_latestVersion;
-}
-
-void LoginResponse::setLatestVersion(qint64 v)
-{
- this->m_latestVersion = v;
-}
diff --git a/libmultimc/src/logintask.cpp b/libmultimc/src/logintask.cpp
deleted file mode 100644
index 4a55037c..00000000
--- a/libmultimc/src/logintask.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/* 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 "logintask.h"
-
-#include <QStringList>
-
-#include <QtNetwork/QNetworkAccessManager>
-#include <QtNetwork/QNetworkReply>
-#include <QtNetwork/QNetworkRequest>
-
-#include <QUrl>
-#include <QUrlQuery>
-
-LoginTask::LoginTask( const UserInfo& uInfo, QObject* parent ) :
- Task(parent), uInfo(uInfo)
-{
-
-}
-
-void LoginTask::executeTask()
-{
- setStatus("Logging in...");
-
- QNetworkAccessManager netMgr;
- connect(&netMgr, SIGNAL(finished(QNetworkReply*)),
- SLOT(processNetReply(QNetworkReply*)));
-
- QUrl loginURL("https://login.minecraft.net/");
- QNetworkRequest netRequest(loginURL);
- netRequest.setHeader(QNetworkRequest::ContentTypeHeader,
- "application/x-www-form-urlencoded");
-
- QUrlQuery params;
- params.addQueryItem("user", uInfo.username());
- params.addQueryItem("password", uInfo.password());
- params.addQueryItem("version", "13");
-
- netReply = netMgr.post(netRequest, params.query(QUrl::EncodeSpaces).toUtf8());
- exec();
-}
-
-void LoginTask::processNetReply(QNetworkReply *reply)
-{
- // Check for errors.
- switch (reply->error())
- {
- case QNetworkReply::NoError:
- {
- // Check the response code.
- int responseCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
-
- if (responseCode == 200)
- {
- QString responseStr(reply->readAll());
-
- QStringList strings = responseStr.split(":");
- if (strings.count() >= 4)
- {
- bool parseSuccess;
- qint64 latestVersion = strings[0].toLongLong(&parseSuccess);
- if (parseSuccess)
- {
- // strings[1] is the download ticket. It isn't used anymore.
- QString username = strings[2];
- QString sessionID = strings[3];
-
- LoginResponse response(username, sessionID, latestVersion);
- emit loginComplete(response);
- }
- else
- {
- emit loginFailed("Failed to parse Minecraft version string.");
- }
- }
- else
- {
- if (responseStr.toLower() == "bad login")
- emit loginFailed("Invalid username or password.");
- else if (responseStr.toLower() == "old version")
- emit loginFailed("Launcher outdated, please update.");
- else
- emit loginFailed("Login failed: " + responseStr);
- }
- }
- else if (responseCode == 503)
- {
- emit loginFailed("The login servers are currently unavailable. "
- "Check http://help.mojang.com/ for more info.");
- }
- else
- {
- emit loginFailed(QString("Login failed: Unknown HTTP error %1 occurred.").
- arg(QString::number(responseCode)));
- }
- break;
- }
-
- case QNetworkReply::OperationCanceledError:
- emit loginFailed("Login canceled.");
- break;
-
- default:
- emit loginFailed("Login failed: " + reply->errorString());
- break;
- }
-
- quit();
-}
diff --git a/libmultimc/src/lwjglversionlist.cpp b/libmultimc/src/lwjglversionlist.cpp
deleted file mode 100644
index 6069f65c..00000000
--- a/libmultimc/src/lwjglversionlist.cpp
+++ /dev/null
@@ -1,204 +0,0 @@
-/* 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/lwjglversionlist.h"
-
-#include <QtNetwork>
-
-#include <QtXml>
-
-#include <QRegExp>
-
-#define RSS_URL "http://sourceforge.net/api/file/index/project-id/58488/mtime/desc/rss"
-
-LWJGLVersionList mainVersionList;
-
-LWJGLVersionList &LWJGLVersionList::get()
-{
- return mainVersionList;
-}
-
-
-LWJGLVersionList::LWJGLVersionList(QObject *parent) :
- QAbstractListModel(parent)
-{
- setLoading(false);
-}
-
-QVariant LWJGLVersionList::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid())
- return QVariant();
-
- if (index.row() > count())
- return QVariant();
-
- const PtrLWJGLVersion version = at(index.row());
-
- switch (role)
- {
- case Qt::DisplayRole:
- return version->name();
-
- case Qt::ToolTipRole:
- return version->url().toString();
-
- default:
- return QVariant();
- }
-}
-
-QVariant LWJGLVersionList::headerData(int section, Qt::Orientation orientation, int role) const
-{
- switch (role)
- {
- case Qt::DisplayRole:
- return "Version";
-
- case Qt::ToolTipRole:
- return "LWJGL version name.";
-
- default:
- return QVariant();
- }
-}
-
-int LWJGLVersionList::columnCount(const QModelIndex &parent) const
-{
- return 1;
-}
-
-bool LWJGLVersionList::isLoading() const
-{
- return m_loading;
-}
-
-void LWJGLVersionList::loadList()
-{
- Q_ASSERT_X(!m_loading, "loadList", "list is already loading (m_loading is true)");
-
- setLoading(true);
- reply = netMgr.get(QNetworkRequest(QUrl(RSS_URL)));
- connect(reply, SIGNAL(finished()), SLOT(netRequestComplete()));
-}
-
-inline QDomElement getDomElementByTagName(QDomElement parent, QString tagname)
-{
- QDomNodeList elementList = parent.elementsByTagName(tagname);
- if (elementList.count())
- return elementList.at(0).toElement();
- else
- return QDomElement();
-}
-
-void LWJGLVersionList::netRequestComplete()
-{
- if (reply->error() == QNetworkReply::NoError)
- {
- QRegExp lwjglRegex("lwjgl-(([0-9]\\.?)+)\\.zip");
- Q_ASSERT_X(lwjglRegex.isValid(), "load LWJGL list",
- "LWJGL regex is invalid");
-
- QDomDocument doc;
-
- QString xmlErrorMsg;
- int errorLine;
- if (!doc.setContent(reply->readAll(), false, &xmlErrorMsg, &errorLine))
- {
- failed("Failed to load LWJGL list. XML error: " + xmlErrorMsg +
- " at line " + QString::number(errorLine));
- setLoading(false);
- return;
- }
-
- QDomNodeList items = doc.elementsByTagName("item");
-
- QList<PtrLWJGLVersion> tempList;
-
- for (int i = 0; i < items.length(); i++)
- {
- Q_ASSERT_X(items.at(i).isElement(), "load LWJGL list",
- "XML element isn't an element... wat?");
-
- QDomElement linkElement = getDomElementByTagName(items.at(i).toElement(), "link");
- if (linkElement.isNull())
- {
- qWarning() << "Link element" << i << "in RSS feed doesn't exist! Skipping.";
- continue;
- }
-
- QString link = linkElement.text();
-
- // Make sure it's a download link.
- if (link.endsWith("/download") && link.contains(lwjglRegex))
- {
- QString name = link.mid(lwjglRegex.indexIn(link));
- // Subtract 4 here to remove the .zip file extension.
- name = name.left(lwjglRegex.matchedLength() - 4);
-
- QUrl url(link);
- if (!url.isValid())
- {
- qWarning() << "LWJGL version URL isn't valid:" << link << "Skipping.";
- continue;
- }
-
- tempList.append(LWJGLVersion::Create(name, link));
- }
- }
-
- beginResetModel();
- m_vlist.swap(tempList);
- endResetModel();
-
- qDebug("Loaded LWJGL list.");
- finished();
- }
- else
- {
- failed("Failed to load LWJGL list. Network error: " + reply->errorString());
- }
-
- setLoading(false);
- reply->deleteLater();
-}
-
-const PtrLWJGLVersion LWJGLVersionList::getVersion(const QString &versionName)
-{
- for (int i = 0; i < count(); i++)
- {
- if (at(i)->name() == versionName)
- return at(i);
- }
- return PtrLWJGLVersion();
-}
-
-
-void LWJGLVersionList::failed(QString msg)
-{
- qWarning() << msg;
- emit loadListFailed(msg);
-}
-
-void LWJGLVersionList::finished()
-{
- emit loadListFinished();
-}
-
-void LWJGLVersionList::setLoading(bool loading)
-{
- m_loading = loading;
- emit loadingStateUpdated(m_loading);
-}
diff --git a/libmultimc/src/minecraftprocess.cpp b/libmultimc/src/minecraftprocess.cpp
deleted file mode 100644
index e8b9959e..00000000
--- a/libmultimc/src/minecraftprocess.cpp
+++ /dev/null
@@ -1,269 +0,0 @@
-/* Copyright 2013 MultiMC Contributors
- *
- * Authors: Orochimarufan <orochimarufan.x3@gmail.com>
- *
- * 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 "minecraftprocess.h"
-
-#include <QDataStream>
-#include <QFile>
-#include <QDir>
-//#include <QImage>
-#include <QProcessEnvironment>
-
-#include "instance.h"
-
-#include "osutils.h"
-#include "pathutils.h"
-
-#define LAUNCHER_FILE "MultiMCLauncher.jar"
-#define IBUS "@im=ibus"
-
-// commandline splitter
-QStringList MinecraftProcess::splitArgs(QString args)
-{
- QStringList argv;
- QString current;
- bool escape = false;
- QChar inquotes;
- for (int i=0; i<args.length(); i++)
- {
- QChar cchar = args.at(i);
-
- // \ escaped
- if (escape) {
- current += cchar;
- escape = false;
- // in "quotes"
- } else if (!inquotes.isNull()) {
- if (cchar == 0x5C)
- escape = true;
- else if (cchar == inquotes)
- inquotes = 0;
- else
- current += cchar;
- // otherwise
- } else {
- if (cchar == 0x20) {
- if (!current.isEmpty()) {
- argv << current;
- current.clear();
- }
- } else if (cchar == 0x22 || cchar == 0x27)
- inquotes = cchar;
- else
- current += cchar;
- }
- }
- if (!current.isEmpty())
- argv << current;
- return argv;
-}
-
-// prepare tools
-inline void MinecraftProcess::extractIcon(Instance *inst, QString destination)
-{
-// QImage(":/icons/instances/" + inst->iconKey()).save(destination);
-}
-
-inline void MinecraftProcess::extractLauncher(QString destination)
-{
- QFile(":/launcher/launcher.jar").copy(destination);
-}
-
-void MinecraftProcess::prepare(Instance *inst)
-{
- extractLauncher(PathCombine(inst->minecraftDir(), LAUNCHER_FILE));
- extractIcon(inst, PathCombine(inst->minecraftDir(), "icon.png"));
-}
-
-// constructor
-MinecraftProcess::MinecraftProcess(Instance *inst, QString user, QString session) :
- m_instance(inst), m_user(user), m_session(session)
-{
- connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(finish(int, QProcess::ExitStatus)));
-
- // prepare the process environment
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
-
-#ifdef LINUX
- // Strip IBus
- if (env.value("XMODIFIERS").contains(IBUS))
- env.insert("XMODIFIERS", env.value("XMODIFIERS").replace(IBUS, ""));
-#endif
-
- // export some infos
- env.insert("INST_NAME", inst->name());
- env.insert("INST_ID", inst->id());
- env.insert("INST_DIR", QDir(inst->rootDir()).absolutePath());
-
- this->setProcessEnvironment(env);
- m_prepostlaunchprocess.setProcessEnvironment(env);
-
- // set the cwd
- QDir mcDir(inst->minecraftDir());
- this->setWorkingDirectory(mcDir.absolutePath());
- m_prepostlaunchprocess.setWorkingDirectory(mcDir.absolutePath());
-
- // std channels
- connect(this, SIGNAL(readyReadStandardError()), SLOT(on_stdErr()));
- connect(this, SIGNAL(readyReadStandardOutput()), SLOT(on_stdOut()));
-}
-
-// console window
-void MinecraftProcess::on_stdErr()
-{
- QByteArray data = readAllStandardError();
- QString str = m_err_leftover + QString::fromLocal8Bit(data);
- m_err_leftover.clear();
- QStringList lines = str.split("\n");
- bool complete = str.endsWith("\n");
-
- for(int i = 0; i < lines.size() - 1; i++)
- {
- QString & line = lines[i];
- MessageLevel::Enum level = MessageLevel::Error;
- if(line.contains("[INFO]") || line.contains("[CONFIG]") || line.contains("[FINE]") || line.contains("[FINER]") || line.contains("[FINEST]") )
- level = MessageLevel::Message;
- if(line.contains("[SEVERE]") || line.contains("[WARNING]") || line.contains("[STDERR]"))
- level = MessageLevel::Error;
- emit log(lines[i].toLocal8Bit(), level);
- }
- if(!complete)
- m_err_leftover = lines.last();
-}
-
-void MinecraftProcess::on_stdOut()
-{
- QByteArray data = readAllStandardOutput();
- QString str = m_out_leftover + QString::fromLocal8Bit(data);
- m_out_leftover.clear();
- QStringList lines = str.split("\n");
- bool complete = str.endsWith("\n");
-
- for(int i = 0; i < lines.size() - 1; i++)
- {
- QString & line = lines[i];
- emit log(lines[i].toLocal8Bit(), MessageLevel::Message);
- }
- if(!complete)
- m_out_leftover = lines.last();
-}
-
-// exit handler
-void MinecraftProcess::finish(int code, ExitStatus status)
-{
- if (status != NormalExit)
- {
- //TODO: error handling
- }
-
- emit log("Minecraft exited.");
-
- m_prepostlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(code));
-
- // run post-exit
- if (!m_instance->settings().get("PostExitCommand").toString().isEmpty())
- {
- m_prepostlaunchprocess.start(m_instance->settings().get("PostExitCommand").toString());
- m_prepostlaunchprocess.waitForFinished();
- if (m_prepostlaunchprocess.exitStatus() != NormalExit)
- {
- //TODO: error handling
- }
- }
-
-// if (m_console != nullptr)
-// m_console->setMayClose(true);
-
- emit ended();
-}
-
-void MinecraftProcess::launch()
-{
- if (!m_instance->settings().get("PreLaunchCommand").toString().isEmpty())
- {
- m_prepostlaunchprocess.start(m_instance->settings().get("PreLaunchCommand").toString());
- m_prepostlaunchprocess.waitForFinished();
- if (m_prepostlaunchprocess.exitStatus() != NormalExit)
- {
- //TODO: error handling
- return;
- }
- }
-
- m_instance->setLastLaunch();
-
- prepare(m_instance);
-
- genArgs();
-
- emit log(QString("Minecraft folder is: '%1'").arg(workingDirectory()));
- QString JavaPath = m_instance->settings().get("JavaPath").toString();
- emit log(QString("Java path: '%1'").arg(JavaPath));
- emit log(QString("Arguments: '%1'").arg(m_arguments.join("' '")));
- start(JavaPath, m_arguments);
- if (!waitForStarted())
- {
- emit log("Could not launch minecraft!");
- return;
- //TODO: error handling
- }
-
-// if(m_console != nullptr)
-// m_console->setMayClose(false);
-}
-
-void MinecraftProcess::genArgs()
-{
- // start fresh
- m_arguments.clear();
-
- // window size
- QString windowSize;
- if (m_instance->settings().get("LaunchMaximized").toBool())
- windowSize = "max";
- else
- windowSize = QString("%1x%2").
- arg(m_instance->settings().get("MinecraftWinWidth").toInt()).
- arg(m_instance->settings().get("MinecraftWinHeight").toInt());
-
- // window title
- QString windowTitle;
- windowTitle.append("MultiMC: ").append(m_instance->name());
-
- // Java arguments
- m_arguments.append(splitArgs(m_instance->settings().get("JvmArgs").toString()));
-
-#ifdef OSX
- // OSX dock icon and name
- m_arguments << "-Xdock:icon=icon.png";
- m_arguments << QString("-Xdock:name=\"%1\"").arg(windowTitle);
-#endif
-
- // lwjgl
- QString lwjgl = QDir(globalSettings->get("LWJGLDir").toString() + "/" +
- m_instance->lwjglVersion()).absolutePath();
-
- // launcher arguments
- m_arguments << QString("-Xms%1m").arg(m_instance->settings().get("MinMemAlloc").toInt());
- m_arguments << QString("-Xmx%1m").arg(m_instance->settings().get("MaxMemAlloc").toInt());
- m_arguments << "-jar" << LAUNCHER_FILE;
- m_arguments << m_user;
- m_arguments << m_session;
- m_arguments << windowTitle;
- m_arguments << windowSize;
- m_arguments << lwjgl;
-}
diff --git a/libmultimc/src/minecraftversion.cpp b/libmultimc/src/minecraftversion.cpp
deleted file mode 100644
index 36ba87f8..00000000
--- a/libmultimc/src/minecraftversion.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/* Copyright 2013 Andrew Okin
- *
- * 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 "minecraftversion.h"
-
-MinecraftVersion::MinecraftVersion(QString descriptor,
- QString name,
- qint64 timestamp,
- QString dlUrl,
- QString etag,
- InstVersionList *parent) :
- InstVersion(descriptor, name, timestamp, parent), m_dlUrl(dlUrl), m_etag(etag)
-{
- m_isNewLauncherVersion = false;
-}
-
-QString MinecraftVersion::descriptor() const
-{
- return m_descriptor;
-}
-
-QString MinecraftVersion::name() const
-{
- return m_name;
-}
-
-QString MinecraftVersion::typeName() const
-{
- switch (versionType())
- {
- case OldSnapshot:
- return "Snapshot";
-
- case Stable:
- return "Stable";
-
- case CurrentStable:
- return "Current Stable";
-
- case Snapshot:
- return "Snapshot";
-
- case MCNostalgia:
- return "MCNostalgia";
-
- default:
- return QString("Unknown Type %1").arg(versionType());
- }
-}
-
-qint64 MinecraftVersion::timestamp() const
-{
- return m_timestamp;
-}
-
-MinecraftVersion::VersionType MinecraftVersion::versionType() const
-{
- return m_type;
-}
-
-void MinecraftVersion::setVersionType(MinecraftVersion::VersionType typeName)
-{
- m_type = typeName;
-}
-
-QString MinecraftVersion::downloadURL() const
-{
- return m_dlUrl;
-}
-
-QString MinecraftVersion::etag() const
-{
- return m_etag;
-}
-
-MinecraftVersion::LauncherVersion MinecraftVersion::launcherVersion() const
-{
- return m_launcherVersion;
-};
-
-void MinecraftVersion::setLauncherVersion(LauncherVersion launcherVersion)
-{
- m_launcherVersion = launcherVersion;
-}
-
-InstVersion *MinecraftVersion::copyVersion(InstVersionList *newParent) const
-{
- MinecraftVersion *version = new MinecraftVersion(
- descriptor(), name(), timestamp(), downloadURL(), etag(), newParent);
- version->setVersionType(versionType());
- version->setLauncherVersion(launcherVersion());
- return version;
-}
diff --git a/libmultimc/src/minecraftversionlist.cpp b/libmultimc/src/minecraftversionlist.cpp
deleted file mode 100644
index 17737b1e..00000000
--- a/libmultimc/src/minecraftversionlist.cpp
+++ /dev/null
@@ -1,528 +0,0 @@
-/* Copyright 2013 Andrew Okin
- *
- * 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/minecraftversionlist.h"
-
-#include <QDebug>
-
-#include <QtXml>
-
-#include <QJsonDocument>
-#include <QJsonObject>
-#include <QJsonArray>
-#include <QJsonValue>
-#include <QJsonParseError>
-
-#include <QtAlgorithms>
-
-#include <QtNetwork>
-
-#include "netutils.h"
-
-#define MCVLIST_URLBASE "http://s3.amazonaws.com/Minecraft.Download/versions/"
-#define ASSETS_URLBASE "http://assets.minecraft.net/"
-#define MCN_URLBASE "http://sonicrules.org/mcnweb.py"
-
-MinecraftVersionList mcVList;
-
-MinecraftVersionList::MinecraftVersionList(QObject *parent) :
- InstVersionList(parent)
-{
-
-}
-
-Task *MinecraftVersionList::getLoadTask()
-{
- return new MCVListLoadTask(this);
-}
-
-bool MinecraftVersionList::isLoaded()
-{
- return m_loaded;
-}
-
-const InstVersion *MinecraftVersionList::at(int i) const
-{
- return m_vlist.at(i);
-}
-
-int MinecraftVersionList::count() const
-{
- return m_vlist.count();
-}
-
-void MinecraftVersionList::printToStdOut() const
-{
- qDebug() << "---------------- Version List ----------------";
-
- for (int i = 0; i < m_vlist.count(); i++)
- {
- MinecraftVersion *version = qobject_cast<MinecraftVersion *>(m_vlist.at(i));
-
- if (!version)
- continue;
-
- qDebug() << "Version " << version->name();
- qDebug() << "\tDownload: " << version->downloadURL();
- qDebug() << "\tTimestamp: " << version->timestamp();
- qDebug() << "\tType: " << version->typeName();
- qDebug() << "----------------------------------------------";
- }
-}
-
-bool cmpVersions(const InstVersion *first, const InstVersion *second)
-{
- return !first->isLessThan(*second);
-}
-
-void MinecraftVersionList::sort()
-{
- beginResetModel();
- qSort(m_vlist.begin(), m_vlist.end(), cmpVersions);
- endResetModel();
-}
-
-InstVersion *MinecraftVersionList::getLatestStable() const
-{
- for (int i = 0; i < m_vlist.length(); i++)
- {
- if (((MinecraftVersion *)m_vlist.at(i))->versionType() == MinecraftVersion::CurrentStable)
- {
- return m_vlist.at(i);
- }
- }
- return NULL;
-}
-
-MinecraftVersionList &MinecraftVersionList::getMainList()
-{
- return mcVList;
-}
-
-void MinecraftVersionList::updateListData(QList<InstVersion *> versions)
-{
- // First, we populate a temporary list with the copies of the versions.
- QList<InstVersion *> tempList;
- for (int i = 0; i < versions.length(); i++)
- {
- InstVersion *version = versions[i]->copyVersion(this);
- Q_ASSERT(version != NULL);
- tempList.append(version);
- }
-
- // Now we swap the temporary list into the actual version list.
- // This applies our changes to the version list immediately and still gives us
- // access to the old version list so that we can delete the objects in it and
- // free their memory. By doing this, we cause the version list to update as
- // quickly as possible.
- beginResetModel();
- m_vlist.swap(tempList);
- m_loaded = true;
- endResetModel();
-
- // We called swap, so all the data that was in the version list previously is now in
- // tempList (and vice-versa). Now we just free the memory.
- while (!tempList.isEmpty())
- delete tempList.takeFirst();
-
- // NOW SORT!!
- sort();
-}
-
-inline QDomElement getDomElementByTagName(QDomElement parent, QString tagname)
-{
- QDomNodeList elementList = parent.elementsByTagName(tagname);
- if (elementList.count())
- return elementList.at(0).toElement();
- else
- return QDomElement();
-}
-
-inline QDateTime timeFromS3Time(QString str)
-{
- return QDateTime::fromString(str, Qt::ISODate);
-}
-
-
-MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
-{
- m_list = vlist;
- m_currentStable = NULL;
- processedAssetsReply = false;
- processedMCNReply = false;
- processedMCVListReply = false;
-}
-
-MCVListLoadTask::~MCVListLoadTask()
-{
-// delete netMgr;
-}
-
-void MCVListLoadTask::executeTask()
-{
- setSubStatus();
-
- QNetworkAccessManager networkMgr;
- netMgr = &networkMgr;
-
- if (!loadFromVList())
- {
- qDebug() << "Failed to load from Mojang version list.";
- }
- if (!loadFromAssets())
- {
- qDebug() << "Failed to load assets version list.";
- }
- if (!loadMCNostalgia())
- {
- qDebug() << "Failed to load MCNostalgia version list.";
- }
- finalize();
-}
-
-void MCVListLoadTask::setSubStatus(const QString msg)
-{
- if (msg.isEmpty())
- setStatus("Loading instance version list...");
- else
- setStatus("Loading instance version list: " + msg);
-}
-
-// FIXME: we should have a local cache of the version list and a local cache of version data
-bool MCVListLoadTask::loadFromVList()
-{
- QNetworkReply *vlistReply = netMgr->get(QNetworkRequest(QUrl(QString(MCVLIST_URLBASE) +
- "versions.json")));
- NetUtils::waitForNetRequest(vlistReply);
-
- switch (vlistReply->error())
- {
- case QNetworkReply::NoError:
- {
- QJsonParseError jsonError;
- QJsonDocument jsonDoc = QJsonDocument::fromJson(vlistReply->readAll(), &jsonError);
-
- if (jsonError.error == QJsonParseError::NoError)
- {
- Q_ASSERT_X(jsonDoc.isObject(), "loadFromVList", "jsonDoc is not an object");
-
- QJsonObject root = jsonDoc.object();
-
- // Get the ID of the latest release and the latest snapshot.
- Q_ASSERT_X(root.value("latest").isObject(), "loadFromVList",
- "version list is missing 'latest' object");
- QJsonObject latest = root.value("latest").toObject();
-
- QString latestReleaseID = latest.value("release").toString("");
- QString latestSnapshotID = latest.value("snapshot").toString("");
- Q_ASSERT_X(!latestReleaseID.isEmpty(), "loadFromVList", "latest release field is missing");
- Q_ASSERT_X(!latestSnapshotID.isEmpty(), "loadFromVList", "latest snapshot field is missing");
-
- // Now, get the array of versions.
- Q_ASSERT_X(root.value("versions").isArray(), "loadFromVList",
- "version list object is missing 'versions' array");
- QJsonArray versions = root.value("versions").toArray();
-
- for (int i = 0; i < versions.count(); i++)
- {
- // Load the version info.
- Q_ASSERT_X(versions[i].isObject(), "loadFromVList",
- QString("in versions array, index %1 is not an object").
- arg(i).toUtf8());
- QJsonObject version = versions[i].toObject();
-
- QString versionID = version.value("id").toString("");
- QString versionTimeStr = version.value("releaseTime").toString("");
- QString versionTypeStr = version.value("type").toString("");
-
- Q_ASSERT_X(!versionID.isEmpty(), "loadFromVList",
- QString("in versions array, index %1's \"id\" field is not a valid string").
- arg(i).toUtf8());
- Q_ASSERT_X(!versionTimeStr.isEmpty(), "loadFromVList",
- QString("in versions array, index %1's \"time\" field is not a valid string").
- arg(i).toUtf8());
- Q_ASSERT_X(!versionTypeStr.isEmpty(), "loadFromVList",
- QString("in versions array, index %1's \"type\" field is not a valid string").
- arg(i).toUtf8());
-
-
- // Now, process that info and add the version to the list.
-
- // Parse the timestamp.
- QDateTime versionTime = timeFromS3Time(versionTimeStr);
-
- Q_ASSERT_X(versionTime.isValid(), "loadFromVList",
- QString("in versions array, index %1's timestamp failed to parse").
- arg(i).toUtf8());
-
- // Parse the type.
- MinecraftVersion::VersionType versionType;
- if (versionTypeStr == "release")
- {
- // Check if this version is the current stable version.
- if (versionID == latestReleaseID)
- versionType = MinecraftVersion::CurrentStable;
- else
- versionType = MinecraftVersion::Stable;
- }
- else if(versionTypeStr == "snapshot")
- {
- versionType = MinecraftVersion::Snapshot;
- }
- else
- {
- // we don't know what to do with this...
- continue;
- }
-
- // Get the download URL.
- QString dlUrl = QString(MCVLIST_URLBASE) + versionID + "/";
-
-
- // Now, we construct the version object and add it to the list.
- MinecraftVersion *mcVersion = new MinecraftVersion(
- versionID, versionID, versionTime.toMSecsSinceEpoch(),
- dlUrl, "");
- mcVersion->setLauncherVersion(MinecraftVersion::Launcher16);
- mcVersion->setVersionType(versionType);
- tempList.append(mcVersion);
- }
- }
- else
- {
- qDebug() << "Error parsing version list JSON:" << jsonError.errorString();
- }
-
- break;
- }
-
- default:
- // TODO: Network error handling.
- qDebug() << "Failed to load Minecraft main version list" << vlistReply->errorString();
- break;
- }
-
- return true;
-}
-
-bool MCVListLoadTask::loadFromAssets()
-{
- setSubStatus("Loading versions from assets.minecraft.net...");
-
- bool succeeded = false;
-
- QNetworkReply *assetsReply = netMgr->get(QNetworkRequest(QUrl(ASSETS_URLBASE)));
- NetUtils::waitForNetRequest(assetsReply);
-
- switch (assetsReply->error())
- {
- case QNetworkReply::NoError:
- {
- // Get the XML string.
- QString xmlString = assetsReply->readAll();
-
- QString xmlErrorMsg;
-
- QDomDocument doc;
- if (!doc.setContent(xmlString, false, &xmlErrorMsg))
- {
- // TODO: Display error message to the user.
- qDebug() << "Failed to process assets.minecraft.net. XML error:" <<
- xmlErrorMsg << xmlString;
- }
-
- QDomNodeList contents = doc.elementsByTagName("Contents");
-
- QRegExp mcRegex("/minecraft.jar$");
- QRegExp snapshotRegex("[0-9][0-9]w[0-9][0-9][a-z]?|pre|rc");
-
- for (int i = 0; i < contents.length(); i++)
- {
- QDomElement element = contents.at(i).toElement();
-
- if (element.isNull())
- continue;
-
- QDomElement keyElement = getDomElementByTagName(element, "Key");
- QDomElement lastmodElement = getDomElementByTagName(element, "LastModified");
- QDomElement etagElement = getDomElementByTagName(element, "ETag");
-
- if (keyElement.isNull() || lastmodElement.isNull() || etagElement.isNull())
- continue;
-
- QString key = keyElement.text();
- QString lastModStr = lastmodElement.text();
- QString etagStr = etagElement.text();
-
- if (!key.contains(mcRegex))
- continue;
-
- QString versionDirName = key.left(key.length() - 14);
- QString dlUrl = QString("http://assets.minecraft.net/%1/").arg(versionDirName);
-
- QString versionName = versionDirName.replace("_", ".");
-
- QDateTime versionTimestamp = timeFromS3Time(lastModStr);
- if (!versionTimestamp.isValid())
- {
- qDebug(QString("Failed to parse timestamp for version %1 %2").
- arg(versionName, lastModStr).toUtf8());
- versionTimestamp = QDateTime::currentDateTime();
- }
-
- if (m_currentStable)
- {
- {
- bool older = versionTimestamp.toMSecsSinceEpoch() < m_currentStable->timestamp();
- bool newer = versionTimestamp.toMSecsSinceEpoch() > m_currentStable->timestamp();
- bool isSnapshot = versionName.contains(snapshotRegex);
-
- MinecraftVersion *version = new MinecraftVersion(
- versionName, versionName,
- versionTimestamp.toMSecsSinceEpoch(),
- dlUrl, etagStr);
-
- if (newer)
- {
- version->setVersionType(MinecraftVersion::Snapshot);
- }
- else if (older && isSnapshot)
- {
- version->setVersionType(MinecraftVersion::OldSnapshot);
- }
- else if (older)
- {
- version->setVersionType(MinecraftVersion::Stable);
- }
- else
- {
- // Shouldn't happen, but just in case...
- version->setVersionType(MinecraftVersion::CurrentStable);
- }
-
- assetsList.push_back(version);
- }
- }
- else // If there isn't a current stable version.
- {
- bool isSnapshot = versionName.contains(snapshotRegex);
-
- MinecraftVersion *version = new MinecraftVersion(
- versionName, versionName,
- versionTimestamp.toMSecsSinceEpoch(),
- dlUrl, etagStr);
- version->setVersionType(isSnapshot? MinecraftVersion::Snapshot :
- MinecraftVersion::Stable);
- assetsList.push_back(version);
- }
- }
-
- setSubStatus("Loaded assets.minecraft.net");
- succeeded = true;
- break;
- }
-
- default:
- // TODO: Network error handling.
- qDebug() << "Failed to load assets.minecraft.net" << assetsReply->errorString();
- break;
- }
-
- processedAssetsReply = true;
- updateStuff();
- return succeeded;
-}
-
-bool MCVListLoadTask::loadMCNostalgia()
-{
- QNetworkReply *mcnReply = netMgr->get(QNetworkRequest(QUrl(QString(MCN_URLBASE) + "?pversion=1&list=True")));
- NetUtils::waitForNetRequest(mcnReply);
- processedMCNReply = true;
- updateStuff();
- return true;
-}
-
-bool MCVListLoadTask::finalize()
-{
- // First, we need to do some cleanup. We loaded assets versions into assetsList,
- // MCNostalgia versions into mcnList and all the others into tempList. MCNostalgia
- // provides some versions that are on assets.minecraft.net and we want to ignore
- // those, so we remove and delete them from mcnList. assets.minecraft.net also provides
- // versions that are on Mojang's version list and we want to ignore those as well.
-
- // To start, we get a list of the descriptors in tmpList.
- QStringList tlistDescriptors;
- for (int i = 0; i < tempList.count(); i++)
- tlistDescriptors.append(tempList.at(i)->descriptor());
-
- // Now, we go through our assets version list and remove anything with
- // a descriptor that matches one we already have in tempList.
- for (int i = 0; i < assetsList.count(); i++)
- if (tlistDescriptors.contains(assetsList.at(i)->descriptor()))
- delete assetsList.takeAt(i--); // We need to decrement here because we're removing an item.
-
- // We also need to rebuild the list of descriptors.
- tlistDescriptors.clear();
- for (int i = 0; i < tempList.count(); i++)
- tlistDescriptors.append(tempList.at(i)->descriptor());
-
- // Next, we go through our MCNostalgia version list and do the same thing.
- for (int i = 0; i < mcnList.count(); i++)
- if (tlistDescriptors.contains(mcnList.at(i)->descriptor()))
- delete mcnList.takeAt(i--); // We need to decrement here because we're removing an item.
-
- // Now that the duplicates are gone, we need to merge the lists. This is
- // simple enough.
- tempList.append(assetsList);
- tempList.append(mcnList);
-
- // We're done with these lists now, but the items have been moved over to
- // tempList, so we don't need to delete them yet.
-
- // Now, we invoke the updateListData slot on the GUI thread. This will copy all
- // the versions we loaded and set their parents to the version list.
- // Then, it will swap the new list with the old one and free the old list's memory.
- QMetaObject::invokeMethod(m_list, "updateListData", Qt::BlockingQueuedConnection,
- Q_ARG(QList<InstVersion*>, tempList));
-
- // Once that's finished, we can delete the versions in our temp list.
- while (!tempList.isEmpty())
- delete tempList.takeFirst();
-
-#ifdef PRINT_VERSIONS
- m_list->printToStdOut();
-#endif
- return true;
-}
-
-void MCVListLoadTask::updateStuff()
-{
- const int totalReqs = 3;
- int reqsComplete = 0;
-
- if (processedMCVListReply)
- reqsComplete++;
- if (processedAssetsReply)
- reqsComplete++;
- if (processedMCNReply)
- reqsComplete++;
-
- calcProgress(reqsComplete, totalReqs);
-
- if (reqsComplete >= totalReqs)
- {
- quit();
- }
-}
diff --git a/libmultimc/src/task.cpp b/libmultimc/src/task.cpp
deleted file mode 100644
index 780c3b38..00000000
--- a/libmultimc/src/task.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/* 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 "task.h"
-
-Task::Task(QObject *parent) :
- QThread(parent)
-{
-
-}
-
-QString Task::getStatus() const
-{
- return status;
-}
-
-void Task::setStatus(const QString &status)
-{
- this->status = status;
- emitStatusChange(status);
-}
-
-int Task::getProgress() const
-{
- return progress;
-}
-
-void Task::calcProgress(int parts, int whole)
-{
- setProgress((int)((((float)parts) / ((float)whole))*100)); // Not sure if C++ or LISP...
-}
-
-void Task::setProgress(int progress)
-{
- this->progress = progress;
- emitProgressChange(progress);
-}
-
-void Task::startTask()
-{
- start();
-}
-
-void Task::run()
-{
- emitStarted();
- executeTask();
- emitEnded();
-}
-
-void Task::emitStarted()
-{
- emit started();
- emit started(this);
-}
-
-void Task::emitEnded()
-{
- emit ended();
- emit ended(this);
-}
-
-void Task::emitStatusChange(const QString &status)
-{
- emit statusChanged(status);
-}
-
-void Task::emitProgressChange(int progress)
-{
- emit progressChanged(progress);
-}
diff --git a/libmultimc/src/userinfo.cpp b/libmultimc/src/userinfo.cpp
deleted file mode 100644
index 0bb5da11..00000000
--- a/libmultimc/src/userinfo.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-/* 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 "userinfo.h"
-
-UserInfo::UserInfo(const QString &username, const QString &password, QObject *parent) :
- QObject(parent)
-{
- this->m_username = username;
- this->m_password = password;
-}
-
-UserInfo::UserInfo(const UserInfo &other)
-{
- this->m_username = other.m_username;
- this->m_password = other.m_password;
-}
-
-QString UserInfo::username() const
-{
- return m_username;
-}
-
-void UserInfo::setUsername(const QString &username)
-{
- this->m_username = username;
-}
-
-QString UserInfo::password() const
-{
- return m_password;
-}
-
-void UserInfo::setPassword(const QString &password)
-{
- this->m_password = password;
-}
diff --git a/libmultimc/src/version.cpp b/libmultimc/src/version.cpp
deleted file mode 100644
index eec50e13..00000000
--- a/libmultimc/src/version.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/* 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 "version.h"
-
-#include "config.h"
-
-Version Version::current(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_BUILD);
-
-Version::Version(int major, int minor, int revision, int build, QObject *parent) :
- QObject(parent)
-{
- this->major = major;
- this->minor = minor;
- this->revision = revision;
- this->build = build;
-}
-
-Version::Version(const Version& ver)
-{
- this->major = ver.major;
- this->minor = ver.minor;
- this->revision = ver.revision;
- this->build = ver.build;
-}
-
-QString Version::toString() const
-{
- return QString("%1.%2.%3.%4").arg(
- QString::number(major),
- QString::number(minor),
- QString::number(revision),
- QString::number(build));
-}