Ability to add comments into config
This commit is contained in:
parent
76a1f13624
commit
79681415ee
@ -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.
|
||||
/// </summary>
|
||||
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.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user