NOISSUE continue refactoring things to make tests pass

This commit is contained in:
Petr Mrázek 2021-11-21 23:21:12 +01:00
parent c2c56a2f6c
commit 69213b1206
103 changed files with 634 additions and 773 deletions

View File

@ -47,7 +47,6 @@
#include <minecraft/auth/AccountList.h>
#include "icons/IconList.h"
#include "net/HttpMetaCache.h"
#include "Env.h"
#include "java/JavaUtils.h"
@ -62,6 +61,7 @@
#include "settings/Setting.h"
#include "translations/TranslationsModel.h"
#include "meta/Index.h"
#include <Commandline.h>
#include <FileSystem.h>
@ -520,10 +520,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
FS::updateTimestamp(m_rootPath);
#endif
#ifdef MULTIMC_JARS_LOCATION
ENV->setJarsPath( TOSTRING(MULTIMC_JARS_LOCATION) );
#endif
qDebug() << BuildConfig.LAUNCHER_DISPLAYNAME << ", (c) 2013-2021 " << BuildConfig.LAUNCHER_COPYRIGHT;
qDebug() << "Version : " << BuildConfig.printableVersionString();
qDebug() << "Git commit : " << BuildConfig.GIT_COMMIT;
@ -730,6 +726,18 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
QAccessible::installFactory(groupViewAccessibleFactory);
#endif /* !QT_NO_ACCESSIBILITY */
// initialize network access and proxy setup
{
m_network = new QNetworkAccessManager();
QString proxyTypeStr = settings()->get("ProxyType").toString();
QString addr = settings()->get("ProxyAddr").toString();
int port = settings()->get("ProxyPort").value<qint16>();
QString user = settings()->get("ProxyUser").toString();
QString pass = settings()->get("ProxyPass").toString();
updateProxySettings(proxyTypeStr, addr, port, user, pass);
qDebug() << "<> Network done.";
}
// load translations
{
m_translations.reset(new TranslationsModel("translations"));
@ -745,7 +753,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
auto platform = getIdealPlatform(BuildConfig.BUILD_PLATFORM);
auto channelUrl = BuildConfig.UPDATER_BASE + platform + "/channels.json";
qDebug() << "Initializing updater with platform: " << platform << " -- " << channelUrl;
m_updateChecker.reset(new UpdateChecker(channelUrl, BuildConfig.VERSION_CHANNEL, BuildConfig.VERSION_BUILD));
m_updateChecker.reset(new UpdateChecker(m_network, channelUrl, BuildConfig.VERSION_CHANNEL, BuildConfig.VERSION_BUILD));
qDebug() << "<> Updater started.";
}
@ -764,7 +772,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
{
m_icons->directoryChanged(value.toString());
});
ENV->registerIconList(m_icons);
qDebug() << "<> Instance icons intialized.";
}
@ -821,21 +828,28 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
// init the http meta cache
{
ENV->initHttpMetaCache();
m_metacache.reset(new HttpMetaCache("metacache"));
m_metacache->addBase("asset_indexes", QDir("assets/indexes").absolutePath());
m_metacache->addBase("asset_objects", QDir("assets/objects").absolutePath());
m_metacache->addBase("versions", QDir("versions").absolutePath());
m_metacache->addBase("libraries", QDir("libraries").absolutePath());
m_metacache->addBase("minecraftforge", QDir("mods/minecraftforge").absolutePath());
m_metacache->addBase("fmllibs", QDir("mods/minecraftforge/libs").absolutePath());
m_metacache->addBase("liteloader", QDir("mods/liteloader").absolutePath());
m_metacache->addBase("general", QDir("cache").absolutePath());
m_metacache->addBase("ATLauncherPacks", QDir("cache/ATLauncherPacks").absolutePath());
m_metacache->addBase("FTBPacks", QDir("cache/FTBPacks").absolutePath());
m_metacache->addBase("ModpacksCHPacks", QDir("cache/ModpacksCHPacks").absolutePath());
m_metacache->addBase("TechnicPacks", QDir("cache/TechnicPacks").absolutePath());
m_metacache->addBase("FlamePacks", QDir("cache/FlamePacks").absolutePath());
m_metacache->addBase("root", QDir::currentPath());
m_metacache->addBase("translations", QDir("translations").absolutePath());
m_metacache->addBase("icons", QDir("cache/icons").absolutePath());
m_metacache->addBase("meta", QDir("meta").absolutePath());
m_metacache->Load();
qDebug() << "<> Cache initialized.";
}
// init proxy settings
{
QString proxyTypeStr = settings()->get("ProxyType").toString();
QString addr = settings()->get("ProxyAddr").toString();
int port = settings()->get("ProxyPort").value<qint16>();
QString user = settings()->get("ProxyUser").toString();
QString pass = settings()->get("ProxyPass").toString();
ENV->updateProxySettings(proxyTypeStr, addr, port, user, pass);
qDebug() << "<> Proxy settings done.";
}
// now we have network, download translation updates
m_translations->downloadIndex();
@ -894,7 +908,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
m_analytics = new GAnalytics(BuildConfig.ANALYTICS_ID, clientID, analyticsVersion, this);
m_analytics->setLogLevel(GAnalytics::Debug);
m_analytics->setAnonymizeIPs(true);
m_analytics->setNetworkAccessManager(&ENV->network());
// FIXME: the ganalytics library has no idea about our fancy shared pointers...
m_analytics->setNetworkAccessManager(network().get());
if(m_settings->get("AnalyticsSeen").toInt() < m_analytics->version())
{
@ -1043,9 +1058,6 @@ void Application::showFatalErrorMessage(const QString& title, const QString& con
Application::~Application()
{
// kill the other globals.
Env::dispose();
// Shut down logger by setting the logger function to nothing
qInstallMessageHandler(nullptr);
@ -1535,3 +1547,92 @@ void Application::on_windowClose()
QString Application::msaClientId() const {
return Secrets::getMSAClientID('-');
}
void Application::updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password)
{
// Set the application proxy settings.
if (proxyTypeStr == "SOCKS5")
{
QNetworkProxy::setApplicationProxy(
QNetworkProxy(QNetworkProxy::Socks5Proxy, addr, port, user, password));
}
else if (proxyTypeStr == "HTTP")
{
QNetworkProxy::setApplicationProxy(
QNetworkProxy(QNetworkProxy::HttpProxy, addr, port, user, password));
}
else if (proxyTypeStr == "None")
{
// If we have no proxy set, set no proxy and return.
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::NoProxy));
}
else
{
// If we have "Default" selected, set Qt to use the system proxy settings.
QNetworkProxyFactory::setUseSystemConfiguration(true);
}
qDebug() << "Detecting proxy settings...";
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
m_network->setProxy(proxy);
QString proxyDesc;
if (proxy.type() == QNetworkProxy::NoProxy)
{
qDebug() << "Using no proxy is an option!";
return;
}
switch (proxy.type())
{
case QNetworkProxy::DefaultProxy:
proxyDesc = "Default proxy: ";
break;
case QNetworkProxy::Socks5Proxy:
proxyDesc = "Socks5 proxy: ";
break;
case QNetworkProxy::HttpProxy:
proxyDesc = "HTTP proxy: ";
break;
case QNetworkProxy::HttpCachingProxy:
proxyDesc = "HTTP caching: ";
break;
case QNetworkProxy::FtpCachingProxy:
proxyDesc = "FTP caching: ";
break;
default:
proxyDesc = "DERP proxy: ";
break;
}
proxyDesc += QString("%1:%2")
.arg(proxy.hostName())
.arg(proxy.port());
qDebug() << proxyDesc;
}
shared_qobject_ptr< HttpMetaCache > Application::metacache()
{
return m_metacache;
}
shared_qobject_ptr<QNetworkAccessManager> Application::network()
{
return m_network;
}
shared_qobject_ptr<Meta::Index> Application::metadataIndex()
{
if (!m_metadataIndex)
{
m_metadataIndex.reset(new Meta::Index());
}
return m_metadataIndex;
}
QString Application::getJarsPath()
{
if(m_jarsPath.isEmpty())
{
return FS::PathCombine(QCoreApplication::applicationDirPath(), "jars");
}
return m_jarsPath;
}

