更新整理
This commit is contained in:
71
ShrlAlgoToolkit.Core/Assists/IniAssist.cs
Normal file
71
ShrlAlgoToolkit.Core/Assists/IniAssist.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace ShrlAlgoToolkit.Core.Assists;
|
||||
|
||||
public class IniAssist
|
||||
{
|
||||
public IniAssist(string iniPath)
|
||||
{
|
||||
path = iniPath;
|
||||
}
|
||||
|
||||
public string path;
|
||||
|
||||
/// <summary>
|
||||
/// 删除ini文件下所有段落
|
||||
/// </summary>
|
||||
public void ClearAllSection()
|
||||
{
|
||||
IniWriteValue(null, null, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除ini文件下personal段落下的所有键
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
public void ClearSection(string section)
|
||||
{
|
||||
IniWriteValue(section, null, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取INI文件
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public string IniReadValue(string section, string key)
|
||||
{
|
||||
var temp = new StringBuilder(255);
|
||||
GetPrivateProfileString(section, key, "", temp, 255, path);
|
||||
return temp.ToString();
|
||||
}
|
||||
|
||||
public byte[] IniReadValues(string section, string key)
|
||||
{
|
||||
var temp = new byte[255];
|
||||
var i = GetPrivateProfileString(section, key, "", temp, 255, path);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写INI文件
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public void IniWriteValue(string section, string key, string value)
|
||||
{
|
||||
WritePrivateProfileString(section, key, value, path);
|
||||
}
|
||||
|
||||
[DllImport("kernel32")]
|
||||
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
|
||||
|
||||
[DllImport("kernel32")]
|
||||
private static extern int GetPrivateProfileString(string section, string key, string defVal, byte[] retVal, int size, string filePath);
|
||||
|
||||
[DllImport("kernel32")]
|
||||
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
|
||||
}
|
||||
Reference in New Issue
Block a user