123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- 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;
- namespace Vinno.FIS.Sonopost.Features.Config
- {
- 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 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);
- static SonopostSystemSettings()
- {
- 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"
- },
- },
- 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)"
- },
- SkippedMicDeviceNames = new List<string>
- {
- "HD Audio 1 (LT8501-DVI Card) (LT8501-DVI Card)"
- },
- ModelType = "SP-0002",
- CodecName = "h264_qsv",
- OledCommName = null,
- };
- Instance.Save();
- }
- }
- private static bool LoadConfig()
- {
- if (!Directory.Exists(_systemSettingFolderPath))
- {
- Directory.CreateDirectory(_systemSettingFolderPath);
- return false;
- }
- if (!File.Exists(_systemSettingFilePath))
- {
- return false;
- }
- try
- {
- var jsonString = File.ReadAllText(_systemSettingFilePath);
- Instance = JsonHelper.JsonToObj<SonopostSystemSettings>(jsonString);
- if (Instance == null)
- {
- return false;
- }
- return true;
- }
- catch
- {
- }
- return false;
- }
- /// <summary>
- /// Save settings.
- /// </summary>
- public void Save()
- {
- DirectoryHelper.CreateDirectory(_systemSettingFolderPath);
- var jsonString = JsonHelper.ToJson(Instance, new JsonSerializerOptions
- {
- WriteIndented = true
- });
- File.WriteAllText(_systemSettingFilePath, jsonString);
- }
- }
- }
|