123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- using FISLib.LiveVideo;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text.Json;
- using Vinno.FIS.Sonopost.Common;
- using Vinno.FIS.Sonopost.Features.Oled;
- using Vinno.FIS.Sonopost.Helpers;
- namespace Vinno.FIS.Sonopost.Features.Config
- {
- internal class SonopostUserDefinedSettingInfo
- {
- public ServerSetting ServerSetting { get; set; }
- public DicomSetting DicomSetting { get; set; }
- public NetworkSetting NetworkSetting { get; set; }
- public HardwareSetting HardwareSetting { get; set; }
- public OledSetting OledSetting { get; set; }
- public PageSetting PageSetting { get; set; }
- public CaptureSetting CaptureSetting { get; set; }
- public bool IsFirstLogin { get; set; }
- public int Version { get; set; }
- }
- internal class SonopostUserDefinedSettings : SonopostUserDefinedSettingInfo
- {
- internal static SonopostUserDefinedSettings Instance { get; private set; }
- private static string _userDefinedFolderPath = Path.Combine(SonopostConstants.DataFolder, SonopostConstants.UserDefinedSettingsFolder);
- private static string _userDefinedFilePath = Path.Combine(SonopostConstants.DataFolder, SonopostConstants.UserDefinedSettingsFolder, SonopostConstants.UserDefinedSettingFileName);
- static SonopostUserDefinedSettings()
- {
- if (!LoadConfig())
- {
- Instance = new SonopostUserDefinedSettings
- {
- ServerSetting = new ServerSetting
- {
- DefaultServer = new ServerInfoSetting(SonopostConstants.ChinaServerHost, 9096, true, SonopostConstants.FlyinsonoServerName),
- Servers = new List<ServerInfoSetting>
- {
- new ServerInfoSetting(SonopostConstants.ChinaServerHost, 9096, true, SonopostConstants.FlyinsonoServerName),
- new ServerInfoSetting(SonopostConstants.ChinaServerHost, 9096, true, ""),
- new ServerInfoSetting(SonopostConstants.GermanyServerHost, 9096, true, ""),
- new ServerInfoSetting(SonopostConstants.HongkongServerHost, 9096, true, ""),
- },
- },
- DicomSetting = new DicomSetting
- {
- UseDicomService = false,
- DicomTitile = "Sonopost",
- DicomPort = 104,
- TempFileDays = 1,
- UseWorkStationProxy = false,
- WorkStationTitle = "vStation",
- WorkStationIpAddress = "",
- WorkStationPort = 6104,
- },
- NetworkSetting = new NetworkSetting(),
- HardwareSetting = new HardwareSetting
- {
- VideoDeviceInfoList = new List<FISVideoDeviceInfo>(),
- MicDeviceInfo = new FISMicDeviceInfo(),
- },
- OledSetting = new OledSetting
- {
- Language = Language.Chinese,
- },
- PageSetting = new PageSetting
- {
- Language = Language.Chinese,
- },
- CaptureSetting = new CaptureSetting
- {
- RealTimeCaptureEnabled = false,
- ImageCaptureKeyForFootToogle = EnumFootToggleKey.LeftKey,
- VideoCaptureKeyForFootToggle = EnumFootToggleKey.RightKey,
- FootToggleLeftKeyForKeyBoard = EnumKeyboardKey.F1,
- FootToggleRightKeyForKeyBoard = EnumKeyboardKey.F2,
- },
- IsFirstLogin = true,
- Version = SonopostConstants.CurrentSonopostUserDefinedSettingVersion,
- };
- Instance.Save();
- }
- }
- private static bool LoadConfig()
- {
- if (!Directory.Exists(_userDefinedFolderPath))
- {
- Directory.CreateDirectory(_userDefinedFolderPath);
- return false;
- }
- if (!File.Exists(_userDefinedFilePath))
- {
- return false;
- }
- try
- {
- var jsonString = File.ReadAllText(_userDefinedFilePath);
- Instance = JsonHelper.JsonToObj<SonopostUserDefinedSettings>(jsonString);
- if (Instance == null)
- {
- return false;
- }
- if (Instance.Version < SonopostConstants.CurrentSonopostUserDefinedSettingVersion)
- {
- UpdateVersionFrom0To1();
- UpdateVersionFrom1To2();
- }
- return true;
- }
- catch
- {
- }
- return false;
- }
- private static void UpdateVersionFrom0To1()
- {
- if (Instance.Version == 0)
- {
- if (Instance.PageSetting == null)//老版的配置文件可能为空,
- {
- Instance.PageSetting = new PageSetting
- {
- Language = Language.Chinese,
- };
- }
- if (!Instance.ServerSetting.Servers.Any(x => x.DisplayName == SonopostConstants.ChinaServerName && x.IsDefault))
- {
- Instance.ServerSetting.Servers.Insert(1, new ServerInfoSetting(SonopostConstants.ChinaServerHost, 9096, true, ""));
- }
- if (!Instance.ServerSetting.Servers.Any(x => x.DisplayName == SonopostConstants.GermanyServerName && x.IsDefault))
- {
- Instance.ServerSetting.Servers.Insert(2, new ServerInfoSetting(SonopostConstants.GermanyServerHost, 9096, true, ""));
- }
- if (!Instance.ServerSetting.Servers.Any(x => x.DisplayName == SonopostConstants.HongkongServerName && x.IsDefault))
- {
- Instance.ServerSetting.Servers.Insert(3, new ServerInfoSetting(SonopostConstants.HongkongServerHost, 9096, true, ""));
- }
- if (Instance.CaptureSetting == null || Instance.CaptureSetting.ImageCaptureKeyForFootToogle == Instance.CaptureSetting.VideoCaptureKeyForFootToggle || Instance.CaptureSetting.FootToggleLeftKeyForKeyBoard == Instance.CaptureSetting.FootToggleRightKeyForKeyBoard)
- {
- Instance.CaptureSetting = new CaptureSetting
- {
- RealTimeCaptureEnabled = false,
- ImageCaptureKeyForFootToogle = EnumFootToggleKey.LeftKey,
- VideoCaptureKeyForFootToggle = EnumFootToggleKey.RightKey,
- FootToggleLeftKeyForKeyBoard = EnumKeyboardKey.F1,
- FootToggleRightKeyForKeyBoard = EnumKeyboardKey.F2,
- };
- }
- Instance.Version = 1;
- Instance.Save();
- }
- }
- private static void UpdateVersionFrom1To2()
- {
- if (Instance.Version == 1)
- {
- if (Instance.CaptureSetting == null)
- {
- Instance.CaptureSetting = new CaptureSetting
- {
- RealTimeCaptureEnabled = false,
- ImageCaptureKeyForFootToogle = EnumFootToggleKey.LeftKey,
- VideoCaptureKeyForFootToggle = EnumFootToggleKey.RightKey,
- FootToggleLeftKeyForKeyBoard = EnumKeyboardKey.F1,
- FootToggleRightKeyForKeyBoard = EnumKeyboardKey.F2,
- };
- }
- Instance.Version = 2;
- Instance.Save();
- }
- }
- /// <summary>
- /// Save settings.
- /// </summary>
- public void Save()
- {
- DirectoryHelper.CreateDirectory(_userDefinedFolderPath);
- var jsonString = JsonHelper.ToJson(Instance, new JsonSerializerOptions
- {
- WriteIndented = true
- });
- File.WriteAllText(_userDefinedFilePath, jsonString);
- }
- }
- }
|