/// <summary> /// Create a new instance of <b>IniFile</b>. /// </summary> /// <param name="fileName">Path to the inifile to read.</param> public IniFile(string fileName) { if (!System.IO.File.Exists(fileName)) throw new System.IO.FileNotFoundException("File " + fileName + " Not found"); byte[] buffer = new byte[32767]; int i = 0; string[] sTmp, kTmp; i = GetPrivateProfileString(null, null, null, buffer, 32767, fileName); if (i == 0) { sections = new Section[0]; return; } sTmp = System.Text.Encoding.GetEncoding(1252).GetString(buffer, 0, i).TrimEnd((char)0).Split((char)0); sections = new Section[sTmp.Length]; for( int j = 0; j< sTmp.Length ; j++) { i = GetPrivateProfileString(sTmp[j], null, null, buffer, 32767, fileName); kTmp = System.Text.Encoding.GetEncoding(1252).GetString(buffer, 0, i).TrimEnd((char)0).Split((char)0); Key[] keys = new Key[kTmp.Length]; for( int k =0; k< kTmp.Length ; k++) { i = GetPrivateProfileString(sTmp[j], kTmp[k], null, buffer, 32767, fileName); keys[k] = new Key( kTmp[k] , System.Text.Encoding.GetEncoding(1252).GetString(buffer, 0, i).TrimEnd((char)0)); } sections[j] = new Section(sTmp[j], keys); } }
/// <summary> /// Create an instance of <b>Section</b> /// </summary> /// <param name="sectionName">name of the section</param> /// <param name="keys">keys that can be used in the section</param> public Section( string sectionName, Key[] keys) { this.keys = keys; name = sectionName; }