NOISSUE continue refactoring things to make tests pass
This commit is contained in:
@ -47,7 +47,6 @@
|
||||
#include <minecraft/auth/AccountList.h>
|
||||
#include "icons/IconList.h"
|
||||
#include "net/HttpMetaCache.h"
|
||||
#include "Env.h"
|
||||
|
||||
#include "java/JavaUtils.h"
|
||||
|
||||
@ -62,6 +61,7 @@
|
||||
#include "settings/Setting.h"
|
||||
|
||||
#include "translations/TranslationsModel.h"
|
||||
#include "meta/Index.h"
|
||||
|
||||
#include <Commandline.h>
|
||||
#include <FileSystem.h>
|
||||
@ -520,10 +520,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
FS::updateTimestamp(m_rootPath);
|
||||
#endif
|
||||
|
||||
#ifdef MULTIMC_JARS_LOCATION
|
||||
ENV->setJarsPath( TOSTRING(MULTIMC_JARS_LOCATION) );
|
||||
#endif
|
||||
|
||||
qDebug() << BuildConfig.LAUNCHER_DISPLAYNAME << ", (c) 2013-2021 " << BuildConfig.LAUNCHER_COPYRIGHT;
|
||||
qDebug() << "Version : " << BuildConfig.printableVersionString();
|
||||
qDebug() << "Git commit : " << BuildConfig.GIT_COMMIT;
|
||||
@ -730,6 +726,18 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
QAccessible::installFactory(groupViewAccessibleFactory);
|
||||
#endif /* !QT_NO_ACCESSIBILITY */
|
||||
|
||||
// initialize network access and proxy setup
|
||||
{
|
||||
m_network = new QNetworkAccessManager();
|
||||
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();
|
||||
updateProxySettings(proxyTypeStr, addr, port, user, pass);
|
||||
qDebug() << "<> Network done.";
|
||||
}
|
||||
|
||||
// load translations
|
||||
{
|
||||
m_translations.reset(new TranslationsModel("translations"));
|
||||
@ -745,7 +753,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
auto platform = getIdealPlatform(BuildConfig.BUILD_PLATFORM);
|
||||
auto channelUrl = BuildConfig.UPDATER_BASE + platform + "/channels.json";
|
||||
qDebug() << "Initializing updater with platform: " << platform << " -- " << channelUrl;
|
||||
m_updateChecker.reset(new UpdateChecker(channelUrl, BuildConfig.VERSION_CHANNEL, BuildConfig.VERSION_BUILD));
|
||||
m_updateChecker.reset(new UpdateChecker(m_network, channelUrl, BuildConfig.VERSION_CHANNEL, BuildConfig.VERSION_BUILD));
|
||||
qDebug() << "<> Updater started.";
|
||||
}
|
||||
|
||||
@ -764,7 +772,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
{
|
||||
m_icons->directoryChanged(value.toString());
|
||||
});
|
||||
ENV->registerIconList(m_icons);
|
||||
qDebug() << "<> Instance icons intialized.";
|
||||
}
|
||||
|
||||
@ -821,21 +828,28 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
|
||||
// init the http meta cache
|
||||
{
|
||||
ENV->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("ATLauncherPacks", QDir("cache/ATLauncherPacks").absolutePath());
|
||||
m_metacache->addBase("FTBPacks", QDir("cache/FTBPacks").absolutePath());
|
||||
m_metacache->addBase("ModpacksCHPacks", QDir("cache/ModpacksCHPacks").absolutePath());
|
||||
m_metacache->addBase("TechnicPacks", QDir("cache/TechnicPacks").absolutePath());
|
||||
m_metacache->addBase("FlamePacks", QDir("cache/FlamePacks").absolutePath());
|
||||
m_metacache->addBase("root", QDir::currentPath());
|
||||
m_metacache->addBase("translations", QDir("translations").absolutePath());
|
||||
m_metacache->addBase("icons", QDir("cache/icons").absolutePath());
|
||||
m_metacache->addBase("meta", QDir("meta").absolutePath());
|
||||
m_metacache->Load();
|
||||
qDebug() << "<> Cache initialized.";
|
||||
}
|
||||
|
||||
// init proxy settings
|
||||
{
|
||||
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);
|
||||
qDebug() << "<> Proxy settings done.";
|
||||
}
|
||||
|
||||
// now we have network, download translation updates
|
||||
m_translations->downloadIndex();
|
||||
|
||||
@ -894,7 +908,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
m_analytics = new GAnalytics(BuildConfig.ANALYTICS_ID, clientID, analyticsVersion, this);
|
||||
m_analytics->setLogLevel(GAnalytics::Debug);
|
||||
m_analytics->setAnonymizeIPs(true);
|
||||
m_analytics->setNetworkAccessManager(&ENV->network());
|
||||
// FIXME: the ganalytics library has no idea about our fancy shared pointers...
|
||||
m_analytics->setNetworkAccessManager(network().get());
|
||||
|
||||
if(m_settings->get("AnalyticsSeen").toInt() < m_analytics->version())
|
||||
{
|
||||
@ -1043,9 +1058,6 @@ void Application::showFatalErrorMessage(const QString& title, const QString& con
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
// kill the other globals.
|
||||
Env::dispose();
|
||||
|
||||
// Shut down logger by setting the logger function to nothing
|
||||
qInstallMessageHandler(nullptr);
|
||||
|
||||
@ -1535,3 +1547,92 @@ void Application::on_windowClose()
|
||||
QString Application::msaClientId() const {
|
||||
return Secrets::getMSAClientID('-');
|
||||
}
|
||||
|
||||
void Application::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);
|
||||
}
|
||||
|
||||
qDebug() << "Detecting proxy settings...";
|
||||
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
|
||||
m_network->setProxy(proxy);
|
||||
|
||||
QString proxyDesc;
|
||||
if (proxy.type() == QNetworkProxy::NoProxy)
|
||||
{
|
||||
qDebug() << "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("%1:%2")
|
||||
.arg(proxy.hostName())
|
||||
.arg(proxy.port());
|
||||
qDebug() << proxyDesc;
|
||||
}
|
||||
|
||||
shared_qobject_ptr< HttpMetaCache > Application::metacache()
|
||||
{
|
||||
return m_metacache;
|
||||
}
|
||||
|
||||
shared_qobject_ptr<QNetworkAccessManager> Application::network()
|
||||
{
|
||||
return m_network;
|
||||
}
|
||||
|
||||
shared_qobject_ptr<Meta::Index> Application::metadataIndex()
|
||||
{
|
||||
if (!m_metadataIndex)
|
||||
{
|
||||
m_metadataIndex.reset(new Meta::Index());
|
||||
}
|
||||
return m_metadataIndex;
|
||||
}
|
||||
|
||||
QString Application::getJarsPath()
|
||||
{
|
||||
if(m_jarsPath.isEmpty())
|
||||
{
|
||||
return FS::PathCombine(QCoreApplication::applicationDirPath(), "jars");
|
||||
}
|
||||
return m_jarsPath;
|
||||
}
|
||||
|
Reference in New Issue
Block a user