commit 853e8eab0d6d9b593dc674020b3701911c866c51 Author: Chris Kaczor Date: Tue Jan 27 18:58:09 2026 -0500 Initial WIP commit diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml new file mode 100644 index 0000000..ca37e80 --- /dev/null +++ b/.gitea/workflows/main.yml @@ -0,0 +1,36 @@ +name: Deploy to Gitea Releases + +on: + push: + branches: + - main + + workflow_dispatch: + +jobs: + deploy-to-gitea-releases: + runs-on: ubuntu-latest + + container: + image: ghcr.io/catthehacker/ubuntu:dotnet-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Get next version + uses: reecetech/version-increment@2024.4.3 + id: version + with: + scheme: calver + + - name: Publish Application + run: dotnet publish HardwareMonitorStatusWindow.csproj -r win-x64 -c Debug -o publish + + - name: Create Velopack Release + run: | + export PATH="$PATH:/root/.dotnet/tools" + dotnet tool install -g vpk + vpk [win] download gitea --channel win-x64 --repoUrl https://gitea.kaczorzoo.net/ckaczor/HardwareMonitorStatusWindow + vpk [win] pack --channel win-x64 -u HardwareMonitorStatusWindow -v ${{ steps.version.outputs.version }} -p publish --packTitle "Hardware Monitor Status Window" --shortcuts StartMenuRoot --framework net10.0-x64-desktop + vpk [win] upload gitea --channel win-x64 --repoUrl https://gitea.kaczorzoo.net/ckaczor/HardwareMonitorStatusWindow --publish --releaseName "${{ steps.version.outputs.version }}" --token ${{ secrets.VPK_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a30d25 --- /dev/null +++ b/.gitignore @@ -0,0 +1,398 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# 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 +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# 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 +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml diff --git a/HardwareMonitorStatusWindow.sln.DotSettings b/HardwareMonitorStatusWindow.sln.DotSettings new file mode 100644 index 0000000..b347252 --- /dev/null +++ b/HardwareMonitorStatusWindow.sln.DotSettings @@ -0,0 +1,3 @@ + + True + True \ No newline at end of file diff --git a/HardwareMonitorStatusWindow.slnx b/HardwareMonitorStatusWindow.slnx new file mode 100644 index 0000000..a64e237 --- /dev/null +++ b/HardwareMonitorStatusWindow.slnx @@ -0,0 +1,7 @@ + + + + + + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..bcadd84 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# HardwareMonitorStatusWindow \ No newline at end of file diff --git a/Service/Hardware.cs b/Service/Hardware.cs new file mode 100644 index 0000000..a2c8130 --- /dev/null +++ b/Service/Hardware.cs @@ -0,0 +1,41 @@ +namespace HardwareMonitorStatusWindow.Service; + +public class Hardware +{ + public required HardwareType Type { get; set; } + public required string Identifier { get; set; } + public required string Name { get; set; } + public required IEnumerable Sensors { get; set; } + + internal static Hardware Create(LibreHardwareMonitor.Hardware.IHardware hardware) + { + return new Hardware + { + Type = MapHardwareType(hardware.HardwareType), + Name = hardware.Name, + Identifier = hardware.Identifier.ToString(), + Sensors = hardware.Sensors.Select(Sensor.Create) + }; + } + + private static HardwareType MapHardwareType(LibreHardwareMonitor.Hardware.HardwareType hardwareType) + { + return hardwareType switch + { + LibreHardwareMonitor.Hardware.HardwareType.Motherboard => HardwareType.Motherboard, + LibreHardwareMonitor.Hardware.HardwareType.SuperIO => HardwareType.SuperIo, + LibreHardwareMonitor.Hardware.HardwareType.Cpu => HardwareType.Cpu, + LibreHardwareMonitor.Hardware.HardwareType.Memory => HardwareType.Memory, + LibreHardwareMonitor.Hardware.HardwareType.GpuNvidia => HardwareType.GpuNvidia, + LibreHardwareMonitor.Hardware.HardwareType.GpuAmd => HardwareType.GpuAmd, + LibreHardwareMonitor.Hardware.HardwareType.GpuIntel => HardwareType.GpuIntel, + LibreHardwareMonitor.Hardware.HardwareType.Storage => HardwareType.Storage, + LibreHardwareMonitor.Hardware.HardwareType.Network => HardwareType.Network, + LibreHardwareMonitor.Hardware.HardwareType.Cooler => HardwareType.Cooler, + LibreHardwareMonitor.Hardware.HardwareType.EmbeddedController => HardwareType.EmbeddedController, + LibreHardwareMonitor.Hardware.HardwareType.Psu => HardwareType.Psu, + LibreHardwareMonitor.Hardware.HardwareType.Battery => HardwareType.Battery, + _ => throw new ArgumentOutOfRangeException(nameof(hardwareType), hardwareType, null) + }; + } +} \ No newline at end of file diff --git a/Service/HardwareMonitorService.cs b/Service/HardwareMonitorService.cs new file mode 100644 index 0000000..6467176 --- /dev/null +++ b/Service/HardwareMonitorService.cs @@ -0,0 +1,41 @@ +using LibreHardwareMonitor.Hardware; + +namespace HardwareMonitorStatusWindow.Service; + +public class HardwareMonitorService : IHardwareMonitorService +{ + public const string ScheduledTaskName = "HardwareMonitorService"; + public const string PipeName = "HardwareMonitorService"; + + private static readonly Computer Computer; + private static readonly HardwareUpdateVisitor HardwareUpdateVisitor; + + static HardwareMonitorService() + { + Computer = new Computer + { + IsCpuEnabled = true, + IsGpuEnabled = true, + IsMemoryEnabled = true, + IsMotherboardEnabled = true, + IsControllerEnabled = true, + IsNetworkEnabled = true, + IsStorageEnabled = true, + IsBatteryEnabled = true, + IsPsuEnabled = true + }; + + Computer.Open(); + + HardwareUpdateVisitor = new HardwareUpdateVisitor(); + } + + public IEnumerable GetHardware() + { + Computer.Accept(HardwareUpdateVisitor); + + var hardwareEntries = Computer.Hardware.Select(Hardware.Create); + + return hardwareEntries; + } +} \ No newline at end of file diff --git a/Service/HardwarePipeSerializer.cs b/Service/HardwarePipeSerializer.cs new file mode 100644 index 0000000..b21840d --- /dev/null +++ b/Service/HardwarePipeSerializer.cs @@ -0,0 +1,26 @@ +using PipeMethodCalls; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace HardwareMonitorStatusWindow.Service; + +public class HardwarePipeSerializer : IPipeSerializer +{ + private static readonly JsonSerializerOptions JsonSerializerOptions = new() + { + NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals + }; + + public object? Deserialize(byte[] data, Type type) + { + return JsonSerializer.Deserialize(data, type, JsonSerializerOptions); + } + + public byte[] Serialize(object o) + { + using var memoryStream = new MemoryStream(); + using var utf8JsonWriter = new Utf8JsonWriter(memoryStream); + JsonSerializer.Serialize(utf8JsonWriter, o, JsonSerializerOptions); + return memoryStream.ToArray(); + } +} \ No newline at end of file diff --git a/Service/HardwareType.cs b/Service/HardwareType.cs new file mode 100644 index 0000000..55d294e --- /dev/null +++ b/Service/HardwareType.cs @@ -0,0 +1,18 @@ +namespace HardwareMonitorStatusWindow.Service; + +public enum HardwareType +{ + Motherboard, + SuperIo, + Cpu, + Memory, + GpuNvidia, + GpuAmd, + GpuIntel, + Storage, + Network, + Cooler, + EmbeddedController, + Psu, + Battery, +} \ No newline at end of file diff --git a/Service/HardwareUpdateVisitor.cs b/Service/HardwareUpdateVisitor.cs new file mode 100644 index 0000000..42edbbe --- /dev/null +++ b/Service/HardwareUpdateVisitor.cs @@ -0,0 +1,25 @@ +using LibreHardwareMonitor.Hardware; + +namespace HardwareMonitorStatusWindow.Service; + +internal class HardwareUpdateVisitor : IVisitor +{ + public void VisitComputer(IComputer computer) + { + computer.Traverse(this); + } + + public void VisitHardware(IHardware hardware) + { + hardware.Update(); + foreach (var subHardware in hardware.SubHardware) subHardware.Accept(this); + } + + public void VisitSensor(ISensor sensor) + { + } + + public void VisitParameter(IParameter parameter) + { + } +} \ No newline at end of file diff --git a/Service/IHardwareMonitorService.cs b/Service/IHardwareMonitorService.cs new file mode 100644 index 0000000..a4a4dda --- /dev/null +++ b/Service/IHardwareMonitorService.cs @@ -0,0 +1,6 @@ +namespace HardwareMonitorStatusWindow.Service; + +public interface IHardwareMonitorService +{ + IEnumerable GetHardware(); +} \ No newline at end of file diff --git a/Service/Program.cs b/Service/Program.cs new file mode 100644 index 0000000..7f14d7d --- /dev/null +++ b/Service/Program.cs @@ -0,0 +1,111 @@ +using System.IO.Pipes; +using System.Security.AccessControl; +using System.Security.Principal; +using Microsoft.Win32.TaskScheduler; +using PipeMethodCalls; +using Serilog; +using Task = System.Threading.Tasks.Task; + +namespace HardwareMonitorStatusWindow.Service; + +internal class Program +{ + private static async Task Main(string[] args) + { + Log.Logger = new LoggerConfiguration().WriteTo.File("log.txt").CreateLogger(); + + Log.Logger.Information("Start"); + + if (args.Contains("--install", StringComparer.InvariantCultureIgnoreCase)) + { + Log.Logger.Information("Starting install..."); + + try + { + using var taskService = new TaskService(); + + var existingTask = taskService.FindTask(HardwareMonitorService.ScheduledTaskName); + + if (existingTask == null) + { + var taskDefinition = taskService.NewTask(); + taskDefinition.Principal.RunLevel = TaskRunLevel.Highest; + + taskDefinition.Triggers.Add(new LogonTrigger { Delay = TimeSpan.FromSeconds(30) }); + taskDefinition.Actions.Add(new ExecAction(Environment.ProcessPath!)); + taskDefinition.Settings.RestartInterval = TimeSpan.FromMinutes(1); + taskDefinition.Settings.RestartCount = 3; + taskDefinition.Settings.StartWhenAvailable = true; + taskDefinition.Settings.ExecutionTimeLimit = TimeSpan.Zero; + taskDefinition.Settings.StopIfGoingOnBatteries = false; + taskDefinition.Settings.DisallowStartIfOnBatteries = false; + + taskService.RootFolder.RegisterTaskDefinition(HardwareMonitorService.ScheduledTaskName, taskDefinition); + } + + existingTask = taskService.FindTask(HardwareMonitorService.ScheduledTaskName); + existingTask.Run(); + } + catch (Exception exception) + { + Log.Logger.Error(exception, "Install"); + } + + Log.Logger.Information("Install complete"); + } + else if (args.Contains("--uninstall", StringComparer.InvariantCultureIgnoreCase)) + { + Log.Logger.Information("Starting uninstall..."); + + try + { + using var taskService = new TaskService(); + + var existingTask = taskService.FindTask(HardwareMonitorService.ScheduledTaskName); + + existingTask?.Stop(); + + taskService.RootFolder.DeleteTask(HardwareMonitorService.ScheduledTaskName, false); + } + catch (Exception exception) + { + Log.Logger.Error(exception, "Uninstall"); + } + + Log.Logger.Information("Uninstall complete"); + } + else + { + Log.Logger.Information("Starting"); + + try + { + while (true) + { + var pipeSecurity = new PipeSecurity(); + pipeSecurity.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow)); + + var pipeWithSecurity = NamedPipeServerStreamAcl.Create(HardwareMonitorService.PipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, 0, pipeSecurity); + + var pipeServer = new PipeServer(new HardwarePipeSerializer(), pipeWithSecurity, () => new HardwareMonitorService()); + //var pipeServer = new PipeServer( + // new HardwarePipeSerializer(), + // HardwareMonitorService.PipeName, + // () => new HardwareMonitorService()); + + await pipeServer.WaitForConnectionAsync().ConfigureAwait(false); + + await pipeServer.WaitForRemotePipeCloseAsync().ConfigureAwait(false); + + pipeServer.Dispose(); + } + } + catch (Exception exception) + { + Log.Logger.Error(exception, ""); + } + } + + Log.Logger.Information("Closing"); + } +} \ No newline at end of file diff --git a/Service/Sensor.cs b/Service/Sensor.cs new file mode 100644 index 0000000..930e579 --- /dev/null +++ b/Service/Sensor.cs @@ -0,0 +1,49 @@ +namespace HardwareMonitorStatusWindow.Service; + +public class Sensor +{ + public required SensorType Type { get; set; } + public required string Identifier { get; set; } + public required string Name { get; set; } + public required float? Value { get; set; } + + internal static Sensor Create(LibreHardwareMonitor.Hardware.ISensor sensor) + { + return new Sensor + { + Type = MapSensorType(sensor.SensorType), + Name = sensor.Name, + Identifier = sensor.Identifier.ToString(), + Value = sensor.Value + }; + } + + private static SensorType MapSensorType(LibreHardwareMonitor.Hardware.SensorType sensorType) + { + return sensorType switch + { + LibreHardwareMonitor.Hardware.SensorType.Voltage => SensorType.Voltage, + LibreHardwareMonitor.Hardware.SensorType.Current => SensorType.Current, + LibreHardwareMonitor.Hardware.SensorType.Power => SensorType.Power, + LibreHardwareMonitor.Hardware.SensorType.Clock => SensorType.Clock, + LibreHardwareMonitor.Hardware.SensorType.Temperature => SensorType.Temperature, + LibreHardwareMonitor.Hardware.SensorType.Load => SensorType.Load, + LibreHardwareMonitor.Hardware.SensorType.Frequency => SensorType.Frequency, + LibreHardwareMonitor.Hardware.SensorType.Fan => SensorType.Fan, + LibreHardwareMonitor.Hardware.SensorType.Flow => SensorType.Flow, + LibreHardwareMonitor.Hardware.SensorType.Control => SensorType.Control, + LibreHardwareMonitor.Hardware.SensorType.Level => SensorType.Level, + LibreHardwareMonitor.Hardware.SensorType.Factor => SensorType.Factor, + LibreHardwareMonitor.Hardware.SensorType.Data => SensorType.Data, + LibreHardwareMonitor.Hardware.SensorType.SmallData => SensorType.SmallData, + LibreHardwareMonitor.Hardware.SensorType.Throughput => SensorType.Throughput, + LibreHardwareMonitor.Hardware.SensorType.TimeSpan => SensorType.TimeSpan, + LibreHardwareMonitor.Hardware.SensorType.Timing => SensorType.Timing, + LibreHardwareMonitor.Hardware.SensorType.Energy => SensorType.Energy, + LibreHardwareMonitor.Hardware.SensorType.Noise => SensorType.Noise, + LibreHardwareMonitor.Hardware.SensorType.Conductivity => SensorType.Conductivity, + LibreHardwareMonitor.Hardware.SensorType.Humidity => SensorType.Humidity, + _ => throw new ArgumentOutOfRangeException(nameof(sensorType), sensorType, null) + }; + } +} \ No newline at end of file diff --git a/Service/SensorType.cs b/Service/SensorType.cs new file mode 100644 index 0000000..9cc6c08 --- /dev/null +++ b/Service/SensorType.cs @@ -0,0 +1,26 @@ +namespace HardwareMonitorStatusWindow.Service; + +public enum SensorType +{ + Voltage, + Current, + Power, + Clock, + Temperature, + Load, + Frequency, + Fan, + Flow, + Control, + Level, + Factor, + Data, + SmallData, + Throughput, + TimeSpan, + Timing, + Energy, + Noise, + Conductivity, + Humidity, +} \ No newline at end of file diff --git a/Service/Service.csproj b/Service/Service.csproj new file mode 100644 index 0000000..42be8f8 --- /dev/null +++ b/Service/Service.csproj @@ -0,0 +1,20 @@ + + + + WinExe + net10.0-windows + enable + enable + HardwareMonitorStatusWindow.Service + app.manifest + + + + + + + + + + + diff --git a/Service/app.manifest b/Service/app.manifest new file mode 100644 index 0000000..4d08f0c --- /dev/null +++ b/Service/app.manifest @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StatusWindow/App.config b/StatusWindow/App.config new file mode 100644 index 0000000..7804f4a --- /dev/null +++ b/StatusWindow/App.config @@ -0,0 +1,24 @@ + + + + +
+ + + + + + + + + True + + + True + + + [] + + + + \ No newline at end of file diff --git a/StatusWindow/App.xaml b/StatusWindow/App.xaml new file mode 100644 index 0000000..bf08da7 --- /dev/null +++ b/StatusWindow/App.xaml @@ -0,0 +1,7 @@ + + + + + diff --git a/StatusWindow/App.xaml.cs b/StatusWindow/App.xaml.cs new file mode 100644 index 0000000..503bf5e --- /dev/null +++ b/StatusWindow/App.xaml.cs @@ -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 _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); + } +} \ No newline at end of file diff --git a/StatusWindow/AssemblyInfo.cs b/StatusWindow/AssemblyInfo.cs new file mode 100644 index 0000000..1618e8e --- /dev/null +++ b/StatusWindow/AssemblyInfo.cs @@ -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")] \ No newline at end of file diff --git a/StatusWindow/Data.cs b/StatusWindow/Data.cs new file mode 100644 index 0000000..3848542 --- /dev/null +++ b/StatusWindow/Data.cs @@ -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 _pipeClient; + private static IEnumerable _hardware; + + internal static ObservableCollection SensorEntries { get; set; } + + internal static async Task LoadComputer() + { + try + { + _pipeClient = new PipeClient(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 ComputerHardware => _hardware.ToList(); + + internal static void Load() + { + SensorEntries = JsonSerializer.Deserialize>(Settings.Default.Sensors); + } + + internal static void Save() + { + Settings.Default.Sensors = JsonSerializer.Serialize(SensorEntries); + Settings.Default.Save(); + } +} \ No newline at end of file diff --git a/StatusWindow/DataErrorDictionary.cs b/StatusWindow/DataErrorDictionary.cs new file mode 100644 index 0000000..ed6f4d4 --- /dev/null +++ b/StatusWindow/DataErrorDictionary.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; + +namespace HardwareMonitorStatusWindow.StatusWindow; + +internal class DataErrorDictionary : Dictionary> +{ + public event EventHandler 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); + } +} \ No newline at end of file diff --git a/StatusWindow/Program.cs b/StatusWindow/Program.cs new file mode 100644 index 0000000..54e75ed --- /dev/null +++ b/StatusWindow/Program.cs @@ -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"); + } +} \ No newline at end of file diff --git a/StatusWindow/Resources.Designer.cs b/StatusWindow/Resources.Designer.cs new file mode 100644 index 0000000..0b49e09 --- /dev/null +++ b/StatusWindow/Resources.Designer.cs @@ -0,0 +1,446 @@ +//------------------------------------------------------------------------------ +// +// 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. +// +//------------------------------------------------------------------------------ + +namespace HardwareMonitorStatusWindow.StatusWindow { + 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", "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() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [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; + } + } + + /// + /// 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)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Add. + /// + public static string AddSensorLink { + get { + return ResourceManager.GetString("AddSensorLink", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Add Sensor. + /// + public static string AddSensorToolTip { + get { + return ResourceManager.GetString("AddSensorToolTip", resourceCulture); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + public static System.Drawing.Icon ApplicationIcon { + get { + object obj = ResourceManager.GetObject("ApplicationIcon", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + + /// + /// Looks up a localized string similar to Hardware Monitor Status Window. + /// + public static string ApplicationName { + get { + return ResourceManager.GetString("ApplicationName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cancel. + /// + public static string CancelButton { + get { + return ResourceManager.GetString("CancelButton", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Checking for update.... + /// + public static string CheckingForUpdate { + get { + return ResourceManager.GetString("CheckingForUpdate", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to _Check for Update. + /// + public static string CheckUpdate { + get { + return ResourceManager.GetString("CheckUpdate", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Check _Now. + /// + public static string checkVersionNowButton { + get { + return ResourceManager.GetString("checkVersionNowButton", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to _Check for a new version on startup. + /// + public static string checkVersionOnStartupCheckBox { + get { + return ResourceManager.GetString("checkVersionOnStartupCheckBox", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Close. + /// + public static string CloseButtonText { + get { + return ResourceManager.GetString("CloseButtonText", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Are you sure you want to delete the selected sensors?. + /// + public static string ConfirmDeleteSensors { + get { + return ResourceManager.GetString("ConfirmDeleteSensors", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Confirm Delete. + /// + public static string ConfirmDeleteTitle { + get { + return ResourceManager.GetString("ConfirmDeleteTitle", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Delete. + /// + public static string DeleteSensorLink { + get { + return ResourceManager.GetString("DeleteSensorLink", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Delete Sensor. + /// + public static string DeleteSensorToolTip { + get { + return ResourceManager.GetString("DeleteSensorToolTip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Downloading update.... + /// + public static string DownloadingUpdate { + get { + return ResourceManager.GetString("DownloadingUpdate", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Edit. + /// + public static string EditSensorLink { + get { + return ResourceManager.GetString("EditSensorLink", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Edit Sensor. + /// + public static string EditSensorToolTip { + get { + return ResourceManager.GetString("EditSensorToolTip", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Hardware. + /// + public static string HardwareColumnHeader { + get { + return ResourceManager.GetString("HardwareColumnHeader", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Hardware Type. + /// + public static string HardwareTypeWatermark { + get { + return ResourceManager.GetString("HardwareTypeWatermark", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Hardware. + /// + public static string HardwareWatermark { + get { + return ResourceManager.GetString("HardwareWatermark", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Installing update.... + /// + public static string InstallingUpdate { + get { + return ResourceManager.GetString("InstallingUpdate", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Label. + /// + public static string LabelColumnHeader { + get { + return ResourceManager.GetString("LabelColumnHeader", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Loading.... + /// + public static string Loading { + get { + return ResourceManager.GetString("Loading", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to OK. + /// + public static string OkayButton { + get { + return ResourceManager.GetString("OkayButton", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to About. + /// + public static string optionCategoryAbout { + get { + return ResourceManager.GetString("optionCategoryAbout", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to General. + /// + public static string optionCategoryGeneral { + get { + return ResourceManager.GetString("optionCategoryGeneral", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Hardware. + /// + public static string optionCategoryHardware { + get { + return ResourceManager.GetString("optionCategoryHardware", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sensors. + /// + public static string optionCategorySensors { + get { + return ResourceManager.GetString("optionCategorySensors", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Update. + /// + public static string optionCategoryUpdate { + get { + return ResourceManager.GetString("optionCategoryUpdate", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sensor. + /// + public static string SensorColumnHeader { + get { + return ResourceManager.GetString("SensorColumnHeader", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sensor Type. + /// + public static string SensorTypeWatermark { + get { + return ResourceManager.GetString("SensorTypeWatermark", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sensor. + /// + public static string SensorWatermark { + get { + return ResourceManager.GetString("SensorWatermark", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Add Sensor. + /// + public static string SensorWindowAdd { + get { + return ResourceManager.GetString("SensorWindowAdd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Edit Sensor. + /// + public static string SensorWindowEdit { + get { + return ResourceManager.GetString("SensorWindowEdit", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Service not installed - restart application. + /// + public static string ServiceNotInstalled { + get { + return ResourceManager.GetString("ServiceNotInstalled", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Waiting for service to start.... + /// + public static string ServiceNotStarted { + get { + return ResourceManager.GetString("ServiceNotStarted", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Settings. + /// + public static string SettingsTitle { + get { + return ResourceManager.GetString("SettingsTitle", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to _Start when Windows starts. + /// + public static string startWithWindowsCheckBox { + get { + return ResourceManager.GetString("startWithWindowsCheckBox", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You are already running the most recent version. + /// + ///No updates are available at this time.. + /// + public static string UpdateCheckCurrent { + get { + return ResourceManager.GetString("UpdateCheckCurrent", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Version {0} is now available. + /// + ///Would you like to download and install it now?. + /// + public static string UpdateCheckNewVersion { + get { + return ResourceManager.GetString("UpdateCheckNewVersion", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} Update. + /// + public static string UpdateCheckTitle { + get { + return ResourceManager.GetString("UpdateCheckTitle", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Version {0}. + /// + public static string Version { + get { + return ResourceManager.GetString("Version", resourceCulture); + } + } + } +} diff --git a/StatusWindow/Resources.resx b/StatusWindow/Resources.resx new file mode 100644 index 0000000..51acf95 --- /dev/null +++ b/StatusWindow/Resources.resx @@ -0,0 +1,251 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + Hardware Monitor Status Window + + + About + + + _Check for Update + + + _Start when Windows starts + + + General + + + Settings + + + Close + + + Version {0} + + + Update + + + _Check for a new version on startup + + + Check _Now + + + {0} Update + + + You are already running the most recent version. + +No updates are available at this time. + + + Version {0} is now available. + +Would you like to download and install it now? + + + Loading... + + + Checking for update... + + + Downloading update... + + + Installing update... + + + Confirm Delete + + + OK + + + Cancel + + + Hardware + + + Edit + + + Delete + + + Add Sensor + + + Edit Sensor + + + Delete Sensor + + + Sensors + + + Label + + + Sensor + + + Add + + + Add Sensor + + + Edit Sensor + + + Are you sure you want to delete the selected sensors? + + + Hardware + + + Sensor + + + Sensor Type + + + Hardware + + + Hardware Type + + + + Resources\Application.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + Service not installed - restart application + + + Waiting for service to start... + + \ No newline at end of file diff --git a/StatusWindow/Resources/Application.ico b/StatusWindow/Resources/Application.ico new file mode 100644 index 0000000..b7d7601 Binary files /dev/null and b/StatusWindow/Resources/Application.ico differ diff --git a/StatusWindow/SensorEntry.cs b/StatusWindow/SensorEntry.cs new file mode 100644 index 0000000..22b9ab3 --- /dev/null +++ b/StatusWindow/SensorEntry.cs @@ -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 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(ref T field, T value, [CallerMemberName] string propertyName = null) + { + if (EqualityComparer.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 + }; + } + } +} \ No newline at end of file diff --git a/StatusWindow/Settings.Designer.cs b/StatusWindow/Settings.Designer.cs new file mode 100644 index 0000000..1753c61 --- /dev/null +++ b/StatusWindow/Settings.Designer.cs @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// +// 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. +// +//------------------------------------------------------------------------------ + +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; + } + } + } +} diff --git a/StatusWindow/Settings.settings b/StatusWindow/Settings.settings new file mode 100644 index 0000000..5b4ce4d --- /dev/null +++ b/StatusWindow/Settings.settings @@ -0,0 +1,18 @@ + + + + + + + + + True + + + True + + + [] + + + \ No newline at end of file diff --git a/StatusWindow/SettingsWindow/AboutSettingsPanel.xaml b/StatusWindow/SettingsWindow/AboutSettingsPanel.xaml new file mode 100644 index 0000000..a8b9e48 --- /dev/null +++ b/StatusWindow/SettingsWindow/AboutSettingsPanel.xaml @@ -0,0 +1,20 @@ + + + + + + + + + \ No newline at end of file diff --git a/StatusWindow/SettingsWindow/AboutSettingsPanel.xaml.cs b/StatusWindow/SettingsWindow/AboutSettingsPanel.xaml.cs new file mode 100644 index 0000000..aae025c --- /dev/null +++ b/StatusWindow/SettingsWindow/AboutSettingsPanel.xaml.cs @@ -0,0 +1,12 @@ +namespace HardwareMonitorStatusWindow.StatusWindow.SettingsWindow +{ + public partial class AboutSettingsPanel + { + public AboutSettingsPanel() + { + InitializeComponent(); + } + + public override string CategoryName => StatusWindow.Resources.optionCategoryAbout; + } +} \ No newline at end of file diff --git a/StatusWindow/SettingsWindow/GeneralSettingsPanel.xaml b/StatusWindow/SettingsWindow/GeneralSettingsPanel.xaml new file mode 100644 index 0000000..3f91b9d --- /dev/null +++ b/StatusWindow/SettingsWindow/GeneralSettingsPanel.xaml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/StatusWindow/SettingsWindow/GeneralSettingsPanel.xaml.cs b/StatusWindow/SettingsWindow/GeneralSettingsPanel.xaml.cs new file mode 100644 index 0000000..4667be8 --- /dev/null +++ b/StatusWindow/SettingsWindow/GeneralSettingsPanel.xaml.cs @@ -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); + } +} \ No newline at end of file diff --git a/StatusWindow/SettingsWindow/HardwareSettingsPanel.xaml b/StatusWindow/SettingsWindow/HardwareSettingsPanel.xaml new file mode 100644 index 0000000..dfe9596 --- /dev/null +++ b/StatusWindow/SettingsWindow/HardwareSettingsPanel.xaml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StatusWindow/SettingsWindow/HardwareSettingsPanel.xaml.cs b/StatusWindow/SettingsWindow/HardwareSettingsPanel.xaml.cs new file mode 100644 index 0000000..d5ea377 --- /dev/null +++ b/StatusWindow/SettingsWindow/HardwareSettingsPanel.xaml.cs @@ -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(); + } +} \ No newline at end of file diff --git a/StatusWindow/SettingsWindow/HardwareTypeItem.cs b/StatusWindow/SettingsWindow/HardwareTypeItem.cs new file mode 100644 index 0000000..aa6961c --- /dev/null +++ b/StatusWindow/SettingsWindow/HardwareTypeItem.cs @@ -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(); +} \ No newline at end of file diff --git a/StatusWindow/SettingsWindow/SensorTypeItem.cs b/StatusWindow/SettingsWindow/SensorTypeItem.cs new file mode 100644 index 0000000..7c83cf4 --- /dev/null +++ b/StatusWindow/SettingsWindow/SensorTypeItem.cs @@ -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(); +} \ No newline at end of file diff --git a/StatusWindow/SettingsWindow/SensorWindow.xaml b/StatusWindow/SettingsWindow/SensorWindow.xaml new file mode 100644 index 0000000..d696f40 --- /dev/null +++ b/StatusWindow/SettingsWindow/SensorWindow.xaml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +