Skip to content

Commit

Permalink
Release v1.0.6!
Browse files Browse the repository at this point in the history
Added installer exe.
Added auto-detection and change of images of logos of computer elements.
Added change of images of logos of computer elements manually.
Added the ability to select a hidden launch of the application at autoload.
Fixed a bug related to the lack of a video card in the computer.
Fixed minor possible bugs related to NullReferenceException.
  • Loading branch information
TTLC198 committed Jan 15, 2023
1 parent 0f4b924 commit 1396d86
Show file tree
Hide file tree
Showing 33 changed files with 1,250 additions and 172 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### v1.0.6 (16.01.2023)

- Added installer exe.
- Added auto-detection and change of images of logos of computer elements.
- Added change of images of logos of computer elements manually.
- Added the ability to select a hidden launch of the application at autoload.
- Fixed a bug related to the lack of a video card in the computer.
- Fixed minor possible bugs related to NullReferenceException.
27 changes: 27 additions & 0 deletions HSMonitor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
.idea/

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
[Xx]64/
[Xx]86/
[Bb]uild/
bld/
[Bb]in/
[Oo]bj/

# Installer binary sources
Installer/Source

# Coverage
*.opencover.xml

# Rider's global.json
global.json
4 changes: 2 additions & 2 deletions HSMonitor/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

[assembly: AssemblyTitle("HSMonitor")]
[assembly: AssemblyDescription("Server part of the program for monitoring the state of computer hardware on a separate screen.")]
[assembly: AssemblyConfiguration("debug")]
[assembly: AssemblyConfiguration("release")]
[assembly: AssemblyCompany("ttlc198")]
[assembly: AssemblyProduct("HSMonitor")]
[assembly: AssemblyCopyright("ttlc198 2023")]
[assembly: AssemblyTrademark("")]

[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.5.0")]
[assembly: AssemblyVersion("1.0.6")]
7 changes: 6 additions & 1 deletion HSMonitor/HSMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<ItemGroup>
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="LibreHardwareMonitorLib" Version="0.9.2-pre188" />
<PackageReference Include="MaterialDesignColors" Version="2.1.0-ci409" />
<PackageReference Include="MaterialDesignThemes" Version="4.7.0-ci409" />
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" />
<PackageReference Include="Stylet" Version="1.3.6" />
Expand All @@ -29,6 +28,12 @@
<Resource Include="Resources\Images\favicon_wrong.ico" />
<None Remove="Resources\Images\favicon_light.ico" />
<Resource Include="Resources\Images\favicon_light.ico" />
<None Remove="Resources\Images\AmdLogo.png" />
<Resource Include="Resources\Images\AmdLogo.png" />
<None Remove="Resources\Images\NvidiaLogo.png" />
<Resource Include="Resources\Images\NvidiaLogo.png" />
<None Remove="Resources\Images\UnknownLogo.png" />
<Resource Include="Resources\Images\UnknownLogo.png" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 8 additions & 1 deletion HSMonitor/Models/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ public class ApplicationSettings

public string? CpuCustomName { get; set; }

public string? CpuCustomType { get; set; }

public string? GpuCustomName { get; set; }

public string? GpuCustomType { get; set; }

public string? MemoryCustomType { get; set; }

public bool IsAutodetectHardwareEnabled { get; set; }
public bool IsAutoDetectHardwareEnabled { get; set; }

// Advanced
[JsonIgnore]
public bool IsAutoStartEnabled { get; set; }
public bool IsHiddenAutoStartEnabled { get; set; }
}
1 change: 1 addition & 0 deletions HSMonitor/Models/HardwareInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class GpuFan

