public void Refresh() { lock (m_Lock) { StreamReader sr = null; try { m_Sections.Clear(); try { sr = new StreamReader(FileName); } catch (FileNotFoundException) { return; } Dictionary <string, string> CurrentSection = null; string s; string SectionName; string Key = null; string Value = null; while ((s = sr.ReadLine()) != null) { s = s.Trim(); SectionName = ParseSectionName(s); if (SectionName != null) { if (m_Sections.ContainsKey(SectionName)) { CurrentSection = null; } else { CurrentSection = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); m_Sections.Add(SectionName, CurrentSection); } } else if (CurrentSection != null) { if (ParseKeyValuePair(s, ref Key, ref Value)) { if (!CurrentSection.ContainsKey(Key)) { CurrentSection.Add(Key, Value); } } } } } finally { if (sr != null) { sr.Close(); } sr = null; } } }
private void Refresh() { lock (_lock) { StringReader sr = null; try { _sections.Clear(); _modified.Clear(); sr = new StringReader(IniString); Dictionary <string, string> CurrentSection = null; string s; string SectionName; string Key = null; string Value = null; while ((s = sr.ReadLine()) != null) { s = s.Trim(); SectionName = ParseSectionName(s); if (SectionName != null) { if (_sections.ContainsKey(SectionName)) { CurrentSection = null; } else { CurrentSection = new Dictionary <string, string>(); _sections.Add(SectionName, CurrentSection); } } else if (CurrentSection != null) { if (ParseKeyValuePair(s, ref Key, ref Value)) { if (!CurrentSection.ContainsKey(Key)) { CurrentSection.Add(Key, Value); } } } } } finally { if (sr != null) { sr.Close(); } sr = null; } } }
// *** Read file contents into local cache *** private void Refresh() { lock (m_Lock) { StringReader sr = null; try { // *** Clear local cache *** m_Sections.Clear(); m_Modified.Clear(); // *** String Reader *** sr = new StringReader(m_iniString); // *** Read up the file content *** Dictionary <string, string> CurrentSection = null; string s; string SectionName; string Key = null; string Value = null; while ((s = sr.ReadLine()) != null) { s = s.Trim(); // *** Check for section names *** SectionName = ParseSectionName(s); if (SectionName != null) { // *** Only first occurrence of a section is loaded *** if (m_Sections.ContainsKey(SectionName)) { CurrentSection = null; } else { CurrentSection = new Dictionary <string, string>(); m_Sections.Add(SectionName, CurrentSection); } } else if (CurrentSection != null) { // *** Check for key+value pair *** if (ParseKeyValuePair(s, ref Key, ref Value)) { // *** Only first occurrence of a key is loaded *** if (!CurrentSection.ContainsKey(Key)) { CurrentSection.Add(Key, Value); } } } } } finally { // *** Cleanup: close file *** if (sr != null) { sr.Close(); } sr = null; } } }
// *** Read file contents into local cache *** internal void Refresh() { lock (m_Lock) { StreamReader sr = null; try { // *** Clear local cache *** m_Sections.Clear(); // *** Open the INI file *** try { sr = new StreamReader(m_FileName); } catch (FileNotFoundException) { return; } // *** Read up the file content *** Dictionary <string, string> CurrentSection = null; string s; while ((s = sr.ReadLine()) != null) { s = s.Trim(); // *** Check for section names *** if (s.StartsWith("[") && s.EndsWith("]")) { if (s.Length > 2) { string SectionName = s.Substring(1, s.Length - 2); // *** Only first occurrence of a section is loaded *** if (m_Sections.ContainsKey(SectionName)) { CurrentSection = null; } else { CurrentSection = new Dictionary <string, string>(); m_Sections.Add(SectionName, CurrentSection); } } } else if (CurrentSection != null) { // *** Check for key+value pair *** int i; if ((i = s.IndexOf('=')) > 0) { int j = s.Length - i - 1; string Key = s.Substring(0, i).Trim(); if (Key.Length > 0) { // *** Only first occurrence of a key is loaded *** if (!CurrentSection.ContainsKey(Key)) { string Value = (j > 0) ? (s.Substring(i + 1, j).Trim()) : (""); CurrentSection.Add(Key, Value); } } } } } } finally { // *** Cleanup: close file *** if (sr != null) { sr.Close(); } sr = null; } } }
// *** Read file contents into local cache *** internal void Refresh() { lock (m_Lock) { FileStream fs = null; StreamReader sr = null; try { // *** Clear local cache *** m_Sections.Clear(); // *** Open the INI file *** if (File.Exists(m_FileName)) { fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); sr = new StreamReader(fs); } else { return; } // *** Read up the file content *** Dictionary <string, string> CurrentSection = null; string s; while ((s = sr.ReadLine()) != null) { s = s.Trim(); // *** Check for section names *** if (s.StartsWith("[") && s.EndsWith("]")) { if (s.Length > 2) { string SectionName = s.Substring(1, s.Length - 2); // *** Only first occurrence of a section is loaded *** if (m_Sections.ContainsKey(SectionName)) { CurrentSection = null; } else { CurrentSection = new Dictionary <string, string>(); m_Sections.Add(SectionName, CurrentSection); } } } else if (CurrentSection != null) { // *** Check for key+value pair *** int i; if (s.StartsWith("#")) { // It's a comment // *** Only first occurrence of a key is loaded *** if (!CurrentSection.ContainsKey(s)) { CurrentSection.Add(s, ""); } } else if ((i = s.IndexOf('=')) > 0) { // It's a value int j = s.Length - i - 1; string Key = s.Substring(0, i).Trim(); if (Key.Length > 0) { // *** Only first occurrence of a key is loaded *** if (!CurrentSection.ContainsKey(Key)) { string Value = (j > 0) ? (s.Substring(i + 1, j).Trim()) : (""); CurrentSection.Add(Key, Value); } } } } } } finally { // *** Cleanup: close file *** if (sr != null) { sr.Close(); } if (fs != null) { fs.Close(); } sr = null; fs = null; } } }
// *** Read file contents into local cache *** internal void Refresh() { lock (_lock) { StreamReader sr = null; try { // *** Clear local cache *** _sections.Clear(); _modified.Clear(); // *** Open the INI file *** try { sr = new StreamReader(_fileName); } catch (FileNotFoundException) { return; } // *** Read up the file content *** Dictionary <string, string> CurrentSection = null; string s; string SectionName; string Key = null; string Value = null; while ((s = sr.ReadLine()) != null) { s = s.Trim(); // *** Check for section names *** SectionName = ParseSectionName(s); if (SectionName != null) { // *** Only first occurrence of a section is loaded *** if (_sections.ContainsKey(SectionName)) { CurrentSection = null; } else { CurrentSection = new Dictionary <string, string>(); _sections.Add(SectionName, CurrentSection); } } else if (CurrentSection != null) { // *** Check for key+value pair *** if (ParseKeyValuePair(s, ref Key, ref Value)) { // *** Only first occurrence of a key is loaded *** if (!CurrentSection.ContainsKey(Key)) { CurrentSection.Add(Key, Value); } } } } } finally { // *** Cleanup: close file *** if (sr != null) { sr.Close(); } sr = null; } } }