View File

@ -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<SettingsObject> settings() const
{
std::shared_ptr<SettingsObject> 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> updateChecker()
{
shared_qobject_ptr<UpdateChecker> updateChecker() {
return m_updateChecker;
}
@ -91,46 +88,44 @@ public:
std::shared_ptr<JavaInstallList> javalist();
std::shared_ptr<InstanceList> instances() const
{
std::shared_ptr<InstanceList> instances() const {
return m_instances;
}
FolderInstanceProvider * folderProvider() const
{
return m_instanceFolder;
}
std::shared_ptr<IconList> icons() const
{
std::shared_ptr<IconList> icons() const {
return m_icons;
}
MCEditTool *mcedit() const
{
MCEditTool *mcedit() const {
return m_mcedit.get();
}
shared_qobject_ptr<AccountList> accounts() const
{
shared_qobject_ptr<AccountList> accounts() const {
return m_accounts;
}
QString msaClientId() const;
Status status() const
{
Status status() const {
return m_status;
}
const QMap<QString, std::shared_ptr<BaseProfilerFactory>> &profilers() const
{
const QMap<QString, std::shared_ptr<BaseProfilerFactory>> &profilers() const {
return m_profilers;
}
void updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password);
shared_qobject_ptr<QNetworkAccessManager> network();
shared_qobject_ptr<HttpMetaCache> metacache();
shared_qobject_ptr<Meta::Index> 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<QNetworkAccessManager> m_network;
shared_qobject_ptr<UpdateChecker> m_updateChecker;
shared_qobject_ptr<AccountList> m_accounts;
shared_qobject_ptr<HttpMetaCache> m_metacache;
shared_qobject_ptr<Meta::Index> m_metadataIndex;
std::shared_ptr<SettingsObject> m_settings;
std::shared_ptr<InstanceList> m_instances;
FolderInstanceProvider * m_instanceFolder = nullptr;
std::shared_ptr<IconList> m_icons;
std::shared_ptr<UpdateChecker> m_updateChecker;
shared_qobject_ptr<AccountList> m_accounts;
std::shared_ptr<JavaInstallList> m_javalist;
std::shared_ptr<TranslationsModel> m_translations;
std::shared_ptr<GenericPageProvider> m_globalSettingsProvider;
std::map<QString, std::unique_ptr<ITheme>> m_themes;
std::unique_ptr<MCEditTool> m_mcedit;
QString m_jarsPath;
QSet<QString> m_features;
QMap<QString, std::shared_ptr<BaseProfilerFactory>> m_profilers;
@ -209,8 +211,7 @@ private:
#endif
// FIXME: attach to instances instead.
struct InstanceXtras
{
struct InstanceXtras {
InstanceWindow * window = nullptr;
shared_qobject_ptr<LaunchController> controller;
};

View File

@ -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
)

View File

@ -1,210 +0,0 @@
#include "Env.h"
#include "net/HttpMetaCache.h"
#include "BaseVersion.h"
#include "BaseVersionList.h"
#include <QDir>
#include <QCoreApplication>
#include <QNetworkProxy>
#include <QNetworkAccessManager>
#include <QDebug>
#include "tasks/Task.h"
#include "meta/Index.h"
#include "FileSystem.h"
#include <QDebug>
struct Env::Private
{
QNetworkAccessManager m_qnam;
shared_qobject_ptr<HttpMetaCache> m_metacache;
std::shared_ptr<IIconList> m_iconlist;
shared_qobject_ptr<Meta::Index> m_metadataIndex;
QString m_jarsPath;
QSet<QString> 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<IIconList> Env::icons()
{
return d->m_iconlist;
}
void Env::registerIconList(std::shared_ptr<IIconList> iconlist)
{
d->m_iconlist = iconlist;
}
shared_qobject_ptr<Meta::Index> 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<QString>& features) const
{
features = d->m_features;
}
void Env::setEnabledFeatures(const QSet<QString>& features) const
{
d->m_features = features;
}

View File

@ -1,63 +0,0 @@
#pragma once
#include <memory>
#include "icons/IIconList.h"
#include <QString>
#include <QMap>
#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<HttpMetaCache> metacache();
std::shared_ptr<IIconList> 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<IIconList> iconlist);
shared_qobject_ptr<Meta::Index> 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<QString> & features) const;
void setEnabledFeatures(const QSet<QString> & features) const;
protected:
Private * d;
};

View File

@ -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 <QtConcurrentRun>
@ -33,6 +32,9 @@
#include <quazipdir.h>
#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<INISettingsObject>(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);

View File

@ -55,7 +55,7 @@ private slots:
void extractAborted();
private: /* data */
NetJobPtr m_filesNetJob;
NetJob::Ptr m_filesNetJob;
shared_qobject_ptr<Flame::FileResolvingTask> m_modIdResolver;
QUrl m_sourceUrl;
QString m_archivePath;

View File

@ -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

View File

@ -47,7 +47,6 @@
#include <QtWidgets/QShortcut>
#include <BaseInstance.h>
#include <Env.h>
#include <InstanceList.h>
#include <MMCZip.h>
#include <icons/IconList.h>
@ -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))
{

View File

@ -15,7 +15,7 @@
#include "SkinUtils.h"
#include "net/HttpMetaCache.h"
#include "Env.h"
#include "Application.h"
#include <QFile>
#include <QPainter>
@ -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())
{

View File

@ -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()

View File

@ -42,6 +42,6 @@ slots:
private:
Ui::AboutDialog *ui;
NetJobPtr netJob;
NetJob::Ptr netJob;
QByteArray dataSink;
};

View File

@ -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)

View File

@ -62,6 +62,6 @@ protected:
private:
Ui::UpdateDialog *ui;
QByteArray changelogData;
NetJobPtr dljob;
NetJob::Ptr dljob;
ChangelogType m_changelogType = CHANGELOG_MARKDOWN;
};

