From 30b266622c9457a825d38ba084c9391437a2c87a Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sat, 22 Oct 2022 15:39:53 +0300 Subject: [PATCH 01/24] Add 'Create shortcut' button to instance toolbar Implemented on Windows only rn! Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/ui/MainWindow.cpp | 86 ++++++++++++++++++++++++++++++++++++++ launcher/ui/MainWindow.h | 2 + 2 files changed, 88 insertions(+) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 85b00b67..419bb9bd 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -237,6 +237,7 @@ public: TranslatedAction actionLaunchInstanceOffline; TranslatedAction actionLaunchInstanceDemo; TranslatedAction actionExportInstance; + TranslatedAction actionCreateInstanceShortcut; QVector all_actions; LabeledToolButton *renameButton = nullptr; @@ -597,6 +598,7 @@ public: actionExportInstance->setEnabled(enabled); actionDeleteInstance->setEnabled(enabled); actionCopyInstance->setEnabled(enabled); + actionCreateInstanceShortcut->setEnabled(enabled); } void createStatusBar(QMainWindow *MainWindow) @@ -735,6 +737,14 @@ public: actionCopyInstance->setIcon(APPLICATION->getThemedIcon("copy")); all_actions.append(&actionCopyInstance); + actionCreateInstanceShortcut = TranslatedAction(MainWindow); + actionCreateInstanceShortcut->setObjectName(QStringLiteral("actionCreateInstanceShortcut")); + actionCreateInstanceShortcut.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Create shortcut")); + actionCreateInstanceShortcut.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Creates a shortcut on your desktop to launch the selected instance.")); + actionCreateInstanceShortcut->setShortcut(QKeySequence(tr("Ctrl+D"))); + //actionCreateInstanceShortcut->setIcon(APPLICATION->getThemedIcon("copy")); // TODO + all_actions.append(&actionCreateInstanceShortcut); + setInstanceActionsEnabled(false); } @@ -783,6 +793,8 @@ public: } } + instanceToolBar->addAction(actionCreateInstanceShortcut); + all_toolbars.append(&instanceToolBar); MainWindow->addToolBar(Qt::RightToolBarArea, instanceToolBar); } @@ -2075,6 +2087,80 @@ void MainWindow::on_actionKillInstance_triggered() } } +#ifdef Q_OS_WIN +#define WIN32_LEAN_AND_MEAN +#include "windows.h" +#include "winnls.h" +#include "shobjidl.h" +#include "objbase.h" +#include "objidl.h" +#include "shlguid.h" +#endif + +void MainWindow::on_actionCreateInstanceShortcut_triggered() +{ + if (m_selectedInstance) + { + auto desktopDir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + if (desktopDir.isEmpty()) { + // TODO come up with an alternative solution (open "save file" dialog) + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Couldn't find desktop!")); + return; + } + +#if defined(Q_OS_WIN) + // Windows + WCHAR wsz[MAX_PATH]; + + // ...yes, you need to initialize the entire COM stack to make a shortcut in Windows. + // I hate it. + CoInitialize(nullptr); + + HRESULT hres; + IShellLink* psl; + + hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); + if (SUCCEEDED(hres)) + { + IPersistFile* ppf; + + QApplication::applicationFilePath().left(MAX_PATH - 1).toWCharArray(wsz); + psl->SetPath(wsz); + + wmemset(wsz, 0, MAX_PATH); + QStringLiteral("--launch %1").arg(m_selectedInstance->id()).left(MAX_PATH - 1).toWCharArray(wsz); + psl->SetArguments(wsz); + + // TODO set icon + + hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); + + if (SUCCEEDED(hres)) + { + wmemset(wsz, 0, MAX_PATH); + + desktopDir + .append('/') + .append(QStringLiteral("%1.lnk").arg(m_selectedInstance->name())) + .left(MAX_PATH - 1).toWCharArray(wsz); + + hres = ppf->Save(wsz, TRUE); + ppf->Release(); + } + psl->Release(); + } + + CoUninitialize(); +#elif defined(Q_OS_LINUX) + // Linux +#elif defined(Q_OS_MACOS) + // macOSX + // TODO actually write this path + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Not supported on macOSX yet!")); +#endif + } +} + void MainWindow::taskEnd() { QObject *sender = QObject::sender(); diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h index f9d1f1c7..b23ba146 100644 --- a/launcher/ui/MainWindow.h +++ b/launcher/ui/MainWindow.h @@ -157,6 +157,8 @@ private slots: void on_actionEditInstance_triggered(); + void on_actionCreateInstanceShortcut_triggered(); + void taskEnd(); /** 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: [PATCH 02/24] Windows: implement FS::createShortcut Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/FileSystem.cpp | 145 +++++++++++++++++++++++++++++++------ launcher/FileSystem.h | 5 ++ launcher/ui/MainWindow.cpp | 88 +++++++--------------- 3 files changed, 154 insertions(+), 84 deletions(-) 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); + QFileInfo targetInfo(target); - // QString argStr; - // for (int i = 0; i < args.count(); i++) - // { - // argStr.append(args[i]); - // argStr.append(" "); - // } - // argStr.toWCharArray(args_w); + if (!targetInfo.exists()) + { + qWarning() << "Target file does not exist!"; + return false; + } - // return SUCCEEDED(CreateLink(file_w, dest_w, args_w)); - 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; diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index b7e175fd..23cc575b 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -156,4 +156,9 @@ QString getDesktopDir(); // Overrides one folder with the contents of another, preserving items exclusive to the first folder // Equivalent to doing QDir::rename, but allowing for overrides bool overrideFolder(QString overwritten_path, QString override_path); + +/** + * Creates a shortcut to the specified target file at the specified destination path. + */ +bool createShortcut(QString destination, QString target, QStringList args, QString name, QString icon); } diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 419bb9bd..1ad9713a 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -39,6 +39,7 @@ #include "Application.h" #include "BuildConfig.h" +#include "FileSystem.h" #include "MainWindow.h" @@ -739,9 +740,9 @@ public: actionCreateInstanceShortcut = TranslatedAction(MainWindow); actionCreateInstanceShortcut->setObjectName(QStringLiteral("actionCreateInstanceShortcut")); - actionCreateInstanceShortcut.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Create shortcut")); + actionCreateInstanceShortcut.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Create Shortcut")); actionCreateInstanceShortcut.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Creates a shortcut on your desktop to launch the selected instance.")); - actionCreateInstanceShortcut->setShortcut(QKeySequence(tr("Ctrl+D"))); + //actionCreateInstanceShortcut->setShortcut(QKeySequence(tr("Ctrl+D"))); // TODO //actionCreateInstanceShortcut->setIcon(APPLICATION->getThemedIcon("copy")); // TODO all_actions.append(&actionCreateInstanceShortcut); @@ -793,7 +794,7 @@ public: } } - instanceToolBar->addAction(actionCreateInstanceShortcut); + instanceToolBar->addAction(actionCreateInstanceShortcut); // TODO find better position for this all_toolbars.append(&instanceToolBar); MainWindow->addToolBar(Qt::RightToolBarArea, instanceToolBar); @@ -2087,76 +2088,39 @@ void MainWindow::on_actionKillInstance_triggered() } } -#ifdef Q_OS_WIN -#define WIN32_LEAN_AND_MEAN -#include "windows.h" -#include "winnls.h" -#include "shobjidl.h" -#include "objbase.h" -#include "objidl.h" -#include "shlguid.h" -#endif - void MainWindow::on_actionCreateInstanceShortcut_triggered() { if (m_selectedInstance) { - auto desktopDir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); - if (desktopDir.isEmpty()) { + auto desktopPath = FS::getDesktopDir(); + if (desktopPath.isEmpty()) { // TODO come up with an alternative solution (open "save file" dialog) - QMessageBox::critical(this, tr("Create instance shortcut"), tr("Couldn't find desktop!")); + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Couldn't find desktop?!")); return; } -#if defined(Q_OS_WIN) - // Windows - WCHAR wsz[MAX_PATH]; - - // ...yes, you need to initialize the entire COM stack to make a shortcut in Windows. - // I hate it. - CoInitialize(nullptr); - - HRESULT hres; - IShellLink* psl; - - hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); - if (SUCCEEDED(hres)) - { - IPersistFile* ppf; - - QApplication::applicationFilePath().left(MAX_PATH - 1).toWCharArray(wsz); - psl->SetPath(wsz); - - wmemset(wsz, 0, MAX_PATH); - QStringLiteral("--launch %1").arg(m_selectedInstance->id()).left(MAX_PATH - 1).toWCharArray(wsz); - psl->SetArguments(wsz); - - // TODO set icon - - hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); - - if (SUCCEEDED(hres)) - { - wmemset(wsz, 0, MAX_PATH); - - desktopDir - .append('/') - .append(QStringLiteral("%1.lnk").arg(m_selectedInstance->name())) - .left(MAX_PATH - 1).toWCharArray(wsz); - - hres = ppf->Save(wsz, TRUE); - ppf->Release(); - } - psl->Release(); - } - - CoUninitialize(); -#elif defined(Q_OS_LINUX) - // Linux -#elif defined(Q_OS_MACOS) +#if defined(Q_OS_MACOS) // macOSX // TODO actually write this path QMessageBox::critical(this, tr("Create instance shortcut"), tr("Not supported on macOSX yet!")); +#else + QString iconPath; + +#if defined(Q_OS_WIN) + // TODO + // need to convert icon to ICO format and save it somewhere... + iconPath = ""; +#elif defined(Q_OS_UNIX) + iconPath = ""; // TODO get instance icon path +#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 + { + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); + } #endif } } From f12117c532de4bdbf74968cf173d1c288a7e426a Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Tue, 25 Oct 2022 17:37:30 +0300 Subject: [PATCH 03/24] [UNTESTED] Linux: add icons to shortcuts Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/ui/MainWindow.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 1ad9713a..8f2196f2 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2104,6 +2104,8 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() // TODO actually write this path QMessageBox::critical(this, tr("Create instance shortcut"), tr("Not supported on macOSX yet!")); #else + auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey()); + QString iconPath; #if defined(Q_OS_WIN) @@ -2111,7 +2113,7 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() // need to convert icon to ICO format and save it somewhere... iconPath = ""; #elif defined(Q_OS_UNIX) - iconPath = ""; // TODO get instance icon path + iconPath = icon->getFilePath(); #endif if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), QApplication::applicationFilePath(), { "--launch", m_selectedInstance->id() }, m_selectedInstance->name(), iconPath)) { From 6ae3b183fdb1f6e4887617fc7230d52c803e63fd Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Tue, 25 Oct 2022 21:18:53 +0300 Subject: [PATCH 04/24] Remove unnessecary "is defined" check Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/ui/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 8f2196f2..34c51ec6 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2112,7 +2112,7 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() // TODO // need to convert icon to ICO format and save it somewhere... iconPath = ""; -#elif defined(Q_OS_UNIX) +#else iconPath = icon->getFilePath(); #endif if (FS::createShortcut(FS::PathCombine(desktopPath, m_selectedInstance->name()), 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: [PATCH 05/24] 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(-) 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; } + 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; + } + 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; + // 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); From 4d4dfab38869bca82626e171336cbe8f7c89a1a1 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Fri, 28 Oct 2022 17:42:29 +0300 Subject: [PATCH 06/24] Windows: add instance icon to shortcut Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/ui/MainWindow.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 34c51ec6..9743c822 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2107,11 +2107,28 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey()); QString iconPath; + bool iconGenerated = false; #if defined(Q_OS_WIN) - // TODO - // need to convert icon to ICO format and save it somewhere... - iconPath = ""; + iconPath = FS::PathCombine(m_selectedInstance->instanceRoot(), "icon.ico"); + + QFile iconFile(iconPath); + if (!iconFile.open(QFile::WriteOnly)) + { + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); + return; + } + + if (!icon->icon().pixmap(64, 64).save(&iconFile, "ICO")) + { + iconFile.close(); + iconFile.remove(); + QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); + return; + } + + iconFile.close(); + iconGenerated = true; #else iconPath = icon->getFilePath(); #endif @@ -2121,6 +2138,10 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() } else { + if (iconGenerated) + { + QFile::remove(iconPath); + } QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); } #endif From cc5f82bfac162becf55dfcb015f55be3c833bc32 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Fri, 28 Oct 2022 21:11:51 +0300 Subject: [PATCH 07/24] Windows: fix window icon being replaced Dunno why it happens but the fix was literally 2 lines, so whatever I guess Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/ui/MainWindow.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 9743c822..a87da362 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2112,6 +2112,10 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() #if defined(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(); + QFile iconFile(iconPath); if (!iconFile.open(QFile::WriteOnly)) { @@ -2129,6 +2133,9 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() iconFile.close(); iconGenerated = true; + + // restore original window icon + QGuiApplication::setWindowIcon(appIcon); #else iconPath = icon->getFilePath(); #endif From 487e352642c4430f57643b53a8e9cd3d04edfeb8 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Fri, 4 Nov 2022 22:04:42 +0200 Subject: [PATCH 08/24] Fix nested #if directive Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/ui/MainWindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index a87da362..15fdd6f2 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2103,7 +2103,8 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() // macOSX // TODO actually write this path QMessageBox::critical(this, tr("Create instance shortcut"), tr("Not supported on macOSX yet!")); -#else + return; +#endif auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey()); QString iconPath; @@ -2151,7 +2152,6 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() } QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); } -#endif } } 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: [PATCH 09/24] 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(-) 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)) From 9be48f1dc44dc764d2131c559780624908ff636d Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Wed, 9 Nov 2022 21:55:13 +0200 Subject: [PATCH 10/24] this ain't static, falco Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/ui/MainWindow.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index cd3c1b5b..ff1982ce 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2113,7 +2113,7 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() // 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"); + auto appIcon = APPLICATION->getThemedIcon("logo"); QFile iconFile(iconPath); if (!iconFile.open(QFile::WriteOnly)) @@ -2121,20 +2121,22 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); return; } + bool success = icon->icon().pixmap(64, 64).save(&iconFile, "ICO"); + iconFile.close(); - if (!icon->icon().pixmap(64, 64).save(&iconFile, "ICO")) + // restore original window icon + QGuiApplication::setWindowIcon(appIcon); + + if (success) + { + iconGenerated = true; + } + else { - iconFile.close(); iconFile.remove(); QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); return; } - - iconFile.close(); - iconGenerated = true; - - // restore original window icon - QGuiApplication::setWindowIcon(appIcon); #else iconPath = icon->getFilePath(); #endif From dbe0553b4a6100d8269f749cc4eb372e5a30cb3b Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Wed, 9 Nov 2022 21:56:46 +0200 Subject: [PATCH 11/24] Move addAction call above left-align loop Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/ui/MainWindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index ff1982ce..0a846b59 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -784,6 +784,8 @@ public: instanceToolBar->addAction(actionCopyInstance); instanceToolBar->addAction(actionDeleteInstance); + instanceToolBar->addAction(actionCreateInstanceShortcut); // TODO find better position for this + QLayout * lay = instanceToolBar->layout(); for(int i = 0; i < lay->count(); i++) { @@ -794,8 +796,6 @@ public: } } - instanceToolBar->addAction(actionCreateInstanceShortcut); // TODO find better position for this - all_toolbars.append(&instanceToolBar); MainWindow->addToolBar(Qt::RightToolBarArea, instanceToolBar); } 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: [PATCH 12/24] 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(-) 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); 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: [PATCH 13/24] 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(-) 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 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: [PATCH 14/24] 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(-) 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 } } From 45ce72593ac29e54311219e71d47b044eda14b14 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sat, 12 Nov 2022 20:43:58 +0200 Subject: [PATCH 15/24] Windows: remove icon if shortcut creation fails Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/ui/MainWindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 8e8a7c56..3f99ac99 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2158,6 +2158,7 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() } else { + iconFile.remove(); QMessageBox::critical(this, tr("Create instance shortcut"), tr("Failed to create instance shortcut!")); } #else From 5322155b19e68b44e879512cf46ee152045dc1b1 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sat, 12 Nov 2022 20:48:21 +0200 Subject: [PATCH 16/24] Mac: fix build Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/ui/MainWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 3f99ac99..aedd9e4f 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2101,7 +2101,7 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() #if defined(Q_OS_MACOS) // handle macOS bundle weirdness - QFileInfo appFileInfo(QApplication::applicationFilePath())); + QFileInfo appFileInfo(QApplication::applicationFilePath()); QString appName = appFileInfo.baseName(); QString exeName = FS::PathCombine(appFileInfo.filePath(), "Contents/MacOS/" + appName); 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: [PATCH 17/24] 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(-) 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 From 43b9d9484da280fc209a0c9f195b0ca338eacdb9 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:49:28 +0200 Subject: [PATCH 18/24] tabs -> spaces Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/ui/MainWindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 17371149..c7de46c7 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2101,10 +2101,10 @@ 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(), "")) { 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: [PATCH 19/24] 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(-) 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 From c4cfec1e94d1665dc3c1ccd44966a34f349698ea Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sun, 13 Nov 2022 18:00:18 +0200 Subject: [PATCH 20/24] Undo accidental tomlplusplus downgrade Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- libraries/tomlplusplus | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/tomlplusplus b/libraries/tomlplusplus index 4b166b69..cc741c9f 160000 --- a/libraries/tomlplusplus +++ b/libraries/tomlplusplus @@ -1 +1 @@ -Subproject commit 4b166b69f28e70a416a1a04a98f365d2aeb90de8 +Subproject commit cc741c9f5f2a62856a2a2e9e275f61eb0591c09c 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: [PATCH 21/24] 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(-) 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()) From 5be8545edcf53cd410d0ea14168b5675150106fc Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Sun, 13 Nov 2022 20:18:51 +0200 Subject: [PATCH 22/24] Windows, Linux: prevent segfault on missing icon Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/ui/MainWindow.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 4dbac967..4e6ce82c 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -2131,7 +2131,11 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() } auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey()); - + if (icon == nullptr) + { + icon = APPLICATION->icons()->icon("grass"); + } + QString iconPath = FS::PathCombine(m_selectedInstance->instanceRoot(), "icon.png"); QFile iconFile(iconPath); @@ -2162,7 +2166,11 @@ void MainWindow::on_actionCreateInstanceShortcut_triggered() } #elif defined(Q_OS_WIN) auto icon = APPLICATION->icons()->icon(m_selectedInstance->iconKey()); - + if (icon == nullptr) + { + icon = APPLICATION->icons()->icon("grass"); + } + QString iconPath = FS::PathCombine(m_selectedInstance->instanceRoot(), "icon.ico"); // part of fix for weird bug involving the window icon being replaced From ce892c9e777f13de6e6298806d9fdb5c92f77af6 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Mon, 14 Nov 2022 21:02:31 +0200 Subject: [PATCH 23/24] Add icon NOTE: Currently missing on Legacy, Flat and Flat (White) Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/resources/OSX/OSX.qrc | 4 +- launcher/resources/OSX/scalable/shortcut.svg | 14 +++++++ launcher/resources/iOS/iOS.qrc | 4 +- launcher/resources/iOS/scalable/shortcut.svg | 13 ++++++ launcher/resources/pe_blue/pe_blue.qrc | 4 +- .../resources/pe_blue/scalable/shortcut.svg | 41 +++++++++++++++++++ launcher/resources/pe_colored/pe_colored.qrc | 4 +- .../pe_colored/scalable/shortcut.svg | 13 ++++++ launcher/resources/pe_dark/pe_dark.qrc | 4 +- .../resources/pe_dark/scalable/shortcut.svg | 41 +++++++++++++++++++ launcher/resources/pe_light/pe_light.qrc | 4 +- .../resources/pe_light/scalable/shortcut.svg | 41 +++++++++++++++++++ launcher/ui/MainWindow.cpp | 3 +- 13 files changed, 177 insertions(+), 13 deletions(-) create mode 100644 launcher/resources/OSX/scalable/shortcut.svg create mode 100644 launcher/resources/iOS/scalable/shortcut.svg create mode 100644 launcher/resources/pe_blue/scalable/shortcut.svg create mode 100644 launcher/resources/pe_colored/scalable/shortcut.svg create mode 100644 launcher/resources/pe_dark/scalable/shortcut.svg create mode 100644 launcher/resources/pe_light/scalable/shortcut.svg diff --git a/launcher/resources/OSX/OSX.qrc b/launcher/resources/OSX/OSX.qrc index 19fe312b..3f50d6cf 100644 --- a/launcher/resources/OSX/OSX.qrc +++ b/launcher/resources/OSX/OSX.qrc @@ -1,5 +1,4 @@ - - + index.theme scalable/about.svg @@ -39,5 +38,6 @@ scalable/export.svg scalable/rename.svg scalable/launch.svg + scalable/shortcut.svg diff --git a/launcher/resources/OSX/scalable/shortcut.svg b/launcher/resources/OSX/scalable/shortcut.svg new file mode 100644 index 00000000..a2b7488e --- /dev/null +++ b/launcher/resources/OSX/scalable/shortcut.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/launcher/resources/iOS/iOS.qrc b/launcher/resources/iOS/iOS.qrc index aa08d811..d7044fbb 100644 --- a/launcher/resources/iOS/iOS.qrc +++ b/launcher/resources/iOS/iOS.qrc @@ -1,5 +1,4 @@ - - + index.theme scalable/about.svg @@ -39,5 +38,6 @@ scalable/export.svg scalable/rename.svg scalable/launch.svg + scalable/shortcut.svg diff --git a/launcher/resources/iOS/scalable/shortcut.svg b/launcher/resources/iOS/scalable/shortcut.svg new file mode 100644 index 00000000..16e9fa48 --- /dev/null +++ b/launcher/resources/iOS/scalable/shortcut.svg @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/launcher/resources/pe_blue/pe_blue.qrc b/launcher/resources/pe_blue/pe_blue.qrc index 3121ffe6..dc40103a 100644 --- a/launcher/resources/pe_blue/pe_blue.qrc +++ b/launcher/resources/pe_blue/pe_blue.qrc @@ -1,5 +1,4 @@ - - + index.theme scalable/about.svg @@ -39,5 +38,6 @@ scalable/export.svg scalable/rename.svg scalable/launch.svg + scalable/shortcut.svg diff --git a/launcher/resources/pe_blue/scalable/shortcut.svg b/launcher/resources/pe_blue/scalable/shortcut.svg new file mode 100644 index 00000000..45b73496 --- /dev/null +++ b/launcher/resources/pe_blue/scalable/shortcut.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/pe_colored/pe_colored.qrc b/launcher/resources/pe_colored/pe_colored.qrc index ce5ad8e2..bd1af6ff 100644 --- a/launcher/resources/pe_colored/pe_colored.qrc +++ b/launcher/resources/pe_colored/pe_colored.qrc @@ -1,5 +1,4 @@ - - + index.theme scalable/about.svg @@ -39,5 +38,6 @@ scalable/export.svg scalable/rename.svg scalable/launch.svg + scalable/shortcut.svg diff --git a/launcher/resources/pe_colored/scalable/shortcut.svg b/launcher/resources/pe_colored/scalable/shortcut.svg new file mode 100644 index 00000000..1469674f --- /dev/null +++ b/launcher/resources/pe_colored/scalable/shortcut.svg @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/launcher/resources/pe_dark/pe_dark.qrc b/launcher/resources/pe_dark/pe_dark.qrc index 156d8f8b..05ef7e93 100644 --- a/launcher/resources/pe_dark/pe_dark.qrc +++ b/launcher/resources/pe_dark/pe_dark.qrc @@ -1,5 +1,4 @@ - - + index.theme scalable/about.svg @@ -39,5 +38,6 @@ scalable/export.svg scalable/rename.svg scalable/launch.svg + scalable/shortcut.svg diff --git a/launcher/resources/pe_dark/scalable/shortcut.svg b/launcher/resources/pe_dark/scalable/shortcut.svg new file mode 100644 index 00000000..29b45f26 --- /dev/null +++ b/launcher/resources/pe_dark/scalable/shortcut.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/resources/pe_light/pe_light.qrc b/launcher/resources/pe_light/pe_light.qrc index d8e4a1bd..6acca230 100644 --- a/launcher/resources/pe_light/pe_light.qrc +++ b/launcher/resources/pe_light/pe_light.qrc @@ -1,5 +1,4 @@ - - + index.theme scalable/about.svg @@ -39,5 +38,6 @@ scalable/export.svg scalable/rename.svg scalable/launch.svg + scalable/shortcut.svg diff --git a/launcher/resources/pe_light/scalable/shortcut.svg b/launcher/resources/pe_light/scalable/shortcut.svg new file mode 100644 index 00000000..4d232bcf --- /dev/null +++ b/launcher/resources/pe_light/scalable/shortcut.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 4e6ce82c..0c606660 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -743,7 +743,8 @@ public: actionCreateInstanceShortcut.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Create Shortcut")); actionCreateInstanceShortcut.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Creates a shortcut on your desktop to launch the selected instance.")); //actionCreateInstanceShortcut->setShortcut(QKeySequence(tr("Ctrl+D"))); // TODO - //actionCreateInstanceShortcut->setIcon(APPLICATION->getThemedIcon("copy")); // TODO + // FIXME missing on Legacy, Flat and Flat (White) + actionCreateInstanceShortcut->setIcon(APPLICATION->getThemedIcon("shortcut")); all_actions.append(&actionCreateInstanceShortcut); setInstanceActionsEnabled(false); From cca052ccc9d644c84384ceefe97bbce45381a9e2 Mon Sep 17 00:00:00 2001 From: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> Date: Mon, 14 Nov 2022 22:46:41 +0200 Subject: [PATCH 24/24] Restore QRC headers Signed-off-by: ADudeCalledLeo <7997354+Leo40Git@users.noreply.github.com> --- launcher/resources/OSX/OSX.qrc | 3 ++- launcher/resources/iOS/iOS.qrc | 3 ++- launcher/resources/pe_blue/pe_blue.qrc | 3 ++- launcher/resources/pe_colored/pe_colored.qrc | 3 ++- launcher/resources/pe_dark/pe_dark.qrc | 3 ++- launcher/resources/pe_light/pe_light.qrc | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/launcher/resources/OSX/OSX.qrc b/launcher/resources/OSX/OSX.qrc index 3f50d6cf..9d4511d1 100644 --- a/launcher/resources/OSX/OSX.qrc +++ b/launcher/resources/OSX/OSX.qrc @@ -1,4 +1,5 @@ - + + index.theme scalable/about.svg diff --git a/launcher/resources/iOS/iOS.qrc b/launcher/resources/iOS/iOS.qrc index d7044fbb..0b79efb2 100644 --- a/launcher/resources/iOS/iOS.qrc +++ b/launcher/resources/iOS/iOS.qrc @@ -1,4 +1,5 @@ - + + index.theme scalable/about.svg diff --git a/launcher/resources/pe_blue/pe_blue.qrc b/launcher/resources/pe_blue/pe_blue.qrc index dc40103a..639675f0 100644 --- a/launcher/resources/pe_blue/pe_blue.qrc +++ b/launcher/resources/pe_blue/pe_blue.qrc @@ -1,4 +1,5 @@ - + + index.theme scalable/about.svg diff --git a/launcher/resources/pe_colored/pe_colored.qrc b/launcher/resources/pe_colored/pe_colored.qrc index bd1af6ff..fac58da8 100644 --- a/launcher/resources/pe_colored/pe_colored.qrc +++ b/launcher/resources/pe_colored/pe_colored.qrc @@ -1,4 +1,5 @@ - + + index.theme scalable/about.svg diff --git a/launcher/resources/pe_dark/pe_dark.qrc b/launcher/resources/pe_dark/pe_dark.qrc index 05ef7e93..c0c6ee6c 100644 --- a/launcher/resources/pe_dark/pe_dark.qrc +++ b/launcher/resources/pe_dark/pe_dark.qrc @@ -1,4 +1,5 @@ - + + index.theme scalable/about.svg diff --git a/launcher/resources/pe_light/pe_light.qrc b/launcher/resources/pe_light/pe_light.qrc index 6acca230..bd6a2496 100644 --- a/launcher/resources/pe_light/pe_light.qrc +++ b/launcher/resources/pe_light/pe_light.qrc @@ -1,4 +1,5 @@ - + + index.theme scalable/about.svg