Skip to content

Commit

Permalink
Merge pull request #66 from emoacht/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
emoacht authored Dec 30, 2019
2 parents b898329 + 6c71d8e commit ca24738
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 80 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="2.3.0"
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="2.4.0"
Language="1033" Codepage="1252" UpgradeCode="{81A4D148-75D3-462E-938D-8C208FB48E3C}">
<Package Id="*" InstallerVersion="500" Compressed="yes"
InstallScope="perMachine" InstallPrivileges="elevated"
Expand Down
12 changes: 8 additions & 4 deletions Source/Monitorian.Core/AppControllerCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class AppControllerCore
private readonly PowerWatcher _powerWatcher;
private readonly BrightnessWatcher _brightnessWatcher;

private readonly OperationRecorder _recorder;
private OperationRecorder _recorder;

public AppControllerCore(AppKeeper keeper, SettingsCore settings)
{
Expand All @@ -56,8 +56,6 @@ public AppControllerCore(AppKeeper keeper, SettingsCore settings)
_displayWatcher = new DisplayWatcher();
_powerWatcher = new PowerWatcher();
_brightnessWatcher = new BrightnessWatcher();

_recorder = OperationRecorder.Create();
}

public virtual async Task InitiateAsync()
Expand All @@ -74,6 +72,9 @@ public virtual async Task InitiateAsync()
if (StartupAgent.IsWindowShowExpected())
_current.MainWindow.Show();

if (Settings.MakesOperationLog)
_recorder = new OperationRecorder("Initiated");

await ScanAsync();

StartupAgent.Requested += (sender, e) => e.Response = OnRequested(sender, e.Args);
Expand Down Expand Up @@ -141,14 +142,17 @@ protected virtual void ShowMenuWindow(Point pivot)
{
var window = new MenuWindow(this, pivot);
window.ViewModel.CloseAppRequested += (sender, e) => _current.Shutdown();
window.AddMenuItem(new ProbeSection());
window.AddMenuItem(new ProbeSection(this));
window.Show();
}

protected virtual void OnSettingsChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Settings.EnablesUnison))
OnSettingsEnablesUnisonChanged();

if (e.PropertyName == nameof(Settings.MakesOperationLog))
_recorder = Settings.MakesOperationLog ? new OperationRecorder("Enabled") : null;
}

#region Monitors
Expand Down
2 changes: 1 addition & 1 deletion Source/Monitorian.Core/AppKeeper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AppKeeper
public IReadOnlyCollection<string> FilteredArguments { get; }
public StartupAgent StartupAgent { get; }

public AppKeeper(StartupEventArgs e) : this(e, StartupAgent.Options, LanguageService.Options, WindowEffect.Options, OperationRecorder.Options)
public AppKeeper(StartupEventArgs e) : this(e, StartupAgent.Options, LanguageService.Options, WindowEffect.Options)
{ }

public AppKeeper(StartupEventArgs e, params IEnumerable<string>[] ignorableOptions)
Expand Down
53 changes: 49 additions & 4 deletions Source/Monitorian.Core/Models/LogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void RecordProbe(string content)
+ content;

if (MessageBox.Show(
Resources.RecordProbe,
Resources.RecordProbeMessage,
ProductInfo.Title,
MessageBoxButton.OKCancel,
MessageBoxImage.Information,
Expand All @@ -46,7 +46,7 @@ public static void RecordProbe(string content)
}

/// <summary>
/// Records operation log to Temp.
/// Records operation log to AppData.
/// </summary>
/// <param name="content">Content</param>
/// <remarks>
Expand All @@ -58,7 +58,26 @@ public static void RecordOperation(string content)
content = ComposeHeader() + Environment.NewLine
+ content + Environment.NewLine + Environment.NewLine;

RecordToTemp(OperationFileName, content, 100);
RecordToAppData(OperationFileName, content, 100);
}

/// <summary>
/// Copies operation log to Desktop.
/// </summary>
public static void CopyOperation()
{
if (!TryReadFromAppData(OperationFileName, out string content))
return;

if (MessageBox.Show(
Resources.CopyOperationMessage,
ProductInfo.Title,
MessageBoxButton.OKCancel,
MessageBoxImage.Information,
MessageBoxResult.OK) != MessageBoxResult.OK)
return;

RecordToDesktop(OperationFileName, content);
}

/// <summary>
Expand All @@ -77,7 +96,7 @@ public static void RecordException(Exception exception)
RecordToAppData(ExceptionFileName, content, 10);

