/
spruttechnology
/
cam-api-examples
Обзор
Документация
Войти
/
spruttechnology
/
cam-api-examples
Код
Запросы
3
Задачи
Пакеты
0
Релизы
1
Аналитика
v19/develop
FullWorkflow/PartCalibrationWorkflowNet/project/main/Service/SettingsRepository.cs
42 строки
1 KB
renal
Новые примеры CAMAPI
22 июн 2026, 15:53
22 июн 2026, 15:53
a5f6d2b
Код
Авторство
О чём код?
using System.IO; using System.Text.Json; using PartCalibrationWorkflowNet.Model; namespace PartCalibrationWorkflowNet.Service; /// <summary> /// Loads / saves <see cref="WizardSettings"/> as a JSON file next to the extension DLL. /// </summary> internal sealed class SettingsRepository { private static readonly JsonSerializerOptions JsonOpts = new() { WriteIndented = true }; private readonly string _filePath; public SettingsRepository(string pluginDir) { _filePath = Path.Combine(pluginDir, "wizard.user.json"); } public WizardSettings Load() { if (!File.Exists(_filePath)) return new WizardSettings(); try { var json = File.ReadAllText(_filePath); return JsonSerializer.Deserialize<WizardSettings>(json) ?? new WizardSettings(); } catch { // Corrupted user settings — fall back to defaults silently. return new WizardSettings(); } } public void Save(WizardSettings settings) { File.WriteAllText(_filePath, JsonSerializer.Serialize(settings, JsonOpts)); } }