2020-12-11 14:21:20 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "Commandlets/MakeBinaryConfigCommandlet.h"
|
|
|
|
|
#include "Interfaces/ITargetPlatformManagerModule.h"
|
|
|
|
|
#include "Interfaces/ITargetPlatform.h"
|
|
|
|
|
#include "Interfaces/IPluginManager.h"
|
|
|
|
|
#include "Misc/CoreDelegates.h"
|
|
|
|
|
#include "Misc/CommandLine.h"
|
|
|
|
|
#include "Misc/ConfigCacheIni.h"
|
2022-05-18 08:59:31 -04:00
|
|
|
#include "Misc/ConfigContext.h"
|
2020-12-11 14:21:20 -04:00
|
|
|
#include "Misc/FileHelper.h"
|
|
|
|
|
|
|
|
|
|
UMakeBinaryConfigCommandlet::UMakeBinaryConfigCommandlet(const FObjectInitializer& ObjectInitializer)
|
|
|
|
|
: Super(ObjectInitializer)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32 UMakeBinaryConfigCommandlet::Main(const FString& Params)
|
|
|
|
|
{
|
|
|
|
|
FString OutputFile;
|
|
|
|
|
if (!FParse::Value(FCommandLine::Get(), TEXT("OutputFile="), OutputFile))
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogTemp, Fatal, TEXT("OutputFile= parameter required"));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString StagedPluginsFile;
|
|
|
|
|
if (!FParse::Value(FCommandLine::Get(), TEXT("StagedPluginsFile="), StagedPluginsFile))
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogTemp, Fatal, TEXT("StagedPluginsFile= parameter required"));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// only expecting one targetplatform
|
|
|
|
|
const TArray<ITargetPlatform*>& Platforms = GetTargetPlatformManagerRef().GetActiveTargetPlatforms();
|
|
|
|
|
check(Platforms.Num() == 1);
|
|
|
|
|
FString PlatformName = Platforms[0]->IniPlatformName();
|
|
|
|
|
|
|
|
|
|
FConfigCacheIni Config(EConfigCacheType::Temporary);
|
2022-05-18 08:59:31 -04:00
|
|
|
FConfigContext Context = FConfigContext::ReadIntoConfigSystem(&Config, PlatformName);
|
|
|
|
|
Config.InitializeKnownConfigFiles(Context);
|
2020-12-11 14:21:20 -04:00
|
|
|
|
|
|
|
|
// removing for now, because this causes issues with some plugins not getting ini files merged in
|
|
|
|
|
// IPluginManager::Get().IntegratePluginsIntoConfig(Config, *FinalConfigFilenames.EngineIni, *PlatformName, *StagedPluginsFile);
|
|
|
|
|
|
2021-10-12 21:21:22 -04:00
|
|
|
// pull out deny list entries
|
2020-12-11 14:21:20 -04:00
|
|
|
|
2021-10-12 21:21:22 -04:00
|
|
|
TArray<FString> KeyDenyListStrings;
|
|
|
|
|
TArray<FString> SectionsDenyList;
|
|
|
|
|
GConfig->GetArray(TEXT("/Script/UnrealEd.ProjectPackagingSettings"), TEXT("IniKeyBlacklist"), KeyDenyListStrings, GGameIni);
|
|
|
|
|
GConfig->GetArray(TEXT("/Script/UnrealEd.ProjectPackagingSettings"), TEXT("IniSectionBlacklist"), SectionsDenyList, GGameIni);
|
|
|
|
|
TArray<FName> KeysDenyList;
|
|
|
|
|
for (FString Key : KeyDenyListStrings)
|
2020-12-11 14:21:20 -04:00
|
|
|
{
|
2021-10-12 21:21:22 -04:00
|
|
|
KeysDenyList.Add(FName(*Key));
|
2020-12-11 14:21:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const FString& Filename : Config.GetFilenames())
|
|
|
|
|
{
|
|
|
|
|
FConfigFile* File = Config.FindConfigFile(Filename);
|
|
|
|
|
|
|
|
|
|
delete File->SourceConfigFile;
|
|
|
|
|
File->SourceConfigFile = nullptr;
|
|
|
|
|
|
2021-10-12 21:21:22 -04:00
|
|
|
for (FString Section : SectionsDenyList)
|
2020-12-11 14:21:20 -04:00
|
|
|
{
|
|
|
|
|
File->Remove(Section);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now go over any remaining sections and remove keys
|
|
|
|
|
for (TPair<FString, FConfigSection>& SectionPair : *File)
|
|
|
|
|
{
|
|
|
|
|
FConfigSection& Section = SectionPair.Value;
|
2021-10-12 21:21:22 -04:00
|
|
|
for (FName Key : KeysDenyList)
|
2020-12-11 14:21:20 -04:00
|
|
|
{
|
|
|
|
|
Section.Remove(Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 21:21:22 -04:00
|
|
|
// check the deny list removed itself
|
|
|
|
|
KeyDenyListStrings.Empty();
|
|
|
|
|
Config.GetArray(TEXT("/Script/UnrealEd.ProjectPackagingSettings"), TEXT("IniKeyBlacklist"), KeyDenyListStrings, GGameIni);
|
|
|
|
|
check(KeyDenyListStrings.Num() == 0);
|
2020-12-11 14:21:20 -04:00
|
|
|
|
|
|
|
|
// allow delegates to modify the config data with some tagged binary data
|
|
|
|
|
FCoreDelegates::FExtraBinaryConfigData ExtraData(Config, true);
|
|
|
|
|
FCoreDelegates::AccessExtraBinaryConfigData.Broadcast(ExtraData);
|
|
|
|
|
|
|
|
|
|
// write it all out!
|
|
|
|
|
TArray<uint8> FileContent;
|
|
|
|
|
{
|
|
|
|
|
// Use FMemoryWriter because FileManager::CreateFileWriter doesn't serialize FName as string and is not overridable
|
|
|
|
|
FMemoryWriter MemoryWriter(FileContent, true);
|
|
|
|
|
|
|
|
|
|
Config.Serialize(MemoryWriter);
|
|
|
|
|
MemoryWriter << ExtraData.Data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!FFileHelper::SaveArrayToFile(FileContent, *OutputFile))
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogTemp, Fatal, TEXT("Failed to create Config.bin file"));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|