Files
o3de/Code/Framework/AzToolsFramework/AzToolsFramework/Asset/AssetSystemComponent.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

713 lines
29 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 <AzCore/IO/FileIO.h>
#include <AzFramework/Asset/AssetProcessorMessages.h>
#include <AzFramework/Network/AssetProcessorConnection.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
#include <AzToolsFramework/Asset/AssetProcessorMessages.h>
#include <AzToolsFramework/Asset/AssetSystemComponent.h>
#include <AzToolsFramework/AssetEditor/AssetEditorBus.h>
#include <AzCore/Asset/AssetSerializer.h>
#include <AzCore/PlatformIncl.h>
#include <AzCore/RTTI/BehaviorContext.h>
namespace AzToolsFramework
{
namespace AssetSystem
{
void OnAssetSystemMessage(unsigned int /*typeId*/, const void* buffer, unsigned int bufferSize, AZ::SerializeContext* context)
{
SourceFileNotificationMessage message;
if (!AZ::Utils::LoadObjectFromBufferInPlace(buffer, bufferSize, message, context))
{
AZ_TracePrintf("AssetSystem", "Problem deserializing SourceFileNotificationMessage");
return;
}
switch (message.m_type)
{
case SourceFileNotificationMessage::FileChanged:
AssetSystemBus::QueueBroadcast(&AssetSystemBus::Events::SourceFileChanged,
message.m_relativeSourcePath, message.m_scanFolder, message.m_sourceUUID);
break;
case SourceFileNotificationMessage::FileRemoved:
AssetSystemBus::QueueBroadcast(&AssetSystemBus::Events::SourceFileRemoved,
message.m_relativeSourcePath, message.m_scanFolder, message.m_sourceUUID);
break;
case SourceFileNotificationMessage::FileFailed :
AssetSystemBus::QueueBroadcast(&AssetSystemBus::Events::SourceFileFailed,
message.m_relativeSourcePath, message.m_scanFolder, message.m_sourceUUID);
break;
default:
AZ_TracePrintf("AssetSystem", "Unknown SourceFileNotificationMessage type");
break;
}
}
void OnAssetBrowserShowRequest(const void* buffer, unsigned int bufferSize)
{
AssetBrowserShowRequest message;
if (!AZ::Utils::LoadObjectFromBufferInPlace(buffer, bufferSize, message))
{
AZ_TracePrintf("AssetSystem", "Problem deserializing AssetBrowserShowRequest");
return;
}
QString absolutePath = QString::fromUtf8(message.m_filePath.data());
AZStd::function<void()> finalizeOnMainThread = [absolutePath]()
{
AzToolsFramework::EditorEvents::Bus::Broadcast(&AzToolsFramework::EditorEvents::SelectAsset, absolutePath);
};
AZ::SystemTickBus::QueueFunction(finalizeOnMainThread);
}
AZ::Outcome<AssetSystem::JobInfoContainer> SendAssetJobsRequest(AssetJobsInfoRequest request, AssetJobsInfoResponse &response)
{
if (!SendRequest(request, response))
{
bool hasAssetId = request.m_assetId.IsValid();
bool hasSearchTerm = !request.m_searchTerm.empty();
if(hasAssetId)
{
AZ_Error("Editor", false, "GetAssetJobsInfo request failed for AssetId: %s", request.m_assetId.ToString<AZStd::string>().c_str());
}
else if(hasSearchTerm)
{
AZ_Error("Editor", false, "GetAssetJobsInfo request failed for search term: %s", request.m_searchTerm.c_str());
}
else
{
AZ_Error("Editor", false, "GetAssetJobsInfo request failed, no AssetId or search term was provided");
}
return AZ::Failure();
}
if (response.m_isSuccess)
{
return AZ::Success(response.m_jobList);
}
return AZ::Failure();
}
void AssetSystemComponent::Activate()
{
AZ::SerializeContext* context = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(context, &AZ::ComponentApplicationRequests::GetSerializeContext);
AzFramework::SocketConnection* socketConn = AzFramework::SocketConnection::GetInstance();
AZ_Assert(socketConn, "AzToolsFramework::AssetSystem::AssetSystemComponent requires a valid socket conection!");
if (socketConn)
{
m_cbHandle = socketConn->AddMessageHandler(AZ_CRC("AssetProcessorManager::SourceFileNotification", 0x8bfc4d1c),
[context](unsigned int typeId, unsigned int /*serial*/, const void* data, unsigned int dataLength)
{
OnAssetSystemMessage(typeId, data, dataLength, context);
});
m_showAssetBrowserCBHandle = socketConn->AddMessageHandler(AssetSystem::AssetBrowserShowRequest::MessageType,
[](unsigned int /*typeId*/, unsigned int /*serial*/, const void* data, unsigned int dataLength)
{
OnAssetBrowserShowRequest(data, dataLength);
});
m_wantShowAssetBrowserCBHandle = socketConn->AddMessageHandler(AssetSystem::WantAssetBrowserShowRequest::MessageType,
[](unsigned int /*typeId*/, unsigned int serial, const void* data, unsigned int dataLength)
{
Q_UNUSED(data);
Q_UNUSED(dataLength);
AssetSystem::WantAssetBrowserShowResponse message;
#ifdef AZ_PLATFORM_WINDOWS
message.m_processId = GetCurrentProcessId();
#endif // #ifdef AZ_PLATFORM_WINDOWS
SendResponse(message, serial);
});
}
AssetSystemBus::AllowFunctionQueuing(true);
AssetSystemRequestBus::Handler::BusConnect();
AssetSystemJobRequestBus::Handler::BusConnect();
AzToolsFramework::ToolsAssetSystemBus::Handler::BusConnect();
AZ::SystemTickBus::Handler::BusConnect();
}
void AssetSystemComponent::Deactivate()
{
AZ::SystemTickBus::Handler::BusDisconnect();
AzToolsFramework::ToolsAssetSystemBus::Handler::BusDisconnect();
AssetSystemJobRequestBus::Handler::BusDisconnect();
AssetSystemRequestBus::Handler::BusDisconnect();
AzFramework::SocketConnection* socketConn = AzFramework::SocketConnection::GetInstance();
AZ_Assert(socketConn, "AzToolsFramework::AssetSystem::AssetSystemComponent requires a valid socket conection!");
if (socketConn)
{
socketConn->RemoveMessageHandler(AssetSystem::WantAssetBrowserShowRequest::MessageType, m_wantShowAssetBrowserCBHandle);
socketConn->RemoveMessageHandler(AssetSystem::AssetBrowserShowRequest::MessageType, m_showAssetBrowserCBHandle);
socketConn->RemoveMessageHandler(AZ_CRC("AssetProcessorManager::SourceFileNotification", 0x8bfc4d1c), m_cbHandle);
}
AssetSystemBus::AllowFunctionQueuing(false);
AssetSystemBus::ClearQueuedEvents();
}
void AssetSystemComponent::Reflect(AZ::ReflectContext* context)
{
//source file
SourceFileNotificationMessage::Reflect(context);
// Requests
AssetJobsInfoRequest::Reflect(context);
AssetJobLogRequest::Reflect(context);
GetAbsoluteAssetDatabaseLocationRequest::Reflect(context);
GetScanFoldersRequest::Reflect(context);
GetAssetSafeFoldersRequest::Reflect(context);
AssetProcessorPlatformStatusRequest::Reflect(context);
AssetProcessorPendingPlatformAssetsRequest::Reflect(context);
WantAssetBrowserShowRequest::Reflect(context);
AssetBrowserShowRequest::Reflect(context);
SourceAssetProductsInfoRequest::Reflect(context);
// Responses
AssetJobsInfoResponse::Reflect(context);
AssetJobLogResponse::Reflect(context);
GetAbsoluteAssetDatabaseLocationResponse::Reflect(context);
GetScanFoldersResponse::Reflect(context);
GetAssetSafeFoldersResponse::Reflect(context);
AssetProcessorPlatformStatusResponse::Reflect(context);
AssetProcessorPendingPlatformAssetsResponse::Reflect(context);
WantAssetBrowserShowResponse::Reflect(context);
SourceAssetProductsInfoResponse::Reflect(context);
//JobInfo
AzToolsFramework::AssetSystem::JobInfo::Reflect(context);
//AssetSystemComponent
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<AssetSystemComponent, AZ::Component>()
;
}
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->EBus<AssetEditor::AssetEditorRequestsBus>("AssetEditorRequestsBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
->Attribute(AZ::Script::Attributes::Category, "Editor")
->Attribute(AZ::Script::Attributes::Module, "editor")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
->Event("CreateNewAsset", &AssetEditor::AssetEditorRequests::CreateNewAsset)
->Event("OpenAssetEditorById", &AssetEditor::AssetEditorRequests::OpenAssetEditorById)
;
behaviorContext->EBus<AssetEditor::AssetEditorWidgetRequestsBus>("AssetEditorWidgetRequestsBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
->Attribute(AZ::Script::Attributes::Category, "Editor")
->Attribute(AZ::Script::Attributes::Module, "editor")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
->Event("CreateAsset", &AssetEditor::AssetEditorWidgetRequests::CreateAsset)
->Event("SaveAssetAs", &AssetEditor::AssetEditorWidgetRequests::SaveAssetAs)
->Event("OpenAssetById", &AssetEditor::AssetEditorWidgetRequests::OpenAssetById)
;
}
}
void AssetSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("AssetProcessorToolsConnection", 0x734669bc));
}
void AssetSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC("AssetProcessorToolsConnection", 0x734669bc));
}
void AssetSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
required.push_back(AZ_CRC("AssetProcessorConnection", 0xf0cd75cd));
}
bool AssetSystemComponent::GetRelativeProductPathFromFullSourceOrProductPath(const AZStd::string& fullPath, AZStd::string& outputPath)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
outputPath = fullPath;
return false;
}
AzFramework::AssetSystem::GetRelativeProductPathFromFullSourceOrProductPathRequest request(fullPath);
AzFramework::AssetSystem::GetRelativeProductPathFromFullSourceOrProductPathResponse response;
if (!SendRequest(request, response))
{
AZ_Error("Editor", false, "Failed to send GetAssetId request for %s", fullPath.c_str());
outputPath = fullPath;
return false;
}
outputPath = response.m_relativeProductPath;
return response.m_resolved;
}
bool AssetSystemComponent::GenerateRelativeSourcePath(
const AZStd::string& sourcePath, AZStd::string& relativePath, AZStd::string& rootFilePath)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
relativePath = sourcePath;
return false;
}
AzFramework::AssetSystem::GenerateRelativeSourcePathRequest request(sourcePath);
AzFramework::AssetSystem::GenerateRelativeSourcePathResponse response;
if (!SendRequest(request, response))
{
AZ_Error("Editor", false, "Failed to send GenerateRelativeSourcePath request for %s", sourcePath.c_str());
relativePath = sourcePath;
return false;
}
relativePath = response.m_relativeSourcePath;
rootFilePath = response.m_rootFolder;
return response.m_resolved;
}
bool AssetSystemComponent::GetFullSourcePathFromRelativeProductPath(const AZStd::string& relPath, AZStd::string& fullPath)
{
auto foundIt = m_assetSourceRelativePathToFullPathCache.find(relPath);
if (foundIt != m_assetSourceRelativePathToFullPathCache.end())
{
fullPath = foundIt->second;
return true;
}
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
fullPath = "";
return false;
}
AzFramework::AssetSystem::GetFullSourcePathFromRelativeProductPathRequest request(relPath);
AzFramework::AssetSystem::GetFullSourcePathFromRelativeProductPathResponse response;
if (!SendRequest(request, response))
{
AZ_Error("Editor", false, "Failed to send GetAssetPath request for %s", relPath.c_str());
fullPath = "";
return false;
}
if (response.m_resolved)
{
fullPath = response.m_fullSourcePath;
m_assetSourceRelativePathToFullPathCache[relPath] = fullPath;
return true;
}
else
{
fullPath = "";
return false;
}
}
bool AssetSystemComponent::GetAbsoluteAssetDatabaseLocation(AZStd::string& result)
{
result = "";
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
return false;
}
AzToolsFramework::AssetSystem::GetAbsoluteAssetDatabaseLocationRequest request;
AzToolsFramework::AssetSystem::GetAbsoluteAssetDatabaseLocationResponse response;
if (!SendRequest(request, response))
{
AZ_Error("Editor", false, "Failed to send GetAbsoluteAssetDatabaseLocation request");
return false;
}
if (response.m_isSuccess)
{
result = response.m_absoluteAssetDatabaseLocation;
return true;
}
else
{
return false;
}
}
void AssetSystemComponent::OnSystemTick()
{
AssetSystemBus::ExecuteQueuedEvents();
}
bool AssetSystemComponent::GetAssetInfoById(const AZ::Data::AssetId& assetId, const AZ::Data::AssetType& assetType, const AZStd::string& /*platformName*/, AZ::Data::AssetInfo& assetInfo, AZStd::string& rootFilePath)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
assetInfo.m_assetId.SetInvalid();
assetInfo.m_assetType = AZ::Data::s_invalidAssetType;
if (!engineConnection || !engineConnection->IsConnected())
{
return false;
}
AzFramework::AssetSystem::SourceAssetInfoRequest request(assetId, assetType);
AzFramework::AssetSystem::SourceAssetInfoResponse response;
if (!SendRequest(request, response))
{
AZ_Error("Editor", false, "Failed to send GetAssetInfoById request for %s", assetId.ToString<AZStd::string>().c_str());
return false;
}
if (response.m_found)
{
assetInfo = response.m_assetInfo;
rootFilePath = response.m_rootFolder;
return true;
}
return false;
}
bool AssetSystemComponent::GetSourceInfoBySourcePath(const char* sourcePath, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
assetInfo.m_assetId.SetInvalid();
assetInfo.m_assetType = AZ::Data::s_invalidAssetType;
if (!engineConnection || !engineConnection->IsConnected())
{
return false;
}
AzFramework::AssetSystem::SourceAssetInfoRequest request(sourcePath);
AzFramework::AssetSystem::SourceAssetInfoResponse response;
if (!SendRequest(request, response))
{
AZ_Error("Editor", false, "Failed to send GetSourceInfoBySourcePath request for %s", sourcePath);
return false;
}
if (response.m_found)
{
assetInfo = response.m_assetInfo;
watchFolder = response.m_rootFolder;
}
return response.m_found;
}
bool AssetSystemComponent::GetSourceInfoBySourceUUID(const AZ::Uuid& sourceUuid, AZ::Data::AssetInfo& assetInfo, AZStd::string& watchFolder)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
assetInfo.m_assetId.SetInvalid();
assetInfo.m_assetType = AZ::Data::s_invalidAssetType;
if (!engineConnection || !engineConnection->IsConnected())
{
return false;
}
AzFramework::AssetSystem::SourceAssetInfoRequest request(sourceUuid, AZ::Uuid::CreateNull());
AzFramework::AssetSystem::SourceAssetInfoResponse response;
if (!SendRequest(request, response))
{
AZ_Error("Editor", false, "Failed to send GetSourceInfoBySourceUUID request for uuid: %s", sourceUuid.ToString<AZ::OSString>().c_str());
return false;
}
if (response.m_found)
{
assetInfo = response.m_assetInfo;
watchFolder = response.m_rootFolder;
}
return response.m_found;
}
bool AssetSystemComponent::GetAssetsProducedBySourceUUID(const AZ::Uuid& sourceUuid, AZStd::vector<AZ::Data::AssetInfo>& productsAssetInfo)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
return false;
}
SourceAssetProductsInfoRequest request(sourceUuid);
SourceAssetProductsInfoResponse response;
if (!SendRequest(request, response))
{
AZ_Error("Editor", false, "Failed to send GetAssetsProducedBySourceUUID request for uuid: %s", sourceUuid.ToString<AZ::OSString>().c_str());
return false;
}
if (response.m_found)
{
productsAssetInfo = response.m_productsAssetInfo;
}
return response.m_found;
}
bool AssetSystemComponent::GetScanFolders(AZStd::vector<AZStd::string>& scanFolders)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
return false;
}
GetScanFoldersRequest request;
GetScanFoldersResponse response;
if (!SendRequest(request, response))
{
AZ_Error("Editor", false, "Failed to send GetScanFolders request");
return false;
}
scanFolders.insert(scanFolders.end(), response.m_scanFolders.begin(), response.m_scanFolders.end());
return !response.m_scanFolders.empty();
}
bool AssetSystemComponent::GetAssetSafeFolders(AZStd::vector<AZStd::string>& assetSafeFolders)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
return false;
}
GetAssetSafeFoldersRequest request;
GetAssetSafeFoldersResponse response;
if (!SendRequest(request, response))
{
AZ_Error("Editor", false, "Failed to send GetScanFolders request");
return false;
}
assetSafeFolders.insert(assetSafeFolders.end(), response.m_assetSafeFolders.begin(), response.m_assetSafeFolders.end());
return !response.m_assetSafeFolders.empty();
}
bool AssetSystemComponent::IsAssetPlatformEnabled(const char* platform)
{
AssetProcessorPlatformStatusRequest request;
request.m_platform = platform;
AssetProcessorPlatformStatusResponse response;
if (!SendRequest(request, response))
{
return false;
}
return response.m_isPlatformEnabled;
}
int AssetSystemComponent::GetPendingAssetsForPlatform(const char* platform)
{
AssetProcessorPendingPlatformAssetsRequest request;
request.m_platform = platform;
AssetProcessorPendingPlatformAssetsResponse response;
if (!SendRequest(request, response))
{
return -1;
}
return response.m_numberOfPendingJobs;
}
AZ::Outcome<AssetSystem::JobInfoContainer> AssetSystemComponent::GetAssetJobsInfo(const AZStd::string& path, const bool escalateJobs)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
return AZ::Failure();
}
AssetJobsInfoRequest request(path);
request.m_escalateJobs = escalateJobs;
AssetJobsInfoResponse response;
return SendAssetJobsRequest(request, response);
}
AZ::Outcome<AssetSystem::JobInfoContainer> AssetSystemComponent::GetAssetJobsInfoByAssetID(const AZ::Data::AssetId& assetId, const bool escalateJobs, bool requireFencing = true)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
return AZ::Failure();
}
AssetJobsInfoRequest request(assetId, escalateJobs, requireFencing);
AssetJobsInfoResponse response;
return SendAssetJobsRequest(request, response);
}
AZ::Outcome<JobStatus> AssetSystemComponent::GetAssetJobsStatusByJobKey(const AZStd::string& jobKey, const bool escalateJobs)
{
// Strategy
// First find all jobInfos for the inputted jobkey.
// if there is no jobKey than return missing.
// Otherwise if even one job failed than return failed.
// If none of the job failed than check to see whether any job status are queued or inprogress, if yes than return the appropriate status.
// Otherwise return completed status
AZ::Outcome<AzToolsFramework::AssetSystem::JobInfoContainer> result = AZ::Failure();
result = GetAssetJobsInfoByJobKey(jobKey, escalateJobs);
if (!result.IsSuccess())
{
return AZ::Failure();
}
AzToolsFramework::AssetSystem::JobInfoContainer& jobInfos = result.GetValue();
if (!jobInfos.size())
{
return AZ::Success(JobStatus::Missing);
}
bool isAnyJobInProgress = false;
for (const AzToolsFramework::AssetSystem::JobInfo& jobInfo : jobInfos)
{
if (jobInfo.m_status == JobStatus::Failed)
{
return AZ::Success(JobStatus::Failed);
}
else if (jobInfo.m_status == JobStatus::Queued)
{
return AZ::Success(JobStatus::Queued);
}
else if (jobInfo.m_status == JobStatus::InProgress)
{
isAnyJobInProgress = true;
}
}
if (isAnyJobInProgress)
{
return AZ::Success(JobStatus::InProgress);
}
return AZ::Success(JobStatus::Completed);
}
AZ::Outcome<AssetSystem::JobInfoContainer> AssetSystemComponent::GetAssetJobsInfoByJobKey(const AZStd::string& jobKey, const bool escalateJobs)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
return AZ::Failure();
}
AssetJobsInfoRequest request(jobKey);
request.m_isSearchTermJobKey = true;
request.m_escalateJobs = escalateJobs;
AssetJobsInfoResponse response;
return SendAssetJobsRequest(request, response);
}
AZ::Outcome<AZStd::string> AssetSystemComponent::GetJobLog(AZ::u64 jobrunkey)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
return AZ::Failure();
}
AssetJobLogRequest request(jobrunkey);
AssetJobLogResponse response;
if (!SendRequest(request, response))
{
AZ_Error("Editor", false, "Failed to send GetJobLog Info for jobrunkey: %llu", jobrunkey);
return AZ::Failure();
}
if (response.m_isSuccess)
{
return AZ::Success(response.m_jobLog);
}
return AZ::Failure();
}
void AssetSystemComponent::SourceFileChanged(AZStd::string relativePath, AZStd::string /*scanFolder*/, AZ::Uuid /*sourceUUID*/)
{
m_assetSourceRelativePathToFullPathCache.erase(relativePath);
}
void AssetSystemComponent::SourceFileRemoved(AZStd::string relativePath, AZStd::string /*scanFolder*/, AZ::Uuid /*sourceUUID*/)
{
m_assetSourceRelativePathToFullPathCache.erase(relativePath);
}
void AssetSystemComponent::SourceFileFailed(AZStd::string relativePath, AZStd::string /*scanFolder*/, AZ::Uuid /*sourceUUID*/)
{
m_assetSourceRelativePathToFullPathCache.erase(relativePath);
}
void AssetSystemComponent::RegisterSourceAssetType(const AZ::Data::AssetType& assetType, const char* assetFileFilter)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
return;
}
AzFramework::AssetSystem::RegisterSourceAssetRequest request(assetType, assetFileFilter);
if (!SendRequest(request))
{
AZ_Error("Editor", false, "Failed to send RegisterSourceAssetType request for asset type %s", assetType.ToString<AZStd::string>().c_str());
}
}
void AssetSystemComponent::UnregisterSourceAssetType(const AZ::Data::AssetType& assetType)
{
AzFramework::SocketConnection* engineConnection = AzFramework::SocketConnection::GetInstance();
if (!engineConnection || !engineConnection->IsConnected())
{
return;
}
AzFramework::AssetSystem::UnregisterSourceAssetRequest request(assetType);
if (!SendRequest(request))
{
AZ_Error("Editor", false, "Failed to send UnregisterSourceAssetType request for asset type %s", assetType.ToString<AZStd::string>().c_str());
}
}
} // namespace AssetSystem
} // namespace AzToolsFramework