ProjectUtils.h 8.1 KB

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