Initial WIP commit
Some checks failed
Deploy to Gitea Releases / deploy-to-gitea-releases (push) Failing after 9s

This commit is contained in:
2026-01-27 18:58:09 -05:00
commit 853e8eab0d
45 changed files with 2920 additions and 0 deletions

24
StatusWindow/App.config Normal file
View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="HardwareMonitorStatusWindow.StatusWindow.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<HardwareMonitorStatusWindow.StatusWindow.Settings>
<setting name="WindowSettings" serializeAs="String">
<value />
</setting>
<setting name="AutoStart" serializeAs="String">
<value>True</value>
</setting>
<setting name="CheckVersionAtStartup" serializeAs="String">
<value>True</value>
</setting>
<setting name="Sensors" serializeAs="String">
<value>[]</value>
</setting>
</HardwareMonitorStatusWindow.StatusWindow.Settings>
</userSettings>
</configuration>

7
StatusWindow/App.xaml Normal file
View File

@@ -0,0 +1,7 @@
<Application x:Class="HardwareMonitorStatusWindow.StatusWindow.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ShutdownMode="OnLastWindowClose">
<Application.Resources>
</Application.Resources>
</Application>

37
StatusWindow/App.xaml.cs Normal file
View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using ChrisKaczor.Wpf.Windows.FloatingStatusWindow;
namespace HardwareMonitorStatusWindow.StatusWindow;
public partial class App
{
private List<IDisposable> _windowSourceList;
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
StartManager.ManageAutoStart = true;
StartManager.AutoStartEnabled = !Debugger.IsAttached && Settings.Default.AutoStart;
StartManager.AutoStartChanged += (value =>
{
Settings.Default.AutoStart = value;
Settings.Default.Save();
});
_windowSourceList =
[
new WindowSource()
];
}
protected override void OnExit(ExitEventArgs e)
{
_windowSourceList.ForEach(ws => ws.Dispose());
base.OnExit(e);
}
}

View File

