106 lines
3.3 KiB
C++
106 lines
3.3 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|||
|
|
|
||
|
|
#include "PackLuaBundleCommandlet.h"
|
||
|
|
#include "LuaBundlePacker.h"
|
||
|
|
#include "UnrealLuaDemoEditor.h"
|
||
|
|
#include "LuaBundle/LuaBundleAsset.h"
|
||
|
|
#include "LuaBundle/LuaScriptSettings.h"
|
||
|
|
#include "Misc/Parse.h"
|
||
|
|
|
||
|
|
UPackLuaBundleCommandlet::UPackLuaBundleCommandlet()
|
||
|
|
{
|
||
|
|
IsClient = false;
|
||
|
|
IsEditor = true;
|
||
|
|
IsServer = false;
|
||
|
|
LogToConsole = true;
|
||
|
|
ShowErrorCount = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
int32 UPackLuaBundleCommandlet::Main(const FString& Params)
|
||
|
|
{
|
||
|
|
TOptional<bool> bEncryptOverride;
|
||
|
|
if (FParse::Param(*Params, TEXT("NoEncrypt")))
|
||
|
|
{
|
||
|
|
bEncryptOverride = false;
|
||
|
|
}
|
||
|
|
else if (FParse::Param(*Params, TEXT("Encrypt")))
|
||
|
|
{
|
||
|
|
bEncryptOverride = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
FLuaBundlePackResult AssetResult;
|
||
|
|
if (!FLuaBundlePacker::PackToDefaultAsset(AssetResult, bEncryptOverride))
|
||
|
|
{
|
||
|
|
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[PackLuaBundleCommandlet] PackToDefaultAsset failed: %s"), *AssetResult.ErrorMessage);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
UE_LOG(LogUnrealLuaDemoEditor, Display,
|
||
|
|
TEXT("[PackLuaBundleCommandlet] Packed %d scripts (%d bytes, encrypted=%s) -> %s"),
|
||
|
|
AssetResult.ScriptCount,
|
||
|
|
AssetResult.ArchiveByteSize,
|
||
|
|
AssetResult.bEncrypted ? TEXT("true") : TEXT("false"),
|
||
|
|
*AssetResult.OutputPath);
|
||
|
|
|
||
|
|
FString StandaloneOutputFile;
|
||
|
|
if (FParse::Value(*Params, TEXT("OutputFile="), StandaloneOutputFile) && !StandaloneOutputFile.IsEmpty())
|
||
|
|
{
|
||
|
|
FLuaBundlePackResult FileResult;
|
||
|
|
if (!FLuaBundlePacker::PackToStandaloneFile(StandaloneOutputFile, FileResult, bEncryptOverride))
|
||
|
|
{
|
||
|
|
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[PackLuaBundleCommandlet] PackToStandaloneFile failed: %s"), *FileResult.ErrorMessage);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
UE_LOG(LogUnrealLuaDemoEditor, Display,
|
||
|
|
TEXT("[PackLuaBundleCommandlet] Exported standalone bundle (%d bytes) -> %s"),
|
||
|
|
FileResult.ArchiveByteSize, *FileResult.OutputPath);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (FParse::Param(*Params, TEXT("Verify")))
|
||
|
|
{
|
||
|
|
const ULuaScriptSettings* Settings = GetDefault<ULuaScriptSettings>();
|
||
|
|
ULuaBundleAsset* LoadedAsset = Settings ? Cast<ULuaBundleAsset>(Settings->LuaBundleAssetPath.TryLoad()) : nullptr;
|
||
|
|
if (!LoadedAsset)
|
||
|
|
{
|
||
|
|
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[PackLuaBundleCommandlet] Verify failed: could not load bundle asset."));
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
TArray<FLuaBundleSourceItem> Sources;
|
||
|
|
FString CollectError;
|
||
|
|
if (!FLuaBundlePacker::CollectLuaSources(Sources, CollectError))
|
||
|
|
{
|
||
|
|
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[PackLuaBundleCommandlet] Verify failed: %s"), *CollectError);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
for (const FLuaBundleSourceItem& Source : Sources)
|
||
|
|
{
|
||
|
|
FString ModulePath = Source.RelativePath;
|
||
|
|
if (ModulePath.EndsWith(TEXT(".lua"), ESearchCase::IgnoreCase))
|
||
|
|
{
|
||
|
|
ModulePath.LeftChopInline(4);
|
||
|
|
}
|
||
|
|
|
||
|
|
TArray<uint8> ReadBackBytes;
|
||
|
|
FString ChunkName;
|
||
|
|
if (!LoadedAsset->FindScript(ModulePath, ReadBackBytes, ChunkName))
|
||
|
|
{
|
||
|
|
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[PackLuaBundleCommandlet] Verify failed: missing module '%s'."), *ModulePath);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (ReadBackBytes != Source.PlaintextBytes)
|
||
|
|
{
|
||
|
|
UE_LOG(LogUnrealLuaDemoEditor, Error, TEXT("[PackLuaBundleCommandlet] Verify failed: content mismatch for '%s'."), *ModulePath);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
UE_LOG(LogUnrealLuaDemoEditor, Display,
|
||
|
|
TEXT("[PackLuaBundleCommandlet] Verified all %d scripts round-trip cleanly from ULuaBundleAsset."),
|
||
|
|
Sources.Num());
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|