Fixed a problem, where the MainForm location and size was lost when the application is started minimized and exited without ever showing the form. This caused MainForm_Load to be never called (location and size was not loaded), but the default size and location were still saved. The new implementation only saves the location and size when one of the two is changed.
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;
40 using System.Globalization;
43 namespace OpenHardwareMonitor.Hardware.CPU {
45 internal class CPUGroup : IGroup {
46 private readonly List<IHardware> hardware = new List<IHardware>();
48 private readonly CPUID[][][] threads;
50 private static CPUID[][] GetProcessorThreads() {
52 List<CPUID> threads = new List<CPUID>();
53 for (int i = 0; i < 32; i++) {
55 threads.Add(new CPUID(i));
56 } catch (ArgumentOutOfRangeException) { }
59 SortedDictionary<uint, List<CPUID>> processors =
60 new SortedDictionary<uint, List<CPUID>>();
61 foreach (CPUID thread in threads) {
63 processors.TryGetValue(thread.ProcessorId, out list);
65 list = new List<CPUID>();
66 processors.Add(thread.ProcessorId, list);
71 CPUID[][] processorThreads = new CPUID[processors.Count][];
73 foreach (List<CPUID> list in processors.Values) {
74 processorThreads[index] = list.ToArray();
77 return processorThreads;
80 private static CPUID[][] GroupThreadsByCore(IEnumerable<CPUID> threads) {
82 SortedDictionary<uint, List<CPUID>> cores =
83 new SortedDictionary<uint, List<CPUID>>();
84 foreach (CPUID thread in threads) {
86 cores.TryGetValue(thread.CoreId, out coreList);
87 if (coreList == null) {
88 coreList = new List<CPUID>();
89 cores.Add(thread.CoreId, coreList);
94 CPUID[][] coreThreads = new CPUID[cores.Count][];
96 foreach (List<CPUID> list in cores.Values) {
97 coreThreads[index] = list.ToArray();
103 public CPUGroup(ISettings settings) {
105 CPUID[][] processorThreads = GetProcessorThreads();
106 this.threads = new CPUID[processorThreads.Length][][];
109 foreach (CPUID[] threads in processorThreads) {
110 if (threads.Length == 0)
113 CPUID[][] coreThreads = GroupThreadsByCore(threads);
115 this.threads[index] = coreThreads;
117 switch (threads[0].Vendor) {
119 hardware.Add(new IntelCPU(index, coreThreads, settings));
122 switch (threads[0].Family) {
124 hardware.Add(new AMD0FCPU(index, coreThreads, settings));
127 hardware.Add(new AMD10CPU(index, coreThreads, settings));
130 hardware.Add(new GenericCPU(index, coreThreads, settings));
134 hardware.Add(new GenericCPU(index, coreThreads, settings));
142 public IHardware[] Hardware {
144 return hardware.ToArray();
148 private static void AppendCpuidData(StringBuilder r, uint[,] data,
151 for (int i = 0; i < data.GetLength(0); i++) {
153 r.Append((i + offset).ToString("X8", CultureInfo.InvariantCulture));
154 for (int j = 0; j < 4; j++) {
156 r.Append(data[i, j].ToString("X8", CultureInfo.InvariantCulture));
162 public string GetReport() {
166 StringBuilder r = new StringBuilder();
168 r.AppendLine("CPUID");
171 for (int i = 0; i < threads.Length; i++) {
173 r.AppendLine("Processor " + i);
175 r.AppendFormat("Processor Vendor: {0}{1}", threads[i][0][0].Vendor,
176 Environment.NewLine);
177 r.AppendFormat("Processor Brand: {0}{1}", threads[i][0][0].BrandString,
178 Environment.NewLine);
179 r.AppendFormat("Family: 0x{0}{1}",
180 threads[i][0][0].Family.ToString("X", CultureInfo.InvariantCulture),
181 Environment.NewLine);
182 r.AppendFormat("Model: 0x{0}{1}",
183 threads[i][0][0].Model.ToString("X", CultureInfo.InvariantCulture),
184 Environment.NewLine);
185 r.AppendFormat("Stepping: 0x{0}{1}",
186 threads[i][0][0].Stepping.ToString("X", CultureInfo.InvariantCulture),
187 Environment.NewLine);
190 r.AppendLine("CPUID Return Values");
192 for (int j = 0; j < threads[i].Length; j++)
193 for (int k = 0; k < threads[i][j].Length; k++) {
194 r.AppendLine(" CPU Thread: " + threads[i][j][k].Thread);
195 r.AppendLine(" APIC ID: " + threads[i][j][k].ApicId);
196 r.AppendLine(" Processor ID: " + threads[i][j][k].ProcessorId);
197 r.AppendLine(" Core ID: " + threads[i][j][k].CoreId);
198 r.AppendLine(" Thread ID: " + threads[i][j][k].ThreadId);
200 r.AppendLine(" Function EAX EBX ECX EDX");
201 AppendCpuidData(r, threads[i][j][k].Data, CPUID.CPUID_0);
202 AppendCpuidData(r, threads[i][j][k].ExtData, CPUID.CPUID_EXT);
209 public void Close() { }