using System.IO;
using System.Text.Json;
namespace VideoDownloader.App.Browser.Tabs;
/// 세션 JSON 저장소(T1-10). 종료 시 탭 URL 저장, 시작 시 복원.
public static class TabSessionStore
{
public static void Save(string path, SessionSnapshot snap)
{
try
{
var dir = Path.GetDirectoryName(path);
if (!string.IsNullOrEmpty(dir)) Directory.CreateDirectory(dir);
var tmp = path + ".tmp";
File.WriteAllText(tmp, JsonSerializer.Serialize(snap));
File.Move(tmp, path, overwrite: true);
}
catch { }
}
public static SessionSnapshot? Load(string path)
{
try
{
if (!File.Exists(path)) return null;
var snap = JsonSerializer.Deserialize(File.ReadAllText(path));
if (snap == null || snap.Urls == null || snap.Urls.Count == 0) return null;
var pinned = snap.Pinned ?? new List();
while (pinned.Count < snap.Urls.Count) pinned.Add(false);
return snap with { Pinned = pinned };
}
catch
{
return null;
}
}
}