Skip to content

Commit

Permalink
Merge pull request #353 from emoacht/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
emoacht authored Aug 28, 2022
2 parents 0cb4509 + f0f5685 commit 3d54a59
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 151 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.12.1"
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="3.13.0"
Language="1033" Codepage="1252" UpgradeCode="{81A4D148-75D3-462E-938D-8C208FB48E3C}">
<Package Id="*" InstallerVersion="500" Compressed="yes"
InstallScope="perMachine" InstallPrivileges="elevated"
Expand Down
2 changes: 1 addition & 1 deletion Source/Monitorian.Core/AppControllerCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ await Task.Run(async () =>
var oldMonitorIndices = Enumerable.Range(0, Monitors.Count).ToList();
var newMonitorItems = new List<IMonitor>();
foreach (var item in await MonitorManager.EnumerateMonitorsAsync())
foreach (var item in await MonitorManager.EnumerateMonitorsAsync(TimeSpan.FromSeconds(12)))
{
Recorder.AddGroupRecordItem("Items", item.ToString());
Expand Down
2 changes: 1 addition & 1 deletion Source/Monitorian.Core/Helper/ArraySearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static int GetNearestIndex(byte[] array, byte target) =>

public static int GetNearestIndex<T>(T[] array, T target, Func<T, T, T> measure) where T : IComparable
{
if (array is null or { Length: 0 })
if (array is not { Length: > 0 })
throw new ArgumentNullException(nameof(array));

// The source array must be sorted beforehand.
Expand Down
24 changes: 7 additions & 17 deletions Source/Monitorian.Core/Models/AppDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@ namespace Monitorian.Core.Models
{
public static class AppDataService
{
public static string FolderPath => _folderPath ??= GetFolderPath();
public static string FolderPath => _folderPath ??=
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ProductInfo.Product);
private static string _folderPath;

private static string GetFolderPath()
{
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
if (string.IsNullOrEmpty(appDataPath)) // This should not happen.
throw new DirectoryNotFoundException();

return Path.Combine(appDataPath, ProductInfo.Product);
}

public static void AssureFolder()
public static string EnsureFolderPath()
{
if (!Directory.Exists(FolderPath))
Directory.CreateDirectory(FolderPath);

return FolderPath;
}

#region Access
Expand All @@ -54,9 +48,7 @@ public static async Task<string> ReadAsync(string fileName)

public static async Task WriteAsync(string fileName, bool append, string content)
{
AssureFolder();

var filePath = Path.Combine(FolderPath, fileName);
var filePath = Path.Combine(EnsureFolderPath(), fileName);

using var sw = new StreamWriter(filePath, append, Encoding.UTF8); // BOM will be emitted.
await sw.WriteAsync(content);
Expand Down Expand Up @@ -147,9 +139,7 @@ public static void Load<T>(T instance, string fileName, BindingFlags flags, IEnu
/// <param name="knownTypes">Known types of members of instance</param>
public static void Save<T>(T instance, string fileName, IEnumerable<Type> knownTypes = null) where T : class
{
AssureFolder();

var filePath = Path.Combine(FolderPath, fileName);
var filePath = Path.Combine(EnsureFolderPath(), fileName);

using var sw = new StreamWriter(filePath, false, Encoding.UTF8);
using var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true });
Expand Down
4 changes: 1 addition & 3 deletions Source/Monitorian.Core/Models/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ private static void RecordToAppData(string fileName, string content, int capacit
{
try
{
AppDataService.AssureFolder();

var appDataFilePath = Path.Combine(AppDataService.FolderPath, fileName);
var appDataFilePath = Path.Combine(AppDataService.EnsureFolderPath(), fileName);

UpdateContent(appDataFilePath, content, capacity);
}
Expand Down
1 change: 1 addition & 0 deletions Source/Monitorian.Core/Models/Monitor/DdcMonitorItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public DdcMonitorItem(
displayIndex: displayIndex,
monitorIndex: monitorIndex,
monitorRect: monitorRect,
isInternal: false,
isReachable: true)
{
this._handle = handle ?? throw new ArgumentNullException(nameof(handle));
Expand Down
1 change: 1 addition & 0 deletions Source/Monitorian.Core/Models/Monitor/IMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IMonitor : IDisposable
byte DisplayIndex { get; }
byte MonitorIndex { get; }
Rect MonitorRect { get; }
bool IsInternal { get; }
bool IsReachable { get; }
bool IsBrightnessSupported { get; }
bool IsContrastSupported { get; }
Expand Down
6 changes: 2 additions & 4 deletions Source/Monitorian.Core/Models/Monitor/MSMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DesktopItem
[OnSerializing]
private void OnSerializing(StreamingContext context)
{
_brightnessLevelsString = string.Join(" ", BrightnessLevels ?? Array.Empty<byte>());
_brightnessLevelsString = string.Join(" ", BrightnessLevels ?? Enumerable.Empty<byte>());
}

public DesktopItem(
Expand Down Expand Up @@ -246,10 +246,8 @@ public static (ManagementEventWatcher watcher, string message) StartBrightnessEv
{
try
{
var scope = @"root\wmi";
var query = "SELECT * FROM WmiMonitorBrightnessEvent";
var option = new EventWatcherOptions(null, TimeSpan.FromSeconds(1), 1);
var watcher = new ManagementEventWatcher(scope, query, option);
var watcher = new ManagementEventWatcher(@"root\wmi", "SELECT * FROM WmiMonitorBrightnessEvent", option);

watcher.Start();

Expand Down
4 changes: 4 additions & 0 deletions Source/Monitorian.Core/Models/Monitor/MonitorItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal abstract class MonitorItem : IMonitor, IDisposable
public byte DisplayIndex { get; }
public byte MonitorIndex { get; }
public Rect MonitorRect { get; }
public bool IsInternal { get; }
public bool IsReachable { get; }

public virtual bool IsBrightnessSupported => IsReachable;
Expand All @@ -28,6 +29,7 @@ public MonitorItem(
byte displayIndex,
byte monitorIndex,
Rect monitorRect,
bool isInternal,
bool isReachable)
{
if (string.IsNullOrWhiteSpace(deviceInstanceId))
Expand All @@ -40,6 +42,7 @@ public MonitorItem(
this.DisplayIndex = displayIndex;
this.MonitorIndex = monitorIndex;
this.MonitorRect = monitorRect;
this.IsInternal = isInternal;
this.IsReachable = isReachable;
}

Expand All @@ -63,6 +66,7 @@ public override string ToString()
(nameof(DisplayIndex), DisplayIndex),
(nameof(MonitorIndex), MonitorIndex),
(nameof(MonitorRect), MonitorRect),
(nameof(IsInternal), IsInternal),
(nameof(IsReachable), IsReachable),
(nameof(IsBrightnessSupported), IsBrightnessSupported),
(nameof(IsContrastSupported), IsContrastSupported),
Expand Down
Loading

0 comments on commit 3d54a59

Please sign in to comment.