From cfdfd0e8118fce8525a4618e0ee162f63504ed5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 22 May 2015 00:56:41 +0200 Subject: GH-977 possibly fix FTB on windows. Maybe. Partially. Now maybe for real. --- logic/ftb/FTBPlugin.cpp | 76 ++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/logic/ftb/FTBPlugin.cpp b/logic/ftb/FTBPlugin.cpp index b30fc378..2f294b01 100644 --- a/logic/ftb/FTBPlugin.cpp +++ b/logic/ftb/FTBPlugin.cpp @@ -269,58 +269,62 @@ void FTBPlugin::loadInstances(SettingsObjectPtr globalSettings, QMapregisterSetting("TrackFTBInstances", false); - QString ftbDataDefault; -#ifdef Q_OS_LINUX - QString ftbDefault = ftbDataDefault = QDir::home().absoluteFilePath(".ftblauncher"); -#elif defined(Q_OS_WIN32) + QString ftbDefault; +#ifdef 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)) - { - if(!GetEnvironmentVariableW(L"USERPROFILE", newBuf, APPDATA_BUFFER_SIZE)) - { - qCritical() << "Your LOCALAPPDATA folder is missing! If you are on windows, this means your system is broken."; - } - else - { - auto userHome = QString::fromWCharArray(newBuf); - auto localAppData = PathCombine(QString::fromWCharArray(newBuf), "Local Settings", "Application Data"); - newFtbDefault = QDir(localAppData).absoluteFilePath("ftblauncher"); - } - } - else + if (GetEnvironmentVariableW(L"LOCALAPPDATA", buf, APPDATA_BUFFER_SIZE)) // local { - newFtbDefault = QDir(QString::fromWCharArray(newBuf)).absoluteFilePath("ftblauncher"); + ftbDefault = QDir(QString::fromWCharArray(buf)).absoluteFilePath("ftblauncher"); } - if (!GetEnvironmentVariableW(L"APPDATA", buf, APPDATA_BUFFER_SIZE)) + else if (GetEnvironmentVariableW(L"APPDATA", buf, APPDATA_BUFFER_SIZE)) // roaming { - qCritical() << "Your APPDATA folder is missing! If you are on windows, this means your " - "system is broken."; + ftbDefault = QDir(QString::fromWCharArray(buf)).absoluteFilePath("ftblauncher"); } else { - oldFtbDefault = QDir(QString::fromWCharArray(buf)).absoluteFilePath("ftblauncher"); + qCritical() << "Your LOCALAPPDATA and APPDATA folders are missing!" + " If you are on windows, this means your system is broken."; } - if (QFile::exists(QDir(newFtbDefault).absoluteFilePath("ftblaunch.cfg"))) +#elif defined(Q_OS_MAC) + ftbDefault = PathCombine(QDir::homePath(), "Library/Application Support/ftblauncher"); +#else + ftbDefault = QDir::home().absoluteFilePath(".ftblauncher"); +#endif + return ftbDefault; +} + + +static QString getDynamicStorageLocation() +{ + QString ftbDefault; +#ifdef Q_OS_WIN32 + wchar_t buf[APPDATA_BUFFER_SIZE]; + QString cacheStorage; + if (GetEnvironmentVariableW(L"APPDATA", buf, APPDATA_BUFFER_SIZE)) { - qDebug() << "Old FTB setup"; - ftbDefault = ftbDataDefault = oldFtbDefault; + ftbDefault = QDir(QString::fromWCharArray(buf)).absoluteFilePath("ftblauncher"); } else { - qDebug() << "New FTB setup"; - ftbDefault = oldFtbDefault; - ftbDataDefault = newFtbDefault; + qCritical() << "Your APPDATA folder is missing! If you are on windows, this means your system is broken."; } #elif defined(Q_OS_MAC) - QString ftbDefault = ftbDataDefault = - PathCombine(QDir::homePath(), "Library/Application Support/ftblauncher"); + ftbDefault = PathCombine(QDir::homePath(), "Library/Application Support/ftblauncher"); +#else + ftbDefault = QDir::home().absoluteFilePath(".ftblauncher"); #endif + return ftbDefault; +} + +void FTBPlugin::initialize(SettingsObjectPtr globalSettings) +{ + // FTB + globalSettings->registerSetting("TrackFTBInstances", false); + QString ftbDataDefault = getDynamicStorageLocation(); + QString ftbDefault = getCacheStorageLocation(); + globalSettings->registerSetting("FTBLauncherDataRoot", ftbDataDefault); globalSettings->registerSetting("FTBLauncherRoot", ftbDefault); qDebug() << "FTB Launcher paths:" << globalSettings->get("FTBLauncherDataRoot").toString() -- cgit v1.2.3