additions
This commit is contained in:
58
desktop_global/ServerConfig.cs
Normal file
58
desktop_global/ServerConfig.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace VideoReader
|
||||
{
|
||||
public class ServerConfig
|
||||
{
|
||||
public string ServerType { get; set; } = "standard";
|
||||
public string ServerAddress { get; set; } = "vidser.top";
|
||||
public int Port { get; set; } = 3033;
|
||||
public int Channel { get; set; } = 0;
|
||||
public string Description { get; set; } = "Standard VideoReader server configuration";
|
||||
|
||||
public static ServerConfig LoadConfig()
|
||||
{
|
||||
const string configFile = "server-config.json";
|
||||
|
||||
try
|
||||
{
|
||||
if (File.Exists(configFile))
|
||||
{
|
||||
var json = File.ReadAllText(configFile);
|
||||
var config = JsonSerializer.Deserialize<ServerConfig>(json);
|
||||
Console.WriteLine($"Configuration loaded from {configFile}");
|
||||
return config ?? new ServerConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Configuration file {configFile} not found, using defaults");
|
||||
var defaultConfig = new ServerConfig();
|
||||
SaveConfig(defaultConfig);
|
||||
return defaultConfig;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error loading configuration: {ex.Message}");
|
||||
return new ServerConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveConfig(ServerConfig config)
|
||||
{
|
||||
const string configFile = "server-config.json";
|
||||
try
|
||||
{
|
||||
var json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(configFile, json);
|
||||
Console.WriteLine($"Configuration saved to {configFile}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error saving configuration: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user