123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <native/AssetManager/SourceAssetReference.h>
- namespace AssetProcessor
- {
- SourceAssetReference::SourceAssetReference(AZ::IO::PathView absolutePath)
- {
- IPathConversion* pathConversion = AZ::Interface<IPathConversion>::Get();
- AZ_Assert(pathConversion, "IPathConversion interface is not available");
- if(absolutePath.empty())
- {
- return;
- }
- QString relativePath, scanFolderPath;
- if(!pathConversion->ConvertToRelativePath(absolutePath.FixedMaxPathStringAsPosix().c_str(), relativePath, scanFolderPath))
- {
- return;
- }
- auto* scanFolderInfo = pathConversion->GetScanFolderForFile(scanFolderPath);
- if(!scanFolderInfo)
- {
- return;
- }
- m_scanFolderPath = scanFolderPath.toUtf8().constData();
- m_relativePath = relativePath.toUtf8().constData();
- m_absolutePath = absolutePath;
- m_scanFolderId = scanFolderInfo->ScanFolderID();
- Normalize();
- }
- SourceAssetReference::SourceAssetReference(AZ::s64 scanFolderId, AZ::IO::PathView pathRelativeToScanFolder)
- {
- IPathConversion* pathConversion = AZ::Interface<IPathConversion>::Get();
- AZ_Assert(pathConversion, "IPathConversion interface is not available");
- auto* scanFolder = pathConversion->GetScanFolderById(scanFolderId);
- if(!scanFolder)
- {
- return;
- }
- AZ::IO::Path scanFolderPath = scanFolder->ScanPath().toUtf8().constData();
- if(scanFolderPath.empty() || pathRelativeToScanFolder.empty())
- {
- return;
- }
- auto* scanFolderInfo = pathConversion->GetScanFolderForFile(scanFolderPath.FixedMaxPathStringAsPosix().c_str());
- if(!scanFolderInfo)
- {
- return;
- }
- m_scanFolderPath = scanFolderPath;
- m_relativePath = pathRelativeToScanFolder;
- m_absolutePath = m_scanFolderPath / m_relativePath;
- m_scanFolderId = scanFolderInfo->ScanFolderID();
- Normalize();
- }
- SourceAssetReference::SourceAssetReference(AZ::IO::PathView scanFolderPath, AZ::IO::PathView pathRelativeToScanFolder)
- {
- IPathConversion* pathConversion = AZ::Interface<IPathConversion>::Get();
- AZ_Assert(pathConversion, "IPathConversion interface is not available");
- if(scanFolderPath.empty() || pathRelativeToScanFolder.empty())
- {
- return;
- }
- auto* scanFolderInfo = pathConversion->GetScanFolderForFile(scanFolderPath.FixedMaxPathStringAsPosix().c_str());
- if(!scanFolderInfo)
- {
- return;
- }
- m_scanFolderPath = scanFolderPath;
- m_relativePath = pathRelativeToScanFolder;
- m_absolutePath = m_scanFolderPath / m_relativePath;
- m_scanFolderId = scanFolderInfo->ScanFolderID();
- Normalize();
- }
- SourceAssetReference::SourceAssetReference(
- AZ::s64 scanFolderId, AZ::IO::PathView scanFolderPath, AZ::IO::PathView pathRelativeToScanFolder)
- {
- if (scanFolderPath.empty() || pathRelativeToScanFolder.empty())
- {
- return;
- }
- m_scanFolderPath = scanFolderPath;
- m_relativePath = pathRelativeToScanFolder;
- m_absolutePath = m_scanFolderPath / m_relativePath;
- m_scanFolderId = scanFolderId;
- Normalize();
- }
- bool SourceAssetReference::operator==(const SourceAssetReference& other) const
- {
- return m_absolutePath == other.m_absolutePath;
- }
- bool SourceAssetReference::operator!=(const SourceAssetReference& other) const
- {
- return !operator==(other);
- }
- bool SourceAssetReference::operator<(const SourceAssetReference& other) const
- {
- return m_absolutePath < other.m_absolutePath;
- }
- bool SourceAssetReference::operator>(const SourceAssetReference& other) const
- {
- return m_absolutePath > other.m_absolutePath;
- }
- SourceAssetReference::operator bool() const
- {
- return IsValid();
- }
- bool SourceAssetReference::IsValid() const
- {
- return !m_absolutePath.empty();
- }
- AZ::IO::FixedMaxPath SourceAssetReference::AbsolutePath() const
- {
- return AZ::IO::FixedMaxPath(m_absolutePath);
- }
- AZ::IO::FixedMaxPath SourceAssetReference::RelativePath() const
- {
- return AZ::IO::FixedMaxPath(m_relativePath);
- }
- AZ::IO::FixedMaxPath SourceAssetReference::ScanFolderPath() const
- {
- return AZ::IO::FixedMaxPath(m_scanFolderPath);
- }
- AZ::s64 SourceAssetReference::ScanFolderId() const
- {
- return m_scanFolderId;
- }
- void SourceAssetReference::Normalize()
- {
- m_scanFolderPath = m_scanFolderPath.LexicallyNormal().AsPosix();
- m_relativePath = m_relativePath.LexicallyNormal().AsPosix();
- m_absolutePath = m_absolutePath.LexicallyNormal().AsPosix();
- }
- }
- AZStd::hash<AssetProcessor::SourceAssetReference>::result_type AZStd::hash<AssetProcessor::SourceAssetReference>::operator()(const argument_type& obj) const
- {
- size_t h = 0;
- hash_combine(h, obj.AbsolutePath());
- return h;
- }
|