A fork of Eusth's IPA
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.

90 lines
2.6KB

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