终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

61 lines
2.1 KiB

  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. namespace BeDesignerSCADA.Helper
  9. {
  10. /// <summary>
  11. /// 文件帮助类
  12. /// </summary>
  13. public class IniFile
  14. {
  15. #region ini
  16. [DllImport("kernel32")]
  17. internal static extern long WritePrivateProfileString(string section,
  18. string key, string val, string filePath);
  19. [DllImport("kernel32")]
  20. internal static extern int GetPrivateProfileString(string section,
  21. string key, string def, StringBuilder retVal,
  22. int size, string filePath);
  23. [DllImport("kernel32.dll")]
  24. private static extern int GetPrivateProfileSection(string lpAppName, byte[] lpszReturnBuffer, int nSize, string lpFileName);
  25. static string configFile = null;
  26. public static string ConfigFileName
  27. {
  28. get
  29. {
  30. if (string.IsNullOrEmpty(configFile))
  31. {
  32. string configFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisualCodeEditor");
  33. if (!Directory.Exists(configFolder))
  34. Directory.CreateDirectory(configFolder);
  35. configFile = System.IO.Path.Combine(configFolder, ".config");
  36. }
  37. return configFile;
  38. }
  39. }
  40. public static void WriteValue(string Section, string Key, string Value)
  41. {
  42. WritePrivateProfileString(Section, Key, Value, ConfigFileName);
  43. }
  44. public static string ReadValue(string Section, string Key)
  45. {
  46. StringBuilder temp = new StringBuilder(255);
  47. int i = GetPrivateProfileString(Section, Key, "", temp,
  48. 255, ConfigFileName);
  49. if (i <= 0)
  50. return null;
  51. String Value = temp.ToString();
  52. return Value;
  53. }
  54. #endregion ini
  55. }
  56. }