Skip to content

Commit 69213b1

Browse files
committed
NOISSUE continue refactoring things to make tests pass
1 parent c2c56a2 commit 69213b1

File tree

103 files changed

+633
-772
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+633
-772
lines changed

launcher/Application.cpp

Lines changed: 124 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include <minecraft/auth/AccountList.h>
4848
#include "icons/IconList.h"
4949
#include "net/HttpMetaCache.h"
50-
#include "Env.h"
5150

5251
#include "java/JavaUtils.h"
5352

@@ -62,6 +61,7 @@
6261
#include "settings/Setting.h"
6362

6463
#include "translations/TranslationsModel.h"
64+
#include "meta/Index.h"
6565

6666
#include <Commandline.h>
6767
#include <FileSystem.h>
@@ -520,10 +520,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
520520
FS::updateTimestamp(m_rootPath);
521521
#endif
522522

523-
#ifdef MULTIMC_JARS_LOCATION
524-
ENV->setJarsPath( TOSTRING(MULTIMC_JARS_LOCATION) );
525-
#endif
526-
527523
qDebug() << BuildConfig.LAUNCHER_DISPLAYNAME << ", (c) 2013-2021 " << BuildConfig.LAUNCHER_COPYRIGHT;
528524
qDebug() << "Version : " << BuildConfig.printableVersionString();
529525
qDebug() << "Git commit : " << BuildConfig.GIT_COMMIT;
@@ -730,6 +726,18 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
730726
QAccessible::installFactory(groupViewAccessibleFactory);
731727
#endif /* !QT_NO_ACCESSIBILITY */
732728

729+
// initialize network access and proxy setup
730+
{
731+
m_network = new QNetworkAccessManager();
732+
QString proxyTypeStr = settings()->get("ProxyType").toString();
733+
QString addr = settings()->get("ProxyAddr").toString();
734+
int port = settings()->get("ProxyPort").value<qint16>();
735+
QString user = settings()->get("ProxyUser").toString();
736+
QString pass = settings()->get("ProxyPass").toString();
737+
updateProxySettings(proxyTypeStr, addr, port, user, pass);
738+
qDebug() << "<> Network done.";
739+
}
740+
733741
// load translations
734742
{
735743
m_translations.reset(new TranslationsModel("translations"));
@@ -745,7 +753,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
745753
auto platform = getIdealPlatform(BuildConfig.BUILD_PLATFORM);
746754
auto channelUrl = BuildConfig.UPDATER_BASE + platform + "/channels.json";
747755
qDebug() << "Initializing updater with platform: " << platform << " -- " << channelUrl;
748-
m_updateChecker.reset(new UpdateChecker(channelUrl, BuildConfig.VERSION_CHANNEL, BuildConfig.VERSION_BUILD));
756+
m_updateChecker.reset(new UpdateChecker(m_network, channelUrl, BuildConfig.VERSION_CHANNEL, BuildConfig.VERSION_BUILD));
749757
qDebug() << "<> Updater started.";
750758
}
751759

@@ -764,7 +772,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
764772
{
765773
m_icons->directoryChanged(value.toString());
766774
});
767-
ENV->registerIconList(m_icons);
768775
qDebug() << "<> Instance icons intialized.";
769776
}
770777

@@ -821,21 +828,28 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
821828

