diff --git a/CSharp/Configure.csharp b/CSharp/Configure.csharp
index 7bf397c..0e95ef9 100644
--- a/CSharp/Configure.csharp
+++ b/CSharp/Configure.csharp
@@ -16,20 +16,23 @@ namespace AniNIX.Shared {
/// The Config file
public Configure(String filename) {
StreamReader fileReader = new StreamReader(filename);
- String line = fileReader.ReadLine().Trim();
- while (line != null) {
+ String line;
+ while (true) {
+ line = fileReader.ReadLine();
+ if (line == null) break;
//Ignore comments prefixed with '#'
+ if (line.StartsWith("#")) continue;
if (line.IndexOf('#') > 0) {
- if (line[0] == '#') continue;
lines.Add(line.Split('#')[0].Trim());
} else {
- lines.Add(line);
+ lines.Add(line.Trim());
}
- line = fileReader.ReadLine();
}
fileReader.Close();
fileReader.Dispose();
}
+
+
///
/// Create a new string dictionary from the named section.
///
@@ -53,6 +56,50 @@ namespace AniNIX.Shared {
}
return foundEntries;
}
+ ///
+ /// If a conf section doesn't use key=value syntax, use this to grab the lines instead.
+ ///
+ /// The name of the section header
+ /// New List of read key-value pairs from config section.
+ public List ReadSectionLines(String section) {
+ List foundEntries = new List();
+ String header = String.Format("[ {0} ]",section);
+ int i = 0, j;
+ // Read to find the header
+ for (i = 0; i < lines.Count; i++) {
+ if (lines[i].Equals(header)) {
+ i++;
+ for (j = i; j < lines.Count && lines[j] != null && !String.IsNullOrWhiteSpace(lines[j]); j++) {
+ foundEntries.Add(lines[j]);
+ }
+ break; // Most configuration utilities don't allow multiple same-named sections
+ }
+ }
+ return foundEntries;
+ }
+
+ ///
+ /// Get the headers in a conf file.
+ ///
+ /// The headers from a file
+ public List GetHeaders() {
+ List foundHeaders = new List();
+ int i = 0;
+ for (i = 0; i < lines.Count; i++) {
+ if (lines[i].Length > 5 && lines[i][0] == '[' && lines[i][lines[i].Length-1] == ']') {
+ foundHeaders.Add(lines[i].Substring(2,lines[i].Length-4));
+ }
+ }
+ return foundHeaders;
+ }
+
+ ///
+ /// Get the lines from the file.
+ ///
+ /// The lines from the file
+ public List GetLines() {
+ return this.lines;
+ }
///
/// API for printing the configured section