if (MessageBox.Show(
Resources.RecordException,
Resources.RecordExceptionMessage,
ProductInfo.Title,
MessageBoxButton.YesNo,
MessageBoxImage.Error,
Expand Down Expand Up @@ -123,6 +142,32 @@ private static void RecordToAppData(string fileName, string content, int maxCoun
}
}

private static bool TryReadFromAppData(string fileName, out string content)
{
var appDataFilePath = Path.Combine(
FolderService.AppDataFolderPath,
fileName);

if (File.Exists(appDataFilePath))
{
try
{
using (var sr = new StreamReader(appDataFilePath, Encoding.UTF8))
{
content = sr.ReadToEnd();
return true;
}
}
catch (Exception ex)
{
Trace.WriteLine("Failed to read log from AppData." + Environment.NewLine
+ ex);
}
}
content = null;
return false;
}

private static void RecordToDesktop(string fileName, string content, int maxCount = 1)
{
try
Expand Down
10 changes: 1 addition & 9 deletions Source/Monitorian.Core/Models/OperationRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@ namespace Monitorian.Core.Models
{
internal class OperationRecorder
{
private const string OperationOption = "/operation";

public static IReadOnlyCollection<string> Options => new[] { OperationOption };

private static bool IsRecording() => Environment.GetCommandLineArgs().Skip(1).Contains(OperationOption);

public static OperationRecorder Create() => IsRecording() ? new OperationRecorder() : null;

private OperationRecorder() => LogService.RecordOperation(nameof(Create));
public OperationRecorder(string message) => LogService.RecordOperation(message);

public void Record(string content) => LogService.RecordOperation(content);

Expand Down
11 changes: 11 additions & 0 deletions Source/Monitorian.Core/Models/SettingsCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ public string SelectedDeviceInstanceId
}
private string _selectedDeviceInstanceId;

/// <summary>
/// Whether to make operation log
/// </summary>
[DataMember]
public bool MakesOperationLog
{
get => _makesOperationLog;
set => SetPropertyValue(ref _makesOperationLog, value);
}
private bool _makesOperationLog;

#endregion

private const string SettingsFileName = "settings.xml";
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("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
[assembly: AssemblyVersion("2.4.0.0")]
[assembly: AssemblyFileVersion("2.4.0.0")]
[assembly: NeutralResourcesLanguage("en-US")]

// For unit test
Expand Down
49 changes: 38 additions & 11 deletions Source/Monitorian.Core/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions Source/Monitorian.Core/Properties/Resources.ja-JP.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,28 @@
<data name="Close" xml:space="preserve">
<value>閉じる</value>
</data>
<data name="EnablesUnison" xml:space="preserve">
<data name="CopyOperation" xml:space="preserve">
<value>動作ログをコピーする</value>
</data>
<data name="EnableUnison" xml:space="preserve">
<value>一斉に動かせるようにする</value>
</data>
<data name="MakeOperation" xml:space="preserve">
<value>動作ログを作成する</value>
</data>
<data name="NotControllable" xml:space="preserve">
<value>このモニターはコントロールできません。</value>
</data>
<data name="Probe" xml:space="preserve">
<value>モニターを調査する</value>
</data>
<data name="ShowsAdjusted" xml:space="preserve">
<data name="ShowAdjusted" xml:space="preserve">
<value>調整後の明るさを表示する</value>
</data>
<data name="StartSignIn" xml:space="preserve">
<value>サインイン時に起動する</value>
</data>
<data name="UsesLargeElements" xml:space="preserve">
<data name="UseLargeElements" xml:space="preserve">
<value>大きいボタンを使う</value>
</data>
</root>
19 changes: 14 additions & 5 deletions Source/Monitorian.Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,34 @@
<data name="Close" xml:space="preserve">
<value>Close</value>
</data>
<data name="EnablesUnison" xml:space="preserve">
<data name="CopyOperation" xml:space="preserve">
<value>Copy operation log</value>
</data>
<data name="CopyOperationMessage" xml:space="preserve">
<value>Save operation log to Desktop?</value>
</data>
<data name="EnableUnison" xml:space="preserve">
<value>Enable moving in unison</value>
</data>
<data name="License" xml:space="preserve">
<value>License</value>
</data>
<data name="MakeOperation" xml:space="preserve">
<value>Make operation log</value>
</data>
<data name="NotControllable" xml:space="preserve">
<value>This monitor is not controllable.</value>
</data>
<data name="Probe" xml:space="preserve">
<value>Probe into monitors</value>
</data>
<data name="RecordException" xml:space="preserve">
<data name="RecordExceptionMessage" xml:space="preserve">
<value>An unexpected problem happened. Save exception log to Desktop?</value>
</data>
<data name="RecordProbe" xml:space="preserve">
<data name="RecordProbeMessage" xml:space="preserve">
<value>Save probe log to Desktop?</value>
</data>
<data name="ShowsAdjusted" xml:space="preserve">
<data name="ShowAdjusted" xml:space="preserve">
<value>Show adjusted brightness</value>
</data>
<data name="Site" xml:space="preserve">
Expand All @@ -150,7 +159,7 @@
<data name="StartSignIn" xml:space="preserve">
<value>Start on sign in</value>
</data>
<data name="UsesLargeElements" xml:space="preserve">
<data name="UseLargeElements" xml:space="preserve">
<value>Use large buttons</value>
</data>
</root>
Loading

0 comments on commit ca24738

Please sign in to comment.