Пример #1
0
        public static IniFile Load(string directory, string fileName)
        {
            IniFile ini      = new IniFile(fileName);
            string  fullPath = directory + @"\" + fileName + ".ini";

            try
            {
                bool fE = File.Exists(fullPath);
                if (!fE)
                {
                    return(ini);
                }

                string[] str = File.ReadAllLines(fullPath);
                ini._fileName = fileName;
                ini._filePath = directory;

                if (str == null || str.Length == 0)
                {
                    return(ini);
                }

                string currentSection = null;
                for (int i = 0; i < str.Length; i++)
                {
                    string tSect = ParseSection(str[i]);
                    if (tSect != null)
                    {
                        currentSection = tSect; continue;
                    }

                    string k = null, v = null;
                    bool   parse = ParseKeyValue(str[i], ref k, ref v);
                    if (parse && !string.IsNullOrEmpty(currentSection))
                    {
                        ini.Write(currentSection, k, v);
                    }
                }
                return(ini);
            }
            catch (Exception) { return(ini); }
        }