ProjectUtils.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <ScreenDefs.h>
  10. #include <ProjectInfo.h>
  11. #include <ProjectManagerDefs.h>
  12. #if !defined(Q_MOC_RUN)
  13. #include <QWidget>
  14. #include <QMessageBox>
  15. #include <QProcessEnvironment>
  16. #endif
  17. #include <AzCore/Dependency/Dependency.h>
  18. #include <AzCore/IO/Path/Path_fwd.h>
  19. #include <AzCore/Outcome/Outcome.h>
  20. #include <AzCore/std/string/string_view.h>
  21. namespace O3DE::ProjectManager
  22. {
  23. namespace ProjectUtils
  24. {
  25. static constexpr AZStd::string_view EngineJsonFilename = "engine.json";
  26. static constexpr AZStd::string_view ProjectJsonFilename = "project.json";
  27. bool RegisterProject(const QString& path, QWidget* parent = nullptr);
  28. bool UnregisterProject(const QString& path, QWidget* parent = nullptr);
  29. bool CopyProjectDialog(const QString& origPath, ProjectInfo& newProjectInfo, QWidget* parent = nullptr);
  30. bool CopyProject(const QString& origPath, const QString& newPath, QWidget* parent, bool skipRegister = false, bool showProgress = true);
  31. bool DeleteProjectFiles(const QString& path, bool force = false);
  32. bool MoveProject(QString origPath, QString newPath, QWidget* parent, bool skipRegister = false, bool showProgress = true);
  33. bool ReplaceProjectFile(const QString& origFile, const QString& newFile, QWidget* parent = nullptr, bool interactive = true);
  34. bool FindSupportedCompiler(const ProjectInfo& projectInfo, QWidget* parent = nullptr);
  35. AZ::Outcome<QString, QString> FindSupportedCompilerForPlatform(const ProjectInfo& projectInfo);
  36. //! Detect if cmake is installed
  37. //! Does NOT detect if the version of cmake required to run O3DE
  38. //! The cmake exeuctable is only tool suitable for detecting the minimum cmake version
  39. //! required, so it is left up to it to detect the version and error out.
  40. AZ::Outcome<QString, QString> FindSupportedCMake();
  41. //! Detect if Ninja-build.Ninja is installed
  42. //! This is only required if the project is a Script-Only project.
  43. AZ::Outcome<QString, QString> FindSupportedNinja();
  44. ProjectManagerScreen GetProjectManagerScreen(const QString& screen);
  45. /**
  46. * Execute a console command and return the result.
  47. * @param cmd the command
  48. * @param arguments the command argument list
  49. * @param processEnv the environment
  50. * @param commandTimeoutSeconds the amount of time in seconds to let the command run before terminating it
  51. * @return AZ::Outcome with the command result on success
  52. */
  53. AZ::Outcome<QString, QString> ExecuteCommandResult(
  54. const QString& cmd,
  55. const QStringList& arguments,
  56. int commandTimeoutSeconds = ProjectCommandLineTimeoutSeconds);
  57. /**
  58. * Execute a console command, display the progress in a modal dialog and return the result.
  59. * @param cmd the command
  60. * @param arguments the command argument list
  61. * @param processEnv the environment
  62. * @param commandTimeoutSeconds the amount of time in seconds to let the command run before terminating it
  63. * @return AZ::Outcome with the command result on success
  64. */
  65. AZ::Outcome<QString, QString> ExecuteCommandResultModalDialog(
  66. const QString& cmd,
  67. const QStringList& arguments,
  68. const QString& title);
  69. AZ::Outcome<void, QString> SetupCommandLineProcessEnvironment();
  70. AZ::Outcome<QString, QString> GetProjectBuildPath(const QString& projectPath);
  71. AZ::Outcome<void, QString> OpenCMakeGUI(const QString& projectPath);
  72. AZ::Outcome<QString, QString> RunGetPythonScript(const QString& enginePath);
  73. QString GetPythonExecutablePath(const QString& enginePath);
  74. QString GetDefaultProjectPath();
  75. QString GetDefaultTemplatePath();
  76. /**
  77. * Create a desktop shortcut.
  78. * @param filename the name of the desktop shorcut file
  79. * @param target the path to the target to run
  80. * @param arguments the argument list to provide to the target
  81. * @return AZ::Outcome with the command result on success
  82. */
  83. AZ::Outcome<QString, QString> CreateDesktopShortcut(const QString& filename, const QString& targetPath, const QStringList& arguments);
  84. /**
  85. * Lookup the location of an Editor executable executable that can be used with the
  86. * supplied project path
  87. * First the method attempts to locate a build directory with the project path
  88. * via querying the <project-path>/user/Registry/Platform/<platform>/build_path.setreg
  89. * Once that is done a path is formed to locate the Editor executable within the that build
  90. * directory.
  91. * Two paths will checked for the existence of an Editor
  92. * - "<project-build-directory>/bin/$<CONFIG>/Editor"
  93. * - "<project-build-directory>/bin/<platform>/$<CONFIG>/Editor"
  94. * Where <platform> is the current platform the O3DE executable is running on and $<CONFIG> is the
  95. * current build configuration the O3DE executable
  96. *
  97. * If neiether of the above paths contain an Editor application, then a path to the Editor
  98. * is formed by combinding the O3DE executable directory with the filename of Editor
  99. * - "<executable-directory>/Editor"
  100. *
  101. * @param projectPath Path to the root of the project
  102. * @return path of the Editor Executable if found or an empty path if not
  103. */
  104. AZ::IO::FixedMaxPath GetEditorExecutablePath(const AZ::IO::PathView& projectPath);
  105. /**
  106. * Compare two version strings. Invalid version strings will be treated as 0.0.0
  107. * If you need to validate version strings, use AZ::Validate::ParseVersion()
  108. * @param version1 The first version string
  109. * @param version2 The first version string
  110. * @return 0 if a == b, <0 if a < b, and >0 if a > b on success, or failure
  111. */
  112. int VersionCompare(const QString& a, const QString&b);
  113. /**
  114. * Return a human readable dependency
  115. * @param dependency The dependency, e.g. o3de==1.2.3
  116. * @return a human readable string e.g. o3de 1.2.3, or o3de greater than or equal to 2.3.4
  117. */
  118. QString GetDependencyString(const QString& dependency);
  119. using Dependency = AZ::Dependency<AZ::SemanticVersion::parts_count>;
  120. using Comparison = AZ::Dependency<AZ::SemanticVersion::parts_count>::Bound::Comparison;
  121. /**
  122. * Helper to parse a dependency, e.g. o3de==1.2.3 into an object name, comparator version
  123. * @param dependency The dependency, e.g. o3de==1.2.3
  124. * @param objectName The parsed object name, e.g. o3de
  125. * @param comparator The parsed comparator, e.g. ==
  126. * @param version The parsed version, e.g. 1.2.3
  127. */
  128. void GetDependencyNameAndVersion(const QString& dependency, QString& objectName, Comparison& comparator, QString& version);
  129. /**
  130. * Helper to parse a dependency, e.g. o3de==1.2.3 into an object name
  131. * @param dependency The dependency, e.g. o3de==1.2.3
  132. * @return The parsed object name, e.g. o3de
  133. */
  134. QString GetDependencyName(const QString& dependency);
  135. /**
  136. * Display a dialog with general and detailed sections for the given AZ::Outcome
  137. * @param title Dialog title
  138. * @param outcome The AZ::Outcome with general and detailed error messages
  139. * @param parent Optional QWidget parent
  140. * @return the QMessageBox result
  141. */
  142. int DisplayDetailedError(
  143. const QString& title, const AZ::Outcome<void, AZStd::pair<AZStd::string, AZStd::string>>& outcome, QWidget* parent = nullptr);
  144. /**
  145. * Display a dialog with general and detailed sections for the given ErrorPair
  146. * @param title Dialog title
  147. * @param errorPair The general and detailed error messages pair
  148. * @param parent Optional QWidget parent
  149. * @param buttons Optional buttons to show
  150. * @return the QMessageBox result
  151. */
  152. int DisplayDetailedError(
  153. const QString& title,
  154. const AZStd::string& generalError,
  155. const AZStd::string& detailedError,
  156. QWidget* parent = nullptr,
  157. QMessageBox::StandardButtons buttons = QMessageBox::Ok);
  158. } // namespace ProjectUtils
  159. namespace ErrorMessages
  160. {
  161. static const char * ExportCancelled = "Export Cancelled.";
  162. static const char * LogOpenFailureMsg = "Failed to open log file.";
  163. static const char * LogPathFailureMsg = "Failed to retrieve log file path.";
  164. }
  165. } // namespace O3DE::ProjectManager