3
0

AssetStatusReporter.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 <AtomToolsFramework/Graph/AssetStatusReporter.h>
  9. #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
  10. namespace AtomToolsFramework
  11. {
  12. AssetStatusReporter::AssetStatusReporter(const AZStd::vector<AZStd::string>& sourcePaths)
  13. : m_sourcePaths(sourcePaths)
  14. {
  15. }
  16. AssetStatusReporterState AssetStatusReporter::Update()
  17. {
  18. if (GetCurrentState() == AssetStatusReporterState::Processing)
  19. {
  20. const AZStd::string& sourcePath = GetCurrentPath();
  21. AZ::Outcome<AzToolsFramework::AssetSystem::JobInfoContainer> jobOutcome = AZ::Failure();
  22. AzToolsFramework::AssetSystemJobRequestBus::BroadcastResult(
  23. jobOutcome, &AzToolsFramework::AssetSystemJobRequestBus::Events::GetAssetJobsInfo, sourcePath, false);
  24. if (jobOutcome.IsSuccess())
  25. {
  26. for (const auto& job : jobOutcome.GetValue())
  27. {
  28. switch (job.m_status)
  29. {
  30. case AzToolsFramework::AssetSystem::JobStatus::Failed:
  31. case AzToolsFramework::AssetSystem::JobStatus::Failed_InvalidSourceNameExceedsMaxLimit:
  32. // If any of the asset jobs failed then the entire operation is a failure.
  33. m_failed = true;
  34. return GetCurrentState();
  35. }
  36. }
  37. for (const auto& job : jobOutcome.GetValue())
  38. {
  39. switch (job.m_status)
  40. {
  41. case AzToolsFramework::AssetSystem::JobStatus::Queued:
  42. case AzToolsFramework::AssetSystem::JobStatus::InProgress:
  43. // If any of the asset jobs are queued or in progress then return early until the next status request.
  44. return GetCurrentState();
  45. }
  46. }
  47. }
  48. ++m_index;
  49. }
  50. return GetCurrentState();
  51. }
  52. AssetStatusReporterState AssetStatusReporter::GetCurrentState() const
  53. {
  54. if (m_failed)
  55. {
  56. return AssetStatusReporterState::Failed;
  57. }
  58. return m_index < m_sourcePaths.size() ? AssetStatusReporterState::Processing : AssetStatusReporterState::Succeeded;
  59. }
  60. AZStd::string AssetStatusReporter::GetCurrentStateName() const
  61. {
  62. switch (GetCurrentState())
  63. {
  64. case AssetStatusReporterState::Failed:
  65. return "Failed";
  66. case AssetStatusReporterState::Processing:
  67. return "Processing";
  68. case AssetStatusReporterState::Succeeded:
  69. return "Succeeded";
  70. }
  71. return "Invalid";
  72. }
  73. AZStd::string AssetStatusReporter::GetCurrentStatusMessage() const
  74. {
  75. return AZStd::string::format("%s (%s)", GetCurrentPath().c_str(), GetCurrentStateName().c_str());
  76. }
  77. AZStd::string AssetStatusReporter::GetCurrentPath() const
  78. {
  79. return m_index < m_sourcePaths.size() ? m_sourcePaths[m_index] : AZStd::string();
  80. }
  81. } // namespace AtomToolsFramework