SettingConfig.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace AwInitilizer
  8. {
  9. public class AppSettingConfig
  10. {
  11. public static string FirmwareRoot
  12. {
  13. get
  14. {
  15. if(Instance == null)
  16. {
  17. Instance = new AppSettingConfig();
  18. }
  19. return Instance._FirmwareRoot;
  20. }
  21. }
  22. public static string Language
  23. {
  24. get
  25. {
  26. if (Instance == null)
  27. {
  28. Instance = new AppSettingConfig();
  29. }
  30. return Instance._Language;
  31. }
  32. }
  33. public static string MES
  34. {
  35. get
  36. {
  37. if (Instance == null)
  38. {
  39. Instance = new AppSettingConfig();
  40. }
  41. return Instance._MES;
  42. }
  43. }
  44. public static string MechineCode
  45. {
  46. get
  47. {
  48. if (Instance == null)
  49. {
  50. Instance = new AppSettingConfig();
  51. }
  52. return Instance._MechineCode;
  53. }
  54. }
  55. private static AppSettingConfig Instance;
  56. private string _FirmwareRoot, _Language, _MES , _MechineCode;
  57. private static string settingFileName = "config.ini";
  58. public AppSettingConfig()
  59. {
  60. if(!File.Exists(settingFileName))
  61. {
  62. LoadDefaultSetting();
  63. }
  64. else
  65. {
  66. LoadSettingFromDefaultFile();
  67. }
  68. }
  69. private void LoadSettingFromDefaultFile()
  70. {
  71. try
  72. {
  73. LoadDefaultSetting();
  74. var configStr = File.ReadAllText(settingFileName);
  75. var config = Newtonsoft.Json.JsonConvert.DeserializeObject<Model.AppSettingConfig>(configStr);
  76. _FirmwareRoot = config.FirmwareRoot;
  77. _Language = config.Language;
  78. _MES = config.MES;
  79. _MechineCode = config.MechineCode;
  80. }
  81. catch
  82. {
  83. }
  84. }
  85. private void LoadDefaultSetting()
  86. {
  87. _FirmwareRoot = "./Firmware";
  88. _Language = "zh-chs";
  89. _MES = "shinewave";
  90. }
  91. }
  92. }