// Copyright Epic Games, Inc. All Rights Reserved. #include "Installer/MachineConfig.h" #include "Misc/ConfigCacheIni.h" #include "Core/AsyncHelpers.h" namespace MachineConfigHelpers { TSet LoadInstalledPrereqIds(const FString& LocalMachineConfigFile) { check(IsInGameThread()); TArray ConfigStrings; GConfig->GetArray(TEXT("Portal.BuildPatch"), TEXT("InstalledPrereqs"), ConfigStrings, LocalMachineConfigFile); return TSet(ConfigStrings); }; void SaveInstalledPrereqIds(const FString& LocalMachineConfigFile, const TSet& InstalledPrereqIds, bool bFlush) { check(IsInGameThread()); GConfig->SetArray(TEXT("Portal.BuildPatch"), TEXT("InstalledPrereqs"), InstalledPrereqIds.Array(), LocalMachineConfigFile); if (bFlush) { GConfig->Flush(false, LocalMachineConfigFile); } } } namespace BuildPatchServices { class FMachineConfig : public IMachineConfig { public: /** * Constructor * @param InLocalMachineConfigFile The name of the configuration file which will hold the per machine config data. * @param bAlwaysFlushChanges If true, then we'll always flush changes straight to disk after saving values. */ FMachineConfig(const FString& InLocalMachineConfigFile, bool bAlwaysFlushChanges); //~ Begin IMachineConfig Interface virtual TSet LoadInstalledPrereqIds() override; virtual void SaveInstalledPrereqIds(const TSet& InstalledPrereqIds) override; //~ End IMachineConfig Interface private: // The filename for the local machine config. This is used for per-machine values rather than per-user or shipped config. FString LocalMachineConfigFile; // If true, then we'll always flush changes straight to disk after saving values. bool bAlwaysFlushChanges; }; FMachineConfig::FMachineConfig(const FString& InLocalMachineConfigFile, bool bInAlwaysFlushChanges) : LocalMachineConfigFile(InLocalMachineConfigFile) , bAlwaysFlushChanges(bInAlwaysFlushChanges) { } TSet FMachineConfig::LoadInstalledPrereqIds() { return AsyncHelpers::ExecuteOnGameThread>([this]() { return MachineConfigHelpers::LoadInstalledPrereqIds(LocalMachineConfigFile); }).Get(); } void FMachineConfig::SaveInstalledPrereqIds(const TSet& InstalledPrereqIds) { AsyncHelpers::ExecuteOnGameThread([this, &InstalledPrereqIds]() { MachineConfigHelpers::SaveInstalledPrereqIds(LocalMachineConfigFile, InstalledPrereqIds, bAlwaysFlushChanges); }).Wait(); } IMachineConfig* FMachineConfigFactory::Create(const FString& LocalMachineConfigFile, bool bAlwaysFlushChanges) { return new FMachineConfig(LocalMachineConfigFile, bAlwaysFlushChanges); } }