Removed all code to save packages from the MCP
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
#include "EdGraph/EdGraphSchema.h"
|
||||
#include "Kismet2/BlueprintEditorUtils.h"
|
||||
#include "Kismet2/KismetEditorUtilities.h"
|
||||
#include "UObject/SavePackage.h"
|
||||
#include "UObject/UObjectIterator.h"
|
||||
#include "UObject/UnrealType.h"
|
||||
#include "Misc/Paths.h"
|
||||
@@ -43,13 +42,6 @@
|
||||
#include "Animation/BlendSpace.h"
|
||||
#include "Engine/Texture.h"
|
||||
|
||||
// SEH support (Windows only) — defined in BlueprintWingServer.cpp
|
||||
#if PLATFORM_WINDOWS
|
||||
extern int32 TryCompileBlueprintSEH(UBlueprint* BP, EBlueprintCompileOptions Opts);
|
||||
extern int32 TrySavePackageSEH(
|
||||
UPackage* Package, UObject* Asset, const TCHAR* Filename,
|
||||
FSavePackageArgs* SaveArgs, ESavePackageResult* OutResult);
|
||||
#endif
|
||||
|
||||
// ============================================================
|
||||
// Name sanitization
|
||||
@@ -354,132 +346,6 @@ TArray<UEdGraphNode*> WingUtils::AllNodes(UBlueprint* BP)
|
||||
return Nodes;
|
||||
}
|
||||
|
||||
bool WingUtils::SaveBlueprintPackage(UBlueprint* BP)
|
||||
{
|
||||
UPackage* Package = BP->GetPackage();
|
||||
|
||||
// 1. Build absolute package filename — use .umap for map packages, .uasset otherwise
|
||||
FString PackageExtension = Package->ContainsMap()
|
||||
? FPackageName::GetMapPackageExtension()
|
||||
: FPackageName::GetAssetPackageExtension();
|
||||
FString PackageFilename = FPackageName::LongPackageNameToFilename(
|
||||
Package->GetName(), PackageExtension);
|
||||
PackageFilename = FPaths::ConvertRelativePathToFull(PackageFilename);
|
||||
UE_LOG(LogTemp, Display, TEXT("UEWingman: Save target: %s"), *PackageFilename);
|
||||
|
||||
// 2. Phase 1: Try explicit compilation (same flags as UCompileAllBlueprintsCommandlet)
|
||||
bool bCompiled = false;
|
||||
{
|
||||
EBlueprintCompileOptions CompileOpts =
|
||||
EBlueprintCompileOptions::SkipSave |
|
||||
EBlueprintCompileOptions::BatchCompile |
|
||||
EBlueprintCompileOptions::SkipGarbageCollection |
|
||||
EBlueprintCompileOptions::SkipFiBSearchMetaUpdate;
|
||||
|
||||
UE_LOG(LogTemp, Display, TEXT("UEWingman: Phase 1: Attempting explicit compilation..."));
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
int32 CompileResult = TryCompileBlueprintSEH(BP, CompileOpts);
|
||||
if (CompileResult == 0)
|
||||
{
|
||||
bCompiled = (BP->Status == BS_UpToDate);
|
||||
UE_LOG(LogTemp, Display, TEXT("UEWingman: Compilation %s (status=%d)"),
|
||||
bCompiled ? TEXT("succeeded") : TEXT("completed with warnings"), (int32)BP->Status);
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("UEWingman: Compilation crashed (SEH), proceeding uncompiled"));
|
||||
}
|
||||
#else
|
||||
FKismetEditorUtilities::CompileBlueprint(BP, CompileOpts, nullptr);
|
||||
bCompiled = (BP->Status == BS_UpToDate);
|
||||
#endif
|
||||
}
|
||||
|
||||
// 3. Phase 2: Set guards for save
|
||||
uint8 OldRegen = BP->bIsRegeneratingOnLoad;
|
||||
BP->bIsRegeneratingOnLoad = true;
|
||||
|
||||
EBlueprintStatus OldStatus = (EBlueprintStatus)(uint8)BP->Status;
|
||||
if (!bCompiled)
|
||||
{
|
||||
// Tell PreSave the BP is up-to-date so it doesn't try to compile
|
||||
BP->Status = BS_UpToDate;
|
||||
}
|
||||
|
||||
// 4. Clear read-only attribute if present (source control or LFS may set this)
|
||||
if (FPlatformFileManager::Get().GetPlatformFile().IsReadOnly(*PackageFilename))
|
||||
{
|
||||
UE_LOG(LogTemp, Display, TEXT("UEWingman: Clearing read-only attribute on %s"), *PackageFilename);
|
||||
FPlatformFileManager::Get().GetPlatformFile().SetReadOnly(*PackageFilename, false);
|
||||
}
|
||||
|
||||
// 5. Phase 3: Save with SAVE_NoError + SEH protection
|
||||
FSavePackageArgs SaveArgs;
|
||||
SaveArgs.TopLevelFlags = RF_Public | RF_Standalone;
|
||||
SaveArgs.SaveFlags = SAVE_NoError;
|
||||
|
||||
// For level blueprints (map packages), the base object should be the UWorld, not the BP
|
||||
bool bIsMapPackage = Package->ContainsMap();
|
||||
UObject* BaseObject = BP;
|
||||
if (bIsMapPackage)
|
||||
{
|
||||
// Find the UWorld in this package — it's the actual asset for .umap files
|
||||
UWorld* World = FindObject<UWorld>(Package, *Package->GetName().Mid(Package->GetName().Find(TEXT("/"), ESearchCase::IgnoreCase, ESearchDir::FromEnd) + 1));
|
||||
if (!World)
|
||||
{
|
||||
// Fallback: iterate the package to find any UWorld
|
||||
ForEachObjectWithPackage(Package, [&World](UObject* Obj) {
|
||||
if (UWorld* W = Cast<UWorld>(Obj))
|
||||
{
|
||||
World = W;
|
||||
return false; // stop
|
||||
}
|
||||
return true; // continue
|
||||
});
|
||||
}
|
||||
if (World)
|
||||
{
|
||||
BaseObject = World;
|
||||
UE_LOG(LogTemp, Display, TEXT("UEWingman: Map package detected — saving UWorld '%s'"), *World->GetName());
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("UEWingman: Map package detected but no UWorld found — saving with BP as base"));
|
||||
}
|
||||
}
|
||||
|
||||
ESavePackageResult SaveResult = ESavePackageResult::Error;
|
||||
|
||||
UE_LOG(LogTemp, Display, TEXT("UEWingman: Phase 3: Calling UPackage::Save (compiled=%s, isMap=%s)..."),
|
||||
bCompiled ? TEXT("yes") : TEXT("no"), bIsMapPackage ? TEXT("yes") : TEXT("no"));
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
int32 SEHCode = TrySavePackageSEH(Package, BaseObject, *PackageFilename, &SaveArgs, &SaveResult);
|
||||
if (SEHCode != 0)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("UEWingman: UPackage::Save CRASHED (SEH exception caught)"));
|
||||
}
|
||||
#else
|
||||
FSavePackageResultStruct Result = UPackage::Save(Package, BaseObject, *PackageFilename, SaveArgs);
|
||||
SaveResult = Result.Result;
|
||||
#endif
|
||||
|
||||
// 6. Restore guards
|
||||
BP->bIsRegeneratingOnLoad = OldRegen;
|
||||
if (!bCompiled)
|
||||
{
|
||||
BP->Status = (TEnumAsByte<EBlueprintStatus>)OldStatus;
|
||||
}
|
||||
|
||||
bool bSuccess = (SaveResult == ESavePackageResult::Success);
|
||||
UE_LOG(LogTemp, Display, TEXT("UEWingman: SaveBlueprintPackage — %s for '%s' (compiled=%s, result=%d)"),
|
||||
bSuccess ? TEXT("SUCCEEDED") : TEXT("FAILED"),
|
||||
*BP->GetName(), bCompiled ? TEXT("yes") : TEXT("no"), (int32)SaveResult);
|
||||
|
||||
return bSuccess;
|
||||
|
||||
}
|
||||
// ============================================================
|
||||
// Material helpers
|
||||
// ============================================================
|
||||
@@ -529,43 +395,6 @@ UMaterial* WingUtils::ReplaceMaterialWithTransientCopy(UMaterial* Material)
|
||||
return Material;
|
||||
}
|
||||
|
||||
bool WingUtils::SaveGenericPackage(UObject* Asset)
|
||||
{
|
||||
if (!Asset) return false;
|
||||
UPackage* Package = Asset->GetPackage();
|
||||
UE_LOG(LogTemp, Display, TEXT("UEWingman: SaveGenericPackage — begin for '%s'"), *Asset->GetName());
|
||||
|
||||
FString PackageFilename = FPackageName::LongPackageNameToFilename(
|
||||
Package->GetName(), FPackageName::GetAssetPackageExtension());
|
||||
PackageFilename = FPaths::ConvertRelativePathToFull(PackageFilename);
|
||||
|
||||
if (FPlatformFileManager::Get().GetPlatformFile().IsReadOnly(*PackageFilename))
|
||||
{
|
||||
FPlatformFileManager::Get().GetPlatformFile().SetReadOnly(*PackageFilename, false);
|
||||
}
|
||||
|
||||
FSavePackageArgs SaveArgs;
|
||||
SaveArgs.TopLevelFlags = RF_Public | RF_Standalone;
|
||||
SaveArgs.SaveFlags = SAVE_NoError;
|
||||
|
||||
ESavePackageResult SaveResult = ESavePackageResult::Error;
|
||||
#if PLATFORM_WINDOWS
|
||||
int32 SEHCode = TrySavePackageSEH(Package, Asset, *PackageFilename, &SaveArgs, &SaveResult);
|
||||
if (SEHCode != 0)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("UEWingman: SaveGenericPackage CRASHED (SEH exception)"));
|
||||
}
|
||||
#else
|
||||
FSavePackageResultStruct Result = UPackage::Save(Package, Asset, *PackageFilename, SaveArgs);
|
||||
SaveResult = Result.Result;
|
||||
#endif
|
||||
|
||||
bool bSuccess = (SaveResult == ESavePackageResult::Success);
|
||||
UE_LOG(LogTemp, Display, TEXT("UEWingman: SaveGenericPackage — %s for '%s'"),
|
||||
bSuccess ? TEXT("SUCCEEDED") : TEXT("FAILED"), *Asset->GetName());
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
|
||||
// ============================================================
|
||||
// Anim blueprint helpers
|
||||
|
||||
Reference in New Issue
Block a user