2015-01-31 21:29:03 +05:30
|
|
|
#include "Env.h"
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "net/HttpMetaCache.h"
|
2015-02-02 05:39:28 +05:30
|
|
|
#include "BaseVersion.h"
|
|
|
|
#include "BaseVersionList.h"
|
2015-01-31 21:29:03 +05:30
|
|
|
#include <QDir>
|
|
|
|
#include <QNetworkProxy>
|
|
|
|
#include <QNetworkAccessManager>
|
2015-02-02 06:44:14 +05:30
|
|
|
#include <QDebug>
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "tasks/Task.h"
|
2016-04-07 02:39:30 +05:30
|
|
|
#include "wonko/WonkoIndex.h"
|
2015-01-31 23:51:47 +05:30
|
|
|
#include <QDebug>
|
2015-01-31 21:29:03 +05:30
|
|
|
|
2016-11-07 02:28:54 +05:30
|
|
|
|
|
|
|
class Env::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QNetworkAccessManager m_qnam;
|
|
|
|
shared_qobject_ptr<HttpMetaCache> m_metacache;
|
|
|
|
std::shared_ptr<IIconList> m_iconlist;
|
|
|
|
QMap<QString, std::shared_ptr<BaseVersionList>> m_versionLists;
|
|
|
|
shared_qobject_ptr<WonkoIndex> m_wonkoIndex;
|
|
|
|
QString m_wonkoRootUrl;
|
|
|
|
};
|
|
|
|
|
2015-02-02 05:39:28 +05:30
|
|
|
/*
|
|
|
|
* The *NEW* global rat nest of an object. Handle with care.
|
|
|
|
*/
|
|
|
|
|
2015-01-31 21:29:03 +05:30
|
|
|
Env::Env()
|
|
|
|
{
|
2016-11-07 02:28:54 +05:30
|
|
|
d = new Private();
|
2015-01-31 21:29:03 +05:30
|
|
|
}
|
|
|
|
|
2016-11-07 02:28:54 +05:30
|
|
|
Env::~Env()
|
2015-01-31 21:29:03 +05:30
|
|
|
{
|
2016-11-07 02:28:54 +05:30
|
|
|
delete d;
|
2015-01-31 21:29:03 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
Env& Env::Env::getInstance()
|
|
|
|
{
|
|
|
|
static Env instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2016-11-07 02:28:54 +05:30
|
|
|
shared_qobject_ptr< HttpMetaCache > Env::metacache()
|
2015-01-31 23:51:47 +05:30
|
|
|
{
|
2016-11-07 02:28:54 +05:30
|
|
|
return d->m_metacache;
|
2015-01-31 23:51:47 +05:30
|
|
|
}
|
|
|
|
|
2016-11-07 02:28:54 +05:30
|
|
|
QNetworkAccessManager& Env::qnam() const
|
2015-01-31 23:51:47 +05:30
|
|
|
{
|
2016-11-07 02:28:54 +05:30
|
|
|
return d->m_qnam;
|
2015-01-31 23:51:47 +05:30
|
|
|
}
|
|
|
|
|
2016-05-03 03:57:28 +05:30
|
|
|
std::shared_ptr<IIconList> Env::icons()
|
|
|
|
{
|
2016-11-07 02:28:54 +05:30
|
|
|
return d->m_iconlist;
|
2016-05-03 03:57:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void Env::registerIconList(std::shared_ptr<IIconList> iconlist)
|
|
|
|
{
|
2016-11-07 02:28:54 +05:30
|
|
|
d->m_iconlist = iconlist;
|
2016-05-03 03:57:28 +05:30
|
|
|
}
|
|
|
|
|
2015-02-02 05:39:28 +05:30
|
|
|
BaseVersionPtr Env::getVersion(QString component, QString version)
|
|
|
|
{
|
|
|
|
auto list = getVersionList(component);
|
2015-04-02 23:48:23 +05:30
|
|
|
if(!list)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-02-02 05:39:28 +05:30
|
|
|
return list->findVersion(version);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr< BaseVersionList > Env::getVersionList(QString component)
|
|
|
|
{
|
2016-11-07 02:28:54 +05:30
|
|
|
auto iter = d->m_versionLists.find(component);
|
|
|
|
if(iter != d->m_versionLists.end())
|
2015-02-02 05:39:28 +05:30
|
|
|
{
|
|
|
|
return *iter;
|
|
|
|
}
|
|
|
|
//return std::make_shared<NullVersionList>();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Env::registerVersionList(QString name, std::shared_ptr< BaseVersionList > vlist)
|
|
|
|
{
|
2016-11-07 02:28:54 +05:30
|
|
|
d->m_versionLists[name] = vlist;
|
2015-02-02 05:39:28 +05:30
|
|
|
}
|
|
|
|
|
2016-11-07 02:28:54 +05:30
|
|
|
shared_qobject_ptr<WonkoIndex> Env::wonkoIndex()
|
2016-04-07 02:39:30 +05:30
|
|
|
{
|
2016-11-07 02:28:54 +05:30
|
|
|
if (!d->m_wonkoIndex)
|
2016-04-07 02:39:30 +05:30
|
|
|
{
|
2016-11-07 02:28:54 +05:30
|
|
|
d->m_wonkoIndex.reset(new WonkoIndex());
|
2016-04-07 02:39:30 +05:30
|
|
|
}
|
2016-11-07 02:28:54 +05:30
|
|
|
return d->m_wonkoIndex;
|
2016-04-07 02:39:30 +05:30
|
|
|
}
|
|
|
|
|
2015-01-31 23:51:47 +05:30
|
|
|
|
2015-12-27 08:04:03 +05:30
|
|
|
void Env::initHttpMetaCache()
|
2015-01-31 21:29:03 +05:30
|
|
|
{
|
2016-11-07 02:28:54 +05:30
|
|
|
auto &m_metacache = d->m_metacache;
|
2015-01-31 21:29:03 +05:30
|
|
|
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());
|
2015-12-27 08:04:03 +05:30
|
|
|
m_metacache->addBase("root", QDir::currentPath());
|
|
|
|
m_metacache->addBase("translations", QDir("translations").absolutePath());
|
2015-05-28 23:08:29 +05:30
|
|
|
m_metacache->addBase("icons", QDir("cache/icons").absolutePath());
|
2016-04-07 02:39:30 +05:30
|
|
|
m_metacache->addBase("wonko", QDir("cache/wonko").absolutePath());
|
2015-01-31 21:29:03 +05:30
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-02-02 06:44:14 +05:30
|
|
|
qDebug() << "Detecting proxy settings...";
|
2015-01-31 21:29:03 +05:30
|
|
|
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
|
2016-11-07 02:28:54 +05:30
|
|
|
d->m_qnam.setProxy(proxy);
|
2015-01-31 21:29:03 +05:30
|
|
|
QString proxyDesc;
|
|
|
|
if (proxy.type() == QNetworkProxy::NoProxy)
|
|
|
|
{
|
2015-02-02 06:44:14 +05:30
|
|
|
qDebug() << "Using no proxy is an option!";
|
2015-01-31 21:29:03 +05:30
|
|
|
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());
|
2015-02-02 06:44:14 +05:30
|
|
|
qDebug() << proxyDesc;
|
2015-01-31 21:29:03 +05:30
|
|
|
}
|
2015-02-02 05:39:28 +05:30
|
|
|
|
2016-11-07 02:28:54 +05:30
|
|
|
QString Env::wonkoRootUrl() const
|
|
|
|
{
|
|
|
|
return d->m_wonkoRootUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Env::setWonkoRootUrl(const QString& url)
|
|
|
|
{
|
|
|
|
d->m_wonkoRootUrl = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "Env.moc"
|