Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into mods_txt
This commit is contained in:
commit
5bf091149d
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@ -86,11 +86,11 @@ jobs:
|
||||
|
||||
- os: macos-12
|
||||
name: macOS
|
||||
macosx_deployment_target: 10.15
|
||||
macosx_deployment_target: 11.0
|
||||
qt_ver: 6
|
||||
qt_host: mac
|
||||
qt_arch: ''
|
||||
qt_version: '6.5.1'
|
||||
qt_version: '6.5.0'
|
||||
qt_modules: 'qt5compat qtimageformats'
|
||||
qt_tools: ''
|
||||
|
||||
|
2
.github/workflows/trigger_release.yml
vendored
2
.github/workflows/trigger_release.yml
vendored
@ -47,7 +47,7 @@ jobs:
|
||||
mv PrismLauncher-macOS-Legacy*/PrismLauncher.tar.gz PrismLauncher-macOS-Legacy-${{ env.VERSION }}.tar.gz
|
||||
mv PrismLauncher-macOS*/PrismLauncher.tar.gz PrismLauncher-macOS-${{ env.VERSION }}.tar.gz
|
||||
|
||||
tar -czf PrismLauncher-${{ env.VERSION }}.tar.gz PrismLauncher-${{ env.VERSION }}
|
||||
tar --exclude='.git' -czf PrismLauncher-${{ env.VERSION }}.tar.gz PrismLauncher-${{ env.VERSION }}
|
||||
|
||||
for d in PrismLauncher-Windows-MSVC*; do
|
||||
cd "${d}" || continue
|
||||
|
@ -376,33 +376,33 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
|
||||
// init the logger
|
||||
{
|
||||
static const QString logBase = BuildConfig.LAUNCHER_NAME + "-%0.log";
|
||||
auto moveFile = [](const QString &oldName, const QString &newName)
|
||||
{
|
||||
static const QString baseLogFile = BuildConfig.LAUNCHER_NAME + "-%0.log";
|
||||
static const QString logBase = FS::PathCombine("logs", baseLogFile);
|
||||
auto moveFile = [](const QString& oldName, const QString& newName) {
|
||||
QFile::remove(newName);
|
||||
QFile::copy(oldName, newName);
|
||||
QFile::remove(oldName);
|
||||
};
|
||||
if (FS::ensureFolderPathExists("logs")) { // if this did not fail
|
||||
for (auto i = 0; i <= 4; i++)
|
||||
if (auto oldName = baseLogFile.arg(i);
|
||||
QFile::exists(oldName)) // do not pointlessly delete new files if the old ones are not there
|
||||
moveFile(oldName, logBase.arg(i));
|
||||
}
|
||||
|
||||
moveFile(logBase.arg(3), logBase.arg(4));
|
||||
moveFile(logBase.arg(2), logBase.arg(3));
|
||||
moveFile(logBase.arg(1), logBase.arg(2));
|
||||
moveFile(logBase.arg(0), logBase.arg(1));
|
||||
for (auto i = 4; i > 0; i--)
|
||||
moveFile(logBase.arg(i - 1), logBase.arg(i));
|
||||
|
||||
logFile = std::unique_ptr<QFile>(new QFile(logBase.arg(0)));
|
||||
if(!logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate))
|
||||
{
|
||||
showFatalErrorMessage(
|
||||
"The launcher data folder is not writable!",
|
||||
QString(
|
||||
"The launcher couldn't create a log file - the data folder is not writable.\n"
|
||||
if (!logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
|
||||
showFatalErrorMessage("The launcher data folder is not writable!",
|
||||
QString("The launcher couldn't create a log file - the data folder is not writable.\n"
|
||||
"\n"
|
||||
"Make sure you have write permissions to the data folder.\n"
|
||||
"(%1)\n"
|
||||
"\n"
|
||||
"The launcher cannot continue until you fix this problem."
|
||||
).arg(dataPath)
|
||||
);
|
||||
"The launcher cannot continue until you fix this problem.")
|
||||
.arg(dataPath));
|
||||
return;
|
||||
}
|
||||
qInstallMessageHandler(appDebugOutput);
|
||||
@ -1699,6 +1699,7 @@ bool Application::handleDataMigration(const QString& currentData,
|
||||
matcher->add(std::make_shared<SimplePrefixMatcher>(configFile));
|
||||
matcher->add(std::make_shared<SimplePrefixMatcher>(
|
||||
BuildConfig.LAUNCHER_CONFIGFILE)); // it's possible that we already used that directory before
|
||||
matcher->add(std::make_shared<SimplePrefixMatcher>("logs/"));
|
||||
matcher->add(std::make_shared<SimplePrefixMatcher>("accounts.json"));
|
||||
matcher->add(std::make_shared<SimplePrefixMatcher>("accounts/"));
|
||||
matcher->add(std::make_shared<SimplePrefixMatcher>("assets/"));
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "minecraft/mod/ModFolderModel.h"
|
||||
|
||||
const QStringList ModrinthPackExportTask::PREFIXES({ "mods", "coremods", "resourcepacks", "texturepacks", "shaderpacks" });
|
||||
const QStringList ModrinthPackExportTask::PREFIXES({ "mods/", "coremods/", "resourcepacks/", "texturepacks/", "shaderpacks/" });
|
||||
const QStringList ModrinthPackExportTask::FILE_EXTENSIONS({ "jar", "litemod", "zip" });
|
||||
|
||||
ModrinthPackExportTask::ModrinthPackExportTask(const QString& name,
|
||||
@ -99,14 +99,12 @@ void ModrinthPackExportTask::collectHashes()
|
||||
|
||||
const QString relative = gameRoot.relativeFilePath(file.absoluteFilePath());
|
||||
// require sensible file types
|
||||
if (!std::any_of(PREFIXES.begin(), PREFIXES.end(),
|
||||
[&relative](const QString& prefix) { return relative.startsWith(prefix + QDir::separator()); }))
|
||||
if (!std::any_of(PREFIXES.begin(), PREFIXES.end(), [&relative](const QString& prefix) { return relative.startsWith(prefix); }))
|
||||
continue;
|
||||
if (!std::any_of(FILE_EXTENSIONS.begin(), FILE_EXTENSIONS.end(), [&relative](const QString& extension) {
|
||||
return relative.endsWith('.' + extension) || relative.endsWith('.' + extension + ".disabled");
|
||||
})) {
|
||||
}))
|
||||
continue;
|
||||
}
|
||||
|
||||
QCryptographicHash sha512(QCryptographicHash::Algorithm::Sha512);
|
||||
|
||||
@ -303,9 +301,7 @@ QByteArray ModrinthPackExportTask::generateIndex()
|
||||
const ResolvedFile& value = iterator.value();
|
||||
|
||||
QJsonObject file;
|
||||
QString path = iterator.key();
|
||||
path.replace(QDir::separator(), "/");
|
||||
file["path"] = path;
|
||||
file["path"] = iterator.key();
|
||||
file["downloads"] = QJsonArray({ iterator.value().url });
|
||||
|
||||
QJsonObject hashes;
|
||||
|
@ -53,7 +53,10 @@ class ByteArraySink : public Sink {
|
||||
public:
|
||||
auto init(QNetworkRequest& request) -> Task::State override
|
||||
{
|
||||
if (m_output)
|
||||
m_output->clear();
|
||||
else
|
||||
qWarning() << "ByteArraySink did not initialize the buffer because it's not addressable";
|
||||
if (initAllValidators(request))
|
||||
return Task::State::Running;
|
||||
return Task::State::Failed;
|
||||
@ -61,7 +64,10 @@ class ByteArraySink : public Sink {
|
||||
|
||||
auto write(QByteArray& data) -> Task::State override
|
||||
{
|
||||
if (m_output)
|
||||
m_output->append(data);
|
||||
else
|
||||
qWarning() << "ByteArraySink did not write the buffer because it's not addressable";
|
||||
if (writeAllValidators(data))
|
||||
return Task::State::Running;
|
||||
return Task::State::Failed;
|
||||
@ -69,7 +75,10 @@ class ByteArraySink : public Sink {
|
||||
|
||||
auto abort() -> Task::State override
|
||||
{
|
||||
if (m_output)
|
||||
m_output->clear();
|
||||
else
|
||||
qWarning() << "ByteArraySink did not clear the buffer because it's not addressable";
|
||||
failAllValidators();
|
||||
return Task::State::Failed;
|
||||
}
|
||||
|
@ -45,12 +45,12 @@
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
INIFile::INIFile()
|
||||
{
|
||||
}
|
||||
INIFile::INIFile() {}
|
||||
|
||||
bool INIFile::saveFile(QString fileName)
|
||||
{
|
||||
if (!contains("ConfigVersion"))
|
||||
insert("ConfigVersion", "1.1");
|
||||
QSettings _settings_obj{ fileName, QSettings::Format::IniFormat };
|
||||
_settings_obj.setFallbacksEnabled(false);
|
||||
|
||||
@ -71,6 +71,67 @@ bool INIFile::saveFile(QString fileName)
|
||||
|
||||
return true;
|
||||
}
|
||||
QString unescape(QString orig)
|
||||
{
|
||||
QString out;
|
||||
QChar prev = QChar::Null;
|
||||
for (auto c : orig) {
|
||||
if (prev == '\\') {
|
||||
if (c == 'n')
|
||||
out += '\n';
|
||||
else if (c == 't')
|
||||
out += '\t';
|
||||
else if (c == '#')
|
||||
out += '#';
|
||||
else
|
||||
out += c;
|
||||
prev = QChar::Null;
|
||||
} else {
|
||||
if (c == '\\') {
|
||||
prev = c;
|
||||
continue;
|
||||
}
|
||||
out += c;
|
||||
prev = QChar::Null;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
bool parseOldFileFormat(QIODevice& device, QSettings::SettingsMap& map)
|
||||
{
|
||||
QTextStream in(device.readAll());
|
||||
#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
|
||||
in.setCodec("UTF-8");
|
||||
#endif
|
||||
|
||||
QStringList lines = in.readAll().split('\n');
|
||||
for (int i = 0; i < lines.count(); i++) {
|
||||
QString& lineRaw = lines[i];
|
||||
// Ignore comments.
|
||||
int commentIndex = 0;
|
||||
QString line = lineRaw;
|
||||
// Search for comments until no more escaped # are available
|
||||
while ((commentIndex = line.indexOf('#', commentIndex + 1)) != -1) {
|
||||
if (commentIndex > 0 && line.at(commentIndex - 1) == '\\') {
|
||||
continue;
|
||||
}
|
||||
line = line.left(lineRaw.indexOf('#')).trimmed();
|
||||
}
|
||||
|
||||
int eqPos = line.indexOf('=');
|
||||
if (eqPos == -1)
|
||||
continue;
|
||||
QString key = line.left(eqPos).trimmed();
|
||||
QString valueStr = line.right(line.length() - eqPos - 1).trimmed();
|
||||
|
||||
valueStr = unescape(valueStr);
|
||||
|
||||
QVariant value(valueStr);
|
||||
map.insert(key, value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool INIFile::loadFile(QString fileName)
|
||||
{
|
||||
@ -84,10 +145,19 @@ bool INIFile::loadFile(QString fileName)
|
||||
qCritical() << "A format error occurred (e.g. loading a malformed INI file).";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_settings_obj.value("ConfigVersion").isValid()) {
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return false;
|
||||
QSettings::SettingsMap map;
|
||||
parseOldFileFormat(file, map);
|
||||
file.close();
|
||||
for (auto&& key : map.keys())
|
||||
insert(key, map.value(key));
|
||||
insert("ConfigVersion", "1.1");
|
||||
} else
|
||||
for (auto&& key : _settings_obj.allKeys())
|
||||
insert(key, _settings_obj.value(key));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -103,4 +173,3 @@ void INIFile::set(QString key, QVariant val)
|
||||
{
|
||||
this->operator[](key) = val;
|
||||
}
|
||||
|
||||
|
@ -138,19 +138,18 @@ void ConcurrentTask::startNext()
|
||||
connect(next.get(), &Task::progress, this, [this, next](qint64 current, qint64 total) { subTaskProgress(next, current, total); });
|
||||
|
||||
m_doing.insert(next.get(), next);
|
||||
qsizetype num_starts = qMin(m_queue.size(), m_total_max_size - m_doing.size());
|
||||
auto task_progress = std::make_shared<TaskStepProgress>(next->getUid());
|
||||
m_task_progress.insert(next->getUid(), task_progress);
|
||||
|
||||
updateState();
|
||||
updateStepProgress(*task_progress.get(), Operation::ADDED);
|
||||
|
||||
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QMetaObject::invokeMethod(next.get(), &Task::start, Qt::QueuedConnection);
|
||||
|
||||
// Allow going up the number of concurrent tasks in case of tasks being added in the middle of a running task.
|
||||
int num_starts = qMin(m_queue.size(), m_total_max_size - m_doing.size());
|
||||
for (int i = 0; i < num_starts; i++)
|
||||
QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection);
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
|
||||
}
|
||||
|
||||
// set the menu for the folders help, and accounts tool buttons
|
||||
// set the menu for the folders help, accounts, and export tool buttons
|
||||
{
|
||||
auto foldersMenuButton = dynamic_cast<QToolButton*>(ui->mainToolBar->widgetForAction(ui->actionFoldersButton));
|
||||
ui->actionFoldersButton->setMenu(ui->foldersMenu);
|
||||
@ -201,6 +201,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
|
||||
auto accountMenuButton = dynamic_cast<QToolButton*>(ui->mainToolBar->widgetForAction(ui->actionAccountsButton));
|
||||
accountMenuButton->setPopupMode(QToolButton::InstantPopup);
|
||||
|
||||
auto exportInstanceMenu = new QMenu(this);
|
||||
exportInstanceMenu->addAction(ui->actionExportInstanceZip);
|
||||
exportInstanceMenu->addAction(ui->actionExportInstanceMrPack);
|
||||
ui->actionExportInstance->setMenu(exportInstanceMenu);
|
||||
}
|
||||
|
||||
// hide, disable and show stuff
|
||||
@ -397,8 +402,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
// removing this looks stupid
|
||||
view->setFocus();
|
||||
|
||||
ui->actionExportInstance->setMenu(ui->exportInstanceMenu);
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
@ -470,8 +473,24 @@ void MainWindow::lockToolbars(bool state)
|
||||
|
||||
void MainWindow::konamiTriggered()
|
||||
{
|
||||
QString gradient = " stop:0 rgba(125, 0, 0, 255), stop:0.166 rgba(125, 125, 0, 255), stop:0.333 rgba(0, 125, 0, 255), stop:0.5 rgba(0, 125, 125, 255), stop:0.666 rgba(0, 0, 125, 255), stop:0.833 rgba(125, 0, 125, 255), stop:1 rgba(125, 0, 0, 255));";
|
||||
QString stylesheet = "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0," + gradient;
|
||||
if (ui->mainToolBar->styleSheet() == stylesheet) {
|
||||
ui->mainToolBar->setStyleSheet("");
|
||||
ui->instanceToolBar->setStyleSheet("");
|
||||
ui->centralWidget->setStyleSheet("");
|
||||
ui->newsToolBar->setStyleSheet("");
|
||||
ui->statusBar->setStyleSheet("");
|
||||
qDebug() << "Super Secret Mode DEACTIVATED!";
|
||||
} else {
|
||||
ui->mainToolBar->setStyleSheet(stylesheet);
|
||||
ui->instanceToolBar->setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1," + gradient);
|
||||
ui->centralWidget->setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1," + gradient);
|
||||
ui->newsToolBar->setStyleSheet(stylesheet);
|
||||
ui->statusBar->setStyleSheet(stylesheet);
|
||||
qDebug() << "Super Secret Mode ACTIVATED!";
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::showInstanceContextMenu(const QPoint &pos)
|
||||
{
|
||||
|
@ -150,10 +150,6 @@
|
||||
<addaction name="actionChangeInstGroup"/>
|
||||
<addaction name="actionViewSelectedInstFolder"/>
|
||||
<addaction name="actionExportInstance"/>
|
||||
<widget class="QMenu" name="exportInstanceMenu">
|
||||
<addaction name="actionExportInstanceZip"/>
|
||||
<addaction name="actionExportInstanceMrPack"/>
|
||||
</widget>
|
||||
<addaction name="actionCopyInstance"/>
|
||||
<addaction name="actionDeleteInstance"/>
|
||||
<addaction name="actionCreateInstanceShortcut"/>
|
||||
@ -467,11 +463,17 @@
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExportInstanceZip">
|
||||
<property name="icon">
|
||||
<iconset theme="launcher"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Prism Launcher (zip)</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExportInstanceMrPack">
|
||||
<property name="icon">
|
||||
<iconset theme="modrinth"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Modrinth (mrpack)</string>
|
||||
</property>
|
||||
|
@ -60,6 +60,10 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
|
||||
m_settings = inst->settings();
|
||||
ui->setupUi(this);
|
||||
|
||||
// As the signal will (probably) not be triggered once we click edit, let's update it manually instead.
|
||||
updateRunningStatus(m_instance->isRunning());
|
||||
|
||||
connect(m_instance, &BaseInstance::runningStatusChanged, this, &InstanceSettingsPage::updateRunningStatus);
|
||||
connect(ui->openGlobalJavaSettingsButton, &QCommandLinkButton::clicked, this, &InstanceSettingsPage::globalSettingsButtonClicked);
|
||||
connect(APPLICATION, &Application::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings);
|
||||
connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
|
||||
@ -70,11 +74,6 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
|
||||
updateThresholds();
|
||||
}
|
||||
|
||||
bool InstanceSettingsPage::shouldDisplay() const
|
||||
{
|
||||
return !m_instance->isRunning();
|
||||
}
|
||||
|
||||
InstanceSettingsPage::~InstanceSettingsPage()
|
||||
{
|
||||
delete ui;
|
||||
@ -524,3 +523,8 @@ void InstanceSettingsPage::updateThresholds()
|
||||
ui->labelMaxMemIcon->setPixmap(pix);
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceSettingsPage::updateRunningStatus(bool running)
|
||||
{
|
||||
setEnabled(!running);
|
||||
}
|
||||
|
@ -75,12 +75,12 @@ public:
|
||||
{
|
||||
return "Instance-settings";
|
||||
}
|
||||
virtual bool shouldDisplay() const override;
|
||||
void retranslate() override;
|
||||
|
||||
void updateThresholds();
|
||||
|
||||
private slots:
|
||||
void updateRunningStatus(bool running);
|
||||
void on_javaDetectBtn_clicked();
|
||||
void on_javaTestBtn_clicked();
|
||||
void on_javaBrowseBtn_clicked();
|
||||
|
@ -240,10 +240,13 @@ void ResourcePage::updateSelectionButton()
|
||||
}
|
||||
|
||||
m_ui->resourceSelectionButton->setEnabled(true);
|
||||
if (!getCurrentPack()->isVersionSelected(m_selected_version_index)) {
|
||||
if (getCurrentPack()) {
|
||||
if (!getCurrentPack()->isVersionSelected(m_selected_version_index))
|
||||
m_ui->resourceSelectionButton->setText(tr("Select %1 for download").arg(resourceString()));
|
||||
} else {
|
||||
else
|
||||
m_ui->resourceSelectionButton->setText(tr("Deselect %1 for download").arg(resourceString()));
|
||||
} else {
|
||||
qWarning() << "Tried to update the selected button but there is not a pack selected";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,24 +1,16 @@
|
||||
#include <QTest>
|
||||
|
||||
#include <settings/INIFile.h>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <settings/INIFile.h>
|
||||
|
||||
#include <QVariantUtils.h>
|
||||
|
||||
class IniFileTest : public QObject
|
||||
{
|
||||
class IniFileTest : public QObject {
|
||||
Q_OBJECT
|
||||
private
|
||||
slots:
|
||||
void initTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
void cleanupTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
private slots:
|
||||
void initTestCase() {}
|
||||
void cleanupTestCase() {}
|
||||
|
||||
void test_Escape_data()
|
||||
{
|
||||
@ -79,6 +71,34 @@ slots:
|
||||
QCOMPARE(out_list_strings, list_strings);
|
||||
QCOMPARE(out_list_numbers, list_numbers);
|
||||
}
|
||||
|
||||
void test_SaveAleardyExistingFile()
|
||||
{
|
||||
QString fileName = "test_SaveAleardyExistingFile.ini";
|
||||
QString fileContent = R"(InstanceType=OneSix
|
||||
iconKey=vanillia_icon
|
||||
name=Minecraft Vanillia
|
||||
OverrideCommands=true
|
||||
PreLaunchCommand="$INST_JAVA" -jar packwiz-installer-bootstrap.jar link
|
||||
)";
|
||||
QFile file(fileName);
|
||||
|
||||
if (file.open(QFile::WriteOnly | QFile::Text)) {
|
||||
QTextStream stream(&file);
|
||||
stream << fileContent;
|
||||
file.close();
|
||||
}
|
||||
|
||||
// load
|
||||
INIFile f1;
|
||||
f1.loadFile(fileName);
|
||||
QCOMPARE(f1.get("PreLaunchCommand", "NOT SET").toString(), "\"$INST_JAVA\" -jar packwiz-installer-bootstrap.jar link");
|
||||
f1.saveFile(fileName);
|
||||
INIFile f2;
|
||||
f2.loadFile(fileName);
|
||||
QCOMPARE(f2.get("PreLaunchCommand", "NOT SET").toString(), "\"$INST_JAVA\" -jar packwiz-installer-bootstrap.jar link");
|
||||
QCOMPARE(f2.get("ConfigVersion", "NOT SET").toString(), "1.1");
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(IniFileTest)
|
||||
|
Loading…
Reference in New Issue
Block a user