1414#include < ContentBrowserModule.h>
1515#include " Core\Public\Modules\ModuleManager.h"
1616#include < IContentBrowserSingleton.h>
17+ #include < HAL/PlatformFilemanager.h>
1718
1819
1920#pragma region Redirectors
@@ -148,10 +149,6 @@ FAssetData UElgEditorBP_Assets::GetAssetDataFromPath(const FString& AssetPath)
148149
149150 FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(" AssetRegistry" );
150151 AssetData = AssetRegistryModule.Get ().GetAssetByObjectPath (*AssetPath);
151- if (!AssetData.IsValid ()) {
152- return AssetData;
153- }
154-
155152 return AssetData;
156153}
157154
@@ -200,6 +197,17 @@ FString UElgEditorBP_Assets::GetAssetPath(const FAssetData& AssetDataStruct)
200197
201198#pragma region GetAssets
202199
200+ void UElgEditorBP_Assets::GetAssetObjectByPath (const FString InAssetPath, UObject*& AssetObject)
201+ {
202+ AssetObject = nullptr ;
203+ FAssetData assetData = GetAssetDataFromPath (InAssetPath);
204+ if (assetData.IsValid ()) {
205+ AssetObject = assetData.GetAsset ();
206+ }
207+ }
208+
209+
210+
203211void UElgEditorBP_Assets::GetAssetObjects (const TArray<FAssetData>& AssetDataStructs, TArray<UObject*>& AssetObjects)
204212{
205213 AssetObjects.Empty ();
@@ -447,7 +455,6 @@ TArray<FString> UElgEditorBP_Assets::GetSelectedPaths()
447455}
448456#pragma endregion
449457
450-
451458#pragma region Paths
452459
453460FString UElgEditorBP_Assets::AssetPathToDiskPath (const FString& InAssetPath)
@@ -468,3 +475,79 @@ TArray<FString> UElgEditorBP_Assets::AssetPathsToDiskPaths(TArray<FString> InAss
468475
469476#pragma endregion
470477
478+ #pragma region DiffAssets
479+
480+ void UElgEditorBP_Assets::DiffAssets (UObject* OldAsset, UObject* NewAsset, const FString OldAssetRevisionString)
481+ {
482+ if (!OldAsset || !NewAsset) {
483+ UE_LOG (LogTemp, Warning, TEXT (" Need two valid Asset objects to diff..." ));
484+ return ;
485+ }
486+
487+ FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>(TEXT (" AssetTools" ));
488+
489+ FRevisionInfo OldRevision;
490+ OldRevision.Revision = OldAssetRevisionString;
491+
492+ FRevisionInfo NewRevision;
493+ NewRevision.Revision = TEXT (" " );
494+
495+ AssetToolsModule.Get ().DiffAssets (OldAsset, NewAsset, OldRevision, NewRevision);
496+ }
497+
498+ void UElgEditorBP_Assets::DiffAssetData (const FAssetData OldAsset, const FAssetData NewAsset, const FString OldAssetRevisionString)
499+ {
500+ if (!OldAsset.IsValid () || !NewAsset.IsValid ()) {
501+ UE_LOG (LogTemp, Warning, TEXT (" Need two valid Asset data to diff..." ));
502+ return ;
503+ }
504+ UObject* oldAsset = OldAsset.GetAsset ();
505+ UObject* newAsset = NewAsset.GetAsset ();
506+ DiffAssets (oldAsset, newAsset, OldAssetRevisionString);
507+ }
508+
509+ void UElgEditorBP_Assets::DiffAssetPath (const FString OldAssetPath, const FString NewAssetPath, const FString OldAssetRevisionString)
510+ {
511+ if (OldAssetPath.IsEmpty () || NewAssetPath.IsEmpty ()) {
512+ UE_LOG (LogTemp, Warning, TEXT (" Need two valid Asset Path to diff..." ));
513+ return ;
514+ }
515+ FAssetData oldAsset = GetAssetDataFromPath (OldAssetPath);
516+ FAssetData newAsset = GetAssetDataFromPath (NewAssetPath);
517+ DiffAssetData (oldAsset, newAsset, OldAssetRevisionString);
518+ }
519+
520+ void UElgEditorBP_Assets::DiffAssetWithExternalAsset (UObject* NewAsset, const FString ExternalAssetFilePath, const FString ExternalAssetName)
521+ {
522+ if (!NewAsset) {
523+ UE_LOG (LogTemp, Warning, TEXT (" Need a valid asset to diff" ));
524+ return ;
525+ }
526+ if (ExternalAssetName.IsEmpty ()) {
527+ UE_LOG (LogTemp, Warning, TEXT (" Need a valid ExternalAssetName to diff" ));
528+ return ;
529+ }
530+ if (!FPlatformFileManager::Get ().GetPlatformFile ().FileExists (*ExternalAssetFilePath)) {
531+ UE_LOG (LogTemp, Warning, TEXT (" Failed to find any file at %s" ), *ExternalAssetFilePath);
532+ return ;
533+ }
534+
535+ FString path = FPaths::ConvertRelativePathToFull (ExternalAssetFilePath);
536+ UPackage* tempPackage = LoadPackage (nullptr , *path, LOAD_ForDiff | LOAD_DisableCompileOnLoad);
537+ if (tempPackage != nullptr ) {
538+ UObject* oldObject = FindObject<UObject>(tempPackage, *ExternalAssetName);
539+ if (oldObject != nullptr ) {
540+ DiffAssets (oldObject, NewAsset, ExternalAssetName);
541+ }
542+ else {
543+ UE_LOG (LogTemp, Warning, TEXT (" Failed to find any asset with name %s in the package" ), *ExternalAssetName);
544+ return ;
545+ }
546+ } else {
547+ UE_LOG (LogTemp, Warning, TEXT (" Failed to load the package at %s" ), *path);
548+ return ;
549+ }
550+ }
551+
552+ #pragma endregion
553+
0 commit comments