From 2fad7f37db565815d12bcc2f053e605f02e5384d Mon Sep 17 00:00:00 2001 From: AMZN-nggieber <52797929+AMZN-nggieber@users.noreply.github.com> Date: Mon, 12 Jul 2021 11:54:36 -0700 Subject: [PATCH] Added a Warning When VS2019 is not Installed with Link to Download it (#2042) * Added a warning when VS2019 is not installed with link to download it Signed-off-by: nggieber * Widden VSWarning dialog Signed-off-by: nggieber * Fix issue with checking for Visual Studio Signed-off-by: nggieber * PALify compiler detection Signed-off-by: nggieber * Changed windows compiler check to waitForFinished instead of waitForReadyRead Signed-off-by: nggieber --- .../Platform/Linux/PAL_linux_files.cmake | 1 + .../Platform/Linux/ProjectUtils_linux.cpp | 21 +++++++ .../Platform/Mac/PAL_mac_files.cmake | 1 + .../Platform/Mac/ProjectUtils_mac.cpp | 21 +++++++ .../Platform/Windows/PAL_windows_files.cmake | 1 + .../Platform/Windows/ProjectUtils_windows.cpp | 60 +++++++++++++++++++ .../Source/CreateProjectCtrl.cpp | 47 ++++++++------- .../ProjectManager/Source/ProjectUtils.cpp | 53 ++++++---------- .../ProjectManager/Source/ProjectUtils.h | 4 +- .../ProjectManager/Source/ProjectsScreen.cpp | 2 +- 10 files changed, 153 insertions(+), 58 deletions(-) create mode 100644 Code/Tools/ProjectManager/Platform/Linux/ProjectUtils_linux.cpp create mode 100644 Code/Tools/ProjectManager/Platform/Mac/ProjectUtils_mac.cpp create mode 100644 Code/Tools/ProjectManager/Platform/Windows/ProjectUtils_windows.cpp diff --git a/Code/Tools/ProjectManager/Platform/Linux/PAL_linux_files.cmake b/Code/Tools/ProjectManager/Platform/Linux/PAL_linux_files.cmake index e8085de555..4125861f2b 100644 --- a/Code/Tools/ProjectManager/Platform/Linux/PAL_linux_files.cmake +++ b/Code/Tools/ProjectManager/Platform/Linux/PAL_linux_files.cmake @@ -8,4 +8,5 @@ set(FILES Python_linux.cpp ProjectBuilderWorker_linux.cpp + ProjectUtils_linux.cpp ) diff --git a/Code/Tools/ProjectManager/Platform/Linux/ProjectUtils_linux.cpp b/Code/Tools/ProjectManager/Platform/Linux/ProjectUtils_linux.cpp new file mode 100644 index 0000000000..64d18ec605 --- /dev/null +++ b/Code/Tools/ProjectManager/Platform/Linux/ProjectUtils_linux.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include + +namespace O3DE::ProjectManager +{ + namespace ProjectUtils + { + AZ::Outcome FindSupportedCompilerForPlatform() + { + // Compiler detection not supported on platform + return AZ::Success(); + } + + } // namespace ProjectUtils +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Platform/Mac/PAL_mac_files.cmake b/Code/Tools/ProjectManager/Platform/Mac/PAL_mac_files.cmake index 01d6b5f112..a0d3add840 100644 --- a/Code/Tools/ProjectManager/Platform/Mac/PAL_mac_files.cmake +++ b/Code/Tools/ProjectManager/Platform/Mac/PAL_mac_files.cmake @@ -8,4 +8,5 @@ set(FILES Python_mac.cpp ProjectBuilderWorker_mac.cpp + ProjectUtils_mac.cpp ) diff --git a/Code/Tools/ProjectManager/Platform/Mac/ProjectUtils_mac.cpp b/Code/Tools/ProjectManager/Platform/Mac/ProjectUtils_mac.cpp new file mode 100644 index 0000000000..64d18ec605 --- /dev/null +++ b/Code/Tools/ProjectManager/Platform/Mac/ProjectUtils_mac.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include + +namespace O3DE::ProjectManager +{ + namespace ProjectUtils + { + AZ::Outcome FindSupportedCompilerForPlatform() + { + // Compiler detection not supported on platform + return AZ::Success(); + } + + } // namespace ProjectUtils +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Platform/Windows/PAL_windows_files.cmake b/Code/Tools/ProjectManager/Platform/Windows/PAL_windows_files.cmake index eb45c61807..8af7638696 100644 --- a/Code/Tools/ProjectManager/Platform/Windows/PAL_windows_files.cmake +++ b/Code/Tools/ProjectManager/Platform/Windows/PAL_windows_files.cmake @@ -8,4 +8,5 @@ set(FILES Python_windows.cpp ProjectBuilderWorker_windows.cpp + ProjectUtils_windows.cpp ) diff --git a/Code/Tools/ProjectManager/Platform/Windows/ProjectUtils_windows.cpp b/Code/Tools/ProjectManager/Platform/Windows/ProjectUtils_windows.cpp new file mode 100644 index 0000000000..c0d977a5f5 --- /dev/null +++ b/Code/Tools/ProjectManager/Platform/Windows/ProjectUtils_windows.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include + +#include +#include +#include +#include + +namespace O3DE::ProjectManager +{ + namespace ProjectUtils + { + AZ::Outcome FindSupportedCompilerForPlatform() + { + QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); + QString programFilesPath = environment.value("ProgramFiles(x86)"); + QString vsWherePath = QDir(programFilesPath).filePath("Microsoft Visual Studio/Installer/vswhere.exe"); + + QFileInfo vsWhereFile(vsWherePath); + if (vsWhereFile.exists() && vsWhereFile.isFile()) + { + QProcess vsWhereProcess; + vsWhereProcess.setProcessChannelMode(QProcess::MergedChannels); + + vsWhereProcess.start( + vsWherePath, + QStringList{ + "-version", + "16.0", + "-latest", + "-requires", + "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", + "-property", + "isComplete" + }); + + if (vsWhereProcess.waitForStarted() && vsWhereProcess.waitForFinished()) + { + QString vsWhereOutput(vsWhereProcess.readAllStandardOutput()); + if (vsWhereOutput.startsWith("1")) + { + return AZ::Success(); + } + } + } + + return AZ::Failure(QObject::tr("Visual Studio 2019 not found.\n\n" + "Visual Studio 2019 is required to build this project." + " Install any edition of Visual Studio 2019" + " before proceeding to the next step.")); + } + + } // namespace ProjectUtils +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/CreateProjectCtrl.cpp b/Code/Tools/ProjectManager/Source/CreateProjectCtrl.cpp index 9c0b4726ed..b2b656dbae 100644 --- a/Code/Tools/ProjectManager/Source/CreateProjectCtrl.cpp +++ b/Code/Tools/ProjectManager/Source/CreateProjectCtrl.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -222,38 +223,42 @@ namespace O3DE::ProjectManager void CreateProjectCtrl::CreateProject() { - if (m_newProjectSettingsScreen->Validate()) + if (ProjectUtils::FindSupportedCompiler(this)) { - ProjectInfo projectInfo = m_newProjectSettingsScreen->GetProjectInfo(); - QString projectTemplatePath = m_newProjectSettingsScreen->GetProjectTemplatePath(); - - auto result = PythonBindingsInterface::Get()->CreateProject(projectTemplatePath, projectInfo); - if (result.IsSuccess()) + if (m_newProjectSettingsScreen->Validate()) { - // automatically register the project - PythonBindingsInterface::Get()->AddProject(projectInfo.m_path); + ProjectInfo projectInfo = m_newProjectSettingsScreen->GetProjectInfo(); + QString projectTemplatePath = m_newProjectSettingsScreen->GetProjectTemplatePath(); -#ifdef TEMPLATE_GEM_CONFIGURATION_ENABLED - if (!m_gemCatalogScreen->EnableDisableGemsForProject(projectInfo.m_path)) + auto result = PythonBindingsInterface::Get()->CreateProject(projectTemplatePath, projectInfo); + if (result.IsSuccess()) { - QMessageBox::critical(this, tr("Failed to configure gems"), tr("Failed to configure gems for template.")); - return; - } + // automatically register the project + PythonBindingsInterface::Get()->AddProject(projectInfo.m_path); + +#ifdef TEMPLATE_GEM_CONFIGURATION_ENABLED + if (!m_gemCatalogScreen->EnableDisableGemsForProject(projectInfo.m_path)) + { + QMessageBox::critical(this, tr("Failed to configure gems"), tr("Failed to configure gems for template.")); + return; + } #endif // TEMPLATE_GEM_CONFIGURATION_ENABLED - projectInfo.m_needsBuild = true; - emit NotifyBuildProject(projectInfo); - emit ChangeScreenRequest(ProjectManagerScreen::Projects); + projectInfo.m_needsBuild = true; + emit NotifyBuildProject(projectInfo); + emit ChangeScreenRequest(ProjectManagerScreen::Projects); + } + else + { + QMessageBox::critical(this, tr("Project creation failed"), tr("Failed to create project.")); + } } else { - QMessageBox::critical(this, tr("Project creation failed"), tr("Failed to create project.")); + QMessageBox::warning( + this, tr("Invalid project settings"), tr("Please correct the indicated project settings and try again.")); } } - else - { - QMessageBox::warning(this, tr("Invalid project settings"), tr("Please correct the indicated project settings and try again.")); - } } void CreateProjectCtrl::ReinitGemCatalogForSelectedTemplate() diff --git a/Code/Tools/ProjectManager/Source/ProjectUtils.cpp b/Code/Tools/ProjectManager/Source/ProjectUtils.cpp index 83e7546670..827973cbec 100644 --- a/Code/Tools/ProjectManager/Source/ProjectUtils.cpp +++ b/Code/Tools/ProjectManager/Source/ProjectUtils.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include namespace O3DE::ProjectManager { @@ -374,46 +376,27 @@ namespace O3DE::ProjectManager return true; } - static bool IsVS2019Installed_internal() + bool FindSupportedCompiler(QWidget* parent) { - QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); - QString programFilesPath = environment.value("ProgramFiles(x86)"); - QString vsWherePath = programFilesPath + "\\Microsoft Visual Studio\\Installer\\vswhere.exe"; + auto findCompilerResult = FindSupportedCompilerForPlatform(); - QFileInfo vsWhereFile(vsWherePath); - if (vsWhereFile.exists() && vsWhereFile.isFile()) + if (!findCompilerResult.IsSuccess()) { - QProcess vsWhereProcess; - vsWhereProcess.setProcessChannelMode(QProcess::MergedChannels); - - vsWhereProcess.start( - vsWherePath, - QStringList{ "-version", "16.0", "-latest", "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", - "-property", "isComplete" }); - - if (!vsWhereProcess.waitForStarted()) - { - return false; - } - - while (vsWhereProcess.waitForReadyRead()) - { - } - - QString vsWhereOutput(vsWhereProcess.readAllStandardOutput()); - if (vsWhereOutput.startsWith("1")) - { - return true; - } + QMessageBox vsWarningMessage(parent); + vsWarningMessage.setIcon(QMessageBox::Warning); + vsWarningMessage.setWindowTitle(QObject::tr("Create Project")); + // Makes link clickable + vsWarningMessage.setTextFormat(Qt::RichText); + vsWarningMessage.setText(findCompilerResult.GetError()); + vsWarningMessage.setStandardButtons(QMessageBox::Close); + + QSpacerItem* horizontalSpacer = new QSpacerItem(600, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + QGridLayout* layout = reinterpret_cast(vsWarningMessage.layout()); + layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); + vsWarningMessage.exec(); } - return false; - } - - bool IsVS2019Installed() - { - static bool vs2019Installed = IsVS2019Installed_internal(); - return vs2019Installed; + return findCompilerResult.IsSuccess(); } ProjectManagerScreen GetProjectManagerScreen(const QString& screen) diff --git a/Code/Tools/ProjectManager/Source/ProjectUtils.h b/Code/Tools/ProjectManager/Source/ProjectUtils.h index 2829a45180..1035ceea65 100644 --- a/Code/Tools/ProjectManager/Source/ProjectUtils.h +++ b/Code/Tools/ProjectManager/Source/ProjectUtils.h @@ -8,6 +8,7 @@ #include #include +#include namespace O3DE::ProjectManager { @@ -23,7 +24,8 @@ namespace O3DE::ProjectManager bool ReplaceFile(const QString& origFile, const QString& newFile, QWidget* parent = nullptr, bool interactive = true); - bool IsVS2019Installed(); + bool FindSupportedCompiler(QWidget* parent = nullptr); + AZ::Outcome FindSupportedCompilerForPlatform(); ProjectManagerScreen GetProjectManagerScreen(const QString& screen); } // namespace ProjectUtils diff --git a/Code/Tools/ProjectManager/Source/ProjectsScreen.cpp b/Code/Tools/ProjectManager/Source/ProjectsScreen.cpp index a31cd8b263..54fdc370d7 100644 --- a/Code/Tools/ProjectManager/Source/ProjectsScreen.cpp +++ b/Code/Tools/ProjectManager/Source/ProjectsScreen.cpp @@ -516,7 +516,7 @@ namespace O3DE::ProjectManager bool ProjectsScreen::StartProjectBuild(const ProjectInfo& projectInfo) { - if (ProjectUtils::IsVS2019Installed()) + if (ProjectUtils::FindSupportedCompiler(this)) { QMessageBox::StandardButton buildProject = QMessageBox::information( this,