1e8e444376
- Added PlaylistsGroupViewModel to manage playlists and selection. - Introduced ProgramsGroupViewModel for handling program groups and subscriptions. - Created ProgramsListViewModel to manage individual program listings. - Developed SettingsViewModel for user settings including playlist management. - Implemented TVPlayerViewModel as the main view model coordinating screens and data. - Added PlayerView for video playback with LibVLC integration. - Created XAML views for PlaylistsGroup, ProgramsGroup, ProgramsList, and Settings. - Added sample M3U playlist for testing. - Documented WPF build instructions and project structure in WPF-BUILD.md. - Configured global.json for .NET SDK versioning.
88 lines
3.1 KiB
C#
88 lines
3.1 KiB
C#
using Newtonsoft.Json;
|
|
using System.IO;
|
|
|
|
namespace TV_Player.ViewModels
|
|
{
|
|
public static class SettingsModel
|
|
{
|
|
private static readonly string AppDataFolder = Path.Combine(GetWritableAppDataFolder(), "TVPlayer");
|
|
private static readonly string SettingsFilePath = Path.Combine(AppDataFolder, "settings.json");
|
|
|
|
private static string GetWritableAppDataFolder()
|
|
{
|
|
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
if (!string.IsNullOrWhiteSpace(localAppData))
|
|
{
|
|
return localAppData;
|
|
}
|
|
|
|
var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
if (!string.IsNullOrWhiteSpace(appData))
|
|
{
|
|
return appData;
|
|
}
|
|
|
|
return AppContext.BaseDirectory;
|
|
}
|
|
|
|
public static Dictionary<string,string> Playlists { get; set; }
|
|
public static bool StartFullScreen { get; set; }
|
|
public static bool StartFromLastScreen { get; set; }
|
|
public static string LastScreen { get; set; }
|
|
public static GroupInfo Group { get; set; }
|
|
public static M3UInfo Program { get; set; }
|
|
public static string[] HiddenGroups { get; set; }
|
|
|
|
public static void SaveSetttings()
|
|
{
|
|
// Create an anonymous object to hold the properties
|
|
var dataToSerialize = new
|
|
{
|
|
Playlists,
|
|
StartFromLastScreen,
|
|
StartFullScreen,
|
|
LastScreen,
|
|
Group,
|
|
Program,
|
|
HiddenGroups,
|
|
};
|
|
|
|
// Serialize the object to JSON
|
|
string json = JsonConvert.SerializeObject(dataToSerialize, Formatting.Indented);
|
|
|
|
if (!Directory.Exists(AppDataFolder))
|
|
Directory.CreateDirectory(AppDataFolder);
|
|
// Save the JSON to a file
|
|
File.WriteAllText(SettingsFilePath, json);
|
|
}
|
|
|
|
public static void LoadSettings()
|
|
{
|
|
var loadedData = new
|
|
{
|
|
Playlists = default(Dictionary<string,string>),
|
|
LastScreen = default(string),
|
|
Group = default(GroupInfo),
|
|
Program = default(M3UInfo),
|
|
StartFromLastScreen = default(bool),
|
|
StartFullScreen = default(bool),
|
|
HiddenGroups = default(string[])
|
|
};
|
|
if (File.Exists(SettingsFilePath))
|
|
{
|
|
// Read the JSON content from the file
|
|
string json = File.ReadAllText(SettingsFilePath);
|
|
loadedData = JsonConvert.DeserializeAnonymousType(json, loadedData);
|
|
}
|
|
// Assign the values to the properties
|
|
Playlists = loadedData.Playlists;
|
|
LastScreen = loadedData.LastScreen;
|
|
Group = loadedData.Group;
|
|
Program = loadedData.Program;
|
|
StartFromLastScreen = loadedData.StartFromLastScreen;
|
|
StartFullScreen = loadedData.StartFullScreen;
|
|
HiddenGroups = loadedData.HiddenGroups;
|
|
}
|
|
}
|
|
}
|