@@ -0,0 +1,24 @@
using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Windows;
[assembly: AssemblyTitle("HardwareMonitorStatusWindow")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HardwareMonitorStatusWindow")]
[assembly: AssemblyCopyright("Copyright © Chris Kaczor 2026")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: SupportedOSPlatform("windows7.0")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

54
StatusWindow/Data.cs Normal file
View File

@@ -0,0 +1,54 @@
using System;
using HardwareMonitorStatusWindow.Service;
using PipeMethodCalls;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
namespace HardwareMonitorStatusWindow.StatusWindow;
internal static class Data
{
private static PipeClient<IHardwareMonitorService> _pipeClient;
private static IEnumerable<Hardware> _hardware;
internal static ObservableCollection<SensorEntry> SensorEntries { get; set; }
internal static async Task LoadComputer()
{
try
{
_pipeClient = new PipeClient<IHardwareMonitorService>(new HardwarePipeSerializer(), HardwareMonitorService.PipeName);
await _pipeClient.ConnectAsync();
}
catch (Exception exception)
{
}
}
internal static void RefreshComputer()
{
_hardware = _pipeClient.InvokeAsync(service => service.GetHardware()).Result;
}
internal static void CloseComputer()
{
_pipeClient.Dispose();
}
internal static IList<Hardware> ComputerHardware => _hardware.ToList();
internal static void Load()
{
SensorEntries = JsonSerializer.Deserialize<ObservableCollection<SensorEntry>>(Settings.Default.Sensors);
}
internal static void Save()
{
Settings.Default.Sensors = JsonSerializer.Serialize(SensorEntries);
Settings.Default.Save();
}
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
namespace HardwareMonitorStatusWindow.StatusWindow;
internal class DataErrorDictionary : Dictionary<string, List<string>>
{
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
private void OnErrorsChanged(string propertyName)
{
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
}
public IEnumerable GetErrors(string propertyName)
{
return TryGetValue(propertyName, out var value) ? value : null;
}
public void AddError(string propertyName, string error)
{
if (!ContainsKey(propertyName))
this[propertyName] = [];
if (this[propertyName].Contains(error))
return;
this[propertyName].Add(error);
OnErrorsChanged(propertyName);
}
public void ClearErrors(string propertyName)
{
if (!ContainsKey(propertyName))
return;
Remove(propertyName);
OnErrorsChanged(propertyName);
}
}

26
StatusWindow/Program.cs Normal file
View File

@@ -0,0 +1,26 @@
using System;
using Serilog;
using Velopack;
namespace HardwareMonitorStatusWindow.StatusWindow;
internal class Program
{
[STAThread]
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration().WriteTo.File("log.txt").CreateLogger();
Log.Logger.Information("Start");
// var loggerFactory = new LoggerFactory().AddSerilog(Log.Logger);
VelopackApp.Build().Run(); // loggerFactory.CreateLogger("Install")
var app = new App();
app.InitializeComponent();
app.Run();
Log.Logger.Information("End");
}
}

446
StatusWindow/Resources.Designer.cs generated Normal file
View File

@@ -0,0 +1,446 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace HardwareMonitorStatusWindow.StatusWindow {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// 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", "18.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public 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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("HardwareMonitorStatusWindow.StatusWindow.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Add.
/// </summary>
public static string AddSensorLink {
get {
return ResourceManager.GetString("AddSensorLink", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Add Sensor.
/// </summary>
public static string AddSensorToolTip {
get {
return ResourceManager.GetString("AddSensorToolTip", resourceCulture);
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
public static System.Drawing.Icon ApplicationIcon {
get {
object obj = ResourceManager.GetObject("ApplicationIcon", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized string similar to Hardware Monitor Status Window.
/// </summary>
public static string ApplicationName {
get {
return ResourceManager.GetString("ApplicationName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Cancel.
/// </summary>
public static string CancelButton {
get {
return ResourceManager.GetString("CancelButton", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Checking for update....
/// </summary>
public static string CheckingForUpdate {
get {
return ResourceManager.GetString("CheckingForUpdate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to _Check for Update.
/// </summary>
public static string CheckUpdate {
get {
return ResourceManager.GetString("CheckUpdate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Check _Now.
/// </summary>
public static string checkVersionNowButton {
get {
return ResourceManager.GetString("checkVersionNowButton", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to _Check for a new version on startup.
/// </summary>
public static string checkVersionOnStartupCheckBox {
get {
return ResourceManager.GetString("checkVersionOnStartupCheckBox", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Close.
/// </summary>
public static string CloseButtonText {
get {
return ResourceManager.GetString("CloseButtonText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Are you sure you want to delete the selected sensors?.
/// </summary>
public static string ConfirmDeleteSensors {
get {
return ResourceManager.GetString("ConfirmDeleteSensors", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Confirm Delete.
/// </summary>
public static string ConfirmDeleteTitle {
get {
return ResourceManager.GetString("ConfirmDeleteTitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Delete.
/// </summary>
public static string DeleteSensorLink {
get {
return ResourceManager.GetString("DeleteSensorLink", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Delete Sensor.
/// </summary>
public static string DeleteSensorToolTip {
get {
return ResourceManager.GetString("DeleteSensorToolTip", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Downloading update....
/// </summary>
public static string DownloadingUpdate {
get {
return ResourceManager.GetString("DownloadingUpdate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Edit.
/// </summary>
public static string EditSensorLink {
get {
return ResourceManager.GetString("EditSensorLink", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Edit Sensor.
/// </summary>
public static string EditSensorToolTip {
get {
return ResourceManager.GetString("EditSensorToolTip", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Hardware.
/// </summary>
public static string HardwareColumnHeader {
get {
return ResourceManager.GetString("HardwareColumnHeader", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Hardware Type.
/// </summary>
public static string HardwareTypeWatermark {
get {
return ResourceManager.GetString("HardwareTypeWatermark", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Hardware.
/// </summary>
public static string HardwareWatermark {
get {
return ResourceManager.GetString("HardwareWatermark", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Installing update....
/// </summary>
public static string InstallingUpdate {
get {
return ResourceManager.GetString("InstallingUpdate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Label.
/// </summary>
public static string LabelColumnHeader {
get {
return ResourceManager.GetString("LabelColumnHeader", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Loading....
/// </summary>
public static string Loading {
get {
return ResourceManager.GetString("Loading", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to OK.
/// </summary>
public static string OkayButton {
get {
return ResourceManager.GetString("OkayButton", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to About.
/// </summary>
public static string optionCategoryAbout {
get {
return ResourceManager.GetString("optionCategoryAbout", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to General.
/// </summary>
public static string optionCategoryGeneral {
get {
return ResourceManager.GetString("optionCategoryGeneral", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Hardware.
/// </summary>
public static string optionCategoryHardware {
get {
return ResourceManager.GetString("optionCategoryHardware", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sensors.
/// </summary>
public static string optionCategorySensors {
get {
return ResourceManager.GetString("optionCategorySensors", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Update.
/// </summary>
public static string optionCategoryUpdate {
get {
return ResourceManager.GetString("optionCategoryUpdate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sensor.
/// </summary>
public static string SensorColumnHeader {
get {
return ResourceManager.GetString("SensorColumnHeader", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sensor Type.
/// </summary>
public static string SensorTypeWatermark {
get {
return ResourceManager.GetString("SensorTypeWatermark", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sensor.
/// </summary>
public static string SensorWatermark {
get {
return ResourceManager.GetString("SensorWatermark", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Add Sensor.
/// </summary>
public static string SensorWindowAdd {
get {
return ResourceManager.GetString("SensorWindowAdd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Edit Sensor.
/// </summary>
public static string SensorWindowEdit {
get {
return ResourceManager.GetString("SensorWindowEdit", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Service not installed - restart application.
/// </summary>
public static string ServiceNotInstalled {
get {
return ResourceManager.GetString("ServiceNotInstalled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Waiting for service to start....
/// </summary>
public static string ServiceNotStarted {
get {
return ResourceManager.GetString("ServiceNotStarted", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Settings.
/// </summary>
public static string SettingsTitle {
get {
return ResourceManager.GetString("SettingsTitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to _Start when Windows starts.
/// </summary>
public static string startWithWindowsCheckBox {
get {
return ResourceManager.GetString("startWithWindowsCheckBox", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You are already running the most recent version.
///
///No updates are available at this time..
/// </summary>
public static string UpdateCheckCurrent {
get {
return ResourceManager.GetString("UpdateCheckCurrent", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Version {0} is now available.
///
///Would you like to download and install it now?.
/// </summary>
public static string UpdateCheckNewVersion {
get {
return ResourceManager.GetString("UpdateCheckNewVersion", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} Update.
/// </summary>
public static string UpdateCheckTitle {
get {
return ResourceManager.GetString("UpdateCheckTitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Version {0}.
/// </summary>
public static string Version {
get {
return ResourceManager.GetString("Version", resourceCulture);
}
}
}
}

251
StatusWindow/Resources.resx Normal file
View File

@@ -0,0 +1,251 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ApplicationName" xml:space="preserve">
<value>Hardware Monitor Status Window</value>
</data>
<data name="optionCategoryAbout" xml:space="preserve">
<value>About</value>
</data>
<data name="CheckUpdate" xml:space="preserve">
<value>_Check for Update</value>
</data>
<data name="startWithWindowsCheckBox" xml:space="preserve">
<value>_Start when Windows starts</value>
</data>
<data name="optionCategoryGeneral" xml:space="preserve">
<value>General</value>
</data>
<data name="SettingsTitle" xml:space="preserve">
<value>Settings</value>
</data>
<data name="CloseButtonText" xml:space="preserve">
<value>Close</value>
</data>
<data name="Version" xml:space="preserve">
<value>Version {0}</value>
</data>
<data name="optionCategoryUpdate" xml:space="preserve">
<value>Update</value>
</data>
<data name="checkVersionOnStartupCheckBox" xml:space="preserve">
<value>_Check for a new version on startup</value>
</data>
<data name="checkVersionNowButton" xml:space="preserve">
<value>Check _Now</value>
</data>
<data name="UpdateCheckTitle" xml:space="preserve">
<value>{0} Update</value>
</data>
<data name="UpdateCheckCurrent" xml:space="preserve">
<value>You are already running the most recent version.
No updates are available at this time.</value>
</data>
<data name="UpdateCheckNewVersion" xml:space="preserve">
<value>Version {0} is now available.
Would you like to download and install it now?</value>
</data>
<data name="Loading" xml:space="preserve">
<value>Loading...</value>
</data>
<data name="CheckingForUpdate" xml:space="preserve">
<value>Checking for update...</value>
</data>
<data name="DownloadingUpdate" xml:space="preserve">
<value>Downloading update...</value>
</data>
<data name="InstallingUpdate" xml:space="preserve">
<value>Installing update...</value>
</data>
<data name="ConfirmDeleteTitle" xml:space="preserve">
<value>Confirm Delete</value>
</data>
<data name="OkayButton" xml:space="preserve">
<value>OK</value>
</data>
<data name="CancelButton" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="optionCategoryHardware" xml:space="preserve">
<value>Hardware</value>
</data>
<data name="EditSensorLink" xml:space="preserve">
<value>Edit</value>
</data>
<data name="DeleteSensorLink" xml:space="preserve">
<value>Delete</value>
</data>
<data name="AddSensorToolTip" xml:space="preserve">
<value>Add Sensor</value>
</data>
<data name="EditSensorToolTip" xml:space="preserve">
<value>Edit Sensor</value>
</data>
<data name="DeleteSensorToolTip" xml:space="preserve">
<value>Delete Sensor</value>
</data>
<data name="optionCategorySensors" xml:space="preserve">
<value>Sensors</value>
</data>
<data name="LabelColumnHeader" xml:space="preserve">
<value>Label</value>
</data>
<data name="SensorColumnHeader" xml:space="preserve">
<value>Sensor</value>
</data>
<data name="AddSensorLink" xml:space="preserve">
<value>Add</value>
</data>
<data name="SensorWindowAdd" xml:space="preserve">
<value>Add Sensor</value>
</data>
<data name="SensorWindowEdit" xml:space="preserve">
<value>Edit Sensor</value>
</data>
<data name="ConfirmDeleteSensors" xml:space="preserve">
<value>Are you sure you want to delete the selected sensors?</value>
</data>
<data name="HardwareWatermark" xml:space="preserve">
<value>Hardware</value>
</data>
<data name="SensorWatermark" xml:space="preserve">
<value>Sensor</value>
</data>
<data name="SensorTypeWatermark" xml:space="preserve">
<value>Sensor Type</value>
</data>
<data name="HardwareColumnHeader" xml:space="preserve">
<value>Hardware</value>
</data>
<data name="HardwareTypeWatermark" xml:space="preserve">
<value>Hardware Type</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="ApplicationIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\Application.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ServiceNotInstalled" xml:space="preserve">
<value>Service not installed - restart application</value>
</data>
<data name="ServiceNotStarted" xml:space="preserve">
<value>Waiting for service to start...</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

133
StatusWindow/SensorEntry.cs Normal file
View File

@@ -0,0 +1,133 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;
using HardwareMonitorStatusWindow.Service;
namespace HardwareMonitorStatusWindow.StatusWindow;
public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged
{
private readonly DataErrorDictionary _dataErrorDictionary;
public SensorEntry()
{
_dataErrorDictionary = new DataErrorDictionary();
_dataErrorDictionary.ErrorsChanged += DataErrorDictionaryErrorsChanged;
}
public string Label
{
get;
set
{
if (!ValidateLabel(value))
return;
SetField(ref field, value);
}
}
public string HardwareId
{
get;
set
{
SetField(ref field, value);
OnPropertyChanged(nameof(Hardware));
}
}
public string SensorId
{
get;
set
{
SetField(ref field, value);
OnPropertyChanged(nameof(Sensor));
}
}
[JsonIgnore]
public Hardware? Hardware => Data.ComputerHardware.FirstOrDefault(h => h.Identifier.ToString() == HardwareId);
[JsonIgnore]
public Sensor? Sensor => Hardware?.Sensors.FirstOrDefault(s => s.Identifier.ToString() == SensorId);
[JsonIgnore]
public bool HasErrors => _dataErrorDictionary.Any();
public IEnumerable GetErrors(string propertyName)
{
return _dataErrorDictionary.GetErrors(propertyName);
}
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
private void DataErrorDictionaryErrorsChanged(object sender, DataErrorsChangedEventArgs e)
{
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(e.PropertyName));
}
private bool ValidateLabel(string newValue)
{
_dataErrorDictionary.ClearErrors(nameof(Label));
if (!string.IsNullOrWhiteSpace(newValue))
return true;
_dataErrorDictionary.AddError(nameof(Label), "Label cannot be empty");
return false;
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
public string SensorValueFormat
{
get
{
return Sensor?.Type switch
{
SensorType.Voltage => "{0:F3} V",
SensorType.Current => "{0:F3} A",
SensorType.Clock => "{0:F1} MHz",
SensorType.Load => "{0:F1} %",
SensorType.Temperature => "{0:F1} °C",
SensorType.Fan => "{0:F0} RPM",
SensorType.Flow => "{0:F1} L/h",
SensorType.Control => "{0:F1} %",
SensorType.Level => "{0:F1} %",
SensorType.Power => "{0:F1} W",
SensorType.Data => "{0:F1} GB",
SensorType.SmallData => "{0:F1} MB",
SensorType.Factor => "{0:F3}",
SensorType.Frequency => "{0:F1} Hz",
SensorType.Throughput => "{0:F1} B/s",
SensorType.TimeSpan => "{0:g}",
SensorType.Timing => "{0:F3} ns",
SensorType.Energy => "{0:F0} mWh",
SensorType.Noise => "{0:F0} dBA",
SensorType.Conductivity => "{0:F1} µS/cm",
SensorType.Humidity => "{0:F0} %",
_ => string.Empty
};
}
}
}

74
StatusWindow/Settings.Designer.cs generated Normal file
View File

@@ -0,0 +1,74 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace HardwareMonitorStatusWindow.StatusWindow {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.14.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("True")]
public bool AutoStart {
get {
return ((bool)(this["AutoStart"]));
}
set {
this["AutoStart"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool CheckVersionAtStartup {
get {
return ((bool)(this["CheckVersionAtStartup"]));
}
set {
this["CheckVersionAtStartup"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("[]")]
public string Sensors {
get {
return ((string)(this["Sensors"]));
}
set {
this["Sensors"] = value;
}
}
}
}

View File

@@ -0,0 +1,18 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="HardwareMonitorStatusWindow.StatusWindow" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="WindowSettings" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="AutoStart" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="CheckVersionAtStartup" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="Sensors" Type="System.String" Scope="User">
<Value Profile="(Default)">[]</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@@ -0,0 +1,20 @@
<windows:CategoryPanelBase x:Class="HardwareMonitorStatusWindow.StatusWindow.SettingsWindow.AboutSettingsPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:windows="clr-namespace:ChrisKaczor.Wpf.Windows;assembly=ChrisKaczor.Wpf.Windows.CategoryWindow"
xmlns:window="clr-namespace:HardwareMonitorStatusWindow.StatusWindow"
mc:Ignorable="d"
d:DesignHeight="150"
d:DesignWidth="300">
<Grid>
<StackPanel windows:Spacing.Vertical="10">
<TextBlock Text="{x:Static window:Resources.ApplicationName}"
FontWeight="Bold" />
<TextBlock Text="{Binding Source={x:Static window:UpdateCheck.LocalVersion}, StringFormat={x:Static window:Resources.Version}}"
Name="VersionLabel" />
<TextBlock Text="Chris Kaczor" />
</StackPanel>
</Grid>
</windows:CategoryPanelBase>

View File

@@ -0,0 +1,12 @@
namespace HardwareMonitorStatusWindow.StatusWindow.SettingsWindow
{
public partial class AboutSettingsPanel
{
public AboutSettingsPanel()
{
InitializeComponent();
}
public override string CategoryName => StatusWindow.Resources.optionCategoryAbout;
}
}

View File

@@ -0,0 +1,16 @@
<windows:CategoryPanelBase x:Class="HardwareMonitorStatusWindow.StatusWindow.SettingsWindow.GeneralSettingsPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:windows="clr-namespace:ChrisKaczor.Wpf.Windows;assembly=ChrisKaczor.Wpf.Windows.CategoryWindow"
xmlns:properties="clr-namespace:HardwareMonitorStatusWindow.StatusWindow"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300">
<StackPanel windows:Spacing.Vertical="10">
<CheckBox Content="{x:Static properties:Resources.startWithWindowsCheckBox}"
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=AutoStart}"
Click="OnSaveSettings" />
</StackPanel>
</windows:CategoryPanelBase>

View File

@@ -0,0 +1,35 @@
using System.Windows;
using ChrisKaczor.Wpf.Application;
namespace HardwareMonitorStatusWindow.StatusWindow.SettingsWindow;
public partial class GeneralSettingsPanel
{
public GeneralSettingsPanel()
{
InitializeComponent();
}
public override string CategoryName => StatusWindow.Resources.optionCategoryGeneral;
public override void LoadPanel(Window parentWindow)
{
base.LoadPanel(parentWindow);
MarkLoaded();
}
private void OnSaveSettings(object sender, RoutedEventArgs e)
{
SaveSettings();
}
private void SaveSettings()
{
if (!HasLoaded) return;
Settings.Default.Save();
Application.Current.SetStartWithWindows(Settings.Default.AutoStart);
}
}

View File

@@ -0,0 +1,126 @@
<windows:CategoryPanelBase
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:hardwareMonitorStatusWindow="clr-namespace:HardwareMonitorStatusWindow.StatusWindow"
xmlns:windows="clr-namespace:ChrisKaczor.Wpf.Windows;assembly=ChrisKaczor.Wpf.Windows.CategoryWindow"
xmlns:controls="clr-namespace:ChrisKaczor.Wpf.Controls;assembly=ChrisKaczor.Wpf.Controls.Link"
xmlns:dd="urn:gong-wpf-dragdrop"
x:Class="HardwareMonitorStatusWindow.StatusWindow.SettingsWindow.HardwareSettingsPanel"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300">
<windows:CategoryPanelBase.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary
Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.FlatButton.xaml" />
<ResourceDictionary
Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/light.cobalt.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</windows:CategoryPanelBase.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<DataGrid Name="SensorDataGrid"
SelectionMode="Extended"
Grid.Column="0"
Grid.Row="0"
AutoGenerateColumns="False"
GridLinesVisibility="None"
CanUserResizeRows="False"
IsReadOnly="True"
CanUserSortColumns="False"
SelectionUnit="FullRow"
HeadersVisibility="Column"
BorderThickness="1,1,1,1"
BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"
Background="{x:Null}"
SelectionChanged="HandleSensorDataGridSelectionChanged"
d:DataContext="{d:DesignInstance hardwareMonitorStatusWindow:SensorEntry }"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=Label}"
Header="{x:Static hardwareMonitorStatusWindow:Resources.LabelColumnHeader}"
Width="*" />
<DataGridTemplateColumn Header="{x:Static hardwareMonitorStatusWindow:Resources.HardwareColumnHeader}"
Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Hardware.Type}"
Height="Auto"
FontSize="10"
VerticalAlignment="Center"
Margin="0,2,0,2" />
<TextBlock Text="{Binding Path=Hardware.Name}"
Height="Auto"
VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="{x:Static hardwareMonitorStatusWindow:Resources.SensorColumnHeader}"
Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Sensor.Type}"
Height="Auto"
FontSize="10"
VerticalAlignment="Center"
Margin="0,2,0,2" />
<TextBlock Text="{Binding Path=Sensor.Name}"
Height="Auto"
VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow"
BasedOn="{StaticResource MahApps.Styles.DataGridRow}">
<EventSetter Event="MouseDoubleClick"
Handler="HandleSensorDataGridRowMouseDoubleClick" />
</Style>
</DataGrid.RowStyle>
</DataGrid>
<Border Grid.Column="0"
Grid.Row="1"
BorderThickness="1,0,1,1"
BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}">
<StackPanel Orientation="Horizontal"
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
<controls:Link Name="AddSensorButton"
Margin="2"
Click="HandleAddSensorButtonClick"
Text="{x:Static hardwareMonitorStatusWindow:Resources.AddSensorLink}"
ToolTip="{x:Static hardwareMonitorStatusWindow:Resources.AddSensorToolTip}">
</controls:Link>
<controls:Link Name="EditSensorButton"
Margin="2"
Click="HandleEditSensorButtonClick"
Text="{x:Static hardwareMonitorStatusWindow:Resources.EditSensorLink}"
ToolTip="{x:Static hardwareMonitorStatusWindow:Resources.EditSensorToolTip}">
</controls:Link>
<controls:Link Name="DeleteSensorButton"
Margin="2"
Click="HandleDeleteSensorButtonClick"
Text="{x:Static hardwareMonitorStatusWindow:Resources.DeleteSensorLink}"
ToolTip="{x:Static hardwareMonitorStatusWindow:Resources.DeleteSensorToolTip}">
</controls:Link>
</StackPanel>
</Border>
</Grid>
</windows:CategoryPanelBase>

View File

@@ -0,0 +1,112 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
namespace HardwareMonitorStatusWindow.StatusWindow.SettingsWindow;
public partial class HardwareSettingsPanel
{
private CollectionViewSource _collectionViewSource;
public HardwareSettingsPanel()
{
InitializeComponent();
}
public override string CategoryName => StatusWindow.Resources.optionCategorySensors;
public override void LoadPanel(Window parentWindow)
{
base.LoadPanel(parentWindow);
if (_collectionViewSource == null)
{
_collectionViewSource = new CollectionViewSource { Source = Data.SensorEntries };
SensorDataGrid.ItemsSource = _collectionViewSource.View;
}
_collectionViewSource.View.Refresh();
if (SensorDataGrid.Items.Count > 0)
SensorDataGrid.SelectedIndex = 0;
SetSensorButtonStates();
}
private void HandleSensorDataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
{
SetSensorButtonStates();
}
private void SetSensorButtonStates()
{
AddSensorButton.IsEnabled = true;
EditSensorButton.IsEnabled = SensorDataGrid.SelectedItems.Count == 1;
DeleteSensorButton.IsEnabled = SensorDataGrid.SelectedItems.Count > 0;
}
private void HandleAddSensorButtonClick(object sender, RoutedEventArgs e)
{
AddSensor();
}
private void HandleEditSensorButtonClick(object sender, RoutedEventArgs e)
{
EditSelectedSensor();
}
private void HandleDeleteSensorButtonClick(object sender, RoutedEventArgs e)
{
DeleteSelectedSensors();
}
private void HandleSensorDataGridRowMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
EditSelectedSensor();
}
private void AddSensor()
{
var sensorEntry = new SensorEntry();
var sensorWindow = new SensorWindow();
var result = sensorWindow.Display(sensorEntry, Window.GetWindow(this));
if (!result.HasValue || !result.Value)
return;
SensorDataGrid.SelectedItem = sensorEntry;
SetSensorButtonStates();
}
private void EditSelectedSensor()
{
if (SensorDataGrid.SelectedItem == null)
return;
var sensorEntry = (SensorEntry)SensorDataGrid.SelectedItem;
var sensorWindow = new SensorWindow();
sensorWindow.Display(sensorEntry, Window.GetWindow(this));
}
private void DeleteSelectedSensors()
{
if (MessageBox.Show(ParentWindow!, StatusWindow.Resources.ConfirmDeleteSensors, StatusWindow.Resources.ConfirmDeleteTitle, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
return;
var selectedItems = new SensorEntry[SensorDataGrid.SelectedItems.Count];
SensorDataGrid.SelectedItems.CopyTo(selectedItems, 0);
foreach (var sensorEntry in selectedItems)
Data.SensorEntries.Remove(sensorEntry);
SetSensorButtonStates();
}
}

View File

@@ -0,0 +1,10 @@
using HardwareMonitorStatusWindow.Service;
namespace HardwareMonitorStatusWindow.StatusWindow.SettingsWindow;
public class HardwareTypeItem(HardwareType hardwareType)
{
public HardwareType Value { get; set; } = hardwareType;
public string Name { get; set; } = hardwareType.ToString();
}

View File

@@ -0,0 +1,9 @@
using HardwareMonitorStatusWindow.Service;
namespace HardwareMonitorStatusWindow.StatusWindow.SettingsWindow;
public class SensorTypeItem(SensorType sensorType)
{
public SensorType Value { get; set; } = sensorType;
public string Name { get; set; } = sensorType.ToString();
}

View File

@@ -0,0 +1,106 @@
<Window x:Class="HardwareMonitorStatusWindow.StatusWindow.SettingsWindow.SensorWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hardwareMonitorStatusWindow="clr-namespace:HardwareMonitorStatusWindow.StatusWindow"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DataContext="{d:DesignInstance Type=hardwareMonitorStatusWindow:SensorEntry}"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:windows="clr-namespace:ChrisKaczor.Wpf.Windows;assembly=ChrisKaczor.Wpf.Windows.CategoryWindow"
mc:Ignorable="d"
Title="SensorWindow"
ResizeMode="NoResize"
SizeToContent="Height"
Width="450"
WindowStartupLocation="CenterOwner"
FocusManager.FocusedElement="{Binding ElementName=LabelTextBox}">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary
Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.FlatButton.xaml" />
<ResourceDictionary
Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/light.cobalt.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid Margin="6">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Margin="0,4"
windows:Spacing.Vertical="8">
<TextBox Name="LabelTextBox"
mah:TextBoxHelper.UseFloatingWatermark="True"
mah:TextBoxHelper.Watermark="{x:Static hardwareMonitorStatusWindow:Resources.LabelColumnHeader}"
mah:TextBoxHelper.SelectAllOnFocus="True"
Text="{Binding Path=Label, UpdateSourceTrigger=Explicit, ValidatesOnExceptions=True}" />
<ComboBox Name="HardwareTypeComboBox"
SelectedValuePath="Value"
DisplayMemberPath="Name"
VirtualizingPanel.IsVirtualizing="False"
mah:TextBoxHelper.UseFloatingWatermark="True"
mah:TextBoxHelper.Watermark="{x:Static hardwareMonitorStatusWindow:Resources.HardwareTypeWatermark}"
SelectionChanged="HardwareTypeComboBox_SelectionChanged">
</ComboBox>
<ComboBox Name="HardwareComboBox"
DisplayMemberPath="Name"
VirtualizingPanel.IsVirtualizing="False"
mah:TextBoxHelper.UseFloatingWatermark="True"
mah:TextBoxHelper.Watermark="{x:Static hardwareMonitorStatusWindow:Resources.HardwareWatermark}"
SelectionChanged="HardwareComboBox_SelectionChanged">
</ComboBox>
<ComboBox Name="SensorTypeComboBox"
SelectedValuePath="Value"
DisplayMemberPath="Name"
VirtualizingPanel.IsVirtualizing="False"
mah:TextBoxHelper.UseFloatingWatermark="True"
mah:TextBoxHelper.Watermark="{x:Static hardwareMonitorStatusWindow:Resources.SensorTypeWatermark}"
SelectionChanged="SensorTypeComboBox_SelectionChanged">
</ComboBox>
<ComboBox Name="SensorComboBox"
DisplayMemberPath="Name"
VirtualizingPanel.IsVirtualizing="False"
mah:TextBoxHelper.UseFloatingWatermark="True"
mah:TextBoxHelper.Watermark="{x:Static hardwareMonitorStatusWindow:Resources.SensorWatermark}">
</ComboBox>
</StackPanel>
<StackPanel Grid.Column="0"
Grid.Row="1"
Orientation="Horizontal"
Margin="0,5,0,0"
HorizontalAlignment="Right">
<Button Content="{x:Static hardwareMonitorStatusWindow:Resources.OkayButton}"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Width="75"
Margin="0,0,5,0"
IsDefault="True"
Click="HandleOkayButtonClick">
<Button.Style>
<Style TargetType="Button"
BasedOn="{StaticResource {x:Type Button}}">
<Style.Triggers>
<DataTrigger Binding="{Binding Text.Length, ElementName=LabelTextBox}"
Value="0">
<Setter Property="IsEnabled"
Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<Button Content="{x:Static hardwareMonitorStatusWindow:Resources.CancelButton}"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Width="75"
IsCancel="True" />
</StackPanel>
</Grid>
</Window>

View File

@@ -0,0 +1,98 @@
using System.Linq;
using System.Windows;
using ChrisKaczor.Wpf.Validation;
using HardwareMonitorStatusWindow.Service;
namespace HardwareMonitorStatusWindow.StatusWindow.SettingsWindow;
public partial class SensorWindow
{
public SensorWindow()
{
InitializeComponent();
}
public bool? Display(SensorEntry sensorEntry, Window owner)
{
DataContext = sensorEntry;
Data.RefreshComputer();
HardwareTypeComboBox.ItemsSource = Data.ComputerHardware.Where(h => h.Sensors.Any()).DistinctBy(h => h.Type).Select(s => new HardwareTypeItem(s.Type)).OrderBy(s => s.Name);
var hardware = Data.ComputerHardware.FirstOrDefault(h => h.Identifier.ToString() == sensorEntry.HardwareId);
var sensor = hardware?.Sensors.FirstOrDefault(s => s.Identifier.ToString() == sensorEntry.SensorId);
HardwareTypeComboBox.SelectedValue = hardware?.Type;
HardwareComboBox.SelectedItem = hardware;
SensorTypeComboBox.SelectedValue = sensor?.Type;
SensorComboBox.SelectedItem = sensor;
Title = string.IsNullOrWhiteSpace(sensorEntry.Label) ? StatusWindow.Resources.SensorWindowAdd : StatusWindow.Resources.SensorWindowEdit;
Owner = owner;
return ShowDialog();
}
private void HandleOkayButtonClick(object sender, RoutedEventArgs e)
{
if (!this.IsValid())
return;
var sensorEntry = (SensorEntry)DataContext;
var hardware = (Hardware)HardwareComboBox.SelectedItem;
sensorEntry.HardwareId = hardware.Identifier;
var sensor = (Sensor)SensorComboBox.SelectedItem;
sensorEntry.SensorId = sensor.Identifier;
if (!Data.SensorEntries.Contains(sensorEntry))
Data.SensorEntries.Add(sensorEntry);
Data.Save();
DialogResult = true;
Close();
}
private void HardwareTypeComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (HardwareTypeComboBox.SelectedIndex == -1)
return;
var hardwareType = (HardwareTypeItem)HardwareTypeComboBox.SelectedItem;
HardwareComboBox.SelectedIndex = -1;
SensorTypeComboBox.SelectedIndex = -1;
SensorComboBox.SelectedIndex = -1;
HardwareComboBox.ItemsSource = Data.ComputerHardware.Where(h => h.Type == hardwareType.Value);
}
private void HardwareComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (HardwareComboBox.SelectedIndex == -1)
return;
var hardware = (Hardware)HardwareComboBox.SelectedItem;
SensorTypeComboBox.SelectedIndex = -1;
SensorComboBox.SelectedIndex = -1;
SensorTypeComboBox.ItemsSource = hardware.Sensors.DistinctBy(s => s.Type).Select(s => new SensorTypeItem(s.Type)).OrderBy(s => s.Name);
}
private void SensorTypeComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (SensorTypeComboBox.SelectedIndex == -1)
return;
var hardware = (Hardware)HardwareComboBox.SelectedItem;
var sensorType = (SensorTypeItem)SensorTypeComboBox.SelectedItem;
SensorComboBox.ItemsSource = hardware.Sensors.Where(s => s.Type == sensorType.Value);
}
}

View File

@@ -0,0 +1,21 @@
<windows:CategoryPanelBase x:Class="HardwareMonitorStatusWindow.StatusWindow.SettingsWindow.UpdateSettingsPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:windows="clr-namespace:ChrisKaczor.Wpf.Windows;assembly=ChrisKaczor.Wpf.Windows.CategoryWindow"
xmlns:window="clr-namespace:HardwareMonitorStatusWindow.StatusWindow"
mc:Ignorable="d"
d:DesignHeight="150"
d:DesignWidth="250">
<StackPanel windows:Spacing.Vertical="10">
<CheckBox Content="{x:Static window:Resources.checkVersionOnStartupCheckBox}"
Name="CheckVersionOnStartupCheckBox"
IsChecked="{Binding Source={x:Static window:Settings.Default}, Path=CheckVersionAtStartup}"
Click="OnSaveSettings" />
<Button Content="{x:Static window:Resources.checkVersionNowButton}"
IsEnabled="{Binding Source={x:Static window:UpdateCheck.IsInstalled}}"
HorizontalAlignment="Left"
Click="HandleCheckVersionNowButtonClick" />
</StackPanel>
</windows:CategoryPanelBase>

View File

@@ -0,0 +1,38 @@
using System.Windows;
using System.Windows.Input;
using HardwareMonitorStatusWindow.StatusWindow;
namespace HardwareMonitorStatusWindow.StatusWindow.SettingsWindow;
public partial class UpdateSettingsPanel
{
public UpdateSettingsPanel()
{
InitializeComponent();
}
public override string CategoryName => StatusWindow.Resources.optionCategoryUpdate;
private async void HandleCheckVersionNowButtonClick(object sender, RoutedEventArgs e)
{
var cursor = Cursor;
Cursor = Cursors.Wait;
await UpdateCheck.DisplayUpdateInformation(true);
Cursor = cursor;
}
private void OnSaveSettings(object sender, RoutedEventArgs e)
{
SaveSettings();
}
private void SaveSettings()
{
if (!HasLoaded) return;
Settings.Default.Save();
}
}

View File

@@ -0,0 +1,69 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0-windows7.0</TargetFramework>
<OutputType>WinExe</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Nullable>enable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<StartupObject>HardwareMonitorStatusWindow.StatusWindow.Program</StartupObject>
<ApplicationIcon>Resources\Application.ico</ApplicationIcon>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<RootNamespace>HardwareMonitorStatusWindow.StatusWindow</RootNamespace>
</PropertyGroup>
<ItemGroup>
<None Remove="Resources\Application.ico" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Application.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ChrisKaczor.Wpf.Application.StartWithWindows" Version="1.0.5" />
<PackageReference Include="ChrisKaczor.Wpf.Controls.Link" Version="1.0.4" />
<PackageReference Include="ChrisKaczor.Wpf.Validation" Version="1.0.4" />
<PackageReference Include="ChrisKaczor.Wpf.Windows.CategoryWindow" Version="1.0.2" />
<PackageReference Include="ChrisKaczor.Wpf.Windows.FloatingStatusWindow" Version="2.0.0.7" />
<PackageReference Include="gong-wpf-dragdrop" Version="4.0.0" />
<PackageReference Include="PipeMethodCalls" Version="4.0.3" />
<PackageReference Include="Serilog" Version="4.3.0" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
<PackageReference Include="Velopack" Version="0.0.1298" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Service\Service.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=settingswindow/@EntryIndexedValue">False</s:Boolean></wpf:ResourceDictionary>

View File

@@ -0,0 +1,50 @@
using System.Threading.Tasks;
using System.Windows;
using NuGet.Versioning;
using Serilog;
using Velopack;
using Velopack.Sources;
namespace HardwareMonitorStatusWindow.StatusWindow;
internal static class UpdateCheck
{
private static UpdateManager _updateManager;
public static UpdateManager UpdateManager => _updateManager ??= new UpdateManager(new GithubSource("https://gitea.kaczorzoo.net/ckaczor/HardwareMonitorStatusWindow", null, false));
public static string LocalVersion => (UpdateManager.CurrentVersion ?? new SemanticVersion(0, 0, 0)).ToString();
public static bool IsInstalled => UpdateManager.IsInstalled;
public static async Task DisplayUpdateInformation(bool showIfCurrent)
{
var newVersion = IsInstalled ? await UpdateManager.CheckForUpdatesAsync() : null;
if (newVersion != null)
{
var updateCheckTitle = string.Format(Resources.UpdateCheckTitle, Resources.ApplicationName);
var updateCheckMessage = string.Format(Resources.UpdateCheckNewVersion, newVersion.TargetFullRelease.Version);
if (MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
return;
Log.Logger.Information("Downloading update");
await UpdateManager.DownloadUpdatesAsync(newVersion);
Log.Logger.Information("Installing update");
UpdateManager.ApplyUpdatesAndRestart(newVersion);
}
else if (showIfCurrent)
{
var updateCheckTitle = string.Format(Resources.UpdateCheckTitle, Resources.ApplicationName);
var updateCheckMessage = string.Format(Resources.UpdateCheckCurrent, Resources.ApplicationName);
MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.OK, MessageBoxImage.Information);
}
}
}

View File

@@ -0,0 +1,235 @@
using ChrisKaczor.Wpf.Windows;
using ChrisKaczor.Wpf.Windows.FloatingStatusWindow;
using HardwareMonitorStatusWindow.Service;
using HardwareMonitorStatusWindow.StatusWindow.SettingsWindow;
using Microsoft.Win32.TaskScheduler;
using Serilog;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Threading;
using Task = System.Threading.Tasks.Task;
using Timer = System.Timers.Timer;
namespace HardwareMonitorStatusWindow.StatusWindow;
internal class WindowSource : IWindowSource, IDisposable
{
private readonly FloatingStatusWindow _floatingStatusWindow;
private readonly Timer _timer;
private readonly Dispatcher _dispatcher;
internal WindowSource()
{
try
{
using var taskService = new TaskService();
var existingTask = taskService.FindTask(HardwareMonitorService.ScheduledTaskName);
if (existingTask == null)
{
var assembly = Assembly.GetExecutingAssembly();
var path = Path.GetDirectoryName(assembly.Location);
if (path != null)
{
var fileName = Path.Combine(path, "Service.exe");
var startInfo = new ProcessStartInfo
{
FileName = fileName,
Arguments = "--install",
UseShellExecute = true,
Verb = "runas"
};
Process.Start(startInfo);
}
}
}
catch (Exception)
{
// Ignored
}
_floatingStatusWindow = new FloatingStatusWindow(this);
_floatingStatusWindow.SetText(Resources.Loading);
_dispatcher = Dispatcher.CurrentDispatcher;
_timer = new Timer(5000);
Task.Factory.StartNew(UpdateApp).ContinueWith(t => Start(t.Result.Result));
}
private async Task<bool> UpdateApp()
{
try
{
if (!UpdateCheck.IsInstalled)
return false;
if (!Settings.Default.CheckVersionAtStartup)
return false;
Log.Logger.Information("Checking for update");
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(Resources.CheckingForUpdate));
var newVersion = await UpdateCheck.UpdateManager.CheckForUpdatesAsync();
if (newVersion == null)
return false;
Log.Logger.Information("Downloading update");
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(Resources.DownloadingUpdate));
await UpdateCheck.UpdateManager.DownloadUpdatesAsync(newVersion);
Log.Logger.Information("Installing update");
await _dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(Resources.InstallingUpdate));
UpdateCheck.UpdateManager.ApplyUpdatesAndRestart(newVersion);
}
catch (Exception e)
{
Log.Logger.Error(e, nameof(UpdateApp));
}
return true;
}
private async Task Start(bool hasUpdate)
{
Log.Logger.Information("Start: hasUpdate={hasUpdate}", hasUpdate);
if (hasUpdate)
return;
Log.Logger.Information("Load");
await Load();
Log.Logger.Information("Starting timer");
_timer.Elapsed += HandleTimerElapsed;
_timer.AutoReset = false;
_timer.Enabled = true;
}
private static async Task Load()
{
await Data.LoadComputer();
Data.Load();
}
private void Save()
{
Data.Save();
}
private void HandleTimerElapsed(object? sender, ElapsedEventArgs e)
{
Refresh();
}
public void Dispose()
{
_timer.Enabled = false;
_timer.Dispose();
Data.CloseComputer();
_floatingStatusWindow.Save();
_floatingStatusWindow.Dispose();
}
public Guid Id => Guid.Parse("0DB9393F-2710-40A5-A27B-34568696C61A");
public string Name => Resources.ApplicationName;
public System.Drawing.Icon Icon => Resources.ApplicationIcon;
public bool HasSettingsMenu => true;
public bool HasAboutMenu => false;
public void ShowAbout()
{
}
public void ShowSettings()
{
var categoryPanels = new List<CategoryPanelBase>
{
new GeneralSettingsPanel(),
new HardwareSettingsPanel(),
new UpdateSettingsPanel(),
new AboutSettingsPanel()
};
var settingsWindow = new CategoryWindow(categoryPanels, Resources.SettingsTitle, Resources.CloseButtonText);
settingsWindow.ShowDialog();
Save();
}
public bool HasRefreshMenu => true;
public void Refresh()
{
using (var taskService = new TaskService())
{
var existingTask = taskService.FindTask(HardwareMonitorService.ScheduledTaskName);
if (existingTask == null)
{
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.ServiceNotInstalled));
return;
}
if (existingTask.State != TaskState.Running)
{
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.ServiceNotStarted));
return;
}
}
var text = new StringBuilder();
Data.RefreshComputer();
foreach (var sensorEntry in Data.SensorEntries)
{
if (text.Length > 0)
text.AppendLine();
text.Append($"{sensorEntry.Label}: {string.Format(sensorEntry.SensorValueFormat, sensorEntry.Sensor.Value)}");
}
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(text.ToString()));
_timer.Start();
}
public string WindowSettings
{
get => Settings.Default.WindowSettings;
set
{
Settings.Default.WindowSettings = value;
Settings.Default.Save();
}
}
}