Write the boot hotfix file in background.

[REVIEW] [at]michael.atchison [at]michael.kirzinger [at]joe.barnes
#jira UE-196689
#rb [at]michael.atchison [at]michael.kirzinger

[CL 28292288 by lorry li in ue5-main branch]
This commit is contained in:
lorry li
2023-09-27 16:53:24 -04:00
parent a34470aa16
commit b794e46e15

View File

@@ -6,12 +6,15 @@
#include "HAL/IConsoleManager.h"
#include "Misc/CoreDelegates.h"
#include "Misc/FileHelper.h"
#include "Tasks/Pipe.h"
#define UE_HOTFIX_FOR_NEXT_BOOT_FILENAME TEXT("HotfixForNextBoot.txt")
namespace UE::ConfigUtilities
{
UE::Tasks::FPipe AsyncTaskPipe( TEXT("SaveHotfixForNextBootPipe") );
const TCHAR* ConvertValueFromHumanFriendlyValue( const TCHAR* Value )
{
static const TCHAR* OnValue = TEXT("1");
@@ -94,23 +97,28 @@ void SaveCVarForNextBoot(const TCHAR* Key, const TCHAR* Value)
return;
}
TMap<FString, FString> CVarsToSave;
FString StrKey(Key);
FString StrValue(Value);
// Read from file, in case there are more than one cvar hotfix event in same run
LoadCVarsFromFileForNextBoot(CVarsToSave);
AsyncTaskPipe.Launch(UE_SOURCE_LOCATION, [StrKey, StrValue] {
TMap<FString, FString> CVarsToSave;
CVarsToSave.FindOrAdd(Key) = Value;
// Read from file, in case there are more than one cvar hotfix event in same run
LoadCVarsFromFileForNextBoot(CVarsToSave);
FString ContentToSave;
for (const TPair<FString, FString>& CVarPair : CVarsToSave)
{
ContentToSave.Append(FString::Format(TEXT("{0}={1}\r\n"), { CVarPair.Key, CVarPair.Value }));
}
CVarsToSave.FindOrAdd(StrKey) = StrValue;
const FString FullPath = FPaths::ProjectPersistentDownloadDir() / UE_HOTFIX_FOR_NEXT_BOOT_FILENAME;
FFileHelper::SaveStringToFile(ContentToSave, *FullPath);
FString ContentToSave;
for (const TPair<FString, FString>& CVarPair : CVarsToSave)
{
ContentToSave.Append(FString::Format(TEXT("{0}={1}\r\n"), { CVarPair.Key, CVarPair.Value }));
}
UE_LOG(LogConfig, Log, TEXT("Local boot hotfix file [%s] saved with hotfixed CVar: %s=%s"), *FullPath, Key, Value);
const FString FullPath = FPaths::ProjectPersistentDownloadDir() / UE_HOTFIX_FOR_NEXT_BOOT_FILENAME;
FFileHelper::SaveStringToFile(ContentToSave, *FullPath);
UE_LOG(LogConfig, Log, TEXT("Local boot hotfix file [%s] saved with hotfixed CVar: %s=%s"), *FullPath, *StrKey, *StrValue);
}, LowLevelTasks::ETaskPriority::BackgroundLow);
#endif // !UE_SERVER
}