Remotely/Desktop.Linux/Services/Config.cs
2021-07-29 07:56:15 -07:00

46 lines
1.3 KiB
C#

using System;
using System.IO;
using System.Text.Json;
namespace Remotely.Desktop.Linux.Services
{
public class Config
{
public string Host { get; set; } = "";
private static string ConfigFile => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Remotely", "Config.json");
private static string ConfigFolder => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Remotely");
public static Config GetConfig()
{
if (!Directory.Exists(ConfigFolder))
{
return new Config();
}
if (File.Exists(ConfigFile))
{
try
{
return JsonSerializer.Deserialize<Config>(File.ReadAllText(ConfigFile));
}
catch
{
return new Config();
}
}
return new Config();
}
public void Save()
{
try
{
Directory.CreateDirectory(ConfigFolder);
File.WriteAllText(ConfigFile, JsonSerializer.Serialize(this));
}
catch
{
}
}
}
}