From 858487521e5bce60b6dc8fd6436cf052779ac31f Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 31 Jul 2022 11:38:00 +0100 Subject: [PATCH] NOISSUE Escape quotes in paths Just in case the user decides to place MMC in a path containing quotes. .desktop files appear to require two backslashes to escape quotes, testing on other desktop environments would be appreciated to make sure this isn't just a KDE-specific bug --- launcher/ui/dialogs/CreateShortcutDialog.cpp | 14 +++++++------- launcher/ui/dialogs/CreateShortcutDialog.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/launcher/ui/dialogs/CreateShortcutDialog.cpp b/launcher/ui/dialogs/CreateShortcutDialog.cpp index a5366835..6eb5e78e 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.cpp +++ b/launcher/ui/dialogs/CreateShortcutDialog.cpp @@ -107,15 +107,15 @@ void CreateShortcutDialog::updateDialogState() } } -QString CreateShortcutDialog::getLaunchCommand() +QString CreateShortcutDialog::getLaunchCommand(bool escapeQuotesTwice) { - return "\"" + QDir::toNativeSeparators(QCoreApplication::applicationFilePath()) + "\"" - + getLaunchArgs(); + return "\"" + QDir::toNativeSeparators(QCoreApplication::applicationFilePath()).replace('"', escapeQuotesTwice ? "\\\\\"" : "\\\"") + "\"" + + getLaunchArgs(escapeQuotesTwice); } -QString CreateShortcutDialog::getLaunchArgs() +QString CreateShortcutDialog::getLaunchArgs(bool escapeQuotesTwice) { - return " -d \"" + QDir::toNativeSeparators(QDir::currentPath()) + "\"" + return " -d \"" + QDir::toNativeSeparators(QDir::currentPath()).replace('"', escapeQuotesTwice ? "\\\\\"" : "\\\"") + "\"" + " -l \"" + m_instance->id() + "\"" + (ui->joinServerCheckBox->isChecked() ? " -s \"" + ui->joinServer->text() + "\"" : "") + (ui->useProfileCheckBox->isChecked() ? " -a \"" + ui->profileComboBox->currentText() + "\"" : "") @@ -137,7 +137,7 @@ void CreateShortcutDialog::createShortcut() { shortcutText = "#!/bin/sh\n" // FIXME: is there a way to use the launcher script instead of the raw binary here? - "cd \"" + QDir::currentPath() + "\"\n" + "cd \"" + QDir::currentPath().replace('"', "\\\"") + "\"\n" + getLaunchCommand() + " &\n"; } else // freedesktop.org desktop entry @@ -152,7 +152,7 @@ void CreateShortcutDialog::createShortcut() shortcutText = "[Desktop Entry]\n" "Type=Application\n" "Name=" + m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME + "\n" - + "Exec=" + getLaunchCommand() + "\n" + + "Exec=" + getLaunchCommand(true) + "\n" + "Path=" + QDir::currentPath() + "\n" + "Icon=" + QDir::currentPath() + "/icons/shortcut-icon.png\n"; diff --git a/launcher/ui/dialogs/CreateShortcutDialog.h b/launcher/ui/dialogs/CreateShortcutDialog.h index a2497dd6..4714253b 100644 --- a/launcher/ui/dialogs/CreateShortcutDialog.h +++ b/launcher/ui/dialogs/CreateShortcutDialog.h @@ -39,8 +39,8 @@ private: Ui::CreateShortcutDialog *ui; InstancePtr m_instance; - QString getLaunchCommand(); - QString getLaunchArgs(); + QString getLaunchCommand(bool escapeQuotesTwice = false); + QString getLaunchArgs(bool escapeQuotesTwice = false); void createShortcut();