34 lines
1,008 B
C#
34 lines
1,008 B
C#
using System.Text.Json;
|
|
using VideoDownloader.Core.Config;
|
|
|
|
namespace VideoDownloader.App.Core;
|
|
|
|
/// <summary>%AppData%/VideoDownloader/config.json 으로 설정 영속화</summary>
|
|
public static class ConfigStore
|
|
{
|
|
private static string Dir => AppPaths.DataDir;
|
|
private static string FilePath => Path.Combine(Dir, "config.json");
|
|
|
|
private static readonly JsonSerializerOptions JsonOpts = new() { WriteIndented = true };
|
|
|
|
public static AppConfig Load()
|
|
{
|
|
try
|
|
{
|
|
if (File.Exists(FilePath))
|
|
return JsonSerializer.Deserialize<AppConfig>(File.ReadAllText(FilePath)) ?? new AppConfig();
|
|
}
|
|
catch { /* 손상 시 기본값 */ }
|
|
return new AppConfig();
|
|
}
|
|
|
|
public static void Save(AppConfig config)
|
|
{
|
|
try
|
|
{
|
|
Directory.CreateDirectory(Dir);
|
|
File.WriteAllText(FilePath, JsonSerializer.Serialize(config, JsonOpts));
|
|
}
|
|
catch { /* 저장 실패는 무시 */ }
|
|
}
|
|
}
|