mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using Remotely.Desktop.Core.Interfaces;
|
|
using Remotely.Shared.Models;
|
|
using Remotely.Shared.Utilities;
|
|
using System;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace Remotely.Desktop.Win.Services
|
|
{
|
|
|
|
public class ConfigServiceWin : IConfigService
|
|
{
|
|
private static readonly string _configFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Remotely");
|
|
private static readonly string _configFile = Path.Combine(_configFolder, "Config.json");
|
|
|
|
public DesktopAppConfig GetConfig()
|
|
{
|
|
var config = new DesktopAppConfig();
|
|
|
|
if (string.IsNullOrWhiteSpace(config.Host) &&
|
|
File.Exists(_configFile))
|
|
{
|
|
try
|
|
{
|
|
config = JsonSerializer.Deserialize<DesktopAppConfig>(File.ReadAllText(_configFile));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Write(ex);
|
|
}
|
|
}
|
|
|
|
return config;
|
|
}
|
|
|
|
public void Save(DesktopAppConfig config)
|
|
{
|
|
try
|
|
{
|
|
Directory.CreateDirectory(_configFolder);
|
|
File.WriteAllText(_configFile, JsonSerializer.Serialize(config));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Write(ex);
|
|
}
|
|
}
|
|
}
|
|
}
|