// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. #include "MergePrivatePCH.h" #include "MergeUtils.h" #include "ISourceControlModule.h" #include "SourceControlHelpers.h" #include "NotificationManager.h" #include "Developer/AssetTools/Public/IAssetTypeActions.h" #include "Runtime/Slate/Public/Widgets/Notifications/SNotificationList.h" #define LOCTEXT_NAMESPACE "MergeToolUtils" //------------------------------------------------------------------------------ FSourceControlStatePtr FMergeToolUtils::GetSourceControlState(const FString& PackageName) { ISourceControlProvider& SourceControlProvider = ISourceControlModule::Get().GetProvider(); TSharedRef UpdateStatusOperation = ISourceControlOperation::Create(); UpdateStatusOperation->SetUpdateHistory(true); SourceControlProvider.Execute(UpdateStatusOperation, SourceControlHelpers::PackageFilename(PackageName)); FSourceControlStatePtr State = SourceControlProvider.GetState(SourceControlHelpers::PackageFilename(PackageName), EStateCacheUsage::Use); if (!State.IsValid() || !State->IsSourceControlled() || !FPackageName::DoesPackageExist(PackageName)) { return FSourceControlStatePtr(); } else { return State; } } //------------------------------------------------------------------------------ UObject const* FMergeToolUtils::LoadRevision(const FString& AssetName, const ISourceControlRevision& DesiredRevision) { FSlateNotificationManager& NotificationManager = FSlateNotificationManager::Get(); // Get the head revision of this package from source control FString TempFileName; if (DesiredRevision.Get(TempFileName)) { // Forcibly disable compile on load in case we are loading old blueprints that might try to update/compile TGuardValue DisableCompileOnLoad(GForceDisableBlueprintCompileOnLoad, true); // Try and load that package UPackage* TempPackage = LoadPackage(NULL, *TempFileName, LOAD_None); if (TempPackage != NULL) { // Grab the old asset from that old package UObject* OldObject = FindObject(TempPackage, *AssetName); if (OldObject) { return OldObject; } else { NotificationManager.AddNotification( FText::Format( LOCTEXT("MergedFailedToFindObject", "Aborted Load of {0} because we could not find an object named {1}" ) , FText::FromString(TempFileName) , FText::FromString(AssetName) ) ); } } else { NotificationManager.AddNotification( FText::Format( LOCTEXT("MergedFailedToLoadPackage", "Aborted Load of {0} because we could not load the package") , FText::FromString(TempFileName) ) ); } } else { NotificationManager.AddNotification( FText::Format( LOCTEXT("MergedFailedToFindRevision", "Aborted Load of {0} because we could not get the requested revision") , FText::FromString(TempFileName) ) ); } return NULL; } //------------------------------------------------------------------------------ UObject const* FMergeToolUtils::LoadRevision(const FString& PackageName, const FRevisionInfo& DesiredRevision) { const UObject* AssetRevision = nullptr; if (UPackage* AssetPackage = LoadPackage(/*Outer =*/nullptr, *PackageName, LOAD_None)) { TArray PackageObjs; GetObjectsWithOuter(AssetPackage, PackageObjs, /*bIncludeNestedObjects =*/false); for (UObject* PackageObj : PackageObjs) { if (PackageObj->IsAsset()) { AssetRevision = LoadRevision(PackageObj, DesiredRevision); break; } } } return AssetRevision; } //------------------------------------------------------------------------------ UObject const* FMergeToolUtils::LoadRevision(const UObject* AssetObject, const FRevisionInfo& DesiredRevision) { check(AssetObject->IsAsset()); const UObject* AssetRevision = nullptr; if (DesiredRevision.Revision.IsEmpty()) { // an invalid revision number represents the local copy AssetRevision = AssetObject; } else { FString const PackageName = AssetObject->GetOutermost()->GetName(); FSourceControlStatePtr SourceControlState = GetSourceControlState(PackageName); if (SourceControlState.IsValid()) { TSharedPtr Revision = SourceControlState->FindHistoryRevision(DesiredRevision.Revision); if (Revision.IsValid()) { FString const AssetName = AssetObject->GetName(); AssetRevision = LoadRevision(AssetName, *Revision); } } } return AssetRevision; } #undef LOCTEXT_NAMESPACE