Skip to content

Commit

Permalink
Merge pull request #158 from emoacht/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
emoacht authored Mar 26, 2021
2 parents f96161b + 1c96d85 commit 4d66cea
Show file tree
Hide file tree
Showing 40 changed files with 628 additions and 326 deletions.
14 changes: 14 additions & 0 deletions Source/Installer/Installer.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@
<RefTargetDir>INSTALLFOLDER</RefTargetDir>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<WixExtension Include="WixUIExtension">
<HintPath>$(WixExtDir)\WixUIExtension.dll</HintPath>
<Name>WixUIExtension</Name>
</WixExtension>
</ItemGroup>
<ItemGroup>
<Content Include="Resources\banner.png" />
<Content Include="Resources\dialog.png" />
<Content Include="Resources\License.rtf" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources" />
</ItemGroup>
<Import Project="$(WixTargetsPath)" />
<!--
To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
10 changes: 9 additions & 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="2.13.3"
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="2.14.0"
Language="1033" Codepage="1252" UpgradeCode="{81A4D148-75D3-462E-938D-8C208FB48E3C}">
<Package Id="*" InstallerVersion="500" Compressed="yes"
InstallScope="perMachine" InstallPrivileges="elevated"
Expand All @@ -12,6 +12,14 @@

<Property Id="VEM" Value="yes"/>

<!-- UI -->
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR"/>
<UIRef Id="WixUI_InstallDir"/>
<UIRef Id="WixUI_ErrorProgressText"/>
<WixVariable Id="WixUIBannerBmp" Value="Resources\banner.png"/>
<WixVariable Id="WixUIDialogBmp" Value="Resources\dialog.png"/>
<WixVariable Id="WixUILicenseRtf" Value="Resources\License.rtf"/>

<Directory Id="TARGETDIR" Name="SourceDir">
<!-- Program Files -->
<Directory Id="ProgramFilesFolder">
Expand Down
Binary file added Source/Installer/Resources/License.rtf
Binary file not shown.
Binary file added Source/Installer/Resources/banner.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 Source/Installer/Resources/dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 16 additions & 9 deletions Source/Monitorian.Core/AppControllerCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public AppControllerCore(AppKeeper keeper, SettingsCore settings)

public virtual async Task InitiateAsync()
{
Settings.Initiate();
await Settings.InitiateAsync();
Settings.MonitorCustomizations.AbsoluteCapacity = MaxKnownMonitorsCount;
Settings.PropertyChanged += OnSettingsChanged;

Expand Down Expand Up @@ -145,13 +145,13 @@ protected virtual void ShowMenuWindow(Point pivot)
window.Show();
}

protected virtual void OnSettingsInitiated()
protected virtual async void OnSettingsInitiated()
{
if (Settings.MakesOperationLog)
Recorder = new("Initiated");
Recorder = await OperationRecorder.CreateAsync("Initiated");
}

