Files
UnrealEngineUWP/Engine/Source/Editor/ContentBrowser/Private/CollectionAssetRegistryBridge.cpp

208 lines
6.8 KiB
C++
Raw Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
#include "CollectionAssetRegistryBridge.h"
#include "AssetRegistry/AssetData.h"
#include "AssetRegistry/IAssetRegistry.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "CollectionManagerModule.h"
#include "CollectionManagerTypes.h"
#include "Containers/Set.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "ContentBrowserLog.h"
#include "Delegates/Delegate.h"
#include "HAL/LowLevelMemTracker.h"
#include "HAL/Platform.h"
#include "ICollectionManager.h"
#include "Logging/LogCategory.h"
#include "Logging/LogMacros.h"
#include "Misc/AssertionMacros.h"
#include "Misc/PackageName.h"
#include "Modules/ModuleManager.h"
#include "Trace/Detail/Channel.h"
#include "UObject/Class.h"
#include "UObject/ConstructorHelpers.h"
#include "UObject/CoreRedirects.h"
#include "UObject/LinkerLoad.h"
#include "UObject/NameTypes.h"
#include "UObject/UObjectGlobals.h"
#include "UObject/UnrealNames.h"
#define LOCTEXT_NAMESPACE "ContentBrowser"
/** The collection manager doesn't know how to follow redirectors, this class provides it with that knowledge */
class FCollectionRedirectorFollower : public ICollectionRedirectorFollower
{
public:
FCollectionRedirectorFollower()
: AssetRegistry(IAssetRegistry::Get())
{
}
virtual bool FixupObject(const FSoftObjectPath& InObjectPath, FSoftObjectPath& OutNewObjectPath) override
{
// Most of the time it will be in the asset registry so early return
FAssetData ObjectAssetData = AssetRegistry->GetAssetByObjectPath(InObjectPath, true);
if (ObjectAssetData.IsValid())
{
if (!ObjectAssetData.IsRedirector())
{
OutNewObjectPath = InObjectPath;
return false;
}
else
{
OutNewObjectPath = AssetRegistry->GetRedirectedObjectPath(InObjectPath);
}
}
else
{
FString InObjectPathString = InObjectPath.ToString();
if (!InObjectPathString.StartsWith(TEXT("/")))
{
if (!GIsSavingPackage)
Copying //UE4/Orion-Staging to //UE4/Main (Origin //Orion/Dev-General @ 2870388) #lockdown Nick.Penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 2870336 on 2016/02/17 by Marc.Audy Continued splitting up Orion Build * Restructure from platform based MakeBuild steps in to a PS4, Server, and Windows Client MakeBuild * Cook server data only once for both Windows and Linux (windows reuses Linux server data) * Split compilation of Win64 Client and Server such that MakeBuild_Server only builds Server and MakeBuild_WindowsClient only builds Client #jira UEB-580 #rb Ben.Marsh #tests Preflight and generated Windows Client and Server work to play game Change 2870026 on 2016/02/17 by Wes.Hunt Don't allow array shrinking when removing the corruption wrapper trailer. #rb none Updating CIS Counter Change 2869725 on 2016/02/17 by Dmitry.Rekman More analytics and QoS stats added for 0.19. #rb none #tests Ran Windows client and Linux server on compatible content. Change 2869705 on 2016/02/16 by Ryan.Gerleve Fix replicated properties and call RepNotifies of startup actors when scrubbing in replays. This is the engine support for fixing OR-6817, towers not respawning when rewinding replays. #rb john.pollard #tests golden path, replays, ps4 nomcp Change 2869644 on 2016/02/16 by Jason.Bestimt #ORION_DEV - Merge MAIN (0.18) at CL# 2869635 #Tests:none #RB:none Change 2869586 on 2016/02/16 by Marcus.Wassmer Fix texturestreaming RHI flushes. #rb none #test goldenpath #codereview Gil.Gribb Change 2869279 on 2016/02/16 by Lukasz.Furman fixed minion hit reaction directions #orion OR-13953 #rb Mieszko.Zielinski #tests PIE: hit minions with various abilities from different angles, checked velocity of death particles when killed by abilities and towers #codereview Dan.Youhon Change 2869277 on 2016/02/16 by Wes.Hunt During cook, when a package is not ready to save, actually early out of the saving code. Saves somewhere in the 130s to 200s range for cooks. #rb daniel.lamb #tests local windows cooks, preflight PS4 cooks Change 2869132 on 2016/02/16 by Mieszko.Zielinski Added a function to AISenseConfig allowing native-code MaxAge configuration #UE4 #rb Lukasz.Furman #test none required Change 2868981 on 2016/02/16 by Wes.Hunt remove -LogCookStats cmdline check, always log cook stats. -SendCookAnalytics flag is still used. This was requested by NickP. #rb none #tests local windows cooks Change 2868975 on 2016/02/16 by Wes.Hunt Don't submit DDC usage stats for zero-sized events. #rb none #tests local windows cook Change 2868956 on 2016/02/16 by Jason.Bestimt #ORION_DEV - Merge MAIN (0.18) at CL# 2868926 #RB:none #Tests:none Change 2868889 on 2016/02/16 by Max.Chen Sequencer: Only allow transport control binding when editing level editor sequencers. #rb none #tests none Change 2868663 on 2016/02/16 by David.Ratti downgrade warning to display #rb none #tests compile Change 2868624 on 2016/02/16 by Marcus.Wassmer Re-Enable Defrag validation for devgeneral #rb none #test none Change 2868493 on 2016/02/16 by Benn.Gallagher Added a few more stats to morph target updates to try and narrow down hitches #rb Bruce.Nesbit #tests pie, -game Win64 Change 2868445 on 2016/02/16 by Dmitry.Rekman Linux: report crashes due to stack overflow (OR-14519). - Reserve memory for alternative stack for signal handlers. Adds about 128KB memory per thread. - Force process spawning to use vfork() when no pipes are needed. - Ignore all signals except explicitly handled. - Prevent signals from being raised while another one is handled. - Added "debug threadrecurse" and "debug threadstackoverflow" to test that. [CL 2873763 by Andrew Grant in Main branch]
2016-02-19 12:03:17 -05:00
{
FTopLevelAssetPath FullPath = UClass::TryConvertShortTypeNameToPathName(UClass::StaticClass(), InObjectPathString);
if (FullPath.IsValid())
Copying //UE4/Orion-Staging to //UE4/Main (Origin //Orion/Dev-General @ 2870388) #lockdown Nick.Penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 2870336 on 2016/02/17 by Marc.Audy Continued splitting up Orion Build * Restructure from platform based MakeBuild steps in to a PS4, Server, and Windows Client MakeBuild * Cook server data only once for both Windows and Linux (windows reuses Linux server data) * Split compilation of Win64 Client and Server such that MakeBuild_Server only builds Server and MakeBuild_WindowsClient only builds Client #jira UEB-580 #rb Ben.Marsh #tests Preflight and generated Windows Client and Server work to play game Change 2870026 on 2016/02/17 by Wes.Hunt Don't allow array shrinking when removing the corruption wrapper trailer. #rb none Updating CIS Counter Change 2869725 on 2016/02/17 by Dmitry.Rekman More analytics and QoS stats added for 0.19. #rb none #tests Ran Windows client and Linux server on compatible content. Change 2869705 on 2016/02/16 by Ryan.Gerleve Fix replicated properties and call RepNotifies of startup actors when scrubbing in replays. This is the engine support for fixing OR-6817, towers not respawning when rewinding replays. #rb john.pollard #tests golden path, replays, ps4 nomcp Change 2869644 on 2016/02/16 by Jason.Bestimt #ORION_DEV - Merge MAIN (0.18) at CL# 2869635 #Tests:none #RB:none Change 2869586 on 2016/02/16 by Marcus.Wassmer Fix texturestreaming RHI flushes. #rb none #test goldenpath #codereview Gil.Gribb Change 2869279 on 2016/02/16 by Lukasz.Furman fixed minion hit reaction directions #orion OR-13953 #rb Mieszko.Zielinski #tests PIE: hit minions with various abilities from different angles, checked velocity of death particles when killed by abilities and towers #codereview Dan.Youhon Change 2869277 on 2016/02/16 by Wes.Hunt During cook, when a package is not ready to save, actually early out of the saving code. Saves somewhere in the 130s to 200s range for cooks. #rb daniel.lamb #tests local windows cooks, preflight PS4 cooks Change 2869132 on 2016/02/16 by Mieszko.Zielinski Added a function to AISenseConfig allowing native-code MaxAge configuration #UE4 #rb Lukasz.Furman #test none required Change 2868981 on 2016/02/16 by Wes.Hunt remove -LogCookStats cmdline check, always log cook stats. -SendCookAnalytics flag is still used. This was requested by NickP. #rb none #tests local windows cooks Change 2868975 on 2016/02/16 by Wes.Hunt Don't submit DDC usage stats for zero-sized events. #rb none #tests local windows cook Change 2868956 on 2016/02/16 by Jason.Bestimt #ORION_DEV - Merge MAIN (0.18) at CL# 2868926 #RB:none #Tests:none Change 2868889 on 2016/02/16 by Max.Chen Sequencer: Only allow transport control binding when editing level editor sequencers. #rb none #tests none Change 2868663 on 2016/02/16 by David.Ratti downgrade warning to display #rb none #tests compile Change 2868624 on 2016/02/16 by Marcus.Wassmer Re-Enable Defrag validation for devgeneral #rb none #test none Change 2868493 on 2016/02/16 by Benn.Gallagher Added a few more stats to morph target updates to try and narrow down hitches #rb Bruce.Nesbit #tests pie, -game Win64 Change 2868445 on 2016/02/16 by Dmitry.Rekman Linux: report crashes due to stack overflow (OR-14519). - Reserve memory for alternative stack for signal handlers. Adds about 128KB memory per thread. - Force process spawning to use vfork() when no pipes are needed. - Ignore all signals except explicitly handled. - Prevent signals from being raised while another one is handled. - Added "debug threadrecurse" and "debug threadstackoverflow" to test that. [CL 2873763 by Andrew Grant in Main branch]
2016-02-19 12:03:17 -05:00
{
FString ClassPathStr = FullPath.ToString();
const FString NewClassName = FLinkerLoad::FindNewPathNameForClass(ClassPathStr, false);
if (!NewClassName.IsEmpty())
{
check(FPackageName::IsValidObjectPath(NewClassName));
// Our new class name might be lacking the path, so try and find it so we can use the full path in the collection
UClass* FoundClass = FindObject<UClass>(nullptr, *NewClassName);
if (FoundClass)
{
OutNewObjectPath = *FoundClass->GetPathName();
}
}
Copying //UE4/Orion-Staging to //UE4/Main (Origin //Orion/Dev-General @ 2870388) #lockdown Nick.Penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 2870336 on 2016/02/17 by Marc.Audy Continued splitting up Orion Build * Restructure from platform based MakeBuild steps in to a PS4, Server, and Windows Client MakeBuild * Cook server data only once for both Windows and Linux (windows reuses Linux server data) * Split compilation of Win64 Client and Server such that MakeBuild_Server only builds Server and MakeBuild_WindowsClient only builds Client #jira UEB-580 #rb Ben.Marsh #tests Preflight and generated Windows Client and Server work to play game Change 2870026 on 2016/02/17 by Wes.Hunt Don't allow array shrinking when removing the corruption wrapper trailer. #rb none Updating CIS Counter Change 2869725 on 2016/02/17 by Dmitry.Rekman More analytics and QoS stats added for 0.19. #rb none #tests Ran Windows client and Linux server on compatible content. Change 2869705 on 2016/02/16 by Ryan.Gerleve Fix replicated properties and call RepNotifies of startup actors when scrubbing in replays. This is the engine support for fixing OR-6817, towers not respawning when rewinding replays. #rb john.pollard #tests golden path, replays, ps4 nomcp Change 2869644 on 2016/02/16 by Jason.Bestimt #ORION_DEV - Merge MAIN (0.18) at CL# 2869635 #Tests:none #RB:none Change 2869586 on 2016/02/16 by Marcus.Wassmer Fix texturestreaming RHI flushes. #rb none #test goldenpath #codereview Gil.Gribb Change 2869279 on 2016/02/16 by Lukasz.Furman fixed minion hit reaction directions #orion OR-13953 #rb Mieszko.Zielinski #tests PIE: hit minions with various abilities from different angles, checked velocity of death particles when killed by abilities and towers #codereview Dan.Youhon Change 2869277 on 2016/02/16 by Wes.Hunt During cook, when a package is not ready to save, actually early out of the saving code. Saves somewhere in the 130s to 200s range for cooks. #rb daniel.lamb #tests local windows cooks, preflight PS4 cooks Change 2869132 on 2016/02/16 by Mieszko.Zielinski Added a function to AISenseConfig allowing native-code MaxAge configuration #UE4 #rb Lukasz.Furman #test none required Change 2868981 on 2016/02/16 by Wes.Hunt remove -LogCookStats cmdline check, always log cook stats. -SendCookAnalytics flag is still used. This was requested by NickP. #rb none #tests local windows cooks Change 2868975 on 2016/02/16 by Wes.Hunt Don't submit DDC usage stats for zero-sized events. #rb none #tests local windows cook Change 2868956 on 2016/02/16 by Jason.Bestimt #ORION_DEV - Merge MAIN (0.18) at CL# 2868926 #RB:none #Tests:none Change 2868889 on 2016/02/16 by Max.Chen Sequencer: Only allow transport control binding when editing level editor sequencers. #rb none #tests none Change 2868663 on 2016/02/16 by David.Ratti downgrade warning to display #rb none #tests compile Change 2868624 on 2016/02/16 by Marcus.Wassmer Re-Enable Defrag validation for devgeneral #rb none #test none Change 2868493 on 2016/02/16 by Benn.Gallagher Added a few more stats to morph target updates to try and narrow down hitches #rb Bruce.Nesbit #tests pie, -game Win64 Change 2868445 on 2016/02/16 by Dmitry.Rekman Linux: report crashes due to stack overflow (OR-14519). - Reserve memory for alternative stack for signal handlers. Adds about 128KB memory per thread. - Force process spawning to use vfork() when no pipes are needed. - Ignore all signals except explicitly handled. - Prevent signals from being raised while another one is handled. - Added "debug threadrecurse" and "debug threadstackoverflow" to test that. [CL 2873763 by Andrew Grant in Main branch]
2016-02-19 12:03:17 -05:00
}
}
}
else if (InObjectPathString.StartsWith(TEXT("/Script/")))
{
// We can't use FindObject while we're saving
if (!GIsSavingPackage)
{
check(FPackageName::IsValidObjectPath(InObjectPathString));
UClass* FoundClass = FindObject<UClass>(nullptr, *InObjectPathString);
if (!FoundClass)
{
// Use the linker to search for class name redirects (from the loaded ActiveClassRedirects)
const FString NewClassName = FLinkerLoad::FindNewPathNameForClass(InObjectPathString, false);
if (!NewClassName.IsEmpty())
{
check(FPackageName::IsValidObjectPath(NewClassName));
// Our new class name might be lacking the path, so try and find it so we can use the full path in the collection
FoundClass = FindObject<UClass>(nullptr, *NewClassName);
if (FoundClass)
{
OutNewObjectPath = *FoundClass->GetPathName();
}
}
}
}
}
else
{
// Check whether there is a GeneralizedObject redirector entry in FCoreRedirects
// This would come from the process of converting on-disk UObjectRedirectors into
// core redirectors
const FCoreRedirectObjectName OldObjectName(InObjectPathString);
FCoreRedirectObjectName NewObjectName =
FCoreRedirects::GetRedirectedName(ECoreRedirectFlags::Type_Asset, OldObjectName);
OutNewObjectPath.SetPath(NewObjectName.ToString());
}
}
return OutNewObjectPath.IsValid() && InObjectPath != OutNewObjectPath;
}
private:
IAssetRegistry* AssetRegistry;
};
FCollectionAssetRegistryBridge::FCollectionAssetRegistryBridge()
{
// Load the asset registry module to listen for updates
IAssetRegistry& AssetRegistry = IAssetRegistry::GetChecked();
AssetRegistry.OnAssetsRemoved().AddRaw(this, &FCollectionAssetRegistryBridge::OnAssetsRemoved);
AssetRegistry.OnAssetRenamed().AddRaw(this, &FCollectionAssetRegistryBridge::OnAssetRenamed);
if (AssetRegistry.IsLoadingAssets())
{
AssetRegistry.OnFilesLoaded().AddRaw(this, &FCollectionAssetRegistryBridge::OnAssetRegistryLoadComplete);
}
else
{
OnAssetRegistryLoadComplete();
}
}
FCollectionAssetRegistryBridge::~FCollectionAssetRegistryBridge()
{
// Load the asset registry module to unregister delegates
if (IAssetRegistry* AssetRegistry = IAssetRegistry::Get())
{
AssetRegistry->OnAssetsRemoved().RemoveAll(this);
AssetRegistry->OnAssetRenamed().RemoveAll(this);
AssetRegistry->OnFilesLoaded().RemoveAll(this);
}
}
void FCollectionAssetRegistryBridge::OnAssetRegistryLoadComplete()
{
LLM_SCOPE_BYNAME(TEXT("CollectionManager"));
FCollectionManagerModule& CollectionManagerModule = FCollectionManagerModule::GetModule();
// We've found all the assets, let the collections manager fix up its references now so that it doesn't reference any redirectors
FCollectionRedirectorFollower RedirectorFollower;
CollectionManagerModule.Get().HandleFixupRedirectors(RedirectorFollower);
}
void FCollectionAssetRegistryBridge::OnAssetRenamed(const FAssetData& AssetData, const FString& OldObjectPath)
{
FCollectionManagerModule& CollectionManagerModule = FCollectionManagerModule::GetModule();
// Notify the collections manager that an asset has been renamed
CollectionManagerModule.Get().HandleObjectRenamed(FSoftObjectPath(OldObjectPath), AssetData.GetSoftObjectPath());
}
void FCollectionAssetRegistryBridge::OnAssetsRemoved(TConstArrayView<FAssetData> AssetDatas)
{
FCollectionManagerModule& CollectionManagerModule = FCollectionManagerModule::GetModule();
TArray<FSoftObjectPath> RedirectorObjectsRemoved;
TArray<FSoftObjectPath> ObjectsRemoved;
ObjectsRemoved.Reserve(AssetDatas.Num());
for (const FAssetData& AssetData : AssetDatas)
{
if (AssetData.IsRedirector())
{
RedirectorObjectsRemoved.Add(AssetData.GetSoftObjectPath());
}
else
{
ObjectsRemoved.Add(AssetData.GetSoftObjectPath());
}
}
// Notify the collections manager that a redirector has been removed
// This will attempt to re-save any collections that still have a reference to this redirector in their on-disk collection data
if (!RedirectorObjectsRemoved.IsEmpty())
{
CollectionManagerModule.Get().HandleRedirectorsDeleted(RedirectorObjectsRemoved);
}
// Notify the collections manager that an asset has been removed
if (!ObjectsRemoved.IsEmpty())
{
CollectionManagerModule.Get().HandleObjectsDeleted(ObjectsRemoved);
}
}
#undef LOCTEXT_NAMESPACE