SonopostSystemSettingInfo.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. using Vinno.FIS.Sonopost.Settings.Config;
  9. using Vinno.IUS.Common.Log;
  10. namespace Vinno.FIS.Sonopost.Settings
  11. {
  12. internal class SonopostSystemSettingInfo
  13. {
  14. public FISRainbowImageDetectConfig RainbowImageDetectSetting { get; set; }
  15. public UpdateSetting UpdateSetting { get; set; }
  16. public WebSetting WebSetting { get; set; }
  17. public List<string> InputDeviceNames { get; set; }
  18. public List<string> SkippedMicDeviceNames { get; set; }
  19. public List<string> SkippedSpeakerDeviceNames { get; set; }
  20. public string ModelType { get; set; }
  21. public string CodecName { get; set; }
  22. public string OledCommName { get; set; }
  23. }
  24. internal class SonopostSystemSettings : SonopostSystemSettingInfo
  25. {
  26. internal static SonopostSystemSettings Instance { get; private set; }
  27. private static string _systemSettingFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.SystemSettingsFolder);
  28. private static string _systemSettingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.SystemSettingsFolder, SonopostConstants.SystemSettingFileName);
  29. private static string _systemSettingTempFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.SystemSettingsFolder, SonopostConstants.SystemSettingTempFileName);
  30. static SonopostSystemSettings()
  31. {
  32. try
  33. {
  34. if (!LoadConfig())
  35. {
  36. Instance = new SonopostSystemSettings
  37. {
  38. RainbowImageDetectSetting = new FISRainbowImageDetectConfig
  39. {
  40. BeforeDisableIntervalTime = 3000,
  41. BeforeEnableIntervalTime = 5000,
  42. AfterEnableIntervalTime = 2000,
  43. ScanIntervalTime = 7500,
  44. IsDetectRainbowImage = false,
  45. CaptureCardList = new List<string>
  46. {
  47. "LT8501-DVI Card",
  48. "HWSPro Capture Card"
  49. },
  50. },
  51. UpdateSetting = new UpdateSetting
  52. {
  53. NeedAutoUpdate = true,
  54. AutoUpdateTime = 3,
  55. },
  56. WebSetting = new WebSetting
  57. {
  58. WebPort = 80,
  59. WebPortStandby = 8080,
  60. WebSocketPort = 54321,
  61. },
  62. InputDeviceNames = new List<string>
  63. {
  64. "HD Video 1 (LT8501-DVI Card)",
  65. "HDPro 1"
  66. },
  67. SkippedMicDeviceNames = new List<string>
  68. {
  69. "HD Audio 1 (LT8501-DVI Card) (LT8501-DVI Card)",
  70. "HD Audio 1 (LT8501-DVI Card) (2- LT8501-DVI Card)",
  71. "HD Audio 1 (LT8501-DVI Card) (HWSPro Capture Card)",
  72. "HD Audio 1 (LT8501-DVI Card) (2- HWSPro Capture Card)",
  73. "HDPro Audio 1 (HWSPro Capture Card)",
  74. "HDPro Audio 1 (2- HWSPro Capture Card)",
  75. "Microphone (High Definition Audio Device)",
  76. "Microphone (2- High Definition Audio Device)",
  77. "麦克风 (High Definition Audio 设备)",
  78. "麦克风 (2- High Definition Audio 设备)"
  79. },
  80. SkippedSpeakerDeviceNames = new List<string>
  81. {
  82. "耳机 (High Definition Audio 设备)",
  83. "耳机 (2- High Definition Audio 设备)",
  84. "Headphones (High Definition Audio Device)",
  85. "Headphones (2- High Definition Audio Device)"
  86. },
  87. ModelType = "SP-0002",
  88. CodecName = "h264_qsv",
  89. OledCommName = null,
  90. };
  91. Instance.Save();
  92. }
  93. }
  94. catch (Exception ex)
  95. {
  96. Logger.WriteLineError($"SonopostSystemSettings Static Cstr Error:{ex}");
  97. }
  98. }
  99. private static bool LoadConfig()
  100. {
  101. if (!Directory.Exists(_systemSettingFolderPath))
  102. {
  103. Logger.WriteLineError($"SonopostSystemSettingInfo Load Config Fail,{_systemSettingFolderPath} is not exist");
  104. Directory.CreateDirectory(_systemSettingFolderPath);
  105. return false;
  106. }
  107. if (!File.Exists(_systemSettingFilePath) && !File.Exists(_systemSettingTempFilePath))
  108. {
  109. Logger.WriteLineError($"SonopostSystemSettingInfo Load Config Fail,{_systemSettingFilePath} and {_systemSettingTempFilePath} are not exist");
  110. return false;
  111. }
  112. else
  113. {
  114. if (File.Exists(_systemSettingFilePath))
  115. {
  116. if (LoadConfigFile())
  117. {
  118. return true;
  119. }
  120. else if (File.Exists(_systemSettingTempFilePath))
  121. {
  122. return LoadTempConfigFile();
  123. }
  124. }
  125. else
  126. {
  127. return LoadTempConfigFile();
  128. }
  129. }
  130. return false;
  131. }
  132. private static bool LoadTempConfigFile()
  133. {
  134. try
  135. {
  136. var jsonString = File.ReadAllText(_systemSettingTempFilePath);
  137. Instance = JsonHelper.JsonToObj<SonopostSystemSettings>(jsonString);
  138. if (Instance == null)
  139. {
  140. Logger.WriteLineError($"SonopostSystemSettingInfo Load temp Config Fail,Instance is null");
  141. return false;
  142. }
  143. return true;
  144. }
  145. catch (Exception ex)
  146. {
  147. Logger.WriteLineError($"SonopostSystemSettingInfo Load temp Config Fail,ex:{ex}");
  148. }
  149. return false;
  150. }
  151. private static bool LoadConfigFile()
  152. {
  153. try
  154. {
  155. var jsonString = File.ReadAllText(_systemSettingFilePath);
  156. Instance = JsonHelper.JsonToObj<SonopostSystemSettings>(jsonString);
  157. if (Instance == null)
  158. {
  159. Logger.WriteLineError($"SonopostSystemSettingInfo Load Config Fail,Instance is null");
  160. return false;
  161. }
  162. return true;
  163. }
  164. catch (Exception ex)
  165. {
  166. Logger.WriteLineError($"SonopostSystemSettingInfo Load Config Fail,ex:{ex}");
  167. }
  168. return false;
  169. }
  170. /// <summary>
  171. /// Save settings.
  172. /// </summary>
  173. public void Save()
  174. {
  175. try
  176. {
  177. DirectoryHelper.CreateDirectory(_systemSettingFolderPath);
  178. var jsonString = JsonHelper.ToJson(Instance, new JsonSerializerOptions
  179. {
  180. WriteIndented = true
  181. });
  182. File.WriteAllText(_systemSettingTempFilePath, jsonString);
  183. FileHelper.CopyFile(_systemSettingTempFilePath, _systemSettingFilePath, true);
  184. }
  185. catch (Exception ex)
  186. {
  187. Logger.WriteLineError($"SonopostSystemSettingInfo Save Error:{ex}");
  188. }
  189. }
  190. }
  191. }