commit d5ee47001871c5887f7dfb1f92948b6aedcc105c Author: Chris Kaczor Date: Fri May 2 17:24:53 2014 -0400 Add implementation diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..abd2844 --- /dev/null +++ b/.gitignore @@ -0,0 +1,155 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets +!packages/*/build/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml + +# NuGet Packages Directory +packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + + +#LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml + +# ========================= +# Windows detritus +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac desktop service store files +.DS_Store diff --git a/App.config b/App.config new file mode 100644 index 0000000..fa7cfbf --- /dev/null +++ b/App.config @@ -0,0 +1,30 @@ + + + + +
+ + + + + + + + + + + + 5000 + + + True + + + 60 + + + 80 + + + + \ No newline at end of file diff --git a/App.xaml b/App.xaml new file mode 100644 index 0000000..4314d94 --- /dev/null +++ b/App.xaml @@ -0,0 +1,7 @@ + + + + + diff --git a/App.xaml.cs b/App.xaml.cs new file mode 100644 index 0000000..1186400 --- /dev/null +++ b/App.xaml.cs @@ -0,0 +1,23 @@ +using System.Windows; + +namespace SystemTemperatureStatusWindow +{ + public partial class App + { + private WindowSource _windowSource; + + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + + _windowSource = new WindowSource(); + } + + protected override void OnExit(ExitEventArgs e) + { + _windowSource.Dispose(); + + base.OnExit(e); + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3678f36 --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SystemTemperatureStatusWindow")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SystemTemperatureStatusWindow")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..47c1d7d --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,136 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34014 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SystemTemperatureStatusWindow.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SystemTemperatureStatusWindow.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon ApplicationIcon { + get { + object obj = ResourceManager.GetObject("ApplicationIcon", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + + /// + /// Looks up a localized string similar to CPU. + /// + internal static string CPU { + get { + return ResourceManager.GetString("CPU", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0}: <font color='{2}'>{1:f1}{3}</font>. + /// + internal static string DisplayLineTemplate { + get { + return ResourceManager.GetString("DisplayLineTemplate", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to GPU. + /// + internal static string GPU { + get { + return ResourceManager.GetString("GPU", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to HD{0}. + /// + internal static string HD { + get { + return ResourceManager.GetString("HD", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Loading.... + /// + internal static string Loading { + get { + return ResourceManager.GetString("Loading", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to °C. + /// + internal static string SuffixC { + get { + return ResourceManager.GetString("SuffixC", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to °F. + /// + internal static string SuffixF { + get { + return ResourceManager.GetString("SuffixF", resourceCulture); + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..3776afa --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\ApplicationIcon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + CPU + + + {0}: <font color='{2}'>{1:f1}{3}</font> + + + GPU + + + HD{0} + + + Loading... + + + °C + + + °F + + \ No newline at end of file diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs new file mode 100644 index 0000000..c9d4cbe --- /dev/null +++ b/Properties/Settings.Designer.cs @@ -0,0 +1,86 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.34014 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SystemTemperatureStatusWindow.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string WindowSettings { + get { + return ((string)(this["WindowSettings"])); + } + set { + this["WindowSettings"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("5000")] + public int UpdateInterval { + get { + return ((int)(this["UpdateInterval"])); + } + set { + this["UpdateInterval"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool DisplayF { + get { + return ((bool)(this["DisplayF"])); + } + set { + this["DisplayF"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("60")] + public int WarningLevel { + get { + return ((int)(this["WarningLevel"])); + } + set { + this["WarningLevel"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("80")] + public int AlertLevel { + get { + return ((int)(this["AlertLevel"])); + } + set { + this["AlertLevel"] = value; + } + } + } +} diff --git a/Properties/Settings.settings b/Properties/Settings.settings new file mode 100644 index 0000000..58ac33a --- /dev/null +++ b/Properties/Settings.settings @@ -0,0 +1,21 @@ + + + + + + + + + 5000 + + + True + + + 60 + + + 80 + + + \ No newline at end of file diff --git a/Resources/ApplicationIcon.ico b/Resources/ApplicationIcon.ico new file mode 100644 index 0000000..b7d7601 Binary files /dev/null and b/Resources/ApplicationIcon.ico differ diff --git a/SystemTemperatureStatusWindow.csproj b/SystemTemperatureStatusWindow.csproj new file mode 100644 index 0000000..2d22e35 --- /dev/null +++ b/SystemTemperatureStatusWindow.csproj @@ -0,0 +1,106 @@ + + + + + Debug + AnyCPU + {E45425FD-4302-4555-8F24-18F2373DE1CE} + WinExe + Properties + SystemTemperatureStatusWindow + SystemTemperatureStatusWindow + v4.5 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\FloatingStatusWindowLibrary\FloatingStatusWindowLibrary\bin\Debug\FloatingStatusWindowLibrary.dll + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + + + + {b0397530-545a-471d-bb74-027ae456df1a} + OpenHardwareMonitorLib + + + + + \ No newline at end of file diff --git a/SystemTemperatureStatusWindow.sln b/SystemTemperatureStatusWindow.sln new file mode 100644 index 0000000..48fef20 --- /dev/null +++ b/SystemTemperatureStatusWindow.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30324.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemTemperatureStatusWindow", "SystemTemperatureStatusWindow.csproj", "{E45425FD-4302-4555-8F24-18F2373DE1CE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenHardwareMonitorLib", "..\..\Public\OpenHardwareMonitor\OpenHardwareMonitorLib.csproj", "{B0397530-545A-471D-BB74-027AE456DF1A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E45425FD-4302-4555-8F24-18F2373DE1CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E45425FD-4302-4555-8F24-18F2373DE1CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E45425FD-4302-4555-8F24-18F2373DE1CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E45425FD-4302-4555-8F24-18F2373DE1CE}.Release|Any CPU.Build.0 = Release|Any CPU + {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/WindowSource.cs b/WindowSource.cs new file mode 100644 index 0000000..1012978 --- /dev/null +++ b/WindowSource.cs @@ -0,0 +1,146 @@ +using FloatingStatusWindowLibrary; +using OpenHardwareMonitor.Hardware; +using System; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading; +using SystemTemperatureStatusWindow.Properties; + +namespace SystemTemperatureStatusWindow +{ + public class WindowSource : IWindowSource, IDisposable + { + private readonly FloatingStatusWindow _floatingStatusWindow; + private readonly BackgroundWorker _backgroundWorker; + + internal WindowSource() + { + _floatingStatusWindow = new FloatingStatusWindow(this); + _floatingStatusWindow.SetText(Resources.Loading); + + _backgroundWorker = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true }; + _backgroundWorker.ProgressChanged += HandleBackgroundWorkerProgressChanged; + _backgroundWorker.DoWork += HandleBackgroundWorkerDoWork; + _backgroundWorker.RunWorkerCompleted += HandleBackgroundWorkerRunWorkerCompleted; + _backgroundWorker.RunWorkerAsync(); + } + + public void Dispose() + { + _backgroundWorker.CancelAsync(); + + _floatingStatusWindow.Save(); + _floatingStatusWindow.Dispose(); + } + + public string Name + { + get { return "System Temperature"; } + } + + public System.Drawing.Icon Icon + { + get { return Resources.ApplicationIcon; } + } + + public string WindowSettings + { + get + { + return Settings.Default.WindowSettings; + } + set + { + Settings.Default.WindowSettings = value; + Settings.Default.Save(); + } + } + + void HandleBackgroundWorkerDoWork(object sender, DoWorkEventArgs e) + { + var backgroundWorker = (BackgroundWorker) sender; + + var computer = new Computer { HDDEnabled = true, FanControllerEnabled = false, GPUEnabled = true, MainboardEnabled = true, CPUEnabled = true }; + computer.Open(); + + while (!backgroundWorker.CancellationPending) + { + var builder = new StringBuilder(); + + foreach (var hardware in computer.Hardware) + { + hardware.Update(); + + var averageValue = hardware.Sensors.Where(sensor => sensor.SensorType == SensorType.Temperature).Average(sensor => sensor.Value); + + if (averageValue.HasValue) + { + string hardwareTag = string.Empty; + + switch (hardware.HardwareType) + { + case HardwareType.CPU: + hardwareTag = Resources.CPU; + break; + + case HardwareType.GpuAti: + case HardwareType.GpuNvidia: + hardwareTag = Resources.GPU; + break; + + case HardwareType.HDD: + string id = hardware.Identifier.ToString(); + hardwareTag = string.Format(Resources.HD, id.Substring(id.LastIndexOf("/", StringComparison.Ordinal) + 1)); + break; + } + + if (!string.IsNullOrWhiteSpace(hardwareTag)) + { + string color = "green"; + + if (averageValue > Settings.Default.AlertLevel) + color = "red"; + else if (averageValue.Value > Settings.Default.WarningLevel) + color = "yellow"; + + double averageDisplay; + string suffix; + + if (Settings.Default.DisplayF) + { + averageDisplay = ((9.0 / 5.0) * averageValue.Value) + 32; + suffix = Resources.SuffixF; + } + else + { + averageDisplay = averageValue.Value; + suffix = Resources.SuffixC; + } + + if (builder.Length > 0) + builder.AppendLine(); + + builder.AppendFormat(Resources.DisplayLineTemplate, hardwareTag, averageDisplay, color, suffix); + } + } + } + + backgroundWorker.ReportProgress(0, builder.ToString()); + + Thread.Sleep(Settings.Default.UpdateInterval); + } + + computer.Close(); + } + + void HandleBackgroundWorkerProgressChanged(object sender, ProgressChangedEventArgs e) + { + _floatingStatusWindow.SetText((string) e.UserState); + } + + void HandleBackgroundWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + } + } +}