KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
UConfigLibrary.cpp
이 파일의 문서화 페이지로 가기
1// Copyright (c) 2025 Doppleddiggong. All rights reserved. Unauthorized copying, modification, or distribution of this file, via any medium is strictly prohibited. Proprietary and confidential.
2
3#include "UConfigLibrary.h"
4#include "Misc/ConfigCacheIni.h"
5
6// =====================================================================
7// CONSTANTS
8// =====================================================================
9
11{
12 constexpr const TCHAR* GlobalSection = TEXT("/Script/CoffeeLibrary.Config");
13 constexpr const TCHAR* UserSection = TEXT("/Script/CoffeeLibrary.UserConfig");
14}
15
16// =====================================================================
17// INTEGER OPERATIONS - GLOBAL
18// =====================================================================
19
20int32 UConfigLibrary::GetInt(const FString& Key, int32 DefaultValue)
21{
22 int32 Result = DefaultValue;
23 GConfig->GetInt(
25 *Key,
26 Result,
27 GGameUserSettingsIni
28 );
29 return Result;
30}
31
32void UConfigLibrary::SetInt(const FString& Key, int32 Value, bool bAutoSave)
33{
34 GConfig->SetInt(
36 *Key,
37 Value,
38 GGameUserSettingsIni
39 );
40
41 if (bAutoSave)
42 {
43 Save();
44 }
45}
46
47// =====================================================================
48// FLOAT OPERATIONS - GLOBAL
49// =====================================================================
50
51float UConfigLibrary::GetFloat(const FString& Key, float DefaultValue)
52{
53 float Result = DefaultValue;
54 GConfig->GetFloat(
56 *Key,
57 Result,
58 GGameUserSettingsIni
59 );
60 return Result;
61}
62
63void UConfigLibrary::SetFloat(const FString& Key, float Value, bool bAutoSave)
64{
65 GConfig->SetFloat(
67 *Key,
68 Value,
69 GGameUserSettingsIni
70 );
71
72 if (bAutoSave)
73 {
74 Save();
75 }
76}
77
78// =====================================================================
79// STRING OPERATIONS - GLOBAL
80// =====================================================================
81
82FString UConfigLibrary::GetString(const FString& Key, const FString& DefaultValue)
83{
84 FString Result = DefaultValue;
85 GConfig->GetString(
87 *Key,
88 Result,
89 GGameUserSettingsIni
90 );
91 return Result;
92}
93
94void UConfigLibrary::SetString(const FString& Key, const FString& Value, bool bAutoSave)
95{
96 GConfig->SetString(
98 *Key,
99 *Value,
100 GGameUserSettingsIni
101 );
102
103 if (bAutoSave)
104 {
105 Save();
106 }
107}
108
109// =====================================================================
110// BOOLEAN OPERATIONS - GLOBAL
111// =====================================================================
112
113bool UConfigLibrary::GetBool(const FString& Key, bool bDefaultValue)
114{
115 return GetInt(Key, bDefaultValue ? 1 : 0) != 0;
116}
117
118void UConfigLibrary::SetBool(const FString& Key, bool bValue, bool bAutoSave)
119{
120 SetInt(Key, bValue ? 1 : 0, bAutoSave);
121}
122
123// =====================================================================
124// INTEGER OPERATIONS - USER-SPECIFIC
125// =====================================================================
126
127int32 UConfigLibrary::GetUserInt(int32 UserId, const FString& Key, int32 DefaultValue)
128{
129 if (UserId <= 0)
130 {
131 return DefaultValue;
132 }
133
134 const FString UserKey = MakeUserKey(UserId, Key);
135 int32 Result = DefaultValue;
136 GConfig->GetInt(
138 *UserKey,
139 Result,
140 GGameUserSettingsIni
141 );
142 return Result;
143}
144
145void UConfigLibrary::SetUserInt(int32 UserId, const FString& Key, int32 Value, bool bAutoSave)
146{
147 if (UserId <= 0)
148 {
149 return;
150 }
151
152 const FString UserKey = MakeUserKey(UserId, Key);
153 GConfig->SetInt(
155 *UserKey,
156 Value,
157 GGameUserSettingsIni
158 );
159
160 if (bAutoSave)
161 {
162 Save();
163 }
164}
165
166// =====================================================================
167// FLOAT OPERATIONS - USER-SPECIFIC
168// =====================================================================
169
170float UConfigLibrary::GetUserFloat(int32 UserId, const FString& Key, float DefaultValue)
171{
172 if (UserId <= 0)
173 {
174 return DefaultValue;
175 }
176
177 const FString UserKey = MakeUserKey(UserId, Key);
178 float Result = DefaultValue;
179 GConfig->GetFloat(
181 *UserKey,
182 Result,
183 GGameUserSettingsIni
184 );
185 return Result;
186}
187
188void UConfigLibrary::SetUserFloat(int32 UserId, const FString& Key, float Value, bool bAutoSave)
189{
190 if (UserId <= 0)
191 {
192 return;
193 }
194
195 const FString UserKey = MakeUserKey(UserId, Key);
196 GConfig->SetFloat(
198 *UserKey,
199 Value,
200 GGameUserSettingsIni
201 );
202
203 if (bAutoSave)
204 {
205 Save();
206 }
207}
208
209// =====================================================================
210// STRING OPERATIONS - USER-SPECIFIC
211// =====================================================================
212
213FString UConfigLibrary::GetUserString(int32 UserId, const FString& Key, const FString& DefaultValue)
214{
215 if (UserId <= 0)
216 {
217 return DefaultValue;
218 }
219
220 const FString UserKey = MakeUserKey(UserId, Key);
221 FString Result = DefaultValue;
222 GConfig->GetString(
224 *UserKey,
225 Result,
226 GGameUserSettingsIni
227 );
228 return Result;
229}
230
231void UConfigLibrary::SetUserString(int32 UserId, const FString& Key, const FString& Value, bool bAutoSave)
232{
233 if (UserId <= 0)
234 {
235 return;
236 }
237
238 const FString UserKey = MakeUserKey(UserId, Key);
239 GConfig->SetString(
241 *UserKey,
242 *Value,
243 GGameUserSettingsIni
244 );
245
246 if (bAutoSave)
247 {
248 Save();
249 }
250}
251
252// =====================================================================
253// BOOLEAN OPERATIONS - USER-SPECIFIC
254// =====================================================================
255
256bool UConfigLibrary::GetUserBool(int32 UserId, const FString& Key, bool bDefaultValue)
257{
258 return GetUserInt(UserId, Key, bDefaultValue ? 1 : 0) != 0;
259}
260
261void UConfigLibrary::SetUserBool(int32 UserId, const FString& Key, bool bValue, bool bAutoSave)
262{
263 SetUserInt(UserId, Key, bValue ? 1 : 0, bAutoSave);
264}
265
266// =====================================================================
267// JSON OPERATIONS - USER-SPECIFIC
268// =====================================================================
269
270void UConfigLibrary::SetUserJson(int32 UserId, const FString& Key, const FString& JsonData, bool bAutoSave)
271{
272 // JSON은 내부적으로 String으로 저장
273 SetUserString(UserId, Key, JsonData, bAutoSave);
274}
275
276FString UConfigLibrary::GetUserJson(int32 UserId, const FString& Key, const FString& DefaultJson)
277{
278 return GetUserString(UserId, Key, DefaultJson);
279}
280
281// =====================================================================
282// KEY MANAGEMENT
283// =====================================================================
284
285bool UConfigLibrary::HasKey(const FString& Key)
286{
287 FString Temp;
288 return GConfig->GetString(
290 *Key,
291 Temp,
292 GGameUserSettingsIni
293 );
294}
295
296bool UConfigLibrary::HasUserKey(int32 UserId, const FString& Key)
297{
298 if (UserId <= 0)
299 {
300 return false;
301 }
302
303 const FString UserKey = MakeUserKey(UserId, Key);
304 FString Temp;
305 return GConfig->GetString(
307 *UserKey,
308 Temp,
309 GGameUserSettingsIni
310 );
311}
312
313void UConfigLibrary::DeleteKey(const FString& Key, bool bAutoSave)
314{
315 GConfig->RemoveKey(
317 *Key,
318 GGameUserSettingsIni
319 );
320
321 if (bAutoSave)
322 {
323 Save();
324 }
325}
326
327void UConfigLibrary::DeleteUserKey(int32 UserId, const FString& Key, bool bAutoSave)
328{
329 if (UserId <= 0)
330 {
331 return;
332 }
333
334 const FString UserKey = MakeUserKey(UserId, Key);
335 GConfig->RemoveKey(
337 *UserKey,
338 GGameUserSettingsIni
339 );
340
341 if (bAutoSave)
342 {
343 Save();
344 }
345}
346
347void UConfigLibrary::DeleteAll(bool bAutoSave)
348{
349 GConfig->EmptySection(
351 GGameUserSettingsIni
352 );
353
354 if (bAutoSave)
355 {
356 Save();
357 }
358}
359
360void UConfigLibrary::DeleteAllUserData(int32 UserId, bool bAutoSave)
361{
362 if (UserId <= 0)
363 {
364 return;
365 }
366
367 // 해당 UserId로 시작하는 모든 키 찾기
368 TArray<FString> AllKeys;
369 GConfig->GetSection(
371 AllKeys,
372 GGameUserSettingsIni
373 );
374
375 const FString UserPrefix = FString::Printf(TEXT("User_%d_"), UserId);
376 for (const FString& KeyValue : AllKeys)
377 {
378 // "Key=Value" 형식에서 Key 부분만 추출
379 FString Key;
380 FString Value;
381 if (KeyValue.Split(TEXT("="), &Key, &Value))
382 {
383 if (Key.StartsWith(UserPrefix))
384 {
385 GConfig->RemoveKey(
387 *Key,
388 GGameUserSettingsIni
389 );
390 }
391 }
392 }
393
394 if (bAutoSave)
395 {
396 Save();
397 }
398}
399
401{
402 GConfig->Flush(false, GGameUserSettingsIni);
403}
404
405// =====================================================================
406// PRIVATE HELPERS
407// =====================================================================
408
413
418
419FString UConfigLibrary::MakeUserKey(int32 UserId, const FString& Key)
420{
421 return FString::Printf(TEXT("User_%d_%s"), UserId, *Key);
422}
GConfig 래퍼 설정 관리 시스템
static FString GetString(const FString &Key, const FString &DefaultValue=TEXT(""))
전역 문자열 설정 읽기
static FString GetUserString(int32 UserId, const FString &Key, const FString &DefaultValue=TEXT(""))
유저별 문자열 설정 읽기
static void SetFloat(const FString &Key, float Value, bool bAutoSave=true)
전역 실수 설정 저장
static void SetUserFloat(int32 UserId, const FString &Key, float Value, bool bAutoSave=true)
유저별 실수 설정 저장
static void SetUserJson(int32 UserId, const FString &Key, const FString &JsonData, bool bAutoSave=true)
유저별 JSON 데이터 저장
static FString MakeUserKey(int32 UserId, const FString &Key)
유저별 키 생성 (UserId 접두사 추가)
static void SetUserString(int32 UserId, const FString &Key, const FString &Value, bool bAutoSave=true)
유저별 문자열 설정 저장
static bool HasUserKey(int32 UserId, const FString &Key)
유저별 키 존재 여부 확인
static float GetUserFloat(int32 UserId, const FString &Key, float DefaultValue=0.0f)
유저별 실수 설정 읽기
static int32 GetUserInt(int32 UserId, const FString &Key, int32 DefaultValue=0)
유저별 정수 설정 읽기
static FString GetUserSection()
유저별 설정 Config Section 이름 반환
static FString GetGlobalSection()
전역 설정 Config Section 이름 반환
static void DeleteUserKey(int32 UserId, const FString &Key, bool bAutoSave=true)
유저별 키 삭제
static void DeleteKey(const FString &Key, bool bAutoSave=true)
전역 키 삭제
static FString GetUserJson(int32 UserId, const FString &Key, const FString &DefaultJson=TEXT("[]"))
유저별 JSON 데이터 읽기
static int32 GetInt(const FString &Key, int32 DefaultValue=0)
전역 정수 설정 읽기
static void SetString(const FString &Key, const FString &Value, bool bAutoSave=true)
전역 문자열 설정 저장
static void SetInt(const FString &Key, int32 Value, bool bAutoSave=true)
전역 정수 설정 저장
static void Save()
대기 중인 모든 변경사항을 디스크에 저장
static float GetFloat(const FString &Key, float DefaultValue=0.0f)
전역 실수 설정 읽기
static void SetUserInt(int32 UserId, const FString &Key, int32 Value, bool bAutoSave=true)
유저별 정수 설정 저장
static void SetBool(const FString &Key, bool bValue, bool bAutoSave=true)
전역 불린 설정 저장
static void DeleteAll(bool bAutoSave=true)
모든 전역 설정 삭제 (주의!)
static void DeleteAllUserData(int32 UserId, bool bAutoSave=true)
특정 유저의 모든 설정 삭제
static bool GetUserBool(int32 UserId, const FString &Key, bool bDefaultValue=false)
유저별 불린 설정 읽기
static bool GetBool(const FString &Key, bool bDefaultValue=false)
전역 불린 설정 읽기
static bool HasKey(const FString &Key)
전역 키 존재 여부 확인
static void SetUserBool(int32 UserId, const FString &Key, bool bValue, bool bAutoSave=true)
유저별 불린 설정 저장
constexpr const TCHAR * GlobalSection
constexpr const TCHAR * UserSection