Files
o3de/Gems/AssetValidation/Code/Source/AssetValidationSystemComponent.cpp
T
lumberyard-employee-dm f648cb1fd8 Update the FileIO Aliases (#4186)
* Update the FileIOAlias naming to make the cache, project root and engine
root paths more clear

The alias of `@root@`, `@assets@`, and `@projectplatformcache@` has been
collapsed to `@projectproductassets@`

The alias of `@devroot@` and `@engroot@` has been collapsed to
`@engroot@`

The alias of `@devassets@` and `@projectroot@` has been collapsed to
`@projectroot@`

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated use of devassets and devroot properties in python

Those properties now use projectroot and engroot

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updating the alias @engroot@ alias path comment in each platform specific LocalFileIO_*.cpp file

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Removed hardcoded size of 9 for the product asset alias.

The ResolvePath function now just appends the @projectproductassets@
alias with the input path

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Remove duplicate @projectproductassets@ check in ProcessFileTreeRequest

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fix for typos in Hydra python test

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated LocalFileIO::Copy call on Windows to use the Unicode aware CopyFileW API

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the AWSMetreicsGemAllocatorFixture to properly suppress asset
cache write errors for Test file creation.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Removed unneeded call to set the @projectproductasstes@ alias at the bottom of the AssetSeedManagerTest SetUp

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Added a deprecated alias map to the FileIO System

When a deprecated alias is accessed, the FileIO System logs an AZ_Error and indicates the alias that should be used

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated python test scripts to use the projectroot binding

Retrieving the AutomatedTesting project path based on "<devroot>/AutomatedTesting" has been removed.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated references to devroot and devgame within the codebase

The GetAbsoluteDevGameFolderPath functions has been replaced with direct call to AZ::Utils::GetProjectPath
The GetAbsoluteDevRootFolderPath functions has been replaced with direct calls to AZ::Utils::GetEnginePath

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated <engroot>/AutomatedTesting references to projectroot


Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Replaced references that assumes the project path is <engroot>/AutomatedTesting with <projectroot> in the AutomatedTesting python test

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Correct casing in emfxworkspace file


Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Removed newly added AppendPathParts function
Removed the Path constructors which accepts a PathIterable instance

The PathIterable isn't safe to return to a user of the Path class as it might be referencing temporary paths supplied via PathView arguments

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed unused parameter warning

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Undid change to the LexicallyProximate function to set the path result to the base path.

It needs to return the *this path if the pathResult is empty

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Moved the LocalFileIO ConvertToAbsolutePath implementations to AZ::Utils

Fixed the ConvertToAbsolutePath implementation for Unix platforms to use a buffer that is size PATH_MAX(4096 on all our supported Unix platforms).
Because the buffer before was AZ::IO::MaxPathLength which as a size of 1024, this was resulting in the Unix `realpath` function smashing the stack when it converts a path to an absolute path that is longer than 1024 characters

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the EditorCore.Tests to attach the AZ Environment to the EditorCore shared library that is statically loaded on launch.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed for DeprecatedAlaisesKeyVisitor Visit function causing the non string_view overloads being hidden causing a hidden base class function warning

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Changed the AWSMetricsGemMock to use a temporary for writing test assets

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the LocalFileIO::ResolvePath function to use HasRootPath to determine if a path starts with a root path such as "D:", "D:/" or "/"

IsAbsolute was not the corect check as the path of "D:" is a relative
path.
To be absolute according to the Windows the path must have a root
directory. i.e "D:/" or "D:\"

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Removed absolute path comment from LocalFile_UnixLike.cpp and LocalFile_Android.cpp FindFiles implementations
Updated the ConvertToAlias to supply an AZ::IO::FixedMaxPath

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Replaced usage of the @projectproductassets@ alias with @engroot@ when referring to the LmbrCentral source folder in the CopyDependencyBuilderTest and the SeedBuilderTests

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the ScriptCanvas Upgrade Tool to output backed up files to the
Project User Path instead of the engine root

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed whitespacing issues in Application.cpp

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Remove unnecessary creation of a FixedMaxPath in the UpgradeTool.cpp

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Modified testSeedFolder variable in the SeedBuilderTests to use the
@engroot@ alias instead of @projectproductassets@/.. alias when
referring to the LmbrCentral Gem source path

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated references to the Project Asset Cache in the PythonTests.

Those tests no longer use the logic `azlmbr.paths.projectroot / "Cache" / "pc"` to retrieve a path to the cache root but instead the `azlmbr.paths.projectproductassets` constant

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed the FileIO Deprecated Alias test on Windows

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Removing @projectsourceassets@ alias, as it is only used once.

Updated the PhysX EditorSystemComponent.cpp to query the ProjectPath
form the SettingsRegistry.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Replaced @projectproductassets@ alias with @products@

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Rollback changes to the PhysX EditorSystemComponent.cpp

The changes to use the ProjectPath from the SettingsRegistry has been implemented in PR #4497

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
2021-10-05 15:12:53 -05:00

594 lines
22 KiB
C++

/*
* 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 <AssetValidationSystemComponent.h>
#include <AzCore/Asset/AssetManager.h>
#include <AzCore/Asset/AssetManagerBus.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/EditContextConstants.inl>
#include <AzCore/Serialization/Utils.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/std/string/conversions.h>
#include <AzFramework/API/ApplicationAPI.h>
#include <AzFramework/FileTag/FileTag.h>
#include <AzFramework/FileTag/FileTagBus.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <AssetSeedUtil.h>
#include <ISystem.h>
#include <IConsole.h>
namespace AssetValidation
{
void AssetValidationSystemComponent::Reflect(AZ::ReflectContext* context)
{
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<AssetValidationSystemComponent, AZ::Component>()
->Version(0);
if (AZ::EditContext* ec = serialize->GetEditContext())
{
ec->Class<AssetValidationSystemComponent>("AssetValidation", "[Description of functionality provided by this System Component]")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
;
}
}
}
void AssetValidationSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("AssetValidationService"));
}
void AssetValidationSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC("AssetValidationService"));
}
void AssetValidationSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
AZ_UNUSED(required);
}
void AssetValidationSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
{
AZ_UNUSED(dependent);
}
void AssetValidationSystemComponent::Init()
{
}
void AssetValidationSystemComponent::Activate()
{
CrySystemEventBus::Handler::BusConnect();
AssetValidationRequestBus::Handler::BusConnect();
}
void AssetValidationSystemComponent::Deactivate()
{
if (m_seedMode)
{
AZ::IO::ArchiveNotificationBus::Handler::BusDisconnect();
}
AssetValidationRequestBus::Handler::BusDisconnect();
CrySystemEventBus::Handler::BusDisconnect();
}
void AssetValidationSystemComponent::ConsoleCommandSeedMode([[maybe_unused]] IConsoleCmdArgs* pCmdArgs)
{
AssetValidationRequestBus::Broadcast(&AssetValidationRequestBus::Events::SeedMode);
}
void AssetValidationSystemComponent::ConsoleCommandTogglePrintExcluded([[maybe_unused]] IConsoleCmdArgs* pCmdArgs)
{
AssetValidationRequestBus::Broadcast(&AssetValidationRequestBus::Events::TogglePrintExcluded);
}
void AssetValidationSystemComponent::TogglePrintExcluded()
{
m_printExcluded = !m_printExcluded;
if (m_printExcluded)
{
AZ_TracePrintf("AssetValidation", "Asset Validation is now on");
}
else
{
AZ_TracePrintf("AssetValidation", "Asset Validation is now off");
}
}
void AssetValidationSystemComponent::SeedMode()
{
m_seedMode = !m_seedMode;
if (m_seedMode)
{
// adding excluded tags
m_excludedFileTags.emplace_back(AzFramework::FileTag::FileTags[static_cast<unsigned int>(AzFramework::FileTag::FileTagsIndex::Ignore)]);
m_excludedFileTags.emplace_back(AzFramework::FileTag::FileTags[static_cast<unsigned int>(AzFramework::FileTag::FileTagsIndex::ProductDependency)]);
AZ::IO::ArchiveNotificationBus::Handler::BusConnect();
BuildAssetList();
AZ_TracePrintf("AssetValidation", "Asset Validation is now on");
}
else
{
AZ::IO::ArchiveNotificationBus::Handler::BusDisconnect();
m_excludedFileTags.clear();
AZ_TracePrintf("AssetValidation", "Asset Validation is now off");
}
AssetValidationNotificationBus::Broadcast(&AssetValidationNotificationBus::Events::SetSeedMode, m_seedMode);
}
void AssetValidationSystemComponent::OnCrySystemInitialized(ISystem& system, const SSystemInitParams& systemInitParams)
{
AZ_UNUSED(systemInitParams);
system.GetIConsole()->AddCommand("seedmode", ConsoleCommandSeedMode);
system.GetIConsole()->AddCommand("addseedpath", ConsoleCommandAddSeedPath);
system.GetIConsole()->AddCommand("removeseedpath", ConsoleCommandRemoveSeedPath);
system.GetIConsole()->AddCommand("listknownassets", ConsoleCommandKnownAssets);
system.GetIConsole()->AddCommand("addseedlist", ConsoleCommandAddSeedList);
system.GetIConsole()->AddCommand("removeseedlist", ConsoleCommandRemoveSeedList);
system.GetIConsole()->AddCommand("printexcluded", ConsoleCommandTogglePrintExcluded);
}
bool AssetValidationSystemComponent::IsKnownAsset(const char* assetPath)
{
AZStd::string lowerAsset{ assetPath };
AZStd::replace(lowerAsset.begin(), lowerAsset.end(), AZ_WRONG_DATABASE_SEPARATOR, AZ_CORRECT_DATABASE_SEPARATOR);
const AZStd::vector<AZStd::string> prefixes = { "./", "@products@/" };
for (const AZStd::string& prefix : prefixes)
{
if (lowerAsset.starts_with(prefix))
{
lowerAsset = lowerAsset.substr(prefix.length());
break;
}
}
AZStd::to_lower(lowerAsset.begin(), lowerAsset.end());
return m_knownAssetPaths.count(lowerAsset) > 0;
}
bool AssetValidationSystemComponent::CheckKnownAsset(const char* assetPath)
{
if (!IsKnownAsset(assetPath))
{
using namespace AzFramework::FileTag;
bool shouldIgnore = false;
QueryFileTagsEventBus::EventResult(shouldIgnore, FileTagType::Exclude, &QueryFileTagsEventBus::Events::Match, assetPath, m_excludedFileTags);
if (shouldIgnore)
{
if (m_printExcluded)
{
AZ_TracePrintf("AssetValidation", "Asset ( %s ) is excluded. \n", assetPath);
}
return true;
}
AZ_Warning("AssetValidation", false, "Asset not found in seed graph: %s", assetPath);
AssetValidationNotificationBus::Broadcast(&AssetValidationNotificationBus::Events::UnknownAsset, assetPath);
return false;
}
return true;
}
void AssetValidationSystemComponent::FileAccess(const char* assetPath)
{
CheckKnownAsset(assetPath);
}
void AssetValidationSystemComponent::AddKnownAssets(AZ::Data::AssetId assetId)
{
AZ::Data::AssetInfo baseAssetInfo;
AZ::Data::AssetCatalogRequestBus::BroadcastResult(baseAssetInfo, &AZ::Data::AssetCatalogRequests::GetAssetInfoById, assetId);
m_knownAssetPaths.insert(baseAssetInfo.m_relativePath);
AZ::Outcome<AZStd::vector<AZ::Data::ProductDependency>, AZStd::string> getDependenciesResult = AZ::Failure(AZStd::string());
AZ::Data::AssetCatalogRequestBus::BroadcastResult(getDependenciesResult, &AZ::Data::AssetCatalogRequestBus::Events::GetAllProductDependencies, assetId);
if (getDependenciesResult.IsSuccess())
{
AZStd::vector<AZ::Data::ProductDependency> entries = getDependenciesResult.TakeValue();
for (const AZ::Data::ProductDependency& productDependency : entries)
{
if (m_knownAssetIds.insert(productDependency.m_assetId).second)
{
AZ::Data::AssetInfo thisAssetInfo;
AZ::Data::AssetCatalogRequestBus::BroadcastResult(thisAssetInfo, &AZ::Data::AssetCatalogRequests::GetAssetInfoById, productDependency.m_assetId);
if (!thisAssetInfo.m_relativePath.empty())
{
m_knownAssetPaths.insert(thisAssetInfo.m_relativePath);
}
}
}
}
}
void AssetValidationSystemComponent::ListKnownAssets()
{
AZ_TracePrintf("AssetValidation", "Seed Asset ids:");
for (const auto& thisIdPair : m_seedAssetIds)
{
AZ::Data::AssetInfo thisAssetInfo;
AZ::Data::AssetCatalogRequestBus::BroadcastResult(thisAssetInfo, &AZ::Data::AssetCatalogRequests::GetAssetInfoById, thisIdPair.first);
AZ_TracePrintf("AssetValidation", "%s - (%s)", thisAssetInfo.m_relativePath.c_str(), thisIdPair.first.ToString<AZStd::string>().c_str());
}
AZ_TracePrintf("AssetValidation", "Known Paths:");
for (const auto& thisPath : m_knownAssetPaths)
{
AZ::Data::AssetId thisAssetId;
AZ::Data::AssetCatalogRequestBus::BroadcastResult(thisAssetId, &AZ::Data::AssetCatalogRequests::GetAssetIdByPath, thisPath.c_str(), AZ::Data::s_invalidAssetType, false);
AZ_TracePrintf("AssetValidation", "%s - (%s)", thisPath.c_str(), thisAssetId.ToString<AZStd::string>().c_str());
}
}
void AssetValidationSystemComponent::BuildAssetList()
{
m_knownAssetIds.clear();
m_knownAssetPaths.clear();
for (const auto& thisAsset : m_seedAssetIds)
{
AddKnownAssets(thisAsset.first);
}
for (const auto& thisPath : m_seedLists)
{
AzFramework::AssetSeedList seedList;
if (!AZ::Utils::LoadObjectFromFileInPlace(thisPath, seedList))
{
AZ_Warning("AssetValidation", false, "Failed to load seed list %s", thisPath.c_str());
continue;
}
AddSeedsFor(seedList, AZ_CRC(thisPath.c_str()));
}
}
bool AssetValidationSystemComponent::AddSeedPath(const char* seedPath)
{
AZ::Data::AssetId assetId;
const bool AutoRegister{ false };
AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetId, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetIdByPath, seedPath, AZ::Data::s_invalidAssetType, AutoRegister);
if (!assetId.IsValid())
{
AZ_Warning("AssetValidation", false, "Can't find an asset %s", seedPath);
return false;
}
return AddSeedAssetId(assetId, 0);
}
bool AssetValidationSystemComponent::AddSeedAssetId(AZ::Data::AssetId assetId, AZ::u32 sourceId)
{
auto curEntry = m_seedAssetIds.find(assetId);
if (curEntry != m_seedAssetIds.end() && curEntry->second.count(sourceId) > 0)
{
AZ_Warning("AssetValidation", false, "AssetID %s from source %d is already added", assetId.ToString< AZStd::string>().c_str(), sourceId);
return false;
}
m_seedAssetIds[assetId].insert(sourceId);
AddKnownAssets(assetId);
AZ_TracePrintf("AssetValidation", "Added assedId %s from source %d", assetId.ToString< AZStd::string>().c_str(), sourceId);
return true;
}
bool AssetValidationSystemComponent::RemoveSeedPath(const char* seedPath)
{
AZ::Data::AssetId assetId;
const bool AutoRegister{ false };
AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetId, &AZ::Data::AssetCatalogRequestBus::Events::GetAssetIdByPath, seedPath, AZ::Data::s_invalidAssetType, AutoRegister);
if (!assetId.IsValid())
{
AZ_Warning("AssetValidation", false, "Can't find an asset %s", seedPath);
return false;
}
return RemoveSeedAssetId(assetId, 0);
}
bool AssetValidationSystemComponent::RemoveSeedAssetId(AZ::Data::AssetId assetId, AZ::u32 sourceId)
{
int removeResult = RemoveSeedAssetIdBySource(assetId, sourceId);
if (removeResult == -1)
{
// invalid remove request
return false;
}
else if(removeResult == 0)
{
// Success and it was the last entry of that assetId, we need to rebuild
BuildAssetList();
}
return true;
}
bool AssetValidationSystemComponent::RemoveSeedAssetIdList(AssetSourceList assetList)
{
bool needRebuild{ false };
for (auto& thisPair : assetList)
{
if (RemoveSeedAssetIdBySource(thisPair.first, thisPair.second) == 0)
{
needRebuild = true;
}
}
if (needRebuild)
{
BuildAssetList();
}
return true;
}
int AssetValidationSystemComponent::RemoveSeedAssetIdBySource(const AZ::Data::AssetId& assetId, AZ::u32 sourceId)
{
auto curEntry = m_seedAssetIds.find(assetId);
if (curEntry == m_seedAssetIds.end() || !curEntry->second.erase(sourceId))
{
AZ_Warning("AssetValidation", false, "AssetID %s from source %d is not in the seed assets list", assetId.ToString< AZStd::string>().c_str(), sourceId);
return -1;
}
if (!curEntry->second.size())
{
m_seedAssetIds.erase(assetId);
return 0;
}
return static_cast<int>(curEntry->second.size());
}
void AssetValidationSystemComponent::ConsoleCommandAddSeedPath(IConsoleCmdArgs* pCmdArgs)
{
if (pCmdArgs->GetArgCount() < 2)
{
AZ_TracePrintf("AssetValidation", "addseedpath assetpath");
return;
}
AssetValidationRequestBus::Broadcast(&AssetValidationRequestBus::Events::AddSeedPath, pCmdArgs->GetArg(1));
}
void AssetValidationSystemComponent::ConsoleCommandKnownAssets([[maybe_unused]] IConsoleCmdArgs* pCmdArgs)
{
AssetValidationRequestBus::Broadcast(&AssetValidationRequestBus::Events::ListKnownAssets);
}
void AssetValidationSystemComponent::ConsoleCommandRemoveSeedPath(IConsoleCmdArgs* pCmdArgs)
{
if (pCmdArgs->GetArgCount() < 2)
{
AZ_TracePrintf("AssetValidation", "removeseedpath assetpath");
return;
}
AssetValidationRequestBus::Broadcast(&AssetValidationRequestBus::Events::RemoveSeedPath, pCmdArgs->GetArg(1));
}
void AssetValidationSystemComponent::ConsoleCommandAddSeedList(IConsoleCmdArgs* pCmdArgs)
{
if (pCmdArgs->GetArgCount() < 2)
{
AZ_TracePrintf("AssetValidation", "Command syntax is: addseedlist <path/to/seedfile> as a relative path under the /dev folder");
return;
}
const char* seedfilepath = pCmdArgs->GetArg(1);
AssetValidationRequestBus::Broadcast(&AssetValidationRequestBus::Events::AddSeedList, seedfilepath);
}
bool AssetValidationSystemComponent::AddSeedsFor(const AzFramework::AssetSeedList& seedList, AZ::u32 seedId)
{
for (const AzFramework::SeedInfo& thisSeed : seedList)
{
AddSeedAssetId(thisSeed.m_assetId, seedId);
}
return true;
}
bool AssetValidationSystemComponent::RemoveSeedsFor(const AzFramework::AssetSeedList& seedList, AZ::u32 seedId)
{
AssetValidationRequests::AssetSourceList removeList;
for (const AzFramework::SeedInfo& thisSeed : seedList)
{
removeList.push_back({ thisSeed.m_assetId, seedId });
}
RemoveSeedAssetIdList(removeList);
return true;
}
bool AssetValidationSystemComponent::AddSeedListHelper(const char* seedPath)
{
AZStd::string absoluteSeedPath;
AZ::Outcome<AzFramework::AssetSeedList, AZStd::string> loadSeedOutcome = LoadSeedList(seedPath, absoluteSeedPath);
if (!loadSeedOutcome.IsSuccess())
{
AZ_Warning("AssetValidation", false, loadSeedOutcome.GetError().c_str());
return false;
}
if (m_seedLists.count(absoluteSeedPath.c_str()))
{
AZ_Warning("AssetValidation", false, "Seed list %s (%s) already loaded", seedPath, absoluteSeedPath.c_str());
return false;
}
AzFramework::AssetSeedList seedList = loadSeedOutcome.TakeValue();
if (m_seedMode && !AddSeedsFor(seedList, AZ_CRC(absoluteSeedPath.c_str())))
{
return false;
}
m_seedLists.insert(absoluteSeedPath.c_str());
AZ_TracePrintf("AssetValidation", "Added seed list %s (%s) with %u elements", seedPath, absoluteSeedPath.c_str(), seedList.size());
return true;
}
bool GetDefaultSeedListFiles(AZStd::vector<AZStd::string>& defaultSeedListFiles)
{
const char* engineRoot = nullptr;
AzFramework::ApplicationRequests::Bus::BroadcastResult(engineRoot, &AzFramework::ApplicationRequests::GetEngineRoot);
const char* appRoot = nullptr;
AzFramework::ApplicationRequests::Bus::BroadcastResult(appRoot, &AzFramework::ApplicationRequests::GetAppRoot);
auto settingsRegistry = AZ::SettingsRegistry::Get();
AZ::SettingsRegistryInterface::FixedValueString gameFolder;
auto projectKey = AZ::SettingsRegistryInterface::FixedValueString::format("%s/project_path", AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey);
settingsRegistry->Get(gameFolder, projectKey);
if (gameFolder.empty())
{
AZ_Warning("AssetValidation", false, "Unable to locate game name in bootstrap.");
return false;
}
AZStd::vector<AzFramework::GemInfo> gemInfoList;
if (!AzFramework::GetGemsInfo(gemInfoList, *settingsRegistry))
{
AZ_Warning("AssetValidation", false, "Unable to get gem information.");
return false;
}
defaultSeedListFiles = AssetSeed::GetDefaultSeedListFiles(gemInfoList, AzFramework::PlatformFlags::Platform_PC);
return true;
}
bool AssetValidationSystemComponent::AddSeedList(const char* seedPath)
{
if (AZ::StringFunc::Equal(seedPath, "default"))
{
AZStd::vector<AZStd::string> defaultSeedListFiles;
if(!GetDefaultSeedListFiles(defaultSeedListFiles))
{
return false;
}
for (const AZStd::string& seedListFile : defaultSeedListFiles)
{
if (!AddSeedListHelper(seedListFile.c_str()))
{
return false;
}
}
return true;
}
return AddSeedListHelper(seedPath);
}
void AssetValidationSystemComponent::ConsoleCommandRemoveSeedList(IConsoleCmdArgs* pCmdArgs)
{
if (pCmdArgs->GetArgCount() < 2)
{
AZ_TracePrintf("AssetValidation", "removeseedlist seedlistpath");
return;
}
const char* seedfilepath = pCmdArgs->GetArg(1);
AssetValidationRequestBus::Broadcast(&AssetValidationRequestBus::Events::RemoveSeedList, seedfilepath);
}
AZ::Outcome<AzFramework::AssetSeedList, AZStd::string> AssetValidationSystemComponent::LoadSeedList(const char* seedPath, AZStd::string& seedListPath)
{
AZStd::string absoluteSeedPath = seedPath;
if (AZ::StringFunc::Path::IsRelative(seedPath))
{
const char* appRoot = nullptr;
AzFramework::ApplicationRequests::Bus::BroadcastResult(appRoot, &AzFramework::ApplicationRequests::GetEngineRoot);
if (!appRoot)
{
return AZ::Failure(AZStd::string("Couldn't get engine root"));
}
absoluteSeedPath = AZStd::string::format("%s/%s", appRoot, seedPath);
}
AzFramework::StringFunc::Path::Normalize(absoluteSeedPath);
AzFramework::AssetSeedList seedList;
if (!AZ::Utils::LoadObjectFromFileInPlace(absoluteSeedPath, seedList))
{
return AZ::Failure(AZStd::string::format("Failed to load seed list %s", absoluteSeedPath.c_str()));
}
seedListPath = absoluteSeedPath;
return AZ::Success(seedList);
}
bool AssetValidationSystemComponent::RemoveSeedListHelper(const char* seedPath)
{
AZStd::string absoluteSeedPath;
AZ::Outcome<AzFramework::AssetSeedList, AZStd::string> loadSeedOutcome = LoadSeedList(seedPath, absoluteSeedPath);
if (!loadSeedOutcome.IsSuccess())
{
AZ_Warning("AssetValidation", false, loadSeedOutcome.GetError().c_str());
return false;
}
AzFramework::AssetSeedList seedList = loadSeedOutcome.TakeValue();
if (!m_seedLists.count(absoluteSeedPath))
{
AZ_Warning("AssetValidation", false, "Seed path %s (%s) wasn't in seed lists", seedPath, absoluteSeedPath.c_str());
return false;
}
m_seedLists.erase(absoluteSeedPath.c_str());
// Don't check if we're currently in seed mode - that will be dealt with on the other side
if (!RemoveSeedsFor(seedList, AZ_CRC(absoluteSeedPath.c_str())))
{
return false;
}
AZ_TracePrintf("AssetValidation", "Removed seed list %s with %u elements", absoluteSeedPath.c_str(), seedList.size());
return true;
}
bool AssetValidationSystemComponent::RemoveSeedList(const char* seedPath)
{
if (AZ::StringFunc::Equal(seedPath, "default"))
{
AZStd::vector<AZStd::string> defaultSeedListFiles;
if (!GetDefaultSeedListFiles(defaultSeedListFiles))
{
return false;
}
for (const AZStd::string& seedListFile : defaultSeedListFiles)
{
if (!RemoveSeedListHelper(seedListFile.c_str()))
{
return false;
}
}
return true;
}
return RemoveSeedListHelper(seedPath);
}
}