Files
UnrealEngineUWP/Engine/Source/Developer/CookedEditor/Private/CookedEditorPackageManager.cpp
robert manuszewski d1443992e1 Deprecating ANY_PACKAGE.
This change consists of multiple changes:

Core:
- Deprecation of ANY_PACKAGE macro. Added ANY_PACKAGE_DEPRECATED macro which can still be used for backwards compatibility purposes (only used in CoreUObject)
- Deprecation of StaticFindObjectFast* functions that take bAnyPackage parameter
- Added UStruct::GetStructPathName function that returns FTopLevelAssetPath representing the path name (package + object FName, super quick compared to UObject::GetPathName) + wrapper UClass::GetClassPathName to make it look better when used with UClasses
- Added (Static)FindFirstObject* functions that find a first object given its Name (no Outer). These functions are used in places I consider valid to do global UObject (UClass) lookups like parsing command line parameters / checking for unique object names
- Added static UClass::TryFindType function which serves a similar purpose as FindFirstObject however it's going to throw a warning (with a callstack / maybe ensure in the future?) if short class name is provided. This function is used  in places that used to use short class names but now should have been converted to use path names to catch any potential regressions and or edge cases I missed.
- Added static UClass::TryConvertShortNameToPathName utility function
- Added static UClass::TryFixShortClassNameExportPath utility function
- Object text export paths will now also include class path (Texture2D'/Game/Textures/Grass.Grass' -> /Script/Engine.Texture2D'/Game/Textures/Grass.Grass')
- All places that manually generated object export paths for objects will now use FObjectPropertyBase::GetExportPath
- Added a new startup test that checks for short type names in UClass/FProperty MetaData values

AssetRegistry:
- Deprecated any member variables (FAssetData / FARFilter) or functions that use FNames to represent class names and replaced them with FTopLevelAssetPath
- Added new member variables and new function overloads that use FTopLevelAssetPath to represent class names
- This also applies to a few other modules' APIs to match AssetRegistry changes

Everything else:
- Updated code that used ANY_PACKAGE (depending on the use case) to use FindObject(nullptr, PathToObject), UClass::TryFindType (used when path name is expected, warns if it's a short name) or FindFirstObject (usually for finding types based on user input but there's been a few legitimate use cases not related to user input)
- Updated code that used AssetRegistry API to use FTopLevelAssetPaths and USomeClass::StaticClass()->GetClassPathName() instead of GetFName()
- Updated meta data and hardcoded FindObject(ANY_PACKAGE, "EEnumNameOrClassName") calls to use path names

#jira UE-99463
#rb many.people
[FYI] Marcus.Wassmer
#preflight 629248ec2256738f75de9b32

#codereviewnumbers 20320742, 20320791, 20320799, 20320756, 20320809, 20320830, 20320840, 20320846, 20320851, 20320863, 20320780, 20320765, 20320876, 20320786

#ROBOMERGE-OWNER: robert.manuszewski
#ROBOMERGE-AUTHOR: robert.manuszewski
#ROBOMERGE-SOURCE: CL 20430220 via CL 20433854 via CL 20435474 via CL 20435484
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v949-20362246)

[CL 20448496 by robert manuszewski in ue5-main branch]
2022-06-01 03:46:59 -04:00

