64e3fbe035
v2-ci / build (push) Failing after 1m43s
v2-ci / unit-tests (tests/Core/ZB.MOM.WW.OtOpcUa.Cluster.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.ControlPlane.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.Host.IntegrationTests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests) (push) Has been skipped
Adds <summary>, <param>, <typeparam>, and <inheritdoc/> tags to public members surfaced by commentchecker — resolves 5,847 of 5,869 issues (99.6%) across three /fixdocs passes.
56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
using System.Text.Json;
|
|
using ZB.MOM.WW.OtOpcUa.Client.Shared;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Client.UI.Services;
|
|
|
|
/// <summary>
|
|
/// Persists user settings to a JSON file under LocalApplicationData.
|
|
/// </summary>
|
|
public sealed class JsonSettingsService : ISettingsService
|
|
{
|
|
// ClientStoragePaths.GetRoot runs the one-shot legacy-folder migration so pre-#208
|
|
// developer boxes pick up their existing settings.json on first launch post-rename.
|
|
private static readonly string SettingsDir = ClientStoragePaths.GetRoot();
|
|
|
|
private static readonly string SettingsPath = Path.Combine(SettingsDir, "settings.json");
|
|
|
|
private static readonly JsonSerializerOptions JsonOptions = new()
|
|
{
|
|
WriteIndented = true
|
|
};
|
|
|
|
/// <summary>Loads user settings from the settings file.</summary>
|
|
/// <returns>The loaded user settings, or a new default instance if load fails.</returns>
|
|
public UserSettings Load()
|
|
{
|
|
try
|
|
{
|
|
if (!File.Exists(SettingsPath))
|
|
return new UserSettings();
|
|
|
|
var json = File.ReadAllText(SettingsPath);
|
|
return JsonSerializer.Deserialize<UserSettings>(json, JsonOptions) ?? new UserSettings();
|
|
}
|
|
catch
|
|
{
|
|
return new UserSettings();
|
|
}
|
|
}
|
|
|
|
/// <summary>Saves user settings to the settings file.</summary>
|
|
/// <param name="settings">The user settings to save.</param>
|
|
public void Save(UserSettings settings)
|
|
{
|
|
try
|
|
{
|
|
Directory.CreateDirectory(SettingsDir);
|
|
var json = JsonSerializer.Serialize(settings, JsonOptions);
|
|
File.WriteAllText(SettingsPath, json);
|
|
}
|
|
catch
|
|
{
|
|
// Best-effort save; don't crash the app
|
|
}
|
|
}
|
|
}
|