GemInfo.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. #include "GemInfo.h"
  9. #include <AzCore/IO/Path/Path.h>
  10. #include <AzCore/Utils/Utils.h>
  11. #include <ProjectUtils.h>
  12. #include <QObject>
  13. namespace O3DE::ProjectManager
  14. {
  15. GemInfo::GemInfo(const QString& name, const QString& creator, const QString& summary, Platforms platforms, bool isAdded)
  16. : m_name(name)
  17. , m_origin(creator)
  18. , m_summary(summary)
  19. , m_platforms(platforms)
  20. , m_isAdded(isAdded)
  21. {
  22. }
  23. bool GemInfo::IsValid() const
  24. {
  25. // remote gems may not have a path because they haven't been downloaded
  26. const bool isValidRemoteGem = (m_gemOrigin == Remote && m_downloadStatus == NotDownloaded);
  27. return !m_name.isEmpty() && (!m_path.isEmpty() || isValidRemoteGem);
  28. }
  29. bool GemInfo::IsCompatible() const
  30. {
  31. const bool hasNoIncompatibleDependencies = m_incompatibleEngineDependencies.isEmpty()
  32. && m_incompatibleGemDependencies.isEmpty();
  33. return m_isEngineGem || hasNoIncompatibleDependencies;
  34. }
  35. QString GemInfo::GetPlatformString(Platform platform)
  36. {
  37. switch (platform)
  38. {
  39. case Android:
  40. return QObject::tr("Android");
  41. case iOS:
  42. return QObject::tr("iOS");
  43. case Linux:
  44. return QObject::tr("Linux");
  45. case macOS:
  46. return QObject::tr("macOS");
  47. case Windows:
  48. return QObject::tr("Windows");
  49. default:
  50. return QObject::tr("<Unknown Platform>");
  51. }
  52. }
  53. QString GemInfo::GetTypeString(Type type)
  54. {
  55. switch (type)
  56. {
  57. case Asset:
  58. return QObject::tr("Asset");
  59. case Code:
  60. return QObject::tr("Code");
  61. case Tool:
  62. return QObject::tr("Tool");
  63. default:
  64. return QObject::tr("<Unknown Type>");
  65. }
  66. }
  67. QString GemInfo::GetGemOriginString(GemOrigin origin)
  68. {
  69. switch (origin)
  70. {
  71. case Open3DEngine:
  72. return QObject::tr("Open 3D Engine");
  73. case Local:
  74. return QObject::tr("Local");
  75. case Remote:
  76. return QObject::tr("Remote");
  77. default:
  78. return QObject::tr("<Unknown Gem Origin>");
  79. }
  80. }
  81. QString GemInfo::GetDownloadStatusString(DownloadStatus status)
  82. {
  83. switch (status)
  84. {
  85. case NotDownloaded:
  86. return QObject::tr("Not Downloaded");
  87. case Downloading:
  88. return QObject::tr("Downloading");
  89. case Downloaded:
  90. return QObject::tr("Downloaded");
  91. case UnknownDownloadStatus:
  92. default:
  93. return QObject::tr("<Unknown Download Status>");
  94. }
  95. };
  96. bool GemInfo::IsPlatformSupported(Platform platform) const
  97. {
  98. return (m_platforms & platform);
  99. }
  100. QString GemInfo::GetNameWithVersionSpecifier(const QString& comparator) const
  101. {
  102. if (m_isEngineGem || m_version.isEmpty() || m_version.contains("unknown", Qt::CaseInsensitive))
  103. {
  104. // The gem should not use a version specifier because it is an engine gem
  105. // or the version is invalid
  106. return m_name;
  107. }
  108. else
  109. {
  110. return QString("%1%2%3").arg(m_name, comparator, m_version);
  111. }
  112. }
  113. bool GemInfo::operator<(const GemInfo& gemInfo) const
  114. {
  115. // Don't use display name for comparison here - do that in whatever model
  116. // or model proxy Qt uses to display the table of gems
  117. // We want to keep gems with the same names together in case the display
  118. // names change, otherwise you can end up with a list that has multiple
  119. // versions of a gem in different orders in the list because the display
  120. // name for that gem was changed
  121. const int compareResult = m_name.compare(gemInfo.m_name, Qt::CaseInsensitive);
  122. if (compareResult == 0)
  123. {
  124. // If the gem names are the same, compare if the version number is less
  125. // If the version is missing or invalid '0.0.0' will be used
  126. return ProjectUtils::VersionCompare(gemInfo.m_version, m_version) < 0;
  127. }
  128. else
  129. {
  130. return compareResult < 0;
  131. }
  132. }
  133. GemInfo::Platforms GemInfo::GetPlatformFromString(const QString& platformText)
  134. {
  135. if(platformText == "Windows")
  136. {
  137. return GemInfo::Platform::Windows;
  138. }
  139. else if(platformText == "Linux")
  140. {
  141. return GemInfo::Platform::Linux;
  142. }
  143. else if(platformText == "Android")
  144. {
  145. return GemInfo::Platform::Android;
  146. }
  147. else if(platformText == "iOS")
  148. {
  149. return GemInfo::Platform::iOS;
  150. }
  151. else if(platformText == "macOS")
  152. {
  153. return GemInfo::Platform::macOS;
  154. }
  155. else
  156. {
  157. return GemInfo::Platforms();
  158. }
  159. }
  160. GemInfo::Platforms GemInfo::GetPlatformsFromStringList(const QStringList& platformStrings)
  161. {
  162. GemInfo::Platforms newPlatforms = GemInfo::Platforms();
  163. for(const QString& platform : platformStrings)
  164. {
  165. newPlatforms |= GetPlatformFromString(platform);
  166. }
  167. return newPlatforms;
  168. }
  169. QStringList GemInfo::GetPlatformsAsStringList() const
  170. {
  171. QStringList platformStrings;
  172. for (int i = 0; i < GemInfo::NumPlatforms; ++i)
  173. {
  174. const GemInfo::Platform platform = static_cast<GemInfo::Platform>(1 << i);
  175. if(m_platforms & platform)
  176. {
  177. platformStrings << GetPlatformString(platform);
  178. }
  179. }
  180. return platformStrings;
  181. }
  182. } // namespace O3DE::ProjectManager