IniFile.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace PDFMonitor_SVG {
  8. internal class IniFile {
  9. private string filePath;
  10. [DllImport("kernel32", CharSet = CharSet.Unicode)]
  11. private static extern long WritePrivateProfileString(string section, string key, string value, string filePath);
  12. [DllImport("kernel32", CharSet = CharSet.Unicode)]
  13. private static extern int GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder retVal, int size, string filePath);
  14. public IniFile(string filePath) {
  15. this.filePath = filePath;
  16. }
  17. public string Read(string section, string key, string defaultValue = "") {
  18. var retVal = new StringBuilder(255);
  19. GetPrivateProfileString(section, key, defaultValue, retVal, 255, filePath);
  20. return retVal.ToString();
  21. }
  22. public void Write(string section, string key, string value) {
  23. WritePrivateProfileString(section, key, value, filePath);
  24. }
  25. }
  26. }