public static bool ParseConfigFile(string filePath, FileUtils.ConfigFileEntryParseCallback callback, object userData) { if (callback == null) { Debug.LogWarning("FileUtils.ParseConfigFile() - no callback given"); return(false); } if (!File.Exists(filePath)) { Debug.LogWarning(string.Format("FileUtils.ParseConfigFile() - file {0} does not exist", filePath)); return(false); } int num = 1; using (StreamReader streamReader = File.OpenText(filePath)) { string baseKey = string.Empty; while (streamReader.Peek() != -1) { string text = streamReader.ReadLine().Trim(); if (text.Length >= 1) { if (text.ToCharArray()[0] != ';') { if (text.ToCharArray()[0] == '[') { if (text.ToCharArray()[(text.Length - 1)] != ']') { Debug.LogWarning(string.Format("FileUtils.ParseConfigFile() - bad key name \"{0}\" on line {1} in file {2}", text, num, filePath)); } else { baseKey = text.Substring(1, text.Length - 2); } } else { if (!text.Contains("=")) { Debug.LogWarning(string.Format("FileUtils.ParseConfigFile() - bad value pair \"{0}\" on line {1} in file {2}", text, num, filePath)); } else { string[] array = text.Split(new char[] { '=' }); string subKey = array[0].Trim(); string text2 = array[1].Trim(); if (text2.ToCharArray()[0] == '"' && text2.ToCharArray()[(text2.Length - 1)] == '"') { text2 = text2.Substring(1, text2.Length - 2); } callback(baseKey, subKey, text2, userData); } } } } } } return(true); }
//---------------------------------------------------------------- public static bool ParseConfigFile(string filePath, FileUtils.ConfigFileEntryParseCallback callback) { return(FileUtils.ParseConfigFile(filePath, callback, null)); }