aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--MultiMC.cpp136
-rw-r--r--MultiMC.h93
-rw-r--r--gui/MainWindow.cpp11
-rw-r--r--gui/pages/LegacyJarModPage.cpp3
-rw-r--r--gui/pages/global/AccountListPage.cpp3
-rw-r--r--gui/pages/global/MinecraftPage.cpp4
-rw-r--r--gui/pages/global/MinecraftPage.ui19
-rw-r--r--logic/Env.cpp104
-rw-r--r--logic/Env.h44
-rw-r--r--logic/LegacyUpdate.cpp14
-rw-r--r--logic/LwjglVersionList.cpp4
-rw-r--r--logic/OneSixUpdate.cpp15
-rw-r--r--logic/SkinUtils.cpp4
-rw-r--r--logic/assets/AssetsUtils.cpp3
-rw-r--r--logic/auth/YggdrasilTask.cpp6
-rw-r--r--logic/forge/ForgeInstaller.cpp11
-rw-r--r--logic/forge/ForgeMirrors.cpp4
-rw-r--r--logic/forge/ForgeVersionList.cpp6
-rw-r--r--logic/forge/ForgeXzDownload.cpp6
-rw-r--r--logic/icons/IconList.cpp8
-rw-r--r--logic/icons/IconList.h7
-rw-r--r--logic/java/JavaChecker.cpp2
-rw-r--r--logic/liteloader/LiteLoaderVersionList.cpp4
-rw-r--r--logic/minecraft/MinecraftProcess.cpp2
-rw-r--r--logic/minecraft/MinecraftVersion.cpp4
-rw-r--r--logic/minecraft/MinecraftVersionList.cpp4
-rw-r--r--logic/minecraft/VersionBuilder.cpp1
-rw-r--r--logic/net/ByteArrayDownload.cpp4
-rw-r--r--logic/net/CacheDownload.cpp6
-rw-r--r--logic/net/HttpMetaCache.cpp5
-rw-r--r--logic/net/HttpMetaCache.h3
-rw-r--r--logic/net/MD5EtagDownload.cpp4
-rw-r--r--logic/net/PasteUpload.cpp4
-rw-r--r--logic/screenshots/ImgurAlbumCreation.cpp4
-rw-r--r--logic/screenshots/ImgurUpload.cpp4
-rw-r--r--logic/trans/TranslationDownloader.cpp5
-rw-r--r--logic/updater/DownloadUpdateTask.cpp11
-rw-r--r--logic/updater/DownloadUpdateTask.h17
-rw-r--r--logic/updater/NotificationChecker.cpp5
-rw-r--r--logic/updater/UpdateChecker.cpp20
-rw-r--r--logic/updater/UpdateChecker.h12
-rw-r--r--tests/tst_DownloadUpdateTask.cpp6
-rw-r--r--tests/tst_UpdateChecker.cpp34
44 files changed, 343 insertions, 325 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e4cd6387..3807d04f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -432,6 +432,8 @@ SET(MULTIMC_SOURCES
logic/DefaultVariable.h
# network stuffs
+ logic/Env.h
+ logic/Env.cpp
logic/net/NetAction.h
logic/net/MD5EtagDownload.h
logic/net/MD5EtagDownload.cpp
diff --git a/MultiMC.cpp b/MultiMC.cpp
index 3644a6ad..b1b03ed9 100644
--- a/MultiMC.cpp
+++ b/MultiMC.cpp
@@ -23,6 +23,7 @@
#include "logic/net/HttpMetaCache.h"
#include "logic/net/URLConstants.h"
+#include "logic/Env.h"
#include "logic/java/JavaUtils.h"
@@ -108,8 +109,9 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar
return;
}
}
- origcwdPath = QDir::currentPath();
- binPath = applicationDirPath();
+
+ QString origcwdPath = QDir::currentPath();
+ QString binPath = applicationDirPath();
QString adjustedBy;
// change directory
QString dirParam = args["dir"].toString();
@@ -191,7 +193,7 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar
initTranslations();
// initialize the updater
- m_updateChecker.reset(new UpdateChecker());
+ m_updateChecker.reset(new UpdateChecker(BuildConfig.CHANLIST_URL, BuildConfig.VERSION_BUILD));
m_translationChecker.reset(new TranslationDownloader());
@@ -219,15 +221,22 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar
m_accounts->loadList();
// init the http meta cache
- initHttpMetaCache();
+ ENV.initHttpMetaCache(rootPath, staticDataPath);
// create the global network manager
- m_qnam.reset(new QNetworkAccessManager(this));
-
- m_translationChecker->downloadTranslations();
+ ENV.m_qnam.reset(new QNetworkAccessManager(this));
// init proxy settings
- updateProxySettings();
+ {
+ QString proxyTypeStr = settings()->get("ProxyType").toString();
+ QString addr = settings()->get("ProxyAddr").toString();
+ int port = settings()->get("ProxyPort").value<qint16>();
+ QString user = settings()->get("ProxyUser").toString();
+ QString pass = settings()->get("ProxyPass").toString();
+ ENV.updateProxySettings(proxyTypeStr, addr, port, user, pass);
+ }
+
+ m_translationChecker->downloadTranslations();
//FIXME: what to do with these?
m_profilers.insert("jprofiler",
@@ -285,7 +294,7 @@ void MultiMC::initTranslations()
}
m_mmc_translator.reset(new QTranslator());
- if (m_mmc_translator->load("mmc_" + locale.bcp47Name(), staticData() + "/translations"))
+ if (m_mmc_translator->load("mmc_" + locale.bcp47Name(), staticDataPath + "/translations"))
{
QLOG_DEBUG() << "Loading MMC Language File for"
<< locale.bcp47Name().toLocal8Bit().constData() << "...";
@@ -335,9 +344,6 @@ void MultiMC::initGlobalSettings(bool test_mode)
m_settings->registerSetting("AutoUpdate", true);
m_settings->registerSetting("IconTheme", QString("multimc"));
- // Minecraft Sneaky Updates
- m_settings->registerSetting("AutoUpdateMinecraftVersions", true);
-
// Notifications
m_settings->registerSetting("ShownNotifications", QString());
@@ -530,99 +536,17 @@ void MultiMC::initGlobalSettings(bool test_mode)
m_settings->registerSetting("PagedGeometry", "");
}
-void MultiMC::initHttpMetaCache()
-{
- m_metacache.reset(new HttpMetaCache("metacache"));
- m_metacache->addBase("asset_indexes", QDir("assets/indexes").absolutePath());
- m_metacache->addBase("asset_objects", QDir("assets/objects").absolutePath());
- m_metacache->addBase("versions", QDir("versions").absolutePath());
- m_metacache->addBase("libraries", QDir("libraries").absolutePath());
- m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
- m_metacache->addBase("fmllibs", QDir("mods/minecraftforge/libs").absolutePath());
- m_metacache->addBase("liteloader", QDir("mods/liteloader").absolutePath());
- m_metacache->addBase("general", QDir("cache").absolutePath());
- m_metacache->addBase("skins", QDir("accounts/skins").absolutePath());
- m_metacache->addBase("root", QDir(root()).absolutePath());
- m_metacache->addBase("translations", QDir(staticData() + "/translations").absolutePath());
- m_metacache->Load();
-}
-
-void MultiMC::updateProxySettings()
-{
- QString proxyTypeStr = settings()->get("ProxyType").toString();
-
- // Get the proxy settings from the settings object.
- QString addr = settings()->get("ProxyAddr").toString();
- int port = settings()->get("ProxyPort").value<qint16>();
- QString user = settings()->get("ProxyUser").toString();
- QString pass = settings()->get("ProxyPass").toString();
-
- // Set the application proxy settings.
- if (proxyTypeStr == "SOCKS5")
- {
- QNetworkProxy::setApplicationProxy(
- QNetworkProxy(QNetworkProxy::Socks5Proxy, addr, port, user, pass));
- }
- else if (proxyTypeStr == "HTTP")
- {
- QNetworkProxy::setApplicationProxy(
- QNetworkProxy(QNetworkProxy::HttpProxy, addr, port, user, pass));
- }
- else if (proxyTypeStr == "None")
- {
- // If we have no proxy set, set no proxy and return.
- QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::NoProxy));
- }
- else
- {
- // If we have "Default" selected, set Qt to use the system proxy settings.
- QNetworkProxyFactory::setUseSystemConfiguration(true);
- }
-
- QLOG_INFO() << "Detecting proxy settings...";
- QNetworkProxy proxy = QNetworkProxy::applicationProxy();
- if (m_qnam.get())
- m_qnam->setProxy(proxy);
- QString proxyDesc;
- if (proxy.type() == QNetworkProxy::NoProxy)
- {
- QLOG_INFO() << "Using no proxy is an option!";
- return;
- }
- switch (proxy.type())
- {
- case QNetworkProxy::DefaultProxy:
- proxyDesc = "Default proxy: ";
- break;
- case QNetworkProxy::Socks5Proxy:
- proxyDesc = "Socks5 proxy: ";
- break;
- case QNetworkProxy::HttpProxy:
- proxyDesc = "HTTP proxy: ";
- break;
- case QNetworkProxy::HttpCachingProxy:
- proxyDesc = "HTTP caching: ";
- break;
- case QNetworkProxy::FtpCachingProxy:
- proxyDesc = "FTP caching: ";
- break;
- default:
- proxyDesc = "DERP proxy: ";
- break;
- }
- proxyDesc += QString("%3@%1:%2 pass %4")
- .arg(proxy.hostName())
- .arg(proxy.port())
- .arg(proxy.user())
- .arg(proxy.password());
- QLOG_INFO() << proxyDesc;
-}
-
std::shared_ptr<IconList> MultiMC::icons()
{
if (!m_icons)
{
- m_icons.reset(new IconList);
+
+ auto setting = MMC->settings()->getSetting("IconsDir");
+ m_icons.reset(new IconList(setting->get().toString()));
+ connect(setting.get(), &Setting::SettingChanged,[&](const Setting &, QVariant value)
+ {
+ m_icons->directoryChanged(value.toString());
+ });
}
return m_icons;
}
@@ -690,13 +614,13 @@ void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags)
QLOG_INFO() << "Installing updates.";
#ifdef WINDOWS
QString finishCmd = applicationFilePath();
- QString updaterBinary = PathCombine(bin(), "updater.exe");
+ QString updaterBinary = PathCombine(applicationDirPath(), "updater.exe");
#elif LINUX
QString finishCmd = PathCombine(root(), "MultiMC");
- QString updaterBinary = PathCombine(bin(), "updater");
+ QString updaterBinary = PathCombine(applicationDirPath(), "updater");
#elif OSX
QString finishCmd = applicationFilePath();
- QString updaterBinary = PathCombine(bin(), "updater");
+ QString updaterBinary = PathCombine(applicationDirPath(), "updater");
#else
#error Unsupported operating system.
#endif
@@ -713,7 +637,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags)
if (flags & RestartOnFinish)
{
args << "--finish-cmd" << finishCmd;
- args << "--finish-dir" << data();
+ args << "--finish-dir" << dataPath;
}
QLOG_INFO() << "Running updater with command" << updaterBinary << args.join(" ");
QFile::setPermissions(updaterBinary, (QFileDevice::Permission)0x7755);
@@ -724,6 +648,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags)
return;
}
+ ENV.destroy();
// Now that we've started the updater, quit MultiMC.
quit();
}
@@ -744,6 +669,7 @@ void MultiMC::onExit()
{
installUpdates(m_updateOnExitPath, m_updateOnExitFlags);
}
+ ENV.destroy();
}
bool MultiMC::openJsonEditor(const QString &filename)
diff --git a/MultiMC.h b/MultiMC.h
index 59ff32d2..ccf950d1 100644
--- a/MultiMC.h
+++ b/MultiMC.h
@@ -40,6 +40,9 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(UpdateFlags);
class MultiMC : public QApplication
{
+ // friends for the purpose of limiting access to deprecated stuff
+ friend class MultiMCPage;
+ friend class MainWindow;
Q_OBJECT
public:
enum Status
@@ -53,106 +56,92 @@ public:
MultiMC(int &argc, char **argv, bool test_mode = false);
virtual ~MultiMC();
+ // InstanceList, IconList, OneSixFTBInstance, LegacyUpdate, LegacyInstance, MCEditTool, JVisualVM, MinecraftInstance, JProfiler, BaseInstance
std::shared_ptr<SettingsObject> settings()
{
return m_settings;
}
+ // InstanceList, OneSixUpdate, MinecraftInstance, OneSixProfileStrategy
+ std::shared_ptr<MinecraftVersionList> minecraftlist();
- std::shared_ptr<InstanceList> instances()
- {
- return m_instances;
- }
-
- std::shared_ptr<MojangAccountList> accounts()
- {
- return m_accounts;
- }
-
+ // LegacyInstance, BaseInstance, OneSixInstance, InstanceList
std::shared_ptr<IconList> icons();
QIcon getThemedIcon(const QString& name);
void setIconTheme(const QString& name);
- Status status()
- {
- return m_status;
- }
-
- std::shared_ptr<QNetworkAccessManager> qnam()
- {
- return m_qnam;
- }
-
- std::shared_ptr<HttpMetaCache> metacache()
- {
- return m_metacache;
- }
-
+ // DownloadUpdateTask
std::shared_ptr<UpdateChecker> updateChecker()
{
return m_updateChecker;
}
+ // LegacyUpdate
std::shared_ptr<LWJGLVersionList> lwjgllist();
+ // APPLICATION ONLY
std::shared_ptr<ForgeVersionList> forgelist();
+ // APPLICATION ONLY
std::shared_ptr<LiteLoaderVersionList> liteloaderlist();
- std::shared_ptr<MinecraftVersionList> minecraftlist();
-
+ // APPLICATION ONLY
std::shared_ptr<JavaVersionList> javalist();
+ // APPLICATION ONLY
+ std::shared_ptr<InstanceList> instances()
+ {
+ return m_instances;
+ }
+
+ // APPLICATION ONLY
+ std::shared_ptr<MojangAccountList> accounts()
+ {
+ return m_accounts;
+ }
+
+ // APPLICATION ONLY
+ Status status()
+ {
+ return m_status;
+ }
+
+ // APPLICATION ONLY
QMap<QString, std::shared_ptr<BaseProfilerFactory>> profilers()
{
return m_profilers;
}
+
+ // APPLICATION ONLY
QMap<QString, std::shared_ptr<BaseDetachedToolFactory>> tools()
{
return m_tools;
}
+ // APPLICATION ONLY
void installUpdates(const QString updateFilesDir, UpdateFlags flags = None);
/*!
- * Updates the application proxy settings from the settings object.
- */
- void updateProxySettings();
-
- /*!
* Opens a json file using either a system default editor, or, if note empty, the editor
* specified in the settings
*/
bool openJsonEditor(const QString &filename);
+protected: /* to be removed! */
+ // FIXME: remove. used by MultiMCPage to enumerate translations.
/// this is the static data. it stores things that don't move.
const QString &staticData()
{
return staticDataPath;
}
+
+ // FIXME: remove. used by MainWindow to create application update tasks
/// this is the root of the 'installation'. Used for automatic updates
const QString &root()
{
return rootPath;
}
- /// this is the where the binary files reside
- const QString &bin()
- {
- return binPath;
- }
- /// this is the work/data path. All user data is here.
- const QString &data()
- {
- return dataPath;
- }
- /**
- * this is the original work path before it was changed by the adjustment mechanism
- */
- const QString &origcwd()
- {
- return origcwdPath;
- }
private slots:
/**
@@ -165,8 +154,6 @@ private:
void initGlobalSettings(bool test_mode);
- void initHttpMetaCache();
-
void initTranslations();
private:
@@ -180,8 +167,6 @@ private:
std::shared_ptr<UpdateChecker> m_updateChecker;
std::shared_ptr<MojangAccountList> m_accounts;
std::shared_ptr<IconList> m_icons;
- std::shared_ptr<QNetworkAccessManager> m_qnam;
- std::shared_ptr<HttpMetaCache> m_metacache;
std::shared_ptr<LWJGLVersionList> m_lwjgllist;
std::shared_ptr<ForgeVersionList> m_forgelist;
std::shared_ptr<LiteLoaderVersionList> m_liteloaderlist;
@@ -200,9 +185,7 @@ private:
QString rootPath;
QString staticDataPath;
- QString binPath;
QString dataPath;
- QString origcwdPath;
Status m_status = MultiMC::Failed;
};
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index f12ccf24..721a6833 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -375,6 +375,7 @@ namespace Ui {
#include "logic/net/URLConstants.h"
#include "logic/net/NetJob.h"
+#include "logic/Env.h"
#include "logic/BaseInstance.h"
#include "logic/OneSixInstance.h"
@@ -572,7 +573,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
{
for (auto profile : account->profiles())
{
- auto meta = MMC->metacache()->resolveEntry("skins", profile.name + ".png");
+ auto meta = Env::getInstance().metacache()->resolveEntry("skins", profile.name + ".png");
auto action = CacheDownload::make(
QUrl("http://" + URLConstants::SKINS_BASE + profile.name + ".png"), meta);
skin_dls.append(action);
@@ -619,7 +620,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
if (MMC->settings()->get("AutoUpdate").toBool())
{
auto updater = MMC->updateChecker();
- updater->checkForUpdate(false);
+ updater->checkForUpdate(MMC->settings()->get("UpdateChannel").toString(), false);
}
m_notificationChecker.reset(new NotificationChecker());
connect(m_notificationChecker.get(),
@@ -981,7 +982,7 @@ void MainWindow::downloadUpdates(QString repo, int versionId, bool installOnExit
// Doing so is a bit complicated, because we'd have to make sure it finished downloading
// before actually exiting MultiMC.
ProgressDialog updateDlg(this);
- DownloadUpdateTask updateTask(repo, versionId, &updateDlg);
+ DownloadUpdateTask updateTask(MMC->root(), repo, versionId, &updateDlg);
// If the task succeeds, install the updates.
if (updateDlg.exec(&updateTask))
{
@@ -1070,7 +1071,7 @@ void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QStrin
else
{
const QString path = url.host() + '/' + url.path();
- auto entry = MMC->metacache()->resolveEntry("general", path);
+ auto entry = ENV.metacache()->resolveEntry("general", path);
CacheDownloadPtr dl = CacheDownload::make(url, entry);
NetJob job(tr("Modpack download"));
job.addNetAction(dl);
@@ -1357,7 +1358,7 @@ void MainWindow::on_actionConfig_Folder_triggered()
void MainWindow::on_actionCheckUpdate_triggered()
{
auto updater = MMC->updateChecker();
- updater->checkForUpdate(true);
+ updater->checkForUpdate(MMC->settings()->get("UpdateChannel").toString(), true);
}
template <typename T>
diff --git a/gui/pages/LegacyJarModPage.cpp b/gui/pages/LegacyJarModPage.cpp
index 8eddf625..219e92ef 100644
--- a/gui/pages/LegacyJarModPage.cpp
+++ b/gui/pages/LegacyJarModPage.cpp
@@ -29,6 +29,7 @@
#include "logic/LegacyInstance.h"
#include "logic/forge/ForgeVersion.h"
#include "logic/forge/ForgeVersionList.h"
+#include "logic/Env.h"
#include "MultiMC.h"
LegacyJarModPage::LegacyJarModPage(LegacyInstance *inst, QWidget *parent)
@@ -109,7 +110,7 @@ void LegacyJarModPage::on_addForgeBtn_clicked()
std::dynamic_pointer_cast<ForgeVersion>(vselect.selectedVersion());
if (!forge)
return;
- auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename());
+ auto entry = Env::getInstance().metacache()->resolveEntry("minecraftforge", forge->filename());
if (entry->stale)
{
NetJob *fjob = new NetJob("Forge download");
diff --git a/gui/pages/global/AccountListPage.cpp b/gui/pages/global/AccountListPage.cpp
index dec7c6e0..2de77115 100644
--- a/gui/pages/global/AccountListPage.cpp
+++ b/gui/pages/global/AccountListPage.cpp
@@ -22,6 +22,7 @@
#include "logic/net/NetJob.h"
#include "logic/net/URLConstants.h"
+#include "logic/Env.h"
#include "gui/dialogs/EditAccountDialog.h"
#include "gui/dialogs/ProgressDialog.h"
@@ -129,7 +130,7 @@ void AccountListPage::addAccount(const QString &errMsg)
for (AccountProfile profile : account->profiles())
{
- auto meta = MMC->metacache()->resolveEntry("skins", profile.name + ".png");
+ auto meta = Env::getInstance().metacache()->resolveEntry("skins", profile.name + ".png");
auto action = CacheDownload::make(
QUrl("http://" + URLConstants::SKINS_BASE + profile.name + ".png"), meta);
job->addNetAction(action);
diff --git a/gui/pages/global/MinecraftPage.cpp b/gui/pages/global/MinecraftPage.cpp
index c2a015ad..5566542c 100644
--- a/gui/pages/global/MinecraftPage.cpp
+++ b/gui/pages/global/MinecraftPage.cpp
@@ -74,8 +74,6 @@ void MinecraftPage::on_maximizedCheckBox_clicked(bool checked)
void MinecraftPage::applySettings()
{
auto s = MMC->settings();
- // Minecraft version updates
- s->set("AutoUpdateMinecraftVersions", ui->autoupdateMinecraft->isChecked());
// Window Size
s->set("LaunchMaximized", ui->maximizedCheckBox->isChecked());
@@ -86,8 +84,6 @@ void MinecraftPage::applySettings()
void MinecraftPage::loadSettings()
{
auto s = MMC->settings();
- // Minecraft version updates
- ui->autoupdateMinecraft->setChecked(s->get("AutoUpdateMinecraftVersions").toBool());
// Window Size
ui->maximizedCheckBox->setChecked(s->get("LaunchMaximized").toBool());
diff --git a/gui/pages/global/MinecraftPage.ui b/gui/pages/global/MinecraftPage.ui
index 9e7df224..825f6a56 100644
--- a/gui/pages/global/MinecraftPage.ui
+++ b/gui/pages/global/MinecraftPage.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>545</width>
- <height>270</height>
+ <height>195</height>
</rect>
</property>
<property name="sizePolicy">
@@ -50,22 +50,6 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
- <widget class="QGroupBox" name="groupBox_5">
- <property name="title">
- <string>Minecraft Version Updates</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_14">
- <item>
- <widget class="QCheckBox" name="autoupdateMinecraft">
- <property name="text">
- <string>Automatically update to latest version revision</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item>
<widget class="QGroupBox" name="windowSizeGroupBox">
<property name="title">
<string>Window Size</string>
@@ -155,7 +139,6 @@
</widget>
<tabstops>
<tabstop>tabWidget</tabstop>
- <tabstop>autoupdateMinecraft</tabstop>
<tabstop>maximizedCheckBox</tabstop>
<tabstop>windowWidthSpinBox</tabstop>
<tabstop>windowHeightSpinBox</tabstop>
diff --git a/logic/Env.cpp b/logic/Env.cpp
new file mode 100644
index 00000000..de93ded3
--- /dev/null
+++ b/logic/Env.cpp
@@ -0,0 +1,104 @@
+#include "Env.h"
+#include "logic/net/HttpMetaCache.h"
+#include <QDir>
+#include <QNetworkProxy>
+#include <QNetworkAccessManager>
+#include "logger/QsLog.h"
+#include "MultiMC.h"
+
+Env::Env()
+{
+ // null
+}
+
+void Env::destroy()
+{
+ m_metacache.reset();
+ m_qnam.reset();
+}
+
+Env& Env::Env::getInstance()
+{
+ static Env instance;
+ return instance;
+}
+
+void Env::initHttpMetaCache(QString rootPath, QString staticDataPath)
+{
+ m_metacache.reset(new HttpMetaCache("metacache"));
+ m_metacache->addBase("asset_indexes", QDir("assets/indexes").absolutePath());
+ m_metacache->addBase("asset_objects", QDir("assets/objects").absolutePath());
+ m_metacache->addBase("versions", QDir("versions").absolutePath());
+ m_metacache->addBase("libraries", QDir("libraries").absolutePath());
+ m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
+ m_metacache->addBase("fmllibs", QDir("mods/minecraftforge/libs").absolutePath());
+ m_metacache->addBase("liteloader", QDir("mods/liteloader").absolutePath());
+ m_metacache->addBase("general", QDir("cache").absolutePath());
+ m_metacache->addBase("skins", QDir("accounts/skins").absolutePath());
+ m_metacache->addBase("root", QDir(rootPath).absolutePath());
+ m_metacache->addBase("translations", QDir(staticDataPath + "/translations").absolutePath());
+ m_metacache->Load();
+}
+
+void Env::updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password)
+{
+ // Set the application proxy settings.
+ if (proxyTypeStr == "SOCKS5")
+ {
+ QNetworkProxy::setApplicationProxy(
+ QNetworkProxy(QNetworkProxy::Socks5Proxy, addr, port, user, password));
+ }
+ else if (proxyTypeStr == "HTTP")
+ {
+ QNetworkProxy::setApplicationProxy(
+ QNetworkProxy(QNetworkProxy::HttpProxy, addr, port, user, password));
+ }
+ else if (proxyTypeStr == "None")
+ {
+ // If we have no proxy set, set no proxy and return.
+ QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::NoProxy));
+ }
+ else
+ {
+ // If we have "Default" selected, set Qt to use the system proxy settings.
+ QNetworkProxyFactory::setUseSystemConfiguration(true);
+ }
+
+ QLOG_INFO() << "Detecting proxy settings...";
+ QNetworkProxy proxy = QNetworkProxy::applicationProxy();
+ if (m_qnam.get())
+ m_qnam->setProxy(proxy);
+ QString proxyDesc;
+ if (proxy.type() == QNetworkProxy::NoProxy)
+ {
+ QLOG_INFO() << "Using no proxy is an option!";
+ return;
+ }
+ switch (proxy.type())
+ {
+ case QNetworkProxy::DefaultProxy:
+ proxyDesc = "Default proxy: ";
+ break;
+ case QNetworkProxy::Socks5Proxy:
+ proxyDesc = "Socks5 proxy: ";
+ break;
+ case QNetworkProxy::HttpProxy:
+ proxyDesc = "HTTP proxy: ";
+ break;
+ case QNetworkProxy::HttpCachingProxy:
+ proxyDesc = "HTTP caching: ";
+ break;
+ case QNetworkProxy::FtpCachingProxy:
+ proxyDesc = "FTP caching: ";
+ break;
+ default:
+ proxyDesc = "DERP proxy: ";
+ break;
+ }
+ proxyDesc += QString("%3@%1:%2 pass %4")
+ .arg(proxy.hostName())
+ .arg(proxy.port())
+ .arg(proxy.user())
+ .arg(proxy.password());
+ QLOG_INFO() << proxyDesc;
+}
diff --git a/logic/Env.h b/logic/Env.h
new file mode 100644
index 00000000..523c51f0
--- /dev/null
+++ b/logic/Env.h
@@ -0,0 +1,44 @@
+#pragma once
+
+#include <memory>
+#include <QString>
+
+class QNetworkAccessManager;
+class HttpMetaCache;
+
+#if defined(ENV)
+ #undef ENV
+#endif
+#define ENV (Env::getInstance())
+
+class Env
+{
+ friend class MultiMC;
+private:
+ Env();
+public:
+ static Env& getInstance();
+
+ // call when Qt stuff is being torn down
+ void destroy();
+
+ std::shared_ptr<QNetworkAccessManager> qnam()
+ {
+ return m_qnam;
+ }
+
+ std::shared_ptr<HttpMetaCache> metacache()
+ {
+ return m_metacache;
+ }
+
+ /// init the cache. FIXME: possible future hook point
+ void initHttpMetaCache(QString rootPath, QString staticDataPath);
+
+ /// Updates the application proxy settings from the settings object.
+ void updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password);
+
+protected:
+ std::shared_ptr<QNetworkAccessManager> m_qnam;
+ std::shared_ptr<HttpMetaCache> m_metacache;