public class MemoryInformation
{
public string? Type { get; set; }
public int Load { get; set; }
public double Available { get; set; }
public double Used { get; set; }
Expand Down
Binary file added HSMonitor/Resources/Images/AmdLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added HSMonitor/Resources/Images/IntelLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added HSMonitor/Resources/Images/NvidiaLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added HSMonitor/Resources/Images/RadeonLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added HSMonitor/Resources/Images/UnknownLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 69 additions & 24 deletions HSMonitor/Services/HardwareMonitorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,35 @@ private CpuInformation CpuInformationUpdate(Computer computer)

return new CpuInformation()
{
Type = cpuHardware.GetType().ToString().Split(".").Last(),
Name = _settingsService.Settings.IsAutodetectHardwareEnabled ? cpuHardware.Name : _settingsService.Settings.CpuCustomName ?? cpuHardware.Name,
Clock = Convert.ToInt32(cpuHardwareSensors.First(s => s.SensorType == SensorType.Clock).Value!),
Type = _settingsService.Settings.IsAutoDetectHardwareEnabled
? (cpuHardware.GetType().ToString().Split(".").Last() ?? "Unknown")
: _settingsService.Settings.CpuCustomType
?? (cpuHardware.GetType().ToString().Split(".").Last() ?? "Unknown"),
Name = _settingsService.Settings.IsAutoDetectHardwareEnabled
? (cpuHardware.Name ?? "Unknown")
: _settingsService.Settings.CpuCustomName
?? (cpuHardware.Name ?? "Unknown"),
Clock = Convert.ToInt32(cpuHardwareSensors.First(s => s.SensorType == SensorType.Clock).Value ?? 0),
Load = Convert.ToInt32(cpuHardwareSensors
.First(s => s.Name.Contains("Total") && s.SensorType == SensorType.Load).Value!),
.First(s => s.Name.Contains("Total") && s.SensorType == SensorType.Load).Value ?? 0),
Power = Math.Round(
Convert.ToDouble(cpuHardwareSensors.First(s => s.SensorType == SensorType.Power).Value!), 1,
Convert.ToDouble(cpuHardwareSensors.First(s => s.SensorType == SensorType.Power).Value ?? 0), 1,
MidpointRounding.ToEven),
Temperature =
Convert.ToInt32(cpuHardwareSensors.First(s => s.SensorType == SensorType.Temperature).Value!),
Convert.ToInt32(cpuHardwareSensors.First(s => s.SensorType == SensorType.Temperature).Value ?? 0),
};
}
catch
{
return null!;
return new CpuInformation()
{
Type = "Unknown type",
Name = "Unknown CPU",
Clock = 0,
Load = 0,
Power = 0,
Temperature = 0,
};
}
}

