2020-09-24 00:43:27 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "Commandlets/SavePackageUtilitiesCommandlet.h"
|
|
|
|
|
|
|
|
|
|
#include "Editor.h"
|
|
|
|
|
#include "HAL/IConsoleManager.h"
|
|
|
|
|
#include "HAL/FileManager.h"
|
|
|
|
|
#include "HAL/IConsoleManager.h"
|
|
|
|
|
#include "Interfaces/ITargetPlatformManagerModule.h"
|
|
|
|
|
#include "Misc/CoreMisc.h"
|
|
|
|
|
#include "Misc/FeedbackContext.h"
|
|
|
|
|
#include "Misc/PackageName.h"
|
|
|
|
|
#include "Misc/Paths.h"
|
2022-02-22 13:32:02 -05:00
|
|
|
#include "UObject/ArchiveCookContext.h"
|
2020-09-24 00:43:27 -04:00
|
|
|
#include "UObject/LinkerDiff.h"
|
2021-05-21 15:53:22 -04:00
|
|
|
#include "UObject/LinkerSave.h"
|
2020-09-24 00:43:27 -04:00
|
|
|
#include "UObject/Package.h"
|
2021-06-15 16:38:03 -04:00
|
|
|
#include "UObject/SavePackage.h"
|
2020-09-24 00:43:27 -04:00
|
|
|
#include "UObject/UObjectGlobals.h"
|
|
|
|
|
#include "UObject/UObjectHash.h"
|
|
|
|
|
|
|
|
|
|
USavePackageUtilitiesCommandlet::USavePackageUtilitiesCommandlet(const FObjectInitializer& ObjectInitializer)
|
|
|
|
|
: Super(ObjectInitializer)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32 USavePackageUtilitiesCommandlet::Main(const FString& Params)
|
|
|
|
|
{
|
|
|
|
|
InitParameters(Params);
|
|
|
|
|
|
|
|
|
|
for (const FString& PackageName : PackageNames)
|
|
|
|
|
{
|
|
|
|
|
// Load Package
|
|
|
|
|
UPackage* Package = LoadPackage(nullptr, *PackageName, LOAD_None);
|
2020-11-04 10:47:45 -04:00
|
|
|
UObject* Asset = Package->FindAssetInPackage();
|
2020-09-24 00:43:27 -04:00
|
|
|
FString Filename = FPaths::CreateTempFilename(*FPaths::ProjectSavedDir());
|
|
|
|
|
|
2022-02-22 13:32:02 -05:00
|
|
|
// CookData should only be nonzero if we are cooking.
|
|
|
|
|
TOptional<FArchiveCookData> CookData;
|
|
|
|
|
FArchiveCookContext CookContext(Package, FArchiveCookContext::ECookTypeUnknown);
|
|
|
|
|
if (TargetPlatform != nullptr)
|
|
|
|
|
{
|
|
|
|
|
CookData.Emplace(*TargetPlatform, CookContext);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 00:43:27 -04:00
|
|
|
FSavePackageArgs SaveArgs;
|
|
|
|
|
SaveArgs.TopLevelFlags = RF_Public;
|
|
|
|
|
SaveArgs.SaveFlags = SAVE_CompareLinker;
|
2022-02-22 13:32:02 -05:00
|
|
|
SaveArgs.ArchiveCookData = CookData.GetPtrOrNull();
|
2021-11-23 20:56:06 -05:00
|
|
|
SaveArgs.bSlowTask = false;
|
2020-09-24 00:43:27 -04:00
|
|
|
|
|
|
|
|
// if not cooking add RF_Standalone to the top level flags
|
|
|
|
|
if (TargetPlatform == nullptr)
|
|
|
|
|
{
|
|
|
|
|
SaveArgs.TopLevelFlags |= RF_Standalone;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 09:04:05 -04:00
|
|
|
FSavePackageResultStruct FirstResult = GEditor->Save(Package, Asset, *Filename, SaveArgs);
|
|
|
|
|
FSavePackageResultStruct SecondResult = GEditor->Save(Package, Asset, *Filename, SaveArgs);
|
|
|
|
|
|
|
|
|
|
if (FirstResult.LinkerSave && SecondResult.LinkerSave)
|
2020-09-24 00:43:27 -04:00
|
|
|
{
|
|
|
|
|
// Compare Linker Save info
|
2022-05-02 09:04:05 -04:00
|
|
|
FLinkerDiff LinkerDiff = FLinkerDiff::CompareLinkers(FirstResult.LinkerSave.Get(), SecondResult.LinkerSave.Get());
|
2020-10-27 17:50:10 -04:00
|
|
|
LinkerDiff.PrintDiff(*GWarn);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 00:43:27 -04:00
|
|
|
// Delete the temp filename
|
|
|
|
|
IFileManager::Get().Delete(*Filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void USavePackageUtilitiesCommandlet::InitParameters(const FString& Params)
|
|
|
|
|
{
|
|
|
|
|
TArray<FString> Tokens;
|
|
|
|
|
TArray<FString> Switches;
|
|
|
|
|
ParseCommandLine(*Params, Tokens, Switches);
|
|
|
|
|
|
|
|
|
|
FString SwitchValue;
|
|
|
|
|
for (const FString& CurrentSwitch : Switches)
|
|
|
|
|
{
|
|
|
|
|
if (FParse::Value(*CurrentSwitch, TEXT("PACKAGE="), SwitchValue))
|
|
|
|
|
{
|
|
|
|
|
FString LongPackageName;
|
|
|
|
|
FPackageName::SearchForPackageOnDisk(SwitchValue, &LongPackageName, nullptr);
|
|
|
|
|
PackageNames.Add(MoveTemp(LongPackageName));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (FParse::Value(*CurrentSwitch, TEXT("PACKAGEFOLDER="), SwitchValue))
|
|
|
|
|
{
|
|
|
|
|
FPackageName::IteratePackagesInDirectory(SwitchValue, [this](const TCHAR* Filename)
|
|
|
|
|
{
|
|
|
|
|
PackageNames.Add(FPackageName::FilenameToLongPackageName(Filename));
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (FParse::Value(*CurrentSwitch, TEXT("CookPlatform="), SwitchValue))
|
|
|
|
|
{
|
|
|
|
|
if (ITargetPlatformManagerModule* TPM = GetTargetPlatformManager())
|
|
|
|
|
{
|
|
|
|
|
TargetPlatform = TPM->FindTargetPlatform(SwitchValue);
|
|
|
|
|
if (TargetPlatform == nullptr)
|
|
|
|
|
{
|
|
|
|
|
// @todo Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|