-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIniEditor3.cs
More file actions
49 lines (43 loc) · 1.48 KB
/
IniEditor3.cs
File metadata and controls
49 lines (43 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using IniParser.Model;
using IniParser;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace FSR3ModSetupUtilityEnhanced
{
internal class IniEditor3
{
public string Path { get; private set; }
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern long WritePrivateProfileString(string section, string key, string value, string filePath);
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern int GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder retVal, int size, string filePath);
public IniEditor3(string path)
{
Path = path;
}
public void ConfigIni3(Dictionary<string, string> keyValuePairs, string? section = null)
{
foreach (var kvp in keyValuePairs)
{
if (section != null)
{
WritePrivateProfileString(section, kvp.Key, kvp.Value, Path);
}
else
{
WritePrivateProfileString(null, kvp.Key, kvp.Value, Path);
}
}
}
public string Read(string section, string key)
{
var retVal = new StringBuilder(255);
GetPrivateProfileString(section, key, "", retVal, 255, Path);
return retVal.ToString();
}
}
}