222 lines
6.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "CookedEditorPackageManager.h"
#include "CoreMinimal.h"
#include "Logging/LogMacros.h"
#include "AssetRegistry/AssetRegistryModule.h"
#include "AssetRegistry/IAssetRegistry.h"
#include "AssetRegistry/AssetRegistryModule.h"
#include "Engine/AssetManager.h"
#include "GameDelegates.h"
DEFINE_LOG_CATEGORY_STATIC(LogCookedEditorTargetPlatform, Log, All)
TUniquePtr<ICookedEditorPackageManager> ICookedEditorPackageManager::FactoryForTargetPlatform(ITargetPlatform* TP, bool bIsCookedCooker)
{
if (FGameDelegates::Get().GetCookedEditorPackageManagerFactoryDelegate().IsBound())
{
return FGameDelegates::Get().GetCookedEditorPackageManagerFactoryDelegate().Execute();
}
return TUniquePtr<ICookedEditorPackageManager>(new FIniCookedEditorPackageManager(bIsCookedCooker));
}
void ICookedEditorPackageManager::AddPackagesFromPath(TArray<FName>& Packages, const TCHAR* Path, EPackageSearchMode SearchMode) const
{
UAssetManager& AssetManager = UAssetManager::Get();
IAssetRegistry& AssetRegistry = AssetManager.GetAssetRegistry();
TArray<FAssetData> AssetDatas;
// look up the path in the asset registry, so we can use it to make sure the asset can be cooked
AssetRegistry.GetAssetsByPath(Path, AssetDatas, SearchMode == EPackageSearchMode::Recurse, true);
for (const FAssetData& AssetData : AssetDatas)
{
if (AssetData.IsUAsset() && AssetManager.VerifyCanCookPackage(nullptr, AssetData.PackageName, false))
{
if (AllowAssetToBeGathered(AssetData))
{
Packages.Add(AssetData.PackageName);
UE_LOG(LogCookedEditorTargetPlatform, Verbose, TEXT(" Adding asset %s to be cooked"), *AssetData.PackageName.ToString());
}
}
else
{
UE_LOG(LogCookedEditorTargetPlatform, Verbose, TEXT(" skipping asset package %s"), *AssetData.PackageName.ToString());
}
}
}
void ICookedEditorPackageManager::GatherAllPackagesExceptDisabled(TArray<FName>& PackageNames, const ITargetPlatform* TargetPlatform, const TArray<FString>& DisabledPlugins) const
{
GetEnginePackagesToCook(PackageNames);
GetProjectPackagesToCook(PackageNames);
// copy array to set for faster contains calls
TSet<FString> CookedEditorDisabledPlugins;
CookedEditorDisabledPlugins.Append(DisabledPlugins);
// walk over plugins and cook their content
for (TSharedRef<IPlugin> Plugin : IPluginManager::Get().GetEnabledPluginsWithContent())
{
if (!CookedEditorDisabledPlugins.Contains(Plugin->GetName()))
{
// check if this engine or project plugin shuold be cooked
bool bShouldCook = (Plugin->GetLoadedFrom() == EPluginLoadedFrom::Engine) ? AllowEnginePluginContentToBeCooked(Plugin) :
AllowProjectPluginContentToBeCooked(Plugin);
if (bShouldCook)
{
UE_LOG(LogCookedEditorTargetPlatform, Display, TEXT("Adding enabled plugin with content: %s"), *Plugin->GetName());
AddPackagesFromPath(PackageNames, *Plugin->GetMountedAssetPath(), EPackageSearchMode::Recurse);
}
}
}
FilterGatheredPackages(PackageNames);
}
void ICookedEditorPackageManager::FilterGatheredPackages(TArray<FName>& PackageNames) const
{
}
FIniCookedEditorPackageManager::FIniCookedEditorPackageManager(bool bInIsCookedCooker)
: bIsCookedCooker(bInIsCookedCooker)
{
EngineAssetPaths = GetConfigArray(TEXT("EngineAssetPaths"));
ProjectAssetPaths = GetConfigArray(TEXT("ProjectAssetPaths"));
DisallowedPathsToGather = GetConfigArray(TEXT("DisallowedPathsToGather"));
DisabledPlugins = GetConfigArray(TEXT("DisabledPlugins"));
TArray<FString> DisallowedObjectClassNamesToLoad = GetConfigArray(TEXT("DisallowedObjectClassesToLoad"));;
for (const FString& ClassName : DisallowedObjectClassNamesToLoad)
{
check(FPackageName::IsValidObjectPath(ClassName));
UClass* Class = FindObject<UClass>(nullptr, *ClassName);
check(Class);
DisallowedObjectClassesToLoad.Add(Class);
}
TArray<FString> DisallowedAssetClassNamesToGather = GetConfigArray(TEXT("DisallowedAssetClassesToGather"));;
for (const FString& ClassName : DisallowedAssetClassNamesToGather)
{
check(FPackageName::IsValidObjectPath(ClassName));
UClass* Class = FindObject<UClass>(nullptr, *ClassName);
check(Class);
DisallowedAssetClassesToGather.Add(Class);
}
}
TArray<FString> FIniCookedEditorPackageManager::GetConfigArray(const TCHAR* Key) const
{
const TCHAR* SharedIniSection = TEXT("CookedEditorSettings");
const TCHAR* SpecificiIniSection = bIsCookedCooker ? TEXT("CookedEditorSettings_CookedCooker") : TEXT("CookedEditorSettings_CookedEditor");
TArray<FString> TempArray;
TArray<FString> ResultArray;
GConfig->GetArray(SpecificiIniSection, Key, ResultArray, GGameIni);
GConfig->GetArray(SharedIniSection, Key, TempArray, GGameIni);
ResultArray.Append(TempArray);
return ResultArray;
}
void FIniCookedEditorPackageManager::GatherAllPackages(TArray<FName>& PackageNames, const ITargetPlatform* TargetPlatform) const
{
GatherAllPackagesExceptDisabled(PackageNames, TargetPlatform, DisabledPlugins);
}
void FIniCookedEditorPackageManager::FilterGatheredPackages(TArray<FName>& PackageNames) const
{
// now filter based on ini settings
PackageNames.RemoveAll([this](FName& AssetPath)
{
for (const FString& Path : DisallowedPathsToGather)
{
if (AssetPath.ToString().StartsWith(Path))
{
return true;
}
}
return false;
});
PackageNames.Remove(NAME_None);
}
void FIniCookedEditorPackageManager::GetEnginePackagesToCook(TArray<FName>& PackagesToCook) const
{
for (const FString& Path : EngineAssetPaths)
{
AddPackagesFromPath(PackagesToCook, *Path, EPackageSearchMode::Recurse);
}
// specific assets to cook
PackagesToCook.Append(GetConfigArray(TEXT("EngineSpecificAssetsToCook")));
}
void FIniCookedEditorPackageManager::GetProjectPackagesToCook(TArray<FName>& PackagesToCook) const
{
for (const FString& Path : ProjectAssetPaths)
{
AddPackagesFromPath(PackagesToCook, *Path, EPackageSearchMode::Recurse);
}
// make sure editor startup map is cooked
FString EditorStartupMap;
if (GConfig->GetString(TEXT("/Script/EngineSettings.GameMapsSettings"), TEXT("EditorStartupMap"), EditorStartupMap, GEngineIni))
{
PackagesToCook.Add(*EditorStartupMap);
}
// specific assets to cook
PackagesToCook.Append(GetConfigArray(TEXT("ProjectSpecificAssetsToCook")));
}
bool FIniCookedEditorPackageManager::AllowObjectToBeCooked(const class UObject* Obj) const
{
for (UClass* Class : DisallowedObjectClassesToLoad)
{
if (Obj->IsA(Class))
{
return false;
}
}
return true;
}
bool FIniCookedEditorPackageManager::AllowAssetToBeGathered(const struct FAssetData& AssetData) const
{
for (UClass* Class : DisallowedAssetClassesToGather)
{
if (AssetData.IsInstanceOf(Class))
{
return false;
}
}
return true;
}
bool FIniCookedEditorPackageManager::AllowEnginePluginContentToBeCooked(const TSharedRef<IPlugin>) const
{
return true;
}
bool FIniCookedEditorPackageManager::AllowProjectPluginContentToBeCooked(const TSharedRef<IPlugin>) const
{
return true;
}