123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734 |
- // Copyright 2017-2021 marynate. All Rights Reserved.
- #pragma once
- #include "ExtContentBrowser.h"
- #include "ExtContentBrowserTypes.h"
- #include "CoreMinimal.h"
- #include "UObject/ObjectMacros.h"
- #include "UObject/LinkerLoad.h"
- #include "AssetRegistry/AssetData.h"
- #include "AssetRegistry/AssetDataTagMap.h"
- #include "EditorFramework/AssetImportData.h"
- #include "Misc/AssetRegistryInterface.h"
- #include "HAL/Runnable.h"
- #include "ExtFeedbackContextEditor.h"
- #include "HAL/FeedbackContextAnsi.h"
- #include "Serialization/BufferArchive.h"
- #include "ExtAssetData.generated.h"
- struct FExtAssetIdentifier;
- struct FARFilter;
- struct FExtAssetDependencyNode;
- struct FExtAssetDependencyWalker;
- /**
- *
- */
- struct FExtAssetRegistryVersion
- {
- enum Type
- {
- // Before any version changes were made
- BeforeCustomVersionWasAdded = 0,
- SaveLoadNameBatch, // 4.27+
- // -----<new versions can be added above this line>-------------------------------------------------
- VersionPlusOne,
- LatestVersion = VersionPlusOne - 1
- };
- // The GUID for this custom version number
- const static FGuid GUID;
- /** Read/write the custom version to the archive, should call at the very beginning */
- static bool SerializeVersion(FArchive& Ar, FExtAssetRegistryVersion::Type& Version);
- private:
- FExtAssetRegistryVersion() {}
- };
- /**
- * Holds info of supported asset type/extensions
- */
- struct FExtAssetSupport
- {
- static FString AssetPackageExtension;
- static FString MapPackageExtension;
- static FString TextAssetPackageExtension;
- static FString TextMapPackageExtension;
- static FORCEINLINE bool IsSupportedPackageFilename(const FString& Filename)
- {
- const bool bShouldSupportMapPackage = true;
- const bool bIsAssetPackage = Filename.EndsWith(FExtAssetSupport::AssetPackageExtension);
- const bool bIsMapMapPackage = Filename.EndsWith(FExtAssetSupport::MapPackageExtension);
- return bShouldSupportMapPackage ? (bIsAssetPackage || bIsMapMapPackage) : bIsAssetPackage;
- }
- };
- /**
- * Holds Constants used in ExtAsstData
- */
- namespace FExtAssetContants
- {
- const FString ExtTempPackagePath(TEXT("/Temp/UAssetBrowser"));
- const FString ExtSandboxPackagePath(TEXT("/UAssetBrowser/Sandbox"));
- const FName DefaultImportedUAssetCollectionName(TEXT("ImportedUAssets"));
- };
- #if ECB_WIP_ASSETREGISTRY_SERIALIZATION
- /** Version used for serializing ext asset registry caches */
- struct ASSETREGISTRY_API FExtAssetRegistryVersion
- {
- enum Type
- {
- PreVersioning = 0, // From before file versioning was implemented
- // -----<new versions can be added above this line>-------------------------------------------------
- VersionPlusOne,
- LatestVersion = VersionPlusOne - 1
- };
- /** The GUID for this custom version number */
- const static FGuid GUID;
- /** Read/write the custom version to the archive, should call at the very beginning */
- static bool SerializeVersion(FArchive& Ar, FAssetRegistryVersion::Type& Version);
- private:
- FExtAssetRegistryVersion() {}
- };
- #endif
- /**
- * A struct to hold external asset information
- */
- USTRUCT(BlueprintType)
- struct FExtAssetData
- {
- GENERATED_BODY()
- public:
- enum class EInvalidReason :uint8
- {
- NotParsed,
- Valid,
- // File Path
- FileNotFound,
- FilePathEmptyOrInvalid,
- FilePathContainsInvalidCharacter,
- // From LinkerLoad
- FailedToLoadPackage,
- // From Package Reader
- PackageFileVersionEmptyOrTooOld,
- PackageFileOrCustomVersionTooNew,
- PackageFileMalformed,
- PackageFileCustomVersionMissing,
- PackageFileFailedToLoad,
- // Basic info
- NoAssetData,
- AssetNameEmpty,
- ClassNameEmpty,
- // Not Supported Type
- GenericAssetTypeNotSupported,
- RedirectorNotSupported,
- ClassAssetNotSupported,
- TextForamtNotSupported,
- CookedPackageNotSupported,
- NotCompatiableWithCurrentEngineVersion,
- Unknown
- };
- enum class EContentType :uint8
- {
- Plugin,
- Project,
- VaultCache,
- Orphan,
- PartialProject,
- Unknown
- };
- public:
- /** Full file path to package disk file */
- UPROPERTY(BlueprintReadOnly, Category = AssetData, transient)
- FName PackageFilePath;
- /** The name of the package in which the asset is found, this is the full long package name such as /Game/Path/Package */
- UPROPERTY(BlueprintReadOnly, Category = AssetData, transient)
- FName PackageName;
- /** The path to the package in which the asset is found, this is /Game/Path with the Package stripped off */
- UPROPERTY(BlueprintReadOnly, Category = AssetData, transient)
- FName PackagePath;
- /** The object path for the asset in the form PackageName.AssetName. e.g. /Game/Path/Package.AssetName */
- UPROPERTY(BlueprintReadOnly, Category = AssetData, transient)
- FName ObjectPath;
- /** The name of the asset without the package */
- UPROPERTY(BlueprintReadOnly, Category = AssetData, transient)
- FName AssetName;
- /** The name of the asset's class */
- UPROPERTY(BlueprintReadOnly, Category = AssetData, transient)
- FName AssetClass;
- /** Asset data to satisfy FAssetData based interface. */
- UPROPERTY(BlueprintReadOnly, Category = AssetData, transient)
- FAssetData AssetData;
- // Content root of current asset
- FName AssetContentRoot = NAME_None;
- // Content root folder name, can get from AssetContentRootDir but cache here for performance
- //FName AssetContentRootDirName = NAME_None;
- // Relative path to asset content root
- FName AssetRelativePath = NAME_None;
- // Asset content type: plugin/project/vaultcahce/orphan
- EContentType AssetContentType;
- /** Asset registry tags */
- FAssetDataTagMapSharedView TagsAndValues;
- /** Hard Dependencies */
- TSet<FName> HardDependentPackages;
- /** Soft References */
- TSet<FName> SoftReferencesList;
- /** UE4 file version */
- int32 FileVersionUE4 = 0;
- /** Engine version this package was saved with.*/
- FEngineVersion SavedByEngineVersion;
- /** Engine version this package is compatible with. See SavedByEngineVersion. */
- FEngineVersion CompatibleWithEngineVersion;
- /** Gathered invalid reason */
- EInvalidReason InvalidReason;
- #if 1 //ECB_DEBUG
- int32 AssetCount = 0;
- int32 ThumbCount = 0;
- int64 FileSize = 0;
- #endif
- public:
- /** Default Constructor. */
- FExtAssetData();
- /** Constructor taking a package file path. */
- FExtAssetData(const FString& InPackageFilePath, bool bDelayParse = false);
- /** Constructor taking a UObject. By default trying to create one for a blueprint class will create one for the UBlueprint instead, but this can be overridden */
- FExtAssetData(const UObject* InAsset, bool bAllowBlueprintClass = false);
- /** Constructor taking a package name. For support wrapping an internal package */
- FExtAssetData(const FName& InPackageName);
- /** Parse .uasset file to gather asset data, assume package file path has been assigned in constructor */
- bool Parse();
- bool ReParse();
- /** Check if has thumbnail data. */
- bool HasThumbnail() const;
- void SetHasThumbnail(bool bInHasThumbnail)
- {
- bHasThumbnail = bInHasThumbnail;
- }
- /** Check if asset has valid content root (project or vault cache data folder) */
- bool HasContentRoot() const;
- /** Load and check if has valid thumbnail data. */
- bool HasValidThumbnail() const;
- /** Check if can import this asset in fastest way */
- bool CanImportFast() const;
- /** Load thumbnail from package. */
- bool LoadThumbnail(FObjectThumbnail& OutThumbnail) const;
- #if ECB_LEGACY
- /** Load soft package references from package. */
- void LoadSoftReferences(TArray<FName>& OutSoftReferences) const;
- #endif
- /** Get saved engine version string */
- FString GetSavedEngineVersionForDisplay() const;
- const FString& GetAssetContentTypeForDisplay() const;
- /** Checks compatibility with current engine version. */
- bool IsCompatibleWithCurrentEngineVersion() const;
- FString GetInvalidReason() const;
- public: // AssetData compatible interface
- /** Prints the details of the asset to the log */
- void PrintAssetData() const;
- /** Check if is parsed and has valid asset name */
- bool IsValid() const
- {
- return bParsed && bValid;//&& AssetName != NAME_None;
- }
- bool IsUAsset() const;
- /**
- * Returns true iff the Asset is a TopLevelAsset (not a subobject, its outer is a UPackage).
- * Only TopLevelAssets can be PrimaryAssets in the AssetManager.
- * A TopLevelAsset is not necessarily the main asset in a package; see IsUAsset.
- * Note that this is distinct from UObject::IsAsset because IsAsset can be overloaded (see e.g. AActor::IsAsset)
- */
- bool IsTopLevelAsset() const;
- bool IsUMap() const;
- /** Check if is parsed and has valid asset name */
- bool IsParsed() const
- {
- return bParsed;
- }
- /** Returns true if the asset is loaded */
- bool IsAssetLoaded() const
- {
- return IsValid() && FindObjectSafe<UObject>(NULL, *ObjectPath.ToString()) != NULL;
- }
- /** Try and get the value associated with the given tag as a type converted value */
- template <typename ValueType>
- bool GetTagValue(const FName InTagName, ValueType& OutTagValue) const;
- UClass* GetIconClass(bool* bOutIsClassType) const;
- /** Returns the asset UObject if it is loaded or loads the asset if it is unloaded then returns the result */
- UObject* GetAsset() const
- {
- if (!IsValid())
- {
- // Dont even try to find the object if the objectpath isn't set
- return NULL;
- }
- UObject* Asset = FindObject<UObject>(NULL, *ObjectPath.ToString());
- if (Asset == NULL)
- {
- Asset = LoadObject<UObject>(NULL, *ObjectPath.ToString());
- }
- return Asset;
- }
- /** Returns the full name for the asset in the form: Class ObjectPath */
- FString GetFullName() const
- {
- FString FullName;
- GetFullName(FullName);
- return FullName;
- }
- /** Convert to a SoftObjectPath. PackageName.AssetName for ToplevelAssets. OptionalOuterName and AssetName joined by : or . for sub-object assets */
- FSoftObjectPath GetSoftObjectPath() const;
- /** Returns the folder path of the asset package file */
- FString GetFolderPath() const;
- /** Populates OutFullName with the full name for the asset in the form: Class ObjectPath */
- void GetFullName(FString& OutFullName) const
- {
- OutFullName.Reset();
- AssetClass.AppendString(OutFullName);
- OutFullName.AppendChar(' ');
- ObjectPath.AppendString(OutFullName);
- }
- /** Returns the class UClass if it is loaded. It is not possible to load the class if it is unloaded since we only have the short name. */
- UClass* GetClass() const
- {
- if (!IsValid())
- {
- // Dont even try to find the class if the objectpath isn't set
- return NULL;
- }
- UClass* FoundClass = FindObject<UClass>(nullptr, *AssetClass.ToString());
- if (!FoundClass)
- {
- // Look for class redirectors
- FName NewPath = FLinkerLoad::FindNewNameForClass(AssetClass, false);
- if (NewPath != NAME_None)
- {
- FoundClass = FindObject<UClass>(nullptr, *NewPath.ToString());
- }
- }
- return FoundClass;
- }
- bool operator==(const FExtAssetData& Other) const
- {
- return ObjectPath == Other.ObjectPath;
- }
- bool operator!=(const FExtAssetData& Other) const
- {
- return ObjectPath != Other.ObjectPath;
- }
- #if ECB_WIP_CACHEDB
- template<class Archive>
- void SerializeForCache(Archive&& Ar);
- #endif
- static FString ConvertFilePathToTempPackageName(const FString& InFilePath);
- static FString& GetSandboxPackagePath();
- static FString& GetSandboxPackagePathWithSlash();
- static FString& GetSandboxDir();
- static FString& GetUAssetBrowserTempDir();
- static FString& GetImportSessionTempDir();
- static FString GetZipExportSessionTempDir();
- public:
- private:
- /** Parse .uasset file to gather asset data */
- bool PreParse();
- /** Parse .uasset file to gather asset data */
- bool DoParse();
- void AppendObjectPath(FString& String) const
- {
- TStringBuilder<FName::StringBufferSize> Builder;
- AppendObjectPath(Builder);
- String.Append(FString(Builder));
- }
- /** Append the object path to the given string builder. */
- void AppendObjectPath(FStringBuilderBase& Builder) const
- {
- if (!IsValid())
- {
- return;
- }
- #if WITH_EDITORONLY_DATA
- if (!OptionalOuterPath.IsNone())
- {
- UE::AssetRegistry::Private::ConcatenateOuterPathAndObjectName(Builder, OptionalOuterPath, AssetName);
- }
- else
- #endif
- {
- Builder << PackageName << '.' << AssetName;
- }
- }
- void CheckIfCompatibleWithCurrentEngineVersion();
- private:
- /** If the package has been parsed */
- bool bParsed;
- /** If the package is valid */
- bool bValid;
- /** If has thumbnail data */
- bool bHasThumbnail;
- /** If the package is compatible with current engine version */
- bool bCompatible;
- #if WITH_EDITORONLY_DATA
- /**
- * If this object is not a top level asset, this contains the path of the outer of this object.
- * Non top-level assets may only be used in the editor.
- * For some assets (such as external actors) this may not start with PackageName.
- * e.g. PackageName = /Game/__EXTERNAL_ACTORS__/Maps/MyMap/ABCDE12345
- OptionalOuterPath = /Game/Maps/MyMap.MyMap:PersistentLevel
- AssetName = SomeExternalActor
- */
- FName OptionalOuterPath;
- #endif
- };
- FORCEINLINE uint32 GetTypeHash(const FExtAssetData& AssetData)
- {
- return GetTypeHash(AssetData.PackageFilePath);
- }
- struct FExtAssetDataUtil
- {
- #if 0
- static bool RemapPackagesToFullFilePath(const FString& InPackageName, const TArray<FString>& InRootPackageNamesToReplace, const FString& InAssetContentDir, FString& OutFullFilePath);
- #endif
- static FString GetPluginNameFromAssetContentRoot(const FString& InAssetContentDir);
- static FString GetPackageRootFromFullPackagePath(const FString& InFullPackagePath);
- static bool RemapGamePackageToFullFilePath(const FString& InGameRoot, const FString& InPackageName, const FString& InAssetContentDir, FString& OutFullFilePath, bool bPackageIsFolder = false);
- static bool SyncToContentBrowser(const FExtAssetData& InAssetData);
- };
- namespace FExtAssetCoreUtil
- {
- class FExtAssetFeedbackContext : public FExtFeedbackContextEditor
- {
- public:
- /**
- * cache the cancel result as FExtFeedbackContextEditor::ReceivedUserCancel seems clears the result right away
- */
- virtual bool ReceivedUserCancel() override;
- private:
- bool bTaskWasCancelledCache = false;
- };
- class IExtAssetProgressReporter
- {
- public:
- virtual ~IExtAssetProgressReporter() = default;
- virtual void BeginWork(const FText& InDescription, float InAmountOfWork, bool bInterruptible = true) = 0;
- virtual void EndWork() = 0;
- virtual void ReportProgress(float IncrementOfWork, const FText& InMessage) = 0;
- virtual bool IsWorkCancelled() = 0;
- virtual FFeedbackContext* GetFeedbackContext() const = 0;
- };
- class FExtAssetWorkReporter
- {
- public:
- FExtAssetWorkReporter(const TSharedPtr<IExtAssetProgressReporter>& InReporter, const FText& InDescription, float InAmountOfWork, float InIncrementOfWork, bool bInterruptible);
-
- ~FExtAssetWorkReporter();
- void ReportNextStep(const FText& InMessage, float InIncrementOfWork);
- void ReportNextStep(const FText& InMessage);
- bool IsWorkCancelled() const;
- private:
- TSharedPtr<IExtAssetProgressReporter> Reporter;
- float DefaultIncrementOfWork;
- };
- class FExtAssetProgressUIReporter : public IExtAssetProgressReporter
- {
- public:
- FExtAssetProgressUIReporter()
- : bIsCancelled(false)
- {
- }
- FExtAssetProgressUIReporter(TSharedRef<FFeedbackContext> InFeedbackContext)
- : FeedbackContext(InFeedbackContext)
- , bIsCancelled(false)
- {
- }
- virtual ~FExtAssetProgressUIReporter()
- {
- }
- /* begin IExtAssetProgressReporter interface */
- virtual void BeginWork(const FText& InTitle, float InAmountOfWork, bool bInterruptible = true) override;
- virtual void EndWork() override;
- virtual void ReportProgress(float Progress, const FText& InMessage) override;
- virtual bool IsWorkCancelled() override;
- FFeedbackContext* GetFeedbackContext() const override;
- /* end IExtAssetProgressReporter interface */
- private:
- TArray< TSharedPtr< FScopedSlowTask > > ProgressTasks;
- TSharedPtr< FFeedbackContext > FeedbackContext;
- bool bIsCancelled;
- };
- class FExtAssetProgressTextReporter : public IExtAssetProgressReporter
- {
- public:
- FExtAssetProgressTextReporter()
- : TaskDepth(0)
- , FeedbackContext(new FFeedbackContextAnsi)
- {
- }
- virtual ~FExtAssetProgressTextReporter()
- {
- }
- // Begin IDataprepProgressReporter interface
- virtual void BeginWork(const FText& InTitle, float InAmountOfWork, bool bInterruptible = true) override;
- virtual void EndWork() override;
- virtual void ReportProgress(float Progress, const FText& InMessage) override;
- virtual bool IsWorkCancelled() override;
- virtual FFeedbackContext* GetFeedbackContext() const override;
- private:
- int32 TaskDepth;
- TUniquePtr<FFeedbackContextAnsi> FeedbackContext;
- };
- }
- /**
- * Collection Util
- */
- struct FExtCollectionUtil
- {
- static FName GetOrCreateCollection(FName CollectionName, bool bUniqueCollection);
- static bool AddAssetsToCollection(const TArray<FAssetData>& InAssets, FName InCollectionName, bool bUniqueCollection);
- };
- /**
- * FAssetData Util
- */
- struct FAssetDataUtil
- {
- static void PlaceToCurrentLevelViewport(const TArray<FAssetData>& InAssets);
- static void ExportAssetsWithDialog(const TArray<FAssetData>& InAssets);
- };
- /**
- *A structure defining a thing that can be reference by something else in the asset registry. Represents either a package of a primary asset id
- */
- struct FExtAssetIdentifier
- {
- /** The name of the package that is depended on, this is always set unless PrimaryAssetType is */
- FName PackageName;
- /** The primary asset type, if valid the ObjectName is the PrimaryAssetName */
- FPrimaryAssetType PrimaryAssetType;
- /** Specific object within a package. If empty, assumed to be the default asset */
- FName ObjectName;
- /** Name of specific value being referenced, if ObjectName specifies a type such as a UStruct */
- FName ValueName;
- /** Can be implicitly constructed from just the package name */
- FExtAssetIdentifier(FName InPackageName, FName InObjectName = NAME_None, FName InValueName = NAME_None)
- : PackageName(InPackageName), PrimaryAssetType(NAME_None), ObjectName(InObjectName), ValueName(InValueName)
- {}
- /** Construct from a primary asset id */
- FExtAssetIdentifier(const FPrimaryAssetId& PrimaryAssetId, FName InValueName = NAME_None)
- : PackageName(NAME_None), PrimaryAssetType(PrimaryAssetId.PrimaryAssetType), ObjectName(PrimaryAssetId.PrimaryAssetName), ValueName(InValueName)
- {}
- FExtAssetIdentifier(UObject* SourceObject, FName InValueName)
- {
- if (SourceObject)
- {
- UPackage* Package = SourceObject->GetOutermost();
- PackageName = Package->GetFName();
- ObjectName = SourceObject->GetFName();
- ValueName = InValueName;
- }
- }
- FExtAssetIdentifier()
- : PackageName(NAME_None), PrimaryAssetType(NAME_None), ObjectName(NAME_None), ValueName(NAME_None)
- {}
- /** Returns primary asset id for this identifier, if valid */
- FPrimaryAssetId GetPrimaryAssetId() const
- {
- if (PrimaryAssetType != NAME_None)
- {
- return FPrimaryAssetId(PrimaryAssetType, ObjectName);
- }
- return FPrimaryAssetId();
- }
- /** Returns true if this represents a package */
- bool IsPackage() const
- {
- return PackageName != NAME_None && !IsObject() && !IsValue();
- }
- /** Returns true if this represents an object, true for both package objects and PrimaryAssetId objects */
- bool IsObject() const
- {
- return ObjectName != NAME_None && !IsValue();
- }
- /** Returns true if this represents a specific value */
- bool IsValue() const
- {
- return ValueName != NAME_None;
- }
- /** Returns true if this is a valid non-null identifier */
- bool IsValid() const
- {
- return PackageName != NAME_None || GetPrimaryAssetId().IsValid();
- }
- /** Returns string version of this identifier in Package.Object::Name format */
- FString ToString() const
- {
- FString Result;
- if (PrimaryAssetType != NAME_None)
- {
- Result = GetPrimaryAssetId().ToString();
- }
- else
- {
- Result = PackageName.ToString();
- if (ObjectName != NAME_None)
- {
- Result += TEXT(".");
- Result += ObjectName.ToString();
- }
- }
- if (ValueName != NAME_None)
- {
- Result += TEXT("::");
- Result += ValueName.ToString();
- }
- return Result;
- }
- /** Converts from Package.Object::Name format */
- static FExtAssetIdentifier FromString(const FString& String)
- {
- // To right of :: is value
- FString PackageString;
- FString ObjectString;
- FString ValueString;
- // Try to split value out
- if (!String.Split(TEXT("::"), &PackageString, &ValueString))
- {
- PackageString = String;
- }
- // Check if it's a valid primary asset id
- FPrimaryAssetId PrimaryId = FPrimaryAssetId::FromString(PackageString);
- if (PrimaryId.IsValid())
- {
- return FExtAssetIdentifier(PrimaryId, *ValueString);
- }
- // Try to split on first . , if it fails PackageString will stay the same
- FString(PackageString).Split(TEXT("."), &PackageString, &ObjectString);
- return FExtAssetIdentifier(*PackageString, *ObjectString, *ValueString);
- }
- friend inline bool operator==(const FExtAssetIdentifier& A, const FExtAssetIdentifier& B)
- {
- return A.PackageName == B.PackageName && A.ObjectName == B.ObjectName && A.ValueName == B.ValueName;
- }
- friend inline uint32 GetTypeHash(const FExtAssetIdentifier& Key)
- {
- uint32 Hash = 0;
- // Most of the time only packagename is set
- if (Key.ObjectName.IsNone() && Key.ValueName.IsNone())
- {
- return GetTypeHash(Key.PackageName);
- }
- Hash = HashCombine(Hash, GetTypeHash(Key.PackageName));
- Hash = HashCombine(Hash, GetTypeHash(Key.PrimaryAssetType));
- Hash = HashCombine(Hash, GetTypeHash(Key.ObjectName));
- Hash = HashCombine(Hash, GetTypeHash(Key.ValueName));
- return Hash;
- }
- /** Identifiers may be serialized as part of the registry cache, or in other contexts. If you make changes here you must also change FAssetRegistryVersion */
- friend FArchive& operator<<(FArchive& Ar, FExtAssetIdentifier& AssetIdentifier)
- {
- // Serialize bitfield of which elements to serialize, in general many are empty
- uint8 FieldBits = 0;
- if (Ar.IsSaving())
- {
- FieldBits |= (AssetIdentifier.PackageName != NAME_None) << 0;
- FieldBits |= (AssetIdentifier.PrimaryAssetType != NAME_None) << 1;
- FieldBits |= (AssetIdentifier.ObjectName != NAME_None) << 2;
- FieldBits |= (AssetIdentifier.ValueName != NAME_None) << 3;
- }
- Ar << FieldBits;
- if (FieldBits & (1 << 0))
- {
- Ar << AssetIdentifier.PackageName;
- }
- if (FieldBits & (1 << 1))
- {
- FName TypeName = AssetIdentifier.PrimaryAssetType.GetName();
- Ar << TypeName;
- if (Ar.IsLoading())
- {
- AssetIdentifier.PrimaryAssetType = TypeName;
- }
- }
- if (FieldBits & (1 << 2))
- {
- Ar << AssetIdentifier.ObjectName;
- }
- if (FieldBits & (1 << 3))
- {
- Ar << AssetIdentifier.ValueName;
- }
- return Ar;
- }
- };
- enum class EDependencyNodePackageType : uint8
- {
- File,
- Script,
- Engine,
- Other,
- };
- enum class EDependencyNodeReferenceType : uint8
- {
- Hard,
- Soft
- };
- enum class EDependencyNodeStatus : uint8
- {
- Unknown,
- AbortGathering,
- Missing,
- Invalid,
- Valid,
- ValidWithSoftReferenceIssue
- };
- /**
- * Dependency info gathered for asset data
- */
- struct FExtAssetDependencyInfo
- {
- // ---------------- Source -----------------
- TArray<FString> ValidDependentFiles;
- TArray<FString> InvalidDependentFiles;
- TArray<FString> MissingDependentFiles;
- TArray<FString> SkippedPackageNames;
- TArray<FString> MissingPackageNames;
- TMap<FName, EDependencyNodeStatus> AllDepdencyPackages; // PakcaegName - DependencyStatus map, dependencies only (not include main asset)
- TMap<FName, TArray<FExtAssetDependencyNode>> AssetDepdencies; // Asset File Path - DependencyNode map
- EDependencyNodeStatus AssetStatus = EDependencyNodeStatus::Unknown;
- bool IsValid(bool bIgnoreSoftIssue = true);
- void Print();
- #if ECB_WIP_CACHEDB
- friend FArchive& operator<<(FArchive& Ar, FExtAssetDependencyInfo& InDependencyInfo);
- #endif
- };
- struct FExtAssetDependencyNode
- {
- FExtAssetDependencyNode(const FName& InPackageName, EDependencyNodeStatus InNodeStatus, bool bSoftReference)
- : PackageName(InPackageName)
- , NodeStatus(InNodeStatus)
- {
- ReferenceType = bSoftReference ? EDependencyNodeReferenceType::Soft : EDependencyNodeReferenceType::Hard;
- }
- FExtAssetDependencyNode() {}
- FName PackageName = NAME_None;
- EDependencyNodeReferenceType ReferenceType = EDependencyNodeReferenceType::Hard;
- EDependencyNodeStatus NodeStatus = EDependencyNodeStatus::Valid;
- static FString GetStatusString(EDependencyNodeStatus InStatus);
- FString ToString() const;
- #if ECB_WIP_CACHEDB
- friend FArchive& operator<<(FArchive& Ar, FExtAssetDependencyNode& InDependencyNode);
- #endif
- };
- struct FExtAssetDependencyWalker
- {
- static EDependencyNodeStatus GatherDependencies(const FExtAssetData& InAssetData, const FString& InAssetContentDir, const FExtAssetData::EContentType& InAssetContentType, FExtAssetDependencyInfo& InOuDependencyInfo, bool bShowProgess = false);
- private:
- static EDependencyNodeStatus GatherDependencies(const FExtAssetData& InAssetData, const FString& InAssetContentDir, const FExtAssetData::EContentType& InAssetContentType, FExtAssetDependencyInfo& InOuDependencyInfo, int32 Level, FScopedSlowTask* SlowTaskPtr = nullptr);
- static EDependencyNodeStatus GatherPackageDependencies(const FName& DependPackageName, FExtAssetDependencyInfo& InOuDependencyInfo
- , const FString& InAssetContentDir, const FExtAssetData::EContentType& InAssetContentType
- , int32& Level, bool bSoftReference, FScopedSlowTask* SlowTaskPtr = nullptr);
- };
- struct FRootContentPathInfo
- {
- FExtAssetData::EContentType ContentType;
- FString AssetContentRoot;
- FText DisplayName;
- #if ECB_WIP_CACHEDB
- friend FArchive& operator<<(FArchive& Ar, FRootContentPathInfo& InDependencyInfo);
- #endif
- };
- /**
- * Cache asset registry state in memory or disk, currently only in memory cache
- */
- class FExtAssetRegistryStateCache
- {
- public:
- void Reset();
- void ClearThumbnailCache();
- void CacheNewAsset(FExtAssetData* InAssetToCache);
- void ReCacheParsedAsset(FExtAssetData* InAssetToCache);
- void UpdateCacheByRemovedFolders(const TArray<FString>& InRemovedFolders);
- bool PurgeAssets(bool bSilent = true);
- void PrintStatus() const;
- /** Returns memory size of entire registry, optionally logging sizes */
- //uint32 GetAllocatedSize(bool bLogDetailed = false) const;
- #if ECB_WIP_CACHEDB
- template<class Archive>
- bool SerializeForCache(Archive&& Ar);
- int32 NumFoldersInCache = 0;
- int32 NumAssetsInCache = 0;
- #endif
- private:
- #if ECB_WIP_CACHEDB
- bool Save(FArchive& Ar);
- bool Load(FArchive& Ar);
- template<class Archive>
- void Load(Archive&& Ar, FExtAssetRegistryVersion::Type Version);
- void SetAssetDatas(TArrayView<FExtAssetData> AssetDatas);
- void SerializeDependencyInfos(FArchive& Ar);
- void SerializeMisc(FArchive& Ar);
- TArray<FExtAssetData*> PreallocatedAssetDataBuffers;
- #endif
- public:
- /** Mirrored Root Content Paths Info Copied from ExtAssetRegistry */
- TArray<FString> CachedRootContentPaths;
- /** A one-to-many mapping between a parent path and its child paths*/
- TMap<FName, TSet<FName>> CachedSubPaths;
- /** The array of empty folders which contains no package recursively */
- TMap<FName, bool> CachedEmptyFoldersStatus;
- /** The set of folders have uasset been fully parsed */
- TSet<FName> CachedFullyParsedFolders;
- /** The map of long package folder path to asset data */
- TMap<FName, TArray<FExtAssetData*> > CachedAssetsByFolder;
- /** A one-to-many mapping between a folder to packages' file path in the folder */
- TMap<FName, TArray<FName>> CachedFilePathsByFolder;
- /** The map of asset file path to asset data */
- TMap<FName, FExtAssetData*> CachedAssetsByFilePath;
- /** Assets been cached but not yet parsed, subset of CachedAssetsByFilePath */
- TMap<FName, FExtAssetData*> CachedUnParsedAssets;
- /** The map of asset file path to asset data */
- TMap<FName, FExtAssetDependencyInfo> CachedDependencyInfoByFilePath;
- /** Cached Asset Thumbnail data, could grows very fast when viewing large amount of assets */
- TMap<FName, FObjectThumbnail> CachedThumbnails; // todo: FIFO queue?
- /** The map of class name to asset data for assets saved to disk */
- TMap<FName, TArray<FExtAssetData*> > CachedAssetsByClass;
- /** The map of asset tag to asset data for assets saved to disk */
- TMap<FName, TArray<FExtAssetData*> > CachedAssetsByTag;
- /** The map of asset package name to file path */
- TMap<FName, FName> CachedPackageNameToFilePathMap;
- /** The array of asset content root dirs, sorted from longest to shortest */
- TArray<FName> CachedAssetContentRoots;
- TMap<FName, FExtAssetData::EContentType> CachedAssetContentType; // ContentRoot - ContentType
- TMap<FName, FName> CachedAssetContentRootHosts; // Host - ContentRoot
- TMap<FName, FName> CachedAssetContentRootConfigDirs; // ContentRoot - ConfigDir
- TMap<FName, TArray<FName>> CachedFolderColorIndices; // ContentRoot - Folders
- TMap<FName, FLinearColor> CachedFolderColors; // Folder - Color
- private:
- void CacheValidAssetInfo(FExtAssetData* InAssetToCache);
- };
- struct FExtFolderGatherResult
- {
- FExtFolderGatherResult(const FName& InRootPath, const FName& InParentPath, const TArray<FName>& InSubPaths, const TMap<FName, TArray<FName>>& InRecurseSubPaths, const TMap<FName, TArray<FName>>& InFolderPackages)
- : RootPath(InRootPath)
- , ParentPath(InParentPath)
- , SubPaths(InSubPaths)
- , RecurseSubPaths(InRecurseSubPaths)
- , FolderPakages(InFolderPackages)
- {}
- FName RootPath;
- FName ParentPath;
- TArray<FName> SubPaths;
- TMap<FName, TArray<FName>> RecurseSubPaths;
- TMap<FName, TArray<FName>> FolderPakages;
- };
- struct FExtAssetContentRootGatherResult
- {
- FExtAssetContentRootGatherResult(const FName& InAssetContentRootDir, const FName& InAssetContentRootHostDir, const FName& InAssetContentRootConfigDir, FExtAssetData::EContentType InAssetContentType)
- : AssetContentRoot(InAssetContentRootDir)
- , AssetContentRootHost(InAssetContentRootHostDir)
- , AssetContentRootConfigDir(InAssetContentRootConfigDir)
- , AssetContentType(InAssetContentType)
- {}
- FName AssetContentRoot;
- FName AssetContentRootHost;
- FName AssetContentRootConfigDir;
- FExtAssetData::EContentType AssetContentType;
- };
- struct FExtAssetGatherResult
- {
- FExtAssetGatherResult()
- {}
- TMap<FName, FExtAssetData> ParsedAssets;
- void AddReuslt(const FName& InFilePath, const FExtAssetData& InParsedAsset);
- bool HasResult() const;
- void Reset();
- const TMap<FName, FExtAssetData>& GetParsedAssets() const { return ParsedAssets; };
- };
- /**
- * Gather and cache information about uasset files and paths
- */
- class FExtAssetRegistry
- {
- public:
- ///////////////////////////////////////////////
- // Events
- //
- DECLARE_EVENT_OneParam(FExtAssetRegistry, FPathAddedEvent, const FString& /*Path*/);
- FPathAddedEvent& OnRootPathAdded() { return RootPathAddedEvent; }
- DECLARE_EVENT_OneParam(FExtAssetRegistry, FPathRemovedEvent, const FString& /*Path*/);
- FPathRemovedEvent& OnRootPathRemoved() { return RootPathRemovedEvent; }
- DECLARE_EVENT(FExtAssetRegistry, FPathUpdatedEvent);
- FPathUpdatedEvent& OnRootPathUpdated() { return RootPathUpdatedEvent; }
- DECLARE_EVENT_OneParam(FExtAssetRegistry, FFolderStartGatheringEvent, const TArray<FString>& /*Paths*/);
- FFolderStartGatheringEvent& OnFolderStartGathering() { return FolderStartGatheringEvent; }
- DECLARE_EVENT_TwoParams(FExtAssetRegistry, FFolderFinishGatheringEvent, const FString& /*GatheredPath*/, const FString& /*RootGatheredPath*/);
- FFolderFinishGatheringEvent& OnFolderFinishGathering() { return FolderFinishGatheringEvent; }
- DECLARE_EVENT_TwoParams(FExtAssetRegistry, FAssetGatheredEvent, const FExtAssetData& /*GatheredAsset*/, int32 /*Left*/);
- FAssetGatheredEvent& OnAssetGathered() { return AssetGatheredEvent; }
- DECLARE_EVENT_OneParam(FExtAssetRegistry, FAssetUpdatedEvent, const FExtAssetData& /*UpdatedAssets*/);
- FAssetUpdatedEvent& OnAssetUpdated() { return AssetUpdatedEvent; }
- void BroadcastAssetUpdatedEvent(const FExtAssetData& /*UpdatedAssets*/);
- ///////////////////////////////////////////////
- // Async Folder Gather
- //
- bool GetAndTrimFolderGatherResult();
- bool IsFolderBackgroundGathering(const FString& InFolder) const;
- FName GetCurrentGatheringFolder() const { return BackgroundGatheringSubFolder; }
- ///////////////////////////////////////////////
- // Async Asset Gather
- //
- bool GetAndTrimAssetGatherResult();
- //bool IsFolderBackgroundGathering(const FString& InFolder) const;
- //FName GetCurrentGatheringFolder() const { return BackgroundGatheringSubFolder; }
- private:
- /** The delegate to execute when an root content path is added to the registry */
- FPathAddedEvent RootPathAddedEvent;
- /** The delegate to execute when an root content path is removed from the registry */
- FPathRemovedEvent RootPathRemovedEvent;
- /** The delegate to execute when an root content path is removed from the registry */
- FPathUpdatedEvent RootPathUpdatedEvent;
- /** The delegate to execute when a folder path is start gathering from the registry */
- FFolderStartGatheringEvent FolderStartGatheringEvent;
- /** The delegate to execute when a folder path is finishing gathering from the registry */
- FFolderFinishGatheringEvent FolderFinishGatheringEvent;
- /** The delegate to execute when an asset is finishing gathering from the registry */
- FAssetGatheredEvent AssetGatheredEvent;
- FAssetUpdatedEvent AssetUpdatedEvent;
- public:
- FExtAssetRegistry();
- virtual ~FExtAssetRegistry();
- public:
- ///////////////////////////////////////////////
- // IAssetRegistry compatible interface
- //
- /** Gets asset data for all assets that match the filter. Alias of GetOrCacheExtAssets */
- bool GetAssets(const struct FARFilter& InFilter, TArray<FExtAssetData>& OutAssetData);
- /** Trims items out of the asset data list that do not pass the supplied filter */
- void RunAssetsThroughFilter(TArray<FExtAssetData>& AssetDataList, const FARFilter& Filter) const;
- /**
- * Gets a list of AssetIdentifiers or FAssetDependencies that reference the supplied AssetIdentifier. (On disk references ONLY)
- *
- * @param AssetIdentifier the name of the package/name for which to gather referencers (eg, /Game/MyFolder/MyAsset)
- * @param OutReferencers a list of things that reference AssetIdentifier.
- * @param Category which category(ies) of referencers to include in the output list. Referencers that have a dependency matching ANY of the OR'd categories will be returned.
- * @param Flags which flags are required present or not present on the referencer's dependency. Referencers that have a dependency matching ALL required and NONE excluded bits will be returned. For each potentially returned dependency, flags not applicable to their category are ignored.
- */
- bool GetReferencers(const FExtAssetIdentifier& AssetIdentifier, TArray<FExtAssetIdentifier>& OutReferencers, UE::AssetRegistry::EDependencyCategory Category = UE::AssetRegistry::EDependencyCategory::All, const UE::AssetRegistry::FDependencyQuery& Flags = UE::AssetRegistry::FDependencyQuery()) const { return false; }
- /**
- * Gets a list of PackageNames that reference the supplied package. (On disk references ONLY)
- *
- * @param PackageName the name of the package for which to gather dependencies (eg, /Game/MyFolder/MyAsset)
- * @param OutReferencers a list of packages that reference the package whose path is PackageName
- * @param Category which category(ies) of referencers to include in the output list. Referencers that have a dependency matching ANY of the OR'd categories will be returned.
- * @param Flags which flags are required present or not present on the referencer's dependency. Referencers that have a dependency matching ALL required and NONE excluded bits will be returned. For each potentially returned dependency, flags not applicable to their category are ignored.
- */
- bool GetReferencers(FName PackageName, TArray<FName>& OutReferencers, UE::AssetRegistry::EDependencyCategory Category = UE::AssetRegistry::EDependencyCategory::Package, const UE::AssetRegistry::FDependencyQuery& Flags = UE::AssetRegistry::FDependencyQuery()) const { return false; }
- /**
- * Gets a list of AssetIdentifiers or FAssetDependencies that are referenced by the supplied AssetIdentifier. (On disk references ONLY)
- *
- * @param AssetIdentifier the name of the package/name for which to gather dependencies.
- * @param OutDependencies a list of things that are referenced by AssetIdentifier.
- * @param Category which category(ies) of dependencies to include in the output list. Dependencies matching ANY of the OR'd categories will be returned.
- * @param Flags which flags are required present or not present on the dependencies. Dependencies matching ALL required and NONE excluded bits will be returned. For each potentially returned dependency, flags not applicable to their category are ignored.
- */
- bool GetDependencies(const FExtAssetIdentifier& AssetIdentifier, TArray<FExtAssetIdentifier>& OutDependencies, UE::AssetRegistry::EDependencyCategory Category = UE::AssetRegistry::EDependencyCategory::All, const UE::AssetRegistry::FDependencyQuery& Flags = UE::AssetRegistry::FDependencyQuery());
- /**
- * Gets a list of PackageNames that are referenced by the supplied package. (On disk references ONLY)
- *
- * @param PackageName the name of the package for which to gather dependencies (eg, /Game/MyFolder/MyAsset)
- * @param OutDependencies a list of packages that are referenced by the package whose path is PackageName
- * @param Category which category(ies) of dependencies to include in the output list. Dependencies matching ANY of the OR'd categories will be returned.
- * @param Flags which flags are required present or not present on the dependencies. Dependencies matching ALL required and NONE excluded bits will be returned. For each potentially returned dependency, flags not applicable to their category are ignored.
- */
- bool GetDependencies(FName PackageName, TArray<FName>& OutDependencies, UE::AssetRegistry::EDependencyCategory Category = UE::AssetRegistry::EDependencyCategory::Package, const UE::AssetRegistry::FDependencyQuery& Flags = UE::AssetRegistry::FDependencyQuery());
- ////////////////////////////////
- // Asset gather progress update
- /** Payload data for a file progress update */
- struct FAssetGatherProgressUpdateData
- {
- FAssetGatherProgressUpdateData(int32 InNumTotalAssets, int32 InNumAssetsProcessedByAssetRegistry, int32 InNumAssetsPendingDataLoad, bool InIsDiscoveringAssetFiles)
- : NumTotalAssets(InNumTotalAssets)
- , NumAssetsProcessedByAssetRegistry(InNumAssetsProcessedByAssetRegistry)
- , NumAssetsPendingDataLoad(InNumAssetsPendingDataLoad)
- , bIsDiscoveringAssetFiles(InIsDiscoveringAssetFiles)
- {
- }
- int32 NumTotalAssets;
- int32 NumAssetsProcessedByAssetRegistry;
- int32 NumAssetsPendingDataLoad;
- bool bIsDiscoveringAssetFiles;
- };
- /** Event to update the progress of the background file load */
- DECLARE_EVENT_OneParam(FExtAssetRegistry, FAssetGatherProgressUpdatedEvent, const FAssetGatherProgressUpdateData& /*ProgressUpdateData*/);
- FAssetGatherProgressUpdatedEvent& OnAssetGatherProgressUpdated()
- {
- return AssetGatherProgressUpdatedEvent;
- }
- /** Returns true if the asset registry is currently gathering uasset files */
- bool IsGatheringAssets() const;
- private:
- /** The delegate to execute while loading files to update progress */
- FAssetGatherProgressUpdatedEvent AssetGatherProgressUpdatedEvent;
- bool bIsGatheringAssets = false;
- int32 NumFilteredAssets = 0;
- int32 NumToGatherAssets = 0;
- public:
- ///////////////////////////////////////////////
- // AssetIdentifier interface
- //
- /** Returns valid PrimaryAssetId if this is a fake AssetData for a primary asset */
- static FPrimaryAssetId ExtractPrimaryAssetIdFromFakeAssetData(const FExtAssetData& InAssetData);
- static void ExtractAssetIdentifiersFromAssetDataList(const TArray<FExtAssetData>& AssetDataList, TArray<FExtAssetIdentifier>& OutAssetIdentifiers);
- public:
- void Shutdown();
- /** Load and cache root content folders from config */
- void LoadRootContentPaths();
- /** Merge input paths to current root content folders */
- void MergeRootContentPathsWith(const TArray<FString>& InPathsToMerge, bool bReplaceCurrent);
- /** Replace current content folders with input */
- void ReplaceRootContentPathsWith(const TArray<FString>& InPaths);
- /** Save root content folders to config file */
- void SaveRootContentPaths();
- /** Get root content folders */
- void QueryRootContentPaths(TArray<FString>& OutRootContentPaths) const;
- /** Get root content folder from file path */
- bool QueryRootContentPathFromFilePath(const FString& InFilePath, FString& OutRootContentPath);
- /** Get root content folders */
- bool QueryRootContentPathInfo(const FString& InRootContentPath, FText* OutDisplayName = nullptr, FExtAssetData::EContentType* OutContentType = nullptr, FString* OutAssetContentRoot = nullptr) const;
- /** Get relative path to any root path, return false if not match any */
- bool ParseAssetContentRoot(const FString& InFilePath, FString& OutRelativePath, FString& OutRootPath, FExtAssetData::EContentType& OutAssetContentType, TSet<FName>* InAllDependencies = nullptr);
- /** Cache found asset content dir */
- void AddAssetContentRoot(const FString& InAssetContentRootDir, const FString& InAssetContentRootHostDir, const FString& ConfigDir, FExtAssetData::EContentType InContentType);
- /** Get cached asset content dir, return false if not found */
- bool GetAssetContentRoot(const FString& InFilePath, FString& OutFoundAssetContentDir) const;
- FExtAssetData::EContentType GetAssetContentRootContentType(const FString& InAssetContentRoot) const;
- /** Get cached folder color*/
- bool GetFolderColor(const FString& InFolderPath, FLinearColor& OutFolderColor) const;
- bool IsAsetContentRootHasFolderColor(const FString& InAssetContentRoot) const;
- void GetAssetContentRootColoredFolders(const FString& InAssetContentRoot, TArray<FName>& OutColoredFolders) const;
- void GetAssetContentRootFolderColors(const FString& InAssetContentRoot, TMap<FName, FLinearColor>& OutFoldersColor) const;
- /** If input path is root content path */
- bool IsRootFolder(const FString& InPath) const;
- /** If input path is root content path */
- bool IsRootFolders(const TArray<FString>& InPaths) const;
- /** Add root content folder */
- bool AddRootFolder(const FString& InPath, TArray<FString>* OutAdded = nullptr, TArray<FString>* OutCombined = nullptr);
- /** Reload root content folders */
- bool ReloadRootFolders(const TArray<FString>& InPaths, TArray<FString>* OutReloaded = nullptr);
- /** Remove root content folders */
- bool RemoveRootFolders(const TArray<FString>& InPaths, TArray<FString>* OutRemovd = nullptr);
- /** Rescan root content folders */
- void ReGatheringFolders(const TArray<FString>& InPaths);
- /** Cache asset data for all assets that match the filter. */
- void CacheAssets(const struct FARFilter& InFilter);
- /** Kick off aysnc cache asset data for all assets that match the filter. */
- void CacheAssetsAsync(const struct FARFilter& InFilter);
- /** Gets a list of all paths that are currently cached below the passed-in base path. */
- void GetOrCacheSubPaths(const FName& InBasePath, TSet<FName>& OutPathList, bool bInRecurse);
- /** Gets a list of all paths that are currently cached below the passed-in base path. */
- void GetCachedSubPaths(const FName& InBasePath, TSet<FName>& OutPathList, bool bInRecurse);
- /** Get or cache asset dependency info. */
- FExtAssetDependencyInfo GetOrCacheAssetDependencyInfo(const FExtAssetData& InAssetData, bool bShowProgess = false);
- /** Get cached asset dependency info. */
- const FExtAssetDependencyInfo* GetCachedAssetDependencyInfo(const FExtAssetData& InAssetData) const;
- bool RemoveCachedAssetDependencyInfo(const FExtAssetData& InAssetData);
- bool IsCachedDependencyInfoInValid(const FExtAssetData& InAssetData, bool bTreatSoftErrorAsInvalid = false) const;
- /** Get or cache an assets by file path. */
- FExtAssetData* GetOrCacheAssetByFilePath(const FName& InFilePath, bool bDelayParse = false);
-
- /** Gets assets by directory, cache them if not already. */
- TMap<FName, TArray<FExtAssetData*>>& GetOrCacheAssetsByFolder(const FName& InDirectory, bool bDelayParse = false);
- /** Gets assets by asset class, cache them if not already. */
- TMap<FName, TArray<FExtAssetData*>>& GetOrCacheAssetsByClass(const TSet<FName>& InPaths, bool bRecursively);
- /** Get cached asset by file path. */
- FExtAssetData* GetCachedAssetByFilePath(const FName& InFilePath);
- /** Get cached asset by package name. */
- FExtAssetData* GetCachedAssetByPackageName(const FName& InPackageName);
- /** Gets cached assets by directory. */
- TArray<FExtAssetData*> GetCachedAssetsByFolder(const FName& InDirectory);
- /** Gets cached assets by asset class. */
- TArray<FExtAssetData*> GetCachedAssetsByClass(const FName& InClass);
- const TMap<FName, FName>& GetCachedAssetContentRootConfigDirs() const;
- const TMap<FName, FName>& GetCachedAssetContentRootHostDirs() const;
- #if ECB_WIP_THUMB_CACHE
- /** Searches for an object's thumbnail in memory and returns it if found */
- const FObjectThumbnail* FindCachedThumbnail(const FName& InFilePath);
- #endif
- /** If input folder has any packages. */
- bool IsEmptyFolder(const FString& FolderPath);
- /** If assets in the input folder been fully parsed. */
- bool IsFolderAssetsFullyParsed(const FString& FolderPath) const;
- /** Checks a filter to make sure there are no illegal entries */
- bool IsFilterValid(const FARFilter& Filter, bool bAllowRecursion);
- /** Modifies passed in filter to make it safe for use on FAssetRegistryState. This expands recursive paths and classes */
- void ExpandRecursiveFilter(const FARFilter& InFilter, FARFilter& ExpandedFilter);
- /** Helper functions to extract asset import information from asset registry tags */
- TOptional<FAssetImportInfo> ExtractAssetImportInfo(const FExtAssetData& AssetData) const;
- void PrintCacheStatus();
- /** Clear cached assets and paths */
- void ClearCache();
- void UpdateCacheByRemovedFolders(const TArray<FString>& InRemovedFolders);
- void StartFolderGathering(const FString& InParentFolder);
- void StartOrCancelAssetGathering(const TArray<FName>& InAssetPaths, int32 TotoalFiltered);
- public:
- #if ECB_WIP_CACHEDB
- bool LoadCacheDBWithFilePicker();
- bool LoadCacheDB(bool bSilent = true);
- bool SaveCacheDB(bool bSilent = true);
- bool PurgeCacheDB(bool bSilent = true);
- void SwitchCacheMode();
- int32 GetNumFoldersInCache() const { return State.NumFoldersInCache; }
- int32 GetNumAssetsInCache() const { return State.NumAssetsInCache; }
- int32 GetNumFoldersInMem() const { return State.CachedSubPaths.Num(); }
- int32 GetNumAssetsInMem() const { return State.CachedAssetsByFilePath.Num(); }
- #endif
- private:
- bool CombineRootContentPaths();
- void CacheRootContentPathInfo();
- void CacheFolderColor(const FName& InAssetContentRootDir);
- /** Returns the names of all subclasses of the class whose name is ClassName */
- void GetSubClasses(const TArray<FTopLevelAssetPath>& InClassPaths, const TSet<FTopLevelAssetPath>& ExcludedClassNames, TSet<FTopLevelAssetPath>& SubClassNames) const;
- void GetSubClasses_Recursive(const FTopLevelAssetPath& InClassName, TSet<FTopLevelAssetPath>& SubClassNames, TSet<FTopLevelAssetPath>& ProcessedClassNames, const TMap<FTopLevelAssetPath, TSet<FTopLevelAssetPath>>& ReverseInheritanceMap, const TSet<FTopLevelAssetPath>& ExcludedClassNames) const;
- void StopAllBackgroundGathering();
-
- private:
- /** The array of root content folders */
- TArray<FString> RootContentPaths;
- TMap<FString, FRootContentPathInfo> RootContentPathsInfo;
- /** Asset data and folder caches */
- FExtAssetRegistryStateCache State;
- /** Folder Gathering */
- TSharedPtr<class FExtFolderGatherer> BackgroundFolderGatherer;
- TSet<FName> BackgroundGatheringFolders;
- FName BackgroundGatheringSubFolder = NAME_None;
- /** Asset Gathering */
- TSharedPtr<class FExtAssetGatherer> BackgroundAssetGatherer;
- };
- /**
- * Helpers to export root content paths
- */
- struct FRootContentPathsExporter
- {
- //static void ImportAssets(const TArray<FExtAssetData>& InAssetDatas, const FExtAssetImportSetting& ImportSetting);
- };
- /**
- * Helpers to import uasset files into current project
- */
- struct FExtAssetImporter
- {
- static void ImportAssets(const TArray<FExtAssetData>& InAssetDatas, const FUAssetImportSetting& ImportSetting);
- static void ImportAssetsByFilePaths(const TArray<FString>& InAssetFilePaths, const FUAssetImportSetting& ImportSetting);
- static void ImportAssetsToFolderPackagePath(const TArray<FExtAssetData>& InAssetDatas, const FUAssetImportSetting& ImportSetting, const FString& InDestPackagePath);
- static void ImportAssetsWithPathPicker(const TArray<FExtAssetData>& InAssetDatas, const FUAssetImportSetting& ImportSetting);
- static void ImportProjectFolderColors(const FString& InRootOrHost);
- static void ExportAssets(const TArray<FExtAssetData>& InAssetDatas);
- static void ZipUpSourceAssets(const TArray<FExtAssetData>& InAssetDatas);
- static bool IsValidImportToPluginName(const FName& InPluginName, FString* OutInValidReason = nullptr, FString* OutValidPluginContentDir = nullptr);
- private:
- static void DoImportAssets(const TArray<FExtAssetData>& InAssetDatas, const FUAssetImportSetting& ImportSetting);
- static bool ValidateImportSetting(const FUAssetImportSetting& ImportSetting);
- };
- /**
- * Helpers to validate a uasset file
- */
- struct FExtAssetValidator
- {
- static bool ValidateDependency(const TArray<FExtAssetData*>& InAssetDatas, FString* OutValidateResultPtr = nullptr, bool bShowProgess = false, EDependencyNodeStatus* OutAssetStatus = nullptr);
- static bool ValidateDependency(const TArray<FExtAssetData>& InAssetDatas, FString* OutValidateResultPtr = nullptr, bool bShowProgess = false, EDependencyNodeStatus* OutAssetStatus = nullptr);
- static void InValidateDependency(const TArray<FExtAssetData>& InAssetDatas);
- };
- /**
- * Helpers count asset data
- */
- struct FExtAssetCountInfo
- {
- int32 TotalAssetsIncludeUMap;
- int32 TotalUAsset;
- int32 TotalUMap;
- int32 TotalInvalid;
- int32 TotalFileSizes;
- };
- struct FExtAssetCounter
- {
- static int32 CountAssetsByFolder(const FString& InFolder, FExtAssetCountInfo& OutCountInfo);
- };
- /**
- * Folder gathering policy
- */
- struct FExtFolderGatherPolicy
- {
- struct FFolderVisitor : public IPlatformFile::FDirectoryVisitor
- {
- virtual bool Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory) override
- {
- if (bIsDirectory)
- {
- bool bShouldIgnore = false;
- if (bIgnoreFoldersStartWithDot || IgnoreFolders.Num() > 0)
- {
- FString PathLeft = FPaths::GetPathLeaf(FilenameOrDirectory);
- if (bIgnoreFoldersStartWithDot && PathLeft.StartsWith(TEXT(".")))
- {
- bShouldIgnore = true;
- }
- if (!bShouldIgnore && IgnoreFolders.Num() > 0)
- {
- for (const FString& IgnoreFolder : IgnoreFolders)
- {
- if (IgnoreFolder.Equals(PathLeft, ESearchCase::IgnoreCase))
- {
- bShouldIgnore = true;
- break;
- }
- }
- }
- }
- if (!bShouldIgnore)
- {
- Directories.Add(FilenameOrDirectory);
- }
- }
- else if (FExtAssetSupport::IsSupportedPackageFilename(FilenameOrDirectory))
- {
- PackageFiles.Add(FilenameOrDirectory);
- }
- #if ECB_WIP // Gather Content Dir
- else
- {
- }
- #endif
- return true;
- }
- void Reset()
- {
- Directories.Reset();
- PackageFiles.Reset();
- }
- FFolderVisitor()
- {
- }
- FFolderVisitor(bool bInIgnoreFoldersStartWithDot, const TArray<FString>& InIgnoreFolders)
- : bIgnoreFoldersStartWithDot(bInIgnoreFoldersStartWithDot)
- , IgnoreFolders(InIgnoreFolders)
- {
- }
- TArray<FName> Directories;
- TArray<FName> PackageFiles;
- bool bIgnoreFoldersStartWithDot = false;
- TArray<FString> IgnoreFolders;
- };
- FFolderVisitor& GetResetedFolderVisitor()
- {
- FolderVisitor.Reset();
- return FolderVisitor;
- }
- void UpdateWith(const FExtFolderGatherPolicy& InNewPolicy)
- {
- FolderVisitor.bIgnoreFoldersStartWithDot = InNewPolicy.IsIgnoreFoldersStartWithDot();
- FolderVisitor.IgnoreFolders = InNewPolicy.GetIgnoreFolders();
- }
- bool IsIgnoreFoldersStartWithDot() const
- {
- return FolderVisitor.bIgnoreFoldersStartWithDot;
- }
- const TArray<FString>& GetIgnoreFolders() const
- {
- return FolderVisitor.IgnoreFolders;
- }
- FExtFolderGatherPolicy(bool bInIgnoreFoldersStartWithDot, const TArray<FString>& InIgnoreFolders)
- : FolderVisitor(bInIgnoreFoldersStartWithDot, InIgnoreFolders)
- {
- }
- FExtFolderGatherPolicy() {}
- private:
- FFolderVisitor FolderVisitor;
- };
- /**
- * Gather folders recursively
- */
- class FExtFolderGatherer : public FRunnable
- {
- public:
- FExtFolderGatherer(const FString& InGatheringFolder);
- FExtFolderGatherer(const FString& InGatheringFolder, const FExtFolderGatherPolicy& InGatherPolicy);
- virtual ~FExtFolderGatherer();
- // FRunnable implementation
- virtual bool Init() override;
- virtual uint32 Run() override;
- virtual void Stop() override;
- virtual void Exit() override;
- void EnsureCompletion();
- void AddSearchFolder(const FString& InFolderToSearch, const FExtFolderGatherPolicy* InUpdatedGatherPolicy);
- void StopSearchFolder(const FString& InFolderToStopSearch);
- bool GetAndTrimGatherResult(TArray<FExtFolderGatherResult>& OutGatherResults, double& OutGatherTime, TArray<FExtFolderGatherResult>& OutSubDirGatherResults, TArray<FExtAssetContentRootGatherResult>& OutAssetContentRootDirGatherResults);
- private:
- FExtFolderGatherPolicy GatherPolicy;
- private:
- struct FPathTree
- {
- FPathTree(const FName& InParent, const FName& InFolder, bool bInEmpty)
- : Parent(InParent)
- , Folder(InFolder)
- , bEmptyFolder(bInEmpty)
- {}
- FName Parent;
- FName Folder;
- bool bEmptyFolder;
- void MarkPathTreeNotEmpty(TMap<FName, FPathTree>& PathTrees)
- {
- bEmptyFolder = false;
- for (FPathTree* ParentTreePtr = PathTrees.Find(Parent); ParentTreePtr; ParentTreePtr = PathTrees.Find(ParentTreePtr->Parent))
- {
- ParentTreePtr->bEmptyFolder = false;
- }
- }
- };
- /** Get all child directories of input base directory */
- void GetDirectoriesAndPackages(const FName& InBaseDirectory, TArray<FName>& OutDirList, TArray<FName>& OutFilePaths);
- /** Get all child directories and packages of input base directory, return false if skipped */
- bool GetAllDirectoriesAndPackagesRecursively(const FName& InBaseDirectory, TArray<FName>& OutSubPaths, TMap<FName, TArray<FName>>& OutRecusriveSubPaths, TMap<FName, TArray<FName>>& OutFilePaths);
- void GetChildDirectoriesAndPackages(const FName& InRoot, const FName& InParent, const TArray<FName>& InBaseDirs, TArray<FName>& OutSubPaths, TMap<FName, TArray<FName>>& OutRecusriveSubPaths, TMap<FName, TArray<FName>>& OutputFilePaths, TMap<FName, FPathTree>& OutputPathTrees, bool bFoundAssetContentRoot = false);
- private:
- TArray<FString> DirectoriesToSearch;
- TArray<FExtFolderGatherResult> RootDirGatherResults;
- TArray<FExtFolderGatherResult> SubDirGatherResults;
- TArray<FExtAssetContentRootGatherResult> AssetContentRootGatherResults;
- /** How many seconds spent on last gathering */
- double GatherTime;
- /** A critical section to protect data transfer to other threads */
- FCriticalSection WorkerThreadCriticalSection;
- /** Thread to run the cleanup FRunnable on */
- FRunnableThread* Thread;
- /** Signal to stop */
- bool bRequestToStop;
- /** Signal to skip current search folder */
- bool bRequestToSkipCurrentSearchFolder;
- /** Current searching folder */
- FString CurrentSearchFolder;
- };
- /**
- * Gather folders recursively
- */
- class FExtAssetGatherer : public FRunnable
- {
- public:
- FExtAssetGatherer();
- virtual ~FExtAssetGatherer();
- // FRunnable implementation
- virtual bool Init() override;
- virtual uint32 Run() override;
- virtual void Stop() override;
- virtual void Exit() override;
- void EnsureCompletion();
- void AddBatchToGather(const TArray<FName>& InBatch);
- void CancelGather();
- bool GetAndTrimGatherResult(FExtAssetGatherResult& OutGatherResults, double& OutGatherTime, int32& OutLeft);
- private:
- bool DoGatherAssetByFilePath(const FName& InFilePath, FExtAssetData& OutExtAssetData) const;
- private:
- TArray<FName> GatherBatch;
- FExtAssetGatherResult GatherResult;
- /** How many seconds spent on last gathering */
- double GatherStartTime;
- double GatherTime;
- /** A critical section to protect data transfer to other threads */
- FCriticalSection WorkerThreadCriticalSection;
- /** Thread to run the cleanup FRunnable on */
- FRunnableThread* Thread;
- /** Signal to stop */
- bool bRequestToStop;
- };
- ////////////////////////////////////////////////
- // FExtContentDirFinder
- //
- struct FExtContentDirFinder
- {
- static bool FindWithFile(const FString& InUAssetFilePath, const FString& InFileToFind, bool bExtension, const FString& InContentFolderPattern, FString& OutContentRootPath, FString& OutRelativePath);
- static bool FindFolder(const FString& InUAssetFilePath, const FString& InContentFolderPattern, FString& OutContentRootPath, FString& OutRelativePath);
- static bool FindWithFolder(const FString& InFolderPath, const FString& InFileToFind, bool bExtension);
- };
|