View File

@ -1,7 +0,0 @@
#include "IIconList.h"
// blargh
IIconList::~IIconList()
{
}

View File

@ -1,25 +0,0 @@
#pragma once
#include <QString>
#include <QStringList>
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;
};

View File

@ -21,14 +21,15 @@
#include <QDir>
#include <QtGui/QIcon>
#include <memory>
#include "MMCIcon.h"
#include "settings/Setting.h"
#include "Env.h" // there is a global icon list inside Env.
#include <icons/IIconList.h>
#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;

View File

@ -17,7 +17,15 @@
#include <QString>
#include <QDateTime>
#include <QIcon>
#include <icons/IIconList.h>
enum IconType : unsigned
{
Builtin,
Transient,
FileBased,
ICONS_TOTAL,
ToBeDeleted
};
struct MMCImage
{

View File

@ -1,14 +1,14 @@
#include "JavaChecker.h"
#include "JavaUtils.h"
#include <FileSystem.h>
#include <Commandline.h>
#include <QFile>
#include <QProcess>
#include <QMap>
#include <QCoreApplication>
#include <QDebug>
#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;

View File

@ -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

View File

@ -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<Task> 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<Task> m_updateTask;
NetJob::Ptr m_updateTask;
};
}

View File

@ -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<Meta::VersionList>("list1"), std::make_shared<Meta::VersionList>("list2"), std::make_shared<Meta::VersionList>("list3")});

