From 69213b1206e97f7d4db4270a4b3b0af41dc9e6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 21 Nov 2021 23:21:12 +0100 Subject: [PATCH] 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 +- .../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 +- .../minecraft/update/FMLLibrariesTask.cpp | 14 +- launcher/minecraft/update/FMLLibrariesTask.h | 2 +- launcher/minecraft/update/LibrariesTask.cpp | 8 +- launcher/minecraft/update/LibrariesTask.h | 2 +- .../atlauncher/ATLPackInstallTask.cpp | 39 ++-- .../atlauncher/ATLPackInstallTask.h | 2 +- .../modplatform/flame/FileResolvingTask.cpp | 8 +- .../modplatform/flame/FileResolvingTask.h | 5 +- .../modplatform/legacy_ftb/PackFetchTask.cpp | 18 +- .../modplatform/legacy_ftb/PackFetchTask.h | 5 +- .../legacy_ftb/PackInstallTask.cpp | 26 +-- .../modplatform/legacy_ftb/PackInstallTask.h | 7 +- .../modpacksch/FTBPackInstallTask.cpp | 13 +- .../modpacksch/FTBPackInstallTask.h | 2 +- .../technic/SingleZipPackInstallTask.cpp | 11 +- .../technic/SingleZipPackInstallTask.h | 2 +- .../technic/SolderPackInstallTask.cpp | 14 +- .../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 +- .../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 +- .../modplatform/atlauncher/AtlListModel.cpp | 9 +- .../modplatform/atlauncher/AtlListModel.h | 2 +- .../pages/modplatform/flame/FlameModel.cpp | 9 +- launcher/pages/modplatform/flame/FlameModel.h | 2 +- .../pages/modplatform/flame/FlamePage.cpp | 2 +- .../pages/modplatform/ftb/FtbListModel.cpp | 11 +- launcher/pages/modplatform/ftb/FtbListModel.h | 4 +- .../modplatform/legacy_ftb/ListModel.cpp | 7 +- .../pages/modplatform/legacy_ftb/Page.cpp | 4 +- .../modplatform/technic/TechnicModel.cpp | 9 +- .../pages/modplatform/technic/TechnicModel.h | 2 +- .../pages/modplatform/technic/TechnicPage.cpp | 4 +- launcher/screenshots/ImgurAlbumCreation.cpp | 12 +- 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, 634 insertions(+), 773 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 #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/launcher/minecraft/services/SkinUpload.cpp index e54f2327..d2d234bf 100644 --- a/launcher/minecraft/services/SkinUpload.cpp +++ b/launcher/minecraft/services/SkinUpload.cpp @@ -1,7 +1,9 @@ #include "SkinUpload.h" + #include #include -#include + +#include "Application.h" QByteArray getVariant(SkinUpload::Model model) { switch (model) { @@ -37,7 +39,7 @@ void SkinUpload::executeTask() multiPart->append(skin); multiPart->append(model); - QNetworkReply *rep = ENV->network().post(request, multiPart); + QNetworkReply *rep = APPLICATION->network()->post(request, multiPart); m_reply = std::shared_ptr(rep); setStatus(tr("Uploading skin")); diff --git a/launcher/minecraft/update/AssetUpdateTask.cpp b/launcher/minecraft/update/AssetUpdateTask.cpp index c8dcdc53..096e1719 100644 --- a/launcher/minecraft/update/AssetUpdateTask.cpp +++ b/launcher/minecraft/update/AssetUpdateTask.cpp @@ -1,10 +1,12 @@ -#include "Env.h" #include "AssetUpdateTask.h" + #include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" #include "net/ChecksumValidator.h" #include "minecraft/AssetsUtils.h" +#include "Application.h" + AssetUpdateTask::AssetUpdateTask(MinecraftInstance * inst) { m_inst = inst; @@ -24,7 +26,7 @@ void AssetUpdateTask::executeTask() QString localPath = assets->id + ".json"; auto job = new NetJob(tr("Asset index for %1").arg(m_inst->name())); - auto metacache = ENV->metacache(); + auto metacache = APPLICATION->metacache(); auto entry = metacache->resolveEntry("asset_indexes", localPath); entry->setStale(true); auto hexSha1 = assets->sha1.toLatin1(); @@ -41,7 +43,7 @@ void AssetUpdateTask::executeTask() connect(downloadJob.get(), &NetJob::progress, this, &AssetUpdateTask::progress); qDebug() << m_inst->name() << ": Starting asset index download"; - downloadJob->start(); + downloadJob->start(APPLICATION->network()); } bool AssetUpdateTask::canAbort() const @@ -62,7 +64,7 @@ void AssetUpdateTask::assetIndexFinished() // FIXME: this looks like a job for a generic validator based on json schema? if (!AssetsUtils::loadAssetsIndexJson(assets->id, asset_fname, index)) { - auto metacache = ENV->metacache(); + auto metacache = APPLICATION->metacache(); auto entry = metacache->resolveEntry("asset_indexes", assets->id + ".json"); metacache->evictEntry(entry); emitFailed(tr("Failed to read the assets index!")); @@ -76,7 +78,7 @@ void AssetUpdateTask::assetIndexFinished() connect(downloadJob.get(), &NetJob::succeeded, this, &AssetUpdateTask::emitSucceeded); connect(downloadJob.get(), &NetJob::failed, this, &AssetUpdateTask::assetsFailed); connect(downloadJob.get(), &NetJob::progress, this, &AssetUpdateTask::progress); - downloadJob->start(); + downloadJob->start(APPLICATION->network()); return; } emitSucceeded(); diff --git a/launcher/minecraft/update/AssetUpdateTask.h b/launcher/minecraft/update/AssetUpdateTask.h index fdfa8f1c..6d7356f3 100644 --- a/launcher/minecraft/update/AssetUpdateTask.h +++ b/launcher/minecraft/update/AssetUpdateTask.h @@ -24,5 +24,5 @@ public slots: private: MinecraftInstance *m_inst; - NetJobPtr downloadJob; + NetJob::Ptr downloadJob; }; diff --git a/launcher/minecraft/update/FMLLibrariesTask.cpp b/launcher/minecraft/update/FMLLibrariesTask.cpp index e7efb369..a5c6b1e3 100644 --- a/launcher/minecraft/update/FMLLibrariesTask.cpp +++ b/launcher/minecraft/update/FMLLibrariesTask.cpp @@ -1,10 +1,12 @@ -#include "Env.h" -#include -#include #include "FMLLibrariesTask.h" + +#include "FileSystem.h" +#include "minecraft/VersionFilterData.h" #include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" + #include "BuildConfig.h" +#include "Application.h" FMLLibrariesTask::FMLLibrariesTask(MinecraftInstance * inst) { @@ -60,7 +62,7 @@ void FMLLibrariesTask::executeTask() // download missing libs to our place setStatus(tr("Downloading FML libraries...")); auto dljob = new NetJob("FML libraries"); - auto metacache = ENV->metacache(); + auto metacache = APPLICATION->metacache(); for (auto &lib : fmlLibsToProcess) { auto entry = metacache->resolveEntry("fmllibs", lib.filename); @@ -72,7 +74,7 @@ void FMLLibrariesTask::executeTask() connect(dljob, &NetJob::failed, this, &FMLLibrariesTask::fmllibsFailed); connect(dljob, &NetJob::progress, this, &FMLLibrariesTask::progress); downloadJob.reset(dljob); - downloadJob->start(); + downloadJob->start(APPLICATION->network()); } bool FMLLibrariesTask::canAbort() const @@ -87,7 +89,7 @@ void FMLLibrariesTask::fmllibsFinished() { setStatus(tr("Copying FML libraries into the instance...")); MinecraftInstance *inst = (MinecraftInstance *)m_inst; - auto metacache = ENV->metacache(); + auto metacache = APPLICATION->metacache(); int index = 0; for (auto &lib : fmlLibsToProcess) { diff --git a/launcher/minecraft/update/FMLLibrariesTask.h b/launcher/minecraft/update/FMLLibrariesTask.h index a1e70ed4..2e5ad83a 100644 --- a/launcher/minecraft/update/FMLLibrariesTask.h +++ b/launcher/minecraft/update/FMLLibrariesTask.h @@ -25,7 +25,7 @@ public slots: private: MinecraftInstance *m_inst; - NetJobPtr downloadJob; + NetJob::Ptr downloadJob; QList fmlLibsToProcess; }; diff --git a/launcher/minecraft/update/LibrariesTask.cpp b/launcher/minecraft/update/LibrariesTask.cpp index 40f0a78c..065b4e06 100644 --- a/launcher/minecraft/update/LibrariesTask.cpp +++ b/launcher/minecraft/update/LibrariesTask.cpp @@ -1,8 +1,10 @@ -#include "Env.h" #include "LibrariesTask.h" + #include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" +#include "Application.h" + LibrariesTask::LibrariesTask(MinecraftInstance * inst) { m_inst = inst; @@ -21,7 +23,7 @@ void LibrariesTask::executeTask() auto job = new NetJob(tr("Libraries for instance %1").arg(inst->name())); downloadJob.reset(job); - auto metacache = ENV->metacache(); + auto metacache = APPLICATION->metacache(); auto processArtifactPool = [&](const QList & pool, QStringList & errors, const QString & localPath) { @@ -63,7 +65,7 @@ void LibrariesTask::executeTask() connect(downloadJob.get(), &NetJob::succeeded, this, &LibrariesTask::emitSucceeded); connect(downloadJob.get(), &NetJob::failed, this, &LibrariesTask::jarlibFailed); connect(downloadJob.get(), &NetJob::progress, this, &LibrariesTask::progress); - downloadJob->start(); + downloadJob->start(APPLICATION->network()); } bool LibrariesTask::canAbort() const diff --git a/launcher/minecraft/update/LibrariesTask.h b/launcher/minecraft/update/LibrariesTask.h index 49f76932..b966ad6c 100644 --- a/launcher/minecraft/update/LibrariesTask.h +++ b/launcher/minecraft/update/LibrariesTask.h @@ -22,5 +22,5 @@ public slots: private: MinecraftInstance *m_inst; - NetJobPtr downloadJob; + NetJob::Ptr downloadJob; }; diff --git a/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp b/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp index 66b592bb..9ef32db1 100644 --- a/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp +++ b/launcher/modplatform/atlauncher/ATLPackInstallTask.cpp @@ -1,13 +1,13 @@ -#include -#include -#include -#include -#include -#include -#include #include "ATLPackInstallTask.h" -#include "BuildConfig.h" +#include + +#include + +#include "MMCZip.h" +#include "minecraft/OneSixVersionFormat.h" +#include "Version.h" +#include "net/ChecksumValidator.h" #include "FileSystem.h" #include "Json.h" #include "minecraft/MinecraftInstance.h" @@ -17,6 +17,9 @@ #include "meta/Version.h" #include "meta/VersionList.h" +#include "BuildConfig.h" +#include "Application.h" + namespace ATLauncher { PackInstallTask::PackInstallTask(UserInteractionSupport *support, QString pack, QString version) @@ -43,7 +46,7 @@ void PackInstallTask::executeTask() .arg(m_pack).arg(m_version_name); netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); jobPtr = netJob; - jobPtr->start(); + jobPtr->start(APPLICATION->network()); QObject::connect(netJob, &NetJob::succeeded, this, &PackInstallTask::onDownloadSucceeded); QObject::connect(netJob, &NetJob::failed, this, &PackInstallTask::onDownloadFailed); @@ -76,7 +79,7 @@ void PackInstallTask::onDownloadSucceeded() } m_version = version; - auto vlist = ENV->metadataIndex()->get("net.minecraft"); + auto vlist = APPLICATION->metadataIndex()->get("net.minecraft"); if(!vlist) { emitFailed(tr("Failed to get local metadata index for %1").arg("net.minecraft")); @@ -157,7 +160,7 @@ QString PackInstallTask::getDirForModType(ModType type, QString raw) QString PackInstallTask::getVersionForLoader(QString uid) { if(m_version.loader.recommended || m_version.loader.latest || m_version.loader.choose) { - auto vlist = ENV->metadataIndex()->get(uid); + auto vlist = APPLICATION->metadataIndex()->get(uid); if(!vlist) { emitFailed(tr("Failed to get local metadata index for %1").arg(uid)); @@ -409,7 +412,7 @@ void PackInstallTask::installConfigs() auto path = QString("Configs/%1/%2.zip").arg(m_pack).arg(m_version_name); auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "packs/%1/versions/%2/Configs.zip") .arg(m_pack).arg(m_version_name); - auto entry = ENV->metacache()->resolveEntry("ATLauncherPacks", path); + auto entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", path); entry->setStale(true); auto dl = Net::Download::makeCached(url, entry); @@ -438,7 +441,7 @@ void PackInstallTask::installConfigs() setProgress(current, total); }); - jobPtr->start(); + jobPtr->start(APPLICATION->network()); } void PackInstallTask::extractConfigs() @@ -516,7 +519,7 @@ void PackInstallTask::downloadMods() auto cacheName = fileName.completeBaseName() + "-" + mod.md5 + "." + fileName.suffix(); if (mod.type == ModType::Extract || mod.type == ModType::TexturePackExtract || mod.type == ModType::ResourcePackExtract) { - auto entry = ENV->metacache()->resolveEntry("ATLauncherPacks", cacheName); + auto entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", cacheName); entry->setStale(true); modsToExtract.insert(entry->getFullPath(), mod); @@ -528,7 +531,7 @@ void PackInstallTask::downloadMods() jobPtr->addNetAction(dl); } else if(mod.type == ModType::Decomp) { - auto entry = ENV->metacache()->resolveEntry("ATLauncherPacks", cacheName); + auto entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", cacheName); entry->setStale(true); modsToDecomp.insert(entry->getFullPath(), mod); @@ -543,7 +546,7 @@ void PackInstallTask::downloadMods() auto relpath = getDirForModType(mod.type, mod.type_raw); if(relpath == Q_NULLPTR) continue; - auto entry = ENV->metacache()->resolveEntry("ATLauncherPacks", cacheName); + auto entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", cacheName); entry->setStale(true); auto dl = Net::Download::makeCached(url, entry); @@ -558,7 +561,7 @@ void PackInstallTask::downloadMods() modsToCopy[entry->getFullPath()] = path; if(mod.type == ModType::Forge) { - auto vlist = ENV->metadataIndex()->get("net.minecraftforge"); + auto vlist = APPLICATION->metadataIndex()->get("net.minecraftforge"); if(vlist) { auto ver = vlist->getVersion(mod.version); @@ -593,7 +596,7 @@ void PackInstallTask::downloadMods() setProgress(current, total); }); - jobPtr->start(); + jobPtr->start(APPLICATION->network()); } void PackInstallTask::onModsDownloaded() { diff --git a/launcher/modplatform/atlauncher/ATLPackInstallTask.h b/launcher/modplatform/atlauncher/ATLPackInstallTask.h index 39e2b013..f8ea2d54 100644 --- a/launcher/modplatform/atlauncher/ATLPackInstallTask.h +++ b/launcher/modplatform/atlauncher/ATLPackInstallTask.h @@ -74,7 +74,7 @@ private: bool abortable = false; - NetJobPtr jobPtr; + NetJob::Ptr jobPtr; QByteArray response; QString m_pack; diff --git a/launcher/modplatform/flame/FileResolvingTask.cpp b/launcher/modplatform/flame/FileResolvingTask.cpp index 295574f0..06f0cf2b 100644 --- a/launcher/modplatform/flame/FileResolvingTask.cpp +++ b/launcher/modplatform/flame/FileResolvingTask.cpp @@ -5,8 +5,8 @@ namespace { const char * metabase = "https://cursemeta.dries007.net"; } -Flame::FileResolvingTask::FileResolvingTask(Flame::Manifest& toProcess) - : m_toProcess(toProcess) +Flame::FileResolvingTask::FileResolvingTask(shared_qobject_ptr network, Flame::Manifest& toProcess) + : m_network(network), m_toProcess(toProcess) { } @@ -14,7 +14,7 @@ void Flame::FileResolvingTask::executeTask() { setStatus(tr("Resolving mod IDs...")); setProgress(0, m_toProcess.files.size()); - m_dljob.reset(new NetJob("Mod id resolver")); + m_dljob = new NetJob("Mod id resolver"); results.resize(m_toProcess.files.size()); int index = 0; for(auto & file: m_toProcess.files) @@ -27,7 +27,7 @@ void Flame::FileResolvingTask::executeTask() index ++; } connect(m_dljob.get(), &NetJob::finished, this, &Flame::FileResolvingTask::netJobFinished); - m_dljob->start(); + m_dljob->start(m_network); } void Flame::FileResolvingTask::netJobFinished() diff --git a/launcher/modplatform/flame/FileResolvingTask.h b/launcher/modplatform/flame/FileResolvingTask.h index 78a38fcb..5e5adcd7 100644 --- a/launcher/modplatform/flame/FileResolvingTask.h +++ b/launcher/modplatform/flame/FileResolvingTask.h @@ -10,7 +10,7 @@ class FileResolvingTask : public Task { Q_OBJECT public: - explicit FileResolvingTask(Flame::Manifest &toProcess); + explicit FileResolvingTask(shared_qobject_ptr network, Flame::Manifest &toProcess); virtual ~FileResolvingTask() {}; const Flame::Manifest &getResults() const @@ -25,8 +25,9 @@ protected slots: void netJobFinished(); private: /* data */ + shared_qobject_ptr m_network; Flame::Manifest m_toProcess; QVector results; - NetJobPtr m_dljob; + NetJob::Ptr m_dljob; }; } diff --git a/launcher/modplatform/legacy_ftb/PackFetchTask.cpp b/launcher/modplatform/legacy_ftb/PackFetchTask.cpp index c2ef6436..ecf36188 100644 --- a/launcher/modplatform/legacy_ftb/PackFetchTask.cpp +++ b/launcher/modplatform/legacy_ftb/PackFetchTask.cpp @@ -2,7 +2,8 @@ #include "PrivatePackManager.h" #include -#include +#include "BuildConfig.h" +#include "Application.h" namespace LegacyFTB { @@ -11,21 +12,20 @@ void PackFetchTask::fetch() publicPacks.clear(); thirdPartyPacks.clear(); - NetJob *netJob = new NetJob("LegacyFTB::ModpackFetch"); + jobPtr = new NetJob("LegacyFTB::ModpackFetch"); QUrl publicPacksUrl = QUrl(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/modpacks.xml"); qDebug() << "Downloading public version info from" << publicPacksUrl.toString(); - netJob->addNetAction(Net::Download::makeByteArray(publicPacksUrl, &publicModpacksXmlFileData)); + jobPtr->addNetAction(Net::Download::makeByteArray(publicPacksUrl, &publicModpacksXmlFileData)); QUrl thirdPartyUrl = QUrl(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/thirdparty.xml"); qDebug() << "Downloading thirdparty version info from" << thirdPartyUrl.toString(); - netJob->addNetAction(Net::Download::makeByteArray(thirdPartyUrl, &thirdPartyModpacksXmlFileData)); + jobPtr->addNetAction(Net::Download::makeByteArray(thirdPartyUrl, &thirdPartyModpacksXmlFileData)); - QObject::connect(netJob, &NetJob::succeeded, this, &PackFetchTask::fileDownloadFinished); - QObject::connect(netJob, &NetJob::failed, this, &PackFetchTask::fileDownloadFailed); + QObject::connect(jobPtr.get(), &NetJob::succeeded, this, &PackFetchTask::fileDownloadFinished); + QObject::connect(jobPtr.get(), &NetJob::failed, this, &PackFetchTask::fileDownloadFailed); - jobPtr.reset(netJob); - netJob->start(); + jobPtr->start(m_network); } void PackFetchTask::fetchPrivate(const QStringList & toFetch) @@ -63,7 +63,7 @@ void PackFetchTask::fetchPrivate(const QStringList & toFetch) delete data; }); - job->start(); + job->start(m_network); } } diff --git a/launcher/modplatform/legacy_ftb/PackFetchTask.h b/launcher/modplatform/legacy_ftb/PackFetchTask.h index 3ab32fab..f1667e90 100644 --- a/launcher/modplatform/legacy_ftb/PackFetchTask.h +++ b/launcher/modplatform/legacy_ftb/PackFetchTask.h @@ -13,14 +13,15 @@ class PackFetchTask : public QObject { Q_OBJECT public: - PackFetchTask() = default; + PackFetchTask(shared_qobject_ptr network) : QObject(nullptr), m_network(network) {}; virtual ~PackFetchTask() = default; void fetch(); void fetchPrivate(const QStringList &toFetch); private: - NetJobPtr jobPtr; + shared_qobject_ptr m_network; + NetJob::Ptr jobPtr; QByteArray publicModpacksXmlFileData; QByteArray thirdPartyModpacksXmlFileData; diff --git a/launcher/modplatform/legacy_ftb/PackInstallTask.cpp b/launcher/modplatform/legacy_ftb/PackInstallTask.cpp index 70b0ab94..64aecb39 100644 --- a/launcher/modplatform/legacy_ftb/PackInstallTask.cpp +++ b/launcher/modplatform/legacy_ftb/PackInstallTask.cpp @@ -1,24 +1,25 @@ #include "PackInstallTask.h" -#include "Env.h" -#include "MMCZip.h" +#include +#include "MMCZip.h" #include "BaseInstance.h" #include "FileSystem.h" #include "settings/INISettingsObject.h" #include "minecraft/MinecraftInstance.h" #include "minecraft/PackProfile.h" #include "minecraft/GradleSpecifier.h" -#include "BuildConfig.h" -#include +#include "BuildConfig.h" +#include "Application.h" namespace LegacyFTB { -PackInstallTask::PackInstallTask(Modpack pack, QString version) +PackInstallTask::PackInstallTask(shared_qobject_ptr network, Modpack pack, QString version) { m_pack = pack; m_version = version; + m_network = network; } void PackInstallTask::executeTask() @@ -31,8 +32,8 @@ void PackInstallTask::downloadPack() setStatus(tr("Downloading zip for %1").arg(m_pack.name)); auto packoffset = QString("%1/%2/%3").arg(m_pack.dir, m_version.replace(".", "_"), m_pack.file); - auto entry = ENV->metacache()->resolveEntry("FTBPacks", packoffset); - NetJob *job = new NetJob("Download FTB Pack"); + auto entry = APPLICATION->metacache()->resolveEntry("FTBPacks", packoffset); + netJobContainer = new NetJob("Download FTB Pack"); entry->setStale(true); QString url; @@ -44,14 +45,13 @@ void PackInstallTask::downloadPack() { url = QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "modpacks/%1").arg(packoffset); } - job->addNetAction(Net::Download::makeCached(url, entry)); + netJobContainer->addNetAction(Net::Download::makeCached(url, entry)); archivePath = entry->getFullPath(); - netJobContainer.reset(job); - connect(job, &NetJob::succeeded, this, &PackInstallTask::onDownloadSucceeded); - connect(job, &NetJob::failed, this, &PackInstallTask::onDownloadFailed); - connect(job, &NetJob::progress, this, &PackInstallTask::onDownloadProgress); - job->start(); + connect(netJobContainer.get(), &NetJob::succeeded, this, &PackInstallTask::onDownloadSucceeded); + connect(netJobContainer.get(), &NetJob::failed, this, &PackInstallTask::onDownloadFailed); + connect(netJobContainer.get(), &NetJob::progress, this, &PackInstallTask::onDownloadProgress); + netJobContainer->start(m_network); progress(1, 4); } diff --git a/launcher/modplatform/legacy_ftb/PackInstallTask.h b/launcher/modplatform/legacy_ftb/PackInstallTask.h index 600f72e7..305635a1 100644 --- a/launcher/modplatform/legacy_ftb/PackInstallTask.h +++ b/launcher/modplatform/legacy_ftb/PackInstallTask.h @@ -8,6 +8,8 @@ #include "meta/VersionList.h" #include "PackHelpers.h" +#include "net/NetJob.h" + #include namespace LegacyFTB { @@ -17,7 +19,7 @@ class PackInstallTask : public InstanceTask Q_OBJECT public: - explicit PackInstallTask(Modpack pack, QString version); + explicit PackInstallTask(shared_qobject_ptr network, Modpack pack, QString version); virtual ~PackInstallTask(){} bool canAbort() const override { return true; } @@ -41,11 +43,12 @@ private slots: void onUnzipCanceled(); private: /* data */ + shared_qobject_ptr m_network; bool abortable = false; std::unique_ptr m_packZip; QFuture> m_extractFuture; QFutureWatcher> m_extractFutureWatcher; - NetJobPtr netJobContainer; + NetJob::Ptr netJobContainer; QString archivePath; Modpack m_pack; diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 785d3dd6..563b5cfa 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -1,7 +1,5 @@ #include "FTBPackInstallTask.h" -#include "BuildConfig.h" -#include "Env.h" #include "FileSystem.h" #include "Json.h" #include "minecraft/MinecraftInstance.h" @@ -9,6 +7,9 @@ #include "net/ChecksumValidator.h" #include "settings/INISettingsObject.h" +#include "BuildConfig.h" +#include "Application.h" + namespace ModpacksCH { PackInstallTask::PackInstallTask(Modpack pack, QString version) @@ -50,7 +51,7 @@ void PackInstallTask::executeTask() .arg(m_pack.id).arg(version.id); netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); jobPtr = netJob; - jobPtr->start(); + jobPtr->start(APPLICATION->network()); QObject::connect(netJob, &NetJob::succeeded, this, &PackInstallTask::onDownloadSucceeded); QObject::connect(netJob, &NetJob::failed, this, &PackInstallTask::onDownloadFailed); @@ -95,14 +96,14 @@ void PackInstallTask::downloadPack() { setStatus(tr("Downloading mods...")); - jobPtr.reset(new NetJob(tr("Mod download"))); + jobPtr = new NetJob(tr("Mod download")); for(auto file : m_version.files) { if(file.serverOnly) continue; QFileInfo fileName(file.name); auto cacheName = fileName.completeBaseName() + "-" + file.sha1 + "." + fileName.suffix(); - auto entry = ENV->metacache()->resolveEntry("ModpacksCHPacks", cacheName); + auto entry = APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", cacheName); entry->setStale(true); auto relpath = FS::PathCombine("minecraft", file.path, file.name); @@ -141,7 +142,7 @@ void PackInstallTask::downloadPack() setProgress(current, total); }); - jobPtr->start(); + jobPtr->start(APPLICATION->network()); } void PackInstallTask::install() diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.h b/launcher/modplatform/modpacksch/FTBPackInstallTask.h index fdd84c4e..23362dc9 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.h +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.h @@ -32,7 +32,7 @@ private: private: bool abortable = false; - NetJobPtr jobPtr; + NetJob::Ptr jobPtr; QByteArray response; Modpack m_pack; diff --git a/launcher/modplatform/technic/SingleZipPackInstallTask.cpp b/launcher/modplatform/technic/SingleZipPackInstallTask.cpp index f2aa37a0..0ab9f3c0 100644 --- a/launcher/modplatform/technic/SingleZipPackInstallTask.cpp +++ b/launcher/modplatform/technic/SingleZipPackInstallTask.cpp @@ -15,12 +15,13 @@ #include "SingleZipPackInstallTask.h" -#include "Env.h" +#include + #include "MMCZip.h" #include "TechnicPackProcessor.h" +#include "FileSystem.h" -#include -#include +#include "Application.h" Technic::SingleZipPackInstallTask::SingleZipPackInstallTask(const QUrl &sourceUrl, const QString &minecraftVersion) { @@ -41,7 +42,7 @@ void Technic::SingleZipPackInstallTask::executeTask() setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString())); 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)); @@ -50,7 +51,7 @@ void Technic::SingleZipPackInstallTask::executeTask() connect(job, &NetJob::succeeded, this, &Technic::SingleZipPackInstallTask::downloadSucceeded); connect(job, &NetJob::progress, this, &Technic::SingleZipPackInstallTask::downloadProgressChanged); connect(job, &NetJob::failed, this, &Technic::SingleZipPackInstallTask::downloadFailed); - m_filesNetJob->start(); + m_filesNetJob->start(APPLICATION->network()); } void Technic::SingleZipPackInstallTask::downloadSucceeded() diff --git a/launcher/modplatform/technic/SingleZipPackInstallTask.h b/launcher/modplatform/technic/SingleZipPackInstallTask.h index 80f10a98..74f60941 100644 --- a/launcher/modplatform/technic/SingleZipPackInstallTask.h +++ b/launcher/modplatform/technic/SingleZipPackInstallTask.h @@ -55,7 +55,7 @@ private: QUrl m_sourceUrl; QString m_minecraftVersion; QString m_archivePath; - NetJobPtr m_filesNetJob; + NetJob::Ptr m_filesNetJob; std::unique_ptr m_packZip; QFuture> m_extractFuture; QFutureWatcher> m_extractFutureWatcher; diff --git a/launcher/modplatform/technic/SolderPackInstallTask.cpp b/launcher/modplatform/technic/SolderPackInstallTask.cpp index 1b4186d4..2492ee81 100644 --- a/launcher/modplatform/technic/SolderPackInstallTask.cpp +++ b/launcher/modplatform/technic/SolderPackInstallTask.cpp @@ -21,10 +21,14 @@ #include #include "TechnicPackProcessor.h" -Technic::SolderPackInstallTask::SolderPackInstallTask(const QUrl &sourceUrl, const QString &minecraftVersion) -{ +Technic::SolderPackInstallTask::SolderPackInstallTask( + shared_qobject_ptr network, + const QUrl &sourceUrl, + const QString &minecraftVersion +) { m_sourceUrl = sourceUrl; m_minecraftVersion = minecraftVersion; + m_network = network; } bool Technic::SolderPackInstallTask::abort() { @@ -43,7 +47,7 @@ void Technic::SolderPackInstallTask::executeTask() auto job = m_filesNetJob.get(); connect(job, &NetJob::succeeded, this, &Technic::SolderPackInstallTask::versionSucceeded); connect(job, &NetJob::failed, this, &Technic::SolderPackInstallTask::downloadFailed); - m_filesNetJob->start(); + m_filesNetJob->start(m_network); } void Technic::SolderPackInstallTask::versionSucceeded() @@ -68,7 +72,7 @@ void Technic::SolderPackInstallTask::versionSucceeded() auto job = m_filesNetJob.get(); connect(job, &NetJob::succeeded, this, &Technic::SolderPackInstallTask::fileListSucceeded); connect(job, &NetJob::failed, this, &Technic::SolderPackInstallTask::downloadFailed); - m_filesNetJob->start(); + m_filesNetJob->start(m_network); } void Technic::SolderPackInstallTask::fileListSucceeded() @@ -109,7 +113,7 @@ void Technic::SolderPackInstallTask::fileListSucceeded() connect(m_filesNetJob.get(), &NetJob::succeeded, this, &Technic::SolderPackInstallTask::downloadSucceeded); connect(m_filesNetJob.get(), &NetJob::progress, this, &Technic::SolderPackInstallTask::downloadProgressChanged); connect(m_filesNetJob.get(), &NetJob::failed, this, &Technic::SolderPackInstallTask::downloadFailed); - m_filesNetJob->start(); + m_filesNetJob->start(m_network); } void Technic::SolderPackInstallTask::downloadSucceeded() diff --git a/launcher/modplatform/technic/SolderPackInstallTask.h b/launcher/modplatform/technic/SolderPackInstallTask.h index 6e1057eb..9b2058d8 100644 --- a/launcher/modplatform/technic/SolderPackInstallTask.h +++ b/launcher/modplatform/technic/SolderPackInstallTask.h @@ -27,7 +27,7 @@ namespace Technic { Q_OBJECT public: - explicit SolderPackInstallTask(const QUrl &sourceUrl, const QString &minecraftVersion); + explicit SolderPackInstallTask(shared_qobject_ptr network, const QUrl &sourceUrl, const QString &minecraftVersion); bool canAbort() const override { return true; } bool abort() override; @@ -48,7 +48,9 @@ namespace Technic private: bool m_abortable = false; - NetJobPtr m_filesNetJob; + shared_qobject_ptr m_network; + + NetJob::Ptr m_filesNetJob; QUrl m_sourceUrl; QString m_minecraftVersion; QByteArray m_response; diff --git a/launcher/net/Download.cpp b/launcher/net/Download.cpp index 48c49dde..b314573f 100644 --- a/launcher/net/Download.cpp +++ b/launcher/net/Download.cpp @@ -15,16 +15,17 @@ #include "Download.h" -#include "BuildConfig.h" #include #include #include -#include "Env.h" -#include + +#include "FileSystem.h" #include "ChecksumValidator.h" #include "MetaCacheSink.h" #include "ByteArraySink.h" +#include "BuildConfig.h" + namespace Net { Download::Download():NetAction() @@ -41,7 +42,7 @@ Download::Ptr Download::makeCached(QUrl url, MetaEntryPtr entry, Options options auto cachedNode = new MetaCacheSink(entry, md5Node); dl->m_sink.reset(cachedNode); dl->m_target_path = entry->getFullPath(); - return std::shared_ptr(dl); + return dl; } Download::Ptr Download::makeByteArray(QUrl url, QByteArray *output, Options options) @@ -50,7 +51,7 @@ Download::Ptr Download::makeByteArray(QUrl url, QByteArray *output, Options opti dl->m_url = url; dl->m_options = options; dl->m_sink.reset(new ByteArraySink(output)); - return std::shared_ptr(dl); + return dl; } Download::Ptr Download::makeFile(QUrl url, QString path, Options options) @@ -59,7 +60,7 @@ Download::Ptr Download::makeFile(QUrl url, QString path, Options options) dl->m_url = url; dl->m_options = options; dl->m_sink.reset(new FileSink(path)); - return std::shared_ptr(dl); + return dl; } void Download::addValidator(Validator * v) @@ -67,7 +68,7 @@ void Download::addValidator(Validator * v) m_sink->addValidator(v); } -void Download::start() +void Download::startImpl() { if(m_status == Job_Aborted) { @@ -97,7 +98,7 @@ void Download::start() request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT); - QNetworkReply *rep = ENV->network().get(request); + QNetworkReply *rep = m_network->get(request); m_reply.reset(rep); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64))); @@ -207,7 +208,7 @@ bool Download::handleRedirect() m_url = QUrl(redirect.toString()); qDebug() << "Following redirect to " << m_url.toString(); - start(); + start(m_network); return true; } diff --git a/launcher/net/Download.h b/launcher/net/Download.h index a224bb86..0f9bfe7f 100644 --- a/launcher/net/Download.h +++ b/launcher/net/Download.h @@ -20,13 +20,15 @@ #include "Validator.h" #include "Sink.h" +#include "QObjectPtr.h" + namespace Net { class Download : public NetAction { Q_OBJECT public: /* types */ - typedef std::shared_ptr Ptr; + typedef shared_qobject_ptr Ptr; enum class Option { NoOptions = 0, @@ -62,7 +64,7 @@ protected slots: void downloadReadyRead() override; public slots: - void start() override; + void startImpl() override; private: /* data */ // FIXME: remove this, it has no business being here. diff --git a/launcher/net/FileSink.cpp b/launcher/net/FileSink.cpp index 8b3e917d..7e9b8929 100644 --- a/launcher/net/FileSink.cpp +++ b/launcher/net/FileSink.cpp @@ -1,7 +1,6 @@ #include "FileSink.h" #include #include -#include "Env.h" #include "FileSystem.h" namespace Net { diff --git a/launcher/net/HttpMetaCache.cpp b/launcher/net/HttpMetaCache.cpp index 4bc8fbc8..8734e0bf 100644 --- a/launcher/net/HttpMetaCache.cpp +++ b/launcher/net/HttpMetaCache.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "Env.h" #include "HttpMetaCache.h" #include "FileSystem.h" diff --git a/launcher/net/MetaCacheSink.cpp b/launcher/net/MetaCacheSink.cpp index ae9314f1..5cdf0460 100644 --- a/launcher/net/MetaCacheSink.cpp +++ b/launcher/net/MetaCacheSink.cpp @@ -1,8 +1,8 @@ #include "MetaCacheSink.h" #include #include -#include "Env.h" #include "FileSystem.h" +#include "Application.h" namespace Net { @@ -53,7 +53,7 @@ JobStatus MetaCacheSink::finalizeCache(QNetworkReply & reply) } m_entry->setLocalChangedTimestamp(output_file_info.lastModified().toUTC().toMSecsSinceEpoch()); m_entry->setStale(false); - ENV->metacache()->updateEntry(m_entry); + APPLICATION->metacache()->updateEntry(m_entry); return Job_Finished; } diff --git a/launcher/net/NetAction.h b/launcher/net/NetAction.h index c13c187f..efb20953 100644 --- a/launcher/net/NetAction.h +++ b/launcher/net/NetAction.h @@ -35,14 +35,15 @@ enum JobStatus Job_Failed_Proceed }; -typedef std::shared_ptr NetActionPtr; class NetAction : public QObject { Q_OBJECT protected: - explicit NetAction() : QObject(0) {}; + explicit NetAction() : QObject(nullptr) {}; public: + using Ptr = shared_qobject_ptr; + virtual ~NetAction() {}; bool isRunning() const @@ -93,9 +94,17 @@ protected slots: virtual void downloadReadyRead() = 0; public slots: - virtual void start() = 0; + void start(shared_qobject_ptr network) { + m_network = network; + startImpl(); + } + +protected: + virtual void startImpl() = 0; public: + shared_qobject_ptr m_network; + /// index within the parent job, FIXME: nuke int m_index_within_job = 0; diff --git a/launcher/net/NetJob.cpp b/launcher/net/NetJob.cpp index 029d9e34..9bad89ed 100644 --- a/launcher/net/NetJob.cpp +++ b/launcher/net/NetJob.cpp @@ -144,7 +144,7 @@ void NetJob::startMoreParts() connect(part.get(), SIGNAL(aborted(int)), SLOT(partAborted(int))); connect(part.get(), SIGNAL(netActionProgress(int, qint64, qint64)), SLOT(partProgress(int, qint64, qint64))); - part->start(); + part->start(m_network); } } @@ -194,7 +194,7 @@ bool NetJob::abort() return fullyAborted; } -bool NetJob::addNetAction(NetActionPtr action) +bool NetJob::addNetAction(NetAction::Ptr action) { action->m_index_within_job = downloads.size(); downloads.append(action); diff --git a/launcher/net/NetJob.h b/launcher/net/NetJob.h index 338f8e71..45b9bc0f 100644 --- a/launcher/net/NetJob.h +++ b/launcher/net/NetJob.h @@ -22,33 +22,34 @@ #include "QObjectPtr.h" class NetJob; -typedef shared_qobject_ptr NetJobPtr; class NetJob : public Task { Q_OBJECT public: + using Ptr = shared_qobject_ptr; + explicit NetJob(QString job_name) : Task() { setObjectName(job_name); } virtual ~NetJob(); - bool addNetAction(NetActionPtr action); + bool addNetAction(NetAction::Ptr action); - NetActionPtr operator[](int index) + NetAction::Ptr operator[](int index) { return downloads[index]; } - const NetActionPtr at(const int index) + const NetAction::Ptr at(const int index) { return downloads.at(index); } - NetActionPtr first() + NetAction::Ptr first() { if (downloads.size()) return downloads[0]; - return NetActionPtr(); + return NetAction::Ptr(); } int size() const { @@ -64,6 +65,19 @@ private slots: public slots: virtual void executeTask() override; virtual bool abort() override; + virtual void start(shared_qobject_ptr network) { + m_network = network; + start(); + } + +protected slots: + void start() override { + if(!m_network) { + throw "Missing network while trying to start " + objectName(); + return; + } + Task::start(); + } private slots: void partProgress(int index, qint64 bytesReceived, qint64 bytesTotal); @@ -72,13 +86,15 @@ private slots: void partAborted(int index); private: + shared_qobject_ptr m_network; + struct part_info { qint64 current_progress = 0; qint64 total_progress = 1; int failures = 0; }; - QList downloads; + QList downloads; QList parts_progress; QQueue m_todo; QSet m_doing; diff --git a/launcher/net/PasteUpload.cpp b/launcher/net/PasteUpload.cpp index 159c3e2a..4b69b68a 100644 --- a/launcher/net/PasteUpload.cpp +++ b/launcher/net/PasteUpload.cpp @@ -1,11 +1,12 @@ #include "PasteUpload.h" -#include "Env.h" +#include "BuildConfig.h" +#include "Application.h" + #include #include #include #include #include -#include PasteUpload::PasteUpload(QWidget *window, QString text, QString key) : m_window(window) { @@ -41,7 +42,7 @@ void PasteUpload::executeTask() request.setRawHeader("Content-Length", QByteArray::number(m_jsonContent.size())); request.setRawHeader("X-Auth-Token", m_key.toStdString().c_str()); - QNetworkReply *rep = ENV->network().post(request, m_jsonContent); + QNetworkReply *rep = APPLICATION->network()->post(request, m_jsonContent); m_reply = std::shared_ptr(rep); setStatus(tr("Uploading to paste.ee")); diff --git a/launcher/news/NewsChecker.cpp b/launcher/news/NewsChecker.cpp index c66f49e1..77d428a5 100644 --- a/launcher/news/NewsChecker.cpp +++ b/launcher/news/NewsChecker.cpp @@ -20,8 +20,9 @@ #include -NewsChecker::NewsChecker(const QString& feedUrl) +NewsChecker::NewsChecker(shared_qobject_ptr network, const QString& feedUrl) { + m_network = network; m_feedUrl = feedUrl; } @@ -41,7 +42,7 @@ void NewsChecker::reloadNews() QObject::connect(job, &NetJob::succeeded, this, &NewsChecker::rssDownloadFinished); QObject::connect(job, &NetJob::failed, this, &NewsChecker::rssDownloadFailed); m_newsNetJob.reset(job); - job->start(); + job->start(m_network); } void NewsChecker::rssDownloadFinished() diff --git a/launcher/news/NewsChecker.h b/launcher/news/NewsChecker.h index 84b1f552..8467a541 100644 --- a/launcher/news/NewsChecker.h +++ b/launcher/news/NewsChecker.h @@ -30,7 +30,7 @@ public: /*! * Constructs a news reader to read from the given RSS feed URL. */ - NewsChecker(const QString& feedUrl); + NewsChecker(shared_qobject_ptr network, const QString& feedUrl); /*! * Returns the error message for the last time the news was loaded. @@ -80,7 +80,7 @@ protected: /* data */ QList m_newsEntries; //! The network job to use to load the news. - NetJobPtr m_newsNetJob; + NetJob::Ptr m_newsNetJob; //! True if news has been loaded. bool m_loadedNews; @@ -93,6 +93,8 @@ protected: /* data */ */ QString m_lastLoadError; + shared_qobject_ptr m_network; + protected slots: /// Emits newsLoaded() and sets m_lastLoadError to empty string. void succeed(); diff --git a/launcher/notifications/NotificationChecker.cpp b/launcher/notifications/NotificationChecker.cpp index 4ccd3d6c..00c918f8 100644 --- a/launcher/notifications/NotificationChecker.cpp +++ b/launcher/notifications/NotificationChecker.cpp @@ -5,9 +5,9 @@ #include #include -#include "Env.h" #include "net/Download.h" +#include "Application.h" NotificationChecker::NotificationChecker(QObject *parent) : QObject(parent) @@ -53,11 +53,11 @@ void NotificationChecker::checkForNotifications() return; } m_checkJob.reset(new NetJob("Checking for notifications")); - auto entry = ENV->metacache()->resolveEntry("root", "notifications.json"); + auto entry = APPLICATION->metacache()->resolveEntry("root", "notifications.json"); entry->setStale(true); m_checkJob->addNetAction(m_download = Net::Download::makeCached(m_notificationsUrl, entry)); connect(m_download.get(), &Net::Download::succeeded, this, &NotificationChecker::downloadSucceeded); - m_checkJob->start(); + m_checkJob->start(APPLICATION->network()); } void NotificationChecker::downloadSucceeded(int) diff --git a/launcher/notifications/NotificationChecker.h b/launcher/notifications/NotificationChecker.h index eb2b32a2..0f305f33 100644 --- a/launcher/notifications/NotificationChecker.h +++ b/launcher/notifications/NotificationChecker.h @@ -52,7 +52,7 @@ private: private: QList m_entries; QUrl m_notificationsUrl; - NetJobPtr m_checkJob; + NetJob::Ptr m_checkJob; Net::Download::Ptr m_download; QString m_appVersionChannel; diff --git a/launcher/pages/global/AccountListPage.cpp b/launcher/pages/global/AccountListPage.cpp index d0138dcc..1e175df7 100644 --- a/launcher/pages/global/AccountListPage.cpp +++ b/launcher/pages/global/AccountListPage.cpp @@ -22,7 +22,6 @@ #include #include "net/NetJob.h" -#include "Env.h" #include "dialogs/ProgressDialog.h" #include "dialogs/LoginDialog.h" diff --git a/launcher/pages/global/ProxyPage.cpp b/launcher/pages/global/ProxyPage.cpp index 622b8ef3..5bc8199e 100644 --- a/launcher/pages/global/ProxyPage.cpp +++ b/launcher/pages/global/ProxyPage.cpp @@ -20,7 +20,7 @@ #include "settings/SettingsObject.h" #include "Application.h" -#include "Env.h" +#include "Application.h" ProxyPage::ProxyPage(QWidget *parent) : QWidget(parent), ui(new Ui::ProxyPage) { @@ -77,8 +77,13 @@ void ProxyPage::applySettings() s->set("ProxyUser", ui->proxyUserEdit->text()); s->set("ProxyPass", ui->proxyPassEdit->text()); - ENV->updateProxySettings(proxyType, ui->proxyAddrEdit->text(), ui->proxyPortEdit->value(), - ui->proxyUserEdit->text(), ui->proxyPassEdit->text()); + APPLICATION->updateProxySettings( + proxyType, + ui->proxyAddrEdit->text(), + ui->proxyPortEdit->value(), + ui->proxyUserEdit->text(), + ui->proxyPassEdit->text() + ); } void ProxyPage::loadSettings() { diff --git a/launcher/pages/instance/ScreenshotsPage.cpp b/launcher/pages/instance/ScreenshotsPage.cpp index f303e9fa..b2d440c3 100644 --- a/launcher/pages/instance/ScreenshotsPage.cpp +++ b/launcher/pages/instance/ScreenshotsPage.cpp @@ -302,8 +302,8 @@ void ScreenshotsPage::on_actionUpload_triggered() if (selection.isEmpty()) return; - QList uploaded; - auto job = NetJobPtr(new NetJob("Screenshot Upload")); + QList uploaded; + auto job = NetJob::Ptr(new NetJob("Screenshot Upload")); if(selection.size() < 2) { auto item = selection.at(0); @@ -344,7 +344,7 @@ void ScreenshotsPage::on_actionUpload_triggered() job->addNetAction(ImgurUpload::make(screenshot)); } SequentialTask task; - auto albumTask = NetJobPtr(new NetJob("Imgur Album Creation")); + auto albumTask = NetJob::Ptr(new NetJob("Imgur Album Creation")); auto imgurAlbum = ImgurAlbumCreation::make(uploaded); albumTask->addNetAction(imgurAlbum); task.addTask(job); diff --git a/launcher/pages/instance/VersionPage.cpp b/launcher/pages/instance/VersionPage.cpp index 15d5d8d5..d36f7b8d 100644 --- a/launcher/pages/instance/VersionPage.cpp +++ b/launcher/pages/instance/VersionPage.cpp @@ -420,7 +420,7 @@ void VersionPage::on_actionDownload_All_triggered() void VersionPage::on_actionInstall_Forge_triggered() { - auto vlist = ENV->metadataIndex()->get("net.minecraftforge"); + auto vlist = APPLICATION->metadataIndex()->get("net.minecraftforge"); if(!vlist) { return; @@ -449,7 +449,7 @@ void VersionPage::on_actionInstall_Forge_triggered() void VersionPage::on_actionInstall_Fabric_triggered() { - auto vlist = ENV->metadataIndex()->get("net.fabricmc.fabric-loader"); + auto vlist = APPLICATION->metadataIndex()->get("net.fabricmc.fabric-loader"); if(!vlist) { return; @@ -494,7 +494,7 @@ void VersionPage::on_actionAdd_Empty_triggered() void VersionPage::on_actionInstall_LiteLoader_triggered() { - auto vlist = ENV->metadataIndex()->get("com.mumfrey.liteloader"); + auto vlist = APPLICATION->metadataIndex()->get("com.mumfrey.liteloader"); if(!vlist) { return; diff --git a/launcher/pages/modplatform/VanillaPage.cpp b/launcher/pages/modplatform/VanillaPage.cpp index 6dbc3970..4527d1a0 100644 --- a/launcher/pages/modplatform/VanillaPage.cpp +++ b/launcher/pages/modplatform/VanillaPage.cpp @@ -1,16 +1,15 @@ #include "VanillaPage.h" #include "ui_VanillaPage.h" -#include "Application.h" - -#include -#include -#include -#include -#include -#include #include +#include "Application.h" +#include "meta/Index.h" +#include "meta/VersionList.h" +#include "dialogs/NewInstanceDialog.h" +#include "Filter.h" +#include "InstanceCreationTask.h" + VanillaPage::VanillaPage(NewInstanceDialog *dialog, QWidget *parent) : QWidget(parent), dialog(dialog), ui(new Ui::VanillaPage) { @@ -31,7 +30,7 @@ void VanillaPage::openedImpl() { if(!initialized) { - auto vlist = ENV->metadataIndex()->get("net.minecraft"); + auto vlist = APPLICATION->metadataIndex()->get("net.minecraft"); ui->versionList->initialize(vlist.get()); initialized = true; } diff --git a/launcher/pages/modplatform/atlauncher/AtlListModel.cpp b/launcher/pages/modplatform/atlauncher/AtlListModel.cpp index 68234f6b..e8c6deee 100644 --- a/launcher/pages/modplatform/atlauncher/AtlListModel.cpp +++ b/launcher/pages/modplatform/atlauncher/AtlListModel.cpp @@ -2,7 +2,6 @@ #include #include -#include #include namespace Atl { @@ -75,7 +74,7 @@ void ListModel::request() auto url = QString(BuildConfig.ATL_DOWNLOAD_SERVER_URL + "launcher/json/packsnew.json"); netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), &response)); jobPtr = netJob; - jobPtr->start(); + jobPtr->start(APPLICATION->network()); QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::requestFinished); QObject::connect(netJob, &NetJob::failed, this, &ListModel::requestFailed); @@ -134,7 +133,7 @@ void ListModel::getLogo(const QString &logo, const QString &logoUrl, LogoCallbac { if(m_logoMap.contains(logo)) { - callback(ENV->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath()); + callback(APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath()); } else { @@ -167,7 +166,7 @@ void ListModel::requestLogo(QString file, QString url) return; } - MetaEntryPtr entry = ENV->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(file.section(".", 0, 0))); + MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("ATLauncherPacks", QString("logos/%1").arg(file.section(".", 0, 0))); NetJob *job = new NetJob(QString("ATLauncher Icon Download %1").arg(file)); job->addNetAction(Net::Download::makeCached(QUrl(url), entry)); @@ -186,7 +185,7 @@ void ListModel::requestLogo(QString file, QString url) emit logoFailed(file); }); - job->start(); + job->start(APPLICATION->network()); m_loadingLogos.append(file); } diff --git a/launcher/pages/modplatform/atlauncher/AtlListModel.h b/launcher/pages/modplatform/atlauncher/AtlListModel.h index 2d30a64e..79aa8180 100644 --- a/launcher/pages/modplatform/atlauncher/AtlListModel.h +++ b/launcher/pages/modplatform/atlauncher/AtlListModel.h @@ -45,7 +45,7 @@ private: LogoMap m_logoMap; QMap waitingCallbacks; - NetJobPtr jobPtr; + NetJob::Ptr jobPtr; QByteArray response; }; diff --git a/launcher/pages/modplatform/flame/FlameModel.cpp b/launcher/pages/modplatform/flame/FlameModel.cpp index c983eefd..a05ab641 100644 --- a/launcher/pages/modplatform/flame/FlameModel.cpp +++ b/launcher/pages/modplatform/flame/FlameModel.cpp @@ -9,7 +9,6 @@ #include #include -#include namespace Flame { @@ -100,7 +99,7 @@ void ListModel::requestLogo(QString logo, QString url) return; } - MetaEntryPtr entry = ENV->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo.section(".", 0, 0))); + MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo.section(".", 0, 0))); NetJob *job = new NetJob(QString("Flame Icon Download %1").arg(logo)); job->addNetAction(Net::Download::makeCached(QUrl(url), entry)); @@ -119,7 +118,7 @@ void ListModel::requestLogo(QString logo, QString url) emit logoFailed(logo); }); - job->start(); + job->start(APPLICATION->network()); m_loadingLogos.append(logo); } @@ -128,7 +127,7 @@ void ListModel::getLogo(const QString &logo, const QString &logoUrl, LogoCallbac { if(m_logoMap.contains(logo)) { - callback(ENV->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath()); + callback(APPLICATION->metacache()->resolveEntry("FlamePacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath()); } else { @@ -172,7 +171,7 @@ void ListModel::performPaginatedSearch() ).arg(nextSearchOffset).arg(currentSearchTerm).arg(currentSort); netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); jobPtr = netJob; - jobPtr->start(); + jobPtr->start(APPLICATION->network()); QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::searchRequestFinished); QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed); } diff --git a/launcher/pages/modplatform/flame/FlameModel.h b/launcher/pages/modplatform/flame/FlameModel.h index 24383db0..536f6add 100644 --- a/launcher/pages/modplatform/flame/FlameModel.h +++ b/launcher/pages/modplatform/flame/FlameModel.h @@ -69,7 +69,7 @@ private: ResetRequested, Finished } searchState = None; - NetJobPtr jobPtr; + NetJob::Ptr jobPtr; QByteArray response; }; diff --git a/launcher/pages/modplatform/flame/FlamePage.cpp b/launcher/pages/modplatform/flame/FlamePage.cpp index 11fc4222..b3e30d5a 100644 --- a/launcher/pages/modplatform/flame/FlamePage.cpp +++ b/launcher/pages/modplatform/flame/FlamePage.cpp @@ -139,7 +139,7 @@ void FlamePage::onSelectionChanged(QModelIndex first, QModelIndex second) suggestCurrent(); }); - netJob->start(); + netJob->start(APPLICATION->network()); } else { diff --git a/launcher/pages/modplatform/ftb/FtbListModel.cpp b/launcher/pages/modplatform/ftb/FtbListModel.cpp index 16a744cf..59cd0b85 100644 --- a/launcher/pages/modplatform/ftb/FtbListModel.cpp +++ b/launcher/pages/modplatform/ftb/FtbListModel.cpp @@ -1,7 +1,6 @@ #include "FtbListModel.h" #include "BuildConfig.h" -#include "Env.h" #include "Application.h" #include "Json.h" @@ -78,7 +77,7 @@ void ListModel::getLogo(const QString &logo, const QString &logoUrl, LogoCallbac { if(m_logoMap.contains(logo)) { - callback(ENV->metacache()->resolveEntry("ModpacksCHPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath()); + callback(APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath()); } else { @@ -96,7 +95,7 @@ void ListModel::request() auto url = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/all"); netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), &response)); jobPtr = netJob; - jobPtr->start(); + jobPtr->start(APPLICATION->network()); QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::requestFinished); QObject::connect(netJob, &NetJob::failed, this, &ListModel::requestFailed); @@ -140,7 +139,7 @@ void ListModel::requestPack() .arg(currentPack); netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); jobPtr = netJob; - jobPtr->start(); + jobPtr->start(APPLICATION->network()); QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::packRequestFinished); QObject::connect(netJob, &NetJob::failed, this, &ListModel::packRequestFailed); @@ -252,7 +251,7 @@ void ListModel::requestLogo(QString logo, QString url) return; } - MetaEntryPtr entry = ENV->metacache()->resolveEntry("ModpacksCHPacks", QString("logos/%1").arg(logo.section(".", 0, 0))); + MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", QString("logos/%1").arg(logo.section(".", 0, 0))); bool stale = entry->isStale(); @@ -273,7 +272,7 @@ void ListModel::requestLogo(QString logo, QString url) auto &newLogoEntry = m_logoMap[logo]; newLogoEntry.downloadJob = job; newLogoEntry.fullpath = fullPath; - job->start(); + job->start(APPLICATION->network()); } } diff --git a/launcher/pages/modplatform/ftb/FtbListModel.h b/launcher/pages/modplatform/ftb/FtbListModel.h index 2d6e91da..e2b73c25 100644 --- a/launcher/pages/modplatform/ftb/FtbListModel.h +++ b/launcher/pages/modplatform/ftb/FtbListModel.h @@ -10,7 +10,7 @@ namespace Ftb { struct Logo { QString fullpath; - NetJobPtr downloadJob; + NetJob::Ptr downloadJob; QIcon result; bool failed = false; }; @@ -52,7 +52,7 @@ private: QList modpacks; LogoMap m_logoMap; - NetJobPtr jobPtr; + NetJob::Ptr jobPtr; int currentPack; QList remainingPacks; QByteArray response; diff --git a/launcher/pages/modplatform/legacy_ftb/ListModel.cpp b/launcher/pages/modplatform/legacy_ftb/ListModel.cpp index dfef278b..5fa932b7 100644 --- a/launcher/pages/modplatform/legacy_ftb/ListModel.cpp +++ b/launcher/pages/modplatform/legacy_ftb/ListModel.cpp @@ -8,7 +8,6 @@ #include #include -#include #include @@ -216,7 +215,7 @@ void ListModel::requestLogo(QString file) return; } - MetaEntryPtr entry = ENV->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file.section(".", 0, 0))); + MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(file.section(".", 0, 0))); NetJob *job = new NetJob(QString("FTB Icon Download for %1").arg(file)); job->addNetAction(Net::Download::makeCached(QUrl(QString(BuildConfig.LEGACY_FTB_CDN_BASE_URL + "static/%1").arg(file)), entry)); @@ -235,7 +234,7 @@ void ListModel::requestLogo(QString file) emit logoFailed(file); }); - job->start(); + job->start(APPLICATION->network()); m_loadingLogos.append(file); } @@ -244,7 +243,7 @@ void ListModel::getLogo(const QString &logo, LogoCallback callback) { if(m_logoMap.contains(logo)) { - callback(ENV->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath()); + callback(APPLICATION->metacache()->resolveEntry("FTBPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath()); } else { diff --git a/launcher/pages/modplatform/legacy_ftb/Page.cpp b/launcher/pages/modplatform/legacy_ftb/Page.cpp index 93002a87..ecd9fece 100644 --- a/launcher/pages/modplatform/legacy_ftb/Page.cpp +++ b/launcher/pages/modplatform/legacy_ftb/Page.cpp @@ -16,7 +16,7 @@ namespace LegacyFTB { Page::Page(NewInstanceDialog* dialog, QWidget *parent) : QWidget(parent), dialog(dialog), ui(new Ui::Page) { - ftbFetchTask.reset(new PackFetchTask()); + ftbFetchTask.reset(new PackFetchTask(APPLICATION->network())); ftbPrivatePacks.reset(new PrivatePackManager()); ui->setupUi(this); @@ -133,7 +133,7 @@ void Page::suggestCurrent() return; } - dialog->setSuggestedPack(selected.name, new PackInstallTask(selected, selectedVersion)); + dialog->setSuggestedPack(selected.name, new PackInstallTask(APPLICATION->network(), selected, selectedVersion)); QString editedLogoName; if(selected.logo.toLower().startsWith("ftb")) { diff --git a/launcher/pages/modplatform/technic/TechnicModel.cpp b/launcher/pages/modplatform/technic/TechnicModel.cpp index a07395ef..63c2d4c4 100644 --- a/launcher/pages/modplatform/technic/TechnicModel.cpp +++ b/launcher/pages/modplatform/technic/TechnicModel.cpp @@ -14,7 +14,6 @@ */ #include "TechnicModel.h" -#include "Env.h" #include "Application.h" #include "Json.h" @@ -105,7 +104,7 @@ void Technic::ListModel::performSearch() } netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); jobPtr = netJob; - jobPtr->start(); + jobPtr->start(APPLICATION->network()); QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::searchRequestFinished); QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed); } @@ -163,7 +162,7 @@ void Technic::ListModel::getLogo(const QString& logo, const QString& logoUrl, Te { if(m_logoMap.contains(logo)) { - callback(ENV->metacache()->resolveEntry("TechnicPacks", QString("logos/%1").arg(logo))->getFullPath()); + callback(APPLICATION->metacache()->resolveEntry("TechnicPacks", QString("logos/%1").arg(logo))->getFullPath()); } else { @@ -216,7 +215,7 @@ void Technic::ListModel::requestLogo(QString logo, QString url) return; } - MetaEntryPtr entry = ENV->metacache()->resolveEntry("TechnicPacks", QString("logos/%1").arg(logo)); + MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("TechnicPacks", QString("logos/%1").arg(logo)); NetJob *job = new NetJob(QString("Technic Icon Download %1").arg(logo)); job->addNetAction(Net::Download::makeCached(QUrl(url), entry)); @@ -232,7 +231,7 @@ void Technic::ListModel::requestLogo(QString logo, QString url) logoFailed(logo); }); - job->start(); + job->start(APPLICATION->network()); m_loadingLogos.append(logo); } diff --git a/launcher/pages/modplatform/technic/TechnicModel.h b/launcher/pages/modplatform/technic/TechnicModel.h index 82a03842..e80e6e7c 100644 --- a/launcher/pages/modplatform/technic/TechnicModel.h +++ b/launcher/pages/modplatform/technic/TechnicModel.h @@ -63,7 +63,7 @@ private: ResetRequested, Finished } searchState = None; - NetJobPtr jobPtr; + NetJob::Ptr jobPtr; QByteArray response; }; diff --git a/launcher/pages/modplatform/technic/TechnicPage.cpp b/launcher/pages/modplatform/technic/TechnicPage.cpp index 2befda04..1e4f4106 100644 --- a/launcher/pages/modplatform/technic/TechnicPage.cpp +++ b/launcher/pages/modplatform/technic/TechnicPage.cpp @@ -164,7 +164,7 @@ void TechnicPage::suggestCurrent() current.metadataLoaded = true; metadataLoaded(); }); - netJob->start(); + netJob->start(APPLICATION->network()); } // expects current.metadataLoaded to be true @@ -193,6 +193,6 @@ void TechnicPage::metadataLoaded() else { while (current.url.endsWith('/')) current.url.chop(1); - dialog->setSuggestedPack(current.name, new Technic::SolderPackInstallTask(current.url + "/modpack/" + current.slug, current.minecraftVersion)); + dialog->setSuggestedPack(current.name, new Technic::SolderPackInstallTask(APPLICATION->network(), current.url + "/modpack/" + current.slug, current.minecraftVersion)); } } diff --git a/launcher/screenshots/ImgurAlbumCreation.cpp b/launcher/screenshots/ImgurAlbumCreation.cpp index d1b21f5f..d5de302a 100644 --- a/launcher/screenshots/ImgurAlbumCreation.cpp +++ b/launcher/screenshots/ImgurAlbumCreation.cpp @@ -5,18 +5,18 @@ #include #include #include - -#include "BuildConfig.h" -#include "Env.h" #include -ImgurAlbumCreation::ImgurAlbumCreation(QList screenshots) : NetAction(), m_screenshots(screenshots) +#include "BuildConfig.h" +#include "Application.h" + +ImgurAlbumCreation::ImgurAlbumCreation(QList screenshots) : NetAction(), m_screenshots(screenshots) { m_url = BuildConfig.IMGUR_BASE_URL + "album.json"; m_status = Job_NotStarted; } -void ImgurAlbumCreation::start() +void ImgurAlbumCreation::startImpl() { m_status = Job_InProgress; QNetworkRequest request(m_url); @@ -33,7 +33,7 @@ void ImgurAlbumCreation::start() const QByteArray data = "deletehashes=" + hashes.join(',').toUtf8() + "&title=Minecraft%20Screenshots&privacy=hidden"; - QNetworkReply *rep = ENV->network().post(request, data); + QNetworkReply *rep = APPLICATION->network()->post(request, data); m_reply.reset(rep); connect(rep, &QNetworkReply::uploadProgress, this, &ImgurAlbumCreation::downloadProgress); diff --git a/launcher/screenshots/ImgurAlbumCreation.h b/launcher/screenshots/ImgurAlbumCreation.h index 954637e6..cb048a23 100644 --- a/launcher/screenshots/ImgurAlbumCreation.h +++ b/launcher/screenshots/ImgurAlbumCreation.h @@ -1,13 +1,14 @@ #pragma once #include "net/NetAction.h" #include "Screenshot.h" +#include "QObjectPtr.h" -typedef std::shared_ptr ImgurAlbumCreationPtr; +typedef shared_qobject_ptr ImgurAlbumCreationPtr; class ImgurAlbumCreation : public NetAction { public: - explicit ImgurAlbumCreation(QList screenshots); - static ImgurAlbumCreationPtr make(QList screenshots) + explicit ImgurAlbumCreation(QList screenshots); + static ImgurAlbumCreationPtr make(QList screenshots) { return ImgurAlbumCreationPtr(new ImgurAlbumCreation(screenshots)); } @@ -32,10 +33,10 @@ slots: public slots: - virtual void start(); + virtual void startImpl(); private: - QList m_screenshots; + QList m_screenshots; QString m_deleteHash; QString m_id; diff --git a/launcher/screenshots/ImgurUpload.cpp b/launcher/screenshots/ImgurUpload.cpp index dfdbf2e8..76a84947 100644 --- a/launcher/screenshots/ImgurUpload.cpp +++ b/launcher/screenshots/ImgurUpload.cpp @@ -1,4 +1,5 @@ #include "ImgurUpload.h" +#include "BuildConfig.h" #include #include @@ -7,18 +8,15 @@ #include #include #include - -#include "BuildConfig.h" -#include "Env.h" #include -ImgurUpload::ImgurUpload(ScreenshotPtr shot) : NetAction(), m_shot(shot) +ImgurUpload::ImgurUpload(ScreenShot::Ptr shot) : NetAction(), m_shot(shot) { m_url = BuildConfig.IMGUR_BASE_URL + "upload.json"; m_status = Job_NotStarted; } -void ImgurUpload::start() +void ImgurUpload::startImpl() { finished = false; m_status = Job_InProgress; @@ -49,7 +47,7 @@ void ImgurUpload::start() namePart.setBody(m_shot->m_file.baseName().toUtf8()); multipart->append(namePart); - QNetworkReply *rep = ENV->network().post(request, multipart); + QNetworkReply *rep = m_network->post(request, multipart); m_reply.reset(rep); connect(rep, &QNetworkReply::uploadProgress, this, &ImgurUpload::downloadProgress); diff --git a/launcher/screenshots/ImgurUpload.h b/launcher/screenshots/ImgurUpload.h index 0507d499..ac57d1ba 100644 --- a/launcher/screenshots/ImgurUpload.h +++ b/launcher/screenshots/ImgurUpload.h @@ -1,15 +1,15 @@ #pragma once +#include "QObjectPtr.h" #include "net/NetAction.h" #include "Screenshot.h" -typedef std::shared_ptr ImgurUploadPtr; -class ImgurUpload : public NetAction -{ +class ImgurUpload : public NetAction { public: - explicit ImgurUpload(ScreenshotPtr shot); - static ImgurUploadPtr make(ScreenshotPtr shot) - { - return ImgurUploadPtr(new ImgurUpload(shot)); + using Ptr = shared_qobject_ptr; + + explicit ImgurUpload(ScreenShot::Ptr shot); + static Ptr make(ScreenShot::Ptr shot) { + return Ptr(new ImgurUpload(shot)); } protected @@ -17,15 +17,13 @@ slots: virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); virtual void downloadError(QNetworkReply::NetworkError error); virtual void downloadFinished(); - virtual void downloadReadyRead() - { - } + virtual void downloadReadyRead() {} public slots: - virtual void start(); + void startImpl() override; private: - ScreenshotPtr m_shot; + ScreenShot::Ptr m_shot; bool finished = true; }; diff --git a/launcher/screenshots/Screenshot.h b/launcher/screenshots/Screenshot.h index 9db3a8a1..ca45aabf 100644 --- a/launcher/screenshots/Screenshot.h +++ b/launcher/screenshots/Screenshot.h @@ -5,10 +5,10 @@ #include #include -struct ScreenShot -{ - ScreenShot(QFileInfo file) - { +struct ScreenShot { + using Ptr = std::shared_ptr; + + ScreenShot(QFileInfo file) { m_file = file; } QFileInfo m_file; @@ -16,5 +16,3 @@ struct ScreenShot QString m_imgurId; QString m_imgurDeleteHash; }; - -typedef std::shared_ptr ScreenshotPtr; diff --git a/launcher/tasks/Task.h b/launcher/tasks/Task.h index 2367f1ec..9cf08dbd 100644 --- a/launcher/tasks/Task.h +++ b/launcher/tasks/Task.h @@ -19,10 +19,14 @@ #include #include +#include "QObjectPtr.h" + class Task : public QObject { Q_OBJECT public: + using Ptr = shared_qobject_ptr; + enum class State { Inactive, diff --git a/launcher/translations/TranslationsModel.cpp b/launcher/translations/TranslationsModel.cpp index b96f87d7..ce53ac32 100644 --- a/launcher/translations/TranslationsModel.cpp +++ b/launcher/translations/TranslationsModel.cpp @@ -6,15 +6,17 @@ #include #include #include -#include -#include -#include -#include -#include + +#include "FileSystem.h" +#include "net/NetJob.h" +#include "net/ChecksumValidator.h" +#include "BuildConfig.h" #include "Json.h" #include "POTranslator.h" +#include "Application.h" + const static QLatin1Literal defaultLangCode("en_US"); enum class FileType @@ -119,10 +121,10 @@ struct TranslationsModel::Private std::unique_ptr m_qt_translator; std::unique_ptr m_app_translator; - std::shared_ptr m_index_task; + Net::Download::Ptr m_index_task; QString m_downloadingTranslation; - NetJobPtr m_dl_job; - NetJobPtr m_index_job; + NetJob::Ptr m_dl_job; + NetJob::Ptr m_index_job; QString m_nextDownload; std::unique_ptr m_po_translator; @@ -558,13 +560,13 @@ void TranslationsModel::downloadIndex() } qDebug() << "Downloading Translations Index..."; d->m_index_job.reset(new NetJob("Translations Index")); - MetaEntryPtr entry = ENV->metacache()->resolveEntry("translations", "index_v2.json"); + MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("translations", "index_v2.json"); entry->setStale(true); d->m_index_task = Net::Download::makeCached(QUrl("https://files.multimc.org/translations/index_v2.json"), entry); d->m_index_job->addNetAction(d->m_index_task); connect(d->m_index_job.get(), &NetJob::failed, this, &TranslationsModel::indexFailed); connect(d->m_index_job.get(), &NetJob::succeeded, this, &TranslationsModel::indexReceived); - d->m_index_job->start(); + d->m_index_job->start(APPLICATION->network()); } void TranslationsModel::updateLanguage(QString key) @@ -601,7 +603,7 @@ void TranslationsModel::downloadTranslation(QString key) } d->m_downloadingTranslation = key; - MetaEntryPtr entry = ENV->metacache()->resolveEntry("translations", "mmc_" + key + ".qm"); + MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("translations", "mmc_" + key + ".qm"); entry->setStale(true); auto dl = Net::Download::makeCached(QUrl(BuildConfig.TRANSLATIONS_BASE_URL + lang->file_name), entry); @@ -615,7 +617,7 @@ void TranslationsModel::downloadTranslation(QString key) connect(d->m_dl_job.get(), &NetJob::succeeded, this, &TranslationsModel::dlGood); connect(d->m_dl_job.get(), &NetJob::failed, this, &TranslationsModel::dlFailed); - d->m_dl_job->start(); + d->m_dl_job->start(APPLICATION->network()); } void TranslationsModel::downloadNext() diff --git a/launcher/updater/DownloadTask.cpp b/launcher/updater/DownloadTask.cpp index 875d9d84..eba59142 100644 --- a/launcher/updater/DownloadTask.cpp +++ b/launcher/updater/DownloadTask.cpp @@ -26,8 +26,12 @@ namespace GoUpdate { -DownloadTask::DownloadTask(Status status, QString target, QObject *parent) - : Task(parent), m_updateFilesDir(target) +DownloadTask::DownloadTask( + shared_qobject_ptr network, + Status status, + QString target, + QObject *parent +) : Task(parent), m_updateFilesDir(target), m_network(network) { m_status = status; @@ -63,7 +67,7 @@ void DownloadTask::loadVersionInfo() connect(netJob, &NetJob::succeeded, this, &DownloadTask::processDownloadedVersionInfo); connect(netJob, &NetJob::failed, this, &DownloadTask::vinfoDownloadFailed); m_vinfoNetJob.reset(netJob); - netJob->start(); + netJob->start(m_network); } void DownloadTask::vinfoDownloadFailed() @@ -117,7 +121,7 @@ void DownloadTask::processDownloadedVersionInfo() setStatus(tr("Processing file lists - figuring out how to install the update...")); // make a new netjob for the actual update files - NetJobPtr netJob (new NetJob("Update Files")); + NetJob::Ptr netJob (new NetJob("Update Files")); // fill netJob and operationList if (!processFileLists(m_currentVersionFileList, m_newVersionFileList, m_status.rootPath, m_updateFilesDir.path(), netJob, m_operations)) @@ -141,7 +145,7 @@ void DownloadTask::processDownloadedVersionInfo() } qDebug() << "Begin downloading update files to" << m_updateFilesDir.path(); m_filesNetJob = netJob; - m_filesNetJob->start(); + m_filesNetJob->start(m_network); } void DownloadTask::fileDownloadFinished() diff --git a/launcher/updater/DownloadTask.h b/launcher/updater/DownloadTask.h index fc5030b4..eac26238 100644 --- a/launcher/updater/DownloadTask.h +++ b/launcher/updater/DownloadTask.h @@ -35,7 +35,7 @@ public: * * target is a template - XXXXXX at the end will be replaced with a random generated string, ensuring uniqueness */ - explicit DownloadTask(Status status, QString target, QObject* parent = 0); + explicit DownloadTask(shared_qobject_ptr network, Status status, QString target, QObject* parent = 0); virtual ~DownloadTask() {}; /// Get the directory that will contain the update files. @@ -62,13 +62,13 @@ protected: */ void loadVersionInfo(); - NetJobPtr m_vinfoNetJob; + NetJob::Ptr m_vinfoNetJob; QByteArray currentVersionFileListData; QByteArray newVersionFileListData; Net::Download::Ptr m_currentVersionFileListDownload; Net::Download::Ptr m_newVersionFileListDownload; - NetJobPtr m_filesNetJob; + NetJob::Ptr m_filesNetJob; Status m_status; @@ -91,6 +91,9 @@ protected slots: void fileDownloadFinished(); void fileDownloadFailed(QString reason); void fileDownloadProgressChanged(qint64 current, qint64 total); + +private: + shared_qobject_ptr m_network; }; } diff --git a/launcher/updater/GoUpdate.cpp b/launcher/updater/GoUpdate.cpp index 6167418e..76f68b55 100644 --- a/launcher/updater/GoUpdate.cpp +++ b/launcher/updater/GoUpdate.cpp @@ -68,7 +68,7 @@ bool processFileLists const VersionFileList &newVersion, const QString &rootPath, const QString &tempPath, - NetJobPtr job, + NetJob::Ptr job, OperationList &ops ) { diff --git a/launcher/updater/GoUpdate.h b/launcher/updater/GoUpdate.h index 8058e543..46a679ef 100644 --- a/launcher/updater/GoUpdate.h +++ b/launcher/updater/GoUpdate.h @@ -117,7 +117,7 @@ bool processFileLists const VersionFileList &newVersion, const QString &rootPath, const QString &tempPath, - NetJobPtr job, + NetJob::Ptr job, OperationList &ops ); diff --git a/launcher/updater/UpdateChecker.cpp b/launcher/updater/UpdateChecker.cpp index c96a6c9f..c72bbe0b 100644 --- a/launcher/updater/UpdateChecker.cpp +++ b/launcher/updater/UpdateChecker.cpp @@ -26,8 +26,9 @@ #include "BuildConfig.h" #include "sys.h" -UpdateChecker::UpdateChecker(QString channelUrl, QString currentChannel, int currentBuild) +UpdateChecker::UpdateChecker(shared_qobject_ptr nam, QString channelUrl, QString currentChannel, int currentBuild) { + m_network = nam; m_channelUrl = channelUrl; m_currentChannel = currentChannel; m_currentBuild = currentBuild; @@ -103,12 +104,11 @@ void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate) QUrl indexUrl = QUrl(m_newRepoUrl).resolved(QUrl("index.json")); - auto job = new NetJob("GoUpdate Repository Index"); - job->addNetAction(Net::Download::makeByteArray(indexUrl, &indexData)); - connect(job, &NetJob::succeeded, [this, notifyNoUpdate](){ updateCheckFinished(notifyNoUpdate); }); - connect(job, &NetJob::failed, this, &UpdateChecker::updateCheckFailed); - indexJob.reset(job); - job->start(); + indexJob = new NetJob("GoUpdate Repository Index"); + indexJob->addNetAction(Net::Download::makeByteArray(indexUrl, &indexData)); + connect(indexJob.get(), &NetJob::succeeded, [this, notifyNoUpdate](){ updateCheckFinished(notifyNoUpdate); }); + connect(indexJob.get(), &NetJob::failed, this, &UpdateChecker::updateCheckFailed); + indexJob->start(m_network); } void UpdateChecker::updateCheckFinished(bool notifyNoUpdate) @@ -191,12 +191,11 @@ void UpdateChecker::updateChanList(bool notifyNoUpdate) } m_chanListLoading = true; - NetJob *job = new NetJob("Update System Channel List"); - job->addNetAction(Net::Download::makeByteArray(QUrl(m_channelUrl), &chanlistData)); - connect(job, &NetJob::succeeded, [this, notifyNoUpdate]() { chanListDownloadFinished(notifyNoUpdate); }); - QObject::connect(job, &NetJob::failed, this, &UpdateChecker::chanListDownloadFailed); - chanListJob.reset(job); - job->start(); + chanListJob = new NetJob("Update System Channel List"); + chanListJob->addNetAction(Net::Download::makeByteArray(QUrl(m_channelUrl), &chanlistData)); + connect(chanListJob.get(), &NetJob::succeeded, [this, notifyNoUpdate]() { chanListDownloadFinished(notifyNoUpdate); }); + connect(chanListJob.get(), &NetJob::failed, this, &UpdateChecker::chanListDownloadFailed); + chanListJob->start(m_network); } void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate) @@ -233,10 +232,12 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate) for (QJsonValue chanVal : channelArray) { QJsonObject channelObj = chanVal.toObject(); - ChannelListEntry entry{channelObj.value("id").toVariant().toString(), - channelObj.value("name").toVariant().toString(), - channelObj.value("description").toVariant().toString(), - channelObj.value("url").toVariant().toString()}; + ChannelListEntry entry { + channelObj.value("id").toVariant().toString(), + channelObj.value("name").toVariant().toString(), + channelObj.value("description").toVariant().toString(), + channelObj.value("url").toVariant().toString() + }; if (entry.id.isEmpty() || entry.name.isEmpty() || entry.url.isEmpty()) { qCritical() << "Channel list entry with empty ID, name, or URL. Skipping."; @@ -253,8 +254,9 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate) qDebug() << "Successfully loaded UpdateChecker channel list."; // If we're waiting to check for updates, do that now. - if (m_checkUpdateWaiting) + if (m_checkUpdateWaiting) { checkForUpdate(m_deferredUpdateChannel, notifyNoUpdate); + } emit channelListLoaded(); } diff --git a/launcher/updater/UpdateChecker.h b/launcher/updater/UpdateChecker.h index 219c3c62..13ee4efd 100644 --- a/launcher/updater/UpdateChecker.h +++ b/launcher/updater/UpdateChecker.h @@ -23,7 +23,7 @@ class UpdateChecker : public QObject Q_OBJECT public: - UpdateChecker(QString channelUrl, QString currentChannel, int currentBuild); + UpdateChecker(shared_qobject_ptr nam, QString channelUrl, QString currentChannel, int currentBuild); void checkForUpdate(QString updateChannel, bool notifyNoUpdate); /*! @@ -73,9 +73,11 @@ private slots: private: friend class UpdateCheckerTest; - NetJobPtr indexJob; + shared_qobject_ptr m_network; + + NetJob::Ptr indexJob; QByteArray indexData; - NetJobPtr chanListJob; + NetJob::Ptr chanListJob; QByteArray chanlistData; QString m_channelUrl; diff --git a/launcher/updater/UpdateChecker_test.cpp b/launcher/updater/UpdateChecker_test.cpp index 5702d9c6..ec55a40e 100644 --- a/launcher/updater/UpdateChecker_test.cpp +++ b/launcher/updater/UpdateChecker_test.cpp @@ -91,7 +91,8 @@ slots: QFETCH(bool, valid); QFETCH(QList, result); - UpdateChecker checker(channelUrl, channel, 0); + shared_qobject_ptr nam = new QNetworkAccessManager(); + UpdateChecker checker(nam, channelUrl, channel, 0); QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded())); QVERIFY(channelListLoadedSpy.isValid()); @@ -119,7 +120,8 @@ slots: QString channelUrl = findTestDataUrl("data/channels.json"); int currentBuild = 2; - UpdateChecker checker(channelUrl, channel, currentBuild); + shared_qobject_ptr nam = new QNetworkAccessManager(); + UpdateChecker checker(nam, channelUrl, channel, currentBuild); QSignalSpy updateAvailableSpy(&checker, SIGNAL(updateAvailable(GoUpdate::Status))); QVERIFY(updateAvailableSpy.isValid());