From e82768167e4dca0d9ff127eb5d17f5f838f2c410 Mon Sep 17 00:00:00 2001 From: Ondrej Salplachta Date: Sat, 23 Jan 2021 19:56:38 +0100 Subject: [PATCH] Ability to show / hide context menu "Browse for Logs" in Windows Explorer. Closes #19. --- Src/AdvancedLogViewer/History.xml | 3 +- .../UI/SettingsDlg.Designer.cs | 16 ++++++++ Src/AdvancedLogViewer/UI/SettingsDlg.cs | 39 +++++++++++++++++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/Src/AdvancedLogViewer/History.xml b/Src/AdvancedLogViewer/History.xml index 591e313..344a5ae 100644 --- a/Src/AdvancedLogViewer/History.xml +++ b/Src/AdvancedLogViewer/History.xml @@ -1,7 +1,8 @@  - Based on feature request #24: Added support for tabs beside spaces in custom patterns. It's a new keyword $Tabs$. Also both the existing $Spaces$ and new one $Tabs$ are shown in the help below the edit box. + Feature request #24: Added support for tabs beside spaces in custom patterns. It's a new keyword $Tabs$. Also both the existing $Spaces$ and new one $Tabs$ are shown in the help below the edit box. + Feature request #19: Ability to show / hide context menu "Browse for Logs" in Windows Explorer. Option is in Settings->System Integration This is the first version built in .NET 5 as self-contained application. Thus it doesn't need any .NET framework to be installed on the target machine. Because of that, the app is compiled for both x86 and x64 environments with appropriate embedded framework inside. This change increased installer size to ~20 MB but benefit of not requiring installed specific .NET framework won over the increased size of binaries. There is visible performance boost mainly on bigger logs thanks to improvements in .NET 5. diff --git a/Src/AdvancedLogViewer/UI/SettingsDlg.Designer.cs b/Src/AdvancedLogViewer/UI/SettingsDlg.Designer.cs index 951b7df..55349a0 100644 --- a/Src/AdvancedLogViewer/UI/SettingsDlg.Designer.cs +++ b/Src/AdvancedLogViewer/UI/SettingsDlg.Designer.cs @@ -58,6 +58,7 @@ private void InitializeComponent() this.label1 = new System.Windows.Forms.Label(); this.extDiffPathEdit = new System.Windows.Forms.TextBox(); this.associateWithAlvCheckBox = new System.Windows.Forms.CheckBox(); + this.showBrowseWithAlvCheckBox = new System.Windows.Forms.CheckBox(); this.totalCmdStatusLabel = new System.Windows.Forms.Label(); this.integrateWithTotalCmdCheckBox = new System.Windows.Forms.CheckBox(); this.label8 = new System.Windows.Forms.Label(); @@ -415,6 +416,19 @@ private void InitializeComponent() this.associateWithAlvCheckBox.TabIndex = 6; this.associateWithAlvCheckBox.Text = "Associate *.LOG files with this Advanced Log Viewer application."; this.associateWithAlvCheckBox.UseVisualStyleBackColor = true; + // + // showBrowseWithAlvCheckBox + // + this.showBrowseWithAlvCheckBox.AutoSize = true; + this.showBrowseWithAlvCheckBox.Location = new System.Drawing.Point(17, 80); + this.showBrowseWithAlvCheckBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.showBrowseWithAlvCheckBox.Name = "showBrowseWithAlvCheckBox"; + this.showBrowseWithAlvCheckBox.Size = new System.Drawing.Size(364, 19); + this.showBrowseWithAlvCheckBox.TabIndex = 6; + this.showBrowseWithAlvCheckBox.Text = "Show \"Browse for Logs\" in Windows Explorer's context menu on each folder."; + this.showBrowseWithAlvCheckBox.UseVisualStyleBackColor = true; + + // // totalCmdStatusLabel // @@ -652,6 +666,7 @@ private void InitializeComponent() // totalCmdTab // this.totalCmdTab.Controls.Add(this.associateWithAlvCheckBox); + this.totalCmdTab.Controls.Add(this.showBrowseWithAlvCheckBox); this.totalCmdTab.Controls.Add(this.totalCmdStatusLabel); this.totalCmdTab.Controls.Add(this.integrateWithTotalCmdCheckBox); this.totalCmdTab.ImageIndex = 1; @@ -817,6 +832,7 @@ private void InitializeComponent() private System.Windows.Forms.Label label13; private System.Windows.Forms.TextBox extTextEditPathEdit; private System.Windows.Forms.CheckBox associateWithAlvCheckBox; + private System.Windows.Forms.CheckBox showBrowseWithAlvCheckBox; private System.Windows.Forms.CheckBox showLogIconsCheckBox; private System.Windows.Forms.CheckBox messageWordWrapCheckBox; private System.Windows.Forms.Button DefaultFontButton; diff --git a/Src/AdvancedLogViewer/UI/SettingsDlg.cs b/Src/AdvancedLogViewer/UI/SettingsDlg.cs index 7f602e6..af219f6 100644 --- a/Src/AdvancedLogViewer/UI/SettingsDlg.cs +++ b/Src/AdvancedLogViewer/UI/SettingsDlg.cs @@ -15,6 +15,8 @@ using AdvancedLogViewer.BL.LogBrowser; using Scarfsail.Common.BL; using System.Reflection; +using Microsoft.Win32; +using AdvancedLogViewer.Common; namespace AdvancedLogViewer.UI { @@ -24,6 +26,7 @@ public partial class SettingsDlg : Form TotalCmdIntegration totalCmd; LogBrowserSettings logBrowser; bool alvWasAssociated; + bool explorerContextMenuWasPresent; private static Scarfsail.Logging.Log log = new Scarfsail.Logging.Log(); public SettingsDlg(AlvSettings alvSettings, bool firstTimeShown) @@ -85,6 +88,17 @@ public SettingsDlg(AlvSettings alvSettings, bool firstTimeShown) MessageBox.Show("Can't get information about associated application with LOG extension. Run ALV as Administrator.", "Administration rights required", MessageBoxButtons.OK, MessageBoxIcon.Error); associateWithAlvCheckBox.Enabled = false; } + try + { + explorerContextMenuWasPresent = Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Classes\Folder\Shell\Browse for Logs\command", null, null) != null; + showBrowseWithAlvCheckBox.Checked = explorerContextMenuWasPresent; + + } + catch + { + MessageBox.Show("Can't get information about explorer context menu. Run ALV as Administrator.", "Administration rights required", MessageBoxButtons.OK, MessageBoxIcon.Error); + showBrowseWithAlvCheckBox.Enabled = false; + } this.automaticUpdateEnabledCheckBox.Checked = this.settings.AutomaticUpdates.EnableAutomaticCheck; this.automaticUpdateCheckPeriodEdit.Value = this.settings.AutomaticUpdates.CheckInterval; @@ -178,12 +192,31 @@ private void okButton_Click(object sender, EventArgs e) } catch { - var msg = "Can'setassociation for the LOG extension. Run ALV as Administrator."; + var msg = "Can'set association for the LOG extension. Run ALV as Administrator."; + MessageBox.Show(msg, "Administration rights required", MessageBoxButtons.OK, MessageBoxIcon.Error); + log.Error(msg); + } + } + if (this.showBrowseWithAlvCheckBox.Enabled && this.showBrowseWithAlvCheckBox.Checked != explorerContextMenuWasPresent) + { + try + { + if (this.showBrowseWithAlvCheckBox.Checked) + { + //C:\Program Files (x86)\AdvancedLogViewer\AdvancedLogViewer.exe "%1\\" + Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Classes\Folder\Shell\Browse for Logs\command","", $"{System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName} \"%1\\\\\""); + } + else + { + Registry.CurrentUser.DeleteSubKeyTree(@"SOFTWARE\Classes\Folder\Shell\Browse for Logs"); + } + } + catch (System.Exception) + { + var msg = "Can'set explorer's context menu. Run ALV as Administrator."; MessageBox.Show(msg, "Administration rights required", MessageBoxButtons.OK, MessageBoxIcon.Error); log.Error(msg); } - - } }