using System.IO;
using Microsoft.Data.Sqlite;
using ytLive.Models;
namespace ytLive.Services;
public partial class LayoutStore : IDisposable
{
public static LayoutStore? Instance { get; private set; }
private readonly SqliteConnection _connection;
public string ActivePath { get; }
/// The app-wide webcam identity loaded with the last Load() (null = never picked).
public Webcam? Webcam { get; private set; }
/// The app-wide social bar config loaded with the last Load() (null = never defined).
public SocialsConfig? Socials { get; private set; }
/// The app-wide background music (TASK 9 TRAX) loaded with the last
/// Load() (null = no track chosen).
public Music? Music { get; private set; }
public LayoutStore(string path)
{
ActivePath = path;
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
_connection = new SqliteConnection($"Data Source={path}");
_connection.Open();
using (var pragma = _connection.CreateCommand())
{
pragma.CommandText = "PRAGMA foreign_keys = ON;";
pragma.ExecuteNonQuery();
}
EnsureSchema();
Instance = this;
}
private int GetUserVersion()
{
using var cmd = _connection.CreateCommand();
cmd.CommandText = "PRAGMA user_version;";
return Convert.ToInt32(cmd.ExecuteScalar());
}
public void Dispose()
{
_connection.Dispose();
}
}