9#include <util/ue-header-guard-begin.h>
10#include "Misc/ConfigCacheIni.h"
11#include <util/ue-header-guard-end.h>
21 template <
typename TARGET,
typename SOURCE>
24 if ((source >= std::numeric_limits<TARGET>::lowest()) &&
25 (source <= std::numeric_limits<TARGET>::max())) {
26 target =
static_cast<TARGET
>(source);
28 UE_LOG(LogCarla, Error, TEXT(
"FIniFile: Type cast failed"));
43 ConfigFile.Read(FileName);
54 return ConfigFile.Combine(FileName);
59 ConfigFile.ProcessInputFileContents(INIFileContents, Hint);
64 return (ConfigFile.Num() > 0) && (ConfigFile.FindSection(Section) !=
nullptr);
69 if (!HasSection(Section)) {
70 ConfigFile.Add(Section, FConfigSection());
75 bool Write(
const FString &Filename)
77 return ConfigFile.Write(Filename);
93 void GetInt(
const TCHAR* Section,
const TCHAR* Key, T &Target)
const
96 if (ConfigFile.GetInt64(Section, Key, Value)) {
97 SafeCastTo<T>(Value, Target);
101 void GetString(
const TCHAR* Section,
const TCHAR* Key, FString &Target)
const
104 if (ConfigFile.GetString(Section, Key, Value)) {
109 void GetBool(
const TCHAR* Section,
const TCHAR* Key,
bool &Target)
const
112 if (ConfigFile.GetBool(Section, Key, Value)) {
117 void GetFloat(
const TCHAR* Section,
const TCHAR* Key,
float &Target,
const float Factor = 1.0f)
const
120 if (ConfigFile.GetString(Section, Key, Value)) {
121 Target = Factor * FCString::Atof(*Value);
125 void GetLinearColor(
const TCHAR* Section,
const TCHAR* Key, FLinearColor &Target)
const
128 if (ConfigFile.GetString(Section, Key, Value)) {
129 Target.InitFromString(Value);
139 void SetInt(
const TCHAR* Section,
const TCHAR* Key,
const int64 Value)
141 ConfigFile.SetInt64(Section, Key, Value);
144 void SetString(
const TCHAR* Section,
const TCHAR* Key,
const TCHAR* Value)
146 ConfigFile.SetString(Section, Key, Value);
149 void SetString(
const TCHAR* Section,
const TCHAR* Key,
const FString &Value)
151 SetString(Section, Key, *Value);
154 void SetBool(
const TCHAR* Section,
const TCHAR* Key,
const bool Value)
156 SetString(Section, Key, Value ? TEXT(
"True") : TEXT(
"False"));
159 void SetFloat(
const TCHAR* Section,
const TCHAR* Key,
const float Value)
161 SetString(Section, Key, FText::AsNumber(Value).ToString());
164 void SetLinearColor(
const TCHAR* Section,
const TCHAR* Key,
const FLinearColor &Value)
166 SetString(Section, Key, Value.ToString());
Wrapper around Unreal's INI file.
void SetLinearColor(const TCHAR *Section, const TCHAR *Key, const FLinearColor &Value)
const FConfigFile & GetFConfigFile() const
Retrieve Unreal's FConfigFile.
bool Combine(const FString &FileName)
bool Write(const FString &Filename)
Write contents to disk.
static void SafeCastTo(SOURCE source, TARGET &target)
bool HasSection(const FString &Section) const
void SetFloat(const TCHAR *Section, const TCHAR *Key, const float Value)
void GetBool(const TCHAR *Section, const TCHAR *Key, bool &Target) const
FIniFile(const FString &FileName)
void GetFloat(const TCHAR *Section, const TCHAR *Key, float &Target, const float Factor=1.0f) const
void GetString(const TCHAR *Section, const TCHAR *Key, FString &Target) const
void SetString(const TCHAR *Section, const TCHAR *Key, const TCHAR *Value)
void SetString(const TCHAR *Section, const TCHAR *Key, const FString &Value)
void ProcessInputFileContents(const FString &INIFileContents, const FString &Hint)
void AddSectionIfMissing(const FString &Section)
void GetInt(const TCHAR *Section, const TCHAR *Key, T &Target) const
void SetInt(const TCHAR *Section, const TCHAR *Key, const int64 Value)
void SetBool(const TCHAR *Section, const TCHAR *Key, const bool Value)
void GetLinearColor(const TCHAR *Section, const TCHAR *Key, FLinearColor &Target) const