123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using Newtonsoft.Json.Converters;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- namespace InitializerModel
- {
- public static class AppSettingConfig
- {
- private static AppSettingConfigModel _Instance;
- public static AppSettingConfigModel Instance
- {
- get
- {
- if (_Instance == null)
- {
- Reload();
- }
- return _Instance;
- }
- private set => _Instance = value;
- }
-
-
-
- private static string settingFileName = "config.ini";
-
-
-
-
-
-
-
-
-
-
-
- public static void Reload()
- {
-
- if (!File.Exists(settingFileName))
- {
- LoadDefaultSetting();
- }
- else
- {
- LoadSettingFromDefaultFile();
- }
- }
- public static void Save()
- {
-
-
-
-
-
-
- File.WriteAllText(
- settingFileName,
- JsonConvert.SerializeObject(
- Instance,
- Formatting.Indented,
- new StringEnumConverter()
- ));
- }
- private static void LoadSettingFromDefaultFile()
- {
- try
- {
- LoadDefaultSetting();
- var configStr = File.ReadAllText(settingFileName);
- var config = Newtonsoft.Json.JsonConvert.DeserializeObject<AppSettingConfigModel>(configStr);
- CompacityChnage(config);
- _Instance = config;
-
-
-
-
-
-
- }
- catch
- {
- }
- }
- private static void LoadDefaultSetting()
- {
- _Instance = new AppSettingConfigModel()
- {
- FirmwareRoot = "./Firmware",
- Language = "zh-chs",
- MES = "sajet2",
- MechineCode = "testMechineCode"
- };
- }
- private static void CompacityChnage(AppSettingConfigModel config)
- {
- if (config == null)
- {
- return;
- }
- if (config.Language.ToLower() == "zh-chs")
- {
- config.Language = "zh-CHS";
- }
- if (config.Language.ToLower() == "en-us")
- {
- config.Language = "en-US";
- }
- }
- }
- }
|