A fork of Eusth's IPA
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

88 satır
2.6KB

  1. using System.IO;
  2. using System.Runtime.InteropServices;
  3. using System.Text;
  4. namespace IllusionPlugin
  5. {
  6. /// <summary>
  7. /// Create a New INI file to store or load data
  8. /// </summary>
  9. internal class IniFile
  10. {
  11. [DllImport("KERNEL32.DLL", EntryPoint = "GetPrivateProfileStringW",
  12. SetLastError = true,
  13. CharSet = CharSet.Unicode, ExactSpelling = true,
  14. CallingConvention = CallingConvention.StdCall)]
  15. private static extern int GetPrivateProfileString(
  16. string lpSection,
  17. string lpKey,
  18. string lpDefault,
  19. StringBuilder lpReturnString,
  20. int nSize,
  21. string lpFileName);
  22. [DllImport("KERNEL32.DLL", EntryPoint = "WritePrivateProfileStringW",
  23. SetLastError = true,
  24. CharSet = CharSet.Unicode, ExactSpelling = true,
  25. CallingConvention = CallingConvention.StdCall)]
  26. private static extern int WritePrivateProfileString(
  27. string lpSection,
  28. string lpKey,
  29. string lpValue,
  30. string lpFileName);
  31. private string _path = "";
  32. public string Path
  33. {
  34. get
  35. {
  36. return _path;
  37. }
  38. set
  39. {
  40. if (!File.Exists(value))
  41. File.WriteAllText(value, "", Encoding.Unicode);
  42. _path = value;
  43. }
  44. }
  45. /// <summary>
  46. /// INIFile Constructor.
  47. /// </summary>
  48. /// <PARAM name="INIPath"></PARAM>
  49. public IniFile(string INIPath)
  50. {
  51. this.Path = INIPath;
  52. }
  53. /// <summary>
  54. /// Write Data to the INI File
  55. /// </summary>
  56. /// <PARAM name="Section"></PARAM>
  57. /// Section name
  58. /// <PARAM name="Key"></PARAM>
  59. /// Key Name
  60. /// <PARAM name="Value"></PARAM>
  61. /// Value Name
  62. public void IniWriteValue(string Section, string Key, string Value)
  63. {
  64. WritePrivateProfileString(Section, Key, Value, this.Path);
  65. }
  66. /// <summary>
  67. /// Read Data Value From the Ini File
  68. /// </summary>
  69. /// <PARAM name="Section"></PARAM>
  70. /// <PARAM name="Key"></PARAM>
  71. /// <PARAM name="Path"></PARAM>
  72. /// <returns></returns>
  73. public string IniReadValue(string Section, string Key)
  74. {
  75. const int MAX_CHARS = 1023;
  76. StringBuilder result = new StringBuilder(MAX_CHARS);
  77. GetPrivateProfileString(Section, Key, "", result, MAX_CHARS, this.Path);
  78. return result.ToString();
  79. }
  80. }
  81. }