fix most dark mode issues of logging

This commit is contained in:
Vincent Maas committed 2023-06-24 10:58:10 +02:00
1 parent 3ef21278cd
commit 04d447a48b
17 files changed
+4867 -270

No files matched your search

+13 -20
View File
@@ -18,8 +18,8 @@
<PublisherName>Maassoft</PublisherName>
<Company>Maassoft</Company>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>9.5.0.0</ApplicationVersion>
<Version>9.5.0.0</Version>
<ApplicationVersion>9.6.0.0</ApplicationVersion>
<Version>9.6.0.0</Version>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>false</BootstrapperEnabled>
@@ -48,14 +48,10 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<None Remove="XForms\LogWindow.xaml" />
<None Remove="Themes\DarkTheme.xaml" />
<None Remove="XForms\LogWindow.xaml" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Update="Services\Common\QuickAccessForm.cs">
<SubType>Form</SubType>
</Compile>
@@ -74,6 +70,9 @@
<Content Include="LgPresets.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Resource Include="Themes\DarkTheme.xaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
</ItemGroup>
<ItemGroup>
<Content Include="pngbarn.ico" />
@@ -105,9 +104,9 @@
<PackageReference Include="Vanara.PInvoke.IpHlpApi" Version="3.4.13" />
</ItemGroup>
<ItemGroup>
<Page Include="XForms\LogWindow.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="XForms\LogWindow.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NLogViewer\NLogViewer.csproj" />
@@ -116,14 +115,8 @@
<ProjectReference Include="..\NvAPIWrapper\NvAPIWrapper.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Services\Samsung\SamsungPanel.resx">
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<EmbeddedResource Update="Services\Samsung\SamsungPanel.resx">
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
</Project>
+37 -1
View File
@@ -1,7 +1,11 @@
using System;
using ColorControl.Native;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using static ColorControl.Native.WinApi;
namespace ColorControl.Common
{
@@ -46,6 +50,18 @@ namespace ColorControl.Common
public static Process Parent(this Process process, IEnumerable<Process> processes = null)
{
if (Utils.IsAdministrator())
{
try
{
return GetParentProcess(process.Handle);
}
catch
{
return null;
}
}
var indexedProcessName = FindIndexedProcessName(process.Id, process.ProcessName, processes);
if (indexedProcessName == null)
{
@@ -54,5 +70,25 @@ namespace ColorControl.Common
return FindPidFromIndexedProcessName(indexedProcessName, processes);
}
public static Process GetParentProcess(IntPtr handle)
{
var pbi = new ParentProcessUtilities();
int returnLength;
int status = WinApi.NtQueryInformationProcess(handle, 0, ref pbi, Marshal.SizeOf(pbi), out returnLength);
if (status != 0)
throw new Win32Exception(status);
try
{
return Process.GetProcessById(pbi.InheritedFromUniqueProcessId.ToInt32());
}
catch (ArgumentException)
{
// not found
return null;
}
}
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ namespace ColorControl.Forms
private static Dictionary<string, Tuple<Color, Color, Color, Color>> _defaultColors = new Dictionary<string, Tuple<Color, Color, Color, Color>>();
private static ToolStripRenderer _defaultRenderer;
private static Type[] _windowColorTypes = new[] { typeof(GroupBox), typeof(TabPage), typeof(UserControl) };
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
public const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
public class DarkModeToolStripRenderer : ToolStripProfessionalRenderer
{
+12 -87
View File
@@ -41,6 +41,7 @@
lblFixChromeFontsDescription = new System.Windows.Forms.Label();
chkFixChromeFonts = new System.Windows.Forms.CheckBox();
grpGeneralOptions = new System.Windows.Forms.GroupBox();
btnOptionsLog = new System.Windows.Forms.Button();
btnOptionsAdvanced = new System.Windows.Forms.Button();
chkOptionsUseDarkMode = new System.Windows.Forms.CheckBox();
chkAutoInstallUpdates = new System.Windows.Forms.CheckBox();
@@ -57,11 +58,6 @@
chkMinimizeOnClose = new System.Windows.Forms.CheckBox();
chkStartMinimized = new System.Windows.Forms.CheckBox();
chkStartAfterLogin = new System.Windows.Forms.CheckBox();
tabLog = new System.Windows.Forms.TabPage();
lblShowLog = new System.Windows.Forms.Label();
cbxLogType = new System.Windows.Forms.ComboBox();
btnClearLog = new System.Windows.Forms.Button();
edtLog = new System.Windows.Forms.TextBox();
tabInfo = new System.Windows.Forms.TabPage();
grpNVIDIAInfo = new System.Windows.Forms.GroupBox();
btnRefreshNVIDIAInfo = new System.Windows.Forms.Button();
@@ -71,13 +67,11 @@
label7 = new System.Windows.Forms.Label();
lblInfo = new System.Windows.Forms.Label();
btnUpdate = new System.Windows.Forms.Button();
btnOptionsLog = new System.Windows.Forms.Button();
tcMain.SuspendLayout();
tabOptions.SuspendLayout();
grpOptionsModules.SuspendLayout();
grpMiscellaneousOptions.SuspendLayout();
grpGeneralOptions.SuspendLayout();
tabLog.SuspendLayout();
tabInfo.SuspendLayout();
grpNVIDIAInfo.SuspendLayout();
groupBox3.SuspendLayout();
@@ -87,7 +81,6 @@
//
tcMain.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
tcMain.Controls.Add(tabOptions);
tcMain.Controls.Add(tabLog);
tcMain.Controls.Add(tabInfo);
tcMain.Location = new System.Drawing.Point(14, 14);
tcMain.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
@@ -243,6 +236,17 @@
grpGeneralOptions.TabStop = false;
grpGeneralOptions.Text = "General";
//
// btnOptionsLog
//
btnOptionsLog.Location = new System.Drawing.Point(103, 172);
btnOptionsLog.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
btnOptionsLog.Name = "btnOptionsLog";
btnOptionsLog.Size = new System.Drawing.Size(88, 27);
btnOptionsLog.TabIndex = 68;
btnOptionsLog.Text = "Logging...";
btnOptionsLog.UseVisualStyleBackColor = true;
btnOptionsLog.Click += btnOptionsLog_Click;
//
// btnOptionsAdvanced
//
btnOptionsAdvanced.Location = new System.Drawing.Point(7, 172);
@@ -435,67 +439,6 @@
chkStartAfterLogin.UseVisualStyleBackColor = true;
chkStartAfterLogin.CheckedChanged += chkStartAfterLogin_CheckedChanged;
//
// tabLog
//
tabLog.Controls.Add(lblShowLog);
tabLog.Controls.Add(cbxLogType);
tabLog.Controls.Add(btnClearLog);
tabLog.Controls.Add(edtLog);
tabLog.Location = new System.Drawing.Point(4, 24);
tabLog.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
tabLog.Name = "tabLog";
tabLog.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
tabLog.Size = new System.Drawing.Size(1114, 539);
tabLog.TabIndex = 3;
tabLog.Text = "Log";
tabLog.UseVisualStyleBackColor = true;
//
// lblShowLog
//
lblShowLog.AutoSize = true;
lblShowLog.Location = new System.Drawing.Point(8, 14);
lblShowLog.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
lblShowLog.Name = "lblShowLog";
lblShowLog.Size = new System.Drawing.Size(88, 15);
lblShowLog.TabIndex = 33;
lblShowLog.Text = "Show log from:";
//
// cbxLogType
//
cbxLogType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
cbxLogType.FormattingEnabled = true;
cbxLogType.Items.AddRange(new object[] { "Main application", "Service" });
cbxLogType.Location = new System.Drawing.Point(102, 9);
cbxLogType.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
cbxLogType.Name = "cbxLogType";
cbxLogType.Size = new System.Drawing.Size(189, 23);
cbxLogType.TabIndex = 32;
cbxLogType.SelectedIndexChanged += cbxLogType_SelectedIndexChanged;
//
// btnClearLog
//
btnClearLog.Location = new System.Drawing.Point(299, 6);
btnClearLog.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
btnClearLog.Name = "btnClearLog";
btnClearLog.Size = new System.Drawing.Size(88, 27);
btnClearLog.TabIndex = 2;
btnClearLog.Text = "Clear log";
btnClearLog.UseVisualStyleBackColor = true;
btnClearLog.Click += btnClearLog_Click;
//
// edtLog
//
edtLog.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
edtLog.Location = new System.Drawing.Point(7, 40);
edtLog.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
edtLog.MaxLength = 327670;
edtLog.Multiline = true;
edtLog.Name = "edtLog";
edtLog.ReadOnly = true;
edtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
edtLog.Size = new System.Drawing.Size(1098, 478);
edtLog.TabIndex = 0;
//
// tabInfo
//
tabInfo.Controls.Add(grpNVIDIAInfo);
@@ -604,17 +547,6 @@
btnUpdate.Visible = false;
btnUpdate.Click += btnUpdate_Click;
//
// btnOptionsLog
//
btnOptionsLog.Location = new System.Drawing.Point(103, 172);
btnOptionsLog.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
btnOptionsLog.Name = "btnOptionsLog";
btnOptionsLog.Size = new System.Drawing.Size(88, 27);
btnOptionsLog.TabIndex = 68;
btnOptionsLog.Text = "Logging...";
btnOptionsLog.UseVisualStyleBackColor = true;
btnOptionsLog.Click += btnOptionsLog_Click;
//
// MainForm
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@@ -646,8 +578,6 @@
grpMiscellaneousOptions.PerformLayout();
grpGeneralOptions.ResumeLayout(false);
grpGeneralOptions.PerformLayout();
tabLog.ResumeLayout(false);
tabLog.PerformLayout();
tabInfo.ResumeLayout(false);
grpNVIDIAInfo.ResumeLayout(false);
groupBox3.ResumeLayout(false);
@@ -662,8 +592,6 @@
private System.Windows.Forms.GroupBox grpGeneralOptions;
private System.Windows.Forms.CheckBox chkStartMinimized;
private System.Windows.Forms.CheckBox chkStartAfterLogin;
private System.Windows.Forms.TabPage tabLog;
private System.Windows.Forms.TextBox edtLog;
private System.Windows.Forms.TabPage tabInfo;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.ListBox lbPlugins;
@@ -679,7 +607,6 @@
private System.Windows.Forms.Label label11;
private System.Windows.Forms.TextBox edtBlankScreenSaverShortcut;
private System.Windows.Forms.CheckBox chkMinimizeOnClose;
private System.Windows.Forms.Button btnClearLog;
private System.Windows.Forms.CheckBox chkMinimizeToSystemTray;
private System.Windows.Forms.CheckBox chkCheckForUpdates;
private System.Windows.Forms.CheckBox chkGdiScaling;
@@ -690,8 +617,6 @@
private System.Windows.Forms.RadioButton rbElevationNone;
private System.Windows.Forms.Button btnElevationInfo;
private System.Windows.Forms.Button btnStartStopService;
private System.Windows.Forms.Label lblShowLog;
private System.Windows.Forms.ComboBox cbxLogType;
private System.Windows.Forms.CheckBox chkAutoInstallUpdates;
private System.Windows.Forms.Button btnUpdate;
private System.Windows.Forms.GroupBox grpOptionsModules;
+29 -84
View File
@@ -762,11 +762,7 @@ NOTE: installing the service may cause a User Account Control popup.");
private void InitSelectedTab()
{
if (tcMain.SelectedTab == tabLog)
{
LoadLog();
}
else if (tcMain.SelectedTab == tabInfo)
if (tcMain.SelectedTab == tabInfo)
{
LoadInfo();
}
@@ -948,48 +944,6 @@ NOTE: installing the service may cause a User Account Control popup.");
await _samsungPanel?.ApplyPreset(preset);
}
private void LoadLog()
{
var logType = cbxLogType.SelectedIndex;
if (logType == -1)
{
cbxLogType.SelectedIndex = 0;
return;
}
string text;
if (logType == 0)
{
var filename = Path.Combine(_dataDir, "LogFile.txt");
text = Utils.ReadText(filename);
text ??= "No log file found";
}
else
{
if (Utils.IsServiceRunning())
{
var message = new SvcMessage { MessageType = SvcMessageType.GetLog };
var result = PipeUtils.SendMessage(message);
text = result?.Data ?? "Cannot get log from service";
}
else
{
text = "The service is not installed or not running";
}
}
edtLog.Text = text;
edtLog.SelectionStart = text.Length;
edtLog.ScrollToCaret();
}
private void LoadInfo()
{
grpNVIDIAInfo.Visible = _serviceManager.NvService != null;
@@ -1035,40 +989,12 @@ NOTE: installing the service may cause a User Account Control popup.");
private void MainForm_Activated(object sender, EventArgs e)
{
if (tcMain.SelectedTab == tabLog)
{
LoadLog();
}
else if (tcMain.SelectedTab?.Controls.Count > 0 && tcMain.SelectedTab.Controls[0] is IModulePanel panel)
if (tcMain.SelectedTab?.Controls.Count > 0 && tcMain.SelectedTab.Controls[0] is IModulePanel panel)
{
panel.UpdateInfo();
}
}
private void btnClearLog_Click(object sender, EventArgs e)
{
var logType = cbxLogType.SelectedIndex;
if (logType == -1)
{
return;
}
if (logType == 0)
{
var filename = Program.LogFilename;
if (File.Exists(filename))
{
File.Delete(filename);
}
}
else
{
PipeUtils.SendMessage(SvcMessageType.ClearLog);
}
edtLog.Clear();
}
private void AfterInitialized()
{
_nvPanel?.AfterInitialized();
@@ -1096,7 +1022,7 @@ NOTE: installing the service may cause a User Account Control popup.");
BeginInvoke(() => HandleCheckForUpdates(latest));
}
private void HandleCheckForUpdates(dynamic latest)
private void HandleCheckForUpdates(dynamit)
{
if (latest?.tag_name == null)
{
@@ -1104,9 +1030,33 @@ NOTE: installing the service may cause a User Account Control popup.");
}
var currentVersion = Application.ProductVersion;
var cvParts = currentVersion.Split(".");
var newVersion = latest.tag_name.Value.Substring(1);
if (newVersion.CompareTo(currentVersion) > 0)
var newVersion = (string)latest.tag_name.Value.Substring(1);
var nvParts = newVersion.Split(".");
bool CompareVersions()
{
var result = true;
for (var i = 0; i < nvParts.Length; i++)
{
var part = nvParts[i];
var cvPart = cvParts[i];
if (Utils.ParseInt(part) >= Utils.ParseInt(cvPart))
{
continue;
}
result = false;
break;
}
return result;
}
if (nvParts.Length != cvParts.Length || CompareVersions())
{
_updateHtmlUrl = latest.html_url.Value;
@@ -1362,11 +1312,6 @@ Currently ColorControl is {(Utils.IsAdministrator() ? "" : "not ")}running as ad
UpdateServiceInfo();
}
private void cbxLogType_SelectedIndexChanged(object sender, EventArgs e)
{
LoadLog();
}
private async void MainForm_Click(object sender, EventArgs e)
{
//_powerEventDispatcher.SendEvent(PowerEventDispatcher.Event_Shutdown);
+15
View File
@@ -96,6 +96,18 @@ namespace ColorControl.Native
public MessageFilterInfo info;
}
[StructLayout(LayoutKind.Sequential)]
public struct ParentProcessUtilities
{
// These members must match PROCESS_BASIC_INFORMATION
internal IntPtr Reserved1;
internal IntPtr PebBaseAddress;
internal IntPtr Reserved2_0;
internal IntPtr Reserved2_1;
internal IntPtr UniqueProcessId;
internal IntPtr InheritedFromUniqueProcessId;
}
public const int ENUM_CURRENT_SETTINGS = -1;
public const int ENUM_REGISTRY_SETTINGS = -2;
@@ -149,5 +161,8 @@ namespace ColorControl.Native
[DllImport("dwmapi.dll", PreserveSig = true)]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
[DllImport("ntdll.dll")]
public static extern int NtQueryInformationProcess(IntPtr processHandle, int processInformationClass, ref ParentProcessUtilities processInformation, int processInformationLength, out int returnLength);
}
}
-26
View File
@@ -1,26 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ColorControl.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}
@@ -1,7 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
+1
View File
@@ -360,6 +360,7 @@
chkSamsungRemoteControlShow.TabIndex = 43;
chkSamsungRemoteControlShow.Text = "Remote Control";
chkSamsungRemoteControlShow.UseVisualStyleBackColor = true;
chkSamsungRemoteControlShow.Visible = false;
chkSamsungRemoteControlShow.CheckedChanged += chkSamsungRemoteControlShow_CheckedChanged;
//
// label3
@@ -41,6 +41,8 @@ namespace ColorControl.Services.Samsung
InitializeComponent();
scSamsungController.Panel2Collapsed = true;
FillLgPresets();
FormUtils.InitSortState(lvSamsungPresets, _config.LgPresetsSortState);
@@ -816,7 +818,7 @@ Do you want to continue?"
private void chkSamsungRemoteControlShow_CheckedChanged(object sender, EventArgs e)
{
scSamsungController.Panel2Collapsed = !chkSamsungRemoteControlShow.Checked;
//scSamsungController.Panel2Collapsed = !chkSamsungRemoteControlShow.Checked;
//_samsungService.Config.ShowRemoteControl = chkSamsungRemoteControlShow.Checked;
}
@@ -120,9 +120,6 @@
<metadata name="mnuLgButtons.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>288, 16</value>
</metadata>
<metadata name="mnuLgExpert.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="mnuLgSettings.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>147, 17</value>
</metadata>
File diff suppressed because it is too large. Load diff
+11 -2
View File
@@ -11,11 +11,12 @@
Height="600"
WindowStartupLocation="CenterOwner"
SnapsToDevicePixels="True"
Style="{DynamicResource CustomWindowStyle}"
d:DesignHeight="450" d:DesignWidth="800" Loaded="Window_Loaded">
<DockPanel Margin="6 0 6 6" LastChildFill="True">
<GroupBox DockPanel.Dock="Top" HorizontalAlignment="Stretch" Margin="0,6,0,0" VerticalAlignment="Bottom" Header="Log settings" Padding="6">
<StackPanel Orientation="Horizontal">
<TextBlock>Log level:</TextBlock>
<TextBlock VerticalAlignment="Center">Log level:</TextBlock>
<ComboBox Width="117" Margin="6,0,0,0" SelectedIndex="{Binding LogLevelIndex}" SelectionChanged="LogLevel_Changed">
<ComboBoxItem>Trace</ComboBoxItem>
<ComboBoxItem>Debug</ComboBoxItem>
@@ -30,11 +31,19 @@
<StackPanel Orientation="Horizontal">
<Button Click="LoadOlder_Click" Content="Load older..." Width="75" Margin="0,0,6,0"/>
<Button Width="75" Click="RawLog_Click" Margin="0,0,6,0">View raw log</Button>
<Button Width="75" Click="DeleteLog_Click" Margin="0,0,6,0">Delete log</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Width="75" Click="Close_Click" IsCancel="True">Close</Button>
</StackPanel>
</DockPanel>
<dj:NLogViewer x:Name="logViewer" />
<TabControl x:Name="tabControl">
<TabItem Header="Application">
<dj:NLogViewer x:Name="logViewerApplication" />
</TabItem>
<TabItem Header="Service">
<dj:NLogViewer x:Name="logViewerService" />
</TabItem>
</TabControl>
</DockPanel>
</Window>
+136 -11
View File
@@ -1,9 +1,16 @@
using ColorControl.Common;
using ColorControl.Forms;
using ColorControl.Native;
using ColorControl.Svc;
using DJ;
using NLog;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Navigation;
namespace ColorControl.XForms
@@ -36,9 +43,9 @@ namespace ColorControl.XForms
public static void CreateAndShow(bool show = true)
{
if (Application.Current == null)
if (System.Windows.Application.Current == null)
{
new Application();
new System.Windows.Application();
}
_window ??= new LogWindow();
@@ -46,12 +53,47 @@ namespace ColorControl.XForms
if (show)
{
_window.WindowState = WindowState.Normal;
_window.InitTheme();
_window.Show();
_window.InitThemeAfterShow();
_window.Topmost = true;
_window.Topmost = false;
}
}
protected void InitThemeAfterShow()
{
var useDarkTheme = DarkModeUtils.UseDarkMode;
var handle = new WindowInteropHelper(_window).Handle;
var value = useDarkTheme ? 1 : 0;
// Takes care of title bar
WinApi.DwmSetWindowAttribute(handle, DarkModeUtils.DWMWA_USE_IMMERSIVE_DARK_MODE, ref value, 4);
}
protected void InitTheme()
{
if (DarkModeUtils.UseDarkMode)
{
var dict = new ResourceDictionary { Source = new Uri($"Themes/DarkTheme.xaml", UriKind.Relative) };
if (Application.Current.Resources.MergedDictionaries.Any())
{
Application.Current.Resources.MergedDictionaries[0] = dict;
}
else
{
Application.Current.Resources.MergedDictionaries.Add(dict);
}
}
else
{
Application.Current.Resources.MergedDictionaries.Clear();
}
}
protected override void OnClosing(CancelEventArgs e)
{
e.Cancel = true;
@@ -72,19 +114,47 @@ namespace ColorControl.XForms
private void RawLog_Click(object sender, RoutedEventArgs e)
{
var context = AppContext.CurrentContext;
var logFile = Path.Combine(context.DataPath, "LogFile.txt");
string logFile;
if (tabControl.SelectedIndex == 0)
{
logFile = Program.LogFilename;
}
else
{
if (!Utils.IsServiceRunning())
{
MessageForms.WarningOk("Service is not running");
return;
}
var message = new SvcMessage { MessageType = SvcMessageType.GetLog };
var result = PipeUtils.SendMessage(message);
var logData = result?.Data ?? "Cannot get log from service";
logFile = Path.Combine(Path.GetTempPath(), "CCServiceLogFile.txt");
Utils.WriteText(logFile, logData);
}
if (!File.Exists(logFile))
{
MessageForms.WarningOk("Log file not found.");
return;
}
Utils.StartProcess(logFile);
}
private void LoadOlder_Click(object sender, RoutedEventArgs e)
{
var context = AppContext.CurrentContext;
var logFile = Path.Combine(context.DataPath, "LogFile.txt");
var viewer = GetCurrentViewer();
var lines = Utils.ReadLines(logFile);
var lines = LoadLog();
logViewer.LoadLines(lines);
viewer.LoadLines(lines);
}
private void Close_Click(object sender, RoutedEventArgs e)
@@ -103,17 +173,72 @@ namespace ColorControl.XForms
private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (logViewer.HasEvents())
var viewer = GetCurrentViewer();
if (viewer.HasEvents())
{
return;
}
var context = AppContext.CurrentContext;
var logFile = Path.Combine(context.DataPath, "LogFile.txt");
var lines = Utils.ReadLines(logFile);
var lines = LoadLog();
logViewer.LoadLines(lines, context.StartTime);
viewer.LoadLines(lines, context.StartTime);
}
private List<string> LoadLog()
{
string logFile;
if (tabControl.SelectedIndex == 0)
{
return Utils.ReadLines(Program.LogFilename);
}
if (Utils.IsServiceRunning())
{
var message = new SvcMessage { MessageType = SvcMessageType.GetLog };
var result = PipeUtils.SendMessage(message);
logFile = result?.Data ?? "Cannot get log from service";
}
else
{
logFile = "The service is not installed or not running";
}
return logFile.Split("\r\n").ToList();
}
private NLogViewer GetCurrentViewer()
{
return tabControl.SelectedIndex == 0 ? logViewerApplication : logViewerService;
}
private void DeleteLog_Click(object sender, RoutedEventArgs e)
{
if (MessageForms.QuestionYesNo("Are you sure you want to delete the log? This will clear all logging.") != System.Windows.Forms.DialogResult.Yes)
{
return;
}
if (tabControl.SelectedIndex == 0)
{
var filename = Program.LogFilename;
if (File.Exists(filename))
{
File.Delete(filename);
}
logViewerApplication.ClearCommand.Execute(null);
}
else
{
PipeUtils.SendMessage(SvcMessageType.ClearLog);
logViewerService.ClearCommand.Execute(null);
}
}
}
}
+32 -20
View File
@@ -123,14 +123,6 @@
</ListView.ItemContainerStyle>
<ListView.View>
<helper:AutoSizedGridView>
<GridViewColumn Header="ID" Width="40">
<GridViewColumn.DisplayMemberBinding>
<MultiBinding Converter="{StaticResource ILogEventResolverToStringConverter}">
<Binding Path="."/>
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=dj:NLogViewer}" Path="IdResolver"/>
</MultiBinding>
</GridViewColumn.DisplayMemberBinding>
</GridViewColumn>
<GridViewColumn Header="Level" Width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
@@ -172,20 +164,40 @@
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="TimeStamp" Width="Auto">
<GridViewColumn.DisplayMemberBinding>
<MultiBinding Converter="{StaticResource ILogEventResolverToStringConverter}">
<Binding Path="."/>
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=dj:NLogViewer}" Path="TimeStampResolver"/>
</MultiBinding>
</GridViewColumn.DisplayMemberBinding>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox
IsReadOnly="True"
Background="Transparent"
BorderThickness="0"
Foreground="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListViewItem}, Path=Foreground}">
<TextBox.Text>
<MultiBinding Converter="{StaticResource ILogEventResolverToStringConverter}">
<Binding Path="."/>
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=dj:NLogViewer}" Path="TimeStampResolver"/>
</MultiBinding>
</TextBox.Text>
</TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="LoggerName" Width="Auto">
<GridViewColumn.DisplayMemberBinding>
<MultiBinding Converter="{StaticResource ILogEventResolverToStringConverter}">
<Binding Path="."/>
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=dj:NLogViewer}" Path="LoggerNameResolver"/>
</MultiBinding>
</GridViewColumn.DisplayMemberBinding>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox
IsReadOnly="True"
Background="Transparent"
BorderThickness="0"
Foreground="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListViewItem}, Path=Foreground}">
<TextBox.Text>
<MultiBinding Converter="{StaticResource ILogEventResolverToStringConverter}">
<Binding Path="."/>
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=dj:NLogViewer}" Path="LoggerNameResolver"/>
</MultiBinding>
</TextBox.Text>
</TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Message" Width="Auto" listViewLayoutManager:RangeColumn.IsFillColumn="True">
<GridViewColumn.CellTemplate>
+8 -1
View File
@@ -562,9 +562,16 @@ namespace DJ
if (lastEventInfo != null && !string.IsNullOrWhiteSpace(line))
{
lastEventInfo.Message += "\r\n" + line;
continue;
}
continue;
if (lines.Count > 1)
{
continue;
}
parts = new string[] { DateTime.Now.ToString(), "info", "", line };
}
var timeStamp = DateTime.Parse(parts[0]);
-6
View File
@@ -1,6 +0,0 @@
{
"sdk": {
"version": "6.0.101",
"rollForward": "disable"
}
}