822829
// init the http meta cache
823830
{
824-
ENV->initHttpMetaCache();
831+
m_metacache.reset(new HttpMetaCache("metacache"));
832+
m_metacache->addBase("asset_indexes", QDir("assets/indexes").absolutePath());
833+
m_metacache->addBase("asset_objects", QDir("assets/objects").absolutePath());
834+
m_metacache->addBase("versions", QDir("versions").absolutePath());
835+
m_metacache->addBase("libraries", QDir("libraries").absolutePath());
836+
m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
837+
m_metacache->addBase("fmllibs", QDir("mods/minecraftforge/libs").absolutePath());
838+
m_metacache->addBase("liteloader", QDir("mods/liteloader").absolutePath());
839+
m_metacache->addBase("general", QDir("cache").absolutePath());
840+
m_metacache->addBase("ATLauncherPacks", QDir("cache/ATLauncherPacks").absolutePath());
841+
m_metacache->addBase("FTBPacks", QDir("cache/FTBPacks").absolutePath());
842+
m_metacache->addBase("ModpacksCHPacks", QDir("cache/ModpacksCHPacks").absolutePath());
843+
m_metacache->addBase("TechnicPacks", QDir("cache/TechnicPacks").absolutePath());
844+
m_metacache->addBase("FlamePacks", QDir("cache/FlamePacks").absolutePath());
845+
m_metacache->addBase("root", QDir::currentPath());
846+
m_metacache->addBase("translations", QDir("translations").absolutePath());
847+
m_metacache->addBase("icons", QDir("cache/icons").absolutePath());
848+
m_metacache->addBase("meta", QDir("meta").absolutePath());
849+
m_metacache->Load();
825850
qDebug() << "<> Cache initialized.";
826851
}
827852

828-
// init proxy settings
829-
{
830-
QString proxyTypeStr = settings()->get("ProxyType").toString();
831-
QString addr = settings()->get("ProxyAddr").toString();
832-
int port = settings()->get("ProxyPort").value<qint16>();
833-
QString user = settings()->get("ProxyUser").toString();
834-
QString pass = settings()->get("ProxyPass").toString();
835-
ENV->updateProxySettings(proxyTypeStr, addr, port, user, pass);
836-
qDebug() << "<> Proxy settings done.";
837-
}
838-
839853
// now we have network, download translation updates
840854
m_translations->downloadIndex();
841855

@@ -894,7 +908,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
894908
m_analytics = new GAnalytics(BuildConfig.ANALYTICS_ID, clientID, analyticsVersion, this);
895909
m_analytics->setLogLevel(GAnalytics::Debug);
896910
m_analytics->setAnonymizeIPs(true);
897-
m_analytics->setNetworkAccessManager(&ENV->network());
911+
// FIXME: the ganalytics library has no idea about our fancy shared pointers...
912+
m_analytics->setNetworkAccessManager(network().get());
898913

899914
if(m_settings->get("AnalyticsSeen").toInt() < m_analytics->version())
900915
{
@@ -1043,9 +1058,6 @@ void Application::showFatalErrorMessage(const QString& title, const QString& con
10431058

10441059
Application::~Application()
10451060
{
1046-
// kill the other globals.
1047-
Env::dispose();
1048-
10491061
// Shut down logger by setting the logger function to nothing
10501062
qInstallMessageHandler(nullptr);
10511063

@@ -1535,3 +1547,92 @@ void Application::on_windowClose()
15351547
QString Application::msaClientId() const {
15361548
return Secrets::getMSAClientID('-');
15371549
}
1550+
1551+
void Application::updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password)
1552+
{
1553+
// Set the application proxy settings.
1554+
if (proxyTypeStr == "SOCKS5")
1555+
{
1556+
QNetworkProxy::setApplicationProxy(
1557+
QNetworkProxy(QNetworkProxy::Socks5Proxy, addr, port, user, password));
1558+
}
1559+
else if (proxyTypeStr == "HTTP")
1560+
{
1561+
QNetworkProxy::setApplicationProxy(
1562+
QNetworkProxy(QNetworkProxy::HttpProxy, addr, port, user, password));
1563+
}
1564+
else if (proxyTypeStr == "None")
1565+
{
1566+
// If we have no proxy set, set no proxy and return.
1567+
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::NoProxy));
1568+
}
1569+
else
1570+
{
1571+
// If we have "Default" selected, set Qt to use the system proxy settings.
1572+
QNetworkProxyFactory::setUseSystemConfiguration(true);
1573+
}
1574+
1575+
qDebug() << "Detecting proxy settings...";
1576+
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
1577+
m_network->setProxy(proxy);
1578+
1579+
QString proxyDesc;
1580+
if (proxy.type() == QNetworkProxy::NoProxy)
1581+
{
1582+
qDebug() << "Using no proxy is an option!";
1583+
return;
1584+
}
1585+
switch (proxy.type())
1586+
{
1587+
case QNetworkProxy::DefaultProxy:
1588+
proxyDesc = "Default proxy: ";
1589+
break;
1590+
case QNetworkProxy::Socks5Proxy:
1591+
proxyDesc = "Socks5 proxy: ";
1592+
break;
1593+
case QNetworkProxy::HttpProxy:
1594+
proxyDesc = "HTTP proxy: ";
1595+
break;
1596+
case QNetworkProxy::HttpCachingProxy:
1597+
proxyDesc = "HTTP caching: ";
1598+
break;
1599+
case QNetworkProxy::FtpCachingProxy:
1600+
proxyDesc = "FTP caching: ";
1601+
break;
1602+
default:
1603+
proxyDesc = "DERP proxy: ";
1604+
break;
1605+
}
1606+
proxyDesc += QString("%1:%2")
1607+
.arg(proxy.hostName())
1608+
.arg(proxy.port());
1609+
qDebug() << proxyDesc;
1610+
}
1611+
1612+
shared_qobject_ptr< HttpMetaCache > Application::metacache()
1613+
{
1614+
return m_metacache;
1615+
}
1616+
1617+
shared_qobject_ptr<QNetworkAccessManager> Application::network()
1618+
{
1619+
return m_network;
1620+
}
1621+
1622+
shared_qobject_ptr<Meta::Index> Application::metadataIndex()
1623+
{
1624+
if (!m_metadataIndex)
1625+
{
1626+
m_metadataIndex.reset(new Meta::Index());
1627+
}
1628+
return m_metadataIndex;
1629+
}
1630+
1631+
QString Application::getJarsPath()
1632+
{
1633+
if(m_jarsPath.isEmpty())
1634+
{
1635+
return FS::PathCombine(QCoreApplication::applicationDirPath(), "jars");
1636+
}
1637+
return m_jarsPath;
1638+
}

