对比新文件 |
| | |
| | | 锘縰sing System.Text; |
| | | |
| | | namespace HStation.Settings |
| | | { |
| | | internal class XhsFileHelper |
| | | { |
| | | /// <summary> |
| | | /// json鏂囦欢鍚嶇О |
| | | /// </summary> |
| | | internal static string JsonFileName |
| | | { |
| | | get |
| | | { |
| | | if (string.IsNullOrEmpty(_jsonFileName)) |
| | | { |
| | | _jsonFileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "paras_xhs_settings.json"); |
| | | } |
| | | return _jsonFileName; |
| | | } |
| | | } |
| | | |
| | | private static string _jsonFileName = null; |
| | | |
| | | /// <summary> |
| | | /// 鑾峰彇 |
| | | /// </summary> |
| | | internal static XhsParas Get() |
| | | { |
| | | if (_appparas == null) |
| | | { |
| | | lock (_locker) |
| | | { |
| | | if (_appparas == null) |
| | | { |
| | | var json = File.ReadAllText(JsonFileName, Encoding.UTF8); |
| | | _appparas = JsonHelper.Json2Object<XhsParas>(json); |
| | | if (_appparas == null) |
| | | { |
| | | _appparas = new XhsParas(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return _appparas; |
| | | } |
| | | |
| | | private static XhsParas _appparas = null; |
| | | private static readonly object _locker = new object(); |
| | | |
| | | /// <summary> |
| | | /// 淇濆瓨 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | internal static bool Save() |
| | | { |
| | | if (_appparas == null) |
| | | { |
| | | return default; |
| | | } |
| | | var json = JsonHelper.Object2FormatJson(_appparas); |
| | | File.WriteAllText(JsonFileName, json, Encoding.UTF8); |
| | | return true; |
| | | } |
| | | } |
| | | } |