using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace FunGame.Core.Api.Util
{
public class INIHelper
{
/*
* 声明API函数
*/
public string INIPath;
[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
///
/// 构造函数
///
/// ini文件路径
public INIHelper(string INIPath = "./fungame.milimoe")
{
this.INIPath = INIPath;
}
///
/// 写入ini文件
///
/// Section
/// 键
/// 值
public void WriteINI(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, INIPath);
}
///
/// 读取ini文件
///
/// Section
/// 键
/// 返回的值
public string ReadINI(string Section, string Key)
{
StringBuilder temp = new StringBuilder(256);
int i = GetPrivateProfileString(Section, Key, "", temp, 256, INIPath);
return temp.ToString();
}
///
/// 查询ini文件是否存在
///
/// 是否存在
public bool ExistINIFile()
{
return File.Exists(INIPath);
}
}
}