Merge branch 'develop' into global-jvm-args

This commit is contained in:
Ryan Cao
2022-05-28 21:15:00 +08:00
committed by GitHub
87 changed files with 3327 additions and 1805 deletions

View File

@ -3,6 +3,7 @@
* PolyMC - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (c) 2022 Lenny McLennington <lenny@sneed.church>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -46,16 +47,43 @@
#include "settings/SettingsObject.h"
#include "tools/BaseProfiler.h"
#include "Application.h"
#include "net/PasteUpload.h"
#include "BuildConfig.h"
APIPage::APIPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::APIPage)
{
// This is here so you can reorder the entries in the combobox without messing stuff up
int comboBoxEntries[] = {
PasteUpload::PasteType::Mclogs,
PasteUpload::PasteType::NullPointer,
PasteUpload::PasteType::PasteGG,
PasteUpload::PasteType::Hastebin
};
static QRegularExpression validUrlRegExp("https?://.+");
ui->setupUi(this);
ui->urlChoices->setValidator(new QRegularExpressionValidator(validUrlRegExp, ui->urlChoices));
ui->tabWidget->tabBar()->hide();\
for (auto pasteType : comboBoxEntries) {
ui->pasteTypeComboBox->addItem(PasteUpload::PasteTypes.at(pasteType).name, pasteType);
}
void (QComboBox::*currentIndexChangedSignal)(int) (&QComboBox::currentIndexChanged);
connect(ui->pasteTypeComboBox, currentIndexChangedSignal, this, &APIPage::updateBaseURLPlaceholder);
// This function needs to be called even when the ComboBox's index is still in its default state.
updateBaseURLPlaceholder(ui->pasteTypeComboBox->currentIndex());
ui->baseURLEntry->setValidator(new QRegularExpressionValidator(validUrlRegExp, ui->baseURLEntry));
ui->tabWidget->tabBar()->hide();
ui->metaURL->setPlaceholderText(BuildConfig.META_URL);
loadSettings();
resetBaseURLNote();
connect(ui->pasteTypeComboBox, currentIndexChangedSignal, this, &APIPage::updateBaseURLNote);
connect(ui->baseURLEntry, &QLineEdit::textEdited, this, &APIPage::resetBaseURLNote);
}
APIPage::~APIPage()
@ -63,13 +91,52 @@ APIPage::~APIPage()
delete ui;
}
void APIPage::resetBaseURLNote()
{
ui->baseURLNote->hide();
baseURLPasteType = ui->pasteTypeComboBox->currentIndex();
}
void APIPage::updateBaseURLNote(int index)
{
if (baseURLPasteType == index)
{
ui->baseURLNote->hide();
}
else if (!ui->baseURLEntry->text().isEmpty())
{
ui->baseURLNote->show();
}
}
void APIPage::updateBaseURLPlaceholder(int index)
{
int pasteType = ui->pasteTypeComboBox->itemData(index).toInt();
QString pasteDefaultURL = PasteUpload::PasteTypes.at(pasteType).defaultBase;
ui->baseURLEntry->setPlaceholderText(pasteDefaultURL);
}
void APIPage::loadSettings()
{
auto s = APPLICATION->settings();
QString pastebinURL = s->get("PastebinURL").toString();
ui->urlChoices->setCurrentText(pastebinURL);
int pasteType = s->get("PastebinType").toInt();
QString pastebinURL = s->get("PastebinCustomAPIBase").toString();
ui->baseURLEntry->setText(pastebinURL);
int pasteTypeIndex = ui->pasteTypeComboBox->findData(pasteType);
if (pasteTypeIndex == -1)
{
pasteTypeIndex = ui->pasteTypeComboBox->findData(PasteUpload::PasteType::Mclogs);
ui->baseURLEntry->clear();
}
ui->pasteTypeComboBox->setCurrentIndex(pasteTypeIndex);
QString msaClientID = s->get("MSAClientIDOverride").toString();
ui->msaClientID->setText(msaClientID);
QString metaURL = s->get("MetaURLOverride").toString();
ui->metaURL->setText(metaURL);
QString curseKey = s->get("CFKeyOverride").toString();
ui->curseKey->setText(curseKey);
}
@ -77,10 +144,27 @@ void APIPage::loadSettings()
void APIPage::applySettings()
{
auto s = APPLICATION->settings();
QString pastebinURL = ui->urlChoices->currentText();
s->set("PastebinURL", pastebinURL);
s->set("PastebinType", ui->pasteTypeComboBox->currentData().toInt());
s->set("PastebinCustomAPIBase", ui->baseURLEntry->text());
QString msaClientID = ui->msaClientID->text();
s->set("MSAClientIDOverride", msaClientID);
QUrl metaURL = ui->metaURL->text();
// Add required trailing slash
if (!metaURL.isEmpty() && !metaURL.path().endsWith('/'))
{
QString path = metaURL.path();
path.append('/');
metaURL.setPath(path);
}
// Don't allow HTTP, since meta is basically RCE with all the jar files.
if(!metaURL.isEmpty() && metaURL.scheme() == "http")
{
metaURL.setScheme("https");
}
s->set("MetaURLOverride", metaURL);
QString curseKey = ui->curseKey->text();
s->set("CFKeyOverride", curseKey);
}

View File

@ -3,6 +3,7 @@
* PolyMC - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (c) 2022 Lenny McLennington <lenny@sneed.church>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -73,6 +74,10 @@ public:
void retranslate() override;
private:
int baseURLPasteType;
void resetBaseURLNote();
void updateBaseURLNote(int index);
void updateBaseURLPlaceholder(int index);
void loadSettings();
void applySettings();

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>603</width>
<height>530</height>
<width>800</width>
<height>600</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -36,60 +36,44 @@
<item>
<widget class="QGroupBox" name="groupBox_paste">
<property name="title">
<string>&amp;Pastebin URL</string>
<string>Pastebin Service</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<widget class="QLabel" name="pasteServiceTypeLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Note: only input that starts with &lt;span style=&quot; font-weight:600;&quot;&gt;http://&lt;/span&gt; or &lt;span style=&quot; font-weight:600;&quot;&gt;https://&lt;/span&gt; will be accepted.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="scaledContents">
<bool>false</bool>
<string>Paste Service Type</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="urlChoices">
<property name="editable">
<widget class="QComboBox" name="pasteTypeComboBox"/>
</item>
<item>
<widget class="QLabel" name="baseURLLabel">
<property name="text">
<string>Base URL</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="baseURLEntry">
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::NoInsert</enum>
</property>
<item>
<property name="text">
<string notr="true">https://0x0.st</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<widget class="QLabel" name="baseURLNote">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Here you can choose from a predefined list of paste services, or input the URL of a different paste service of your choice, provided it supports the same protocol as 0x0.st, that is POST a file parameter to the URL and return a link in the response body.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
<string>Note: you probably want to change or clear the Base URL after changing the paste service type.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
@ -101,13 +85,6 @@
<string>&amp;Microsoft Authentication</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
@ -147,6 +124,51 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_meta">
<property name="title">
<string>Meta&amp;data Server</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>You can set this to a third-party metadata server to use patched libraries or other hacks.</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="metaURL">
<property name="placeholderText">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Enter a custom URL for meta here.</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_curse">
<property name="enabled">
@ -155,16 +177,9 @@
<property name="title">
<string>&amp;CurseForge Core API</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Note: you probably don't need to set this if CurseForge already works.</string>
</property>
@ -181,7 +196,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Enter a custom API Key for CurseForge here. </string>
</property>
@ -199,6 +214,19 @@
</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>