ProjectUtils.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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(QWidget* parent = nullptr);
  35. AZ::Outcome<QString, QString> FindSupportedCompilerForPlatform();
  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. ProjectManagerScreen GetProjectManagerScreen(const QString& screen);
  42. /**
  43. * Execute a console command and return the result.
  44. * @param cmd the command
  45. * @param arguments the command argument list
  46. * @param processEnv the environment
  47. * @param commandTimeoutSeconds the amount of time in seconds to let the command run before terminating it
  48. * @return AZ::Outcome with the command result on success
  49. */
  50. AZ::Outcome<QString, QString> ExecuteCommandResult(
  51. const QString& cmd,
  52. const QStringList& arguments,
  53. int commandTimeoutSeconds = ProjectCommandLineTimeoutSeconds);
  54. /**
  55. * Execute a console command, display the progress in a modal dialog and return the result.
  56. * @param cmd the command
  57. * @param arguments the command argument list
  58. * @param processEnv the environment
  59. * @param commandTimeoutSeconds the amount of time in seconds to let the command run before terminating it
  60. * @return AZ::Outcome with the command result on success
  61. */
  62. AZ::Outcome<QString, QString> ExecuteCommandResultModalDialog(
  63. const QString& cmd,
  64. const QStringList& arguments,
  65. const QString& title);
  66. AZ::Outcome<void, QString> SetupCommandLineProcessEnvironment();
  67. AZ::Outcome<QString, QString> GetProjectBuildPath(const QString& projectPath);
  68. AZ::Outcome<void, QString> OpenCMakeGUI(const QString& projectPath);
  69. AZ::Outcome<QString, QString> RunGetPythonScript(const QString& enginePath);
  70. QString GetPythonExecutablePath(const QString& enginePath);
  71. QString GetDefaultProjectPath();
  72. QString GetDefaultTemplatePath();
  73. /**
  74. * Create a desktop shortcut.
  75. * @param filename the name of the desktop shorcut file
  76. * @param target the path to the target to run
  77. * @param arguments the argument list to provide to the target
  78. * @return AZ::Outcome with the command result on success
  79. */
  80. AZ::Outcome<QString, QString> CreateDesktopShortcut(const QString& filename, const QString& targetPath, const QStringList& arguments);
  81. /**
  82. * Lookup the location of an Editor executable executable that can be used with the
  83. * supplied project path
  84. * First the method attempts to locate a build directory with the project path
  85. * via querying the <project-path>/user/Registry/Platform/<platform>/build_path.setreg
  86. * Once that is done a path is formed to locate the Editor executable within the that build
  87. * directory.
  88. * Two paths will checked for the existence of an Editor
  89. * - "<project-build-directory>/bin/$<CONFIG>/Editor"
  90. * - "<project-build-directory>/bin/<platform>/$<CONFIG>/Editor"
  91. * Where <platform> is the current platform the O3DE executable is running on and $<CONFIG> is the
  92. * current build configuration the O3DE executable
  93. *
  94. * If neiether of the above paths contain an Editor application, then a path to the Editor
  95. * is formed by combinding the O3DE executable directory with the filename of Editor
  96. * - "<executable-directory>/Editor"
  97. *
  98. * @param projectPath Path to the root of the project
  99. * @return path of the Editor Executable if found or an empty path if not
  100. */
  101. AZ::IO::FixedMaxPath GetEditorExecutablePath(const AZ::IO::PathView& projectPath);
  102. /**
  103. * Compare two version strings. Invalid version strings will be treated as 0.0.0
  104. * If you need to validate version strings, use AZ::Validate::ParseVersion()
  105. * @param version1 The first version string
  106. * @param version2 The first version string
  107. * @return 0 if a == b, <0 if a < b, and >0 if a > b on success, or failure
  108. */
  109. int VersionCompare(const QString& a, const QString&b);
  110. /**
  111. * Return a human readable dependency
  112. * @param dependency The dependency, e.g. o3de==1.2.3
  113. * @return a human readable string e.g. o3de 1.2.3, or o3de greater than or equal to 2.3.4
  114. */
  115. QString GetDependencyString(const QString& dependency);
  116. using Dependency = AZ::Dependency<AZ::SemanticVersion::parts_count>;
  117. using Comparison = AZ::Dependency<AZ::SemanticVersion::parts_count>::Bound::Comparison;
  118. /**
  119. * Helper to parse a dependency, e.g. o3de==1.2.3 into an object name, comparator version
  120. * @param dependency The dependency, e.g. o3de==1.2.3
  121. * @param objectName The parsed object name, e.g. o3de
  122. * @param comparator The parsed comparator, e.g. ==
  123. * @param version The parsed version, e.g. 1.2.3
  124. */
  125. void GetDependencyNameAndVersion(const QString& dependency, QString& objectName, Comparison& comparator, QString& version);
  126. /**
  127. * Helper to parse a dependency, e.g. o3de==1.2.3 into an object name
  128. * @param dependency The dependency, e.g. o3de==1.2.3
  129. * @return The parsed object name, e.g. o3de
  130. */
  131. QString GetDependencyName(const QString& dependency);
  132. /**
  133. * Display a dialog with general and detailed sections for the given AZ::Outcome
  134. * @param title Dialog title
  135. * @param outcome The AZ::Outcome with general and detailed error messages
  136. * @param parent Optional QWidget parent
  137. * @return the QMessageBox result
  138. */
  139. int DisplayDetailedError(
  140. const QString& title, const AZ::Outcome<void, AZStd::pair<AZStd::string, AZStd::string>>& outcome, QWidget* parent = nullptr);
  141. /**
  142. * Display a dialog with general and detailed sections for the given ErrorPair
  143. * @param title Dialog title
  144. * @param errorPair The general and detailed error messages pair
  145. * @param parent Optional QWidget parent
  146. * @param buttons Optional buttons to show
  147. * @return the QMessageBox result
  148. */
  149. int DisplayDetailedError(
  150. const QString& title,
  151. const AZStd::string& generalError,
  152. const AZStd::string& detailedError,
  153. QWidget* parent = nullptr,
  154. QMessageBox::StandardButtons buttons = QMessageBox::Ok);
  155. } // namespace ProjectUtils
  156. } // namespace O3DE::ProjectManager