Merge commit 'c0df1846f4f34e7a8adb5191fbda213ff68a5a24' into amzn-tommy/gitflow_211116_o3de2

This commit is contained in:
Tommy Walton
2021-11-16 11:42:11 -08:00
9 changed files with 74 additions and 2 deletions
@@ -9,3 +9,4 @@
#pragma once
#define AZ_TRAIT_PROJECT_MANAGER_CUSTOM_TITLEBAR true
#define AZ_TRAIT_PROJECT_MANAGER_CREATE_DESKTOP_SHORTCUT true
@@ -13,6 +13,7 @@
#include <QFileInfo>
#include <QProcess>
#include <QProcessEnvironment>
#include <QStandardPaths>
#include <AzCore/Utils/Utils.h>
@@ -146,5 +147,26 @@ namespace O3DE::ProjectManager
{
return AZ::Utils::GetExecutableDirectory();
}
AZ::Outcome<QString, QString> CreateDesktopShortcut(const QString& filename, const QString& targetPath, const QStringList& arguments)
{
const QString cmd{"powershell.exe"};
const QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
const QString shortcutPath = QString("%1/%2.lnk").arg(desktopPath).arg(filename);
const QString arg = QString("$s=(New-Object -COM WScript.Shell).CreateShortcut('%1');$s.TargetPath='%2';$s.Arguments='%3';$s.Save();")
.arg(shortcutPath)
.arg(targetPath)
.arg(arguments.join(' '));
auto createShortcutResult = ExecuteCommandResult(cmd, QStringList{"-Command", arg}, QProcessEnvironment::systemEnvironment());
if (!createShortcutResult.IsSuccess())
{
return AZ::Failure(QObject::tr("Failed to create desktop shortcut %1 <br><br>"
"Please verify you have permission to create files at the specified location.<br><br> %2")
.arg(shortcutPath)
.arg(createShortcutResult.GetError()));
}
return AZ::Success(QObject::tr("Desktop shortcut created at<br><a href=\"%1\">%2</a>").arg(desktopPath).arg(shortcutPath));
}
} // namespace ProjectUtils
} // namespace O3DE::ProjectManager