protected virtual void OnSettingsChanged(object sender, PropertyChangedEventArgs e)
protected virtual async void OnSettingsChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
Expand All @@ -160,7 +160,7 @@ protected virtual void OnSettingsChanged(object sender, PropertyChangedEventArgs
break;

case nameof(Settings.MakesOperationLog):
Recorder = Settings.MakesOperationLog ? new("Enabled") : null;
Recorder = Settings.MakesOperationLog ? await OperationRecorder.CreateAsync("Enabled") : null;
break;
}
}
Expand All @@ -169,19 +169,26 @@ protected virtual void OnSettingsChanged(object sender, PropertyChangedEventArgs

protected virtual async void OnMonitorsChangeInferred(object sender = null, PowerModes mode = default, int? count = null)
{
Recorder?.Record($"{nameof(OnMonitorsChangeInferred)} ({sender}{(mode == default ? string.Empty : $"- {mode} {count}")})");
await (Recorder?.RecordAsync($"{nameof(OnMonitorsChangeInferred)} ({sender}{(mode == default ? string.Empty : $"- {mode} {count}")})") ?? Task.CompletedTask);

if (count == 0)
return;

await ScanAsync(TimeSpan.FromSeconds(3));
}

protected internal virtual void OnMonitorsChangeFound()
protected internal virtual async void OnMonitorAccessFailed(AccessResult result)
{
await (Recorder?.RecordAsync($"{nameof(OnMonitorAccessFailed)}" + Environment.NewLine
+ $"Status: {result.Status}" + Environment.NewLine
+ $"Message: {result.Message}") ?? Task.CompletedTask);
}

protected internal virtual async void OnMonitorsChangeFound()
{
if (Monitors.Any())
{
Recorder?.Record($"{nameof(OnMonitorsChangeFound)}");
await (Recorder?.RecordAsync($"{nameof(OnMonitorsChangeFound)}") ?? Task.CompletedTask);

_displayWatcher.RaiseDisplaySettingsChanged();
}
Expand Down Expand Up @@ -270,7 +277,7 @@ await Task.Run(async () =>
var maxMonitorsCount = await GetMaxMonitorsCountAsync();

var updateResults = await Task.WhenAll(Monitors
.Where(x => x.IsLikelyControllable)
.Where(x => x.IsReachable)
.Select((x, index) =>
{
if (index < maxMonitorsCount)
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) || (array.Length == 0))
if (array is null or { Length: 0 })
throw new ArgumentNullException(nameof(array));

// The source array must be sorted beforehand.
Expand Down
59 changes: 55 additions & 4 deletions Source/Monitorian.Core/Models/AppDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,56 @@ public static void AssureFolder()
Directory.CreateDirectory(FolderPath);
}

public static void Load<T>(T instance, string fileName) where T : class
#region Access

public static IEnumerable<string> EnumerateFileNames(string searchPattern)
{
if (!Directory.Exists(FolderPath))
return Enumerable.Empty<string>();

return Directory.EnumerateFiles(FolderPath, searchPattern)
.Select(x => Path.GetFileName(x));
}

public static async Task<string> ReadAsync(string fileName)
{
var filePath = Path.Combine(FolderPath, fileName);

if (!File.Exists(filePath))
return null;

using var sr = new StreamReader(filePath, Encoding.UTF8);
return await sr.ReadToEndAsync();
}

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

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

using var sw = new StreamWriter(filePath, append, Encoding.UTF8); // BOM will be emitted.
await sw.WriteAsync(content);
}

public static void Delete(string fileName)
{
var filePath = Path.Combine(FolderPath, fileName);
File.Delete(filePath);
}

public static void Rename(string oldFileName, string newFileName)
{
var oldFilePath = Path.Combine(FolderPath, oldFileName);
var newFilePath = Path.Combine(FolderPath, newFileName);
File.Move(oldFilePath, newFilePath);
}

#endregion

#region Load/Save

public static void Load<T>(T instance, string fileName, IEnumerable<Type> knownTypes = null) where T : class
{
var filePath = Path.Combine(FolderPath, fileName);
var fileInfo = new FileInfo(filePath);
Expand All @@ -43,7 +92,7 @@ public static void Load<T>(T instance, string fileName) where T : class
using var xr = XmlReader.Create(sr);

var type = instance.GetType(); // GetType method works in derived class.
var serializer = new DataContractSerializer(type);
var serializer = new DataContractSerializer(type, knownTypes);
var loaded = (T)serializer.ReadObject(xr);

type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
Expand All @@ -61,7 +110,7 @@ public static void Load<T>(T instance, string fileName) where T : class
}
}

public static void Save<T>(T instance, string fileName) where T : class
public static void Save<T>(T instance, string fileName, IEnumerable<Type> knownTypes = null) where T : class
{
AssureFolder();

Expand All @@ -71,9 +120,11 @@ public static void Save<T>(T instance, string fileName) where T : class
using var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true });

var type = instance.GetType(); // GetType method works in derived class.
var serializer = new DataContractSerializer(type);
var serializer = new DataContractSerializer(type, knownTypes);
serializer.WriteObject(xw, instance);
xw.Flush();
}

#endregion
}
}
Loading

0 comments on commit 4d66cea

Please sign in to comment.