From 79681415ee7fb81437a5a1af3b60e5ab2af382dc Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 20 Oct 2013 13:24:19 +0300 Subject: [PATCH] Ability to add comments into config --- BatteryWidget/Config.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/BatteryWidget/Config.cs b/BatteryWidget/Config.cs index 378f8cb..56c4f29 100644 --- a/BatteryWidget/Config.cs +++ b/BatteryWidget/Config.cs @@ -60,7 +60,7 @@ namespace BatteryWidget { try { using (var reader = new StreamReader(PATH + Path.DirectorySeparatorChar + CONFIG)) { // Title - title = reader.ReadLine().Trim(); + title = readLine(reader).Trim(); // Size windowSize = readSize(reader); // Colors @@ -69,6 +69,7 @@ namespace BatteryWidget { powerStateColor = readColor(reader); } } catch (Exception) { + // Default configuration title = "Android Battery Widget"; windowSize = new Size(120, 69); warningStateColor = Color.Red; @@ -92,7 +93,7 @@ namespace BatteryWidget { /// Read color from stream. /// private static Color readColor(StreamReader reader) { - string line = reader.ReadLine(); + string line = readLine(reader); return ColorTranslator.FromHtml(line); } @@ -100,11 +101,22 @@ namespace BatteryWidget { /// Read size value from stream. /// private static Size readSize(StreamReader reader) { - string line = reader.ReadLine(); + string line = readLine(reader); string[] arr = line.Split(';'); int width = Convert.ToInt16(arr[0]); int height = Convert.ToInt16(arr[1]); return new Size(width, height); } + + /// + /// Read line missing comments. + /// + private static string readLine(StreamReader reader) { + string line; + do { + line = reader.ReadLine(); + } while ( (line.Trim().Length == 0) || (line.StartsWith("//")) ); + return line; + } } }