Hardware/SMBIOS/SMBIOSGroup.cs
changeset 8 39067efce486
parent 1 361e324a0ed4
child 9 e5adb0fd4917
     1.1 --- a/Hardware/SMBIOS/SMBIOSGroup.cs	Thu Jan 28 23:29:39 2010 +0000
     1.2 +++ b/Hardware/SMBIOS/SMBIOSGroup.cs	Fri Jan 29 19:20:44 2010 +0000
     1.3 @@ -1,4 +1,4 @@
     1.4 -/*
     1.5 +/*
     1.6    
     1.7    Version: MPL 1.1/GPL 2.0/LGPL 2.1
     1.8  
     1.9 @@ -54,55 +54,59 @@
    1.10        int p = (int)System.Environment.OSVersion.Platform;
    1.11        if ((p == 4) || (p == 128))
    1.12          return;
    1.13 -          
    1.14 -      ManagementObjectCollection collection = new ManagementObjectSearcher(
    1.15 -         "root\\WMI", "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
    1.16 -
    1.17 -      byte[] raw = null;
    1.18 -      foreach (ManagementObject mo in collection) {
    1.19 -        raw = (byte[])mo["SMBiosData"];
    1.20 -        break;
    1.21 -      }
    1.22 -
    1.23 +      
    1.24        List<Structure> structureList = new List<Structure>();
    1.25 -      if (raw != null && raw.Length > 0) {
    1.26 -        int offset = 0;
    1.27 -        byte type = raw[offset];
    1.28 -        while (offset < raw.Length && type != 127) {
    1.29 -          
    1.30 -          type = raw[offset]; offset++;
    1.31 -          int length = raw[offset]; offset++;
    1.32 -          ushort handle = (ushort)((raw[offset] << 8) | raw[offset + 1]); 
    1.33 -          offset += 2;
    1.34 -          
    1.35 -          byte[] data = new byte[length];
    1.36 -          Array.Copy(raw, offset - 4, data, 0, length); offset += length - 4;
    1.37 -
    1.38 -          List<string> stringsList = new List<string>();
    1.39 -          if (raw[offset] == 0)
    1.40 -            offset++;
    1.41 -          while (raw[offset] != 0) {   
    1.42 -            StringBuilder sb = new StringBuilder();
    1.43 -            while (raw[offset] != 0) {
    1.44 -              sb.Append((char)raw[offset]); offset++;
    1.45 +      
    1.46 +      try {
    1.47 +        ManagementObjectCollection collection = new ManagementObjectSearcher(
    1.48 +          "root\\WMI", "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
    1.49 +  
    1.50 +        byte[] raw = null;
    1.51 +        foreach (ManagementObject mo in collection) {
    1.52 +          raw = (byte[])mo["SMBiosData"];
    1.53 +          break;
    1.54 +        }      
    1.55 +      
    1.56 +        if (raw != null && raw.Length > 0) {
    1.57 +          int offset = 0;
    1.58 +          byte type = raw[offset];
    1.59 +          while (offset < raw.Length && type != 127) {
    1.60 +            
    1.61 +            type = raw[offset]; offset++;
    1.62 +            int length = raw[offset]; offset++;
    1.63 +            ushort handle = (ushort)((raw[offset] << 8) | raw[offset + 1]); 
    1.64 +            offset += 2;
    1.65 +            
    1.66 +            byte[] data = new byte[length];
    1.67 +            Array.Copy(raw, offset - 4, data, 0, length); offset += length - 4;
    1.68 +  
    1.69 +            List<string> stringsList = new List<string>();
    1.70 +            if (raw[offset] == 0)
    1.71 +              offset++;
    1.72 +            while (raw[offset] != 0) {   
    1.73 +              StringBuilder sb = new StringBuilder();
    1.74 +              while (raw[offset] != 0) {
    1.75 +                sb.Append((char)raw[offset]); offset++;
    1.76 +              }
    1.77 +              offset++;
    1.78 +              stringsList.Add(sb.ToString());
    1.79              }
    1.80              offset++;
    1.81 -            stringsList.Add(sb.ToString());
    1.82 -          }
    1.83 -          offset++;
    1.84 -          switch (type) {
    1.85 -            case 0x00:
    1.86 -              this.biosInformation = new BIOSInformation(
    1.87 -                type, handle, data, stringsList.ToArray());
    1.88 -              structureList.Add(this.biosInformation); break;
    1.89 -            case 0x02: this.baseBoardInformation = new BaseBoardInformation(
    1.90 -                type, handle, data, stringsList.ToArray());
    1.91 -              structureList.Add(this.baseBoardInformation); break;
    1.92 -            default: structureList.Add(new Structure(
    1.93 -              type, handle, data, stringsList.ToArray())); break;
    1.94 +            switch (type) {
    1.95 +              case 0x00:
    1.96 +                this.biosInformation = new BIOSInformation(
    1.97 +                  type, handle, data, stringsList.ToArray());
    1.98 +                structureList.Add(this.biosInformation); break;
    1.99 +              case 0x02: this.baseBoardInformation = new BaseBoardInformation(
   1.100 +                  type, handle, data, stringsList.ToArray());
   1.101 +                structureList.Add(this.baseBoardInformation); break;
   1.102 +              default: structureList.Add(new Structure(
   1.103 +                type, handle, data, stringsList.ToArray())); break;
   1.104 +            }
   1.105            }
   1.106          }
   1.107 -      }
   1.108 +      } catch (NotImplementedException) { }
   1.109 +      
   1.110        table = structureList.ToArray();
   1.111      }
   1.112