Expand All @@ -108,10 +122,10 @@ private GpuInformation GpuInformationUpdate(Computer computer)
{
var gpuHardware = computer.Hardware
.FirstOrDefault(h => h.HardwareType is HardwareType.GpuAmd or HardwareType.GpuIntel or HardwareType.GpuNvidia);

if (gpuHardware is null)
throw new Exception();

var gpuHardwareSensors = gpuHardware
.Sensors
.Where(s => s.SensorType is SensorType.Clock or SensorType.SmallData or SensorType.Load
Expand Down Expand Up @@ -154,30 +168,48 @@ private GpuInformation GpuInformationUpdate(Computer computer)

return new GpuInformation()
{
Type = gpuHardware.GetType().ToString().Split(".").Last(),
Name = _settingsService.Settings.IsAutodetectHardwareEnabled ? gpuHardware.Name : _settingsService.Settings.GpuCustomName ?? gpuHardware.Name,
Type = _settingsService.Settings.IsAutoDetectHardwareEnabled
? (gpuHardware.GetType().ToString().Split(".").Last() ?? "Unknown")
: _settingsService.Settings.GpuCustomType
?? (gpuHardware.GetType().ToString().Split(".").Last() ?? "Unknown"),
Name = _settingsService.Settings.IsAutoDetectHardwareEnabled
? (gpuHardware.Name ?? "Unknown")
: _settingsService.Settings.GpuCustomName
?? (gpuHardware.Name ?? "Unknown"),
CoreClock = Convert.ToInt32(gpuHardwareSensors
.First(s => s.Name.Contains("Core") && s.SensorType == SensorType.Clock).Value!),
.First(s => s.Name.Contains("Core") && s.SensorType == SensorType.Clock).Value ?? 0),
CoreLoad = Convert.ToInt32(gpuHardwareSensors
.First(s => s.Name.Contains("Core") && s.SensorType == SensorType.Load).Value!),
.First(s => s.Name.Contains("Core") && s.SensorType == SensorType.Load).Value ?? 0),
CoreTemperature = Convert.ToInt32(gpuHardwareSensors
.First(s => s.Name.Contains("Core") && s.SensorType == SensorType.Temperature).Value!),
.First(s => s.Name.Contains("Core") && s.SensorType == SensorType.Temperature).Value ?? 0),
Power = (double) Math.Round(
(decimal) gpuHardwareSensors
.First(s => s.Name.Contains("Package") && s.SensorType == SensorType.Power).Value!, 1,
(decimal) (gpuHardwareSensors
.First(s => s.Name.Contains("Package") && s.SensorType == SensorType.Power).Value ?? 0), 1,
MidpointRounding.AwayFromZero),
VRamClock = Convert.ToInt32(gpuHardwareSensors
.First(s => s.Name.Contains("Memory") && s.SensorType == SensorType.Clock).Value!),
.First(s => s.Name.Contains("Memory") && s.SensorType == SensorType.Clock).Value ?? 0),
VRamMemoryTotal = Convert.ToInt32(gpuHardwareSensors
.First(s => s.Name.Contains("Memory Total") && s.SensorType == SensorType.SmallData).Value!),
.First(s => s.Name.Contains("Memory Total") && s.SensorType == SensorType.SmallData).Value ?? 0),
VRamMemoryUsed = Convert.ToInt32(gpuHardwareSensors
.First(s => s.Name.Contains("Memory Used") && s.SensorType == SensorType.SmallData).Value!),
.First(s => s.Name.Contains("Memory Used") && s.SensorType == SensorType.SmallData).Value ?? 0),
GpuFans = gpuFans
};
}
catch
{
return null!;
return new GpuInformation()
{
Type = "Unknown type",
Name = "Unknown GPU",
CoreClock = 0,
CoreLoad = 0,
CoreTemperature = 0,
Power = 0,
VRamClock = 0,
VRamMemoryTotal = 0,
VRamMemoryUsed = 0,
GpuFans = new List<GpuFan>()
};
}
}

Expand All @@ -201,17 +233,30 @@ private MemoryInformation MemoryInformationUpdate(Computer computer)

return new MemoryInformation()
{
Type = _settingsService.Settings.IsAutoDetectHardwareEnabled
? "Trident"
: _settingsService.Settings.MemoryCustomType
?? "Trident",
Load = (int)Math.Round(
(decimal)memoryHardwareSensors.First(s => s.Name == "Memory" && s.SensorType == SensorType.Load).Value, 0, MidpointRounding.AwayFromZero),
(decimal) (memoryHardwareSensors.First(s => s.Name == "Memory" && s.SensorType == SensorType.Load)
.Value ?? 0), 0, MidpointRounding.AwayFromZero),
Available = (double)Math.Round(
(decimal)memoryHardwareSensors.First(s => s.Name.Contains("Memory Available") && s.SensorType == SensorType.Data).Value!, 1,MidpointRounding.AwayFromZero),
(decimal) (memoryHardwareSensors
.First(s => s.Name.Contains("Memory Available") && s.SensorType == SensorType.Data).Value ?? 0), 1,MidpointRounding.AwayFromZero),
Used = (double)Math.Round(
(decimal)memoryHardwareSensors.First(s => s.Name.Contains("Memory Used") && s.SensorType == SensorType.Data).Value!, 1,MidpointRounding.AwayFromZero),
(decimal) (memoryHardwareSensors
.First(s => s.Name.Contains("Memory Used") && s.SensorType == SensorType.Data).Value ?? 0), 1,MidpointRounding.AwayFromZero),
};
}
catch
{
return null!;
return new MemoryInformation()
{
Type = "Trident",
Load = 0,
Available = 0,
Used = 0,
};
}
}
}
21 changes: 10 additions & 11 deletions HSMonitor/Services/SerialMonitorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public SerialMonitorService(
public bool SendInformationToMonitor()
{
var isConnected = false;
var message = HardwareMonitorService.GetHwInfoMessage() ?? throw new Exception("Message empty");
var jsonData = JsonSerializer
.Serialize(message)
.Append('\0')
.Select(c => (byte)c).ToArray();

try
{
isConnected = _serial.Open();
if (isConnected)
var message = HardwareMonitorService.GetHwInfoMessage() ?? throw new Exception("Message empty");
var jsonData = JsonSerializer
.Serialize(message)
.Select(s => (byte)s)
.ToArray();
if (_serial.Open())
_serial.Write(jsonData);
}
catch (Exception exception)
Expand All @@ -52,11 +52,10 @@ public bool SendInformationToMonitor()
okButtonText: "OK",
cancelButtonText: null
);

Task.Run(async () =>
if (_dialogManager.ShowDialogAsync(messageBoxDialog).Result == true)
{
await _dialogManager.ShowDialogAsync(messageBoxDialog);
});
_serial.Close();
}
}

