Skip to content

Commit

Permalink
Merge pull request #364 from emoacht/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
emoacht authored Oct 23, 2022
2 parents bf14ffa + 502915c commit 6161b6f
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Source/Installer/Product.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="3.13.0"
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="3.14.0"
Language="1033" Codepage="1252" UpgradeCode="{81A4D148-75D3-462E-938D-8C208FB48E3C}">
<Package Id="*" InstallerVersion="500" Compressed="yes"
InstallScope="perMachine" InstallPrivileges="elevated"
Expand Down
10 changes: 1 addition & 9 deletions Source/Monitorian.Core/Models/Monitor/MonitorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Management;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
Expand Down Expand Up @@ -325,7 +324,7 @@ public MonitorData()

public async Task PopulateAsync()
{
System = GetSystem();
System = $"Manufacturer: {SystemInfo.Manufacturer}, Model: {SystemInfo.Model}, OS: {Environment.OSVersion.Version}";

var sw = new Stopwatch();

Expand Down Expand Up @@ -371,13 +370,6 @@ Task<string> GetTask(string name, Action action) =>
return $@"{name,-14} -> {elapsed.ToString($@"{(elapsed.Minutes > 0 ? @"m\:" : string.Empty)}s\.fff")}";
});
}

private string GetSystem()
{
using var @class = new ManagementClass("Win32_ComputerSystem");
using var instance = @class.GetInstances().Cast<ManagementObject>().FirstOrDefault();
return $"Manufacturer: {instance?["Manufacturer"]}, Model: {instance?["Model"]}, OS: {Environment.OSVersion.Version}";
}
}

#endregion
Expand Down
52 changes: 52 additions & 0 deletions Source/Monitorian.Core/Models/SystemInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;

namespace Monitorian.Core.Models
{
/// <summary>
/// System information
/// </summary>
public static class SystemInfo
{
private class SystemInfoInternal
{
public string Manufacturer { get; }
public string Model { get; }

public SystemInfoInternal()
{
try
{
using var @class = new ManagementClass("Win32_ComputerSystem");
using var instance = @class.GetInstances().Cast<ManagementObject>().FirstOrDefault();

Manufacturer = instance?["Manufacturer"] as string;
Model = instance?["Model"] as string;
return;
}
catch (ManagementException)
{
Debug.WriteLine($"Failed to get instances by Win32_ComputerSystem");
}

const string keyName = @"SYSTEM\CurrentControlSet\Control\SystemInformation"; // HKLM

using var key = Registry.LocalMachine.OpenSubKey(keyName);

Manufacturer = key?.GetValue("SystemManufacturer") as string;
Model = key?.GetValue("SystemProductName") as string;
}
}

private static readonly Lazy<SystemInfoInternal> _instance = new(() => new());

public static string Manufacturer => _instance.Value.Manufacturer;
public static string Model => _instance.Value.Model;
}
}
1 change: 1 addition & 0 deletions Source/Monitorian.Core/Monitorian.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<Compile Include="Models\OperationRecorder.cs" />
<Compile Include="Models\ProductInfo.cs" />
<Compile Include="Models\SettingsCore.cs" />
<Compile Include="Models\SystemInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Invariant.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down
4 changes: 2 additions & 2 deletions Source/Monitorian.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.13.0.0")]
[assembly: AssemblyFileVersion("3.13.0.0")]
[assembly: AssemblyVersion("3.14.0.0")]
[assembly: AssemblyFileVersion("3.14.0.0")]
[assembly: NeutralResourcesLanguage("en-US")]

