123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- using FISLib.LiveVideo;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text.Json;
- using Vinno.FIS.Sonopost.Common;
- using Vinno.FIS.Sonopost.Helpers;
- using Vinno.FIS.Sonopost.Settings.Config;
- using Vinno.IUS.Common.Log;
- namespace Vinno.FIS.Sonopost.Settings
- {
- internal class SonopostSystemSettingInfo
- {
- public FISRainbowImageDetectConfig RainbowImageDetectSetting { get; set; }
- public UpdateSetting UpdateSetting { get; set; }
- public WebSetting WebSetting { get; set; }
- public List<string> InputDeviceNames { get; set; }
- public List<string> SkippedMicDeviceNames { get; set; }
- public List<string> SkippedSpeakerDeviceNames { get; set; }
- public string ModelType { get; set; }
- public string CodecName { get; set; }
- public string OledCommName { get; set; }
- }
- internal class SonopostSystemSettings : SonopostSystemSettingInfo
- {
- internal static SonopostSystemSettings Instance { get; private set; }
- private static string _systemSettingFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.SystemSettingsFolder);
- private static string _systemSettingFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.SystemSettingsFolder, SonopostConstants.SystemSettingFileName);
- private static string _systemSettingTempFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SonopostConstants.SystemSettingsFolder, SonopostConstants.SystemSettingTempFileName);
- static SonopostSystemSettings()
- {
- try
- {
- if (!LoadConfig())
- {
- Instance = new SonopostSystemSettings
- {
- RainbowImageDetectSetting = new FISRainbowImageDetectConfig
- {
- BeforeDisableIntervalTime = 3000,
- BeforeEnableIntervalTime = 5000,
- AfterEnableIntervalTime = 2000,
- ScanIntervalTime = 7500,
- IsDetectRainbowImage = false,
- CaptureCardList = new List<string>
- {
- "LT8501-DVI Card",
- "HWSPro Capture Card"
- },
- },
- UpdateSetting = new UpdateSetting
- {
- NeedAutoUpdate = true,
- AutoUpdateTime = 3,
- },
- WebSetting = new WebSetting
- {
- WebPort = 80,
- WebPortStandby = 8080,
- WebSocketPort = 54321,
- },
- InputDeviceNames = new List<string>
- {
- "HD Video 1 (LT8501-DVI Card)",
- "HDPro 1"
- },
- SkippedMicDeviceNames = new List<string>
- {
- "HD Audio 1 (LT8501-DVI Card) (LT8501-DVI Card)",
- "HD Audio 1 (LT8501-DVI Card) (2- LT8501-DVI Card)",
- "HD Audio 1 (LT8501-DVI Card) (HWSPro Capture Card)",
- "HD Audio 1 (LT8501-DVI Card) (2- HWSPro Capture Card)",
- "HDPro Audio 1 (HWSPro Capture Card)",
- "HDPro Audio 1 (2- HWSPro Capture Card)",
- "Microphone (High Definition Audio Device)",
- "Microphone (2- High Definition Audio Device)",
- "麦克风 (High Definition Audio 设备)",
- "麦克风 (2- High Definition Audio 设备)"
- },
- SkippedSpeakerDeviceNames = new List<string>
- {
- "耳机 (High Definition Audio 设备)",
- "耳机 (2- High Definition Audio 设备)",
- "Headphones (High Definition Audio Device)",
- "Headphones (2- High Definition Audio Device)"
- },
- ModelType = "SP-0002",
- CodecName = "h264_qsv",
- OledCommName = null,
- };
- Instance.Save();
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"SonopostSystemSettings Static Cstr Error:{ex}");
- }
- }
- private static bool LoadConfig()
- {
- if (!Directory.Exists(_systemSettingFolderPath))
- {
- Logger.WriteLineError($"SonopostSystemSettingInfo Load Config Fail,{_systemSettingFolderPath} is not exist");
- Directory.CreateDirectory(_systemSettingFolderPath);
- return false;
- }
- if (!File.Exists(_systemSettingFilePath) && !File.Exists(_systemSettingTempFilePath))
- {
- Logger.WriteLineError($"SonopostSystemSettingInfo Load Config Fail,{_systemSettingFilePath} and {_systemSettingTempFilePath} are not exist");
- return false;
- }
- else
- {
- if (File.Exists(_systemSettingFilePath))
- {
- if (LoadConfigFile())
- {
- return true;
- }
- else if (File.Exists(_systemSettingTempFilePath))
- {
- return LoadTempConfigFile();
- }
- }
- else
- {
- return LoadTempConfigFile();
- }
- }
- return false;
- }
- private static bool LoadTempConfigFile()
- {
- try
- {
- var jsonString = File.ReadAllText(_systemSettingTempFilePath);
- Instance = JsonHelper.JsonToObj<SonopostSystemSettings>(jsonString);
- if (Instance == null)
- {
- Logger.WriteLineError($"SonopostSystemSettingInfo Load temp Config Fail,Instance is null");
- return false;
- }
- return true;
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"SonopostSystemSettingInfo Load temp Config Fail,ex:{ex}");
- }
- return false;
- }
- private static bool LoadConfigFile()
- {
- try
- {
- var jsonString = File.ReadAllText(_systemSettingFilePath);
- Instance = JsonHelper.JsonToObj<SonopostSystemSettings>(jsonString);
- if (Instance == null)
- {
- Logger.WriteLineError($"SonopostSystemSettingInfo Load Config Fail,Instance is null");
- return false;
- }
- return true;
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"SonopostSystemSettingInfo Load Config Fail,ex:{ex}");
- }
- return false;
- }
- /// <summary>
- /// Save settings.
- /// </summary>
- public void Save()
- {
- try
- {
- DirectoryHelper.CreateDirectory(_systemSettingFolderPath);
- var jsonString = JsonHelper.ToJson(Instance, new JsonSerializerOptions
- {
- WriteIndented = true
- });
- File.WriteAllText(_systemSettingTempFilePath, jsonString);
- FileHelper.CopyFile(_systemSettingTempFilePath, _systemSettingFilePath, true);
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"SonopostSystemSettingInfo Save Error:{ex}");
- }
- }
- }
- }
|