Files
integration/Plugins/UEWingman/Deprecated/BlueprintExportSubsystem.cpp
2026-03-18 10:29:38 -04:00

68 lines
2.2 KiB
C++

#include "BlueprintExportSubsystem.h"
#include "BlueprintExporter.h"
#include "Engine/Blueprint.h"
#include "EdGraph/EdGraph.h"
#include "UObject/Package.h"
#include "Exporters/Exporter.h"
#include "UnrealExporter.h"
#include "Misc/FileHelper.h"
#include "Misc/Paths.h"
void UBlueprintExportSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
OnAssetSavedHandle = UPackage::PackageSavedWithContextEvent.AddUObject(
this, &UBlueprintExportSubsystem::OnAssetSaved);
}
void UBlueprintExportSubsystem::Deinitialize()
{
UPackage::PackageSavedWithContextEvent.Remove(OnAssetSavedHandle);
Super::Deinitialize();
}
void UBlueprintExportSubsystem::OnAssetSaved(const FString& PackageFilename, UPackage* Package, FObjectPostSaveContext Context)
{
if (!Package) return;
FString PkDir = FPaths::ProjectDir() / TEXT("Saved") / TEXT("BlueprintExports") / FPaths::GetBaseFilename(PackageFilename);
IFileManager::Get().DeleteDirectory(*PkDir, false, true);
// Export the whole package in both formats for comparison.
{
FStringOutputDevice Archive;
const FExportObjectInnerContext InnerContext;
UExporter::ExportToOutputDevice(&InnerContext, Package, nullptr, Archive, TEXT("copy"), 0);
FFileHelper::SaveStringToFile(Archive, *(PkDir / TEXT("COPY_DUMP.txt")));
}
{
FStringOutputDevice Archive;
const FExportObjectInnerContext InnerContext;
UExporter::ExportToOutputDevice(&InnerContext, Package, nullptr, Archive, TEXT("t3d"), 0);
FFileHelper::SaveStringToFile(Archive, *(PkDir / TEXT("T3D_DUMP.txt")));
}
TArray<UObject*> AllObjects;
GetObjectsWithPackage(Package, AllObjects);
for (UObject *Obj : AllObjects)
{
if (UBlueprint *BP = Cast<UBlueprint>(Obj))
{
FString BPDir = PkDir / BP->GetName();
TArray<UEdGraph*> AllGraphs;
BP->GetAllGraphs(AllGraphs);
for (UEdGraph* Graph : AllGraphs)
{
MCPGraphExport Exporter(Graph);
FString FilePath = BPDir / Graph->GetName() + TEXT(".txt");
FString DetailsPath = BPDir / TEXT("DETAILS") / Graph->GetName() + TEXT(".txt");
FFileHelper::SaveStringToFile(Exporter.GetOutput(), *FilePath);
FFileHelper::SaveStringToFile(Exporter.GetDetails(), *DetailsPath);
UE_LOG(LogTemp, Warning, TEXT("Blueprint export: %s"), *FilePath);
}
}
}
}