// For unit test
Expand Down
31 changes: 17 additions & 14 deletions Source/Monitorian.Core/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public ListCollectionView MonitorsView
_monitorsView = new ListCollectionView(_controller.Monitors);
if (Settings.OrdersArrangement)
{
_monitorsView.SortDescriptions.Add(new SortDescription(nameof(MonitorViewModel.MonitorTop), ListSortDirection.Ascending));
_monitorsView.SortDescriptions.Add(new SortDescription(nameof(MonitorViewModel.MonitorTopLeft), ListSortDirection.Ascending));
_monitorsView.IsLiveSorting = true;
_monitorsView.LiveSortingProperties.Add(nameof(MonitorViewModel.MonitorTopLeft));
}
_monitorsView.SortDescriptions.Add(new SortDescription(nameof(MonitorViewModel.DisplayIndex), ListSortDirection.Ascending));
_monitorsView.SortDescriptions.Add(new SortDescription(nameof(MonitorViewModel.MonitorIndex), ListSortDirection.Ascending));
Expand Down Expand Up @@ -88,21 +90,22 @@ private void OnSettingsChanged(object sender, PropertyChangedEventArgs e)
switch (e.PropertyName)
{
case nameof(Settings.OrdersArrangement):
var orderDescription = MonitorsView.SortDescriptions.FirstOrDefault(x => x.PropertyName == nameof(MonitorViewModel.MonitorTop));
var description = new SortDescription(nameof(MonitorViewModel.MonitorTopLeft), ListSortDirection.Ascending);
int index = MonitorsView.SortDescriptions.IndexOf(description);

if (Settings.OrdersArrangement)
switch (Settings.OrdersArrangement, index)
{
if (orderDescription != default)
return;

MonitorsView.SortDescriptions.Insert(0, new SortDescription(nameof(MonitorViewModel.MonitorTop), ListSortDirection.Ascending));
}
else
{
if (orderDescription == default)
return;

MonitorsView.SortDescriptions.Remove(orderDescription);
case (true, < 0):
MonitorsView.SortDescriptions.Insert(0, description);
MonitorsView.IsLiveSorting = true;
MonitorsView.LiveSortingProperties.Add(description.PropertyName);
break;

case (false, >= 0):
MonitorsView.SortDescriptions.RemoveAt(index);
MonitorsView.IsLiveSorting = false;
MonitorsView.LiveSortingProperties.Remove(description.PropertyName);
break;
}

MonitorsView.Refresh();
Expand Down
26 changes: 25 additions & 1 deletion Source/Monitorian.Core/ViewModels/MonitorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public MonitorViewModel(AppControllerCore controller, IMonitor monitor)
{
this._controller = controller ?? throw new ArgumentNullException(nameof(controller));
this._monitor = monitor ?? throw new ArgumentNullException(nameof(monitor));
SetTopLeft();

LoadCustomization();
}
Expand All @@ -37,6 +38,7 @@ internal void Replace(IMonitor monitor)
{
this._monitor.Dispose();
this._monitor = monitor;
SetTopLeft();
}
}
else
Expand All @@ -50,7 +52,6 @@ internal void Replace(IMonitor monitor)
public byte DisplayIndex => _monitor.DisplayIndex;
public byte MonitorIndex => _monitor.MonitorIndex;
public Rect MonitorRect => _monitor.MonitorRect;
public double MonitorTop => _monitor.MonitorRect.Top;

#region Customization

Expand Down Expand Up @@ -463,6 +464,29 @@ public bool IsSelected

#endregion

#region Arrangement

public ulong MonitorTopLeft
{
get => _monitorTopLeft;
private set => SetProperty(ref _monitorTopLeft, value);
}
private ulong _monitorTopLeft;

private void SetTopLeft()
{
MonitorTopLeft = GetTopLeft(_monitor.MonitorRect.Location);

static ulong GetTopLeft(Point location)
{
var x = (long)Math.Round(location.X, MidpointRounding.AwayFromZero) + int.MaxValue;
var y = (long)Math.Round(location.Y, MidpointRounding.AwayFromZero) + int.MaxValue;
return (ulong)x | ((ulong)y << 32);
}
}

#endregion

public bool IsTarget
{
get => _isTarget;
Expand Down
4 changes: 2 additions & 2 deletions Source/Monitorian/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.13.0.0")]
[assembly: AssemblyFileVersion("3.13.0.0")]
[assembly: AssemblyVersion("3.14.0.0")]
[assembly: AssemblyFileVersion("3.14.0.0")]
[assembly: Guid("a4cc5362-9b08-465b-ad64-5cfabc72a4c7")]
[assembly: NeutralResourcesLanguage("en-US")]

0 comments on commit 6161b6f

Please sign in to comment.