Restricted ITE detection to port 0x2E.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2010
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
43 using OpenHardwareMonitor.Hardware;
45 namespace OpenHardwareMonitor {
46 public class PersistentSettings : ISettings {
48 private IDictionary<string, string> settings =
49 new Dictionary<string, string>();
51 public void Load(string fileName) {
52 XmlDocument doc = new XmlDocument();
58 XmlNodeList list = doc.GetElementsByTagName("appSettings");
59 foreach (XmlNode node in list) {
60 XmlNode parent = node.ParentNode;
61 if (parent != null && parent.Name == "configuration" &&
62 parent.ParentNode is XmlDocument) {
63 foreach (XmlNode child in node.ChildNodes) {
64 if (child.Name == "add") {
65 XmlAttributeCollection attributes = child.Attributes;
66 XmlAttribute keyAttribute = attributes["key"];
67 XmlAttribute valueAttribute = attributes["value"];
68 if (keyAttribute != null && valueAttribute != null &&
69 keyAttribute.Value != null) {
70 settings.Add(keyAttribute.Value, valueAttribute.Value);
78 public void Save(string fileName) {
79 XmlDocument doc = new XmlDocument();
80 doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null));
81 XmlElement configuration = doc.CreateElement("configuration");
82 doc.AppendChild(configuration);
83 XmlElement appSettings = doc.CreateElement("appSettings");
84 configuration.AppendChild(appSettings);
85 foreach (KeyValuePair<string, string> keyValuePair in settings) {
86 XmlElement add = doc.CreateElement("add");
87 add.SetAttribute("key", keyValuePair.Key);
88 add.SetAttribute("value", keyValuePair.Value);
89 appSettings.AppendChild(add);
94 public bool Contains(string name) {
95 return settings.ContainsKey(name);
98 public void SetValue(string name, string value) {
99 settings[name] = value;
102 public string GetValue(string name, string value) {
104 if (settings.TryGetValue(name, out result))
110 public void Remove(string name) {
111 settings.Remove(name);
114 public void SetValue(string name, int value) {
115 settings[name] = value.ToString();
118 public int GetValue(string name, int value) {
120 if (settings.TryGetValue(name, out str)) {
122 if (int.TryParse(str, out parsedValue))
131 public void SetValue(string name, bool value) {
132 settings[name] = value ? "true" : "false";
135 public bool GetValue(string name, bool value) {
137 if (settings.TryGetValue(name, out str)) {
138 return str == "true";
144 public void SetValue(string name, Color color) {
145 settings[name] = color.ToArgb().ToString("X8");
148 public Color GetValue(string name, Color value) {
150 if (settings.TryGetValue(name, out str)) {
152 if (int.TryParse(str,
153 System.Globalization.NumberStyles.HexNumber,
154 System.Globalization.CultureInfo.InvariantCulture, out parsedValue))
155 return Color.FromArgb(parsedValue);