ProductAssetTreeItemData.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "ProductAssetTreeItemData.h"
  9. #include "native/utilities/assetUtils.h"
  10. #include <AzCore/std/smart_ptr/make_shared.h>
  11. #include <QDir>
  12. #include <QStack>
  13. namespace AssetProcessor
  14. {
  15. AZStd::shared_ptr<ProductAssetTreeItemData> ProductAssetTreeItemData::MakeShared(
  16. const AzToolsFramework::AssetDatabase::ProductDatabaseEntry* databaseInfo,
  17. const AZStd::string& assetDbName,
  18. QString name,
  19. bool isFolder,
  20. const AZ::Uuid& uuid,
  21. const AZ::s64 scanFolderID)
  22. {
  23. return AZStd::make_shared<ProductAssetTreeItemData>(databaseInfo, assetDbName, name, isFolder, uuid, scanFolderID);
  24. }
  25. ProductAssetTreeItemData::ProductAssetTreeItemData(
  26. const AzToolsFramework::AssetDatabase::ProductDatabaseEntry* databaseInfo,
  27. const AZStd::string& assetDbName,
  28. QString name,
  29. bool isFolder,
  30. const AZ::Uuid& uuid,
  31. const AZ::s64 scanFolderID)
  32. :
  33. AssetTreeItemData(assetDbName, name, isFolder, uuid, scanFolderID)
  34. {
  35. if (databaseInfo)
  36. {
  37. m_hasDatabaseInfo = true;
  38. m_databaseInfo = *databaseInfo;
  39. }
  40. else
  41. {
  42. m_hasDatabaseInfo = false;
  43. }
  44. }
  45. AZ::Outcome<QString> GetAbsolutePathToProduct(const AssetTreeItem& product)
  46. {
  47. QDir cacheRootDir;
  48. if (!AssetUtilities::ComputeProjectCacheRoot(cacheRootDir))
  49. {
  50. return AZ::Failure();
  51. }
  52. QString pathOnDisk;
  53. if (product.getChildCount() > 0)
  54. {
  55. // Folders are special case, they only exist in the interface and don't exist in the asset database.
  56. // Figure out the path to the folder by creating a stack of each folder in its hierarchy.
  57. QStack<QString> folderStack;
  58. for (const AssetTreeItem* folderHierarchy = &product; folderHierarchy != nullptr; folderHierarchy = folderHierarchy->GetParent())
  59. {
  60. folderStack.push(folderHierarchy->GetData()->m_name);
  61. }
  62. while (!folderStack.empty())
  63. {
  64. cacheRootDir.cd(folderStack.pop());
  65. }
  66. pathOnDisk = cacheRootDir.absolutePath();
  67. }
  68. else
  69. {
  70. const AZStd::shared_ptr<const ProductAssetTreeItemData> productItemData = AZStd::rtti_pointer_cast<const ProductAssetTreeItemData>(product.GetData());
  71. if (!productItemData)
  72. {
  73. return AZ::Failure();
  74. }
  75. pathOnDisk = cacheRootDir.filePath(productItemData->m_databaseInfo.m_productName.c_str());
  76. }
  77. return AZ::Success(pathOnDisk);
  78. }
  79. }