return isConnected;
Expand Down
31 changes: 23 additions & 8 deletions HSMonitor/Services/SettingsService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand All @@ -18,7 +19,8 @@ public class SettingsService
private readonly DialogManager _dialogManager;
private readonly RegistryHandler _autoStartSwitch = new(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
$"\"{App.ExecutableFilePath}\" {App.HiddenOnLaunchArgument}"
$"\"{App.ExecutableFilePath}\"",
new string[] {App.HiddenOnLaunchArgument}
);

public event EventHandler? SettingsReset;
Expand Down Expand Up @@ -47,8 +49,11 @@ public void Reset()
SendInterval = 1000,
CpuCustomName = null,
GpuCustomName = null,
IsAutodetectHardwareEnabled = true,
IsAutoStartEnabled = true
CpuCustomType = null,
GpuCustomType = null,
IsAutoDetectHardwareEnabled = true,
IsAutoStartEnabled = true,
IsHiddenAutoStartEnabled = true,
};
Save();
SettingsReset?.Invoke(this, EventArgs.Empty);
Expand All @@ -68,6 +73,20 @@ public void Save()

try
{
if (Settings.IsAutoStartEnabled)
{
if (Settings.IsHiddenAutoStartEnabled)
{
if (_autoStartSwitch.Args.FirstOrDefault(a => a.Contains(App.HiddenOnLaunchArgument)) is null)
_autoStartSwitch.Args = _autoStartSwitch.Args.Append(App.HiddenOnLaunchArgument).ToArray();
}
else
{
if (_autoStartSwitch.Args.FirstOrDefault(a => a.Contains(App.HiddenOnLaunchArgument)) is not null)
_autoStartSwitch.Args = _autoStartSwitch.Args.Where(a => !a.Contains(App.HiddenOnLaunchArgument))
.ToArray();
}
}
_autoStartSwitch.IsSet = Settings.IsAutoStartEnabled;
}
catch (Exception exception)
Expand All @@ -80,11 +99,7 @@ public void Save()
okButtonText: "OK",
cancelButtonText: null
);

Task.Run(async () =>
{
await _dialogManager.ShowDialogAsync(messageBoxDialog);
});
_dialogManager.ShowDialogAsync(messageBoxDialog);
}

SettingsSaved?.Invoke(this, EventArgs.Empty);
Expand Down
7 changes: 7 additions & 0 deletions HSMonitor/Utils/Bootstrapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System.Windows;
using HSMonitor.Services;
using HSMonitor.ViewModels;
using HSMonitor.ViewModels.Framework;
Expand Down Expand Up @@ -42,4 +43,10 @@ protected override void Launch()

base.Launch();
}

protected override void OnExit(ExitEventArgs e)
{
GetInstance<SerialMonitorService>().Dispose();
base.OnExit(e);
}
}
2 changes: 1 addition & 1 deletion HSMonitor/Utils/JsonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static (bool result, Exception exception) JsonToFile<T>(this T sender, st
var options = new JsonSerializerOptions { WriteIndented = true };
File.WriteAllText(fileName, JsonSerializer.Serialize(sender, format ? options : null));

return (true, null);
return (true, null!);
}
catch (Exception exception)
{
Expand Down
Loading

0 comments on commit 1396d86

Please sign in to comment.