NOISSUE Split MultiMC app object into MultiMC and Env
This commit is contained in:
104
logic/Env.cpp
Normal file
104
logic/Env.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#include "Env.h"
|
||||
#include "logic/net/HttpMetaCache.h"
|
||||
#include <QDir>
|
||||
#include <QNetworkProxy>
|
||||
#include <QNetworkAccessManager>
|
||||
#include "logger/QsLog.h"
|
||||
#include "MultiMC.h"
|
||||
|
||||
Env::Env()
|
||||
{
|
||||
// null
|
||||
}
|
||||
|
||||
void Env::destroy()
|
||||
{
|
||||
m_metacache.reset();
|
||||
m_qnam.reset();
|
||||
}
|
||||
|
||||
Env& Env::Env::getInstance()
|
||||
{
|
||||
static Env instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void Env::initHttpMetaCache(QString rootPath, QString staticDataPath)
|
||||
{
|
||||
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("skins", QDir("accounts/skins").absolutePath());
|
||||
m_metacache->addBase("root", QDir(rootPath).absolutePath());
|
||||
m_metacache->addBase("translations", QDir(staticDataPath + "/translations").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);
|
||||
}
|
||||
|
||||
QLOG_INFO() << "Detecting proxy settings...";
|
||||
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
|
||||
if (m_qnam.get())
|
||||
m_qnam->setProxy(proxy);
|
||||
QString proxyDesc;
|
||||
if (proxy.type() == QNetworkProxy::NoProxy)
|
||||
{
|
||||
QLOG_INFO() << "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("%3@%1:%2 pass %4")
|
||||
.arg(proxy.hostName())
|
||||
.arg(proxy.port())
|
||||
.arg(proxy.user())
|
||||
.arg(proxy.password());
|
||||
QLOG_INFO() << proxyDesc;
|
||||
}
|
||||
44
logic/Env.h
Normal file
44
logic/Env.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <QString>
|
||||
|
||||
class QNetworkAccessManager;
|
||||
class HttpMetaCache;
|
||||
|
||||
#if defined(ENV)
|
||||
#undef ENV
|
||||
#endif
|
||||
#define ENV (Env::getInstance())
|
||||
|
||||
class Env
|
||||
{
|
||||
friend class MultiMC;
|
||||
private:
|
||||
Env();
|
||||
public:
|
||||
static Env& getInstance();
|
||||
|
||||
// call when Qt stuff is being torn down
|
||||
void destroy();
|
||||
|
||||
std::shared_ptr<QNetworkAccessManager> qnam()
|
||||
{
|
||||
return m_qnam;
|
||||
}
|
||||
|
||||
std::shared_ptr<HttpMetaCache> metacache()
|
||||
{
|
||||
return m_metacache;
|
||||
}
|
||||
|
||||
/// init the cache. FIXME: possible future hook point
|
||||
void initHttpMetaCache(QString rootPath, QString staticDataPath);
|
||||
|
||||
/// Updates the application proxy settings from the settings object.
|
||||
void updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<QNetworkAccessManager> m_qnam;
|
||||
std::shared_ptr<HttpMetaCache> m_metacache;
|
||||
};
|
||||
@@ -25,13 +25,13 @@
|
||||
#include "logic/minecraft/MinecraftVersionList.h"
|
||||
#include "logic/BaseInstance.h"
|
||||
#include "logic/LegacyInstance.h"
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "logic/ModList.h"
|
||||
|
||||
#include "logger/QsLog.h"
|
||||
#include "logic/net/URLConstants.h"
|
||||
#include "JarUtils.h"
|
||||
|
||||
#include "MultiMC.h"
|
||||
|
||||
LegacyUpdate::LegacyUpdate(BaseInstance *inst, QObject *parent) : Task(parent), m_inst(inst)
|
||||
{
|
||||
@@ -110,7 +110,7 @@ void LegacyUpdate::fmllibsStart()
|
||||
// download missing libs to our place
|
||||
setStatus(tr("Dowloading FML libraries..."));
|
||||
auto dljob = new NetJob("FML libraries");
|
||||
auto metacache = MMC->metacache();
|
||||
auto metacache = ENV.metacache();
|
||||
for (auto &lib : fmlLibsToProcess)
|
||||
{
|
||||
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
|
||||
@@ -133,7 +133,7 @@ void LegacyUpdate::fmllibsFinished()
|
||||
{
|
||||
setStatus(tr("Copying FML libraries into the instance..."));
|
||||
LegacyInstance *inst = (LegacyInstance *)m_inst;
|
||||
auto metacache = MMC->metacache();
|
||||
auto metacache = ENV.metacache();
|
||||
int index = 0;
|
||||
for (auto &lib : fmlLibsToProcess)
|
||||
{
|
||||
@@ -197,7 +197,7 @@ void LegacyUpdate::lwjglStart()
|
||||
QString url = version->url();
|
||||
QUrl realUrl(url);
|
||||
QString hostname = realUrl.host();
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
QNetworkRequest req(realUrl);
|
||||
req.setRawHeader("Host", hostname.toLatin1());
|
||||
req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
|
||||
@@ -222,7 +222,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply *reply)
|
||||
"a row. YMMV");
|
||||
return;
|
||||
}
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
// Here i check if there is a cookie for me in the reply and extract it
|
||||
QList<QNetworkCookie> cookies =
|
||||
qvariant_cast<QList<QNetworkCookie>>(reply->header(QNetworkRequest::SetCookieHeader));
|
||||
@@ -376,7 +376,7 @@ void LegacyUpdate::jarStart()
|
||||
|
||||
auto dljob = new NetJob("Minecraft.jar for version " + version_id);
|
||||
|
||||
auto metacache = MMC->metacache();
|
||||
auto metacache = ENV.metacache();
|
||||
auto entry = metacache->resolveEntry("versions", localPath);
|
||||
dljob->addNetAction(CacheDownload::make(QUrl(urlstr), entry));
|
||||
connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished()));
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "LwjglVersionList.h"
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
|
||||
#include <QtNetwork>
|
||||
#include <QtXml>
|
||||
@@ -82,7 +82,7 @@ void LWJGLVersionList::loadList()
|
||||
Q_ASSERT_X(!m_loading, "loadList", "list is already loading (m_loading is true)");
|
||||
|
||||
setLoading(true);
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
QNetworkRequest req(QUrl(RSS_URL));
|
||||
req.setRawHeader("Accept", "application/rss+xml, text/xml, */*");
|
||||
req.setRawHeader("User-Agent", "MultiMC/5.0 (Uncached)");
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "OneSixUpdate.h"
|
||||
|
||||
#include <QtNetwork>
|
||||
@@ -94,7 +95,7 @@ void OneSixUpdate::assetIndexStart()
|
||||
QString localPath = assetName + ".json";
|
||||
auto job = new NetJob(tr("Asset index for %1").arg(inst->name()));
|
||||
|
||||
auto metacache = MMC->metacache();
|
||||
auto metacache = ENV.metacache();
|
||||
auto entry = metacache->resolveEntry("asset_indexes", localPath);
|
||||
job->addNetAction(CacheDownload::make(indexUrl, entry));
|
||||
jarlibDownloadJob.reset(job);
|
||||
@@ -118,7 +119,7 @@ void OneSixUpdate::assetIndexFinished()
|
||||
QString asset_fname = "assets/indexes/" + assetName + ".json";
|
||||
if (!AssetsUtils::loadAssetsIndexJson(asset_fname, &index))
|
||||
{
|
||||
auto metacache = MMC->metacache();
|
||||
auto metacache = ENV.metacache();
|
||||
auto entry = metacache->resolveEntry("asset_indexes", assetName + ".json");
|
||||
metacache->evictEntry(entry);
|
||||
emitFailed(tr("Failed to read the assets index!"));
|
||||
@@ -200,7 +201,7 @@ void OneSixUpdate::jarlibStart()
|
||||
|
||||
auto job = new NetJob(tr("Libraries for instance %1").arg(inst->name()));
|
||||
|
||||
auto metacache = MMC->metacache();
|
||||
auto metacache = ENV.metacache();
|
||||
auto entry = metacache->resolveEntry("versions", localPath);
|
||||
job->addNetAction(CacheDownload::make(QUrl(urlstr), entry));
|
||||
jarHashOnEntry = entry->md5sum;
|
||||
@@ -211,7 +212,7 @@ void OneSixUpdate::jarlibStart()
|
||||
auto libs = version->getActiveNativeLibs();
|
||||
libs.append(version->getActiveNormalLibs());
|
||||
|
||||
auto metacache = MMC->metacache();
|
||||
auto metacache = ENV.metacache();
|
||||
QList<ForgeXzDownloadPtr> ForgeLibs;
|
||||
QList<std::shared_ptr<OneSixLibrary>> brokenLocalLibs;
|
||||
|
||||
@@ -317,7 +318,7 @@ void OneSixUpdate::jarlibFinished()
|
||||
{
|
||||
auto sourceJarPath = m_inst->versionsPath().absoluteFilePath(version->id + "/" + version->id + ".jar");
|
||||
QString localPath = version_id + "/" + version_id + ".jar";
|
||||
auto metacache = MMC->metacache();
|
||||
auto metacache = ENV.metacache();
|
||||
auto entry = metacache->resolveEntry("versions", localPath);
|
||||
QString fullJarPath = entry->getFullPath();
|
||||
if(!JarUtils::createModdedJar(sourceJarPath, finalJarPath, jarMods))
|
||||
@@ -390,7 +391,7 @@ void OneSixUpdate::fmllibsStart()
|
||||
// download missing libs to our place
|
||||
setStatus(tr("Dowloading FML libraries..."));
|
||||
auto dljob = new NetJob("FML libraries");
|
||||
auto metacache = MMC->metacache();
|
||||
auto metacache = ENV.metacache();
|
||||
for (auto &lib : fmlLibsToProcess)
|
||||
{
|
||||
auto entry = metacache->resolveEntry("fmllibs", lib.filename);
|
||||
@@ -413,7 +414,7 @@ void OneSixUpdate::fmllibsFinished()
|
||||
{
|
||||
setStatus(tr("Copying FML libraries into the instance..."));
|
||||
OneSixInstance *inst = (OneSixInstance *)m_inst;
|
||||
auto metacache = MMC->metacache();
|
||||
auto metacache = ENV.metacache();
|
||||
int index = 0;
|
||||
for (auto &lib : fmlLibsToProcess)
|
||||
{
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "logic/SkinUtils.h"
|
||||
#include "net/HttpMetaCache.h"
|
||||
#include "logic/Env.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
@@ -29,7 +29,7 @@ namespace SkinUtils
|
||||
*/
|
||||
QPixmap getFaceFromCache(QString username, int height, int width)
|
||||
{
|
||||
QFile fskin(MMC->metacache()
|
||||
QFile fskin(ENV.metacache()
|
||||
->resolveEntry("skins", username + ".png")
|
||||
->getFullPath());
|
||||
|
||||
|
||||
@@ -19,9 +19,10 @@
|
||||
#include <QJsonParseError>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QVariant>
|
||||
#include <logger/QsLog.h>
|
||||
|
||||
#include "AssetsUtils.h"
|
||||
#include "MultiMC.h"
|
||||
#include <pathutils.h>
|
||||
|
||||
namespace AssetsUtils
|
||||
|
||||
@@ -22,10 +22,12 @@
|
||||
#include <QNetworkReply>
|
||||
#include <QByteArray>
|
||||
|
||||
#include <MultiMC.h>
|
||||
#include <logic/Env.h>
|
||||
#include <logic/auth/MojangAccount.h>
|
||||
#include <logic/net/URLConstants.h>
|
||||
|
||||
#include "logger/QsLog.h"
|
||||
|
||||
YggdrasilTask::YggdrasilTask(MojangAccount *account, QObject *parent)
|
||||
: Task(parent), m_account(account)
|
||||
{
|
||||
@@ -39,7 +41,7 @@ void YggdrasilTask::executeTask()
|
||||
// Get the content of the request we're going to send to the server.
|
||||
QJsonDocument doc(getRequestContent());
|
||||
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
QUrl reqUrl("https://" + URLConstants::AUTH_BASE + getEndpoint());
|
||||
QNetworkRequest netRequest(reqUrl);
|
||||
netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "logic/OneSixInstance.h"
|
||||
#include "logic/forge/ForgeVersionList.h"
|
||||
#include "logic/minecraft/VersionFilterData.h"
|
||||
#include "logic/Env.h"
|
||||
|
||||
#include <quazip.h>
|
||||
#include <quazipfile.h>
|
||||
@@ -28,7 +29,7 @@
|
||||
#include <QStringList>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionMatch>
|
||||
#include "MultiMC.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QSaveFile>
|
||||
@@ -86,7 +87,7 @@ void ForgeInstaller::prepare(const QString &filename, const QString &universalUr
|
||||
// where do we put the library? decode the mojang path
|
||||
OneSixLibrary lib(libraryName);
|
||||
|
||||
auto cacheentry = MMC->metacache()->resolveEntry("libraries", lib.storagePath());
|
||||
auto cacheentry = ENV.metacache()->resolveEntry("libraries", lib.storagePath());
|
||||
finalPath = "libraries/" + lib.storagePath();
|
||||
if (!ensureFilePathExists(finalPath))
|
||||
return;
|
||||
@@ -110,7 +111,7 @@ void ForgeInstaller::prepare(const QString &filename, const QString &universalUr
|
||||
|
||||
cacheentry->stale = false;
|
||||
cacheentry->md5sum = md5sum.result().toHex().constData();
|
||||
MMC->metacache()->updateEntry(cacheentry);
|
||||
ENV.metacache()->updateEntry(cacheentry);
|
||||
}
|
||||
file.close();
|
||||
|
||||
@@ -275,7 +276,7 @@ bool ForgeInstaller::addLegacy(OneSixInstance *to)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
auto entry = MMC->metacache()->resolveEntry("minecraftforge", m_forge_version->filename());
|
||||
auto entry = ENV.metacache()->resolveEntry("minecraftforge", m_forge_version->filename());
|
||||
finalPath = PathCombine(to->jarModsDir(), m_forge_version->filename());
|
||||
if (!ensureFilePathExists(finalPath))
|
||||
{
|
||||
@@ -346,7 +347,7 @@ protected:
|
||||
}
|
||||
void prepare(ForgeVersionPtr forgeVersion)
|
||||
{
|
||||
auto entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename());
|
||||
auto entry = ENV.metacache()->resolveEntry("minecraftforge", forgeVersion->filename());
|
||||
auto installFunction = [this, entry, forgeVersion]()
|
||||
{
|
||||
if (!install(entry, forgeVersion))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "ForgeMirrors.h"
|
||||
#include "logger/QsLog.h"
|
||||
#include <algorithm>
|
||||
@@ -18,7 +18,7 @@ void ForgeMirrors::start()
|
||||
QLOG_INFO() << "Downloading " << m_url.toString();
|
||||
QNetworkRequest request(m_url);
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
QNetworkReply *rep = worker->get(request);
|
||||
|
||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "logic/forge/ForgeVersion.h"
|
||||
#include "logic/net/NetJob.h"
|
||||
#include "logic/net/URLConstants.h"
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
|
||||
#include <QtNetwork>
|
||||
#include <QtXml>
|
||||
@@ -162,8 +162,8 @@ void ForgeListLoadTask::executeTask()
|
||||
setStatus(tr("Fetching Forge version lists..."));
|
||||
auto job = new NetJob("Version index");
|
||||
// we do not care if the version is stale or not.
|
||||
auto forgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "list.json");
|
||||
auto gradleForgeListEntry = MMC->metacache()->resolveEntry("minecraftforge", "json");
|
||||
auto forgeListEntry = ENV.metacache()->resolveEntry("minecraftforge", "list.json");
|
||||
auto gradleForgeListEntry = ENV.metacache()->resolveEntry("minecraftforge", "json");
|
||||
|
||||
// verify by poking the server.
|
||||
forgeListEntry->stale = true;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "ForgeXzDownload.h"
|
||||
#include <pathutils.h>
|
||||
|
||||
@@ -67,7 +67,7 @@ void ForgeXzDownload::start()
|
||||
request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1());
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
|
||||
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
QNetworkReply *rep = worker->get(request);
|
||||
|
||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||
@@ -382,7 +382,7 @@ void ForgeXzDownload::decompressAndInstall()
|
||||
m_entry->local_changed_timestamp =
|
||||
output_file_info.lastModified().toUTC().toMSecsSinceEpoch();
|
||||
m_entry->stale = false;
|
||||
MMC->metacache()->updateEntry(m_entry);
|
||||
ENV.metacache()->updateEntry(m_entry);
|
||||
|
||||
m_reply.reset();
|
||||
emit succeeded(m_index_within_job);
|
||||
|
||||
@@ -15,18 +15,16 @@
|
||||
|
||||
#include "IconList.h"
|
||||
#include <pathutils.h>
|
||||
#include "logic/settings/SettingsObject.h"
|
||||
#include <QMap>
|
||||
#include <QEventLoop>
|
||||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <MultiMC.h>
|
||||
#include <logic/settings/Setting.h>
|
||||
|
||||
#define MAX_SIZE 1024
|
||||
|
||||
IconList::IconList(QObject *parent) : QAbstractListModel(parent)
|
||||
IconList::IconList(QString path, QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
// add builtin icons
|
||||
QDir instance_icons(":/icons/instances/");
|
||||
@@ -43,10 +41,6 @@ IconList::IconList(QObject *parent) : QAbstractListModel(parent)
|
||||
SLOT(directoryChanged(QString)));
|
||||
connect(m_watcher.get(), SIGNAL(fileChanged(QString)), SLOT(fileChanged(QString)));
|
||||
|
||||
auto setting = MMC->settings()->getSetting("IconsDir");
|
||||
QString path = setting->get().toString();
|
||||
connect(setting.get(), SIGNAL(SettingChanged(const Setting &, QVariant)),
|
||||
SLOT(SettingChanged(const Setting &, QVariant)));
|
||||
directoryChanged(path);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class IconList : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit IconList(QObject *parent = 0);
|
||||
explicit IconList(QString path, QObject *parent = 0);
|
||||
virtual ~IconList() {};
|
||||
|
||||
QIcon getIcon(QString key);
|
||||
@@ -64,9 +64,10 @@ private:
|
||||
IconList &operator=(const IconList &) = delete;
|
||||
void reindex();
|
||||
|
||||
protected
|
||||
slots:
|
||||
public slots:
|
||||
void directoryChanged(const QString &path);
|
||||
|
||||
protected slots:
|
||||
void fileChanged(const QString &path);
|
||||
void SettingChanged(const Setting & setting, QVariant value);
|
||||
private:
|
||||
|
||||
@@ -12,7 +12,7 @@ JavaChecker::JavaChecker(QObject *parent) : QObject(parent)
|
||||
|
||||
void JavaChecker::performCheck()
|
||||
{
|
||||
QString checkerJar = PathCombine(MMC->bin(), "jars", "JavaCheck.jar");
|
||||
QString checkerJar = PathCombine(QCoreApplication::applicationDirPath(), "jars", "JavaCheck.jar");
|
||||
|
||||
QStringList args = {"-jar", checkerJar};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "LiteLoaderVersionList.h"
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "logic/net/URLConstants.h"
|
||||
#include <MMCError.h>
|
||||
|
||||
@@ -104,7 +104,7 @@ void LLListLoadTask::executeTask()
|
||||
setStatus(tr("Loading LiteLoader version list..."));
|
||||
auto job = new NetJob("Version index");
|
||||
// we do not care if the version is stale or not.
|
||||
auto liteloaderEntry = MMC->metacache()->resolveEntry("liteloader", "versions.json");
|
||||
auto liteloaderEntry = ENV.metacache()->resolveEntry("liteloader", "versions.json");
|
||||
|
||||
// verify by poking the server.
|
||||
liteloaderEntry->stale = true;
|
||||
|
||||
@@ -151,7 +151,7 @@ QStringList MinecraftProcess::javaArguments() const
|
||||
args << "-Duser.language=en";
|
||||
if (!m_nativeFolder.isEmpty())
|
||||
args << QString("-Djava.library.path=%1").arg(m_nativeFolder);
|
||||
args << "-jar" << PathCombine(MMC->bin(), "jars", "NewLaunch.jar");
|
||||
args << "-jar" << PathCombine(QCoreApplication::applicationDirPath(), "jars", "NewLaunch.jar");
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
@@ -152,9 +152,7 @@ QString MinecraftVersion::getPatchFilename()
|
||||
|
||||
bool MinecraftVersion::needsUpdate()
|
||||
{
|
||||
auto settings = MMC->settings();
|
||||
bool result = m_versionSource == Remote || (hasUpdate() && settings->get("AutoUpdateMinecraftVersions").toBool());
|
||||
return result;
|
||||
return m_versionSource == Remote || hasUpdate();
|
||||
}
|
||||
|
||||
bool MinecraftVersion::hasUpdate()
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <QtAlgorithms>
|
||||
#include <QtNetwork>
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "MMCError.h"
|
||||
|
||||
#include "MinecraftVersionList.h"
|
||||
@@ -399,7 +399,7 @@ MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
|
||||
void MCVListLoadTask::executeTask()
|
||||
{
|
||||
setStatus(tr("Loading instance version list..."));
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
vlistReply = worker->get(QNetworkRequest(
|
||||
QUrl("http://" + URLConstants::AWS_DOWNLOAD_VERSIONS + "versions.json")));
|
||||
connect(vlistReply, SIGNAL(finished()), this, SLOT(list_downloaded()));
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <modutils.h>
|
||||
#include <pathutils.h>
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "logic/minecraft/VersionBuilder.h"
|
||||
#include "logic/minecraft/MinecraftProfile.h"
|
||||
#include "logic/minecraft/OneSixRule.h"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "ByteArrayDownload.h"
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "logger/QsLog.h"
|
||||
|
||||
ByteArrayDownload::ByteArrayDownload(QUrl url) : NetAction()
|
||||
@@ -28,7 +28,7 @@ void ByteArrayDownload::start()
|
||||
QLOG_INFO() << "Downloading " << m_url.toString();
|
||||
QNetworkRequest request(m_url);
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
QNetworkReply *rep = worker->get(request);
|
||||
|
||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "CacheDownload.h"
|
||||
#include <pathutils.h>
|
||||
|
||||
@@ -21,6 +20,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QDateTime>
|
||||
#include "logger/QsLog.h"
|
||||
#include "logic/Env.h"
|
||||
|
||||
CacheDownload::CacheDownload(QUrl url, MetaEntryPtr entry)
|
||||
: NetAction(), md5sum(QCryptographicHash::Md5)
|
||||
@@ -74,7 +74,7 @@ void CacheDownload::start()
|
||||
|
||||
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
|
||||
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
QNetworkReply *rep = worker->get(request);
|
||||
|
||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||
@@ -168,7 +168,7 @@ void CacheDownload::downloadFinished()
|
||||
m_entry->local_changed_timestamp =
|
||||
output_file_info.lastModified().toUTC().toMSecsSinceEpoch();
|
||||
m_entry->stale = false;
|
||||
MMC->metacache()->updateEntry(m_entry);
|
||||
ENV.metacache()->updateEntry(m_entry);
|
||||
|
||||
m_reply.reset();
|
||||
emit succeeded(m_index_within_job);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "HttpMetaCache.h"
|
||||
#include <pathutils.h>
|
||||
|
||||
@@ -32,7 +32,8 @@
|
||||
|
||||
QString MetaEntry::getFullPath()
|
||||
{
|
||||
return PathCombine(MMC->metacache()->getBasePath(base), path);
|
||||
// FIXME: make local?
|
||||
return PathCombine(ENV.metacache()->getBasePath(base), path);
|
||||
}
|
||||
|
||||
HttpMetaCache::HttpMetaCache(QString path) : QObject()
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <qtimer.h>
|
||||
#include <memory>
|
||||
|
||||
class HttpMetaCache;
|
||||
|
||||
struct MetaEntry
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "MD5EtagDownload.h"
|
||||
#include <pathutils.h>
|
||||
#include <QCryptographicHash>
|
||||
@@ -83,7 +83,7 @@ void MD5EtagDownload::start()
|
||||
return;
|
||||
}
|
||||
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
QNetworkReply *rep = worker->get(request);
|
||||
|
||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "PasteUpload.h"
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "logger/QsLog.h"
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
@@ -25,7 +25,7 @@ void PasteUpload::executeTask()
|
||||
request.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
request.setRawHeader("Content-Length", QByteArray::number(content.size()));
|
||||
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
QNetworkReply *rep = worker->post(request, content);
|
||||
|
||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <QStringList>
|
||||
|
||||
#include "logic/net/URLConstants.h"
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "logger/QsLog.h"
|
||||
|
||||
ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenshotPtr> screenshots) : NetAction(), m_screenshots(screenshots)
|
||||
@@ -33,7 +33,7 @@ void ImgurAlbumCreation::start()
|
||||
|
||||
const QByteArray data = "ids=" + ids.join(',').toUtf8() + "&title=Minecraft%20Screenshots&privacy=hidden";
|
||||
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
QNetworkReply *rep = worker->post(request, data);
|
||||
|
||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <QUrl>
|
||||
|
||||
#include "logic/net/URLConstants.h"
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "logger/QsLog.h"
|
||||
|
||||
ImgurUpload::ImgurUpload(ScreenshotPtr shot) : NetAction(), m_shot(shot)
|
||||
@@ -48,7 +48,7 @@ void ImgurUpload::start()
|
||||
namePart.setBody(m_shot->m_file.baseName().toUtf8());
|
||||
multipart->append(namePart);
|
||||
|
||||
auto worker = MMC->qnam();
|
||||
auto worker = ENV.qnam();
|
||||
QNetworkReply *rep = worker->post(request, multipart);
|
||||
|
||||
m_reply = std::shared_ptr<QNetworkReply>(rep);
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
#include "logic/net/ByteArrayDownload.h"
|
||||
#include "logic/net/CacheDownload.h"
|
||||
#include "logic/net/URLConstants.h"
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "logger/QsLog.h"
|
||||
|
||||
TranslationDownloader::TranslationDownloader()
|
||||
{
|
||||
@@ -27,7 +28,7 @@ void TranslationDownloader::indexRecieved()
|
||||
{
|
||||
if (!line.isEmpty())
|
||||
{
|
||||
MetaEntryPtr entry = MMC->metacache()->resolveEntry("translations", "mmc_" + line);
|
||||
MetaEntryPtr entry = ENV.metacache()->resolveEntry("translations", "mmc_" + line);
|
||||
entry->stale = true;
|
||||
CacheDownloadPtr dl = CacheDownload::make(
|
||||
QUrl(URLConstants::TRANSLATIONS_BASE_URL + line),
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "DownloadUpdateTask.h"
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "BuildConfig.h"
|
||||
|
||||
#include "logic/updater/UpdateChecker.h"
|
||||
@@ -28,10 +29,11 @@
|
||||
|
||||
#include <QDomDocument>
|
||||
|
||||
DownloadUpdateTask::DownloadUpdateTask(QString repoUrl, int versionId, QObject *parent)
|
||||
DownloadUpdateTask::DownloadUpdateTask(QString rootPath, QString repoUrl, int versionId, QObject *parent)
|
||||
: Task(parent)
|
||||
{
|
||||
m_cVersionId = BuildConfig.VERSION_BUILD;
|
||||
m_rootPath = rootPath;
|
||||
|
||||
m_nRepoUrl = repoUrl;
|
||||
m_nVersionId = versionId;
|
||||
@@ -293,7 +295,7 @@ DownloadUpdateTask::processFileLists(NetJob *job,
|
||||
// delete anything in the current one version's list that isn't in the new version's list.
|
||||
for (VersionFileEntry entry : currentVersion)
|
||||
{
|
||||
QFileInfo toDelete(PathCombine(MMC->root(), entry.path));
|
||||
QFileInfo toDelete(PathCombine(m_rootPath, entry.path));
|
||||
if (!toDelete.exists())
|
||||
{
|
||||
QLOG_ERROR() << "Expected file " << toDelete.absoluteFilePath()
|
||||
@@ -327,7 +329,7 @@ DownloadUpdateTask::processFileLists(NetJob *job,
|
||||
// TODO: Let's not MD5sum a ton of files on the GUI thread. We should probably find a
|
||||
// way to do this in the background.
|
||||
QString fileMD5;
|
||||
QString realEntryPath = PathCombine(MMC->root(), entry.path);
|
||||
QString realEntryPath = PathCombine(m_rootPath, entry.path);
|
||||
QFile entryFile(realEntryPath);
|
||||
QFileInfo entryInfo(realEntryPath);
|
||||
|
||||
@@ -356,7 +358,6 @@ DownloadUpdateTask::processFileLists(NetJob *job,
|
||||
}
|
||||
if (!pass)
|
||||
{
|
||||
QLOG_ERROR() << "ROOT: " << MMC->root();
|
||||
ops.clear();
|
||||
return false;
|
||||
}
|
||||
@@ -413,7 +414,7 @@ DownloadUpdateTask::processFileLists(NetJob *job,
|
||||
}
|
||||
else
|
||||
{
|
||||
auto cache_entry = MMC->metacache()->resolveEntry("root", entry.path);
|
||||
auto cache_entry = ENV.metacache()->resolveEntry("root", entry.path);
|
||||
QLOG_DEBUG() << "Updater will be in " << cache_entry->getFullPath();
|
||||
// force check.
|
||||
cache_entry->stale = true;
|
||||
|
||||
@@ -27,13 +27,13 @@ class DownloadUpdateTask : public Task
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DownloadUpdateTask(QString repoUrl, int versionId, QObject* parent=0);
|
||||
explicit DownloadUpdateTask(QString rootPath, QString repoUrl, int versionId, QObject* parent=0);
|
||||
|
||||
/*!
|
||||
* Gets the directory that contains the update files.
|
||||
*/
|
||||
QString updateFilesDir();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// TODO: We should probably put these data structures into a separate header...
|
||||
@@ -130,7 +130,7 @@ protected:
|
||||
/*!
|
||||
* Downloads the version info files from the repository.
|
||||
* The files for both the current build, and the build that we're updating to need to be downloaded.
|
||||
* If the current version's info file can't be found, MultiMC will not delete files that
|
||||
* If the current version's info file can't be found, MultiMC will not delete files that
|
||||
* were removed between versions. It will still replace files that have changed, however.
|
||||
* Note that although the repository URL for the current version is not given to the update task,
|
||||
* the task will attempt to look it up in the UpdateChecker's channel list.
|
||||
@@ -142,7 +142,7 @@ protected:
|
||||
* This function is called when version information is finished downloading.
|
||||
* This handles parsing the JSON downloaded by the version info network job and then calls processFileLists.
|
||||
* Note that this function will sometimes be called even if the version info download emits failed. If
|
||||
* we couldn't download the current version's info file, we can still update. This will be called even if the
|
||||
* we couldn't download the current version's info file, we can still update. This will be called even if the
|
||||
* current version's info file fails to download, as long as the new version's info file succeeded.
|
||||
*/
|
||||
virtual void parseDownloadedVersionInfo();
|
||||
@@ -176,7 +176,7 @@ protected:
|
||||
|
||||
//! Network job for downloading version info files.
|
||||
NetJobPtr m_vinfoNetJob;
|
||||
|
||||
|
||||
//! Network job for downloading update files.
|
||||
NetJobPtr m_filesNetJob;
|
||||
|
||||
@@ -188,6 +188,9 @@ protected:
|
||||
int m_cVersionId;
|
||||
QString m_cRepoUrl;
|
||||
|
||||
// path to the root of the application
|
||||
QString m_rootPath;
|
||||
|
||||
/*!
|
||||
* Temporary directory to store update files in.
|
||||
* This will be set to not auto delete. Task will fail if this fails to be created.
|
||||
@@ -199,9 +202,9 @@ protected:
|
||||
* This fixes destination paths for OSX.
|
||||
* The updater runs in MultiMC.app/Contents/MacOs by default
|
||||
* The destination paths are such as this: MultiMC.app/blah/blah
|
||||
*
|
||||
*
|
||||
* Therefore we chop off the 'MultiMC.app' prefix
|
||||
*
|
||||
*
|
||||
* Returns false if the path couldn't be fixed (is invalid)
|
||||
*/
|
||||
static bool fixPathForOSX(QString &path);
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "logic/Env.h"
|
||||
#include "BuildConfig.h"
|
||||
#include "logic/net/CacheDownload.h"
|
||||
#include "logger/QsLog.h"
|
||||
|
||||
NotificationChecker::NotificationChecker(QObject *parent)
|
||||
: QObject(parent), m_notificationsUrl(QUrl(BuildConfig.NOTIFICATION_URL))
|
||||
@@ -43,7 +44,7 @@ void NotificationChecker::checkForNotifications()
|
||||
return;
|
||||
}
|
||||
m_checkJob.reset(new NetJob("Checking for notifications"));
|
||||
auto entry = MMC->metacache()->resolveEntry("root", "notifications.json");
|
||||
auto entry = ENV.metacache()->resolveEntry("root", "notifications.json");
|
||||
entry->stale = true;
|
||||
m_checkJob->addNetAction(m_download = CacheDownload::make(m_notificationsUrl, entry));
|
||||
connect(m_download.get(), &CacheDownload::succeeded, this,
|
||||
|
||||
@@ -15,23 +15,19 @@
|
||||
|
||||
#include "UpdateChecker.h"
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include "BuildConfig.h"
|
||||
|
||||
#include "logger/QsLog.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
|
||||
#include "logic/settings/SettingsObject.h"
|
||||
|
||||
#define API_VERSION 0
|
||||
#define CHANLIST_FORMAT 0
|
||||
|
||||
UpdateChecker::UpdateChecker()
|
||||
UpdateChecker::UpdateChecker(QString channelListUrl, int currentBuild)
|
||||
{
|
||||
m_channelListUrl = BuildConfig.CHANLIST_URL;
|
||||
m_channelListUrl = channelListUrl;
|
||||
m_currentBuild = currentBuild;
|
||||
m_updateChecking = false;
|
||||
m_chanListLoading = false;
|
||||
m_checkUpdateWaiting = false;
|
||||
@@ -48,7 +44,7 @@ bool UpdateChecker::hasChannels() const
|
||||
return !m_channels.isEmpty();
|
||||
}
|
||||
|
||||
void UpdateChecker::checkForUpdate(bool notifyNoUpdate)
|
||||
void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate)
|
||||
{
|
||||
QLOG_DEBUG() << "Checking for updates.";
|
||||
|
||||
@@ -59,6 +55,7 @@ void UpdateChecker::checkForUpdate(bool notifyNoUpdate)
|
||||
QLOG_DEBUG() << "Channel list isn't loaded yet. Loading channel list and deferring "
|
||||
"update check.";
|
||||
m_checkUpdateWaiting = true;
|
||||
m_deferredUpdateChannel = updateChannel;
|
||||
updateChanList(notifyNoUpdate);
|
||||
return;
|
||||
}
|
||||
@@ -71,9 +68,6 @@ void UpdateChecker::checkForUpdate(bool notifyNoUpdate)
|
||||
|
||||
m_updateChecking = true;
|
||||
|
||||
// Get the channel we're checking.
|
||||
QString updateChannel = MMC->settings()->get("UpdateChannel").toString();
|
||||
|
||||
// Find the desired channel within the channel list and get its repo URL. If if cannot be
|
||||
// found, error.
|
||||
m_repoUrl = "";
|
||||
@@ -149,7 +143,7 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate)
|
||||
// We've got the version with the greatest ID number. Now compare it to our current build
|
||||
// number and update if they're different.
|
||||
int newBuildNumber = newestVersion.value("Id").toVariant().toInt();
|
||||
if (newBuildNumber != BuildConfig.VERSION_BUILD)
|
||||
if (newBuildNumber != m_currentBuild)
|
||||
{
|
||||
QLOG_DEBUG() << "Found newer version with ID" << newBuildNumber;
|
||||
// Update!
|
||||
@@ -251,7 +245,7 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
|
||||
|
||||
// If we're waiting to check for updates, do that now.
|
||||
if (m_checkUpdateWaiting)
|
||||
checkForUpdate(notifyNoUpdate);
|
||||
checkForUpdate(m_deferredUpdateChannel, notifyNoUpdate);
|
||||
|
||||
emit channelListLoaded();
|
||||
}
|
||||
|
||||
@@ -24,10 +24,8 @@ class UpdateChecker : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UpdateChecker();
|
||||
void checkForUpdate(bool notifyNoUpdate);
|
||||
|
||||
void setChannelListUrl(const QString &url) { m_channelListUrl = url; }
|
||||
UpdateChecker(QString channelListUrl, int currentBuild);
|
||||
void checkForUpdate(QString updateChannel, bool notifyNoUpdate);
|
||||
|
||||
/*!
|
||||
* Causes the update checker to download the channel list from the URL specified in config.h (generated by CMake).
|
||||
@@ -107,5 +105,11 @@ private:
|
||||
* When the channel list finishes loading, if this is true, the update checker will check for updates.
|
||||
*/
|
||||
bool m_checkUpdateWaiting;
|
||||
|
||||
/*!
|
||||
* if m_checkUpdateWaiting, this is the last used update channel
|
||||
*/
|
||||
QString m_deferredUpdateChannel;
|
||||
int m_currentBuild = -1;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user