View File

@ -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())

View File

@ -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<QString, AssetObject> objects;

View File

@ -1,14 +1,16 @@
#include <meta/VersionList.h>
#include <meta/Index.h>
#include <Env.h>
#include "Component.h"
#include <QSaveFile>
#include "meta/Version.h"
#include "VersionFile.h"
#include "minecraft/PackProfile.h"
#include <FileSystem.h>
#include <QSaveFile>
#include "FileSystem.h"
#include "OneSixVersionFormat.h"
#include "Application.h"
#include <assert.h>
Component::Component(PackProfile * parent, const QString& uid)
@ -85,9 +87,9 @@ std::shared_ptr<class VersionFile> Component::getVersionFile() const
std::shared_ptr<class Meta::VersionList> 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;

View File

@ -3,16 +3,17 @@
#include "PackProfile_p.h"
#include "PackProfile.h"
#include "Component.h"
#include <Env.h>
#include <meta/Index.h>
#include <meta/VersionList.h>
#include <meta/Version.h>
#include "meta/Index.h"
#include "meta/VersionList.h"
#include "meta/Version.h"
#include "ComponentUpdateTask_p.h"
#include <cassert>
#include <Version.h>
#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<Task>
}
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_ptr<Tas
}
LoadResult result = LoadResult::Failed;
auto metaList = ENV->metadataIndex()->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<Tas
static LoadResult loadIndex(shared_qobject_ptr<Task>& 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;

View File

@ -3,7 +3,6 @@
#include <net/Download.h>
#include <net/ChecksumValidator.h>
#include <Env.h>
#include <FileSystem.h>
#include <BuildConfig.h>
@ -45,14 +44,14 @@ void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& na
}
}
QList< std::shared_ptr< NetAction > > Library::getDownloads(
QList<NetAction::Ptr> Library::getDownloads(
OpSys system,
class HttpMetaCache* cache,
QStringList& failedLocalFiles,
const QString & overridePath
) const
{
QList<NetActionPtr> out;
QList<NetAction::Ptr> out;
bool stale = isAlwaysStale();
bool local = isLocal();

View File

@ -152,7 +152,7 @@ public: /* methods */
bool isForge() const;
// Get a list of downloads for this library
QList<NetActionPtr> getDownloads(OpSys system, class HttpMetaCache * cache,
QList<NetAction::Ptr> getDownloads(OpSys system, class HttpMetaCache * cache,
QStringList & failedLocalFiles, const QString & overridePath) const;
private: /* methods */

View File

@ -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()

View File

@ -1,15 +1,16 @@
#include "MinecraftInstance.h"
#include <minecraft/launch/CreateGameFolders.h>
#include <minecraft/launch/ExtractNatives.h>
#include <minecraft/launch/PrintInstanceInfo.h>
#include <settings/Setting.h>
#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 <MMCStrings.h>
#include <pathmatcher/RegexpMatcher.h>
#include <pathmatcher/MultiMatcher.h>
#include <FileSystem.h>
#include <java/JavaVersion.h>
#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 <QCoreApplication>
#include "PackProfile.h"
#include "AssetsUtils.h"
#include "MinecraftUpdate.h"
#include "MinecraftLoadAndCheck.h"
#include <minecraft/gameoptions/GameOptions.h>
#include <minecraft/update/FoldersTask.h>
#include "minecraft/gameoptions/GameOptions.h"
#include "minecraft/update/FoldersTask.h"
#define IBUS "@im=ibus"
@ -816,7 +820,7 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt
auto process = LaunchTask::create(std::dynamic_pointer_cast<MinecraftInstance>(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
{

View File

@ -13,7 +13,6 @@
* limitations under the License.
*/
#include "Env.h"
#include "MinecraftUpdate.h"
#include "MinecraftInstance.h"

View File

@ -20,22 +20,23 @@
#include <QJsonDocument>
#include <QJsonArray>
#include <QDebug>
#include "Exception.h"
#include <minecraft/OneSixVersionFormat.h>
#include <FileSystem.h>
#include <QSaveFile>
#include <Env.h>
#include <meta/Index.h>
#include <minecraft/MinecraftInstance.h>
#include <QUuid>
#include <QTimer>
#include <Json.h>
#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;
}

View File

@ -17,7 +17,6 @@
#include "Parsers.h"
#include <Application.h>
#include <Env.h>
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);

View File

@ -5,11 +5,10 @@
#include <QBuffer>
#include <QUrlQuery>
#include "Application.h"
#include "AuthRequest.h"
#include "katabasis/Globals.h"
#include <Env.h>
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()));

View File

@ -22,10 +22,9 @@
#include <QJsonDocument>
#include <QNetworkReply>
#include <QByteArray>
#include <QDebug>
#include <Env.h>
#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);

View File

@ -14,13 +14,14 @@
*/
#include "LauncherPartLaunch.h"
#include <QCoreApplication>
#include <launch/LaunchTask.h>
#include <minecraft/MinecraftInstance.h>
#include <FileSystem.h>
#include <Commandline.h>
#include <QStandardPaths>
#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

View File

@ -1,7 +1,9 @@
#include "CapeChange.h"
#include <QNetworkRequest>
#include <QHttpMultiPart>
#include <Env.h>
#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"));

View File

@ -1,7 +1,9 @@
#include "SkinDelete.h"
#include <QNetworkRequest>
#include <QHttpMultiPart>
#include <Env.h>
#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<QNetworkReply>(rep);
setStatus(tr("Deleting skin"));

View File

@ -1,7 +1,9 @@
#include "SkinUpload.h"
#include <QNetworkRequest>
#include <QHttpMultiPart>
#include <Env.h>
#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<QNetworkReply>(rep);
setStatus(tr("Uploading skin"));

View File

@ -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();

View File

@ -24,5 +24,5 @@ public slots:
private:
MinecraftInstance *m_inst;
NetJobPtr downloadJob;
NetJob::Ptr downloadJob;
};

View File

@ -1,10 +1,12 @@
#include "Env.h"
#include <FileSystem.h>
#include <minecraft/VersionFilterData.h>
#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)
{

View File

@ -25,7 +25,7 @@ public slots:
private:
MinecraftInstance *m_inst;
NetJobPtr downloadJob;
NetJob::Ptr downloadJob;
QList<FMLlib> fmlLibsToProcess;
};

View File

@ -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<LibraryPtr> & 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

View File

@ -22,5 +22,5 @@ public slots:
private:
MinecraftInstance *m_inst;
NetJobPtr downloadJob;
NetJob::Ptr downloadJob;
};