launcher/Application.h

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class LocalPeer;
1818
class InstanceWindow;
1919
class MainWindow;
2020
class SetupWizard;
21-
class FolderInstanceProvider;
2221
class GenericPageProvider;
2322
class QFile;
2423
class HttpMetaCache;
@@ -36,6 +35,10 @@ class ITheme;
3635
class MCEditTool;
3736
class GAnalytics;
3837

38+
namespace Meta {
39+
class Index;
40+
}
41+
3942
#if defined(APPLICATION)
4043
#undef APPLICATION
4144
#endif
@@ -46,8 +49,7 @@ class Application : public QApplication
4649
// friends for the purpose of limiting access to deprecated stuff
4750
Q_OBJECT
4851
public:
49-
enum Status
50-
{
52+
enum Status {
5153
StartingUp,
5254
Failed,
5355
Succeeded,
@@ -58,18 +60,15 @@ class Application : public QApplication
5860
Application(int &argc, char **argv);
5961
virtual ~Application();
6062

61-
GAnalytics *analytics() const
62-
{
63+
GAnalytics *analytics() const {
6364
return m_analytics;
6465
}
6566

66-
std::shared_ptr<SettingsObject> settings() const
67-
{
67+
std::shared_ptr<SettingsObject> settings() const {
6868
return m_settings;
6969
}
7070

71-
qint64 timeSinceStart() const
72-
{
71+
qint64 timeSinceStart() const {
7372
return startTime.msecsTo(QDateTime::currentDateTime());
7473
}
7574

@@ -81,56 +80,52 @@ class Application : public QApplication
8180

8281
void setApplicationTheme(const QString& name, bool initial);
8382

84-
// DownloadUpdateTask
85-
std::shared_ptr<UpdateChecker> updateChecker()
86-
{
83+
shared_qobject_ptr<UpdateChecker> updateChecker() {
8784
return m_updateChecker;
8885
}
8986

9087
std::shared_ptr<TranslationsModel> translations();
9188

9289
std::shared_ptr<JavaInstallList> javalist();
9390

94-
std::shared_ptr<InstanceList> instances() const
95-
{
91+
std::shared_ptr<InstanceList> instances() const {
9692
return m_instances;
9793
}
9894

99-
FolderInstanceProvider * folderProvider() const
100-
{
101-
return m_instanceFolder;
102-
}
103-
104-
std::shared_ptr<IconList> icons() const
105-
{
95+
std::shared_ptr<IconList> icons() const {
10696
return m_icons;
10797
}
10898

109-
MCEditTool *mcedit() const
110-
{
99+
MCEditTool *mcedit() const {
111100
return m_mcedit.get();
112101
}
113102

114-
shared_qobject_ptr<AccountList> accounts() const
115-
{
103+
shared_qobject_ptr<AccountList> accounts() const {
116104
return m_accounts;
117105
}
118106

119107
QString msaClientId() const;
120108

121-
Status status() const
122-
{
109+
Status status() const {
123110
return m_status;
124111
}
125112

126-
const QMap<QString, std::shared_ptr<BaseProfilerFactory>> &profilers() const
127-
{
113+
const QMap<QString, std::shared_ptr<BaseProfilerFactory>> &profilers() const {
128114
return m_profilers;
129115
}
130116

117+
void updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password);
118+
119+
shared_qobject_ptr<QNetworkAccessManager> network();
120+
121+
shared_qobject_ptr<HttpMetaCache> metacache();
122+
123+
shared_qobject_ptr<Meta::Index> metadataIndex();
124+
125+
QString getJarsPath();
126+
131127
/// this is the root of the 'installation'. Used for automatic updates
132-
const QString &root()
133-
{
128+
const QString &root() {
134129
return m_rootPath;
135130
}
136131

@@ -155,11 +150,11 @@ class Application : public QApplication
155150

156151
public slots:
157152
bool launch(
158-
InstancePtr instance,
159-
bool online = true,
160-
BaseProfilerFactory *profiler = nullptr,
161-
MinecraftServerTargetPtr serverToJoin = nullptr,
162-
MinecraftAccountPtr accountToUse = nullptr
153+
InstancePtr instance,
154+
bool online = true,
155+
BaseProfilerFactory *profiler = nullptr,
156+
MinecraftServerTargetPtr serverToJoin = nullptr,
157+
MinecraftAccountPtr accountToUse = nullptr
163158
);
164159
bool kill(InstancePtr instance);
165160

@@ -186,17 +181,24 @@ private slots:
186181
private:
187182
QDateTime startTime;
188183

184+
shared_qobject_ptr<QNetworkAccessManager> m_network;
185+
186+
shared_qobject_ptr<UpdateChecker> m_updateChecker;
187+
shared_qobject_ptr<AccountList> m_accounts;
188+
189+
shared_qobject_ptr<HttpMetaCache> m_metacache;
190+
shared_qobject_ptr<Meta::Index> m_metadataIndex;
191+
189192
std::shared_ptr<SettingsObject> m_settings;
190193
std::shared_ptr<InstanceList> m_instances;
191-
FolderInstanceProvider * m_instanceFolder = nullptr;
192194
std::shared_ptr<IconList> m_icons;
193-
std::shared_ptr<UpdateChecker> m_updateChecker;
194-
shared_qobject_ptr<AccountList> m_accounts;
195195
std::shared_ptr<JavaInstallList> m_javalist;
196196
std::shared_ptr<TranslationsModel> m_translations;
197197
std::shared_ptr<GenericPageProvider> m_globalSettingsProvider;
198198
std::map<QString, std::unique_ptr<ITheme>> m_themes;
199199
std::unique_ptr<MCEditTool> m_mcedit;
200+
QString m_jarsPath;
201+
QSet<QString> m_features;
200202

201203
QMap<QString, std::shared_ptr<BaseProfilerFactory>> m_profilers;
202204

@@ -209,8 +211,7 @@ private slots:
209211
#endif
210212

211213
// FIXME: attach to instances instead.
212-
struct InstanceXtras
213-
{
214+
struct InstanceXtras {
214215
InstanceWindow * window = nullptr;
215216
shared_qobject_ptr<LaunchController> controller;
216217
};

0 commit comments

Comments
 (0)