private static LanguageDescriptor getDescriptorFor(string filePath) { var langDesc = new LanguageDescriptor(Path.GetFileNameWithoutExtension(filePath)); var reader = new StreamReader(filePath); var line = reader.ReadLine(); if (line != null) line = line.Trim(); while (line != null && line.StartsWith("#")) { if (line.StartsWith("#Name") && line.Contains("=")) langDesc.Name = line.Substring(line.IndexOf('=')+1).Trim(); if (line.StartsWith("#Author") && line.Contains("=")) langDesc.Author = line.Substring(line.IndexOf('=') + 1).Trim(); if (line.StartsWith("#Version") && line.Contains("=")) langDesc.Version = line.Substring(line.IndexOf('=') + 1).Trim(); line = reader.ReadLine(); if (line != null) line = line.Trim(); } reader.Close(); return langDesc; }
public static void Load(string culture) { var filePath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath) ?? string.Empty, culture + ".ini"); if (!File.Exists(filePath)) return; var reader = new StreamReader(filePath); _current = getDescriptorFor(filePath); if (_contents == null) _contents = new Dictionary<string, Dictionary<string, string>>(); else _contents.Clear(); if (_strings == null) _strings = new Dictionary<string, string>(); else _strings.Clear(); Dictionary<string, string> currentSection = null; string line; //= reader.ReadLine(); while ((line = reader.ReadLine()) != null) { line = line.Trim(); if (line == "") continue; if (line[0] == ';') continue; if (line[0] == '@' && line.Contains("=")) { var eqPos = line.IndexOf('='); _strings[line.Substring(1, eqPos - 1).Trim()] = line.Substring(eqPos + 1).Trim().Replace(@"\n", "\n"); } else if (line.StartsWith("[") && line.EndsWith("]") && line.Length > 2) { var currentSectionName = line.Substring(1, line.Length - 2); if (_contents.ContainsKey(currentSectionName)) { currentSection = _contents[currentSectionName]; } else { currentSection = new Dictionary<string, string>(); _contents[currentSectionName] = currentSection; } } else if (currentSection != null && line.Contains("=") && line.Contains(".")) { var dotPos = line.IndexOf('.'); var eqPos = line.IndexOf('='); if (dotPos < eqPos) //must have a structure of {A.B=C} currentSection[line.Substring(0, eqPos).Trim()] = line.Substring(eqPos + 1).Trim().Replace(@"\n", "\n"); } //line = reader.ReadLine(); } reader.Close(); }