diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | Hacks.cpp | 8 | ||||
-rw-r--r-- | MultiMC.cpp | 125 | ||||
-rw-r--r-- | MultiMC.h | 5 | ||||
-rw-r--r-- | gui/dialogs/SettingsDialog.cpp | 37 | ||||
-rw-r--r-- | gui/dialogs/SettingsDialog.h | 1 | ||||
-rw-r--r-- | gui/dialogs/SettingsDialog.ui | 162 | ||||
-rw-r--r-- | logic/JavaChecker.cpp | 2 | ||||
-rw-r--r-- | logic/JavaChecker.h | 2 | ||||
-rw-r--r-- | logic/JavaCheckerJob.cpp | 6 | ||||
-rw-r--r-- | logic/lists/JavaVersionList.cpp | 4 | ||||
-rw-r--r-- | logic/updater/UpdateChecker.cpp | 4 |
12 files changed, 302 insertions, 56 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a9bd32c..160d09f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -529,7 +529,7 @@ QT5_ADD_RESOURCES(GRAPHICS_QRC graphics.qrc) ADD_LIBRARY(MultiMC_common STATIC ${MULTIMC_SOURCES} ${MULTIMC_UI} ${GENERATED_QRC} ${GRAPHICS_QRC}) # Add executable -ADD_EXECUTABLE(MultiMC MACOSX_BUNDLE WIN32 main.cpp ${MULTIMC_RCS}) +ADD_EXECUTABLE(MultiMC MACOSX_BUNDLE WIN32 main.cpp Hacks.cpp ${MULTIMC_RCS}) # Link TARGET_LINK_LIBRARIES(MultiMC MultiMC_common) diff --git a/Hacks.cpp b/Hacks.cpp new file mode 100644 index 00000000..3c3d8191 --- /dev/null +++ b/Hacks.cpp @@ -0,0 +1,8 @@ +#include "MultiMC.h" + +#ifdef Q_OS_WIN32 +extern "C" +{ +__declspec(dllexport) uint32_t NvOptimusEnablement = 0x00000001; +} +#endif diff --git a/MultiMC.cpp b/MultiMC.cpp index 297d08fd..7c411693 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -198,56 +198,12 @@ MultiMC::MultiMC(int &argc, char **argv, bool root_override) // init the http meta cache initHttpMetaCache(); - // set up a basic autodetected proxy (system default) - QNetworkProxyFactory::setUseSystemConfiguration(true); - - QLOG_INFO() << "Detecting system proxy settings..."; - auto proxies = QNetworkProxyFactory::systemProxyForQuery(); - if (proxies.size() == 1 && proxies[0].type() == QNetworkProxy::NoProxy) - { - QLOG_INFO() << "No proxy found."; - } - else - for (auto proxy : proxies) - { - QString proxyDesc; - if (proxy.type() == QNetworkProxy::NoProxy) - { - QLOG_INFO() << "Using no proxy is an option!"; - continue; - } - 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; - } - // create the global network manager m_qnam.reset(new QNetworkAccessManager(this)); + // init proxy settings + updateProxySettings(); + // launch instance, if that's what should be done // WARNING: disabled until further notice /* @@ -424,6 +380,13 @@ void MultiMC::initGlobalSettings() m_settings->registerSetting({"MinecraftWinWidth", "MCWindowWidth"}, 854); m_settings->registerSetting({"MinecraftWinHeight", "MCWindowHeight"}, 480); + // Proxy Settings + m_settings->registerSetting("ProxyType", "Default"); + m_settings->registerSetting({"ProxyAddr", "ProxyHostName"}, "127.0.0.1"); + m_settings->registerSetting("ProxyPort", 8080); + m_settings->registerSetting({"ProxyUser", "ProxyUsername"}, ""); + m_settings->registerSetting({"ProxyPass", "ProxyPassword"}, ""); + // Memory m_settings->registerSetting({"MinMemAlloc", "MinMemoryAlloc"}, 512); m_settings->registerSetting({"MaxMemAlloc", "MaxMemoryAlloc"}, 1024); @@ -467,6 +430,74 @@ void MultiMC::initHttpMetaCache() m_metacache->Load(); } +void MultiMC::updateProxySettings() +{ + QString proxyTypeStr = settings()->get("ProxyType").toString(); + + // Get the proxy settings from the settings object. + 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(); + + // Set the application proxy settings. + if (proxyTypeStr == "SOCKS5") + { + QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, addr, port, user, pass)); + } + else if (proxyTypeStr == "HTTP") + { + QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, addr, port, user, pass)); + } + 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; +} + std::shared_ptr<IconList> MultiMC::icons() { if (!m_icons) @@ -124,6 +124,11 @@ public: void installUpdates(const QString updateFilesDir, UpdateFlags flags = None); /*! + * Updates the application proxy settings from the settings object. + */ + void updateProxySettings(); + + /*! * Opens a json file using either a system default editor, or, if note empty, the editor * specified in the settings */ diff --git a/gui/dialogs/SettingsDialog.cpp b/gui/dialogs/SettingsDialog.cpp index 549b11b0..00b3b1fd 100644 --- a/gui/dialogs/SettingsDialog.cpp +++ b/gui/dialogs/SettingsDialog.cpp @@ -61,6 +61,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se { MMC->updateChecker()->updateChanList(); } + connect(ui->proxyGroup, SIGNAL(buttonClicked(int)), SLOT(proxyChanged(int))); } SettingsDialog::~SettingsDialog() @@ -83,6 +84,8 @@ void SettingsDialog::updateCheckboxStuff() { ui->windowWidthSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked()); ui->windowHeightSpinBox->setEnabled(!ui->maximizedCheckBox->isChecked()); + ui->proxyAddrBox->setEnabled(!ui->proxyNoneBtn->isChecked() && !ui->proxyDefaultBtn->isChecked()); + ui->proxyAuthBox->setEnabled(!ui->proxyNoneBtn->isChecked() && !ui->proxyDefaultBtn->isChecked()); } void SettingsDialog::on_ftbLauncherBrowseBtn_clicked() @@ -202,6 +205,9 @@ void SettingsDialog::on_buttonBox_accepted() { applySettings(MMC->settings().get()); + // Apply proxy settings + MMC->updateProxySettings(); + MMC->settings()->set("SettingsGeometry", saveGeometry().toBase64()); } @@ -210,6 +216,11 @@ void SettingsDialog::on_buttonBox_rejected() MMC->settings()->set("SettingsGeometry", saveGeometry().toBase64()); } +void SettingsDialog::proxyChanged(int) +{ + updateCheckboxStuff(); +} + void SettingsDialog::refreshUpdateChannelList() { // Stop listening for selection changes. It's going to change a lot while we update it and we don't need to update the @@ -310,6 +321,19 @@ void SettingsDialog::applySettings(SettingsObject *s) s->set("MinecraftWinWidth", ui->windowWidthSpinBox->value()); s->set("MinecraftWinHeight", ui->windowHeightSpinBox->value()); + // Proxy + QString proxyType = "None"; + if (ui->proxyDefaultBtn->isChecked()) proxyType = "Default"; + else if (ui->proxyNoneBtn->isChecked()) proxyType = "None"; + else if (ui->proxySOCKS5Btn->isChecked()) proxyType = "SOCKS5"; + else if (ui->proxyHTTPBtn->isChecked()) proxyType = "HTTP"; + + s->set("ProxyType", proxyType); + s->set("ProxyAddr", ui->proxyAddrEdit->text()); + s->set("ProxyPort", ui->proxyPortEdit->value()); + s->set("ProxyUser", ui->proxyUserEdit->text()); + s->set("ProxyPass", ui->proxyPassEdit->text()); + // Memory s->set("MinMemAlloc", ui->minMemSpinBox->value()); s->set("MaxMemAlloc", ui->maxMemSpinBox->value()); @@ -384,6 +408,18 @@ void SettingsDialog::loadSettings(SettingsObject *s) ui->sortByNameBtn->setChecked(true); } + // Proxy + QString proxyType = s->get("ProxyType").toString(); + if (proxyType == "Default") ui->proxyDefaultBtn->setChecked(true); + else if (proxyType == "None") ui->proxyNoneBtn->setChecked(true); + else if (proxyType == "SOCKS5") ui->proxySOCKS5Btn->setChecked(true); + else if (proxyType == "HTTP") ui->proxyHTTPBtn->setChecked(true); + + ui->proxyAddrEdit->setText(s->get("ProxyAddr").toString()); + ui->proxyPortEdit->setValue(s->get("ProxyPort").value<qint16>()); + ui->proxyUserEdit->setText(s->get("ProxyUser").toString()); + ui->proxyPassEdit->setText(s->get("ProxyPass").toString()); + // Java Settings ui->javaPathTextBox->setText(s->get("JavaPath").toString()); ui->jvmArgsTextBox->setText(s->get("JvmArgs").toString()); @@ -447,4 +483,3 @@ void SettingsDialog::checkFinished(JavaCheckResult result) "or set the path to the java executable.")); } } - diff --git a/gui/dialogs/SettingsDialog.h b/gui/dialogs/SettingsDialog.h index df67d492..d7bbbeb3 100644 --- a/gui/dialogs/SettingsDialog.h +++ b/gui/dialogs/SettingsDialog.h @@ -86,6 +86,7 @@ slots: void refreshUpdateChannelDesc(); void updateChannelSelectionChanged(int index); + void proxyChanged(int); private: Ui::SettingsDialog *ui; diff --git a/gui/dialogs/SettingsDialog.ui b/gui/dialogs/SettingsDialog.ui index 7d2708cb..e7671cce 100644 --- a/gui/dialogs/SettingsDialog.ui +++ b/gui/dialogs/SettingsDialog.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>526</width> - <height>639</height> + <height>723</height> </rect> </property> <property name="sizePolicy"> @@ -424,6 +424,165 @@ </item> </layout> </widget> + <widget class="QWidget" name="networkTab"> + <property name="toolTip"> + <string>Network settings.</string> + </property> + <attribute name="title"> + <string>Network</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_6"> + <item> + <widget class="QGroupBox" name="proxySettingsBox"> + <property name="title"> + <string>Proxy</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_8"> + <item> + <widget class="QGroupBox" name="proxyTypeBox"> + <property name="title"> + <string>Type</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QRadioButton" name="proxyDefaultBtn"> + <property name="toolTip"> + <string>Uses your system's default proxy settings.</string> + </property> + <property name="text"> + <string>Default</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">proxyGroup</string> + </attribute> + </widget> + </item> + <item> + <widget class="QRadioButton" name="proxyNoneBtn"> + <property name="text"> + <string>None</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">proxyGroup</string> + </attribute> + </widget> + </item> + <item> + <widget class="QRadioButton" name="proxySOCKS5Btn"> + <property name="text"> + <string>SOCKS5</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">proxyGroup</string> + </attribute> + </widget> + </item> + <item> + <widget class="QRadioButton" name="proxyHTTPBtn"> + <property name="text"> + <string>HTTP</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">proxyGroup</string> + </attribute> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="proxyAddrBox"> + <property name="title"> + <string>Address and Port</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLineEdit" name="proxyAddrEdit"> + <property name="placeholderText"> + <string>127.0.0.1</string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="proxyPortEdit"> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="buttonSymbols"> + <enum>QAbstractSpinBox::PlusMinus</enum> + </property> + <property name="maximum"> + <number>65535</number> + </property> + <property name="value"> + <number>8080</number> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="proxyAuthBox"> + <property name="title"> + <string>Authentication</string> + </property> + <layout class="QGridLayout" name="gridLayout_5"> + <item row="0" column="1"> + <widget class="QLineEdit" name="proxyUserEdit"/> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="proxyUsernameLabel"> + <property name="text"> + <string>Username:</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="proxyPasswordLabel"> + <property name="text"> + <string>Password:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="proxyPassEdit"> + <property name="echoMode"> + <enum>QLineEdit::Password</enum> + </property> + </widget> + </item> + <item row="2" column="0" colspan="2"> + <widget class="QLabel" name="proxyPlainTextWarningLabel"> + <property name="text"> + <string>Note: Proxy username and password are stored in plain text inside MultiMC's configuration file!</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> <widget class="QWidget" name="javaTab"> <attribute name="title"> <string>Java</string> @@ -737,5 +896,6 @@ </connections> <buttongroups> <buttongroup name="sortingModeGroup"/> + <buttongroup name="proxyGroup"/> </buttongroups> </ui> diff --git a/logic/JavaChecker.cpp b/logic/JavaChecker.cpp index 113974ff..a470bfa2 100644 --- a/logic/JavaChecker.cpp +++ b/logic/JavaChecker.cpp @@ -47,6 +47,7 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status) JavaCheckResult result; { result.path = path; + result.id = id; } if (status == QProcess::CrashExit || exitcode == 1) @@ -104,6 +105,7 @@ void JavaChecker::error(QProcess::ProcessError err) JavaCheckResult result; { result.path = path; + result.id = id; } emit checkFinished(result); diff --git a/logic/JavaChecker.h b/logic/JavaChecker.h index 291bf46c..4705381c 100644 --- a/logic/JavaChecker.h +++ b/logic/JavaChecker.h @@ -15,6 +15,7 @@ struct JavaCheckResult QString javaVersion; bool valid = false; bool is_64bit = false; + int id; }; typedef std::shared_ptr<QProcess> QProcessPtr; @@ -27,6 +28,7 @@ public: void performCheck(); QString path; + int id; signals: void checkFinished(JavaCheckResult result); diff --git a/logic/JavaCheckerJob.cpp b/logic/JavaCheckerJob.cpp index 36a8a050..b0aea758 100644 --- a/logic/JavaCheckerJob.cpp +++ b/logic/JavaCheckerJob.cpp @@ -26,10 +26,7 @@ void JavaCheckerJob::partFinished(JavaCheckResult result) << javacheckers.size(); emit progress(num_finished, javacheckers.size()); - javaresults.append(result); - int result_size = javacheckers.size(); - - emit progress(num_finished, result_size); + javaresults.replace(result.id, result); if (num_finished == javacheckers.size()) { @@ -43,6 +40,7 @@ void JavaCheckerJob::start() m_running = true; for (auto iter : javacheckers) { + javaresults.append(JavaCheckResult()); connect(iter.get(), SIGNAL(checkFinished(JavaCheckResult)), SLOT(partFinished(JavaCheckResult))); iter->performCheck(); } diff --git a/logic/lists/JavaVersionList.cpp b/logic/lists/JavaVersionList.cpp index e8c5acd0..eb1c5650 100644 --- a/logic/lists/JavaVersionList.cpp +++ b/logic/lists/JavaVersionList.cpp @@ -182,13 +182,17 @@ void JavaListLoadTask::executeTask() connect(m_job.get(), SIGNAL(progress(int, int)), this, SLOT(checkerProgress(int, int))); QLOG_DEBUG() << "Probing the following Java paths: "; + int id = 0; for(QString candidate : candidate_paths) { QLOG_DEBUG() << " " << candidate; auto candidate_checker = new JavaChecker(); candidate_checker->path = candidate; + candidate_checker->id = id; m_job->addJavaCheckerAction(JavaCheckerPtr(candidate_checker)); + + id++; } m_job->start(); diff --git a/logic/updater/UpdateChecker.cpp b/logic/updater/UpdateChecker.cpp index 489e7769..8a280dd1 100644 --- a/logic/updater/UpdateChecker.cpp +++ b/logic/updater/UpdateChecker.cpp @@ -142,8 +142,6 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate) if (newestVersion.value("Id").toVariant().toInt() < version.value("Id").toVariant().toInt()) { - QLOG_DEBUG() << "Found newer version with ID" - << version.value("Id").toVariant().toInt(); newestVersion = version; } } @@ -153,6 +151,7 @@ void UpdateChecker::updateCheckFinished(bool notifyNoUpdate) int newBuildNumber = newestVersion.value("Id").toVariant().toInt(); if (newBuildNumber != MMC->version().build) { + QLOG_DEBUG() << "Found newer version with ID" << newBuildNumber; // Update! emit updateAvailable(m_repoUrl, newestVersion.value("Name").toVariant().toString(), newBuildNumber); @@ -262,3 +261,4 @@ void UpdateChecker::chanListDownloadFailed() QLOG_ERROR() << "Failed to download channel list."; emit channelListLoaded(); } + |