View File

@ -1,13 +1,13 @@
#include <Env.h>
#include <quazip.h>
#include <QtConcurrent/QtConcurrent>
#include <MMCZip.h>
#include <minecraft/OneSixVersionFormat.h>
#include <Version.h>
#include <net/ChecksumValidator.h>
#include "ATLPackInstallTask.h"
#include "BuildConfig.h"
#include <QtConcurrent/QtConcurrent>
#include <quazip.h>
#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() {

View File

@ -74,7 +74,7 @@ private:
bool abortable = false;
NetJobPtr jobPtr;
NetJob::Ptr jobPtr;
QByteArray response;
QString m_pack;

View File

@ -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<QNetworkAccessManager> 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()

View File

@ -10,7 +10,7 @@ class FileResolvingTask : public Task
{
Q_OBJECT
public:
explicit FileResolvingTask(Flame::Manifest &toProcess);
explicit FileResolvingTask(shared_qobject_ptr<QNetworkAccessManager> network, Flame::Manifest &toProcess);
virtual ~FileResolvingTask() {};
const Flame::Manifest &getResults() const
@ -25,8 +25,9 @@ protected slots:
void netJobFinished();
private: /* data */
shared_qobject_ptr<QNetworkAccessManager> m_network;
Flame::Manifest m_toProcess;
QVector<QByteArray> results;
NetJobPtr m_dljob;
NetJob::Ptr m_dljob;
};
}

View File

@ -2,7 +2,8 @@
#include "PrivatePackManager.h"
#include <QDomDocument>
#include <BuildConfig.h>
#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);
}
}

