ConfigService.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. namespace EEMSUIClient.Services;
  2. public class ConfigService(LocalFilePathInfo localFile,
  3. ConfigPath configPath,
  4. RunningData running,
  5. AddressInfo address)
  6. {
  7. public bool SaveDirectoryInfo()
  8. {
  9. return JsonHelper.WriteFile(configPath.FolderInfoFilePath, localFile);
  10. }
  11. public bool LoadDirectoryInfo()
  12. {
  13. if (!JsonHelper.ReadFile(configPath.FolderInfoFilePath, out LocalFilePathInfo? folder) || folder is null)
  14. return false;
  15. folder.Adapt(localFile);
  16. return true;
  17. }
  18. public bool SaveDeviceInfo()
  19. {
  20. return JsonHelper.WriteFile(configPath.DeviceInfoFilePath, running.DeviceInfo);
  21. }
  22. public bool LoadDeviceInfo()
  23. {
  24. if (!JsonHelper.ReadFile(configPath.DeviceInfoFilePath, out DeviceInfo? device) || device is null)
  25. return false;
  26. device.Adapt(running.DeviceInfo);
  27. return true;
  28. }
  29. public bool SaveConnectionInfo()
  30. {
  31. return JsonHelper.WriteFile(configPath.IPAddressFilePath, address);
  32. }
  33. public bool LoadConnectionInfo()
  34. {
  35. if (!JsonHelper.ReadFile(configPath.IPAddressFilePath, out AddressInfo? addressInfo) || addressInfo is null)
  36. return false;
  37. addressInfo.Adapt(address);
  38. return true;
  39. }
  40. }