Files
integration/Plugins/UEWingman/Deprecated/BlueprintExportSubsystem.cpp

68 lines
2.2 KiB
C++
Raw Normal View History

2026-03-09 06:47:43 -04:00
#include "BlueprintExportSubsystem.h"
2026-03-08 21:28:47 -04:00
#include "BlueprintExporter.h"
#include "Engine/Blueprint.h"
#include "EdGraph/EdGraph.h"
2026-03-12 19:12:37 -04:00
#include "UObject/Package.h"
2026-03-08 21:28:47 -04:00
#include "Exporters/Exporter.h"
#include "UnrealExporter.h"
#include "Misc/FileHelper.h"
2026-03-12 19:12:37 -04:00
#include "Misc/Paths.h"
2026-03-09 06:47:43 -04:00
void UBlueprintExportSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
2026-03-08 21:28:47 -04:00
OnAssetSavedHandle = UPackage::PackageSavedWithContextEvent.AddUObject(
2026-03-09 06:47:43 -04:00
this, &UBlueprintExportSubsystem::OnAssetSaved);
}
2026-03-09 06:47:43 -04:00
void UBlueprintExportSubsystem::Deinitialize()
{
2026-03-08 21:28:47 -04:00
UPackage::PackageSavedWithContextEvent.Remove(OnAssetSavedHandle);
Super::Deinitialize();
}
2026-03-09 06:47:43 -04:00
void UBlueprintExportSubsystem::OnAssetSaved(const FString& PackageFilename, UPackage* Package, FObjectPostSaveContext Context)
2026-03-08 21:28:47 -04:00
{
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);
2026-03-08 21:28:47 -04:00
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);
}
}
}
}