diff options
| author | Petr Mrázek <peterix@gmail.com> | 2015-01-27 22:31:07 +0100 |
|---|---|---|
| committer | Petr Mrázek <peterix@gmail.com> | 2015-04-02 00:14:06 +0200 |
| commit | 791221e923586bb717396ecf18bd13e57034df99 (patch) | |
| tree | 9f608af07375b38626c8964671620477158341ba /logic/minecraft | |
| parent | 593111b14463e9d5d08256061b981b5ab1cfb710 (diff) | |
| download | PrismLauncher-791221e923586bb717396ecf18bd13e57034df99.tar.gz PrismLauncher-791221e923586bb717396ecf18bd13e57034df99.tar.bz2 PrismLauncher-791221e923586bb717396ecf18bd13e57034df99.zip | |
NOISSUE Refactors and moving of things
Diffstat (limited to 'logic/minecraft')
26 files changed, 1250 insertions, 683 deletions
diff --git a/logic/minecraft/JarMod.cpp b/logic/minecraft/JarMod.cpp index 18a9411c..fce8a492 100644 --- a/logic/minecraft/JarMod.cpp +++ b/logic/minecraft/JarMod.cpp @@ -11,30 +11,6 @@ JarmodPtr Jarmod::fromJson(const QJsonObject &libObj, const QString &filename) "contains a jarmod that doesn't have a 'name' field"); } out->name = libObj.value("name").toString(); - - auto readString = [libObj, filename](const QString & key, QString & variable) - { - if (libObj.contains(key)) - { - QJsonValue val = libObj.value(key); - if (!val.isString()) - { - QLOG_WARN() << key << "is not a string in" << filename << "(skipping)"; - } - else - { - variable = val.toString(); - } - } - }; - - readString("url", out->baseurl); - readString("MMC-hint", out->hint); - readString("MMC-absoluteUrl", out->absoluteUrl); - if(!out->baseurl.isEmpty() && out->absoluteUrl.isEmpty()) - { - out->absoluteUrl = out->baseurl + out->name; - } return out; } @@ -42,15 +18,5 @@ QJsonObject Jarmod::toJson() { QJsonObject out; writeString(out, "name", name); - writeString(out, "url", baseurl); - writeString(out, "MMC-absoluteUrl", absoluteUrl); - writeString(out, "MMC-hint", hint); return out; } - -QString Jarmod::url() -{ - if(!absoluteUrl.isEmpty()) - return absoluteUrl; - else return baseurl + name; -} diff --git a/logic/minecraft/JarMod.h b/logic/minecraft/JarMod.h index c438dbcd..7d9fa038 100644 --- a/logic/minecraft/JarMod.h +++ b/logic/minecraft/JarMod.h @@ -9,10 +9,6 @@ class Jarmod public: /* methods */ static JarmodPtr fromJson(const QJsonObject &libObj, const QString &filename); QJsonObject toJson(); - QString url(); public: /* data */ QString name; - QString baseurl; - QString hint; - QString absoluteUrl; }; diff --git a/logic/minecraft/MinecraftInstance.cpp b/logic/minecraft/MinecraftInstance.cpp new file mode 100644 index 00000000..090c9389 --- /dev/null +++ b/logic/minecraft/MinecraftInstance.cpp @@ -0,0 +1,58 @@ +#include "MinecraftInstance.h" +#include "MultiMC.h" +#include "logic/settings/SettingsObject.h" +#include <pathutils.h> +#include "logic/minecraft/MinecraftVersionList.h" + +MinecraftInstance::MinecraftInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) + : BaseInstance(rootDir, settings, parent) +{ + auto globalSettings = MMC->settings(); + + // Java Settings + m_settings->registerSetting("OverrideJava", false); + m_settings->registerSetting("OverrideJavaLocation", false); + m_settings->registerSetting("OverrideJavaArgs", false); + m_settings->registerOverride(globalSettings->getSetting("JavaPath")); + m_settings->registerOverride(globalSettings->getSetting("JvmArgs")); + + // Custom Commands + m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false); + m_settings->registerOverride(globalSettings->getSetting("PreLaunchCommand")); + m_settings->registerOverride(globalSettings->getSetting("PostExitCommand")); + + // Window Size + m_settings->registerSetting("OverrideWindow", false); + m_settings->registerOverride(globalSettings->getSetting("LaunchMaximized")); + m_settings->registerOverride(globalSettings->getSetting("MinecraftWinWidth")); + m_settings->registerOverride(globalSettings->getSetting("MinecraftWinHeight")); + + // Memory + m_settings->registerSetting("OverrideMemory", false); + m_settings->registerOverride(globalSettings->getSetting("MinMemAlloc")); + m_settings->registerOverride(globalSettings->getSetting("MaxMemAlloc")); + m_settings->registerOverride(globalSettings->getSetting("PermGen")); + + // Console + m_settings->registerSetting("OverrideConsole", false); + m_settings->registerOverride(globalSettings->getSetting("ShowConsole")); + m_settings->registerOverride(globalSettings->getSetting("AutoCloseConsole")); + m_settings->registerOverride(globalSettings->getSetting("LogPrePostOutput")); +} + +QString MinecraftInstance::minecraftRoot() const +{ + QFileInfo mcDir(PathCombine(instanceRoot(), "minecraft")); + QFileInfo dotMCDir(PathCombine(instanceRoot(), ".minecraft")); + + if (dotMCDir.exists() && !mcDir.exists()) + return dotMCDir.filePath(); + else + return mcDir.filePath(); +} + +std::shared_ptr< BaseVersionList > MinecraftInstance::versionList() const +{ + return std::dynamic_pointer_cast<BaseVersionList>(MMC->minecraftlist()); +} + diff --git a/logic/minecraft/MinecraftInstance.h b/logic/minecraft/MinecraftInstance.h new file mode 100644 index 00000000..9097a2da --- /dev/null +++ b/logic/minecraft/MinecraftInstance.h @@ -0,0 +1,30 @@ +#pragma once +#include "logic/BaseInstance.h" + +class MinecraftInstance: public BaseInstance +{ +public: + MinecraftInstance(const QString& rootDir, SettingsObject* settings, QObject* parent = 0); + virtual ~MinecraftInstance() {}; + + /// Path to the instance's minecraft directory. + QString minecraftRoot() const; + + ////// Mod Lists ////// + virtual std::shared_ptr<ModList> resourcePackList() const + { + return nullptr; + } + virtual std::shared_ptr<ModList> texturePackList() const + { + return nullptr; + } + /// get all jar mods applicable to this instance's jar + virtual QList<Mod> getJarMods() const + { + return QList<Mod>(); + } + virtual std::shared_ptr< BaseVersionList > versionList() const; +}; + +typedef std::shared_ptr<MinecraftInstance> MinecraftInstancePtr; diff --git a/logic/minecraft/MinecraftProcess.cpp b/logic/minecraft/MinecraftProcess.cpp new file mode 100644 index 00000000..0fc3f067 --- /dev/null +++ b/logic/minecraft/MinecraftProcess.cpp @@ -0,0 +1,216 @@ +/* Copyright 2013-2014 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 "MultiMC.h" +#include "BuildConfig.h" + +#include "logic/minecraft/MinecraftProcess.h" +#include "logic/BaseInstance.h" + +#include <QDataStream> +#include <QFile> +#include <QDir> +#include <QProcessEnvironment> +#include <QRegularExpression> +#include <QStandardPaths> + +#include "osutils.h" +#include "pathutils.h" +#include "cmdutils.h" + +#define IBUS "@im=ibus" + +// constructor +MinecraftProcess::MinecraftProcess(MinecraftInstancePtr inst) : BaseProcess(inst) +{ +} + +MinecraftProcess* MinecraftProcess::create(MinecraftInstancePtr inst) +{ + auto proc = new MinecraftProcess(inst); + proc->init(); + return proc; +} + + +QString MinecraftProcess::censorPrivateInfo(QString in) +{ + if (!m_session) + return in; + + if (m_session->session != "-") + in.replace(m_session->session, "<SESSION ID>"); + in.replace(m_session->access_token, "<ACCESS TOKEN>"); + in.replace(m_session->client_token, "<CLIENT TOKEN>"); + in.replace(m_session->uuid, "<PROFILE ID>"); + in.replace(m_session->player_name, "<PROFILE NAME>"); + + auto i = m_session->u.properties.begin(); + while (i != m_session->u.properties.end()) + { + in.replace(i.value(), "<" + i.key().toUpper() + ">"); + ++i; + } + + return in; +} + +// console window +MessageLevel::Enum MinecraftProcess::guessLevel(const QString &line, MessageLevel::Enum level) +{ + QRegularExpression re("\\[(?<timestamp>[0-9:]+)\\] \\[[^/]+/(?<level>[^\\]]+)\\]"); + auto match = re.match(line); + if(match.hasMatch()) + { + // New style logs from log4j + QString timestamp = match.captured("timestamp"); + QString levelStr = match.captured("level"); + if(levelStr == "INFO") + level = MessageLevel::Message; + if(levelStr == "WARN") + level = MessageLevel::Warning; + if(levelStr == "ERROR") + level = MessageLevel::Error; + if(levelStr == "FATAL") + level = MessageLevel::Fatal; + if(levelStr == "TRACE" || levelStr == "DEBUG") + level = MessageLevel::Debug; + } + else + { + // Old style forge logs + 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("[STDERR]")) + level = MessageLevel::Error; + if (line.contains("[WARNING]")) + level = MessageLevel::Warning; + if (line.contains("[DEBUG]")) + level = MessageLevel::Debug; + } + if (line.contains("overwriting existing")) + return MessageLevel::Fatal; + if (line.contains("Exception in thread") || line.contains(QRegularExpression("\\s+at "))) + return MessageLevel::Error; + return level; +} + +QMap<QString, QString> MinecraftProcess::getVariables() const +{ + auto mcInstance = std::dynamic_pointer_cast<MinecraftInstance>(m_instance); + QMap<QString, QString> out; + out.insert("INST_NAME", mcInstance->name()); + out.insert("INST_ID", mcInstance->id()); + out.insert("INST_DIR", QDir(mcInstance->instanceRoot()).absolutePath()); + out.insert("INST_MC_DIR", QDir(mcInstance->minecraftRoot()).absolutePath()); + out.insert("INST_JAVA", mcInstance->settings().get("JavaPath").toString()); + out.insert("INST_JAVA_ARGS", javaArguments().join(' ')); + return out; +} + +QStringList MinecraftProcess::javaArguments() const +{ + QStringList args; + + // custom args go first. we want to override them if we have our own here. + args.append(m_instance->extraArguments()); + + // OSX dock icon and name +#ifdef OSX + args << "-Xdock:icon=icon.png"; + args << QString("-Xdock:name=\"%1\"").arg(m_instance->windowTitle()); +#endif + + // HACK: Stupid hack for Intel drivers. See: https://mojang.atlassian.net/browse/MCL-767 +#ifdef Q_OS_WIN32 + args << QString("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_" + "minecraft.exe.heapdump"); +#endif + + args << QString("-Xms%1m").arg(m_instance->settings().get("MinMemAlloc").toInt()); + args << QString("-Xmx%1m").arg(m_instance->settings().get("MaxMemAlloc").toInt()); + auto permgen = m_instance->settings().get("PermGen").toInt(); + if (permgen != 64) + { + args << QString("-XX:PermSize=%1m").arg(permgen); + } + args << "-Duser.language=en"; + if (!m_nativeFolder.isEmpty()) + args << QString("-Djava.library.path=%1").arg(m_nativeFolder); + args << "-jar" << PathCombine(MMC->bin(), "jars", "NewLaunch.jar"); + + return args; +} + +void MinecraftProcess::arm() +{ + emit log("MultiMC version: " + BuildConfig.printableVersionString() + "\n\n"); + emit log("Minecraft folder is:\n" + workingDirectory() + "\n\n"); + + if (!preLaunch()) + { + emit ended(m_instance, 1, QProcess::CrashExit); + return; + } + + m_instance->setLastLaunch(); + + QStringList args = javaArguments(); + + QString JavaPath = m_instance->settings().get("JavaPath").toString(); + emit log("Java path is:\n" + JavaPath + "\n\n"); + QString allArgs = args.join(", "); + emit log("Java Arguments:\n[" + censorPrivateInfo(allArgs) + "]\n\n"); + + auto realJavaPath = QStandardPaths::findExecutable(JavaPath); + if (realJavaPath.isEmpty()) + { + emit log(tr("The java binary \"%1\" couldn't be found. You may have to set up java " + "if Minecraft fails to launch.").arg(JavaPath), + MessageLevel::Warning); + } + + // instantiate the launcher part + start(JavaPath, args); + if (!waitForStarted()) + { + //: Error message displayed if instace can't start + emit log(tr("Could not launch minecraft!"), MessageLevel::Error); + m_instance->cleanupAfterRun(); + emit launch_failed(m_instance); + // not running, failed + m_instance->setRunning(false); + return; + } + // send the launch script to the launcher part + QByteArray bytes = launchScript.toUtf8(); + writeData(bytes.constData(), bytes.length()); +} + +void MinecraftProcess::launch() +{ + QString launchString("launch\n"); + QByteArray bytes = launchString.toUtf8(); + writeData(bytes.constData(), bytes.length()); +} + +void MinecraftProcess::abort() +{ + QString launchString("abort\n"); + QByteArray bytes = launchString.toUtf8(); + writeData(bytes.constData(), bytes.length()); +} diff --git a/logic/minecraft/MinecraftProcess.h b/logic/minecraft/MinecraftProcess.h new file mode 100644 index 00000000..30a59e91 --- /dev/null +++ b/logic/minecraft/MinecraftProcess.h @@ -0,0 +1,77 @@ +/* Copyright 2013-2014 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. + */ + +#pragma once + +#include <QString> +#include "logic/minecraft/MinecraftInstance.h" +#include "logic/BaseProcess.h" + +/** + * The MinecraftProcess class + */ +class MinecraftProcess : public BaseProcess +{ + Q_OBJECT +protected: + MinecraftProcess(MinecraftInstancePtr inst); +public: + static MinecraftProcess *create(MinecraftInstancePtr inst); + + virtual ~MinecraftProcess(){}; + + /** + * @brief start the launcher part with the provided launch script + */ + void arm() override; + + /** + * @brief launch the armed instance! + */ + void launch() override; + + /** + * @brief abort launch! + */ + void abort() override; + + void setLaunchScript(QString script) + { + launchScript = script; + } + + void setNativeFolder(QString natives) + { + m_nativeFolder = natives; + } + + inline void setLogin(AuthSessionPtr session) + { + m_session = session; + } + +protected: + AuthSessionPtr m_session; + QString launchScript; + QString m_nativeFolder; + + virtual QMap<QString, QString> getVariables() const override; + + QStringList javaArguments() const; + virtual QString censorPrivateInfo(QString in) override; + virtual MessageLevel::Enum guessLevel(const QString &message, MessageLevel::Enum defaultLevel) override; +}; diff --git a/logic/minecraft/InstanceVersion.cpp b/logic/minecraft/MinecraftProfile.cpp index cc077767..3fbfd105 100644 --- a/logic/minecraft/InstanceVersion.cpp +++ b/logic/minecraft/MinecraftProfile.cpp @@ -15,31 +15,50 @@ #include <QFile> #include <QDir> -#include <QUuid> #include <QJsonDocument> #include <QJsonArray> #include <pathutils.h> -#include "logic/minecraft/InstanceVersion.h" +#include "logic/minecraft/MinecraftProfile.h" #include "logic/minecraft/VersionBuilder.h" +#include "ProfileUtils.h" +#include "NullProfileStrategy.h" #include "logic/OneSixInstance.h" -InstanceVersion::InstanceVersion(OneSixInstance *instance, QObject *parent) - : QAbstractListModel(parent), m_instance(instance) +MinecraftProfile::MinecraftProfile(ProfileStrategy *strategy) + : QAbstractListModel() { + setStrategy(strategy); clear(); } -void InstanceVersion::reload(const QStringList &external) +void MinecraftProfile::setStrategy(ProfileStrategy* strategy) +{ + Q_ASSERT(strategy != nullptr); + + if(m_strategy != nullptr) + { + delete m_strategy; + m_strategy = nullptr; + } + m_strategy = strategy; + m_strategy->profile = this; +} + +ProfileStrategy* MinecraftProfile::strategy() +{ + return m_strategy; +} + +void MinecraftProfile::reload() { - m_externalPatches = external; beginResetModel(); - VersionBuilder::build(this, m_instance, m_externalPatches); - reapply(true); + m_strategy->load(); + reapply(); endResetModel(); } -void InstanceVersion::clear() +void MinecraftProfile::clear() { id.clear(); m_updateTimeString.clear(); @@ -59,44 +78,45 @@ void InstanceVersion::clear() traits.clear(); } -bool InstanceVersion::canRemove(const int index) const +void MinecraftProfile::clearPatches() { - return VersionPatches.at(index)->isMoveable(); + beginResetModel(); + VersionPatches.clear(); + endResetModel(); } -bool InstanceVersion::preremove(VersionPatchPtr patch) +void MinecraftProfile::appendPatch(ProfilePatchPtr patch) { - bool ok = true; - for(auto & jarmod: patch->getJarMods()) - { - QString fullpath =PathCombine(m_instance->jarModsDir(), jarmod->name); - QFileInfo finfo (fullpath); - if(finfo.exists()) - ok &= QFile::remove(fullpath); - } - return ok; + int index = VersionPatches.size(); + beginInsertRows(QModelIndex(), index, index); + VersionPatches.append(patch); + endInsertRows(); } -bool InstanceVersion::remove(const int index) +bool MinecraftProfile::canRemove(const int index) const +{ + return VersionPatches.at(index)->isMoveable(); +} + +bool MinecraftProfile::remove(const int index) { if (!canRemove(index)) return false; - if(!preremove(VersionPatches[index])) + + if(!m_strategy->removePatch(VersionPatches.at(index))) { return false; } - auto toDelete = VersionPatches.at(index)->getPatchFilename(); - if(!QFile::remove(toDelete)) - return false; + beginRemoveRows(QModelIndex(), index, index); VersionPatches.removeAt(index); endRemoveRows(); - reapply(true); + reapply(); saveCurrentOrder(); return true; } -bool InstanceVersion::remove(const QString id) +bool MinecraftProfile::remove(const QString id) { int i = 0; for (auto patch : VersionPatches) @@ -110,7 +130,7 @@ bool InstanceVersion::remove(const QString id) return false; } -QString InstanceVersion::versionFileId(const int index) const +QString MinecraftProfile::versionFileId(const int index) const { if (index < 0 || index >= VersionPatches.size()) { @@ -119,7 +139,7 @@ QString InstanceVersion::versionFileId(const int index) const return VersionPatches.at(index)->getPatchID(); } -VersionPatchPtr InstanceVersion::versionPatch(const QString &id) +ProfilePatchPtr MinecraftProfile::versionPatch(const QString &id) { for (auto file : VersionPatches) { @@ -131,67 +151,27 @@ VersionPatchPtr InstanceVersion::versionPatch(const QString &id) return 0; } -VersionPatchPtr InstanceVersion::versionPatch(int index) +ProfilePatchPtr MinecraftProfile::versionPatch(int index) { if(index < 0 || index >= VersionPatches.size()) return 0; return VersionPatches[index]; } - -bool InstanceVersion::hasJarMods() -{ - return !jarMods.isEmpty(); -} - -bool InstanceVersion::hasFtbPack() -{ - return versionPatch("org.multimc.ftb.pack.json") != nullptr; -} - -bool InstanceVersion::removeFtbPack() +bool MinecraftProfile::isVanilla() { - return remove("org.multimc.ftb.pack.json"); -} - -bool InstanceVersion::isVanilla() -{ - QDir patches(PathCombine(m_instance->instanceRoot(), "patches/")); for(auto patchptr: VersionPatches) { if(patchptr->isCustom()) return false; } - if(QFile::exists(PathCombine(m_instance->instanceRoot(), "custom.json"))) - return false; - if(QFile::exists(PathCombine(m_instance->instanceRoot(), "version.json"))) - return false; return true; } -bool InstanceVersion::revertToVanilla() +bool MinecraftProfile::revertToVanilla() { + /* beginResetModel(); - // remove custom.json, if present - QString customPath = PathCombine(m_instance->instanceRoot(), "custom.json"); - if(QFile::exists(customPath)) - { - if(!QFile::remove(customPath)) - { - endResetModel(); - return false; - } - } - // remove version.json, if present - QString versionPath = PathCombine(m_instance->instanceRoot(), "version.json"); - if(QFile::exists(versionPath)) - { - if(!QFile::remove(versionPath)) - { - endResetModel(); - return false; - } - } // remove patches, if present auto it = VersionPatches.begin(); while (it != VersionPatches.end()) @@ -215,49 +195,15 @@ bool InstanceVersion::revertToVanilla() else it++; } - reapply(true); + reapply(); endResetModel(); saveCurrentOrder(); return true; -} - -bool InstanceVersion::hasDeprecatedVersionFiles() -{ - if(QFile::exists(PathCombine(m_instance->instanceRoot(), "custom.json"))) - return true; - if(QFile::exists(PathCombine(m_instance->instanceRoot(), "version.json"))) - return true; + */ return false; } -bool InstanceVersion::removeDeprecatedVersionFiles() -{ - beginResetModel(); - // remove custom.json, if present - QString customPath = PathCombine(m_instance->instanceRoot(), "custom.json"); - if(QFile::exists(customPath)) - { - if(!QFile::remove(customPath)) - { - endResetModel(); - return false; - } - } - // remove version.json, if present - QString versionPath = PathCombine(m_instance->instanceRoot(), "version.json"); - if(QFile::exists(versionPath)) - { - if(!QFile::remove(versionPath)) - { - endResetModel(); - return false; - } - } - endResetModel(); - return true; -} - -QList<std::shared_ptr<OneSixLibrary> > InstanceVersion::getActiveNormalLibs() +QList<std::shared_ptr<OneSixLibrary> > MinecraftProfile::getActiveNormalLibs() { QList<std::shared_ptr<OneSixLibrary> > output; for (auto lib : libraries) @@ -277,7 +223,8 @@ QList<std::shared_ptr<OneSixLibrary> > InstanceVersion::getActiveNormalLibs() } return output; } -QList<std::shared_ptr<OneSixLibrary> > InstanceVersion::getActiveNativeLibs() + +QList<std::shared_ptr<OneSixLibrary> > MinecraftProfile::getActiveNativeLibs() { QList<std::shared_ptr<OneSixLibrary> > output; for (auto lib : libraries) @@ -290,9 +237,9 @@ QList<std::shared_ptr<OneSixLibrary> > InstanceVersion::getActiveNativeLibs() return output; } -std::shared_ptr<InstanceVersion> InstanceVersion::fromJson(const QJsonObject &obj) +std::shared_ptr<MinecraftProfile> MinecraftProfile::fromJson(const QJsonObject &obj) { - std::shared_ptr<InstanceVersion> version(new InstanceVersion(0)); + std::shared_ptr<MinecraftProfile> version(new MinecraftProfile(new NullProfileStrategy())); try { VersionBuilder::readJsonAndApplyToVersion(version.get(), obj); @@ -304,7 +251,7 @@ std::shared_ptr<InstanceVersion> InstanceVersion::fromJson(const QJsonObject &ob return version; } -QVariant InstanceVersion::data(const QModelIndex &index, int role) const +QVariant MinecraftProfile::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); @@ -329,7 +276,7 @@ QVariant InstanceVersion::data(const QModelIndex &index, int role) const } return QVariant(); } -QVariant InstanceVersion::headerData(int section, Qt::Orientation orientation, int role) const +QVariant MinecraftProfile::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal) { @@ -348,36 +295,36 @@ QVariant InstanceVersion::headerData(int section, Qt::Orientation orientation, i } return QVariant(); } -Qt::ItemFlags InstanceVersion::flags(const QModelIndex &index) const +Qt::ItemFlags MinecraftProfile::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::NoItemFlags; return Qt::ItemIsSelectable | Qt::ItemIsEnabled; } -int InstanceVersion::rowCount(const QModelIndex &parent) const +int MinecraftProfile::rowCount(const QModelIndex &parent) const { return VersionPatches.size(); } -int InstanceVersion::columnCount(const QModelIndex &parent) const +int MinecraftProfile::columnCount(const QModelIndex &parent) const { return 2; } -void InstanceVersion::saveCurrentOrder() const +void MinecraftProfile::saveCurrentOrder() const { - PatchOrder order; + ProfileUtils::PatchOrder order; for(auto item: VersionPatches) { if(!item->isMoveable()) continue; order.append(item->getPatchID()); } - VersionBuilder::writeOverrideOrders(m_instance, order); + m_strategy->saveOrder(order); } -void InstanceVersion::move(const int index, const MoveDirection direction) +void MinecraftProfile::move(const int index, const MoveDirection direction) { int theirIndex; if (direction == MoveUp) @@ -388,7 +335,7 @@ void InstanceVersion::move(const int index, const MoveDirection direction) { theirIndex = index + 1; } - + if (index < 0 || index >= VersionPatches.size()) return; if (theirIndex >= rowCount()) @@ -401,7 +348,7 @@ void InstanceVersion::move(const int index, const MoveDirection direction) auto from = versionPatch(index); auto to = versionPatch(theirIndex); - + if (!from || !to || !to->isMoveable() || !from->isMoveable()) { return; @@ -412,13 +359,13 @@ void InstanceVersion::move(const int index, const MoveDirection direction) saveCurrentOrder(); reapply(); } -void InstanceVersion::resetOrder() +void MinecraftProfile::resetOrder() { - QDir(m_instance->instanceRoot()).remove("order.json"); - reload(m_externalPatches); + m_strategy->resetOrder(); + reload(); } -void InstanceVersion::reapply(const bool alreadyReseting) +void MinecraftProfile::reapply() { clear(); for(auto file: VersionPatches) @@ -428,7 +375,7 @@ void InstanceVersion::reapply(const bool alreadyReseting) finalize(); } -void InstanceVersion::finalize() +void MinecraftProfile::finalize() { // HACK: deny april fools. my head hurts enough already. QDate now = QDate::currentDate(); @@ -465,78 +412,15 @@ void InstanceVersion::finalize() finalizeArguments(minecraftArguments, processArguments); } -void InstanceVersion::installJarMods(QStringList selectedFiles) -{ - for(auto filename: selectedFiles) - { - installJarModByFilename(filename); - } -} - -void InstanceVersion::installJarModByFilename(QString filepath) +void MinecraftProfile::installJarMods(QStringList selectedFiles) { - QString patchDir = PathCombine(m_instance->instanceRoot(), "patches"); - if(!ensureFolderPathExists(patchDir)) - { - // THROW... - return; - } - - if (!ensureFolderPathExists(m_ |
