Merge pull request #4842 from arthomnix/shortcut-path-fix

NOISSUE Fix shortcut creation on official Linux builds
This commit is contained in:
Petr Mrázek 2022-07-19 21:54:35 +02:00 committed by GitHub
commit b5e81bbb0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -112,7 +112,8 @@ QString CreateShortcutDialog::getLaunchCommand()
QString CreateShortcutDialog::getLaunchArgs() QString CreateShortcutDialog::getLaunchArgs()
{ {
return " -l " + m_instance->id() return " -d \"" + QDir::toNativeSeparators(QDir::currentPath()) + "\""
+ " -l " + m_instance->id()
+ (ui->joinServerCheckBox->isChecked() ? " -s " + ui->joinServer->text() : "") + (ui->joinServerCheckBox->isChecked() ? " -s " + ui->joinServer->text() : "")
+ (ui->useProfileCheckBox->isChecked() ? " -a " + ui->profileComboBox->currentText() : "") + (ui->useProfileCheckBox->isChecked() ? " -a " + ui->profileComboBox->currentText() : "")
+ (ui->launchOfflineCheckBox->isChecked() ? " -o" : "") + (ui->launchOfflineCheckBox->isChecked() ? " -o" : "")
@ -132,31 +133,32 @@ void CreateShortcutDialog::createShortcut()
if (ui->createScriptCheckBox->isChecked()) if (ui->createScriptCheckBox->isChecked())
{ {
shortcutText = "#!/bin/sh\n" shortcutText = "#!/bin/sh\n"
"cd \"" + QCoreApplication::applicationDirPath() + "\"\n" // FIXME: is there a way to use the launcher script instead of the raw binary here?
"cd \"" + QDir::currentPath() + "\"\n"
+ getLaunchCommand() + " &\n"; + getLaunchCommand() + " &\n";
} else } else
// freedesktop.org desktop entry // freedesktop.org desktop entry
{ {
// save the launcher icon to a file so we can use it in the shortcut // save the launcher icon to a file so we can use it in the shortcut
if (!QFileInfo::exists(QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.png")) if (!QFileInfo::exists(QDir::currentPath() + "/icons/shortcut-icon.png"))
{ {
QPixmap iconPixmap = QIcon(":/logo.svg").pixmap(64, 64); QPixmap iconPixmap = QIcon(":/logo.svg").pixmap(64, 64);
iconPixmap.save(QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.png"); iconPixmap.save(QDir::currentPath() + "/icons/shortcut-icon.png");
} }
shortcutText = "[Desktop Entry]\n" shortcutText = "[Desktop Entry]\n"
"Type=Application\n" "Type=Application\n"
"Name=" + m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME + "\n" "Name=" + m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME + "\n"
+ "Exec=" + getLaunchCommand() + "\n" + "Exec=" + getLaunchCommand() + "\n"
+ "Path=" + QCoreApplication::applicationDirPath() + "\n" + "Path=" + QDir::currentPath() + "\n"
+ "Icon=" + QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.png\n"; + "Icon=" + QDir::currentPath() + "/icons/shortcut-icon.png\n";
} }
#endif #endif
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
// Windows batch script implementation // Windows batch script implementation
shortcutText = "@ECHO OFF\r\n" shortcutText = "@ECHO OFF\r\n"
"CD \"" + QDir::toNativeSeparators(QCoreApplication::applicationDirPath()) + "\"\r\n" "CD \"" + QDir::toNativeSeparators(QDir::currentPath()) + "\"\r\n"
"START /B " + getLaunchCommand() + "\r\n"; "START /B " + getLaunchCommand() + "\r\n";
#endif #endif
QFile shortcutFile(ui->shortcutPath->text()); QFile shortcutFile(ui->shortcutPath->text());
@ -172,18 +174,18 @@ void CreateShortcutDialog::createShortcut()
} }
else else
{ {
if (!QFileInfo::exists(QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.ico")) if (!QFileInfo::exists(QDir::currentPath() + "/icons/shortcut-icon.ico"))
{ {
QPixmap iconPixmap = QIcon(":/logo.svg").pixmap(64, 64); QPixmap iconPixmap = QIcon(":/logo.svg").pixmap(64, 64);
iconPixmap.save(QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.ico"); iconPixmap.save(QDir::currentPath() + "/icons/shortcut-icon.ico");
} }
createWindowsLink(QDir::toNativeSeparators(QCoreApplication::applicationFilePath()).toStdString().c_str(), createWindowsLink(QDir::toNativeSeparators(QCoreApplication::applicationFilePath()).toStdString().c_str(),
QDir::toNativeSeparators(QCoreApplication::applicationDirPath()).toStdString().c_str(), QDir::toNativeSeparators(QDir::currentPath()).toStdString().c_str(),
getLaunchArgs().toStdString().c_str(), getLaunchArgs().toStdString().c_str(),
ui->shortcutPath->text().toStdString().c_str(), ui->shortcutPath->text().toStdString().c_str(),
(m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME).toStdString().c_str(), (m_instance->name() + " - " + BuildConfig.LAUNCHER_DISPLAYNAME).toStdString().c_str(),
QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/icons/shortcut-icon.ico").toStdString().c_str() QDir::toNativeSeparators(QDir::currentPath() + "/icons/shortcut-icon.ico").toStdString().c_str()
); );
} }
#endif #endif