Ability to add comments into config

This commit is contained in:
Victor 2013-10-20 13:24:19 +03:00
parent 76a1f13624
commit 79681415ee

View File

@ -60,7 +60,7 @@ namespace BatteryWidget {
try { try {
using (var reader = new StreamReader(PATH + Path.DirectorySeparatorChar + CONFIG)) { using (var reader = new StreamReader(PATH + Path.DirectorySeparatorChar + CONFIG)) {
// Title // Title
title = reader.ReadLine().Trim(); title = readLine(reader).Trim();
// Size // Size
windowSize = readSize(reader); windowSize = readSize(reader);
// Colors // Colors
@ -69,6 +69,7 @@ namespace BatteryWidget {
powerStateColor = readColor(reader); powerStateColor = readColor(reader);
} }
} catch (Exception) { } catch (Exception) {
// Default configuration
title = "Android Battery Widget"; title = "Android Battery Widget";
windowSize = new Size(120, 69); windowSize = new Size(120, 69);
warningStateColor = Color.Red; warningStateColor = Color.Red;
@ -92,7 +93,7 @@ namespace BatteryWidget {
/// Read color from stream. /// Read color from stream.
/// </summary> /// </summary>
private static Color readColor(StreamReader reader) { private static Color readColor(StreamReader reader) {
string line = reader.ReadLine(); string line = readLine(reader);
return ColorTranslator.FromHtml(line); return ColorTranslator.FromHtml(line);
} }
@ -100,11 +101,22 @@ namespace BatteryWidget {
/// Read size value from stream. /// Read size value from stream.
/// </summary> /// </summary>
private static Size readSize(StreamReader reader) { private static Size readSize(StreamReader reader) {
string line = reader.ReadLine(); string line = readLine(reader);
string[] arr = line.Split(';'); string[] arr = line.Split(';');
int width = Convert.ToInt16(arr[0]); int width = Convert.ToInt16(arr[0]);
int height = Convert.ToInt16(arr[1]); int height = Convert.ToInt16(arr[1]);
return new Size(width, height); return new Size(width, height);
} }
/// <summary>
/// Read line missing comments.
/// </summary>
private static string readLine(StreamReader reader) {
string line;
do {
line = reader.ReadLine();
} while ( (line.Trim().Length == 0) || (line.StartsWith("//")) );
return line;
}
} }
} }