ConfigIni.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. namespace MeterVision.Config
  10. {
  11. //INI配置文件
  12. public class ConfigIni
  13. {
  14. private static readonly string IniFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.ini");
  15. [DllImport("kernel32")]
  16. private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
  17. [DllImport("kernel32")]
  18. private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
  19. private static readonly int iCapacity = 255; //最大长度
  20. public static string ReadIniValue(string Section, string def, string Key)
  21. {
  22. try
  23. {
  24. if (File.Exists(IniFilePath))
  25. {
  26. StringBuilder strValue = new StringBuilder(iCapacity);
  27. int i = GetPrivateProfileString(Section, Key, def, strValue, iCapacity, IniFilePath);
  28. return strValue.ToString().Trim();
  29. }
  30. else
  31. {
  32. return def;
  33. }
  34. }
  35. catch (Exception ex)
  36. {
  37. //LogTool.Error(string.Format("{0}--{1}", Section, Key), ex);
  38. MessageBox.Show($"读配置文件:{ex.Message}");
  39. return def;
  40. }
  41. }
  42. public static string WriteIniValue(string Section, string Key, string Value)
  43. {
  44. return WritePrivateProfileString(Section, Key, Value, IniFilePath).ToString();
  45. }
  46. }
  47. //[file_path]
  48. // onnx=N_I_RP_RGB_ns_4PB_5d0_94c_241221_2GPU_11_t1.25_0.70_v1.35_0.56.onnx
  49. // ai_dll = freeAI.dll
  50. //output=d:\MeterVision_output\
  51. //[page_size]
  52. // single=10
  53. //stand=10
  54. //stand_detail=20
  55. //patch=10
  56. //patch_detail=20
  57. //[window_size]
  58. // dialog_image=
  59. //dialog_stand=
  60. //--------------------------------------------
  61. }