NOISSUE rearrange MultiMC.cpp to make it make more sense

This commit is contained in:
Petr Mrázek 2016-10-31 00:57:40 +01:00
parent a36c962a31
commit 4b03dfcbd7
2 changed files with 63 additions and 64 deletions

View File

@ -202,11 +202,10 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
{ {
m_peerInstance->sendMessage(m_instanceIdToLaunch, 2000); m_peerInstance->sendMessage(m_instanceIdToLaunch, 2000);
} }
quit(); m_status = MultiMC::Succeeded;
return; return;
} }
// in test mode, root path is the same as the binary path.
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QDir foo(FS::PathCombine(binPath, "..")); QDir foo(FS::PathCombine(binPath, ".."));
m_rootPath = foo.absolutePath(); m_rootPath = foo.absolutePath();
@ -255,63 +254,17 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
m_translationChecker.reset(new TranslationDownloader()); m_translationChecker.reset(new TranslationDownloader());
// load icons
initIcons(); initIcons();
// load themes
initThemes(); initThemes();
initInstances();
// and instances initAccounts();
auto InstDirSetting = m_settings->getSetting("InstanceDir"); initNetwork();
// instance path: check for problems with '!' in instance path and warn the user in the log
// and rememer that we have to show him a dialog when the gui starts (if it does so)
QString instDir = m_settings->get("InstanceDir").toString();
qDebug() << "Instance path : " << instDir;
if (FS::checkProblemticPathJava(QDir(instDir)))
{
qWarning()
<< "Your instance path contains \'!\' and this is known to cause java problems";
}
m_instances.reset(new InstanceList(m_settings, InstDirSetting->get().toString(), this));
m_instanceFolder = new FolderInstanceProvider(m_settings, instDir);
connect(InstDirSetting.get(), &Setting::SettingChanged, m_instanceFolder, &FolderInstanceProvider::on_InstFolderChanged);
m_instances->addInstanceProvider(m_instanceFolder);
m_instances->addInstanceProvider(new FTBInstanceProvider(m_settings));
qDebug() << "Loading Instances...";
m_instances->loadList(true);
// and accounts
m_accounts.reset(new MojangAccountList(this));
qDebug() << "Loading accounts...";
m_accounts->setListFilePath("accounts.json", true);
m_accounts->loadList();
// init the http meta cache
ENV.initHttpMetaCache();
// create the global network manager
ENV.m_qnam.reset(new QNetworkAccessManager(this));
// 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);
}
initSSL();
m_translationChecker->downloadTranslations(); m_translationChecker->downloadTranslations();
//FIXME: what to do with these? //FIXME: what to do with these?
m_profilers.insert("jprofiler", m_profilers.insert("jprofiler", std::shared_ptr<BaseProfilerFactory>(new JProfilerFactory()));
std::shared_ptr<BaseProfilerFactory>(new JProfilerFactory())); m_profilers.insert("jvisualvm", std::shared_ptr<BaseProfilerFactory>(new JVisualVMFactory()));
m_profilers.insert("jvisualvm",
std::shared_ptr<BaseProfilerFactory>(new JVisualVMFactory()));
for (auto profiler : m_profilers.values()) for (auto profiler : m_profilers.values())
{ {
profiler->registerSettings(m_settings); profiler->registerSettings(m_settings);
@ -330,6 +283,7 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
setIconTheme(settings()->get("IconTheme").toString()); setIconTheme(settings()->get("IconTheme").toString());
setApplicationTheme(settings()->get("ApplicationTheme").toString()); setApplicationTheme(settings()->get("ApplicationTheme").toString());
if(!m_instanceIdToLaunch.isEmpty()) if(!m_instanceIdToLaunch.isEmpty())
{ {
auto inst = instances()->getInstanceById(m_instanceIdToLaunch); auto inst = instances()->getInstanceById(m_instanceIdToLaunch);
@ -384,8 +338,24 @@ void MultiMC::messageReceived(const QString& message)
#include "CertWorkaround.h" #include "CertWorkaround.h"
#endif #endif
void MultiMC::initSSL() void MultiMC::initNetwork()
{ {
// init the http meta cache
ENV.initHttpMetaCache();
// create the global network manager
ENV.m_qnam.reset(new QNetworkAccessManager(this));
// 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);
}
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
Q_INIT_RESOURCE(certs); Q_INIT_RESOURCE(certs);
RebuildQtCertificates(); RebuildQtCertificates();
@ -446,15 +416,6 @@ void MultiMC::initIcons()
ENV.registerIconList(m_icons); ENV.registerIconList(m_icons);
} }
static void moveFile(const QString &oldName, const QString &newName)
{
QFile::remove(newName);
QFile::copy(oldName, newName);
QFile::remove(oldName);
}
void appDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) void appDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{ {
const char *levels = "DWCF"; const char *levels = "DWCF";
@ -475,6 +436,13 @@ void appDebugOutput(QtMsgType type, const QMessageLogContext &context, const QSt
fflush(stderr); fflush(stderr);
} }
static void moveFile(const QString &oldName, const QString &newName)
{
QFile::remove(newName);
QFile::copy(oldName, newName);
QFile::remove(oldName);
}
void MultiMC::initLogger() void MultiMC::initLogger()
{ {
static const QString logBase = "MultiMC-%0.log"; static const QString logBase = "MultiMC-%0.log";
@ -490,6 +458,35 @@ void MultiMC::initLogger()
logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate); logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
} }
void MultiMC::initInstances()
{
auto InstDirSetting = m_settings->getSetting("InstanceDir");
// instance path: check for problems with '!' in instance path and warn the user in the log
// and rememer that we have to show him a dialog when the gui starts (if it does so)
QString instDir = m_settings->get("InstanceDir").toString();
qDebug() << "Instance path : " << instDir;
if (FS::checkProblemticPathJava(QDir(instDir)))
{
qWarning() << "Your instance path contains \'!\' and this is known to cause java problems";
}
m_instances.reset(new InstanceList(m_settings, InstDirSetting->get().toString(), this));
m_instanceFolder = new FolderInstanceProvider(m_settings, instDir);
connect(InstDirSetting.get(), &Setting::SettingChanged, m_instanceFolder, &FolderInstanceProvider::on_InstFolderChanged);
m_instances->addInstanceProvider(m_instanceFolder);
m_instances->addInstanceProvider(new FTBInstanceProvider(m_settings));
qDebug() << "Loading Instances...";
m_instances->loadList(true);
}
void MultiMC::initAccounts()
{
// and accounts
m_accounts.reset(new MojangAccountList(this));
qDebug() << "Loading accounts...";
m_accounts->setListFilePath("accounts.json", true);
m_accounts->loadList();
}
void MultiMC::initGlobalSettings() void MultiMC::initGlobalSettings()
{ {
m_settings.reset(new INISettingsObject("multimc.cfg", this)); m_settings.reset(new INISettingsObject("multimc.cfg", this));

View File

@ -160,7 +160,9 @@ private:
void initThemes(); void initThemes();
void initGlobalSettings(); void initGlobalSettings();
void initTranslations(); void initTranslations();
void initSSL(); void initNetwork();
void initInstances();
void initAccounts();
private: private:
QDateTime startTime; QDateTime startTime;