/* * 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 #include #include #include #include #include #include namespace AzFramework { GemInfo::GemInfo(AZStd::string name) : m_gemName(AZStd::move(name)) { } bool GetGemsInfo(AZStd::vector& gemInfoList, AZ::SettingsRegistryInterface& settingsRegistry) { AZStd::vector gemModuleSourcePaths; struct GemSourcePathsVisitor : AZ::SettingsRegistryInterface::Visitor { GemSourcePathsVisitor(AZ::SettingsRegistryInterface& settingsRegistry, AZStd::vector& gemInfoList) : m_settingsRegistry(settingsRegistry) , m_gemInfoList(gemInfoList) { } void Visit(AZStd::string_view path, AZStd::string_view, AZ::SettingsRegistryInterface::Type, AZStd::string_view value) override { AZStd::string_view jsonPointerPath{ path }; // Remove the array index from the path and check if the JSON path ends with "/SourcePaths" AZ::StringFunc::TokenizeLast(jsonPointerPath, '/'); if (jsonPointerPath.ends_with("/SourcePaths")) { AZStd::string_view gemName; // The parent key of the "SourcePaths" field is the gem name AZ::StringFunc::TokenizeLast(jsonPointerPath, '/'); // Peel off "/SourcePaths" // Retrieve Gem name if (auto gemNameToken = AZ::StringFunc::TokenizeLast(jsonPointerPath, '/'); gemNameToken.has_value()) { gemName = *gemNameToken; } auto FindGemInfoByName = [gemName](const GemInfo& gemInfo) { return gemName == gemInfo.m_gemName; }; auto gemInfoFoundIter = AZStd::find_if(m_gemInfoList.begin(), m_gemInfoList.end(), FindGemInfoByName); GemInfo& gemInfo = gemInfoFoundIter != m_gemInfoList.end() ? *gemInfoFoundIter : m_gemInfoList.emplace_back(gemName); AZ::IO::Path& gemAbsPath = gemInfo.m_absoluteSourcePaths.emplace_back(value); // Resolve any file aliases first - Do not use ResolvePath() as that assumes // any relative path is underneath the @assets@ alias if (auto fileIoBase = AZ::IO::FileIOBase::GetInstance(); fileIoBase != nullptr) { AZ::IO::FixedMaxPath replacedAliasPath; if (fileIoBase->ReplaceAlias(replacedAliasPath, value)) { gemAbsPath = AZ::IO::PathView(replacedAliasPath); } } // The current assumption is that the gem source path is the relative to the engine root AZ::IO::FixedMaxPath engineRootPath; m_settingsRegistry.Get(engineRootPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder); gemAbsPath = (engineRootPath / gemAbsPath).LexicallyNormal(); } } AZ::SettingsRegistryInterface& m_settingsRegistry; AZStd::vector& m_gemInfoList; }; GemSourcePathsVisitor visitor{ settingsRegistry, gemInfoList }; constexpr auto gemListKey = AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::OrganizationRootKey) + "/Gems"; settingsRegistry.Visit(visitor, gemListKey); return true; } }