2015-01-31 15:59:03 +00:00
|
|
|
#include "Env.h"
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "net/HttpMetaCache.h"
|
2015-02-02 00:09:28 +00:00
|
|
|
#include "BaseVersion.h"
|
|
|
|
#include "BaseVersionList.h"
|
2015-01-31 15:59:03 +00:00
|
|
|
#include <QDir>
|
2017-05-13 00:24:15 +01:00
|
|
|
#include <QCoreApplication>
|
2015-01-31 15:59:03 +00:00
|
|
|
#include <QNetworkProxy>
|
|
|
|
#include <QNetworkAccessManager>
|
2015-02-02 01:14:14 +00:00
|
|
|
#include <QDebug>
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "tasks/Task.h"
|
2017-03-11 00:39:45 +00:00
|
|
|
#include "meta/Index.h"
|
2017-05-13 00:24:15 +01:00
|
|
|
#include "FileSystem.h"
|
2015-01-31 18:21:47 +00:00
|
|
|
#include <QDebug>
|
2015-01-31 15:59:03 +00:00
|
|
|
|
2016-11-06 20:58:54 +00:00
|
|
|
|
2017-07-05 17:02:49 +01:00
|
|
|
struct Env::Private
|
2016-11-06 20:58:54 +00:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
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;
|
2018-08-01 19:05:18 +01:00
|
|
|
QSet<QString> m_features;
|
2016-11-06 20:58:54 +00:00
|
|
|
};
|
|
|
|
|
2016-11-07 01:28:18 +00:00
|
|
|
static Env * instance;
|
|
|
|
|
2015-02-02 00:09:28 +00:00
|
|
|
/*
|
|
|
|
* The *NEW* global rat nest of an object. Handle with care.
|
|
|
|
*/
|
|
|
|
|
2015-01-31 15:59:03 +00:00
|
|
|
Env::Env()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
d = new Private();
|
2015-01-31 15:59:03 +00:00
|
|
|
}
|
|
|
|
|
2016-11-06 20:58:54 +00:00
|
|
|
Env::~Env()
|
2015-01-31 15:59:03 +00:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
delete d;
|
2015-01-31 15:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Env& Env::Env::getInstance()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
if(!instance)
|
|
|
|
{
|
|
|
|
instance = new Env();
|
|
|
|
}
|
|
|
|
return *instance;
|
2016-11-07 01:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Env::dispose()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
delete instance;
|
|
|
|
instance = nullptr;
|
2015-01-31 15:59:03 +00:00
|
|
|
}
|
|
|
|
|
2016-11-06 20:58:54 +00:00
|
|
|
shared_qobject_ptr< HttpMetaCache > Env::metacache()
|
2015-01-31 18:21:47 +00:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
return d->m_metacache;
|
2015-01-31 18:21:47 +00:00
|
|
|
}
|
|
|
|
|
2016-11-06 20:58:54 +00:00
|
|
|
QNetworkAccessManager& Env::qnam() const
|
2015-01-31 18:21:47 +00:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
return d->m_qnam;
|
2015-01-31 18:21:47 +00:00
|
|
|
}
|
|
|
|
|
2016-05-02 23:27:28 +01:00
|
|
|
std::shared_ptr<IIconList> Env::icons()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
return d->m_iconlist;
|
2016-05-02 23:27:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Env::registerIconList(std::shared_ptr<IIconList> iconlist)
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
d->m_iconlist = iconlist;
|
2016-05-02 23:27:28 +01:00
|
|
|
}
|
|
|
|
|
2017-03-11 00:39:45 +00:00
|
|
|
shared_qobject_ptr<Meta::Index> Env::metadataIndex()
|
2016-04-06 22:09:30 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
if (!d->m_metadataIndex)
|
|
|
|
{
|
|
|
|
d->m_metadataIndex.reset(new Meta::Index());
|
|
|
|
}
|
|
|
|
return d->m_metadataIndex;
|
2016-04-06 22:09:30 +01:00
|
|
|
}
|
|
|
|
|
2015-01-31 18:21:47 +00:00
|
|
|
|
2015-12-27 02:34:03 +00:00
|
|
|
void Env::initHttpMetaCache()
|
2015-01-31 15:59:03 +00:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
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());
|
2020-08-24 23:13:43 +01:00
|
|
|
m_metacache->addBase("ATLauncherPacks", QDir("cache/ATLauncherPacks").absolutePath());
|
2018-07-15 13:51:05 +01:00
|
|
|
m_metacache->addBase("FTBPacks", QDir("cache/FTBPacks").absolutePath());
|
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 16:14:47 +01:00
|
|
|
m_metacache->addBase("ModpacksCHPacks", QDir("cache/ModpacksCHPacks").absolutePath());
|
2020-06-07 16:46:12 +01:00
|
|
|
m_metacache->addBase("TechnicPacks", QDir("cache/TechnicPacks").absolutePath());
|
2020-03-31 02:13:19 +01:00
|
|
|
m_metacache->addBase("TwitchPacks", QDir("cache/TwitchPacks").absolutePath());
|
2018-07-15 13:51:05 +01:00
|
|
|
m_metacache->addBase("skins", QDir("accounts/skins").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();
|
2015-01-31 15:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Env::updateProxySettings(QString proxyTypeStr, QString addr, int port, QString user, QString password)
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
// 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;
|
|
|
|
}
|
2021-02-06 19:16:04 +00:00
|
|
|
proxyDesc += QString("%1:%2")
|
2018-07-15 13:51:05 +01:00
|
|
|
.arg(proxy.hostName())
|
2021-02-06 19:16:04 +00:00
|
|
|
.arg(proxy.port());
|
2018-07-15 13:51:05 +01:00
|
|
|
qDebug() << proxyDesc;
|
2015-01-31 15:59:03 +00:00
|
|
|
}
|
2015-02-02 00:09:28 +00:00
|
|
|
|
2017-05-13 00:24:15 +01:00
|
|
|
QString Env::getJarsPath()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
if(d->m_jarsPath.isEmpty())
|
|
|
|
{
|
|
|
|
return FS::PathCombine(QCoreApplication::applicationDirPath(), "jars");
|
|
|
|
}
|
|
|
|
return d->m_jarsPath;
|
2017-05-13 00:24:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Env::setJarsPath(const QString& path)
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
d->m_jarsPath = path;
|
2017-05-13 00:24:15 +01:00
|
|
|
}
|
2018-08-01 19:05:18 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|