SonopostSystemSettingInfo.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using FISLib.LiveVideo;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Text.Json;
  6. using Vinno.FIS.Sonopost.Common;
  7. using Vinno.FIS.Sonopost.Helpers;
  8. namespace Vinno.FIS.Sonopost.Features.Config
  9. {
  10. internal class SonopostSystemSettingInfo
  11. {
  12. public FISRainbowImageDetectConfig RainbowImageDetectSetting { get; set; }
  13. public UpdateSetting UpdateSetting { get; set; }
  14. public WebSetting WebSetting { get; set; }
  15. public List<string> InputDeviceNames { get; set; }
  16. public List<string> SkippedMicDeviceNames { get; set; }
  17. public string ModelType { get; set; }
  18. public string CodecName { get; set; }
  19. public string OledCommName { get; set; }
  20. }
  21. internal class SonopostSystemSettings : SonopostSystemSettingInfo
  22. {
  23. internal static SonopostSystemSettings Instance { get; private set; }
  24. private static string _systemSettingFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.SystemSettingsFolder);
  25. private static string _systemSettingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.SystemSettingsFolder, SonopostConstants.SystemSettingFileName);
  26. static SonopostSystemSettings()
  27. {
  28. if (!LoadConfig())
  29. {
  30. Instance = new SonopostSystemSettings
  31. {
  32. RainbowImageDetectSetting = new FISRainbowImageDetectConfig
  33. {
  34. BeforeDisableIntervalTime = 3000,
  35. BeforeEnableIntervalTime = 5000,
  36. AfterEnableIntervalTime = 2000,
  37. ScanIntervalTime = 7500,
  38. IsDetectRainbowImage = false,
  39. CaptureCardList = new List<string>
  40. {
  41. "LT8501-DVI Card"
  42. },
  43. },
  44. UpdateSetting = new UpdateSetting
  45. {
  46. NeedAutoUpdate = true,
  47. AutoUpdateTime = 3,
  48. },
  49. WebSetting = new WebSetting
  50. {
  51. WebPort = 80,
  52. WebPortStandby = 8080,
  53. WebSocketPort = 54321,
  54. },
  55. InputDeviceNames = new List<string>
  56. {
  57. "HD Video 1 (LT8501-DVI Card)"
  58. },
  59. SkippedMicDeviceNames = new List<string>
  60. {
  61. "HD Audio 1 (LT8501-DVI Card) (LT8501-DVI Card)"
  62. },
  63. ModelType = "SP-0002",
  64. CodecName = "h264_qsv",
  65. OledCommName = null,
  66. };
  67. Instance.Save();
  68. }
  69. }
  70. private static bool LoadConfig()
  71. {
  72. if (!Directory.Exists(_systemSettingFolderPath))
  73. {
  74. Directory.CreateDirectory(_systemSettingFolderPath);
  75. return false;
  76. }
  77. if (!File.Exists(_systemSettingFilePath))
  78. {
  79. return false;
  80. }
  81. try
  82. {
  83. var jsonString = File.ReadAllText(_systemSettingFilePath);
  84. Instance = JsonHelper.JsonToObj<SonopostSystemSettings>(jsonString);
  85. if (Instance == null)
  86. {
  87. return false;
  88. }
  89. return true;
  90. }
  91. catch
  92. {
  93. }
  94. return false;
  95. }
  96. /// <summary>
  97. /// Save settings.
  98. /// </summary>
  99. public void Save()
  100. {
  101. DirectoryHelper.CreateDirectory(_systemSettingFolderPath);
  102. var jsonString = JsonHelper.ToJson(Instance, new JsonSerializerOptions
  103. {
  104. WriteIndented = true
  105. });
  106. File.WriteAllText(_systemSettingFilePath, jsonString);
  107. }
  108. }
  109. }