diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bc06b0e..60e92e8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -559,6 +559,8 @@ SET(MULTIMC_SOURCES logic/ftb/LegacyFTBInstance.cpp logic/ftb/FTBProfileStrategy.h logic/ftb/FTBProfileStrategy.cpp + logic/ftb/FTBPlugin.h + logic/ftb/FTBPlugin.cpp # the screenshots feature logic/screenshots/Screenshot.h diff --git a/MultiMC.cpp b/MultiMC.cpp index b1b03ed9..6a967808 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -43,10 +43,7 @@ #include "logic/trans/TranslationDownloader.h" -#ifdef Q_OS_WIN32 -#include -static const int APPDATA_BUFFER_SIZE = 1024; -#endif +#include "logic/ftb/FTBPlugin.h" using namespace Util::Commandline; @@ -381,92 +378,7 @@ void MultiMC::initGlobalSettings(bool test_mode) } m_settings->registerSetting("ConsoleFontSize", defaultSize); - // FTB - m_settings->registerSetting("TrackFTBInstances", false); - QString ftbDataDefault; -#ifdef Q_OS_LINUX - QString ftbDefault = ftbDataDefault = QDir::home().absoluteFilePath(".ftblauncher"); -#elif defined(Q_OS_WIN32) - wchar_t buf[APPDATA_BUFFER_SIZE]; - wchar_t newBuf[APPDATA_BUFFER_SIZE]; - QString ftbDefault, newFtbDefault, oldFtbDefault; - if (!GetEnvironmentVariableW(L"LOCALAPPDATA", newBuf, APPDATA_BUFFER_SIZE)) - { - QLOG_FATAL() << "Your LOCALAPPDATA folder is missing! If you are on windows, this " - "means your system is broken. If you aren't on windows, how the **** " - "are you running the windows build????"; - } - else - { - newFtbDefault = QDir(QString::fromWCharArray(newBuf)).absoluteFilePath("ftblauncher"); - } - if (!GetEnvironmentVariableW(L"APPDATA", buf, APPDATA_BUFFER_SIZE)) - { - QLOG_FATAL() << "Your APPDATA folder is missing! If you are on windows, this means " - "your system is broken. If you aren't on windows, how the **** are you " - "running the windows build????"; - } - else - { - oldFtbDefault = QDir(QString::fromWCharArray(buf)).absoluteFilePath("ftblauncher"); - } - if (QFile::exists(QDir(newFtbDefault).absoluteFilePath("ftblaunch.cfg"))) - { - QLOG_INFO() << "Old FTB setup"; - ftbDefault = ftbDataDefault = oldFtbDefault; - } - else - { - QLOG_INFO() << "New FTB setup"; - ftbDefault = oldFtbDefault; - ftbDataDefault = newFtbDefault; - } -#elif defined(Q_OS_MAC) - QString ftbDefault = ftbDataDefault = - PathCombine(QDir::homePath(), "Library/Application Support/ftblauncher"); -#endif - m_settings->registerSetting("FTBLauncherDataRoot", ftbDataDefault); - m_settings->registerSetting("FTBLauncherRoot", ftbDefault); - QLOG_INFO() << "FTB Launcher paths:" << m_settings->get("FTBLauncherDataRoot").toString() - << "and" << m_settings->get("FTBLauncherRoot").toString(); - - m_settings->registerSetting("FTBRoot"); - if (m_settings->get("FTBRoot").isNull()) - { - QString ftbRoot; - QFile f(QDir(m_settings->get("FTBLauncherRoot").toString()) - .absoluteFilePath("ftblaunch.cfg")); - QLOG_INFO() << "Attempting to read" << f.fileName(); - if (f.open(QFile::ReadOnly)) - { - const QString data = QString::fromLatin1(f.readAll()); - QRegularExpression exp("installPath=(.*)"); - ftbRoot = QDir::cleanPath(exp.match(data).captured(1)); -#ifdef Q_OS_WIN32 - if (!ftbRoot.isEmpty()) - { - if (ftbRoot.at(0).isLetter() && ftbRoot.size() > 1 && ftbRoot.at(1) == '/') - { - ftbRoot.remove(1, 1); - } - } -#endif - if (ftbRoot.isEmpty()) - { - QLOG_INFO() << "Failed to get FTB root path"; - } - else - { - QLOG_INFO() << "FTB is installed at" << ftbRoot; - m_settings->set("FTBRoot", ftbRoot); - } - } - else - { - QLOG_WARN() << "Couldn't open" << f.fileName() << ":" << f.errorString(); - QLOG_WARN() << "This is perfectly normal if you don't have FTB installed"; - } - } + FTBPlugin::initialize(); // Folders m_settings->registerSetting("InstanceDir", "instances"); diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp index 857d3a09..2f1748cc 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -31,9 +31,6 @@ #include "logic/OneSixInstance.h" #include "logic/BaseVersion.h" #include "logic/minecraft/MinecraftVersion.h" -#include "logic/ftb/LegacyFTBInstance.h" -#include "logic/ftb/OneSixFTBInstance.h" -#include "logic/ftb/FTBVersion.h" InstanceFactory InstanceFactory::loader; @@ -59,14 +56,6 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(InstancePtr &inst, { inst.reset(new LegacyInstance(instDir, m_settings)); } - else if (inst_type == "LegacyFTB") - { - inst.reset(new LegacyFTBInstance(instDir, m_settings)); - } - else if (inst_type == "OneSixFTB") - { - inst.reset(new OneSixFTBInstance(instDir, m_settings)); - } else { return InstanceFactory::UnknownLoadError; @@ -106,25 +95,6 @@ InstanceFactory::createInstance(InstancePtr &inst, BaseVersionPtr version, const inst->init(); return InstanceFactory::NoCreateError; } - auto ftbVersion = std::dynamic_pointer_cast(version); - if(ftbVersion) - { - auto mcversion = ftbVersion->getMinecraftVersion(); - if (mcversion->usesLegacyLauncher()) - { - m_settings->set("InstanceType", "LegacyFTB"); - inst.reset(new LegacyFTBInstance(instDir, m_settings)); - inst->setIntendedVersionId(mcversion->descriptor()); - } - else - { - m_settings->set("InstanceType", "OneSixFTB"); - inst.reset(new OneSixFTBInstance(instDir, m_settings)); - inst->setIntendedVersionId(mcversion->descriptor()); - inst->init(); - } - return InstanceFactory::NoCreateError; - } delete m_settings; return InstanceFactory::NoSuchVersion; } @@ -146,11 +116,6 @@ InstanceFactory::InstCreateError InstanceFactory::copyInstance(InstancePtr &newI settings_obj.registerSetting("InstanceType", "Legacy"); QString inst_type = settings_obj.get("InstanceType").toString(); - if (inst_type == "OneSixFTB") - settings_obj.set("InstanceType", "OneSix"); - if (inst_type == "LegacyFTB") - settings_obj.set("InstanceType", "Legacy"); - oldInstance->copy(instDir); auto error = loadInstance(newInstance, instDir); diff --git a/logic/InstanceList.cpp b/logic/InstanceList.cpp index ec7dbdbf..3aaace8a 100644 --- a/logic/InstanceList.cpp +++ b/logic/InstanceList.cpp @@ -32,7 +32,7 @@ #include "logic/minecraft/MinecraftVersionList.h" #include "logic/BaseInstance.h" #include "logic/InstanceFactory.h" -#include "ftb/FTBVersion.h" +#include "ftb/FTBPlugin.h" #include "logger/QsLog.h" #include "gui/groupview/GroupView.h" @@ -284,169 +284,6 @@ void InstanceList::loadGroupList(QMap &groupMap) } } -QSet InstanceList::discoverFTBInstances() -{ - QSet records; - QDir dir = QDir(MMC->settings()->get("FTBLauncherDataRoot").toString()); - QDir dataDir = QDir(MMC->settings()->get("FTBRoot").toString()); - if (!dataDir.exists()) - { - QLOG_INFO() << "The FTB directory specified does not exist. Please check your settings"; - return records; - } - else if (!dir.exists()) - { - QLOG_INFO() << "The FTB launcher data directory specified does not exist. Please check your settings"; - return records; - } - dir.cd("ModPacks"); - auto allFiles = dir.entryList(QDir::Readable | QDir::Files, QDir::Name); - for (auto filename : allFiles) - { - if (!filename.endsWith(".xml")) - continue; - auto fpath = dir.absoluteFilePath(filename); - QFile f(fpath); - QLOG_INFO() << "Discovering FTB instances -- " << fpath; - if (!f.open(QFile::ReadOnly)) - continue; - - // read the FTB packs XML. - QXmlStreamReader reader(&f); - while (!reader.atEnd()) - { - switch (reader.readNext()) - { - case QXmlStreamReader::StartElement: - { - if (reader.name() == "modpack") - { - QXmlStreamAttributes attrs = reader.attributes(); - FTBRecord record; - record.dirName = attrs.value("dir").toString(); - record.instanceDir = dataDir.absoluteFilePath(record.dirName); - record.templateDir = dir.absoluteFilePath(record.dirName); - QDir test(record.instanceDir); - QLOG_DEBUG() << dataDir.absolutePath() << record.instanceDir << record.dirName; - if (!test.exists()) - continue; - record.name = attrs.value("name").toString(); - record.logo = attrs.value("logo").toString(); - auto customVersions = attrs.value("customMCVersions"); - if(!customVersions.isNull()) - { - QMap versionMatcher; - QString customVersionsStr = customVersions.toString(); - QStringList list = customVersionsStr.split(';'); - for(auto item: list) - { - auto segment = item.split('^'); - if(segment.size() != 2) - { - QLOG_ERROR() << "FTB: Segment of size < 2 in " << customVersionsStr; - continue; - } - versionMatcher[segment[0]] = segment[1]; - } - auto actualVersion = attrs.value("version").toString(); - if(versionMatcher.contains(actualVersion)) - { - record.mcVersion = versionMatcher[actualVersion]; - } - else - { - record.mcVersion = attrs.value("mcVersion").toString(); - } - } - else - { - record.mcVersion = attrs.value("mcVersion").toString(); - } - record.description = attrs.value("description").toString(); - records.insert(record); - } - break; - } - case QXmlStreamReader::EndElement: - break; - case QXmlStreamReader::Characters: - break; - default: - break; - } - } - f.close(); - } - return records; -} - -void InstanceList::loadFTBInstances(QMap &groupMap, - QList &tempList) -{ - auto records = discoverFTBInstances(); - if (!records.size()) - { - QLOG_INFO() << "No FTB instances to load."; - return; - } - QLOG_INFO() << "Loading FTB instances! -- got " << records.size(); - // process the records we acquired. - for (auto record : records) - { - QLOG_INFO() << "Loading FTB instance from " << record.instanceDir; - QString iconKey = record.logo; - iconKey.remove(QRegularExpression("\\..*")); - MMC->icons()->addIcon(iconKey, iconKey, PathCombine(record.templateDir, record.logo), - MMCIcon::Transient); - - if (!QFileInfo(PathCombine(record.instanceDir, "instance.cfg")).exists()) - { - QLOG_INFO() << "Converting " << record.name << " as new."; - InstancePtr instPtr; - auto &factory = InstanceFactory::get(); - auto mcVersion = std::dynamic_pointer_cast(MMC->minecraftlist()->findVersion(record.mcVersion)); - if (!mcVersion) - { - QLOG_ERROR() << "Can't load instance " << record.instanceDir - << " because minecraft version " << record.mcVersion - << " can't be resolved."; - continue; - } - auto ftbVersion = std::make_shared(mcVersion); - auto error = factory.createInstance(instPtr, ftbVersion, record.instanceDir); - - if (!instPtr || error != InstanceFactory::NoCreateError) - continue; - - instPtr->setGroupInitial("FTB"); - instPtr->setName(record.name); - instPtr->setIconKey(iconKey); - instPtr->setIntendedVersionId(record.mcVersion); - instPtr->setNotes(record.description); - if(!continueProcessInstance(instPtr, error, record.instanceDir, groupMap)) - continue; - tempList.append(InstancePtr(instPtr)); - } - else - { - QLOG_INFO() << "Loading existing " << record.name; - InstancePtr instPtr; - auto error = InstanceFactory::get().loadInstance(instPtr, record.instanceDir); - if (!instPtr || error != InstanceFactory::NoLoadError) - continue; - instPtr->setGroupInitial("FTB"); - instPtr->setName(record.name); - instPtr->setIconKey(iconKey); - if (instPtr->intendedVersionId() != record.mcVersion) - instPtr->setIntendedVersionId(record.mcVersion); - instPtr->setNotes(record.description); - if(!continueProcessInstance(instPtr, error, record.instanceDir, groupMap)) - continue; - tempList.append(InstancePtr(instPtr)); - } - } -} - InstanceList::InstListError InstanceList::loadList() { // load the instance groups @@ -471,10 +308,9 @@ InstanceList::InstListError InstanceList::loadList() } } - if (MMC->settings()->get("TrackFTBInstances").toBool()) - { - loadFTBInstances(groupMap, tempList); - } + // FIXME: generalize + FTBPlugin::loadInstances(groupMap, tempList); + beginResetModel(); m_instances.clear(); for(auto inst: tempList) diff --git a/logic/InstanceList.h b/logic/InstanceList.h index c251be5a..b7f2b997 100644 --- a/logic/InstanceList.h +++ b/logic/InstanceList.h @@ -26,33 +26,11 @@ class BaseInstance; class QDir; -struct FTBRecord -{ - QString dirName; - QString name; - QString logo; - QString mcVersion; - QString description; - QString instanceDir; - QString templateDir; - bool operator ==(const FTBRecord other) const - { - return instanceDir == other.instanceDir; - } -}; - -inline uint qHash(FTBRecord record) -{ - return qHash(record.instanceDir); -} - class InstanceList : public QAbstractListModel { Q_OBJECT private: void loadGroupList(QMap &groupList); - QSet discoverFTBInstances(); - void loadFTBInstances(QMap &groupMap, QList & tempList); public slots: @@ -141,7 +119,8 @@ slots: private: int getInstIndex(BaseInstance *inst) const; - bool continueProcessInstance(InstancePtr instPtr, const int error, const QDir &dir, +public: + static bool continueProcessInstance(InstancePtr instPtr, const int error, const QDir &dir, QMap &groupMap); protected: diff --git a/logic/ftb/FTBPlugin.cpp b/logic/ftb/FTBPlugin.cpp new file mode 100644 index 00000000..d9c6fec6 --- /dev/null +++ b/logic/ftb/FTBPlugin.cpp @@ -0,0 +1,361 @@ +#include "FTBPlugin.h" +#include "FTBVersion.h" +#include "LegacyFTBInstance.h" +#include "OneSixFTBInstance.h" +#include +#include +#include +#include +#include +#include +#include "MultiMC.h" +#include +#include "QDebug" +#include +#include + +struct FTBRecord +{ + QString dirName; + QString name; + QString logo; + QString mcVersion; + QString description; + QString instanceDir; + QString templateDir; + bool operator==(const FTBRecord other) const + { + return instanceDir == other.instanceDir; + } +}; + +inline uint qHash(FTBRecord record) +{ + return qHash(record.instanceDir); +} + +QSet discoverFTBInstances() +{ + QSet records; + QDir dir = QDir(MMC->settings()->get("FTBLauncherDataRoot").toString()); + QDir dataDir = QDir(MMC->settings()->get("FTBRoot").toString()); + if (!dataDir.exists()) + { + qDebug() << "The FTB directory specified does not exist. Please check your settings"; + return records; + } + else if (!dir.exists()) + { + qDebug() << "The FTB launcher data directory specified does not exist. Please check " + "your settings"; + return records; + } + dir.cd("ModPacks"); + auto allFiles = dir.entryList(QDir::Readable | QDir::Files, QDir::Name); + for (auto filename : allFiles) + { + if (!filename.endsWith(".xml")) + continue; + auto fpath = dir.absoluteFilePath(filename); + QFile f(fpath); + qDebug() << "Discovering FTB instances -- " << fpath; + if (!f.open(QFile::ReadOnly)) + continue; + + // read the FTB packs XML. + QXmlStreamReader reader(&f); + while (!reader.atEnd()) + { + switch (reader.readNext()) + { + case QXmlStreamReader::StartElement: + { + if (reader.name() == "modpack") + { + QXmlStreamAttributes attrs = reader.attributes(); + FTBRecord record; + record.dirName = attrs.value("dir").toString(); + record.instanceDir = dataDir.absoluteFilePath(record.dirName); + record.templateDir = dir.absoluteFilePath(record.dirName); + QDir test(record.instanceDir); + qDebug() << dataDir.absolutePath() << record.instanceDir << record.dirName; + if (!test.exists()) + continue; + record.name = attrs.value("name").toString(); + record.logo = attrs.value("logo").toString(); + auto customVersions = attrs.value("customMCVersions"); + if (!customVersions.isNull()) + { + QMap versionMatcher; + QString customVersionsStr = customVersions.toString(); + QStringList list = customVersionsStr.split(';'); + for (auto item : list) + { + auto segment = item.split('^'); + if (segment.size() != 2) + { + qCritical() << "FTB: Segment of size < 2 in " + << customVersionsStr; + continue; + } + versionMatcher[segment[0]] = segment[1]; + } + auto actualVersion = attrs.value("version").toString(); + if (versionMatcher.contains(actualVersion)) + { + record.mcVersion = versionMatcher[actualVersion]; + } + else + { + record.mcVersion = attrs.value("mcVersion").toString(); + } + } + else + { + record.mcVersion = attrs.value("mcVersion").toString(); + } + record.description = attrs.value("description").toString(); + records.insert(record); + } + break; + } + case QXmlStreamReader::EndElement: + break; + case QXmlStreamReader::Characters: + break; + default: + break; + } + } + f.close(); + } + return records; +} + +InstancePtr loadInstance(const QString &instDir) +{ + auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); + + InstancePtr inst; + + m_settings->registerSetting("InstanceType", "Legacy"); + + QString inst_type = m_settings->get("InstanceType").toString(); + + if (inst_type == "LegacyFTB") + { + inst.reset(new LegacyFTBInstance(instDir, m_settings)); + } + else if (inst_type == "OneSixFTB") + { + inst.reset(new OneSixFTBInstance(instDir, m_settings)); + } + inst->init(); + return inst; +} + +InstancePtr createInstance(MinecraftVersionPtr version, const QString &instDir) +{ + QDir rootDir(instDir); + + InstancePtr inst; + + if (!version) + { + qCritical() << "Can't create instance for non-existing MC version"; + return nullptr; + } + + qDebug() << instDir.toUtf8(); + if (!rootDir.exists() && !rootDir.mkpath(".")) + { + qCritical() << "Can't create instance folder" << instDir; + return nullptr; + } + + auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); + m_settings->registerSetting("InstanceType", "Legacy"); + + if (version->usesLegacyLauncher()) + { + m_settings->set("InstanceType", "LegacyFTB"); + inst.reset(new LegacyFTBInstance(instDir, m_settings)); + inst->setIntendedVersionId(version->descriptor()); + } + else + { + m_settings->set("InstanceType", "OneSixFTB"); + inst.reset(new OneSixFTBInstance(instDir, m_settings)); + inst->setIntendedVersionId(version->descriptor()); + inst->init(); + } + return inst; +} + +void FTBPlugin::loadInstances(QMap &groupMap, QList &tempList) +{ + // nothing to load when we don't have + if (MMC->settings()->get("TrackFTBInstances").toBool() != true) + { + return; + } + + auto records = discoverFTBInstances(); + if (!records.size()) + { + qDebug() << "No FTB instances to load."; + return; + } + qDebug() << "Loading FTB instances! -- got " << records.size(); + // process the records we acquired. + for (auto record : records) + { + qDebug() << "Loading FTB instance from " << record.instanceDir; + QString iconKey = record.logo; + iconKey.remove(QRegularExpression("\\..*")); + MMC->icons()->addIcon(iconKey, iconKey, PathCombine(record.templateDir, record.logo), + MMCIcon::Transient); + + if (!QFileInfo(PathCombine(record.instanceDir, "instance.cfg")).exists()) + { + qDebug() << "Converting " << record.name << " as new."; + auto mcVersion = std::dynamic_pointer_cast(MMC->minecraftlist()->findVersion(record.mcVersion)); + if (!mcVersion) + { + qCritical() << "Can't load instance " << record.instanceDir + << " because minecraft version " << record.mcVersion + << " can't be resolved."; + continue; + } + + auto instPtr = createInstance(mcVersion, record.instanceDir); + if (!instPtr) + { + continue; + } + + instPtr->setGroupInitial("FTB"); + instPtr->setName(record.name); + instPtr->setIconKey(iconKey); + instPtr->setIntendedVersionId(record.mcVersion); + instPtr->setNotes(record.description); + if (!InstanceList::continueProcessInstance(instPtr, InstanceFactory::NoCreateError, record.instanceDir, groupMap)) + continue; + tempList.append(InstancePtr(instPtr)); + } + else + { + qDebug() << "Loading existing " << record.name; + auto instPtr = loadInstance(record.instanceDir); + if (!instPtr) + { + continue; + } + instPtr->setGroupInitial("FTB"); + instPtr->setName(record.name); + instPtr->setIconKey(iconKey); + if (instPtr->intendedVersionId() != record.mcVersion) + { + instPtr->setIntendedVersionId(record.mcVersion); + } + instPtr->setNotes(record.description); + if (!InstanceList::continueProcessInstance(instPtr, InstanceFactory::NoCreateError, record.instanceDir, groupMap)) + continue; + tempList.append(InstancePtr(instPtr)); + } + } +} + +#ifdef Q_OS_WIN32 +#include +static const int APPDATA_BUFFER_SIZE = 1024; +#endif + +void FTBPlugin::initialize() +{ + auto m_settings = MMC->settings(); + // FTB + m_settings->registerSetting("TrackFTBInstances", false); + QString ftbDataDefault; +#ifdef Q_OS_LINUX + QString ftbDefault = ftbDataDefault = QDir::home().absoluteFilePath(".ftblauncher"); +#elif defined(Q_OS_WIN32) + wchar_t buf[APPDATA_BUFFER_SIZE]; + wchar_t newBuf[APPDATA_BUFFER_SIZE]; + QString ftbDefault, newFtbDefault, oldFtbDefault; + if (!GetEnvironmentVariableW(L"LOCALAPPDATA", newBuf, APPDATA_BUFFER_SIZE)) + { + qCritical() << "Your LOCALAPPDATA folder is missing! If you are on windows, this means " + "your system is broken."; + } + else + { + newFtbDefault = QDir(QString::fromWCharArray(newBuf)).absoluteFilePath("ftblauncher"); + } + if (!GetEnvironmentVariableW(L"APPDATA", buf, APPDATA_BUFFER_SIZE)) + { + qCritical() << "Your APPDATA folder is missing! If you are on windows, this means your " + "system is broken."; + } + else + { + oldFtbDefault = QDir(QString::fromWCharArray(buf)).absoluteFilePath("ftblauncher"); + } + if (QFile::exists(QDir(newFtbDefault).absoluteFilePath("ftblaunch.cfg"))) + { + qDebug() << "Old FTB setup"; + ftbDefault = ftbDataDefault = oldFtbDefault; + } + else + { + qDebug() << "New FTB setup"; + ftbDefault = oldFtbDefault; + ftbDataDefault = newFtbDefault; + } +#elif defined(Q_OS_MAC) + QString ftbDefault = ftbDataDefault = + PathCombine(QDir::homePath(), "Library/Application Support/ftblauncher"); +#endif + m_settings->registerSetting("FTBLauncherDataRoot", ftbDataDefault); + m_settings->registerSetting("FTBLauncherRoot", ftbDefault); + qDebug() << "FTB Launcher paths:" << m_settings->get("FTBLauncherDataRoot").toString() + << "and" << m_settings->get("FTBLauncherRoot").toString(); + + m_settings->registerSetting("FTBRoot"); + if (m_settings->get("FTBRoot").isNull()) + { + QString ftbRoot; + QFile f(QDir(m_settings->get("FTBLauncherRoot").toString()) + .absoluteFilePath("ftblaunch.cfg")); + qDebug() << "Attempting to read" << f.fileName(); + if (f.open(QFile::ReadOnly)) + { + const QString data = QString::fromLatin1(f.readAll()); + QRegularExpression exp("installPath=(.*)"); + ftbRoot = QDir::cleanPath(exp.match(data).captured(1)); +#ifdef Q_OS_WIN32 + if (!ftbRoot.isEmpty()) + { + if (ftbRoot.at(0).isLetter() && ftbRoot.size() > 1 && ftbRoot.at(1) == '/') + { + ftbRoot.remove(1, 1); + } + } +#endif + if (ftbRoot.isEmpty()) + { + qDebug() << "Failed to get FTB root path"; + } + else + { + qDebug() << "FTB is installed at" << ftbRoot; + m_settings->set("FTBRoot", ftbRoot); + } + } + else + { + qWarning() << "Couldn't open" << f.fileName() << ":" << f.errorString(); + qWarning() << "This is perfectly normal if you don't have FTB installed"; + } + } +} diff --git a/logic/ftb/FTBPlugin.h b/logic/ftb/FTBPlugin.h new file mode 100644 index 00000000..cb309355 --- /dev/null +++ b/logic/ftb/FTBPlugin.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +// Pseudo-plugin for FTB related things. Super derpy! +class FTBPlugin +{ +public: + static void initialize(); + static void loadInstances(QMap &groupMap, QList &tempList); +}; diff --git a/logic/ftb/LegacyFTBInstance.cpp b/logic/ftb/LegacyFTBInstance.cpp index 06bef948..bbc69e2c 100644 --- a/logic/ftb/LegacyFTBInstance.cpp +++ b/logic/ftb/LegacyFTBInstance.cpp @@ -1,4 +1,6 @@ #include "LegacyFTBInstance.h" +#include +#include LegacyFTBInstance::LegacyFTBInstance(const QString &rootDir, SettingsObject *settings, QObject *parent) : LegacyInstance(rootDir, settings, parent) @@ -18,3 +20,12 @@ QString LegacyFTBInstance::id() const { return "FTB/" + BaseInstance::id(); } + +void LegacyFTBInstance::copy(const QDir &newDir) +{ + // set the target instance to be plain Legacy + INISettingsObject settings_obj(newDir.absoluteFilePath("instance.cfg")); + settings_obj.registerSetting("InstanceType", "Legacy"); + QString inst_type = settings_obj.get("InstanceType").toString(); + settings_obj.set("InstanceType", "Legacy"); +} diff --git a/logic/ftb/LegacyFTBInstance.h b/logic/ftb/LegacyFTBInstance.h index 7ae7a97c..e67549e1 100644 --- a/logic/ftb/LegacyFTBInstance.h +++ b/logic/ftb/LegacyFTBInstance.h @@ -10,4 +10,5 @@ public: QObject *parent = 0); virtual QString getStatusbarDescription(); virtual QString id() const; + virtual void copy(const QDir &newDir); }; diff --git a/logic/ftb/OneSixFTBInstance.cpp b/logic/ftb/OneSixFTBInstance.cpp index 212b7373..6d64ddd8 100644 --- a/logic/ftb/OneSixFTBInstance.cpp +++ b/logic/ftb/OneSixFTBInstance.cpp @@ -7,6 +7,7 @@ #include "logic/tasks/SequentialTask.h" #include "logic/forge/ForgeInstaller.h" #include "logic/forge/ForgeVersionList.h" +#include #include "MultiMC.h" #include "pathutils.h" @@ -93,6 +94,11 @@ void OneSixFTBInstance::copy(const QDir &newDir) } } } + // now set the target instance to be plain OneSix + INISettingsObject settings_obj(newDir.absoluteFilePath("instance.cfg")); + settings_obj.registerSetting("InstanceType", "Legacy"); + QString inst_type = settings_obj.get("InstanceType").toString(); + settings_obj.set("InstanceType", "OneSix"); } QString OneSixFTBInstance::id() const