Fetch the repository succeeded.
This action will force synchronization from CortexMi/HIDtool, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace HIDTOOL
{
class IniFileOperate
{
/*
* 文件结构:
[Section1]
key 1 = val1
key 2 = val2
……
[Section2]
key 1 = val1
key 2 = val2
……
*/
/// <summary>
/// 写入INI文件
/// </summary>
/// <param name="section">节点名称[如[TypeName]]</param>
/// <param name="key">键</param>
/// <param name="val">值</param>
/// <param name="filepath">文件路径</param>
/// <returns></returns>
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filepath);
/// <summary>
/// 读取INI文件
/// </summary>
/// <param name="section">节点名称</param>
/// <param name="key">键</param>
/// <param name="def">值</param>
/// <param name="retval">stringbulider对象</param>
/// <param name="size">字节大小</param>
/// <param name="filePath">文件路径</param>
/// <returns></returns>
[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);
//========================================================================================================================================================
string iniFilePath = "";
public IniFileOperate(string iniFileName) //构造方法
{
this.iniFilePath = Application.StartupPath + @"\" + iniFileName;
}
/// <summary>
/// 验证文件是否存在
/// </summary>
/// <returns>布尔值</returns>
public bool ExistINIFile()
{
return File.Exists(this.iniFilePath);
}
/// <summary>
/// 写入
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <param name="iValue"></param>
public void Write(string section, string key, string iValue)
{
WritePrivateProfileString(section, key, iValue, this.iniFilePath);
}
/// <summary>
/// 读取INI文件中的内容方法
/// </summary>
/// <param name="Section">键</param>
/// <param name="key">值</param>
/// <returns></returns>
public string Read(string Section, string key)
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(Section, key, "", temp, 1024, this.iniFilePath);
return temp.ToString();
}
public byte[] ReadBytes(string section, string key)
{
byte[] temp = new byte[255];
int i = GetPrivateProfileString(section, key, "", temp, 255, this.iniFilePath);
return temp;
}
public void DelIniFile()
{
File.Delete(this.iniFilePath);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。