Files
RadioDJViewer/RadioDJViewer/ProfileStorage.cs
2025-09-08 16:38:29 -04:00

76 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
namespace RadioDJViewer
{
public class Profile
{
public string Name { get; set; }
public string IP { get; set; }
public string Port { get; set; }
public string Password { get; set; }
public string MainImagesFolder { get; set; }
public string OutputFolder { get; set; }
public string OutputImageName { get; set; }
public string UrlFormat { get; set; }
public int PollingRateSeconds { get; set; } // Add polling rate property
public string MarqueeScrollSpeed { get; set; } // "Very Slow", etc.
public int MarqueePauseTime { get; set; } // in seconds
public string MarqueeSeparator { get; set; } // e.g. " | "
}
public static class ProfileStorage
{
private static string jsonPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "profiles.json");
private static List<Profile> LoadAll()
{
if (!File.Exists(jsonPath)) return new List<Profile>();
var json = File.ReadAllText(jsonPath);
return JsonConvert.DeserializeObject<List<Profile>>(json) ?? new List<Profile>();
}
private static void SaveAll(List<Profile> profiles)
{
var json = JsonConvert.SerializeObject(profiles, Formatting.Indented);
File.WriteAllText(jsonPath, json);
}
public static void SaveProfile(Profile profile)
{
var profiles = LoadAll();
var existing = profiles.FirstOrDefault(p => p.Name == profile.Name);
if (existing != null)
profiles.Remove(existing);
profiles.Add(profile);
SaveAll(profiles);
}
public static Profile LoadProfile(string name)
{
var profiles = LoadAll();
return profiles.FirstOrDefault(p => p.Name == name);
}
public static List<string> GetProfileNames()
{
var profiles = LoadAll();
return profiles.Select(p => p.Name).ToList();
}
public static void DeleteProfile(string name)
{
var profiles = LoadAll();
var existing = profiles.FirstOrDefault(p => p.Name == name);
if (existing != null)
{
profiles.Remove(existing);
SaveAll(profiles);
}
}
}
}