38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace VideoDownloader.Browser.Tabs;
|
|
|
|
/// <summary>세션 JSON 저장소(T1-10). 종료 시 탭 URL 저장, 시작 시 복원.</summary>
|
|
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<SessionSnapshot>(File.ReadAllText(path));
|
|
if (snap == null || snap.Urls == null || snap.Urls.Count == 0) return null;
|
|
var pinned = snap.Pinned ?? new List<bool>();
|
|
while (pinned.Count < snap.Urls.Count) pinned.Add(false);
|
|
return snap with { Pinned = pinned };
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|