View File

@ -13,14 +13,15 @@ class PackFetchTask : public QObject {
Q_OBJECT
public:
PackFetchTask() = default;
PackFetchTask(shared_qobject_ptr<QNetworkAccessManager> network) : QObject(nullptr), m_network(network) {};
virtual ~PackFetchTask() = default;
void fetch();
void fetchPrivate(const QStringList &toFetch);
private:
NetJobPtr jobPtr;
shared_qobject_ptr<QNetworkAccessManager> m_network;
NetJob::Ptr jobPtr;
QByteArray publicModpacksXmlFileData;
QByteArray thirdPartyModpacksXmlFileData;

View File

@ -1,24 +1,25 @@
#include "PackInstallTask.h"
#include "Env.h"
#include "MMCZip.h"
#include <QtConcurrent>
#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 <QtConcurrent>
#include "BuildConfig.h"
#include "Application.h"
namespace LegacyFTB {
PackInstallTask::PackInstallTask(Modpack pack, QString version)
PackInstallTask::PackInstallTask(shared_qobject_ptr<QNetworkAccessManager> 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);
}

View File

@ -8,6 +8,8 @@
#include "meta/VersionList.h"
#include "PackHelpers.h"
#include "net/NetJob.h"
#include <nonstd/optional>
namespace LegacyFTB {
@ -17,7 +19,7 @@ class PackInstallTask : public InstanceTask
Q_OBJECT
public:
explicit PackInstallTask(Modpack pack, QString version);
explicit PackInstallTask(shared_qobject_ptr<QNetworkAccessManager> 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<QNetworkAccessManager> m_network;
bool abortable = false;
std::unique_ptr<QuaZip> m_packZip;
QFuture<nonstd::optional<QStringList>> m_extractFuture;
QFutureWatcher<nonstd::optional<QStringList>> m_extractFutureWatcher;
NetJobPtr netJobContainer;
NetJob::Ptr netJobContainer;
QString archivePath;
Modpack m_pack;

View File

@ -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()

View File

@ -32,7 +32,7 @@ private:
private:
bool abortable = false;
NetJobPtr jobPtr;
NetJob::Ptr jobPtr;
QByteArray response;
Modpack m_pack;

View File

@ -15,12 +15,13 @@
#include "SingleZipPackInstallTask.h"
#include "Env.h"
#include <QtConcurrent>
#include "MMCZip.h"
#include "TechnicPackProcessor.h"
#include "FileSystem.h"
#include <QtConcurrent>
#include <FileSystem.h>
#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()

View File

@ -55,7 +55,7 @@ private:
QUrl m_sourceUrl;
QString m_minecraftVersion;
QString m_archivePath;
NetJobPtr m_filesNetJob;
NetJob::Ptr m_filesNetJob;
std::unique_ptr<QuaZip> m_packZip;
QFuture<nonstd::optional<QStringList>> m_extractFuture;
QFutureWatcher<nonstd::optional<QStringList>> m_extractFutureWatcher;

View File

@ -21,10 +21,14 @@
#include <MMCZip.h>
#include "TechnicPackProcessor.h"
Technic::SolderPackInstallTask::SolderPackInstallTask(const QUrl &sourceUrl, const QString &minecraftVersion)
{
Technic::SolderPackInstallTask::SolderPackInstallTask(
shared_qobject_ptr<QNetworkAccessManager> 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()

View File

@ -27,7 +27,7 @@ namespace Technic
{
Q_OBJECT
public:
explicit SolderPackInstallTask(const QUrl &sourceUrl, const QString &minecraftVersion);
explicit SolderPackInstallTask(shared_qobject_ptr<QNetworkAccessManager> 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<QNetworkAccessManager> m_network;
NetJob::Ptr m_filesNetJob;
QUrl m_sourceUrl;
QString m_minecraftVersion;
QByteArray m_response;

View File

@ -15,16 +15,17 @@
#include "Download.h"
#include "BuildConfig.h"
#include <QFileInfo>
#include <QDateTime>
#include <QDebug>
#include "Env.h"
#include <FileSystem.h>
#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<Download>(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<Download>(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<Download>(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;
}

View File

@ -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<class Download> Ptr;
typedef shared_qobject_ptr<class Download> 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.

View File

@ -1,7 +1,6 @@
#include "FileSink.h"
#include <QFile>
#include <QFileInfo>
#include "Env.h"
#include "FileSystem.h"
namespace Net {

View File

@ -13,7 +13,6 @@
* limitations under the License.
*/
#include "Env.h"
#include "HttpMetaCache.h"
#include "FileSystem.h"

View File

@ -1,8 +1,8 @@
#include "MetaCacheSink.h"
#include <QFile>
#include <QFileInfo>
#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;
}

View File

@ -35,14 +35,15 @@ enum JobStatus
Job_Failed_Proceed
};
typedef std::shared_ptr<class NetAction> NetActionPtr;
class NetAction : public QObject
{
Q_OBJECT
protected:
explicit NetAction() : QObject(0) {};
explicit NetAction() : QObject(nullptr) {};
public:
using Ptr = shared_qobject_ptr<NetAction>;
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<QNetworkAccessManager> network) {
m_network = network;
startImpl();
}
protected:
virtual void startImpl() = 0;
public:
shared_qobject_ptr<QNetworkAccessManager> m_network;
/// index within the parent job, FIXME: nuke
int m_index_within_job = 0;

View File

@ -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);

View File

@ -22,33 +22,34 @@
#include "QObjectPtr.h"
class NetJob;
typedef shared_qobject_ptr<NetJob> NetJobPtr;
class NetJob : public Task
{
Q_OBJECT
public:
using Ptr = shared_qobject_ptr<NetJob>;
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<QNetworkAccessManager> 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<QNetworkAccessManager> m_network;
struct part_info
{
qint64 current_progress = 0;
qint64 total_progress = 1;
int failures = 0;
};
QList<NetActionPtr> downloads;
QList<NetAction::Ptr> downloads;
QList<part_info> parts_progress;
QQueue<int> m_todo;
QSet<int> m_doing;

View File

@ -1,11 +1,12 @@
#include "PasteUpload.h"
#include "Env.h"
#include "BuildConfig.h"
#include "Application.h"
#include <QDebug>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <QFile>
#include <BuildConfig.h>
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<QNetworkReply>(rep);
setStatus(tr("Uploading to paste.ee"));

View File

@ -20,8 +20,9 @@
#include <QDebug>
NewsChecker::NewsChecker(const QString& feedUrl)
NewsChecker::NewsChecker(shared_qobject_ptr<QNetworkAccessManager> 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()

View File

@ -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<QNetworkAccessManager> network, const QString& feedUrl);
/*!
* Returns the error message for the last time the news was loaded.
@ -80,7 +80,7 @@ protected: /* data */
QList<NewsEntryPtr> 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<QNetworkAccessManager> m_network;
protected slots:
/// Emits newsLoaded() and sets m_lastLoadError to empty string.
void succeed();

View File

@ -5,9 +5,9 @@
#include <QJsonArray>
#include <QDebug>
#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)

View File

@ -52,7 +52,7 @@ private:
private:
QList<NotificationEntry> m_entries;
QUrl m_notificationsUrl;
NetJobPtr m_checkJob;
NetJob::Ptr m_checkJob;
Net::Download::Ptr m_download;
QString m_appVersionChannel;

View File

@ -22,7 +22,6 @@
#include <QDebug>
#include "net/NetJob.h"
#include "Env.h"
#include "dialogs/ProgressDialog.h"
#include "dialogs/LoginDialog.h"

View File

@ -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()
{

View File

@ -302,8 +302,8 @@ void ScreenshotsPage::on_actionUpload_triggered()
if (selection.isEmpty())
return;
QList<ScreenshotPtr> uploaded;
auto job = NetJobPtr(new NetJob("Screenshot Upload"));
QList<ScreenShot::Ptr> 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);

View File

@ -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;

View File

@ -1,16 +1,15 @@
#include "VanillaPage.h"
#include "ui_VanillaPage.h"
#include "Application.h"
#include <meta/Index.h>
#include <meta/VersionList.h>
#include <dialogs/NewInstanceDialog.h>
#include <Filter.h>
#include <Env.h>
#include <InstanceCreationTask.h>
#include <QTabBar>
#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;
}

View File

@ -2,7 +2,6 @@
#include <BuildConfig.h>
#include <Application.h>
#include <Env.h>
#include <Json.h>
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);
}

View File

@ -45,7 +45,7 @@ private:
LogoMap m_logoMap;
QMap<QString, LogoCallback> waitingCallbacks;
NetJobPtr jobPtr;
NetJob::Ptr jobPtr;
QByteArray response;
};

View File

@ -9,7 +9,6 @@
#include <QLabel>
#include <RWStorage.h>
#include <Env.h>
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);
}

