<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      ini配置文件讀取類

      ini配置文件讀取類
      代碼
        1 using System;
        2  using System.Collections.Generic;
        3 using System.Text;
        4 using System.Runtime.InteropServices;
        5 using System.IO;
        6 
        7 namespace DABAOKU
        8 {
        9     /// <summary>
       10     /// 讀寫ini配置文件類
       11     /// </summary>
       12     class IniFile
       13     {
       14         #region 成員變量
       15         public string filePath = "";    //文件路徑
       16         static private uint MaxBufferSize = 32767;//緩存大小
       17         #endregion
       18      
       19         #region 導(dǎo)入API
       20         [DllImport("kernel32", CharSet = CharSet.Auto)]
       21         private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
       22         [DllImport("kernel32", CharSet = CharSet.Auto)]
       23         private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
       24         [DllImport("kernel32", CharSet = CharSet.Auto)]
       25         private static extern int GetPrivateProfileString(string section, string key, string def, IntPtr retVal, int size, string filePath);
       26         [DllImport("kernel32", CharSet = CharSet.Auto)]
       27         private static extern int GetPrivateProfileInt(string section, string key, int def, string filePath);
       28         [DllImport("kernel32", CharSet = CharSet.Auto)]
       29         private static extern int GetPrivateProfileSection(string section, IntPtr lpReturnedString, uint nSize, string filePath);
       30         [DllImport("kernel32", CharSet = CharSet.Auto)]
       31         private static extern int GetPrivateProfileSectionNames(IntPtr lpszReturnBuffer, uint nSize, string filepath);
       32         #endregion
       33        
       34         #region 構(gòu)造函數(shù)
       35         
       36         public IniFile(string filename)
       37         {
       38             filePath = System.IO.Path.GetFullPath(filename);
       39         }
       40         #endregion
       41 
       42         #region 讀取數(shù)據(jù)
       43 
       44         public string GetString(string Section, string Key)
       45         {
       46             StringBuilder temp = new StringBuilder(255);
       47             int i = GetPrivateProfileString(Section, Key, "", temp, 255this.filePath);
       48             return temp.ToString();
       49         }
       50 
       51         public int GetInt(string Section, string Key)
       52         {
       53             return GetPrivateProfileInt(Section, Key, 0this.filePath);
       54         }
       55 
       56         public List<KeyValuePair<stringstring>> GetValueSetList(string Section)  //讀取一段內(nèi)的所有數(shù)據(jù)
       57         {
       58             List<KeyValuePair<stringstring>> retval;
       59             string[] keyValuePairs;
       60             string key, value;
       61             int equalSignPos;
       62             //申請空間
       63             IntPtr ptr = Marshal.AllocCoTaskMem((int)IniFile.MaxBufferSize);
       64 
       65             try
       66             {
       67                 int len = GetPrivateProfileSection(Section, ptr, MaxBufferSize, filePath);
       68                 keyValuePairs = ConvertNullSeperatedStringToStringArray(ptr, len);
       69             }
       70             finally
       71             {
       72                 Marshal.FreeCoTaskMem(ptr);
       73             }
       74             //輸出結(jié)果
       75             retval = new List<KeyValuePair<stringstring>>(keyValuePairs.Length);
       76             for (int i = 0; i < keyValuePairs.Length; ++i)
       77             {
       78                 equalSignPos = keyValuePairs[i].IndexOf('=');
       79                 key = keyValuePairs[i].Substring(0, equalSignPos);
       80                 value = keyValuePairs[i].Substring(equalSignPos + 1, keyValuePairs[i].Length - equalSignPos - 1);
       81                 retval.Add(new KeyValuePair<stringstring>(key, value));
       82             }
       83             return retval;
       84         }
       85         public string[] GetSectionNames()   //獲得所有段名
       86         {
       87             string[] retval;
       88             int len;
       89             IntPtr ptr = Marshal.AllocCoTaskMem((int)IniFile.MaxBufferSize);
       90             try
       91             {
       92                 len = GetPrivateProfileSectionNames(ptr, IniFile.MaxBufferSize, filePath);
       93                 retval = ConvertNullSeperatedStringToStringArray(ptr, len);
       94             }
       95             finally
       96             {
       97                 Marshal.FreeCoTaskMem(ptr);
       98             }
       99             return retval;
      100         }
      101         public string[] GetKeyNames(string Section) //獲得一段內(nèi)所有關(guān)鍵碼
      102         {
      103             int len;
      104             string[] retval;
      105             IntPtr ptr = Marshal.AllocCoTaskMem((int)IniFile.MaxBufferSize);
      106             try
      107             {
      108                 len = GetPrivateProfileString(Section, nullnull, ptr, (int)IniFile.MaxBufferSize, filePath);
      109                 retval = ConvertNullSeperatedStringToStringArray(ptr, len);
      110             }
      111             finally
      112             {
      113                 Marshal.FreeCoTaskMem(ptr);
      114             }
      115             return retval;
      116         }
      117 
      118         private static string[] ConvertNullSeperatedStringToStringArray(IntPtr ptr, int valLength) //轉(zhuǎn)換字符串指針空間為字符串?dāng)?shù)組
      119         {
      120             string[] retval;
      121             if (valLength == 0)
      122             {
      123                 retval = new string[0];
      124             }
      125             else
      126             {
      127                 string buff = Marshal.PtrToStringAuto(ptr, valLength - 1);
      128                 retval = buff.Split('\0');
      129             }
      130             return retval;
      131         }
      132         #endregion
      133 
      134         #region 寫數(shù)據(jù)
      135 
      136         public void SetValue(string Section, string Key, string Value)
      137         {
      138             WritePrivateProfileString(Section, Key, Value, this.filePath);
      139         }
      140         public void SetValue(string Section, string Key, int Value)
      141         {
      142             WritePrivateProfileString(Section, Key, Value.ToString(), this.filePath);
      143         }
      144         public void SetValue(string Section, string Key, float Value)
      145         {
      146             WritePrivateProfileString(Section, Key, Value.ToString(), this.filePath);
      147         }
      148         public void SetValue(string Section, string Key, double Value)
      149         {
      150             WritePrivateProfileString(Section, Key, Value.ToString(), this.filePath);
      151         }
      152 
      153         #endregion
      154       
      155         #region 刪除
      156         public void DeleteKey(string Section, string Key)
      157         {
      158             SetValue(Section, Key, null);
      159         }
      160         public void DeleteKey(string Section)
      161         {
      162             SetValue(Section, nullnull);
      163         }
      164         #endregion
      165 
      166         #region 補(bǔ)充
      167         static public void FormatIni(string filePath)
      168         {
      169             StreamReader sr = new StreamReader(filePath);
      170             StreamWriter sw = new StreamWriter(filePath+".gc1");
      171             string s = "";
      172             while ((s = sr.ReadLine()) != null)
      173             {
      174                 if (s != "" && s.IndexOf("["== -1 && s.IndexOf("="== -1)
      175                     s += "=";
      176                 sw.WriteLine(s);
      177             }
      178             sr.Close();
      179             sw.Close();
      180             try
      181             {
      182                 File.Move(filePath, filePath + ".gc");
      183             }
      184             catch(System.Exception ex){}
      185             try
      186             {
      187                 File.Move(filePath+".gc1", filePath);
      188             }
      189             catch (System.Exception ex){}
      190             try
      191             {
      192                 File.Delete(filePath+".gc1");
      193             }
      194             catch(System.Exception ex){}
      195         }
      196 #endregion
      197     }
      198 }

       

      posted on 2010-02-21 22:19  大寶pku  閱讀(510)  評論(0)    收藏  舉報(bào)

      導(dǎo)航

      主站蜘蛛池模板: 男女xx00上下抽搐动态图| 蜜桃视频无码区在线观看| 三人成全免费观看电视剧高清| 亚洲精品码中文在线观看| 成年午夜性影院| 日韩av天堂综合网久久| 久久精品国产清自在天天线| 亚洲精品人妻中文字幕| 美女胸18下看禁止免费视频| 国产综合色精品一区二区三区| 久久久无码精品亚洲日韩蜜桃 | 精品一区二区三区无码视频| 日韩精品一区二区亚洲专区| 色偷偷www.8888在线观看| 美女爽到高潮嗷嗷嗷叫免费网站| 国产亚洲精品成人av久| 国产999久久高清免费观看| 亚洲欧美激情在线一区| 国产精品人妻一码二码尿失禁| 国产成人无码综合亚洲日韩| 中文字幕人妻中文AV不卡专区| 亚洲欧美日韩国产手机在线| 日本中文字幕在线播放| 精品免费看国产一区二区| 制服 丝袜 亚洲 中文 综合| 国产精品成人av电影不卡| 久久综合久中文字幕青草| 日韩精品亚洲专在线电影| 国产黄色一区二区三区四区| 婷婷伊人久久| 午夜精品福利亚洲国产| 亚洲精品乱码久久观看网| 精品久久久无码中文字幕| 97精品久久久大香线焦| 精品人妻免费看一区二区三区| 亚洲色成人网站www永久下载 | 青青草无码免费一二三区| 少妇人妻系列无码专区视频| 日本道不卡一二三区视频| 无码专区 人妻系列 在线| 欧美XXXX黑人又粗又长|