123456789101112131415161718192021222324252627282930 |
- using Bmp.Core.Common.AssemblyInject.Interfaces;
- using Bmp.Core.Common.EventBus;
- using Bmp.WinForms.SaveLoad.Models;
- using Newtonsoft.Json;
- namespace Bmp.WinForms.SaveLoad;
- internal class SaveLoadService : IAssemblyInjectSingleton, IAssemblyInjectSyncInitStarStop
- {
- private readonly IEventBus _eventBus;
- private static readonly string FileName = $"{Application.ExecutablePath}.{nameof(SaveLoadState)}.json";
- public SaveLoadState State { get; private set; } = new();
- public SaveLoadService(IEventBus eventBus) => _eventBus = eventBus;
- public void Init()
- {
- }
- public void Start()
- {
- if (File.Exists(FileName)) State = JsonConvert.DeserializeObject<SaveLoadState>(File.ReadAllText(FileName)) ?? new();
- else State = new();
- }
- public void Stop() => Save();
- public void Save() => File.WriteAllText(FileName, JsonConvert.SerializeObject(State));
- }
|