From 75b87656049cbaaac8661a45741b92bd23a92c61 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Sun, 3 Jul 2022 14:00:55 +0100 Subject: [PATCH] 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