2015-04-04 14:46:15 +01:00
|
|
|
#include "FTBPlugin.h"
|
2016-04-10 03:29:29 +01:00
|
|
|
#include <Env.h>
|
2015-04-04 14:46:15 +01:00
|
|
|
#include "FTBVersion.h"
|
|
|
|
#include "LegacyFTBInstance.h"
|
|
|
|
#include "OneSixFTBInstance.h"
|
2015-02-09 00:51:14 +00:00
|
|
|
#include <BaseInstance.h>
|
|
|
|
#include <InstanceList.h>
|
|
|
|
#include <minecraft/MinecraftVersionList.h>
|
|
|
|
#include <settings/INISettingsObject.h>
|
2015-10-05 00:47:27 +01:00
|
|
|
#include <FileSystem.h>
|
2015-04-04 14:46:15 +01:00
|
|
|
|
2016-10-02 23:55:54 +01:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QRegularExpression>
|
2015-04-04 14:46:15 +01:00
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
static const int APPDATA_BUFFER_SIZE = 1024;
|
|
|
|
#endif
|
|
|
|
|
2015-05-22 00:27:59 +01:00
|
|
|
static QString getLocalCacheStorageLocation()
|
2015-04-04 14:46:15 +01:00
|
|
|
{
|
2015-05-21 23:56:41 +01:00
|
|
|
QString ftbDefault;
|
|
|
|
#ifdef Q_OS_WIN32
|
2015-04-04 14:46:15 +01:00
|
|
|
wchar_t buf[APPDATA_BUFFER_SIZE];
|
2015-05-21 23:56:41 +01:00
|
|
|
if (GetEnvironmentVariableW(L"LOCALAPPDATA", buf, APPDATA_BUFFER_SIZE)) // local
|
2015-04-04 14:46:15 +01:00
|
|
|
{
|
2015-05-21 23:56:41 +01:00
|
|
|
ftbDefault = QDir(QString::fromWCharArray(buf)).absoluteFilePath("ftblauncher");
|
2015-04-04 14:46:15 +01:00
|
|
|
}
|
2015-05-21 23:56:41 +01:00
|
|
|
else if (GetEnvironmentVariableW(L"APPDATA", buf, APPDATA_BUFFER_SIZE)) // roaming
|
2015-04-04 14:46:15 +01:00
|
|
|
{
|
2015-05-21 23:56:41 +01:00
|
|
|
ftbDefault = QDir(QString::fromWCharArray(buf)).absoluteFilePath("ftblauncher");
|
2015-04-04 14:46:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-21 23:56:41 +01:00
|
|
|
qCritical() << "Your LOCALAPPDATA and APPDATA folders are missing!"
|
|
|
|
" If you are on windows, this means your system is broken.";
|
2015-04-04 14:46:15 +01:00
|
|
|
}
|
2015-05-21 23:56:41 +01:00
|
|
|
#elif defined(Q_OS_MAC)
|
2015-10-05 00:53:09 +01:00
|
|
|
ftbDefault = FS::PathCombine(QDir::homePath(), "Library/Application Support/ftblauncher");
|
2015-05-21 23:56:41 +01:00
|
|
|
#else
|
|
|
|
ftbDefault = QDir::home().absoluteFilePath(".ftblauncher");
|
|
|
|
#endif
|
|
|
|
return ftbDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-22 00:27:59 +01:00
|
|
|
static QString getRoamingStorageLocation()
|
2015-05-21 23:56:41 +01:00
|
|
|
{
|
|
|
|
QString ftbDefault;
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
wchar_t buf[APPDATA_BUFFER_SIZE];
|
|
|
|
QString cacheStorage;
|
|
|
|
if (GetEnvironmentVariableW(L"APPDATA", buf, APPDATA_BUFFER_SIZE))
|
2015-04-04 14:46:15 +01:00
|
|
|
{
|
2015-05-21 23:56:41 +01:00
|
|
|
ftbDefault = QDir(QString::fromWCharArray(buf)).absoluteFilePath("ftblauncher");
|
2015-04-04 14:46:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-21 23:56:41 +01:00
|
|
|
qCritical() << "Your APPDATA folder is missing! If you are on windows, this means your system is broken.";
|
2015-04-04 14:46:15 +01:00
|
|
|
}
|
|
|
|
#elif defined(Q_OS_MAC)
|
2015-10-05 00:53:09 +01:00
|
|
|
ftbDefault = FS::PathCombine(QDir::homePath(), "Library/Application Support/ftblauncher");
|
2015-05-21 23:56:41 +01:00
|
|
|
#else
|
|
|
|
ftbDefault = QDir::home().absoluteFilePath(".ftblauncher");
|
2015-04-04 14:46:15 +01:00
|
|
|
#endif
|
2015-05-21 23:56:41 +01:00
|
|
|
return ftbDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FTBPlugin::initialize(SettingsObjectPtr globalSettings)
|
|
|
|
{
|
|
|
|
// FTB
|
|
|
|
globalSettings->registerSetting("TrackFTBInstances", false);
|
2015-05-22 00:27:59 +01:00
|
|
|
QString ftbRoaming = getRoamingStorageLocation();
|
|
|
|
QString ftbLocal = getLocalCacheStorageLocation();
|
2015-05-21 23:56:41 +01:00
|
|
|
|
2015-05-22 00:27:59 +01:00
|
|
|
globalSettings->registerSetting("FTBLauncherRoaming", ftbRoaming);
|
|
|
|
globalSettings->registerSetting("FTBLauncherLocal", ftbLocal);
|
|
|
|
qDebug() << "FTB Launcher paths:" << globalSettings->get("FTBLauncherRoaming").toString()
|
|
|
|
<< "and" << globalSettings->get("FTBLauncherLocal").toString();
|
2015-04-04 14:46:15 +01:00
|
|
|
|
2015-02-02 00:09:28 +00:00
|
|
|
globalSettings->registerSetting("FTBRoot");
|
|
|
|
if (globalSettings->get("FTBRoot").isNull())
|
2015-04-04 14:46:15 +01:00
|
|
|
{
|
|
|
|
QString ftbRoot;
|
2015-05-22 00:27:59 +01:00
|
|
|
QFile f(QDir(globalSettings->get("FTBLauncherRoaming").toString()).absoluteFilePath("ftblaunch.cfg"));
|
2015-04-04 14:46:15 +01:00
|
|
|
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;
|
2015-02-02 00:09:28 +00:00
|
|
|
globalSettings->set("FTBRoot", ftbRoot);
|
2015-04-04 14:46:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << "Couldn't open" << f.fileName() << ":" << f.errorString();
|
|
|
|
qWarning() << "This is perfectly normal if you don't have FTB installed";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|