View File

@ -69,7 +69,7 @@ private:
ResetRequested,
Finished
} searchState = None;
NetJobPtr jobPtr;
NetJob::Ptr jobPtr;
QByteArray response;
};

View File

@ -139,7 +139,7 @@ void FlamePage::onSelectionChanged(QModelIndex first, QModelIndex second)
suggestCurrent();
});
netJob->start();
netJob->start(APPLICATION->network());
}
else
{

View File

@ -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());
}
}

View File

@ -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<ModpacksCH::Modpack> modpacks;
LogoMap m_logoMap;
NetJobPtr jobPtr;
NetJob::Ptr jobPtr;
int currentPack;
QList<int> remainingPacks;
QByteArray response;

View File

@ -8,7 +8,6 @@
#include <QLabel>
#include <RWStorage.h>
#include <Env.h>
#include <BuildConfig.h>
@ -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
{

View File

@ -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"))
{

View File

@ -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);
}

View File

@ -63,7 +63,7 @@ private:
ResetRequested,
Finished
} searchState = None;
NetJobPtr jobPtr;
NetJob::Ptr jobPtr;
QByteArray response;
};

View File

@ -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));
}
}

View File

@ -5,18 +5,18 @@
#include <QJsonObject>
#include <QUrl>
#include <QStringList>
#include "BuildConfig.h"
#include "Env.h"
#include <QDebug>
ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenshotPtr> screenshots) : NetAction(), m_screenshots(screenshots)
#include "BuildConfig.h"
#include "Application.h"
ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenShot::Ptr> 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);

