Hardware/Mainboard/Mainboard.cs
author moel.mich
Sun, 15 May 2011 21:43:40 +0000
changeset 288 a35a89a35532
parent 195 0ee888c485d5
child 298 96263190189a
permissions -rw-r--r--
Improved the selection dragging on the tree view. The selection moves now only when the dragging starts on the tree view. With the old implementation, double-clicking the gadget would change the selection, because the mouse is still pressed when the main window is shown.
     1 /*
     2   
     3   Version: MPL 1.1/GPL 2.0/LGPL 2.1
     4 
     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
     8  
     9   http://www.mozilla.org/MPL/
    10 
    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.
    14 
    15   The Original Code is the Open Hardware Monitor code.
    16 
    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-2011
    20   the Initial Developer. All Rights Reserved.
    21 
    22   Contributor(s):
    23 
    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.
    35  
    36 */
    37 
    38 using System;
    39 using System.Text;
    40 using OpenHardwareMonitor.Hardware.LPC;
    41 
    42 namespace OpenHardwareMonitor.Hardware.Mainboard {
    43   internal class Mainboard : IHardware {
    44     private readonly SMBIOS smbios;
    45     private readonly string name;
    46     private string customName;
    47     private readonly ISettings settings;
    48     private readonly LPCIO lpcio;
    49     private readonly LMSensors lmSensors;
    50     private readonly IHardware[] superIOHardware;
    51 
    52     public Mainboard(ISettings settings) {
    53       this.settings = settings;
    54       this.smbios = new SMBIOS();
    55      
    56       if (smbios.Board != null) {
    57         if (!string.IsNullOrEmpty(smbios.Board.ProductName)) {
    58           if (smbios.Board.Manufacturer == Manufacturer.Unknown)
    59             this.name = smbios.Board.ProductName;
    60           else
    61             this.name = smbios.Board.Manufacturer + " " +
    62               smbios.Board.ProductName;
    63         } else {
    64           this.name = smbios.Board.Manufacturer.ToString();
    65         }
    66       } else {
    67         this.name = Manufacturer.Unknown.ToString();
    68       }
    69 
    70       this.customName = settings.GetValue(
    71         new Identifier(Identifier, "name").ToString(), name);
    72 
    73       ISuperIO[] superIO;
    74       int p = (int)Environment.OSVersion.Platform;
    75       if ((p == 4) || (p == 128)) {
    76         this.lmSensors = new LMSensors();
    77         superIO = lmSensors.SuperIO;
    78       } else {
    79         this.lpcio = new LPCIO();       
    80         superIO = lpcio.SuperIO;
    81       }
    82       
    83       superIOHardware = new IHardware[superIO.Length];
    84       for (int i = 0; i < superIO.Length; i++)
    85         superIOHardware[i] = new SuperIOHardware(this, superIO[i], 
    86           smbios.Board != null ? smbios.Board.Manufacturer : 
    87           Manufacturer.Unknown, smbios.Board != null ? smbios.Board.Model :
    88           Model.Unknown, settings);
    89     }
    90 
    91     public string Name {
    92       get {
    93         return customName;
    94       }
    95       set {
    96         if (!string.IsNullOrEmpty(value))
    97           customName = value;
    98         else
    99           customName = name;
   100         settings.SetValue(new Identifier(Identifier, "name").ToString(),
   101           customName);
   102       }
   103     }
   104 
   105     public Identifier Identifier {
   106       get { return new Identifier("mainboard"); }
   107     }
   108 
   109     public HardwareType HardwareType {
   110       get { return HardwareType.Mainboard; }
   111     }
   112 
   113     public virtual IHardware Parent {
   114       get { return null; }
   115     }
   116 
   117     public string GetReport() {
   118       StringBuilder r = new StringBuilder(); 
   119 
   120       r.AppendLine("Mainboard");
   121       r.AppendLine();           
   122       r.Append(smbios.GetReport());
   123 
   124       if (lpcio != null)
   125         r.Append(lpcio.GetReport());
   126 
   127       return r.ToString();
   128     }
   129 
   130     public void Update() { }
   131 
   132     public void Close() {
   133       if (lmSensors != null)
   134         lmSensors.Close();
   135     }
   136 
   137     public IHardware[] SubHardware {
   138       get { return superIOHardware; }
   139     }
   140 
   141     public ISensor[] Sensors {
   142       get { return new ISensor[0]; }
   143     }
   144 
   145     #pragma warning disable 67
   146     public event SensorEventHandler SensorAdded;
   147     public event SensorEventHandler SensorRemoved;
   148     #pragma warning restore 67
   149 
   150     public void Accept(IVisitor visitor) {
   151       if (visitor == null)
   152         throw new ArgumentNullException("visitor");
   153       visitor.VisitHardware(this);
   154     }
   155 
   156     public void Traverse(IVisitor visitor) {
   157       foreach (IHardware hardware in superIOHardware)
   158         hardware.Accept(visitor);     
   159     }
   160   }
   161 }