From 69213b1206e97f7d4db4270a4b3b0af41dc9e6fc Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 21 Nov 2021 23:21:12 +0100 Subject: NOISSUE continue refactoring things to make tests pass --- launcher/Application.cpp | 147 ++++++++++++--- launcher/Application.h | 83 ++++---- launcher/CMakeLists.txt | 6 - launcher/Env.cpp | 210 --------------------- launcher/Env.h | 63 ------- launcher/InstanceImportTask.cpp | 17 +- launcher/InstanceImportTask.h | 2 +- launcher/InstancePageProvider.h | 2 - launcher/MainWindow.cpp | 6 +- launcher/SkinUtils.cpp | 4 +- launcher/dialogs/AboutDialog.cpp | 2 +- launcher/dialogs/AboutDialog.h | 2 +- launcher/dialogs/UpdateDialog.cpp | 2 +- launcher/dialogs/UpdateDialog.h | 2 +- launcher/icons/IIconList.cpp | 7 - launcher/icons/IIconList.h | 25 --- launcher/icons/IconList.h | 23 +-- launcher/icons/MMCIcon.h | 10 +- launcher/java/JavaChecker.cpp | 12 +- launcher/meta/BaseEntity.cpp | 18 +- launcher/meta/BaseEntity.h | 6 +- launcher/meta/Index_test.cpp | 7 - launcher/minecraft/AssetsUtils.cpp | 4 +- launcher/minecraft/AssetsUtils.h | 4 +- launcher/minecraft/Component.cpp | 18 +- launcher/minecraft/ComponentUpdateTask.cpp | 23 +-- launcher/minecraft/Library.cpp | 5 +- launcher/minecraft/Library.h | 2 +- launcher/minecraft/Library_test.cpp | 2 +- launcher/minecraft/MinecraftInstance.cpp | 36 ++-- launcher/minecraft/MinecraftUpdate.cpp | 1 - launcher/minecraft/PackProfile.cpp | 21 ++- launcher/minecraft/auth/flows/AuthContext.cpp | 4 +- launcher/minecraft/auth/flows/AuthRequest.cpp | 7 +- launcher/minecraft/auth/flows/Yggdrasil.cpp | 5 +- launcher/minecraft/launch/LauncherPartLaunch.cpp | 15 +- launcher/minecraft/services/CapeChange.cpp | 8 +- launcher/minecraft/services/SkinDelete.cpp | 6 +- launcher/minecraft/services/SkinUpload.cpp | 6 +- launcher/minecraft/update/AssetUpdateTask.cpp | 12 +- launcher/minecraft/update/AssetUpdateTask.h | 2 +- launcher/minecraft/update/FMLLibrariesTask.cpp | 14 +- launcher/minecraft/update/FMLLibrariesTask.h | 2 +- launcher/minecraft/update/LibrariesTask.cpp | 8 +- launcher/minecraft/update/LibrariesTask.h | 2 +- .../modplatform/atlauncher/ATLPackInstallTask.cpp | 39 ++-- .../modplatform/atlauncher/ATLPackInstallTask.h | 2 +- launcher/modplatform/flame/FileResolvingTask.cpp | 8 +- launcher/modplatform/flame/FileResolvingTask.h | 5 +- launcher/modplatform/legacy_ftb/PackFetchTask.cpp | 18 +- launcher/modplatform/legacy_ftb/PackFetchTask.h | 5 +- .../modplatform/legacy_ftb/PackInstallTask.cpp | 26 +-- launcher/modplatform/legacy_ftb/PackInstallTask.h | 7 +- .../modplatform/modpacksch/FTBPackInstallTask.cpp | 13 +- .../modplatform/modpacksch/FTBPackInstallTask.h | 2 +- .../technic/SingleZipPackInstallTask.cpp | 11 +- .../modplatform/technic/SingleZipPackInstallTask.h | 2 +- .../modplatform/technic/SolderPackInstallTask.cpp | 14 +- .../modplatform/technic/SolderPackInstallTask.h | 6 +- launcher/net/Download.cpp | 19 +- launcher/net/Download.h | 6 +- launcher/net/FileSink.cpp | 1 - launcher/net/HttpMetaCache.cpp | 1 - launcher/net/MetaCacheSink.cpp | 4 +- launcher/net/NetAction.h | 15 +- launcher/net/NetJob.cpp | 4 +- launcher/net/NetJob.h | 30 ++- launcher/net/PasteUpload.cpp | 7 +- launcher/news/NewsChecker.cpp | 5 +- launcher/news/NewsChecker.h | 6 +- launcher/notifications/NotificationChecker.cpp | 6 +- launcher/notifications/NotificationChecker.h | 2 +- launcher/pages/global/AccountListPage.cpp | 1 - launcher/pages/global/ProxyPage.cpp | 11 +- launcher/pages/instance/ScreenshotsPage.cpp | 6 +- launcher/pages/instance/VersionPage.cpp | 6 +- launcher/pages/modplatform/VanillaPage.cpp | 17 +- .../pages/modplatform/atlauncher/AtlListModel.cpp | 9 +- .../pages/modplatform/atlauncher/AtlListModel.h | 2 +- launcher/pages/modplatform/flame/FlameModel.cpp | 9 +- launcher/pages/modplatform/flame/FlameModel.h | 2 +- launcher/pages/modplatform/flame/FlamePage.cpp | 2 +- launcher/pages/modplatform/ftb/FtbListModel.cpp | 11 +- launcher/pages/modplatform/ftb/FtbListModel.h | 4 +- .../pages/modplatform/legacy_ftb/ListModel.cpp | 7 +- launcher/pages/modplatform/legacy_ftb/Page.cpp | 4 +- .../pages/modplatform/technic/TechnicModel.cpp | 9 +- launcher/pages/modplatform/technic/TechnicModel.h | 2 +- launcher/pages/modplatform/technic/TechnicPage.cpp | 4 +- launcher/screenshots/ImgurAlbumCreation.cpp | 10 +- launcher/screenshots/ImgurAlbumCreation.h | 11 +- launcher/screenshots/ImgurUpload.cpp | 10 +- launcher/screenshots/ImgurUpload.h | 22 +-- launcher/screenshots/Screenshot.h | 10 +- launcher/tasks/Task.h | 4 + launcher/translations/TranslationsModel.cpp | 26 +-- launcher/updater/DownloadTask.cpp | 14 +- launcher/updater/DownloadTask.h | 9 +- launcher/updater/GoUpdate.cpp | 2 +- launcher/updater/GoUpdate.h | 2 +- launcher/updater/UpdateChecker.cpp | 38 ++-- launcher/updater/UpdateChecker.h | 8 +- launcher/updater/UpdateChecker_test.cpp | 6 +- 103 files changed, 633 insertions(+), 772 deletions(-) delete mode 100644 launcher/Env.cpp delete mode 100644 launcher/Env.h delete mode 100644 launcher/icons/IIconList.cpp delete mode 100644 launcher/icons/IIconList.h diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 8789d096..7a266213 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -47,7 +47,6 @@ #include #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 #include @@ -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(); + 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(); - 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 Application::network() +{ + return m_network; +} + +shared_qobject_ptr 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; +} diff --git a/launcher/Application.h b/launcher/Application.h index ce22a2e8..1b2a2b60 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -18,7 +18,6 @@ class LocalPeer; class InstanceWindow; class MainWindow; class SetupWizard; -class FolderInstanceProvider; class GenericPageProvider; class QFile; class HttpMetaCache; @@ -36,6 +35,10 @@ class ITheme; class MCEditTool; class GAnalytics; +namespace Meta { + class Index; +} + #if defined(APPLICATION) #undef APPLICATION #endif @@ -46,8 +49,7 @@ class Application : public QApplication // friends for the purpose of limiting access to deprecated stuff Q_OBJECT public: - enum Status - { + enum Status { StartingUp, Failed, Succeeded, @@ -58,18 +60,15 @@ public: Application(int &argc, char **argv); virtual ~Application(); - GAnalytics *analytics() const - { + GAnalytics *analytics() const { return m_analytics; } - std::shared_ptr settings() const - { + std::shared_ptr settings() const { return m_settings; } - qint64 timeSinceStart() const - { + qint64 timeSinceStart() const { return startTime.msecsTo(QDateTime::currentDateTime()); } @@ -81,9 +80,7 @@ public: void setApplicationTheme(const QString& name, bool initial); - // DownloadUpdateTask - std::shared_ptr updateChecker() - { + shared_qobject_ptr updateChecker() { return m_updateChecker; } @@ -91,46 +88,44 @@ public: std::shared_ptr javalist(); - std::shared_ptr instances() const - { + std::shared_ptr instances() const { return m_instances; } - FolderInstanceProvider * folderProvider() const - { - return m_instanceFolder; - } - - std::shared_ptr icons() const - { + std::shared_ptr icons() const { return m_icons; } - MCEditTool *mcedit() const - { + MCEditTool *mcedit() const { return m_mcedit.get(); } - shared_qobject_ptr accounts() const - { + shared_qobject_ptr accounts() const { return m_accounts; } QString msaClientId() const; - Status status() const - { + Status status() const { return m_status; } - const QMap> &profilers() const - { + const QMap> &profilers() const { return m_profilers; } + void updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password); + + shared_qobject_ptr network(); + + shared_qobject_ptr metacache(); + + shared_qobject_ptr metadataIndex(); + + QString getJarsPath(); + /// this is the root of the 'installation'. Used for automatic updates - const QString &root() - { + const QString &root() { return m_rootPath; } @@ -155,11 +150,11 @@ signals: public slots: bool launch( - InstancePtr instance, - bool online = true, - BaseProfilerFactory *profiler = nullptr, - MinecraftServerTargetPtr serverToJoin = nullptr, - MinecraftAccountPtr accountToUse = nullptr + InstancePtr instance, + bool online = true, + BaseProfilerFactory *profiler = nullptr, + MinecraftServerTargetPtr serverToJoin = nullptr, + MinecraftAccountPtr accountToUse = nullptr ); bool kill(InstancePtr instance); @@ -186,17 +181,24 @@ private: private: QDateTime startTime; + shared_qobject_ptr m_network; + + shared_qobject_ptr m_updateChecker; + shared_qobject_ptr m_accounts; + + shared_qobject_ptr m_metacache; + shared_qobject_ptr m_metadataIndex; + std::shared_ptr m_settings; std::shared_ptr m_instances; - FolderInstanceProvider * m_instanceFolder = nullptr; std::shared_ptr m_icons; - std::shared_ptr m_updateChecker; - shared_qobject_ptr m_accounts; std::shared_ptr m_javalist; std::shared_ptr m_translations; std::shared_ptr m_globalSettingsProvider; std::map> m_themes; std::unique_ptr m_mcedit; + QString m_jarsPath; + QSet m_features; QMap> m_profilers; @@ -209,8 +211,7 @@ private: #endif // FIXME: attach to instances instead. - struct InstanceXtras - { + struct InstanceXtras { InstanceWindow * window = nullptr; shared_qobject_ptr controller; }; diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index f9a4327d..f2f42ab0 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -43,10 +43,6 @@ set(CORE_SOURCES # Prefix tree where node names are strings between separators SeparatorPrefixTree.h - # WARNING: globals live here - Env.h - Env.cpp - # String filters Filter.h Filter.cpp @@ -191,8 +187,6 @@ set(NEWS_SOURCES # Icon interface set(ICONS_SOURCES # Icons System and related code - icons/IIconList.h - icons/IIconList.cpp icons/IconUtils.h icons/IconUtils.cpp ) diff --git a/launcher/Env.cpp b/launcher/Env.cpp deleted file mode 100644 index 1ca82e4b..00000000 --- a/launcher/Env.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#include "Env.h" -#include "net/HttpMetaCache.h" -#include "BaseVersion.h" -#include "BaseVersionList.h" -#include -#include -#include -#include -#include -#include "tasks/Task.h" -#include "meta/Index.h" -#include "FileSystem.h" -#include - - -struct Env::Private -{ - QNetworkAccessManager m_qnam; - shared_qobject_ptr m_metacache; - std::shared_ptr m_iconlist; - shared_qobject_ptr m_metadataIndex; - QString m_jarsPath; - QSet m_features; -}; - -static Env * instance; - -/* - * The *NEW* global rat nest of an object. Handle with care. - */ - -Env::Env() -{ - d = new Private(); -} - -Env::~Env() -{ - delete d; -} - -Env* Env::Env::getInstance() -{ - if(!instance) - { - instance = new Env(); - } - return instance; -} - -void Env::dispose() -{ - delete instance; - instance = nullptr; -} - -shared_qobject_ptr< HttpMetaCache > Env::metacache() -{ - return d->m_metacache; -} - -QNetworkAccessManager& Env::network() const -{ - return d->m_qnam; -} - -std::shared_ptr Env::icons() -{ - return d->m_iconlist; -} - -void Env::registerIconList(std::shared_ptr iconlist) -{ - d->m_iconlist = iconlist; -} - -shared_qobject_ptr Env::metadataIndex() -{ - if (!d->m_metadataIndex) - { - d->m_metadataIndex.reset(new Meta::Index()); - } - return d->m_metadataIndex; -} - - -void Env::initHttpMetaCache() -{ - auto &m_metacache = d->m_metacache; - 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(); -} - -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); - } - - qDebug() << "Detecting proxy settings..."; - QNetworkProxy proxy = QNetworkProxy::applicationProxy(); - d->m_qnam.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; -} - -QString Env::getJarsPath() -{ - if(d->m_jarsPath.isEmpty()) - { - return FS::PathCombine(QCoreApplication::applicationDirPath(), "jars"); - } - return d->m_jarsPath; -} - -void Env::setJarsPath(const QString& path) -{ - d->m_jarsPath = path; -} - -void Env::enableFeature(const QString& featureName, bool state) -{ - if(state) - { - d->m_features.insert(featureName); - } - else - { - d->m_features.remove(featureName); - } -} - -bool Env::isFeatureEnabled(const QString& featureName) const -{ - return d->m_features.contains(featureName); -} - -void Env::getEnabledFeatures(QSet& features) const -{ - features = d->m_features; -} - -void Env::setEnabledFeatures(const QSet& features) const -{ - d->m_features = features; -} diff --git a/launcher/Env.h b/launcher/Env.h deleted file mode 100644 index cbf31732..00000000 --- a/launcher/Env.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include -#include "icons/IIconList.h" -#include -#include - -#include "QObjectPtr.h" - -class QNetworkAccessManager; -class HttpMetaCache; -class BaseVersionList; -class BaseVersion; - -namespace Meta -{ -class Index; -} - -#if defined(ENV) - #undef ENV -#endif -#define ENV (Env::getInstance()) - - -class Env -{ - friend class Application; -private: - struct Private; - Env(); - ~Env(); - static void dispose(); -public: - static Env* getInstance(); - - QNetworkAccessManager &network() const; - - shared_qobject_ptr metacache(); - - std::shared_ptr icons(); - - /// init the cache. FIXME: possible future hook point - void initHttpMetaCache(); - - /// Updates the application proxy settings from the settings object. - void updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password); - - void registerIconList(std::shared_ptr iconlist); - - shared_qobject_ptr metadataIndex(); - - QString getJarsPath(); - void setJarsPath(const QString & path); - - bool isFeatureEnabled(const QString & featureName) const; - void enableFeature(const QString & featureName, bool state = true); - void getEnabledFeatures(QSet & features) const; - void setEnabledFeatures(const QSet & features) const; - -protected: - Private * d; -}; diff --git a/launcher/InstanceImportTask.cpp b/launcher/InstanceImportTask.cpp index 77beda66..d0a63fe3 100644 --- a/launcher/InstanceImportTask.cpp +++ b/launcher/InstanceImportTask.cpp @@ -16,11 +16,10 @@ #include "InstanceImportTask.h" #include "BaseInstance.h" #include "FileSystem.h" -#include "Env.h" +#include "Application.h" #include "MMCZip.h" #include "NullInstance.h" #include "settings/INISettingsObject.h" -#include "icons/IIconList.h" #include "icons/IconUtils.h" #include @@ -33,6 +32,9 @@ #include #include "modplatform/technic/TechnicPackProcessor.h" +#include "icons/IconList.h" +#include "Application.h" + InstanceImportTask::InstanceImportTask(const QUrl sourceUrl) { m_sourceUrl = sourceUrl; @@ -51,7 +53,7 @@ void InstanceImportTask::executeTask() m_downloadRequired = true; const QString path = m_sourceUrl.host() + '/' + m_sourceUrl.path(); - auto entry = ENV->metacache()->resolveEntry("general", path); + auto entry = APPLICATION->metacache()->resolveEntry("general", path); entry->setStale(true); m_filesNetJob.reset(new NetJob(tr("Modpack download"))); m_filesNetJob->addNetAction(Net::Download::makeCached(m_sourceUrl, entry)); @@ -60,7 +62,7 @@ void InstanceImportTask::executeTask() connect(job, &NetJob::succeeded, this, &InstanceImportTask::downloadSucceeded); connect(job, &NetJob::progress, this, &InstanceImportTask::downloadProgressChanged); connect(job, &NetJob::failed, this, &InstanceImportTask::downloadFailed); - m_filesNetJob->start(); + m_filesNetJob->start(APPLICATION->network()); } } @@ -331,7 +333,7 @@ void InstanceImportTask::processFlame() FS::deletePath(jarmodsPath); } instance.setName(m_instName); - m_modIdResolver.reset(new Flame::FileResolvingTask(pack)); + m_modIdResolver = new Flame::FileResolvingTask(APPLICATION->network(), pack); connect(m_modIdResolver.get(), &Flame::FileResolvingTask::succeeded, [&]() { auto results = m_modIdResolver->getResults(); @@ -389,7 +391,7 @@ void InstanceImportTask::processFlame() setProgress(current, total); }); setStatus(tr("Downloading mods...")); - m_filesNetJob->start(); + m_filesNetJob->start(APPLICATION->network()); } ); connect(m_modIdResolver.get(), &Flame::FileResolvingTask::failed, [&](QString reason) @@ -418,7 +420,6 @@ void InstanceImportTask::processTechnic() void InstanceImportTask::processMultiMC() { - // FIXME: copy from FolderInstanceProvider!!! FIX IT!!! QString configPath = FS::PathCombine(m_stagingPath, "instance.cfg"); auto instanceSettings = std::make_shared(configPath); instanceSettings->registerSetting("InstanceType", "Legacy"); @@ -444,7 +445,7 @@ void InstanceImportTask::processMultiMC() if (!importIconPath.isNull() && QFile::exists(importIconPath)) { // import icon - auto iconList = ENV->icons(); + auto iconList = APPLICATION->icons(); if (iconList->iconFileExists(m_instIcon)) { iconList->deleteIcon(m_instIcon); diff --git a/launcher/InstanceImportTask.h b/launcher/InstanceImportTask.h index 72ae6851..a1990647 100644 --- a/launcher/InstanceImportTask.h +++ b/launcher/InstanceImportTask.h @@ -55,7 +55,7 @@ private slots: void extractAborted(); private: /* data */ - NetJobPtr m_filesNetJob; + NetJob::Ptr m_filesNetJob; shared_qobject_ptr m_modIdResolver; QUrl m_sourceUrl; QString m_archivePath; diff --git a/launcher/InstancePageProvider.h b/launcher/InstancePageProvider.h index d45b3f2e..555c07ed 100644 --- a/launcher/InstancePageProvider.h +++ b/launcher/InstancePageProvider.h @@ -19,8 +19,6 @@ #include "pages/instance/ServersPage.h" #include "pages/instance/GameOptionsPage.h" -#include "Env.h" - class InstancePageProvider : public QObject, public BasePageProvider { Q_OBJECT diff --git a/launcher/MainWindow.cpp b/launcher/MainWindow.cpp index f50f092e..cb02d9e0 100644 --- a/launcher/MainWindow.cpp +++ b/launcher/MainWindow.cpp @@ -47,7 +47,6 @@ #include #include -#include #include #include #include @@ -681,7 +680,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow // Add the news label to the news toolbar. { - m_newsChecker.reset(new NewsChecker(BuildConfig.NEWS_RSS_URL)); + m_newsChecker.reset(new NewsChecker(APPLICATION->network(), BuildConfig.NEWS_RSS_URL)); newsLabel = new QToolButton(); newsLabel->setIcon(APPLICATION->getThemedIcon("news")); newsLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); @@ -876,7 +875,6 @@ QMenu * MainWindow::createPopupMenu() void MainWindow::konamiTriggered() { - // ENV->enableFeature("NewModsPage"); qDebug() << "Super Secret Mode ACTIVATED!"; } @@ -1280,7 +1278,7 @@ void MainWindow::downloadUpdates(GoUpdate::Status status) { CustomMessageBox::selectable(this, tr("Error"), tr("Couldn't create folder for update downloads:\n%1").arg(dlPath), QMessageBox::Warning)->show(); } - GoUpdate::DownloadTask updateTask(status, dlPath, &updateDlg); + GoUpdate::DownloadTask updateTask(APPLICATION->network(), status, dlPath, &updateDlg); // If the task succeeds, install the updates. if (updateDlg.execWithTask(&updateTask)) { diff --git a/launcher/SkinUtils.cpp b/launcher/SkinUtils.cpp index 159116d8..1fe0c896 100644 --- a/launcher/SkinUtils.cpp +++ b/launcher/SkinUtils.cpp @@ -15,7 +15,7 @@ #include "SkinUtils.h" #include "net/HttpMetaCache.h" -#include "Env.h" +#include "Application.h" #include #include @@ -30,7 +30,7 @@ namespace SkinUtils */ QPixmap getFaceFromCache(QString username, int height, int width) { - QFile fskin(ENV->metacache()->resolveEntry("skins", username + ".png")->getFullPath()); + QFile fskin(APPLICATION->metacache()->resolveEntry("skins", username + ".png")->getFullPath()); if (fskin.exists()) { diff --git a/launcher/dialogs/AboutDialog.cpp b/launcher/dialogs/AboutDialog.cpp index 6921bf63..4f2e73e0 100644 --- a/launcher/dialogs/AboutDialog.cpp +++ b/launcher/dialogs/AboutDialog.cpp @@ -136,7 +136,7 @@ void AboutDialog::loadPatronList() netJob.reset(new NetJob("Patreon Patron List")); netJob->addNetAction(Net::Download::makeByteArray(QUrl("https://files.multimc.org/patrons.txt"), &dataSink)); connect(netJob.get(), &NetJob::succeeded, this, &AboutDialog::patronListLoaded); - netJob->start(); + netJob->start(APPLICATION->network()); } void AboutDialog::patronListLoaded() diff --git a/launcher/dialogs/AboutDialog.h b/launcher/dialogs/AboutDialog.h index c7621c37..cc4b8850 100644 --- a/launcher/dialogs/AboutDialog.h +++ b/launcher/dialogs/AboutDialog.h @@ -42,6 +42,6 @@ slots: private: Ui::AboutDialog *ui; - NetJobPtr netJob; + NetJob::Ptr netJob; QByteArray dataSink; }; diff --git a/launcher/dialogs/UpdateDialog.cpp b/launcher/dialogs/UpdateDialog.cpp index f3701546..4a6a1fdd 100644 --- a/launcher/dialogs/UpdateDialog.cpp +++ b/launcher/dialogs/UpdateDialog.cpp @@ -49,7 +49,7 @@ void UpdateDialog::loadChangelog() dljob->addNetAction(Net::Download::makeByteArray(QUrl(url), &changelogData)); connect(dljob.get(), &NetJob::succeeded, this, &UpdateDialog::changelogLoaded); connect(dljob.get(), &NetJob::failed, this, &UpdateDialog::changelogFailed); - dljob->start(); + dljob->start(APPLICATION->network()); } QString reprocessMarkdown(QByteArray markdown) diff --git a/launcher/dialogs/UpdateDialog.h b/launcher/dialogs/UpdateDialog.h index ae1799c3..07cbe09f 100644 --- a/launcher/dialogs/UpdateDialog.h +++ b/launcher/dialogs/UpdateDialog.h @@ -62,6 +62,6 @@ protected: private: Ui::UpdateDialog *ui; QByteArray changelogData; - NetJobPtr dljob; + NetJob::Ptr dljob; ChangelogType m_changelogType = CHANGELOG_MARKDOWN; }; diff --git a/launcher/icons/IIconList.cpp b/launcher/icons/IIconList.cpp deleted file mode 100644 index b3a8fb43..00000000 --- a/launcher/icons/IIconList.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "IIconList.h" - -// blargh -IIconList::~IIconList() -{ -} - diff --git a/launcher/icons/IIconList.h b/launcher/icons/IIconList.h deleted file mode 100644 index 15d7dd15..00000000 --- a/launcher/icons/IIconList.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -enum IconType : unsigned -{ - Builtin, - Transient, - FileBased, - ICONS_TOTAL, - ToBeDeleted -}; - -class IIconList -{ -public: - virtual ~IIconList(); - virtual bool addIcon(const QString &key, const QString &name, const QString &path, const IconType type) = 0; - virtual bool deleteIcon(const QString &key) = 0; - virtual void saveIcon(const QString &key, const QString &path, const char * format) const = 0; - virtual bool iconFileExists(const QString &key) const = 0; - virtual void installIcons(const QStringList &iconFiles) = 0; - virtual void installIcon(const QString &file, const QString &name) = 0; -}; diff --git a/launcher/icons/IconList.h b/launcher/icons/IconList.h index 70266ebb..ebbb52e2 100644 --- a/launcher/icons/IconList.h +++ b/launcher/icons/IconList.h @@ -21,14 +21,15 @@ #include #include #include + #include "MMCIcon.h" #include "settings/Setting.h" -#include "Env.h" // there is a global icon list inside Env. -#include + +#include "QObjectPtr.h" class QFileSystemWatcher; -class IconList : public QAbstractListModel, public IIconList +class IconList : public QAbstractListModel { Q_OBJECT public: @@ -42,19 +43,19 @@ public: virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; - bool addThemeIcon(const QString &key); - bool addIcon(const QString &key, const QString &name, const QString &path, const IconType type) override; - void saveIcon(const QString &key, const QString &path, const char * format) const override; - bool deleteIcon(const QString &key) override; - bool iconFileExists(const QString &key) const override; - virtual QStringList mimeTypes() const override; virtual Qt::DropActions supportedDropActions() const override; virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; virtual Qt::ItemFlags flags(const QModelIndex &index) const override; - void installIcons(const QStringList &iconFiles) override; - void installIcon(const QString &file, const QString &name) override; + bool addThemeIcon(const QString &key); + bool addIcon(const QString &key, const QString &name, const QString &path, const IconType type); + void saveIcon(const QString &key, const QString &path, const char * format) const; + bool deleteIcon(const QString &key); + bool iconFileExists(const QString &key) const; + + void installIcons(const QStringList &iconFiles); + void installIcon(const QString &file, const QString &name); const MMCIcon * icon(const QString &key) const; diff --git a/launcher/icons/MMCIcon.h b/launcher/icons/MMCIcon.h index 1f05f28e..13d99318 100644 --- a/launcher/icons/MMCIcon.h +++ b/launcher/icons/MMCIcon.h @@ -17,7 +17,15 @@ #include #include #include -#include + +enum IconType : unsigned +{ + Builtin, + Transient, + FileBased, + ICONS_TOTAL, + ToBeDeleted +}; struct MMCImage { diff --git a/launcher/java/JavaChecker.cpp b/launcher/java/JavaChecker.cpp index 6d73ebfb..80c599cc 100644 --- a/launcher/java/JavaChecker.cpp +++ b/launcher/java/JavaChecker.cpp @@ -1,14 +1,14 @@ #include "JavaChecker.h" -#include "JavaUtils.h" -#include -#include + #include #include #include -#include #include -#include "Env.h" +#include "JavaUtils.h" +#include "FileSystem.h" +#include "Commandline.h" +#include "Application.h" JavaChecker::JavaChecker(QObject *parent) : QObject(parent) { @@ -16,7 +16,7 @@ JavaChecker::JavaChecker(QObject *parent) : QObject(parent) void JavaChecker::performCheck() { - QString checkerJar = FS::PathCombine(ENV->getJarsPath(), "JavaCheck.jar"); + QString checkerJar = FS::PathCombine(APPLICATION->getJarsPath(), "JavaCheck.jar"); QStringList args; diff --git a/launcher/meta/BaseEntity.cpp b/launcher/meta/BaseEntity.cpp index 1618c999..9aa4a3dd 100644 --- a/launcher/meta/BaseEntity.cpp +++ b/launcher/meta/BaseEntity.cpp @@ -15,16 +15,13 @@ #include "BaseEntity.h" -#include "Json.h" - #include "net/Download.h" #include "net/HttpMetaCache.h" #include "net/NetJob.h" - -#include "Env.h" #include "Json.h" #include "BuildConfig.h" +#include "Application.h" class ParsingValidator : public Net::Validator { @@ -120,9 +117,9 @@ void Meta::BaseEntity::load(Net::Mode loadType) { return; } - NetJob *job = new NetJob(QObject::tr("Download of meta file %1").arg(localFilename())); + m_updateTask = new NetJob(QObject::tr("Download of meta file %1").arg(localFilename())); auto url = this->url(); - auto entry = ENV->metacache()->resolveEntry("meta", localFilename()); + auto entry = APPLICATION->metacache()->resolveEntry("meta", localFilename()); entry->setStale(true); auto dl = Net::Download::makeCached(url, entry); /* @@ -130,21 +127,20 @@ void Meta::BaseEntity::load(Net::Mode loadType) * If that fails, the file is not written to storage. */ dl->addValidator(new ParsingValidator(this)); - job->addNetAction(dl); + m_updateTask->addNetAction(dl); m_updateStatus = UpdateStatus::InProgress; - m_updateTask.reset(job); - QObject::connect(job, &NetJob::succeeded, [&]() + QObject::connect(m_updateTask.get(), &NetJob::succeeded, [&]() { m_loadStatus = LoadStatus::Remote; m_updateStatus = UpdateStatus::Succeeded; m_updateTask.reset(); }); - QObject::connect(job, &NetJob::failed, [&]() + QObject::connect(m_updateTask.get(), &NetJob::failed, [&]() { m_updateStatus = UpdateStatus::Failed; m_updateTask.reset(); }); - m_updateTask->start(); + m_updateTask->start(APPLICATION->network()); } bool Meta::BaseEntity::isLoaded() const diff --git a/launcher/meta/BaseEntity.h b/launcher/meta/BaseEntity.h index eff43879..75fa384a 100644 --- a/launcher/meta/BaseEntity.h +++ b/launcher/meta/BaseEntity.h @@ -20,8 +20,8 @@ #include "QObjectPtr.h" #include "net/Mode.h" +#include "net/NetJob.h" -class Task; namespace Meta { class BaseEntity @@ -54,7 +54,7 @@ public: bool shouldStartRemoteUpdate() const; void load(Net::Mode loadType); - shared_qobject_ptr getCurrentTask(); + Task::Ptr getCurrentTask(); protected: /* methods */ bool loadLocalFile(); @@ -62,6 +62,6 @@ protected: /* methods */ private: LoadStatus m_loadStatus = LoadStatus::NotLoaded; UpdateStatus m_updateStatus = UpdateStatus::NotDone; - shared_qobject_ptr m_updateTask; + NetJob::Ptr m_updateTask; }; } diff --git a/launcher/meta/Index_test.cpp b/launcher/meta/Index_test.cpp index d5d477e8..5d3ddc50 100644 --- a/launcher/meta/Index_test.cpp +++ b/launcher/meta/Index_test.cpp @@ -3,19 +3,12 @@ #include "meta/Index.h" #include "meta/VersionList.h" -#include "Env.h" class IndexTest : public QObject { Q_OBJECT private slots: - void test_isProvidedByEnv() - { - QVERIFY(ENV->metadataIndex()); - QCOMPARE(ENV->metadataIndex(), ENV->metadataIndex()); - } - void test_hasUid_and_getList() { Meta::Index windex({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}); diff --git a/launcher/minecraft/AssetsUtils.cpp b/launcher/minecraft/AssetsUtils.cpp index c01733b6..1c65a212 100644 --- a/launcher/minecraft/AssetsUtils.cpp +++ b/launcher/minecraft/AssetsUtils.cpp @@ -284,7 +284,7 @@ bool reconstructAssets(QString assetsId, QString resourcesFolder) } -NetActionPtr AssetObject::getDownloadAction() +NetAction::Ptr AssetObject::getDownloadAction() { QFileInfo objectFile(getLocalPath()); if ((!objectFile.isFile()) || (objectFile.size() != size)) @@ -316,7 +316,7 @@ QString AssetObject::getRelPath() return hash.left(2) + "/" + hash; } -NetJobPtr AssetsIndex::getDownloadJob() +NetJob::Ptr AssetsIndex::getDownloadJob() { auto job = new NetJob(QObject::tr("Assets for %1").arg(id)); for (auto &object : objects.values()) diff --git a/launcher/minecraft/AssetsUtils.h b/launcher/minecraft/AssetsUtils.h index 32e57060..3dbf19ed 100644 --- a/launcher/minecraft/AssetsUtils.h +++ b/launcher/minecraft/AssetsUtils.h @@ -25,7 +25,7 @@ struct AssetObject QString getRelPath(); QUrl getUrl(); QString getLocalPath(); - NetActionPtr getDownloadAction(); + NetAction::Ptr getDownloadAction(); QString hash; qint64 size; @@ -33,7 +33,7 @@ struct AssetObject struct AssetsIndex { - NetJobPtr getDownloadJob(); + NetJob::Ptr getDownloadJob(); QString id; QMap objects; diff --git a/launcher/minecraft/Component.cpp b/launcher/minecraft/Component.cpp index 385688d4..c7dd5e36 100644 --- a/launcher/minecraft/Component.cpp +++ b/launcher/minecraft/Component.cpp @@ -1,14 +1,16 @@ #include #include -#include #include "Component.h" +#include + #include "meta/Version.h" #include "VersionFile.h" #include "minecraft/PackProfile.h" -#include -#include +#include "FileSystem.h" #include "OneSixVersionFormat.h" +#include "Application.h" + #include Component::Component(PackProfile * parent, const QString& uid) @@ -85,9 +87,9 @@ std::shared_ptr Component::getVersionFile() const std::shared_ptr Component::getVersionList() const { // FIXME: what if the metadata index isn't loaded yet? - if(ENV->metadataIndex()->hasUid(m_uid)) + if(APPLICATION->metadataIndex()->hasUid(m_uid)) { - return ENV->metadataIndex()->get(m_uid); + return APPLICATION->metadataIndex()->get(m_uid); } return nullptr; } @@ -192,7 +194,7 @@ bool Component::isRevertible() { if (isCustom()) { - if(ENV->metadataIndex()->hasUid(m_uid)) + if(APPLICATION->metadataIndex()->hasUid(m_uid)) { return true; } @@ -266,7 +268,7 @@ void Component::setVersion(const QString& version) // we don't have a file, therefore we are loaded with metadata m_cachedVersion = version; // see if the meta version is loaded - auto metaVersion = ENV->metadataIndex()->get(m_uid, version); + auto metaVersion = APPLICATION->metadataIndex()->get(m_uid, version); if(metaVersion->isLoaded()) { // if yes, we can continue with that. @@ -350,7 +352,7 @@ bool Component::revert() m_file.reset(); // check local cache for metadata... - auto version = ENV->metadataIndex()->get(m_uid, m_version); + auto version = APPLICATION->metadataIndex()->get(m_uid, m_version); if(version->isLoaded()) { m_metaVersion = version; diff --git a/launcher/minecraft/ComponentUpdateTask.cpp b/launcher/minecraft/ComponentUpdateTask.cpp index 92ba1640..5c52226b 100644 --- a/launcher/minecraft/ComponentUpdateTask.cpp +++ b/launcher/minecraft/ComponentUpdateTask.cpp @@ -3,16 +3,17 @@ #include "PackProfile_p.h" #include "PackProfile.h" #include "Component.h" -#include -#include -#include -#include +#include "meta/Index.h" +#include "meta/VersionList.h" +#include "meta/Version.h" #include "ComponentUpdateTask_p.h" -#include -#include +#include "cassert" +#include "Version.h" #include "net/Mode.h" #include "OneSixVersionFormat.h" +#include "Application.h" + /* * This is responsible for loading the components of a component list AND resolving dependency issues between them */ @@ -102,7 +103,7 @@ static LoadResult loadComponent(ComponentPtr component, shared_qobject_ptr } else { - auto metaVersion = ENV->metadataIndex()->get(component->m_uid, component->m_version); + auto metaVersion = APPLICATION->metadataIndex()->get(component->m_uid, component->m_version); component->m_metaVersion = metaVersion; if(metaVersion->isLoaded()) { @@ -135,7 +136,7 @@ static LoadResult loadPackProfile(ComponentPtr component, shared_qobject_ptrmetadataIndex()->get(component->m_uid); + auto metaList = APPLICATION->metadataIndex()->get(component->m_uid); if(metaList->isLoaded()) { component->m_loaded = true; @@ -154,13 +155,13 @@ static LoadResult loadPackProfile(ComponentPtr component, shared_qobject_ptr& loadTask, Net::Mode netmode) { // FIXME: DECIDE. do we want to run the update task anyway? - if(ENV->metadataIndex()->isLoaded()) + if(APPLICATION->metadataIndex()->isLoaded()) { qDebug() << "Index is already loaded"; return LoadResult::LoadedLocal; } - ENV->metadataIndex()->load(netmode); - loadTask = ENV->metadataIndex()->getCurrentTask(); + APPLICATION->metadataIndex()->load(netmode); + loadTask = APPLICATION->metadataIndex()->getCurrentTask(); if(loadTask) { return LoadResult::RequiresRemote; diff --git a/launcher/minecraft/Library.cpp b/launcher/minecraft/Library.cpp index f2293679..c7982705 100644 --- a/launcher/minecraft/Library.cpp +++ b/launcher/minecraft/Library.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include @@ -45,14 +44,14 @@ void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& na } } -QList< std::shared_ptr< NetAction > > Library::getDownloads( +QList Library::getDownloads( OpSys system, class HttpMetaCache* cache, QStringList& failedLocalFiles, const QString & overridePath ) const { - QList out; + QList out; bool stale = isAlwaysStale(); bool local = isLocal(); diff --git a/launcher/minecraft/Library.h b/launcher/minecraft/Library.h index 119b4a86..41d41a8b 100644 --- a/launcher/minecraft/Library.h +++ b/launcher/minecraft/Library.h @@ -152,7 +152,7 @@ public: /* methods */ bool isForge() const; // Get a list of downloads for this library - QList getDownloads(OpSys system, class HttpMetaCache * cache, + QList getDownloads(OpSys system, class HttpMetaCache * cache, QStringList & failedLocalFiles, const QString & overridePath) const; private: /* methods */ diff --git a/launcher/minecraft/Library_test.cpp b/launcher/minecraft/Library_test.cpp index 75bb4db1..47531ad6 100644 --- a/launcher/minecraft/Library_test.cpp +++ b/launcher/minecraft/Library_test.cpp @@ -55,7 +55,7 @@ slots: auto downloads = test.getDownloads(currentSystem, cache.get(), failedFiles, QString()); QCOMPARE(downloads.size(), 1); QCOMPARE(failedFiles, {}); - NetActionPtr dl = downloads[0]; + NetAction::Ptr dl = downloads[0]; QCOMPARE(dl->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion.jar")); } void test_legacy_url_local_broken() diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index f755fa6e..ad8380c1 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -1,15 +1,16 @@ #include "MinecraftInstance.h" -#include -#include -#include -#include +#include "minecraft/launch/CreateGameFolders.h" +#include "minecraft/launch/ExtractNatives.h" +#include "minecraft/launch/PrintInstanceInfo.h" +#include "settings/Setting.h" #include "settings/SettingsObject.h" -#include "Env.h" -#include -#include -#include -#include -#include +#include "Application.h" + +#include "MMCStrings.h" +#include "pathmatcher/RegexpMatcher.h" +#include "pathmatcher/MultiMatcher.h" +#include "FileSystem.h" +#include "java/JavaVersion.h" #include "MMCTime.h" #include "launch/LaunchTask.h" @@ -18,6 +19,7 @@ #include "launch/steps/Update.h" #include "launch/steps/PreLaunchCommand.h" #include "launch/steps/TextPrint.h" + #include "minecraft/launch/LauncherPartLaunch.h" #include "minecraft/launch/DirectJavaLaunch.h" #include "minecraft/launch/ModMinecraftJar.h" @@ -25,25 +27,27 @@ #include "minecraft/launch/ReconstructAssets.h" #include "minecraft/launch/ScanModFolders.h" #include "minecraft/launch/VerifyJavaInstall.h" + #include "java/launch/CheckJava.h" #include "java/JavaUtils.h" + #include "meta/Index.h" #include "meta/VersionList.h" +#include "icons/IconList.h" + #include "mod/ModFolderModel.h" #include "mod/ResourcePackFolderModel.h" #include "mod/TexturePackFolderModel.h" -#include "WorldList.h" -#include "icons/IIconList.h" +#include "WorldList.h" -#include #include "PackProfile.h" #include "AssetsUtils.h" #include "MinecraftUpdate.h" #include "MinecraftLoadAndCheck.h" -#include -#include +#include "minecraft/gameoptions/GameOptions.h" +#include "minecraft/update/FoldersTask.h" #define IBUS "@im=ibus" @@ -816,7 +820,7 @@ shared_qobject_ptr MinecraftInstance::createLaunchTask(AuthSessionPt auto process = LaunchTask::create(std::dynamic_pointer_cast(shared_from_this())); auto pptr = process.get(); - ENV->icons()->saveIcon(iconKey(), FS::PathCombine(gameRoot(), "icon.png"), "PNG"); + APPLICATION->icons()->saveIcon(iconKey(), FS::PathCombine(gameRoot(), "icon.png"), "PNG"); // print a header { diff --git a/launcher/minecraft/MinecraftUpdate.cpp b/launcher/minecraft/MinecraftUpdate.cpp index 8f1565b0..32e9cbb6 100644 --- a/launcher/minecraft/MinecraftUpdate.cpp +++ b/launcher/minecraft/MinecraftUpdate.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "Env.h" #include "MinecraftUpdate.h" #include "MinecraftInstance.h" diff --git a/launcher/minecraft/PackProfile.cpp b/launcher/minecraft/PackProfile.cpp index f7612719..d6a565c0 100644 --- a/launcher/minecraft/PackProfile.cpp +++ b/launcher/minecraft/PackProfile.cpp @@ -20,22 +20,23 @@ #include #include #include - -#include "Exception.h" -#include -#include #include -#include -#include -#include #include #include -#include + +#include "Exception.h" +#include "minecraft/OneSixVersionFormat.h" +#include "FileSystem.h" +#include "meta/Index.h" +#include "minecraft/MinecraftInstance.h" +#include "Json.h" #include "PackProfile.h" #include "PackProfile_p.h" #include "ComponentUpdateTask.h" +#include "Application.h" + PackProfile::PackProfile(MinecraftInstance * instance) : QAbstractListModel() { @@ -481,7 +482,7 @@ bool PackProfile::migratePreComponentConfig() } else if(!intendedVersion.isEmpty()) { - auto metaVersion = ENV->metadataIndex()->get(uid, intendedVersion); + auto metaVersion = APPLICATION->metadataIndex()->get(uid, intendedVersion); component = new Component(this, metaVersion); } else @@ -546,7 +547,7 @@ bool PackProfile::migratePreComponentConfig() auto patchVersion = d->getOldConfigVersion(uid); if(!patchVersion.isEmpty() && !loadedComponents.contains(uid)) { - auto patch = new Component(this, ENV->metadataIndex()->get(uid, patchVersion)); + auto patch = new Component(this, APPLICATION->metadataIndex()->get(uid, patchVersion)); patch->setOrder(order); loadedComponents[uid] = patch; } diff --git a/launcher/minecraft/auth/flows/AuthContext.cpp b/launcher/minecraft/auth/flows/AuthContext.cpp index 32ee4cbd..34e2bea8 100644 --- a/launcher/minecraft/auth/flows/AuthContext.cpp +++ b/launcher/minecraft/auth/flows/AuthContext.cpp @@ -17,7 +17,6 @@ #include "Parsers.h" #include -#include using OAuth2 = Katabasis::OAuth2; using Activity = Katabasis::Activity; @@ -58,7 +57,8 @@ void AuthContext::initMSA() { opts.accessTokenUrl = "https://login.microsoftonline.com/consumers/oauth2/v2.0/token"; opts.listenerPorts = {28562, 28563, 28564, 28565, 28566}; - m_oauth2 = new OAuth2(opts, m_data->msaToken, this, &ENV->network()); + // FIXME: OAuth2 is not aware of our fancy shared pointers + m_oauth2 = new OAuth2(opts, m_data->msaToken, this, APPLICATION->network().get()); m_oauth2->setGrantFlow(Katabasis::OAuth2::GrantFlowDevice); connect(m_oauth2, &OAuth2::linkingFailed, this, &AuthContext::onOAuthLinkingFailed); diff --git a/launcher/minecraft/auth/flows/AuthRequest.cpp b/launcher/minecraft/auth/flows/AuthRequest.cpp index 751b079d..82dba591 100644 --- a/launcher/minecraft/auth/flows/AuthRequest.cpp +++ b/launcher/minecraft/auth/flows/AuthRequest.cpp @@ -5,11 +5,10 @@ #include #include +#include "Application.h" #include "AuthRequest.h" #include "katabasis/Globals.h" -#include - AuthRequest::AuthRequest(QObject *parent): QObject(parent) { } @@ -18,7 +17,7 @@ AuthRequest::~AuthRequest() { void AuthRequest::get(const QNetworkRequest &req, int timeout/* = 60*1000*/) { setup(req, QNetworkAccessManager::GetOperation); - reply_ = ENV->network().get(request_); + reply_ = APPLICATION->network()->get(request_); status_ = Requesting; timedReplies_.add(new Katabasis::Reply(reply_, timeout)); connect(reply_, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onRequestError(QNetworkReply::NetworkError))); @@ -30,7 +29,7 @@ void AuthRequest::post(const QNetworkRequest &req, const QByteArray &data, int t setup(req, QNetworkAccessManager::PostOperation); data_ = data; status_ = Requesting; - reply_ = ENV->network().post(request_, data_); + reply_ = APPLICATION->network()->post(request_, data_); timedReplies_.add(new Katabasis::Reply(reply_, timeout)); connect(reply_, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onRequestError(QNetworkReply::NetworkError))); connect(reply_, SIGNAL(finished()), this, SLOT(onRequestFinished())); diff --git a/launcher/minecraft/auth/flows/Yggdrasil.cpp b/launcher/minecraft/auth/flows/Yggdrasil.cpp index fc0b18bf..f5622418 100644 --- a/launcher/minecraft/auth/flows/Yggdrasil.cpp +++ b/launcher/minecraft/auth/flows/Yggdrasil.cpp @@ -22,10 +22,9 @@ #include #include #include - #include -#include +#include "Application.h" Yggdrasil::Yggdrasil(AccountData *data, QObject *parent) : AccountTask(data, parent) @@ -38,7 +37,7 @@ void Yggdrasil::sendRequest(QUrl endpoint, QByteArray content) { QNetworkRequest netRequest(endpoint); netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - m_netReply = ENV->network().post(netRequest, content); + m_netReply = APPLICATION->network()->post(netRequest, content); connect(m_netReply, &QNetworkReply::finished, this, &Yggdrasil::processReply); connect(m_netReply, &QNetworkReply::uploadProgress, this, &Yggdrasil::refreshTimers); connect(m_netReply, &QNetworkReply::downloadProgress, this, &Yggdrasil::refreshTimers); diff --git a/launcher/minecraft/launch/LauncherPartLaunch.cpp b/launcher/minecraft/launch/LauncherPartLaunch.cpp index 190bbbbf..8fd11eca 100644 --- a/launcher/minecraft/launch/LauncherPartLaunch.cpp +++ b/launcher/minecraft/launch/LauncherPartLaunch.cpp @@ -14,13 +14,14 @@ */ #include "LauncherPartLaunch.h" -#include -#include -#include -#include -#include + #include -#include "Env.h" + +#include "launch/LaunchTask.h" +#include "minecraft/MinecraftInstance.h" +#include "FileSystem.h" +#include "Commandline.h" +#include "Application.h" LauncherPartLaunch::LauncherPartLaunch(LaunchTask *parent) : LaunchStep(parent) { @@ -72,7 +73,7 @@ void LauncherPartLaunch::executeTask() m_process.setDetachable(true); auto classPath = minecraftInstance->getClassPath(); - classPath.prepend(FS::PathCombine(ENV->getJarsPath(), "NewLaunch.jar")); + classPath.prepend(FS::PathCombine(APPLICATION->getJarsPath(), "NewLaunch.jar")); auto natPath = minecraftInstance->getNativePath(); #ifdef Q_OS_WIN diff --git a/launcher/minecraft/services/CapeChange.cpp b/launcher/minecraft/services/CapeChange.cpp index 43da74fb..e24818ad 100644 --- a/launcher/minecraft/services/CapeChange.cpp +++ b/launcher/minecraft/services/CapeChange.cpp @@ -1,7 +1,9 @@ #include "CapeChange.h" + #include #include -#include + +#include "Application.h" CapeChange::CapeChange(QObject *parent, AuthSessionPtr session, QString cape) : Task(parent), m_capeId(cape), m_session(session) @@ -12,7 +14,7 @@ void CapeChange::setCape(QString& cape) { QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/capes/active")); auto requestString = QString("{\"capeId\":\"%1\"}").arg(m_capeId); request.setRawHeader("Authorization", QString("Bearer %1").arg(m_session->access_token).toLocal8Bit()); - QNetworkReply *rep = ENV->network().put(request, requestString.toUtf8()); + QNetworkReply *rep = APPLICATION->network()->put(request, requestString.toUtf8()); setStatus(tr("Equipping cape")); @@ -26,7 +28,7 @@ void CapeChange::clearCape() { QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/capes/active")); auto requestString = QString("{\"capeId\":\"%1\"}").arg(m_capeId); request.setRawHeader("Authorization", QString("Bearer %1").arg(m_session->access_token).toLocal8Bit()); - QNetworkReply *rep = ENV->network().deleteResource(request); + QNetworkReply *rep = APPLICATION->network()->deleteResource(request); setStatus(tr("Removing cape")); diff --git a/launcher/minecraft/services/SkinDelete.cpp b/launcher/minecraft/services/SkinDelete.cpp index 4675b01a..7638ca1c 100644 --- a/launcher/minecraft/services/SkinDelete.cpp +++ b/launcher/minecraft/services/SkinDelete.cpp @@ -1,7 +1,9 @@ #include "SkinDelete.h" + #include #include -#include + +#include "Application.h" SkinDelete::SkinDelete(QObject *parent, AuthSessionPtr session) : Task(parent), m_session(session) @@ -12,7 +14,7 @@ void SkinDelete::executeTask() { QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/skins/active")); request.setRawHeader("Authorization", QString("Bearer %1").arg(m_session->access_token).toLocal8Bit()); - QNetworkReply *rep = ENV->network().deleteResource(request); + QNetworkReply *rep = APPLICATION->network()->deleteResource(request); m_reply = std::shared_ptr(rep); setStatus(tr("Deleting skin")); diff --git a/launcher/minecraft/services/SkinUpload.cpp b/la