From 5d14dede508bd67d2e1777ebd77aaa386314a0aa Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 07:54:20 +0100 Subject: [PATCH 01/20] NOISSUE WIP implementation of the ability to create instance shortcuts Currently Linux-only and lacking some features --- launcher/CMakeLists.txt | 4 +- launcher/ui/MainWindow.cpp | 28 +- launcher/ui/MainWindow.h | 4 + launcher/ui/dialogs/CreateShortcutDialog.cpp | 117 ++++++++ launcher/ui/dialogs/CreateShortcutDialog.h | 40 +++ launcher/ui/dialogs/CreateShortcutDialog.ui | 275 +++++++++++++++++++ 6 files changed, 464 insertions(+), 4 deletions(-) create mode 100644 launcher/ui/dialogs/CreateShortcutDialog.cpp create mode 100644 launcher/ui/dialogs/CreateShortcutDialog.h create mode 100644 launcher/ui/dialogs/CreateShortcutDialog.ui diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 2f72e0d3..bc0cce66 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -778,7 +778,8 @@ SET(LAUNCHER_SOURCES ui/dialogs/VersionSelectDialog.h ui/dialogs/SkinUploadDialog.cpp ui/dialogs/SkinUploadDialog.h - + ui/dialogs/CreateShortcutDialog.cpp + ui/dialogs/CreateShortcutDialog.h # GUI - widgets ui/widgets/Common.cpp @@ -876,6 +877,7 @@ qt5_wrap_ui(LAUNCHER_UI ui/dialogs/AboutDialog.ui ui/dialogs/LoginDialog.ui ui/dialogs/EditAccountDialog.ui + ui/dialogs/CreateShortcutDialog.ui ) qt5_add_resources(LAUNCHER_RESOURCES diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index c0ba8839..bbdfb043 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -83,14 +83,15 @@ #include "ui/dialogs/UpdateDialog.h" #include "ui/dialogs/EditAccountDialog.h" #include "ui/dialogs/NotificationDialog.h" +#include "ui/dialogs/CreateShortcutDialog.h" + #include "ui/dialogs/ExportInstanceDialog.h" - #include "UpdateController.h" + #include "KonamiCode.h" - #include "InstanceImportTask.h" -#include "InstanceCopyTask.h" +#include "InstanceCopyTask.h" #include "MMCTime.h" namespace { @@ -222,6 +223,9 @@ public: TranslatedAction actionLaunchInstanceOffline; TranslatedAction actionScreenshots; TranslatedAction actionExportInstance; +#if defined(Q_OS_LINUX) // currently only implemented for linux; TODO: other OS implementations + TranslatedAction actionCreateShortcut; +#endif QVector all_actions; LabeledToolButton *renameButton = nullptr; @@ -594,6 +598,15 @@ public: instanceToolBar->addSeparator(); +#if defined(Q_OS_LINUX) + actionCreateShortcut = TranslatedAction(MainWindow); + actionCreateShortcut->setObjectName(QStringLiteral("actionCreateShortcut")); + actionCreateShortcut.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Create Shortcut")); + actionCreateShortcut.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Create a shortcut that launches the selected instance")); + all_actions.append(&actionCreateShortcut); + instanceToolBar->addAction(actionCreateShortcut); +#endif + actionExportInstance = TranslatedAction(MainWindow); actionExportInstance->setObjectName(QStringLiteral("actionExportInstance")); actionExportInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Export Instance")); @@ -1844,6 +1857,15 @@ void MainWindow::on_actionLaunchInstance_triggered() } } +#if defined(Q_OS_LINUX) +void MainWindow::on_actionCreateShortcut_triggered() { + if (m_selectedInstance) + { + CreateShortcutDialog(this, m_selectedInstance).exec(); + } +} +#endif + void MainWindow::activateInstance(InstancePtr instance) { APPLICATION->launch(instance); diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h index e462c524..24d9fee0 100644 --- a/launcher/ui/MainWindow.h +++ b/launcher/ui/MainWindow.h @@ -141,6 +141,10 @@ private slots: void on_actionScreenshots_triggered(); +#if defined(Q_OS_LINUX) + void on_actionCreateShortcut_triggered(); +#endif + void taskEnd(); /** diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp new file mode 100644 index 00000000..71b3c96b --- /dev/null +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -0,0 +1,117 @@ +/* + * Copyright 2022 arthomnix + * + * This source is subject to the Microsoft Public License (MS-PL). + * Please see the COPYING.md file for more information. + */ + +#include +#include +#include +#include +#include "CreateShortcutDialog.h" +#include "ui_CreateShortcutDialog.h" +#include "Application.h" +#include "minecraft/auth/AccountList.h" +#include "icons/IconList.h" + +CreateShortcutDialog::CreateShortcutDialog(QWidget *parent, InstancePtr instance) + :QDialog(parent), ui(new Ui::CreateShortcutDialog), m_instance(instance) +{ + ui->setupUi(this); + + QStringList accountNameList; + auto accounts = APPLICATION->accounts(); + + for (int i = 0; i < accounts->count(); i++) + { + accountNameList.append(accounts->at(i)->profileName()); + } + + ui->profileComboBox->addItems(accountNameList); + + if (accounts->defaultAccount()) + { + ui->profileComboBox->setCurrentText(accounts->defaultAccount()->profileName()); + } + + updateDialogState(); +} + +CreateShortcutDialog::~CreateShortcutDialog() +{ + delete ui; +} + +void CreateShortcutDialog::on_shortcutPathBrowse_clicked() +{ + QString linkExtension; +#ifdef Q_OS_LINUX + linkExtension = "desktop"; +#endif +#ifdef Q_OS_WIN + linkExtension = "lnk"; +#endif + QFileDialog fileDialog(this, tr("Select shortcut path"), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); + fileDialog.setDefaultSuffix(linkExtension); + fileDialog.setAcceptMode(QFileDialog::AcceptOpen); + fileDialog.setFileMode(QFileDialog::AnyFile); + if (fileDialog.exec()) + { + ui->shortcutPath->setText(fileDialog.selectedFiles().at(0)); + } + updateDialogState(); +} + +void CreateShortcutDialog::accept() +{ + createShortcut(); + QDialog::accept(); +} + + +void CreateShortcutDialog::updateDialogState() +{ + + ui->buttonBox->button(QDialogButtonBox::StandardButton::Ok)->setEnabled( + !ui->shortcutPath->text().isEmpty() + && (!ui->joinServerCheckBox->isChecked() || !ui->joinServer->text().isEmpty()) + && (!ui->offlineUsernameCheckBox->isChecked() || !ui->offlineUsername->text().isEmpty()) + && (!ui->useProfileCheckBox->isChecked() || !ui->profileComboBox->currentText().isEmpty()) + ); + ui->joinServer->setEnabled(ui->joinServerCheckBox->isChecked()); + ui->profileComboBox->setEnabled(ui->useProfileCheckBox->isChecked()); + ui->offlineUsernameCheckBox->setEnabled(ui->launchOfflineCheckBox->isChecked()); + ui->offlineUsername->setEnabled(ui->launchOfflineCheckBox->isChecked() && ui->offlineUsernameCheckBox->isChecked()); +} + +QString CreateShortcutDialog::getLaunchCommand() +{ + return QCoreApplication::applicationFilePath() + + " -l " + m_instance->id() + + (ui->joinServerCheckBox->isChecked() ? " -s " + ui->joinServer->text() : "") + + (ui->useProfileCheckBox->isChecked() ? " -a " + ui->profileComboBox->currentText() : "") + + (ui->launchOfflineCheckBox->isChecked() ? " -o" : "") + + (ui->offlineUsernameCheckBox->isChecked() ? " -n " + ui->offlineUsername->text() : ""); +} + +void CreateShortcutDialog::createShortcut() +{ + // Linux implementation using .desktop file +#ifdef Q_OS_LINUX + QFile desktopFile(ui->shortcutPath->text()); + if (desktopFile.open(QIODevice::WriteOnly)) + { + QTextStream stream(&desktopFile); + qDebug() << m_instance->iconKey(); + stream << "[Desktop Entry]" << endl + << "Type=Application" << endl + << "Name=" << m_instance->name() << " - " << BuildConfig.LAUNCHER_DISPLAYNAME << endl + << "Exec=" << getLaunchCommand() << endl; + desktopFile.setPermissions(QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther + | QFile::WriteOwner | QFile::ExeOwner | QFile::ExeGroup); + desktopFile.close(); + } +#endif + // TODO: implementations for other operating systems +} \ No newline at end of file diff --git a/launcher/ui/dialogs/CreateShortcutDialog.h b/launcher/ui/dialogs/CreateShortcutDialog.h new file mode 100644 index 00000000..4725fc5e --- /dev/null +++ b/launcher/ui/dialogs/CreateShortcutDialog.h @@ -0,0 +1,40 @@ +/* + * Copyright 2022 arthomnix + * + * This source is subject to the Microsoft Public License (MS-PL). + * Please see the COPYING.md file for more information. + */ + +#pragma once + +#include +#include "minecraft/auth/MinecraftAccount.h" +#include "BaseInstance.h" + +namespace Ui +{ + class CreateShortcutDialog; +} + +class CreateShortcutDialog : public QDialog +{ + Q_OBJECT + +public: + explicit CreateShortcutDialog(QWidget *parent = nullptr, InstancePtr instance = nullptr); + ~CreateShortcutDialog() override; + +private +slots: + void on_shortcutPathBrowse_clicked(); + void updateDialogState(); + void accept() override; + +private: + Ui::CreateShortcutDialog *ui; + InstancePtr m_instance; + + QString getLaunchCommand(); + + void createShortcut(); +}; \ No newline at end of file diff --git a/launcher/ui/dialogs/CreateShortcutDialog.ui b/launcher/ui/dialogs/CreateShortcutDialog.ui new file mode 100644 index 00000000..b3e17d12 --- /dev/null +++ b/launcher/ui/dialogs/CreateShortcutDialog.ui @@ -0,0 +1,275 @@ + + + + CreateShortcutDialog + + + + 0 + 0 + 796 + 230 + + + + + 796 + 230 + + + + Create Shortcut + + + + + + QLayout::SetDefaultConstraint + + + + + Join server on launch: + + + + + + + Shortcut path: + + + + + + + + + + + + + Launch in offline mode + + + + + + + + + + Browse + + + + + + + Use specific profile: + + + + + + + + + + Set offline mode username: + + + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + CreateShortcutDialog + accept() + + + 397 + 207 + + + 397 + 114 + + + + + buttonBox + rejected() + CreateShortcutDialog + reject() + + + 397 + 207 + + + 397 + 114 + + + + + joinServer + textChanged(QString) + CreateShortcutDialog + updateDialogState() + + + 471 + 61 + + + 397 + 114 + + + + + joinServerCheckBox + stateChanged(int) + CreateShortcutDialog + updateDialogState() + + + 122 + 61 + + + 397 + 114 + + + + + launchOfflineCheckBox + stateChanged(int) + CreateShortcutDialog + updateDialogState() + + + 122 + 130 + + + 397 + 114 + + + + + offlineUsername + textChanged(QString) + CreateShortcutDialog + updateDialogState() + + + 471 + 162 + + + 397 + 114 + + + + + offlineUsernameCheckBox + stateChanged(int) + CreateShortcutDialog + updateDialogState() + + + 122 + 162 + + + 397 + 114 + + + + + profileComboBox + currentTextChanged(QString) + CreateShortcutDialog + updateDialogState() + + + 471 + 98 + + + 397 + 114 + + + + + shortcutPath + textChanged(QString) + CreateShortcutDialog + updateDialogState() + + + 471 + 23 + + + 397 + 114 + + + + + useProfileCheckBox + stateChanged(int) + CreateShortcutDialog + updateDialogState() + + + 122 + 98 + + + 397 + 114 + + + + + From b326fef61b628d89b0c508e9435d3dac8d1c9a7d Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 07:56:25 +0100 Subject: [PATCH 02/20] NOISSUE fix arrangement of includes --- launcher/ui/MainWindow.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index bbdfb043..c7604759 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -84,13 +84,12 @@ #include "ui/dialogs/EditAccountDialog.h" #include "ui/dialogs/NotificationDialog.h" #include "ui/dialogs/CreateShortcutDialog.h" - #include "ui/dialogs/ExportInstanceDialog.h" + #include "UpdateController.h" - #include "KonamiCode.h" -#include "InstanceImportTask.h" +#include "InstanceImportTask.h" #include "InstanceCopyTask.h" #include "MMCTime.h" From 6c31125f02012ac2bc8989fb4f6b7884ae7858fb Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 07:57:15 +0100 Subject: [PATCH 03/20] NOISSUE fix arrangement of includes again --- launcher/ui/MainWindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index c7604759..343d35e1 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -91,6 +91,7 @@ #include "InstanceImportTask.h" #include "InstanceCopyTask.h" + #include "MMCTime.h" namespace { From a0c44f706203758f75b299e79e4ec677b6dc302c Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 08:27:13 +0100 Subject: [PATCH 04/20] NOISSUE shortcut creation: add icons on linux --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 71b3c96b..7e816b0f 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -99,6 +99,13 @@ void CreateShortcutDialog::createShortcut() { // Linux implementation using .desktop file #ifdef Q_OS_LINUX + // save the launcher icon to a file so we can use it in the shortcut + if (!QFileInfo::exists(QCoreApplication::applicationDirPath() + "/shortcut-icon.png")) + { + QPixmap iconPixmap = QIcon(":/logo.svg").pixmap(64, 64); + iconPixmap.save(QCoreApplication::applicationDirPath() + "/shortcut-icon.png"); + } + QFile desktopFile(ui->shortcutPath->text()); if (desktopFile.open(QIODevice::WriteOnly)) { @@ -107,7 +114,8 @@ void CreateShortcutDialog::createShortcut() stream << "[Desktop Entry]" << endl << "Type=Application" << endl << "Name=" << m_instance->name() << " - " << BuildConfig.LAUNCHER_DISPLAYNAME << endl - << "Exec=" << getLaunchCommand() << endl; + << "Exec=" << getLaunchCommand() << endl + << "Icon=" << QCoreApplication::applicationDirPath() << "/shortcut-icon.png" << endl; desktopFile.setPermissions(QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther | QFile::WriteOwner | QFile::ExeOwner | QFile::ExeGroup); desktopFile.close(); From 645bc3f4458107c61e10fd64266d3c23002b3a58 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 08:33:46 +0100 Subject: [PATCH 05/20] NOISSUE shortcut creation: set default shortcut filename --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 7e816b0f..011b67fd 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -56,6 +56,7 @@ void CreateShortcutDialog::on_shortcutPathBrowse_clicked() fileDialog.setDefaultSuffix(linkExtension); fileDialog.setAcceptMode(QFileDialog::AcceptOpen); fileDialog.setFileMode(QFileDialog::AnyFile); + fileDialog.selectFile(m_instance->id() + "." + linkExtension); if (fileDialog.exec()) { ui->shortcutPath->setText(fileDialog.selectedFiles().at(0)); From 6a3ff58c8c641a232697b93b387be657e2fa2d07 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 09:52:56 +0100 Subject: [PATCH 06/20] NOISSUE shortcut creation: add option to create launch scripts This allows shortcuts to be created on Macs (which don't have a concept of desktop shortcuts) as well as Linux systems that don't support the desktop file specification. Also included a windows batch file implementation. --- launcher/ui/MainWindow.cpp | 6 -- launcher/ui/MainWindow.h | 2 - launcher/ui/dialogs/CreateShortcutDialog.cpp | 81 ++++++++++++------ launcher/ui/dialogs/CreateShortcutDialog.ui | 86 +++++++++++--------- 4 files changed, 104 insertions(+), 71 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 343d35e1..139ca780 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -223,9 +223,7 @@ public: TranslatedAction actionLaunchInstanceOffline; TranslatedAction actionScreenshots; TranslatedAction actionExportInstance; -#if defined(Q_OS_LINUX) // currently only implemented for linux; TODO: other OS implementations TranslatedAction actionCreateShortcut; -#endif QVector all_actions; LabeledToolButton *renameButton = nullptr; @@ -598,14 +596,12 @@ public: instanceToolBar->addSeparator(); -#if defined(Q_OS_LINUX) actionCreateShortcut = TranslatedAction(MainWindow); actionCreateShortcut->setObjectName(QStringLiteral("actionCreateShortcut")); actionCreateShortcut.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Create Shortcut")); actionCreateShortcut.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Create a shortcut that launches the selected instance")); all_actions.append(&actionCreateShortcut); instanceToolBar->addAction(actionCreateShortcut); -#endif actionExportInstance = TranslatedAction(MainWindow); actionExportInstance->setObjectName(QStringLiteral("actionExportInstance")); @@ -1857,14 +1853,12 @@ void MainWindow::on_actionLaunchInstance_triggered() } } -#if defined(Q_OS_LINUX) void MainWindow::on_actionCreateShortcut_triggered() { if (m_selectedInstance) { CreateShortcutDialog(this, m_selectedInstance).exec(); } } -#endif void MainWindow::activateInstance(InstancePtr instance) { diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h index 24d9fee0..685adba9 100644 --- a/launcher/ui/MainWindow.h +++ b/launcher/ui/MainWindow.h @@ -141,9 +141,7 @@ private slots: void on_actionScreenshots_triggered(); -#if defined(Q_OS_LINUX) void on_actionCreateShortcut_triggered(); -#endif void taskEnd(); diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 011b67fd..2c260514 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -35,6 +35,11 @@ CreateShortcutDialog::CreateShortcutDialog(QWidget *parent, InstancePtr instance ui->profileComboBox->setCurrentText(accounts->defaultAccount()->profileName()); } +#if defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_LINUX)) + ui->createScriptCheckBox->setEnabled(false); + ui->createScriptCheckBox->setChecked(true); +#endif + updateDialogState(); } @@ -46,11 +51,11 @@ CreateShortcutDialog::~CreateShortcutDialog() void CreateShortcutDialog::on_shortcutPathBrowse_clicked() { QString linkExtension; -#ifdef Q_OS_LINUX - linkExtension = "desktop"; +#ifdef Q_OS_UNIX + linkExtension = ui->createScriptCheckBox->isChecked() ? "sh" : "desktop"; #endif #ifdef Q_OS_WIN - linkExtension = "lnk"; + linkExtension = ui->createScriptCheckBox->isChecked() ? "bat" : "lnk"; #endif QFileDialog fileDialog(this, tr("Select shortcut path"), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); fileDialog.setDefaultSuffix(linkExtension); @@ -98,29 +103,57 @@ QString CreateShortcutDialog::getLaunchCommand() void CreateShortcutDialog::createShortcut() { - // Linux implementation using .desktop file -#ifdef Q_OS_LINUX - // save the launcher icon to a file so we can use it in the shortcut - if (!QFileInfo::exists(QCoreApplication::applicationDirPath() + "/shortcut-icon.png")) +#ifdef Q_OS_WIN + if (ui->createScriptCheckBox->isChecked()) // on windows, creating .lnk shortcuts requires specific win32 api stuff + // rather than just writing a text file { - QPixmap iconPixmap = QIcon(":/logo.svg").pixmap(64, 64); - iconPixmap.save(QCoreApplication::applicationDirPath() + "/shortcut-icon.png"); - } +#endif + QString shortcutText; +#ifdef Q_OS_UNIX + // Unix shell script + if (ui->createScriptCheckBox->isChecked()) + { + shortcutText = "#!/bin/sh\n" + getLaunchCommand() + " &\n"; + } else + // freedesktop.org desktop entry + { + // save the launcher icon to a file so we can use it in the shortcut + if (!QFileInfo::exists(QCoreApplication::applicationDirPath() + "/shortcut-icon.png")) + { + QPixmap iconPixmap = QIcon(":/logo.svg").pixmap(64, 64); + iconPixmap.save(QCoreApplication::applicationDirPath() + "/shortcut-icon.png"); + } - QFile desktopFile(ui->shortcutPath->text()); - if (desktopFile.open(QIODevice::WriteOnly)) - { - QTextStream stream(&desktopFile); - qDebug() << m_instance->iconKey(); - stream << "[Desktop Entry]" << endl - << "Type=Application" << endl - << "Name=" << m_instance->name() << " - " << BuildConfig.LAUNCHER_DISPLAYNAME << endl - << "Exec=" << getLaunchCommand() << endl - << "Icon=" << QCoreApplication::applicationDirPath() << "/shortcut-icon.png" << endl; - desktopFile.setPermissions(QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther - | QFile::WriteOwner | QFile::ExeOwner | QFile::ExeGroup); - desktopFile.close(); + shortcutText = "[Desktop Entry]\n" + "Type=Application\n" + "Name=" + m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME + "\n" + + "Exec=" + getLaunchCommand() + "\n" + + "Icon=" + QCoreApplication::applicationDirPath() + "/shortcut-icon.png\n"; + + } +#endif +#ifdef Q_OS_WIN + // Windows batch script implementation + if (ui->createScriptCheckBox->isChecked()) + { + shortcutText = "@ECHO OFF\r\n" + "START /B " + getLaunchCommand() + "\r\n"; + } + else + { + // TODO: windows .lnk implementation + } +#endif + QFile shortcutFile(ui->shortcutPath->text()); + if (shortcutFile.open(QIODevice::WriteOnly)) + { + QTextStream stream(&shortcutFile); + stream << shortcutText; + shortcutFile.setPermissions(QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther + | QFile::WriteOwner | QFile::ExeOwner | QFile::ExeGroup); + shortcutFile.close(); + } +#ifdef Q_OS_WIN } #endif - // TODO: implementations for other operating systems } \ No newline at end of file diff --git a/launcher/ui/dialogs/CreateShortcutDialog.ui b/launcher/ui/dialogs/CreateShortcutDialog.ui index b3e17d12..c8d1cc87 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.ui +++ b/launcher/ui/dialogs/CreateShortcutDialog.ui @@ -1,10 +1,4 @@ - CreateShortcutDialog @@ -13,7 +7,7 @@ 0 0 796 - 230 + 232 @@ -31,10 +25,10 @@ QLayout::SetDefaultConstraint - - + + - Join server on launch: + Launch in offline mode @@ -45,22 +39,6 @@ - - - - - - - - - - Launch in offline mode - - - - - - @@ -68,6 +46,29 @@ + + + + + + + + + + + + + Set offline mode username: + + + + + + + Join server on launch: + + + @@ -75,15 +76,8 @@ - - - - - - - Set offline mode username: - - + + @@ -101,11 +95,25 @@ - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + 0 - + + + + Create script instead of shortcut + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + From 21413b964aa1c0b43b4238af02836ed01c374982 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 09:56:16 +0100 Subject: [PATCH 07/20] NOISSUE replace copyright header that got removed by qt designer --- launcher/ui/dialogs/CreateShortcutDialog.ui | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.ui b/launcher/ui/dialogs/CreateShortcutDialog.ui index c8d1cc87..568bf0a6 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.ui +++ b/launcher/ui/dialogs/CreateShortcutDialog.ui @@ -1,4 +1,9 @@ + CreateShortcutDialog From 018e6229ca47c81a59b0e74c7e31182d171d0e87 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 13:07:21 +0100 Subject: [PATCH 08/20] NOISSUE shortcut creation: add windows .lnk support --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 93 +++++++++++++++----- launcher/ui/dialogs/CreateShortcutDialog.h | 9 ++ 2 files changed, 79 insertions(+), 23 deletions(-) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 2c260514..c1b0db08 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -5,8 +5,6 @@ * Please see the COPYING.md file for more information. */ -#include -#include #include #include #include "CreateShortcutDialog.h" @@ -15,6 +13,11 @@ #include "minecraft/auth/AccountList.h" #include "icons/IconList.h" +#ifdef Q_OS_WIN +#include +#include +#endif + CreateShortcutDialog::CreateShortcutDialog(QWidget *parent, InstancePtr instance) :QDialog(parent), ui(new Ui::CreateShortcutDialog), m_instance(instance) { @@ -35,7 +38,7 @@ CreateShortcutDialog::CreateShortcutDialog(QWidget *parent, InstancePtr instance ui->profileComboBox->setCurrentText(accounts->defaultAccount()->profileName()); } -#if defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_LINUX)) +#if defined(Q_OS_UNIX) && !defined(Q_OS_LINUX) ui->createScriptCheckBox->setEnabled(false); ui->createScriptCheckBox->setChecked(true); #endif @@ -61,7 +64,7 @@ void CreateShortcutDialog::on_shortcutPathBrowse_clicked() fileDialog.setDefaultSuffix(linkExtension); fileDialog.setAcceptMode(QFileDialog::AcceptOpen); fileDialog.setFileMode(QFileDialog::AnyFile); - fileDialog.selectFile(m_instance->id() + "." + linkExtension); + fileDialog.selectFile(m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME + "." + linkExtension); if (fileDialog.exec()) { ui->shortcutPath->setText(fileDialog.selectedFiles().at(0)); @@ -93,12 +96,17 @@ void CreateShortcutDialog::updateDialogState() QString CreateShortcutDialog::getLaunchCommand() { - return QCoreApplication::applicationFilePath() - + " -l " + m_instance->id() - + (ui->joinServerCheckBox->isChecked() ? " -s " + ui->joinServer->text() : "") - + (ui->useProfileCheckBox->isChecked() ? " -a " + ui->profileComboBox->currentText() : "") - + (ui->launchOfflineCheckBox->isChecked() ? " -o" : "") - + (ui->offlineUsernameCheckBox->isChecked() ? " -n " + ui->offlineUsername->text() : ""); + return QDir::toNativeSeparators(QCoreApplication::applicationFilePath()) + + getLaunchArgs(); +} + +QString CreateShortcutDialog::getLaunchArgs() +{ + return " -l " + m_instance->id() + + (ui->joinServerCheckBox->isChecked() ? " -s " + ui->joinServer->text() : "") + + (ui->useProfileCheckBox->isChecked() ? " -a " + ui->profileComboBox->currentText() : "") + + (ui->launchOfflineCheckBox->isChecked() ? " -o" : "") + + (ui->offlineUsernameCheckBox->isChecked() ? " -n " + ui->offlineUsername->text() : ""); } void CreateShortcutDialog::createShortcut() @@ -118,31 +126,24 @@ void CreateShortcutDialog::createShortcut() // freedesktop.org desktop entry { // save the launcher icon to a file so we can use it in the shortcut - if (!QFileInfo::exists(QCoreApplication::applicationDirPath() + "/shortcut-icon.png")) + if (!QFileInfo::exists(QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.png")) { QPixmap iconPixmap = QIcon(":/logo.svg").pixmap(64, 64); - iconPixmap.save(QCoreApplication::applicationDirPath() + "/shortcut-icon.png"); + iconPixmap.save(QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.png"); } shortcutText = "[Desktop Entry]\n" "Type=Application\n" "Name=" + m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME + "\n" + "Exec=" + getLaunchCommand() + "\n" - + "Icon=" + QCoreApplication::applicationDirPath() + "/shortcut-icon.png\n"; + + "Icon=" + QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.png\n"; } #endif #ifdef Q_OS_WIN // Windows batch script implementation - if (ui->createScriptCheckBox->isChecked()) - { - shortcutText = "@ECHO OFF\r\n" - "START /B " + getLaunchCommand() + "\r\n"; - } - else - { - // TODO: windows .lnk implementation - } + shortcutText = "@ECHO OFF\r\n" + "START /B " + getLaunchCommand() + "\r\n"; #endif QFile shortcutFile(ui->shortcutPath->text()); if (shortcutFile.open(QIODevice::WriteOnly)) @@ -154,6 +155,52 @@ void CreateShortcutDialog::createShortcut() shortcutFile.close(); } #ifdef Q_OS_WIN + } else { + if (!QFileInfo::exists(QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.ico")) + { + QPixmap iconPixmap = QIcon(":/logo.svg").pixmap(64, 64); + iconPixmap.save(QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.ico"); + } + + createWindowsLink(QDir::toNativeSeparators(QCoreApplication::applicationFilePath()).toStdString().c_str(), + getLaunchArgs().toStdString().c_str(), + ui->shortcutPath->text().toStdString().c_str(), + (m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME).toStdString().c_str(), + QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.ico").toStdString().c_str() + ); } #endif -} \ No newline at end of file +} + +#ifdef Q_OS_WIN +void CreateShortcutDialog::createWindowsLink(LPCSTR target, LPCSTR args, LPCSTR filename, LPCSTR desc, LPCSTR iconPath) +{ + HRESULT result; + IShellLink *link; + + CoInitialize(nullptr); + result = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &link); + if (SUCCEEDED(result)) + { + IPersistFile *file; + + link->SetPath(target); + link->SetArguments(args); + link->SetDescription(desc); + link->SetIconLocation(iconPath, 0); + + result = link->QueryInterface(IID_IPersistFile, (LPVOID *) &file); + + if (SUCCEEDED(result)) + { + WCHAR path[MAX_PATH]; + MultiByteToWideChar(CP_ACP, 0, filename, -1, path, MAX_PATH); + + file->Save(path, TRUE); + file->Release(); + } + link->Release(); + } + CoUninitialize(); +} +#endif \ No newline at end of file diff --git a/launcher/ui/dialogs/CreateShortcutDialog.h b/launcher/ui/dialogs/CreateShortcutDialog.h index 4725fc5e..d28a6b0c 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.h +++ b/launcher/ui/dialogs/CreateShortcutDialog.h @@ -11,6 +11,10 @@ #include "minecraft/auth/MinecraftAccount.h" #include "BaseInstance.h" +#ifdef Q_OS_WIN +#include +#endif + namespace Ui { class CreateShortcutDialog; @@ -35,6 +39,11 @@ private: InstancePtr m_instance; QString getLaunchCommand(); + QString getLaunchArgs(); void createShortcut(); + +#ifdef Q_OS_WIN + void createWindowsLink(LPCSTR target, LPCSTR args, LPCSTR filename, LPCSTR desc, LPCSTR iconPath); +#endif }; \ No newline at end of file From bf5be5568ec40e494eb49aa8c2da2e93fa1547e5 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 13:17:25 +0100 Subject: [PATCH 09/20] NOISSUE curly brace formatting --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index c1b0db08..aa30661b 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -155,7 +155,9 @@ void CreateShortcutDialog::createShortcut() shortcutFile.close(); } #ifdef Q_OS_WIN - } else { + } + else + { if (!QFileInfo::exists(QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.ico")) { QPixmap iconPixmap = QIcon(":/logo.svg").pixmap(64, 64); From 7217e3991ae9785fcbf3f6472da9663e6b148dd1 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 13:45:58 +0100 Subject: [PATCH 10/20] NOISSUE shortcut support: set working directory in .desktop files --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index aa30661b..21296cac 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -92,6 +92,10 @@ void CreateShortcutDialog::updateDialogState() ui->profileComboBox->setEnabled(ui->useProfileCheckBox->isChecked()); ui->offlineUsernameCheckBox->setEnabled(ui->launchOfflineCheckBox->isChecked()); ui->offlineUsername->setEnabled(ui->launchOfflineCheckBox->isChecked() && ui->offlineUsernameCheckBox->isChecked()); + if (!ui->launchOfflineCheckBox->isChecked()) + { + ui->offlineUsernameCheckBox->setChecked(false); + } } QString CreateShortcutDialog::getLaunchCommand() @@ -136,6 +140,7 @@ void CreateShortcutDialog::createShortcut() "Type=Application\n" "Name=" + m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME + "\n" + "Exec=" + getLaunchCommand() + "\n" + + "Path=" + QCoreApplication::applicationDirPath() + "\n" + "Icon=" + QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.png\n"; } From 75b87656049cbaaac8661a45741b92bd23a92c61 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 14:00:55 +0100 Subject: [PATCH 11/20] NOISSUE shortcut creation: set working directory in other shortcut types --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 10 ++++++++-- launcher/ui/dialogs/CreateShortcutDialog.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 21296cac..8d5aade2 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -125,7 +125,9 @@ void CreateShortcutDialog::createShortcut() // Unix shell script if (ui->createScriptCheckBox->isChecked()) { - shortcutText = "#!/bin/sh\n" + getLaunchCommand() + " &\n"; + shortcutText = "#!/bin/sh\n" + + "cd " + QCoreApplication::applicationDirPath() + "\n" + + getLaunchCommand() + " &\n"; } else // freedesktop.org desktop entry { @@ -148,6 +150,7 @@ void CreateShortcutDialog::createShortcut() #ifdef Q_OS_WIN // Windows batch script implementation shortcutText = "@ECHO OFF\r\n" + "CD " + QDir::toNativeSeparators(QCoreApplication::applicationDirPath()) + "\r\n" "START /B " + getLaunchCommand() + "\r\n"; #endif QFile shortcutFile(ui->shortcutPath->text()); @@ -170,6 +173,7 @@ void CreateShortcutDialog::createShortcut() } createWindowsLink(QDir::toNativeSeparators(QCoreApplication::applicationFilePath()).toStdString().c_str(), + QDir::toNativeSeparators(QCoreApplication::applicationFilePath()).toStdString().c_str(), getLaunchArgs().toStdString().c_str(), ui->shortcutPath->text().toStdString().c_str(), (m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME).toStdString().c_str(), @@ -180,7 +184,8 @@ void CreateShortcutDialog::createShortcut() } #ifdef Q_OS_WIN -void CreateShortcutDialog::createWindowsLink(LPCSTR target, LPCSTR args, LPCSTR filename, LPCSTR desc, LPCSTR iconPath) +void CreateShortcutDialog::createWindowsLink(LPCSTR target, LPCSTR workingDir, LPCSTR args, LPCSTR filename, + LPCSTR desc, LPCSTR iconPath) { HRESULT result; IShellLink *link; @@ -192,6 +197,7 @@ void CreateShortcutDialog::createWindowsLink(LPCSTR target, LPCSTR args, LPCSTR IPersistFile *file; link->SetPath(target); + link->SetWorkingDirectory(workingDir); link->SetArguments(args); link->SetDescription(desc); link->SetIconLocation(iconPath, 0); diff --git a/launcher/ui/dialogs/CreateShortcutDialog.h b/launcher/ui/dialogs/CreateShortcutDialog.h index d28a6b0c..22e789e0 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.h +++ b/launcher/ui/dialogs/CreateShortcutDialog.h @@ -44,6 +44,6 @@ private: void createShortcut(); #ifdef Q_OS_WIN - void createWindowsLink(LPCSTR target, LPCSTR args, LPCSTR filename, LPCSTR desc, LPCSTR iconPath); + void createWindowsLink(LPCSTR target, LPCSTR workingDir, LPCSTR args, LPCSTR filename, LPCSTR desc, LPCSTR iconPath); #endif }; \ No newline at end of file From bbdbe47e72c62c15fc9357ab331b343f68fb7ef4 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 14:19:50 +0100 Subject: [PATCH 12/20] NOISSUE actually use the directory as the working directory --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 8d5aade2..1e57b142 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -173,7 +173,7 @@ void CreateShortcutDialog::createShortcut() } createWindowsLink(QDir::toNativeSeparators(QCoreApplication::applicationFilePath()).toStdString().c_str(), - QDir::toNativeSeparators(QCoreApplication::applicationFilePath()).toStdString().c_str(), + QDir::toNativeSeparators(QCoreApplication::applicationDirPath()).toStdString().c_str(), getLaunchArgs().toStdString().c_str(), ui->shortcutPath->text().toStdString().c_str(), (m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME).toStdString().c_str(), From 7938585abba3c772916b46e488aeeaa9514163de Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 15:47:26 +0100 Subject: [PATCH 13/20] NOISSUE shortcut creation: add version blacklist for joining server on launch These versions are known to crash when joining a server on launch (see MC-145102 and MC-228828) --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 11 +++++++++++ launcher/ui/dialogs/CreateShortcutDialog.h | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 1e57b142..63cc6a29 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -11,6 +11,8 @@ #include "ui_CreateShortcutDialog.h" #include "Application.h" #include "minecraft/auth/AccountList.h" +#include "minecraft/MinecraftInstance.h" +#include "minecraft/PackProfile.h" #include "icons/IconList.h" #ifdef Q_OS_WIN @@ -38,6 +40,15 @@ CreateShortcutDialog::CreateShortcutDialog(QWidget *parent, InstancePtr instance ui->profileComboBox->setCurrentText(accounts->defaultAccount()->profileName()); } + if (m_instance->typeName() == "Minecraft") + { + MinecraftInstancePtr minecraftInstance = qobject_pointer_cast(m_instance); + QString version = minecraftInstance->getPackProfile()->getComponentVersion("net.minecraft"); + bool enableJoinServer = QRegExp(JOIN_SERVER_DISALLOWED_VERSIONS).exactMatch(version); + ui->joinServerCheckBox->setEnabled(enableJoinServer); + ui->joinServer->setEnabled(enableJoinServer); + } + #if defined(Q_OS_UNIX) && !defined(Q_OS_LINUX) ui->createScriptCheckBox->setEnabled(false); ui->createScriptCheckBox->setChecked(true); diff --git a/launcher/ui/dialogs/CreateShortcutDialog.h b/launcher/ui/dialogs/CreateShortcutDialog.h index 22e789e0..8e6d961f 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.h +++ b/launcher/ui/dialogs/CreateShortcutDialog.h @@ -15,6 +15,22 @@ #include #endif +const QString JOIN_SERVER_DISALLOWED_VERSIONS( + "(19w0[89][a-z])" + "|(19w1[0-9][a-z])" + "|(1.14.?[1-4]?-pre[0-9])" + "|(1.14.?[1-4]?)" + "|(19w[34][0-9][a-z])" + "|(1.15.?[0-9]?-pre[0-9])" + "|(1.15.?[0-9]?)" + "|(20w[01][0-9][a-z])" + "|(20w20a)" + "|(21w[12][0-9][a-z])" + "|(1.17-pre[0-9])" + "|(1.17-rc[0-9])" + "|(1.17)" + ); + namespace Ui { class CreateShortcutDialog; From 2dc44b3ff52c1bd85a6954258db3e8cb9acb019e Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 16:21:21 +0100 Subject: [PATCH 14/20] NOISSUE fix build --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 63cc6a29..50a584ce 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -137,7 +137,7 @@ void CreateShortcutDialog::createShortcut() if (ui->createScriptCheckBox->isChecked()) { shortcutText = "#!/bin/sh\n" - + "cd " + QCoreApplication::applicationDirPath() + "\n" + "cd " + QCoreApplication::applicationDirPath() + "\n" + getLaunchCommand() + " &\n"; } else // freedesktop.org desktop entry From 363588789ebc7a82bd6d9d3ecf77441c02d23686 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 16:30:30 +0100 Subject: [PATCH 15/20] NOISSUE shortcut creation: fix version check --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 50a584ce..3931e931 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -44,7 +44,7 @@ CreateShortcutDialog::CreateShortcutDialog(QWidget *parent, InstancePtr instance { MinecraftInstancePtr minecraftInstance = qobject_pointer_cast(m_instance); QString version = minecraftInstance->getPackProfile()->getComponentVersion("net.minecraft"); - bool enableJoinServer = QRegExp(JOIN_SERVER_DISALLOWED_VERSIONS).exactMatch(version); + bool enableJoinServer = !QRegExp(JOIN_SERVER_DISALLOWED_VERSIONS).exactMatch(version); ui->joinServerCheckBox->setEnabled(enableJoinServer); ui->joinServer->setEnabled(enableJoinServer); } From 6faa0ef7116e1ce71b3722dc8e0d1375616cfa56 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 16:43:23 +0100 Subject: [PATCH 16/20] NOISSUE shortcut creation: reload pack profile before checking version --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 23 +++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 3931e931..fba8cdd7 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "CreateShortcutDialog.h" #include "ui_CreateShortcutDialog.h" #include "Application.h" @@ -42,11 +43,23 @@ CreateShortcutDialog::CreateShortcutDialog(QWidget *parent, InstancePtr instance if (m_instance->typeName() == "Minecraft") { - MinecraftInstancePtr minecraftInstance = qobject_pointer_cast(m_instance); - QString version = minecraftInstance->getPackProfile()->getComponentVersion("net.minecraft"); - bool enableJoinServer = !QRegExp(JOIN_SERVER_DISALLOWED_VERSIONS).exactMatch(version); - ui->joinServerCheckBox->setEnabled(enableJoinServer); - ui->joinServer->setEnabled(enableJoinServer); + try + { + MinecraftInstancePtr minecraftInstance = qobject_pointer_cast(m_instance); + minecraftInstance->getPackProfile()->reload(Net::Mode::Online); + QString version = minecraftInstance->getPackProfile()->getComponentVersion("net.minecraft"); + bool enableJoinServer = !QRegExp(JOIN_SERVER_DISALLOWED_VERSIONS).exactMatch(version); + ui->joinServerCheckBox->setEnabled(enableJoinServer); + ui->joinServer->setEnabled(enableJoinServer); + } + catch (const Exception &e) + { + QMessageBox::critical(this, tr("Error"), e.cause()); + } + catch (...) + { + QMessageBox::critical(this, tr("Error"), tr("Failed to load pack profile to check version!")); + } } #if defined(Q_OS_UNIX) && !defined(Q_OS_LINUX) From 7df413db1a791c876a38394c11c6ae15307b1975 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 16:57:20 +0100 Subject: [PATCH 17/20] NOISSUE shortcut creation: blacklist versions by date instead of regex --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 6 ++++-- launcher/ui/dialogs/CreateShortcutDialog.h | 21 ++++++-------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index fba8cdd7..3dc91988 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -47,8 +47,10 @@ CreateShortcutDialog::CreateShortcutDialog(QWidget *parent, InstancePtr instance { MinecraftInstancePtr minecraftInstance = qobject_pointer_cast(m_instance); minecraftInstance->getPackProfile()->reload(Net::Mode::Online); - QString version = minecraftInstance->getPackProfile()->getComponentVersion("net.minecraft"); - bool enableJoinServer = !QRegExp(JOIN_SERVER_DISALLOWED_VERSIONS).exactMatch(version); + QDateTime versionDate = minecraftInstance->getPackProfile()->getComponent("net.minecraft")->getReleaseDateTime(); + bool enableJoinServer = (versionDate < MC_145102_START) + || (versionDate >= MC_145102_END && versionDate < MC_228828_START) + || (versionDate >= MC_228828_END); ui->joinServerCheckBox->setEnabled(enableJoinServer); ui->joinServer->setEnabled(enableJoinServer); } diff --git a/launcher/ui/dialogs/CreateShortcutDialog.h b/launcher/ui/dialogs/CreateShortcutDialog.h index 8e6d961f..d27e94cd 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.h +++ b/launcher/ui/dialogs/CreateShortcutDialog.h @@ -10,26 +10,17 @@ #include #include "minecraft/auth/MinecraftAccount.h" #include "BaseInstance.h" +#include "minecraft/ParseUtils.h" #ifdef Q_OS_WIN #include #endif -const QString JOIN_SERVER_DISALLOWED_VERSIONS( - "(19w0[89][a-z])" - "|(19w1[0-9][a-z])" - "|(1.14.?[1-4]?-pre[0-9])" - "|(1.14.?[1-4]?)" - "|(19w[34][0-9][a-z])" - "|(1.15.?[0-9]?-pre[0-9])" - "|(1.15.?[0-9]?)" - "|(20w[01][0-9][a-z])" - "|(20w20a)" - "|(21w[12][0-9][a-z])" - "|(1.17-pre[0-9])" - "|(1.17-rc[0-9])" - "|(1.17)" - ); +// Dates when the game was affected by bugs that crashed the game when using the option to join a server on startup +const QDateTime MC_145102_START = timeFromS3Time("2019-02-20T14:56:58+00:00"); +const QDateTime MC_145102_END = timeFromS3Time("2020-05-14T08:16:26+00:00"); +const QDateTime MC_228828_START = timeFromS3Time("2021-03-10T15:24:38+00:00"); +const QDateTime MC_228828_END = timeFromS3Time("2021-06-18T12:24:40+00:00"); namespace Ui { From 0a2ad17f062b42710d111e03567f1d1f08784f42 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 18:11:18 +0100 Subject: [PATCH 18/20] NOISSUE shortcut creation: add comments and todo --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 3dc91988..3238da01 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -41,6 +41,8 @@ CreateShortcutDialog::CreateShortcutDialog(QWidget *parent, InstancePtr instance ui->profileComboBox->setCurrentText(accounts->defaultAccount()->profileName()); } + // check if instance is affected by a bug causing it to crash when trying to join a server on launch + // TODO: implement this check in meta if (m_instance->typeName() == "Minecraft") { try @@ -64,6 +66,7 @@ CreateShortcutDialog::CreateShortcutDialog(QWidget *parent, InstancePtr instance } } + // Macs don't have any concept of a desktop shortcut, so force-enable the option to generate a shell script instead #if defined(Q_OS_UNIX) && !defined(Q_OS_LINUX) ui->createScriptCheckBox->setEnabled(false); ui->createScriptCheckBox->setChecked(true); From 79910e3542e104e600b5dc3d2175d01509bddbf8 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 19:53:45 +0100 Subject: [PATCH 19/20] NOISSUE shortcut creation: put file dialog in save mode This makes sure that the user is prompted if they are about to overwrite a file --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 3238da01..9123d667 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -91,7 +91,7 @@ void CreateShortcutDialog::on_shortcutPathBrowse_clicked() #endif QFileDialog fileDialog(this, tr("Select shortcut path"), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); fileDialog.setDefaultSuffix(linkExtension); - fileDialog.setAcceptMode(QFileDialog::AcceptOpen); + fileDialog.setAcceptMode(QFileDialog::AcceptSave); fileDialog.setFileMode(QFileDialog::AnyFile); fileDialog.selectFile(m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME + "." + linkExtension); if (fileDialog.exec()) From 518b19e6677eb1a328f2a88daa4334fc02202dc7 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Wed, 6 Jul 2022 08:03:04 +0100 Subject: [PATCH 20/20] NOISSUE shortcut creation: enclose paths in quotes --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index 9123d667..f6711397 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -129,7 +129,7 @@ void CreateShortcutDialog::updateDialogState() QString CreateShortcutDialog::getLaunchCommand() { - return QDir::toNativeSeparators(QCoreApplication::applicationFilePath()) + return "\"" + QDir::toNativeSeparators(QCoreApplication::applicationFilePath()) + "\"" + getLaunchArgs(); } @@ -155,7 +155,7 @@ void CreateShortcutDialog::createShortcut() if (ui->createScriptCheckBox->isChecked()) { shortcutText = "#!/bin/sh\n" - "cd " + QCoreApplication::applicationDirPath() + "\n" + "cd \"" + QCoreApplication::applicationDirPath() + "\"\n" + getLaunchCommand() + " &\n"; } else // freedesktop.org desktop entry @@ -179,7 +179,7 @@ void CreateShortcutDialog::createShortcut() #ifdef Q_OS_WIN // Windows batch script implementation shortcutText = "@ECHO OFF\r\n" - "CD " + QDir::toNativeSeparators(QCoreApplication::applicationDirPath()) + "\r\n" + "CD \"" + QDir::toNativeSeparators(QCoreApplication::applicationDirPath()) + "\"\r\n" "START /B " + getLaunchCommand() + "\r\n"; #endif QFile shortcutFile(ui->shortcutPath->text());