View File

@ -1,13 +1,14 @@
#pragma once
#include "net/NetAction.h"
#include "Screenshot.h"
#include "QObjectPtr.h"
typedef std::shared_ptr<class ImgurAlbumCreation> ImgurAlbumCreationPtr;
typedef shared_qobject_ptr<class ImgurAlbumCreation> ImgurAlbumCreationPtr;
class ImgurAlbumCreation : public NetAction
{
public:
explicit ImgurAlbumCreation(QList<ScreenshotPtr> screenshots);
static ImgurAlbumCreationPtr make(QList<ScreenshotPtr> screenshots)
explicit ImgurAlbumCreation(QList<ScreenShot::Ptr> screenshots);
static ImgurAlbumCreationPtr make(QList<ScreenShot::Ptr> screenshots)
{
return ImgurAlbumCreationPtr(new ImgurAlbumCreation(screenshots));
}
@ -32,10 +33,10 @@ slots:
public
slots:
virtual void start();
virtual void startImpl();
private:
QList<ScreenshotPtr> m_screenshots;
QList<ScreenShot::Ptr> m_screenshots;
QString m_deleteHash;
QString m_id;

View File

@ -1,4 +1,5 @@
#include "ImgurUpload.h"
#include "BuildConfig.h"
#include <QNetworkRequest>
#include <QHttpMultiPart>
@ -7,18 +8,15 @@
#include <QHttpPart>
#include <QFile>
#include <QUrl>
#include "BuildConfig.h"
#include "Env.h"
#include <QDebug>
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);

View File

@ -1,15 +1,15 @@
#pragma once
#include "QObjectPtr.h"
#include "net/NetAction.h"
#include "Screenshot.h"
typedef std::shared_ptr<class ImgurUpload> 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<ImgurUpload>;
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;
};

View File

@ -5,10 +5,10 @@
#include <QFileInfo>
#include <memory>
struct ScreenShot
{
ScreenShot(QFileInfo file)
{
struct ScreenShot {
using Ptr = std::shared_ptr<ScreenShot>;
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<ScreenShot> ScreenshotPtr;

View File

@ -19,10 +19,14 @@
#include <QString>
#include <QStringList>
#include "QObjectPtr.h"
class Task : public QObject
{
Q_OBJECT
public:
using Ptr = shared_qobject_ptr<Task>;
enum class State
{
Inactive,

View File

@ -6,15 +6,17 @@
#include <QDir>
#include <QLibraryInfo>
#include <QDebug>
#include <FileSystem.h>
#include <net/NetJob.h>
#include <net/ChecksumValidator.h>
#include <Env.h>
#include <BuildConfig.h>
#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<QTranslator> m_qt_translator;
std::unique_ptr<QTranslator> m_app_translator;
std::shared_ptr<Net::Download> 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<POTranslator> 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()

View File

@ -26,8 +26,12 @@
namespace GoUpdate
{
DownloadTask::DownloadTask(Status status, QString target, QObject *parent)
: Task(parent), m_updateFilesDir(target)
DownloadTask::DownloadTask(
shared_qobject_ptr<QNetworkAccessManager> 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()

View File

@ -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<QNetworkAccessManager> 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<QNetworkAccessManager> m_network;
};
}

View File

@ -68,7 +68,7 @@ bool processFileLists
const VersionFileList &newVersion,
const QString &rootPath,
const QString &tempPath,
NetJobPtr job,
NetJob::Ptr job,
OperationList &ops
)
{

View File

@ -117,7 +117,7 @@ bool processFileLists
const VersionFileList &newVersion,
const QString &rootPath,
const QString &tempPath,
NetJobPtr job,
NetJob::Ptr job,
OperationList &ops
);

Some files were not shown because too many files have changed in this diff Show More