diff --git a/Directory.Build.props b/Directory.Build.props index 32c6f3b..381a9a2 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,5 +2,6 @@ 0.9.6 LibreHardwareMonitor + x64 diff --git a/LibreHardwareMonitor.Windows.WinUI/LibreHardwareMonitor.Windows.WinUI.csproj b/LibreHardwareMonitor.Windows.WinUI/LibreHardwareMonitor.Windows.WinUI.csproj index 2368dd9..ead087e 100644 --- a/LibreHardwareMonitor.Windows.WinUI/LibreHardwareMonitor.Windows.WinUI.csproj +++ b/LibreHardwareMonitor.Windows.WinUI/LibreHardwareMonitor.Windows.WinUI.csproj @@ -5,6 +5,7 @@ 10.0.19041.0 x64;x86;ARM64 win-x64;win-x86;win-arm64 + win-x64 LibreHardwareMonitor.Windows.WinUI Libre Hardware Monitor LibreHardwareMonitor.Windows.WinUI diff --git a/LibreHardwareMonitor.Windows.WinUI/MainWindow.cs b/LibreHardwareMonitor.Windows.WinUI/MainWindow.cs index bc326d2..c5d7b5e 100644 --- a/LibreHardwareMonitor.Windows.WinUI/MainWindow.cs +++ b/LibreHardwareMonitor.Windows.WinUI/MainWindow.cs @@ -581,8 +581,8 @@ public sealed partial class MainWindow : Window plotCheck.Unchecked += (_, _) => QueuePlotSeriesRefresh(); sensorCell.Children.Add(plotCheck); - FontIcon icon = new() { FontSize = 14 }; - Bind(icon, FontIcon.GlyphProperty, item, nameof(SensorTreeItemViewModel.IconGlyph)); + Image icon = new() { Width = 16, Height = 16 }; + icon.Source = SensorTypeDisplay.GetImageByFilename(item.IconImageName); sensorCell.Children.Add(icon); TextBlock name = new() { TextTrimming = TextTrimming.CharacterEllipsis }; diff --git a/LibreHardwareMonitor.Windows.WinUI/SensorGadgetWindow.cs b/LibreHardwareMonitor.Windows.WinUI/SensorGadgetWindow.cs index 2936591..5c49749 100644 --- a/LibreHardwareMonitor.Windows.WinUI/SensorGadgetWindow.cs +++ b/LibreHardwareMonitor.Windows.WinUI/SensorGadgetWindow.cs @@ -8,6 +8,7 @@ using System.Linq; using LibreHardwareMonitor.Hardware; using LibreHardwareMonitor.Windows.WinUI.Services; using LibreHardwareMonitor.Windows.WinUI.ViewModels; +using LibreHardwareMonitor.Windows.WinUI.Utilities; using Microsoft.UI; using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; @@ -111,8 +112,8 @@ public sealed class SensorGadgetWindow : Window }; StackPanel namePanel = new() { Orientation = Orientation.Horizontal, Spacing = 6 }; - FontIcon icon = new() { FontSize = 12 }; - Bind(icon, FontIcon.GlyphProperty, item, nameof(SensorTreeItemViewModel.IconGlyph)); + Image icon = new() { Width = 16, Height = 16 }; + icon.Source = SensorTypeDisplay.GetImageByFilename(item.IconImageName); namePanel.Children.Add(icon); TextBlock name = new() { TextTrimming = TextTrimming.CharacterEllipsis }; diff --git a/LibreHardwareMonitor.Windows.WinUI/Utilities/SensorTypeDisplay.cs b/LibreHardwareMonitor.Windows.WinUI/Utilities/SensorTypeDisplay.cs index e76b682..50e454b 100644 --- a/LibreHardwareMonitor.Windows.WinUI/Utilities/SensorTypeDisplay.cs +++ b/LibreHardwareMonitor.Windows.WinUI/Utilities/SensorTypeDisplay.cs @@ -2,12 +2,20 @@ // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // Copyright (C) LibreHardwareMonitor and Contributors. +using System; +using System.Collections.Generic; +using System.IO; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Media.Imaging; +using Windows.Storage.Streams; using LibreHardwareMonitor.Hardware; namespace LibreHardwareMonitor.Windows.WinUI.Utilities; public static class SensorTypeDisplay { + private static readonly Dictionary _imageCache = new(); + public static string GetText(SensorType sensorType) { return sensorType switch @@ -86,4 +94,94 @@ public static class SensorTypeDisplay _ => "\uE950" }; } + + public static string GetImageFile(SensorType sensorType) + { + return sensorType switch + { + SensorType.Voltage => "voltage.png", + SensorType.Current => "current.png", + SensorType.Clock => "clock.png", + SensorType.Load => "load.png", + SensorType.Temperature => "temperature.png", + SensorType.Fan => "fan.png", + SensorType.Flow => "flow.png", + SensorType.Control => "control.png", + SensorType.Level => "level.png", + SensorType.Power => "power.png", + SensorType.Data => "data.png", + SensorType.SmallData => "data.png", + SensorType.Factor => "factor.png", + SensorType.Frequency => "clock.png", + SensorType.Throughput => "throughput.png", + SensorType.TimeSpan => "time.png", + SensorType.Timing => "time.png", + SensorType.Energy => "power.png", + SensorType.Noise => "loudspeaker.png", + SensorType.Conductivity => "voltage.png", + SensorType.Humidity => "humidity.png", + _ => "power.png" + }; + } + + public static string GetHardwareImageFile(HardwareType hardwareType) + { + return hardwareType switch + { + HardwareType.Motherboard => "mainboard.png", + HardwareType.SuperIO => "chip.png", + HardwareType.Cpu => "cpu.png", + HardwareType.Memory => "ram.png", + HardwareType.GpuNvidia => "nvidia.png", + HardwareType.GpuAmd => "amd.png", + HardwareType.GpuIntel => "intel.png", + HardwareType.Storage => "hdd.png", + HardwareType.Network => "nic.png", + HardwareType.Cooler => "fan.png", + HardwareType.EmbeddedController => "chip.png", + HardwareType.Psu => "power-supply.png", + HardwareType.Battery => "battery.png", + HardwareType.PowerMonitor => "powermonitor.png", + _ => "cpu.png" + }; + } + + public static ImageSource? GetImageByFilename(string? filename) + { + if (string.IsNullOrEmpty(filename)) + return null; + + if (_imageCache.TryGetValue(filename, out var cached)) + return cached; + + try + { + var assembly = typeof(SensorTypeDisplay).Assembly; + using var stream = assembly.GetManifestResourceStream("LibreHardwareMonitor.Windows.WinUI.Resources." + filename); + if (stream == null) + return null; + + var bitmapImage = new BitmapImage(); + var randomAccessStream = new InMemoryRandomAccessStream(); + using (var writeStream = randomAccessStream.AsStreamForWrite()) + { + stream.CopyTo(writeStream); + writeStream.Flush(); + randomAccessStream.Seek(0); + bitmapImage.SetSource(randomAccessStream); + } + + _imageCache[filename] = bitmapImage; + return bitmapImage; + } + catch (Exception ex) + { + try + { + File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "icon_error.txt"), ex.ToString()); + } + catch {} + return null; + } + } } diff --git a/LibreHardwareMonitor.Windows.WinUI/ViewModels/SensorTreeItemViewModel.cs b/LibreHardwareMonitor.Windows.WinUI/ViewModels/SensorTreeItemViewModel.cs index b7362b1..4ab57e8 100644 --- a/LibreHardwareMonitor.Windows.WinUI/ViewModels/SensorTreeItemViewModel.cs +++ b/LibreHardwareMonitor.Windows.WinUI/ViewModels/SensorTreeItemViewModel.cs @@ -53,6 +53,8 @@ public sealed class SensorTreeItemViewModel : ViewModelBase public string IconGlyph { get; private init; } = "\uE950"; + public string? IconImageName { get; private init; } + public bool IsExpanded { get => _isExpanded; @@ -210,6 +212,7 @@ public sealed class SensorTreeItemViewModel : ViewModelBase { _text = text, IconGlyph = "\uE7F4", + IconImageName = "computer.png", _isExpanded = true }; } @@ -221,6 +224,7 @@ public sealed class SensorTreeItemViewModel : ViewModelBase { Hardware = hardware, IconGlyph = SensorTypeDisplay.GetHardwareGlyph(hardware.HardwareType), + IconImageName = SensorTypeDisplay.GetHardwareImageFile(hardware.HardwareType), _expandedSettingName = expandedSettingName, _isExpanded = settings.GetValue(expandedSettingName, true) }; @@ -352,6 +356,7 @@ public sealed class SensorTreeItemViewModel : ViewModelBase { Sensor = sensor, IconGlyph = SensorTypeDisplay.GetGlyph(sensor.SensorType), + IconImageName = SensorTypeDisplay.GetImageFile(sensor.SensorType), _isVisible = !settings.GetValue(hiddenSettingName, sensor.IsDefaultHidden), _plot = settings.GetValue(plotSettingName, false), _penColor = settings.Contains(penColorSettingName) ? settings.GetValue(penColorSettingName, Color.FromArgb(255, 0, 0, 0)) : null @@ -365,6 +370,7 @@ public sealed class SensorTreeItemViewModel : ViewModelBase { _text = SensorTypeDisplay.GetText(sensorType), IconGlyph = SensorTypeDisplay.GetGlyph(sensorType), + IconImageName = SensorTypeDisplay.GetImageFile(sensorType), _expandedSettingName = expandedSettingName, _isExpanded = settings.GetValue(expandedSettingName, true) }; diff --git a/LibreHardwareMonitor.sln b/LibreHardwareMonitor.sln index 7ff6e5d..274bf48 100644 --- a/LibreHardwareMonitor.sln +++ b/LibreHardwareMonitor.sln @@ -34,32 +34,32 @@ Global {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Debug|x64.Build.0 = Debug|x64 {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Debug|x86.ActiveCfg = Debug|x86 {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Debug|x86.Build.0 = Debug|x86 - {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Debug|Any CPU.ActiveCfg = Debug|x64 + {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Debug|Any CPU.Build.0 = Debug|x64 {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Release|ARM64.ActiveCfg = Release|ARM64 {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Release|ARM64.Build.0 = Release|ARM64 {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Release|x64.ActiveCfg = Release|x64 {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Release|x64.Build.0 = Release|x64 {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Release|x86.ActiveCfg = Release|x86 {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Release|x86.Build.0 = Release|x86 - {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Release|Any CPU.Build.0 = Release|Any CPU + {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Release|Any CPU.ActiveCfg = Release|x64 + {49D41E03-7028-4B28-9F5E-4558D0E26EA2}.Release|Any CPU.Build.0 = Release|x64 {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|ARM64.ActiveCfg = Debug|ARM64 {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|ARM64.Build.0 = Debug|ARM64 {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|x64.ActiveCfg = Debug|x64 {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|x64.Build.0 = Debug|x64 {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|x86.ActiveCfg = Debug|x86 {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|x86.Build.0 = Debug|x86 - {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.ActiveCfg = Debug|x64 + {B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.Build.0 = Debug|x64 {B0397530-545A-471D-BB74-027AE456DF1A}.Release|ARM64.ActiveCfg = Release|ARM64 {B0397530-545A-471D-BB74-027AE456DF1A}.Release|ARM64.Build.0 = Release|ARM64 {B0397530-545A-471D-BB74-027AE456DF1A}.Release|x64.ActiveCfg = Release|x64 {B0397530-545A-471D-BB74-027AE456DF1A}.Release|x64.Build.0 = Release|x64 {B0397530-545A-471D-BB74-027AE456DF1A}.Release|x86.ActiveCfg = Release|x86 {B0397530-545A-471D-BB74-027AE456DF1A}.Release|x86.Build.0 = Release|x86 - {B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.Build.0 = Release|Any CPU + {B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.ActiveCfg = Release|x64 + {B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.Build.0 = Release|x64 {AF286D81-C1D0-47B2-AD60-9F60CAE602F9}.Debug|ARM64.ActiveCfg = Debug|Any CPU {AF286D81-C1D0-47B2-AD60-9F60CAE602F9}.Debug|ARM64.Build.0 = Debug|Any CPU