47
47
#include < minecraft/auth/AccountList.h>
48
48
#include " icons/IconList.h"
49
49
#include " net/HttpMetaCache.h"
50
- #include " Env.h"
51
50
52
51
#include " java/JavaUtils.h"
53
52
62
61
#include " settings/Setting.h"
63
62
64
63
#include " translations/TranslationsModel.h"
64
+ #include " meta/Index.h"
65
65
66
66
#include < Commandline.h>
67
67
#include < FileSystem.h>
@@ -520,10 +520,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
520
520
FS::updateTimestamp (m_rootPath);
521
521
#endif
522
522
523
- #ifdef MULTIMC_JARS_LOCATION
524
- ENV->setJarsPath ( TOSTRING (MULTIMC_JARS_LOCATION) );
525
- #endif
526
-
527
523
qDebug () << BuildConfig.LAUNCHER_DISPLAYNAME << " , (c) 2013-2021 " << BuildConfig.LAUNCHER_COPYRIGHT ;
528
524
qDebug () << " Version : " << BuildConfig.printableVersionString ();
529
525
qDebug () << " Git commit : " << BuildConfig.GIT_COMMIT ;
@@ -730,6 +726,18 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
730
726
QAccessible::installFactory (groupViewAccessibleFactory);
731
727
#endif /* !QT_NO_ACCESSIBILITY */
732
728
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
+
733
741
// load translations
734
742
{
735
743
m_translations.reset (new TranslationsModel (" translations" ));
@@ -745,7 +753,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
745
753
auto platform = getIdealPlatform (BuildConfig.BUILD_PLATFORM );
746
754
auto channelUrl = BuildConfig.UPDATER_BASE + platform + " /channels.json" ;
747
755
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 ));
749
757
qDebug () << " <> Updater started." ;
750
758
}
751
759
@@ -764,7 +772,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
764
772
{
765
773
m_icons->directoryChanged (value.toString ());
766
774
});
767
- ENV->registerIconList (m_icons);
768
775
qDebug () << " <> Instance icons intialized." ;
769
776
}
770
777
@@ -821,21 +828,28 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
821
828
822
829
// init the http meta cache
823
830
{
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 ();
825
850
qDebug () << " <> Cache initialized." ;
826
851
}
827
852
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
-
839
853
// now we have network, download translation updates
840
854
m_translations->downloadIndex ();
841
855
@@ -894,7 +908,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
894
908
m_analytics = new GAnalytics (BuildConfig.ANALYTICS_ID , clientID, analyticsVersion, this );
895
909
m_analytics->setLogLevel (GAnalytics::Debug);
896
910
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 ());
898
913
899
914
if (m_settings->get (" AnalyticsSeen" ).toInt () < m_analytics->version ())
900
915
{
@@ -1043,9 +1058,6 @@ void Application::showFatalErrorMessage(const QString& title, const QString& con
1043
1058
1044
1059
Application::~Application ()
1045
1060
{
1046
- // kill the other globals.
1047
- Env::dispose ();
1048
-
1049
1061
// Shut down logger by setting the logger function to nothing
1050
1062
qInstallMessageHandler (nullptr );
1051
1063
@@ -1535,3 +1547,92 @@ void Application::on_windowClose()
1535
1547
QString Application::msaClientId () const {
1536
1548
return Secrets::getMSAClientID (' -' );
1537
1549
}
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
+ }
0 commit comments