From: Philipp Zabel Date: Thu, 27 May 2010 17:13:38 +0000 (+0200) Subject: Adapt MCE INI parser for RX44 X-Git-Tag: v0.0.4~2 X-Git-Url: https://vcs.maemo.org/git/?p=led-pattern-ed;a=commitdiff_plain;h=1dbfa6f55383b49db8c5838636cbdf2a12ae8a64 Adapt MCE INI parser for RX44 --- diff --git a/src/mce-ini-parse.vala b/src/mce-ini-parse.vala index d7a4438..3198ed5 100644 --- a/src/mce-ini-parse.vala +++ b/src/mce-ini-parse.vala @@ -16,17 +16,42 @@ * along with LED Pattern Editor. If not, see . */ -List mce_ini_parse () { - var list = new List (); +enum DeviceType { + RX44, + RX51 +} + +static const DeviceType device = DeviceType.RX51; + +List mce_ini_parse () { + var list = new List (); var f = FileStream.open ("/etc/mce/mce.ini", "r"); + string pattern_section = null; + + switch (device) { + case DeviceType.RX44: + pattern_section = "[LEDPatternNJoyRX44]"; + break; + case DeviceType.RX51: + pattern_section = "[LEDPatternLystiRX51]"; + break; + } var line = f.read_line (); while (line != null) { - if (line == "[LEDPatternLystiRX51]") { + if (line == pattern_section) { line = f.read_line (); while ((line != null) && (line[0] != '[')) { if (line.has_prefix ("Pattern")) { - var pattern = new LedPatternRX51 (); + LedPattern pattern = null; + switch (device) { + case DeviceType.RX44: + pattern = new LedPatternRX44 (); + break; + case DeviceType.RX51: + pattern = new LedPatternRX51 (); + break; + } pattern.parse (line); list.append (pattern); } @@ -39,18 +64,28 @@ List mce_ini_parse () { return list; } -void mce_ini_store (List list) { +void mce_ini_store (List list) { var f = FileStream.open ("/etc/mce/mce.ini", "r"); var g = FileStream.open ("/tmp/mce.ini", "w"); + string pattern_section = null; + + switch (device) { + case DeviceType.RX44: + pattern_section = "[LEDPatternNJoyRX44]"; + break; + case DeviceType.RX51: + pattern_section = "[LEDPatternLystiRX51]"; + break; + } var line = f.read_line (); while (line != null) { - if (line == "[LEDPatternLystiRX51]") { + if (line == pattern_section) { g.printf ("%s\n", line); line = f.read_line (); while ((line != null) && (line[0] != '[')) { if (line.has_prefix ("Pattern")) { - unowned List node; + unowned List node; for (node = list.first (); node != null; node = node.next) { if (line.has_prefix (node.data.name + "=")) { g.printf ("%s\n", node.data.dump ());