using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- * 版权所有 (c) 2024 WenJY 保留所有权利。 * CLR版本:4.0.30319.42000 * 机器名称:T14-GEN3-7895 * 命名空间:SlnMesnac.RfidUpload.Common * 唯一标识:b9e73772-16f9-40b7-92cc-4a95c4c34e6d * * 创建者:WenJY * 电子邮箱: * 创建时间:2024-05-28 14:10:36 * 版本:V1.0.0 * 描述: * *-------------------------------------------------------------------- * 修改人: * 时间: * 修改说明: * * 版本:V1.0.0 *--------------------------------------------------------------------*/ #endregion << 版 本 注 释 >> namespace SlnMesnac.RfidUpload.Common { /// /// 配置操作类 /// public class INIFile { public string path; public INIFile(string INIPath) { path = INIPath; } [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [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); /// /// 写INI文件 /// /// /// /// public void IniWriteValue(string Section, string Key, string Value) { WritePrivateProfileString(Section, Key, Value, this.path); } /// /// 读取INI文件 /// /// /// /// public string IniReadValue(string Section, string Key) { StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path); return temp.ToString(); } public byte[] IniReadValues(string section, string key) { byte[] temp = new byte[255]; int i = GetPrivateProfileString(section, key, "", temp, 255, this.path); return temp; } /// /// 删除ini文件下所有段落 /// public void ClearAllSection() { IniWriteValue(null, null, null); } /// /// 删除ini文件下personal段落下的所有键 /// /// public void ClearSection(string Section) { IniWriteValue(Section, null, null); } } }