using Lskj.Util; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; namespace Lskj.GarbledCodeProcessing { public static class IniUtil { /// /// ini文件目录 /// static string location = Environment.CurrentDirectory + "\\" + "Setting.ini"; /// /// ini文件获取数据 /// /// /// /// /// /// /// /// [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string defVal, StringBuilder retVal, int size, string filePath); /// /// ini文件写入数据 /// /// /// /// /// /// [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); /// /// 写INI文件 /// /// 段落 /// 键 /// 值 public static void IniWriteValue(string section, string key, string iValue) { WritePrivateProfileString(section, key, iValue, location); } /// /// 读取INI文件 /// /// 段落 /// 键 /// 返回的键值 public static string IniReadValue(string section, string key) { StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(section, key, "", temp, 255, location); return temp.ToString(); } //public static string Read(string iniName, string mainKey, string listKey) //{ // string value = string.Empty; // try // { // 判读INI文件是否存在 // string filePath = Path.Combine(new string[] { PubUtil.AbsolutelyPath + iniName }); // if (File.Exists(filePath)) // { // StringBuilder temp = new StringBuilder(1024); // string fileName = Path.GetFileNameWithoutExtension(filePath); // GetPrivateProfileString(mainKey, listKey, "", temp, 1024, filePath); // return temp + ""; // } // } // catch (Exception) // { // } // return value; //} } }