From 70768189bae0f4d5cfb24b57347cf7207dfc5496 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sat, 22 Oct 2022 17:56:27 +0300 Subject: Windows: implement FS::createShortcut Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/FileSystem.cpp | 149 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 125 insertions(+), 24 deletions(-) (limited to 'launcher/FileSystem.cpp') diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 4a8f4bd3..90f0313f 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -49,6 +49,7 @@ #include "StringUtils.h" #if defined Q_OS_WIN32 +#define WIN32_LEAN_AND_MEAN #include #include #include @@ -339,12 +340,12 @@ QString getDesktopDir() } // Cross-platform Shortcut creation -bool createShortCut(QString location, QString dest, QStringList args, QString name, QString icon) +bool createShortcut(QString destination, QString target, QStringList args, QString name, QString icon) { #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) - location = PathCombine(location, name + ".desktop"); + destination = PathCombine(destination, name + ".desktop"); - QFile f(location); + QFile f(destination); f.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream stream(&f); @@ -356,10 +357,13 @@ bool createShortCut(QString location, QString dest, QStringList args, QString na << "\n"; stream << "Type=Application" << "\n"; - stream << "TryExec=" << dest.toLocal8Bit() << "\n"; - stream << "Exec=" << dest.toLocal8Bit() << argstring.toLocal8Bit() << "\n"; + stream << "TryExec=" << target.toLocal8Bit() << "\n"; + stream << "Exec=" << target.toLocal8Bit() << argstring.toLocal8Bit() << "\n"; stream << "Name=" << name.toLocal8Bit() << "\n"; - stream << "Icon=" << icon.toLocal8Bit() << "\n"; + if (!icon.isEmpty()) + { + stream << "Icon=" << icon.toLocal8Bit() << "\n"; + } stream.flush(); f.close(); @@ -368,24 +372,121 @@ bool createShortCut(QString location, QString dest, QStringList args, QString na return true; #elif defined Q_OS_WIN - // TODO: Fix - // QFile file(PathCombine(location, name + ".lnk")); - // WCHAR *file_w; - // WCHAR *dest_w; - // WCHAR *args_w; - // file.fileName().toWCharArray(file_w); - // dest.toWCharArray(dest_w); - - // QString argStr; - // for (int i = 0; i < args.count(); i++) - // { - // argStr.append(args[i]); - // argStr.append(" "); - // } - // argStr.toWCharArray(args_w); - - // return SUCCEEDED(CreateLink(file_w, dest_w, args_w)); - return false; + QFileInfo targetInfo(target); + + if (!targetInfo.exists()) + { + qWarning() << "Target file does not exist!"; + return false; + } + + target = targetInfo.absoluteFilePath(); + + if (target.length() >= MAX_PATH) + { + qWarning() << "Target file path is too long!"; + return false; + } + + if (!icon.isEmpty() && icon.length() >= MAX_PATH) + { + qWarning() << "Icon path is too long!"; + return false; + } + + destination += ".lnk"; + + if (destination.length() >= MAX_PATH) + { + qWarning() << "Destination path is too long!"; + return false; + } + + QString argStr; + int argCount = args.count(); + for (int i = 0; i < argCount; i++) + { + if (args[i].contains(' ')) + { + argStr.append('"').append(args[i]).append('"'); + } + else + { + argStr.append(args[i]); + } + + if (i < argCount - 1) + { + argStr.append(" "); + } + } + + if (argStr.length() >= MAX_PATH) + { + qWarning() << "Arguments string is too long!"; + return false; + } + + WCHAR wsz[MAX_PATH]; + + // ...yes, you need to initialize the entire COM stack to make a shortcut in Windows + CoInitialize(nullptr); + + HRESULT hres; + IShellLink* psl; + + hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); + if (SUCCEEDED(hres)) + { + wmemset(wsz, 0, MAX_PATH); + target.toWCharArray(wsz); + psl->SetPath(wsz); + + wmemset(wsz, 0, MAX_PATH); + argStr.toWCharArray(wsz); + psl->SetArguments(wsz); + + wmemset(wsz, 0, MAX_PATH); + targetInfo.absolutePath().toWCharArray(wsz); + psl->SetWorkingDirectory(wsz); + + if (!icon.isEmpty()) + { + wmemset(wsz, 0, MAX_PATH); + icon.toWCharArray(wsz); + psl->SetIconLocation(wsz, 0); + } + + IPersistFile* ppf; + hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); + if (SUCCEEDED(hres)) + { + wmemset(wsz, 0, MAX_PATH); + destination.toWCharArray(wsz); + hres = ppf->Save(wsz, TRUE); + if (FAILED(hres)) + { + qWarning() << "IPresistFile->Save() failed"; + qWarning() << "hres = " << hres; + } + ppf->Release(); + } + else + { + qWarning() << "Failed to query IPersistFile interface from IShellLink instance"; + qWarning() << "hres = " << hres; + } + psl->Release(); + } + else + { + qWarning() << "Failed to create IShellLink instance"; + qWarning() << "hres = " << hres; + } + + CoUninitialize(); + + return SUCCEEDED(hres); #else qWarning("Desktop Shortcuts not supported on your platform!"); return false; -- cgit From b83f9be1bd65f784bbed603e550fbe9f650b0367 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Fri, 28 Oct 2022 15:46:54 +0300 Subject: Add missing fail check for CoInitialize Add a few comments Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/FileSystem.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'launcher/FileSystem.cpp') diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 90f0313f..587753a0 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -427,14 +427,21 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri return false; } - WCHAR wsz[MAX_PATH]; + HRESULT hres; + + // ...yes, you need to initialize the entire COM stack just to make a shortcut + hres = CoInitialize(nullptr); + if (FAILED(hres)) + { + qWarning() << "Failed to initialize COM!"; + return false; + } - // ...yes, you need to initialize the entire COM stack to make a shortcut in Windows - CoInitialize(nullptr); + WCHAR wsz[MAX_PATH]; - HRESULT hres; IShellLink* psl; + // create an IShellLink instance - this stores the shortcut's attributes hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); if (SUCCEEDED(hres)) { @@ -448,7 +455,7 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri wmemset(wsz, 0, MAX_PATH); targetInfo.absolutePath().toWCharArray(wsz); - psl->SetWorkingDirectory(wsz); + psl->SetWorkingDirectory(wsz); // "Starts in" attribute if (!icon.isEmpty()) { @@ -457,6 +464,8 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri psl->SetIconLocation(wsz, 0); } + // query an IPersistFile interface from our IShellLink instance + // this is the interface that will actually let us save the shortcut to disk! IPersistFile* ppf; hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); if (SUCCEEDED(hres)) @@ -484,6 +493,7 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri qWarning() << "hres = " << hres; } + // go away COM, nobody likes you CoUninitialize(); return SUCCEEDED(hres); -- cgit From 6043444e4e11801e45ad888182c99d6f4e4e5ddc Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Wed, 9 Nov 2022 21:02:40 +0200 Subject: Apply suggestions from code review Co-authored-by: Sefa Eyeoglu Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/FileSystem.cpp | 2 +- launcher/ui/MainWindow.cpp | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'launcher/FileSystem.cpp') diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 587753a0..5a539093 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -342,7 +342,7 @@ QString getDesktopDir() // Cross-platform Shortcut creation bool createShortcut(QString destination, QString target, QStringList args, QString name, QString icon) { -#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) +#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) destination = PathCombine(destination, name + ".desktop"); QFile f(destination); diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 15fdd6f2..cd3c1b5b 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2099,23 +2099,21 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() return; } -#if defined(Q_OS_MACOS) - // macOSX - // TODO actually write this path - QMessageBox::critical(this, tr("Create instance shortcut"), tr("Not supported on macOSX yet!")); - return; +#ifdef Q_OS_MACOS + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Not supported on macOS yet!")); + return; #endif auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey()); QString iconPath; bool iconGenerated = false; -#if defined(Q_OS_WIN) +#ifdef Q_OS_WIN iconPath = FS::PathCombine(m_selectedInstance->instanceRoot(), "icon.ico"); // part of fix for weird bug involving the window icon being replaced // dunno why it happens, but this 2-line fix seems to be enough, so w/e - auto appIcon = QGuiApplication::windowIcon(); + auto appIcon = Application::getThemedIcon("logo"); QFile iconFile(iconPath); if (!iconFile.open(QFile::WriteOnly)) -- cgit From 7e5076b06891f28c1b2e27befd33005d400c49c9 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sat, 12 Nov 2022 20:13:59 +0200 Subject: Linux: fix path shortcut is written to Co-authored-by: flow Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/FileSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'launcher/FileSystem.cpp') diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 5a539093..ddd1a6e5 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -343,7 +343,7 @@ QString getDesktopDir() bool createShortcut(QString destination, QString target, QStringList args, QString name, QString icon) { #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) - destination = PathCombine(destination, name + ".desktop"); + destination += ".desktop"; QFile f(destination); f.open(QIODevice::WriteOnly | QIODevice::Text); -- cgit From f7d7d76ee879c3bdd539e5c8c956cbd2c7328bf0 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sat, 12 Nov 2022 20:36:49 +0200 Subject: Mac: now supported! [UNTESTED] Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/FileSystem.cpp | 26 +++++++++++++++++++++++++- launcher/ui/MainWindow.cpp | 15 ++++++++++++++- libraries/tomlplusplus | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) (limited to 'launcher/FileSystem.cpp') diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index ddd1a6e5..221395be 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -342,7 +342,31 @@ QString getDesktopDir() // Cross-platform Shortcut creation bool createShortcut(QString destination, QString target, QStringList args, QString name, QString icon) { -#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) +#if defined(Q_OS_MACOS) + destination += ".sh"; + + QFile f(destination); + f.open(QIODevice::WriteOnly | QIODevice::Text); + QTextStream stream(&f); + + QString argstring; + if (!args.empty()) + argstring = " \"" + args.join("\" \"") + "\""; + + stream << "#!/bin/bash" + << "\n"; + stream << target + << " " + << argstring + << "\n"; + + stream.flush(); + f.close(); + + f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup | QFileDevice::ExeOther); + + return true; +#elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) destination += ".desktop"; QFile f(destination); diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 0a846b59..02f60233 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2100,7 +2100,20 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() } #ifdef Q_OS_MACOS - QMessageBox::critical(this, tr("Create instance shortcut"), tr("Not supported on macOS yet!")); + // handle macOS bundle weirdness + QFileInfo appFileInfo(QApplication::applicationFilePath())); + QString appName = appFileInfo.baseName(); + QString exeName = FS::PathCombine(appFileInfo.filePath(), "Contents/MacOS/" + appName); + + if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), + exeName, { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), "")) { + QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); + } + else + { + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); + } + return; #endif auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey()); diff --git a/libraries/tomlplusplus b/libraries/tomlplusplus index cc741c9f..4b166b69 160000 --- a/libraries/tomlplusplus +++ b/libraries/tomlplusplus @@ -1 +1 @@ -Subproject commit cc741c9f5f2a62856a2a2e9e275f61eb0591c09c +Subproject commit 4b166b69f28e70a416a1a04a98f365d2aeb90de8 -- cgit From b813c867b505f0c1ec8125fde9916d6252cd4485 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sat, 12 Nov 2022 20:41:52 +0200 Subject: refactor #if checks Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/FileSystem.cpp | 2 +- launcher/ui/MainWindow.cpp | 46 ++++++++++++++++++++++------------------------ 2 files changed, 23 insertions(+), 25 deletions(-) (limited to 'launcher/FileSystem.cpp') diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 221395be..7a1861e7 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -395,7 +395,7 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup | QFileDevice::ExeOther); return true; -#elif defined Q_OS_WIN +#elif defined(Q_OS_WIN) QFileInfo targetInfo(target); if (!targetInfo.exists()) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 02f60233..8e8a7c56 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2099,13 +2099,13 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() return; } -#ifdef Q_OS_MACOS +#if defined(Q_OS_MACOS) // handle macOS bundle weirdness QFileInfo appFileInfo(QApplication::applicationFilePath())); QString appName = appFileInfo.baseName(); QString exeName = FS::PathCombine(appFileInfo.filePath(), "Contents/MacOS/" + appName); - if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), + if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), exeName, { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), "")) { QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); } @@ -2113,17 +2113,22 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() { QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); } - - return; -#endif +#elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey()); - - QString iconPath; - bool iconGenerated = false; - -#ifdef Q_OS_WIN - iconPath = FS::PathCombine(m_selectedInstance->instanceRoot(), "icon.ico"); - + + if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), + QApplication::applicationFilePath(), { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), icon->getFilePath())) { + QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); + } + else + { + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); + } +#elif defined(Q_OS_WIN) + auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey()); + + QString iconPath = FS::PathCombine(m_selectedInstance->instanceRoot(), "icon.ico"); + // part of fix for weird bug involving the window icon being replaced // dunno why it happens, but this 2-line fix seems to be enough, so w/e auto appIcon = APPLICATION->getThemedIcon("logo"); @@ -2140,31 +2145,24 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() // restore original window icon QGuiApplication::setWindowIcon(appIcon); - if (success) - { - iconGenerated = true; - } - else + if (!success) { iconFile.remove(); QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); return; } -#else - iconPath = icon->getFilePath(); -#endif + if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), QApplication::applicationFilePath(), { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), iconPath)) { QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); } else { - if (iconGenerated) - { - QFile::remove(iconPath); - } QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); } +#else + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Not supported on your platform!")); +#endif } } -- cgit From 69bbb2932848fe7509f91623bac2a648ce594ad7 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:47:37 +0200 Subject: Mac: attempt 2 - create .command files instead of .sh - fix shortcuts not working if path to Prism Launcher contains spaces - fix path to executable in shortcutss - add check for running from extracted folder (prevents creating shortcuts) Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/FileSystem.cpp | 7 ++++--- launcher/ui/MainWindow.cpp | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'launcher/FileSystem.cpp') diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 7a1861e7..80715498 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -343,7 +343,7 @@ QString getDesktopDir() bool createShortcut(QString destination, QString target, QStringList args, QString name, QString icon) { #if defined(Q_OS_MACOS) - destination += ".sh"; + destination += ".command"; QFile f(destination); f.open(QIODevice::WriteOnly | QIODevice::Text); @@ -355,8 +355,9 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri stream << "#!/bin/bash" << "\n"; - stream << target - << " " + stream << "\"" + << target + << "\" " << argstring << "\n"; diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index aedd9e4f..17371149 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2100,13 +2100,14 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() } #if defined(Q_OS_MACOS) - // handle macOS bundle weirdness - QFileInfo appFileInfo(QApplication::applicationFilePath()); - QString appName = appFileInfo.baseName(); - QString exeName = FS::PathCombine(appFileInfo.filePath(), "Contents/MacOS/" + appName); + QString appPath = QApplication::applicationFilePath(); + if (appPath.startsWith("/private/var")) { + QMessageBox::critical(this, tr("Create instance shortcut"), tr("The launcher is in the folder it was extracted from, therefore it cannot create shortcuts.")); + return; + } if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), - exeName, { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), "")) { + appPath, { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), "")) { QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); } else -- cgit From b0269e6dfc685cd002340e95e80942410f1b1fc5 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sun, 13 Nov 2022 17:51:29 +0200 Subject: Linux: fixes - Fix shortcut icons - Possibly fix shortcut creation on AppImages - Fix shortcut not working if path to launcher contains spaces Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/FileSystem.cpp | 4 ++-- launcher/ui/MainWindow.cpp | 48 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 8 deletions(-) (limited to 'launcher/FileSystem.cpp') diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 80715498..e1059ca9 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -382,8 +382,8 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri << "\n"; stream << "Type=Application" << "\n"; - stream << "TryExec=" << target.toLocal8Bit() << "\n"; - stream << "Exec=" << target.toLocal8Bit() << argstring.toLocal8Bit() << "\n"; + stream << "TryExec=\"" << target.toLocal8Bit() << "\"\n"; + stream << "Exec=\"" << target.toLocal8Bit() << "\"" << argstring.toLocal8Bit() << "\n"; stream << "Name=" << name.toLocal8Bit() << "\n"; if (!icon.isEmpty()) { diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index c7de46c7..4dbac967 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2101,13 +2101,14 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() #if defined(Q_OS_MACOS) QString appPath = QApplication::applicationFilePath(); - if (appPath.startsWith("/private/var")) { + if (appPath.startsWith("/private/var/")) { QMessageBox::critical(this, tr("Create instance shortcut"), tr("The launcher is in the folder it was extracted from, therefore it cannot create shortcuts.")); return; } if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), - appPath, { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), "")) { + appPath, { "--launch", m_selectedInstance->id() }, + m_selectedInstance->name(), "")) { QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); } else @@ -2115,14 +2116,48 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); } #elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) + QString appPath = QApplication::applicationFilePath(); + if (appPath.startsWith("/tmp/.mount_")) { + // AppImage! + appPath = QProcessEnvironment::systemEnvironment().value(QStringLiteral("APPIMAGE")); + if (appPath.isEmpty()) + { + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Launcher is running as misconfigured AppImage? ($APPIMAGE environment variable is missing)")); + } + else if (appPath.endsWith("/")) + { + appPath.chop(1); + } + } + auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey()); + QString iconPath = FS::PathCombine(m_selectedInstance->instanceRoot(), "icon.png"); + + QFile iconFile(iconPath); + if (!iconFile.open(QFile::WriteOnly)) + { + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut.")); + return; + } + bool success = icon->icon().pixmap(64, 64).save(&iconFile, "PNG"); + iconFile.close(); + + if (!success) + { + iconFile.remove(); + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut.")); + return; + } + if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), - QApplication::applicationFilePath(), { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), icon->getFilePath())) { + appPath, { "--launch", m_selectedInstance->id() }, + m_selectedInstance->name(), iconPath)) { QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); } else { + iconFile.remove(); QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); } #elif defined(Q_OS_WIN) @@ -2137,7 +2172,7 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() QFile iconFile(iconPath); if (!iconFile.open(QFile::WriteOnly)) { - QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut.")); return; } bool success = icon->icon().pixmap(64, 64).save(&iconFile, "ICO"); @@ -2149,12 +2184,13 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() if (!success) { iconFile.remove(); - QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut.")); return; } if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), - QApplication::applicationFilePath(), { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), iconPath)) { + QApplication::applicationFilePath(), { "--launch", m_selectedInstance->id() }, + m_selectedInstance->name(), iconPath)) { QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); } else -- cgit From acd50969e0fcb172cf5f62e5ced4d10c6a9cbbe6 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sun, 13 Nov 2022 19:50:27 +0200 Subject: Linux: remove TryExec entry from .desktop files Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/FileSystem.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'launcher/FileSystem.cpp') diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index e1059ca9..9d911fa0 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -382,7 +382,6 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri << "\n"; stream << "Type=Application" << "\n"; - stream << "TryExec=\"" << target.toLocal8Bit() << "\"\n"; stream << "Exec=\"" << target.toLocal8Bit() << "\"" << argstring.toLocal8Bit() << "\n"; stream << "Name=" << name.toLocal8Bit() << "\n"; if (!icon.isEmpty()) -- cgit From 4208c2c72a160896f63f44148c74cf24fc30d4b9 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 21 Nov 2022 15:47:15 +0100 Subject: fix: actually emit fileCopied Signed-off-by: Sefa Eyeoglu --- launcher/FileSystem.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'launcher/FileSystem.cpp') diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 0c6527b1..987f4e74 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -188,6 +188,8 @@ bool copy::operator()(const QString& offset, bool dryRun) qDebug() << "Source file:" << src_path; qDebug() << "Destination file:" << dst_path; } + m_copied++; + emit fileCopied(relative_dst_path); }; // We can't use copy_opts::recursive because we need to take into account the -- cgit From 37ad1b40d8fc86d746ce89219846582ec641f1e6 Mon Sep 17 00:00:00 2001 From: leo78913 Date: Thu, 8 Dec 2022 10:46:58 -0300 Subject: fix: fix creating instance shortcuts in flatpak Signed-off-by: leo78913 --- launcher/FileSystem.cpp | 2 -- launcher/ui/MainWindow.cpp | 23 +++++++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'launcher/FileSystem.cpp') diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 1da50e21..3e8e10a5 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -372,8 +372,6 @@ bool createShortcut(QString destination, QString target, QStringList args, QStri return true; #elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) - destination += ".desktop"; - QFile f(destination); f.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream stream(&f); diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 91cc5f29..8f156bfb 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2269,10 +2269,25 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create icon for shortcut.")); return; } - - if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), - appPath, { "--launch", m_selectedInstance->id() }, - m_selectedInstance->name(), iconPath)) { + + QString desktopFilePath = FS::PathCombine(desktopPath, m_selectedInstance->name() + ".desktop"); + QStringList args; + if (DesktopServices::isFlatpak()) { + QFileDialog fileDialog; + // workaround to make sure the portal file dialog opens in the desktop directory + fileDialog.setDirectoryUrl(desktopPath); + desktopFilePath = fileDialog.getSaveFileName( + this, tr("Create Shortcut"), desktopFilePath, + tr("Desktop Entries (*.desktop)")); + if (desktopFilePath.isEmpty()) + return; // file dialog canceled by user + appPath = "flatpak"; + QString flatpakAppId = BuildConfig.LAUNCHER_DESKTOPFILENAME; + flatpakAppId.remove(".desktop"); + args.append({ "run", flatpakAppId }); + } + args.append({ "--launch", m_selectedInstance->id() }); + if (FS::createShortcut(desktopFilePath, appPath, args, m_selectedInstance->name(), iconPath)) { QMessageBox::information(this, tr("Create instance shortcut"), tr("Created a shortcut to this instance on your desktop!")); } else -- cgit