From 3b0903e39e0267d21adee7ea73b2ebdf2304678e Mon Sep 17 00:00:00 2001 From: Markus Hofknecht Date: Sun, 29 Mar 2020 13:20:18 +0200 Subject: [PATCH] [Feature] CodeBuity&Refactor #49, [Feature] Code review tool #10, Version 0.9.2.12 --- Business/KeyboardInput.cs | 11 +- Business/SystemTrayMenu.cs | 13 +++ Config/MenuDefines.cs | 32 +++--- DataClasses/MenuData.cs | 4 +- DataClasses/RowData.cs | 46 ++++---- GlobalSuppressions.cs | 8 -- Helpers/KeyboardHook.cs | 14 +-- Helpers/Taskbar.cs | 1 + NativeDllImport/GetIcon.cs | 55 +++++----- NativeDllImport/SHAppBarMessage.cs | 12 +-- NativeDllImport/SHGetFileInfo.cs | 4 +- NativeDllImport/TrackPopupMenuEx.cs | 4 +- Properties/AssemblyInfo.cs | 4 +- SystemTrayMenu.csproj | 11 +- UserInterface/AboutBox.cs | 60 ++++++----- UserInterface/AppContextMenu.cs | 2 +- UserInterface/Menu.cs | 3 +- .../ShellContextMenu/HookEventArgs.cs | 11 -- UserInterface/ShellContextMenu/HookType.cs | 21 ---- .../ShellContextMenu/LocalWindowsHook.cs | 100 ------------------ .../ShellContextMenu/ShellContextMenu.cs | 31 ------ .../ShellContextMenuException.cs | 22 +++- Utilities/File/FileLnk.cs | 7 +- Utilities/File/IconReader.cs | 4 +- 24 files changed, 166 insertions(+), 314 deletions(-) delete mode 100644 GlobalSuppressions.cs delete mode 100644 UserInterface/ShellContextMenu/HookEventArgs.cs delete mode 100644 UserInterface/ShellContextMenu/HookType.cs delete mode 100644 UserInterface/ShellContextMenu/LocalWindowsHook.cs diff --git a/Business/KeyboardInput.cs b/Business/KeyboardInput.cs index fb6c399..1ab7572 100644 --- a/Business/KeyboardInput.cs +++ b/Business/KeyboardInput.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Linq; using System.Windows.Forms; using SystemTrayMenu.DataClasses; @@ -98,7 +99,7 @@ namespace SystemTrayMenu.Handler char.IsWhiteSpace(e.KeyChar) || char.IsSeparator(e.KeyChar)) { - string letter = e.KeyChar.ToString(); + string letter = e.KeyChar.ToString(CultureInfo.InvariantCulture); timerKeySearch.Stop(); @@ -108,7 +109,7 @@ namespace SystemTrayMenu.Handler KeySearchString += letter; SelectByKey(Keys.None, KeySearchString); } - else if (KeySearchString.Length == 1 && KeySearchString.LastOrDefault().ToString() == letter) + else if (KeySearchString.Length == 1 && KeySearchString.LastOrDefault().ToString(CultureInfo.InvariantCulture) == letter) { // initial letter pressed again, jump to next element SelectByKey(Keys.None, letter); @@ -169,8 +170,8 @@ namespace SystemTrayMenu.Handler { if (KeepSelection) { - // Is current selection is still valid for this search then skip selecting different item - if (textselected.ToLower().StartsWith(keyInput.ToLower())) + // If current selection is still valid for this search then skip selecting different item + if (textselected.StartsWith(keyInput, true, CultureInfo.InvariantCulture)) { return; } @@ -380,7 +381,7 @@ namespace SystemTrayMenu.Handler DataGridViewRow row = dgv.Rows[i]; RowData rowData = (RowData)row.Tag; string text = row.Cells[1].Value.ToString(); - if (text.ToLower().StartsWith(keyInput.ToLower())) + if (text.StartsWith(keyInput, true, CultureInfo.InvariantCulture)) { iRowKey = rowData.RowIndex; rowData.IsSelectedByKeyboard = true; diff --git a/Business/SystemTrayMenu.cs b/Business/SystemTrayMenu.cs index 85b6711..a0bf4a0 100644 --- a/Business/SystemTrayMenu.cs +++ b/Business/SystemTrayMenu.cs @@ -214,6 +214,7 @@ namespace SystemTrayMenu public void Dispose() { + worker.Dispose(); keyboardInput.Dispose(); menuNotifyIcon.Dispose(); fastLeave.Dispose(); @@ -402,6 +403,18 @@ namespace SystemTrayMenu Log.Info($"UnauthorizedAccessException:'{path}'"); menuData.Validity = MenuDataValidity.NoAccess; } + //catch (PathTooLongException ex) + //{ + + //} + //catch (DirectoryNotFoundException ex) + //{ + + //} + //catch (IOException ex) + //{ + + //} catch (Exception ex) { Log.Error($"path:'{path}'", ex); diff --git a/Config/MenuDefines.cs b/Config/MenuDefines.cs index 188c3e9..6519b89 100644 --- a/Config/MenuDefines.cs +++ b/Config/MenuDefines.cs @@ -7,14 +7,14 @@ namespace SystemTrayMenu { public static readonly List Languages = new List() { "en", "de" }; - public static Color File = Color.White; - public static Color Folder = Color.White; - public static Color ColorSelectedItem = AppColors.Blue; - public static Color ColorOpenFolder = AppColors.Green; - public static Color ColorTitleWarning = AppColors.Red; - public static Color ColorTitleSelected = AppColors.Yellow; - public static Color ColorTitleBackground = AppColors.YellowSlightly; - public static int KeySearchInterval = 1000; + public static readonly Color File = Color.White; + public static readonly Color Folder = Color.White; + public static readonly Color ColorSelectedItem = AppColors.Blue; + public static readonly Color ColorOpenFolder = AppColors.Green; + public static readonly Color ColorTitleWarning = AppColors.Red; + public static readonly Color ColorTitleSelected = AppColors.Yellow; + public static readonly Color ColorTitleBackground = AppColors.YellowSlightly; + public const int KeySearchInterval = 1000; public const int MenuRowsHeight = 18; public const int LengthMax = 37; public const int Scrollspeed = 4; @@ -28,17 +28,17 @@ namespace SystemTrayMenu public const double OpacityOutStep = 0.05; public const double OpacityHalfStep = 0.01; public const int MenusMax = 50; - public static int MaxClicksInQueue = 1; + public const int MaxClicksInQueue = 1; } public static class AppColors { - public static Color Blue = Color.FromArgb(204, 232, 255); - public static Color BlueSelectedInactive = Color.FromArgb(217, 217, 217); - public static Color Green = Color.FromArgb(194, 245, 222); - public static Color GreenBackgroundInactive = Color.FromArgb(217, 217, 217); - public static Color Red = Color.FromArgb(255, 204, 232); - public static Color Yellow = Color.LightYellow; - public static Color YellowSlightly = Color.Azure; + public static readonly Color Blue = Color.FromArgb(204, 232, 255); + public static readonly Color BlueSelectedInactive = Color.FromArgb(217, 217, 217); + public static readonly Color Green = Color.FromArgb(194, 245, 222); + public static readonly Color GreenBackgroundInactive = Color.FromArgb(217, 217, 217); + public static readonly Color Red = Color.FromArgb(255, 204, 232); + public static readonly Color Yellow = Color.LightYellow; + public static readonly Color YellowSlightly = Color.Azure; } } \ No newline at end of file diff --git a/DataClasses/MenuData.cs b/DataClasses/MenuData.cs index 2056ed7..ef9a562 100644 --- a/DataClasses/MenuData.cs +++ b/DataClasses/MenuData.cs @@ -2,14 +2,14 @@ namespace SystemTrayMenu.DataClasses { - public enum MenuDataValidity + internal enum MenuDataValidity { Valid, Invalid, NoAccess } - public struct MenuData + internal struct MenuData { public List RowDatas; public MenuDataValidity Validity; diff --git a/DataClasses/RowData.cs b/DataClasses/RowData.cs index a5a941e..5774454 100644 --- a/DataClasses/RowData.cs +++ b/DataClasses/RowData.cs @@ -18,25 +18,25 @@ namespace SystemTrayMenu.DataClasses public class RowData : IDisposable { public event Action OpenMenu; - public BackgroundWorker Reading = new BackgroundWorker(); - public FileInfo FileInfo; - public Menu SubMenu; - public Icon Icon; - public bool IsSelected; - public bool IsSelectedByKeyboard; - public bool ContainsMenu; - public bool IsContextMenuOpen; - public bool ResolvedFileNotFound; - public bool IsResolvedLnk; - public bool IsLoading = false; - public bool RestartLoading = false; - public bool HiddenEntry; - public string WorkingDirectory; - public string Arguments; - public string TargetFilePath; - public string TargetFilePathOrig; - public string Text; - public int RowIndex; + internal BackgroundWorker Reading = new BackgroundWorker(); + internal FileInfo FileInfo; + internal Menu SubMenu; + internal Icon Icon; + internal bool IsSelected; + internal bool IsSelectedByKeyboard; + internal bool ContainsMenu; + internal bool IsContextMenuOpen; + internal bool ResolvedFileNotFound; + internal bool IsResolvedLnk; + internal bool IsLoading = false; + internal bool RestartLoading = false; + internal bool HiddenEntry; + internal string WorkingDirectory; + internal string Arguments; + internal string TargetFilePath; + internal string TargetFilePathOrig; + internal string Text; + internal int RowIndex; private readonly WaitMenuOpen waitMenuOpen = new WaitMenuOpen(); private bool isDisposed = false; @@ -279,16 +279,16 @@ namespace SystemTrayMenu.DataClasses try { //https://stackoverflow.com/questions/31627801/ - Process p = new Process + using (Process p = new Process()) { - StartInfo = new ProcessStartInfo(TargetFilePath) + p.StartInfo = new ProcessStartInfo(TargetFilePath) { Arguments = Arguments, WorkingDirectory = WorkingDirectory, CreateNoWindow = true - } + }; + p.Start(); }; - p.Start(); } catch (Exception ex) { diff --git a/GlobalSuppressions.cs b/GlobalSuppressions.cs deleted file mode 100644 index e26bac9..0000000 --- a/GlobalSuppressions.cs +++ /dev/null @@ -1,8 +0,0 @@ -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. - -using System.Diagnostics.CodeAnalysis; - -[assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "", Scope = "type", Target = "~T:SystemTrayMenu.Helper.HookType")] diff --git a/Helpers/KeyboardHook.cs b/Helpers/KeyboardHook.cs index 4557bc4..b241dd0 100644 --- a/Helpers/KeyboardHook.cs +++ b/Helpers/KeyboardHook.cs @@ -10,7 +10,7 @@ namespace SystemTrayMenu.Helper /// private class Window : NativeWindow, IDisposable { - private static readonly int WM_HOTKEY = 0x0312; + private const int WM_HOTKEY = 0x0312; public Window() { @@ -73,7 +73,7 @@ namespace SystemTrayMenu.Helper /// /// The modifiers that are associated with the hot key. /// The key itself that is associated with the hot key. - public void RegisterHotKey(KeyboardHookModifierKeys modifier, Keys key) + internal void RegisterHotKey(KeyboardHookModifierKeys modifier, Keys key) { // increment the counter. _currentId = _currentId + 1; @@ -88,7 +88,7 @@ namespace SystemTrayMenu.Helper /// /// A hot key has been pressed. /// - public event EventHandler KeyPressed; + internal event EventHandler KeyPressed; #region IDisposable Members @@ -110,7 +110,7 @@ namespace SystemTrayMenu.Helper /// /// Event Args for the event that is fired after the hot key has been pressed. /// - public class KeyPressedEventArgs : EventArgs + internal class KeyPressedEventArgs : EventArgs { private readonly KeyboardHookModifierKeys _modifier; private readonly Keys _key; @@ -121,16 +121,16 @@ namespace SystemTrayMenu.Helper _key = key; } - public KeyboardHookModifierKeys Modifier => _modifier; + internal KeyboardHookModifierKeys Modifier => _modifier; - public Keys Key => _key; + internal Keys Key => _key; } /// /// The enumeration of possible modifiers. /// [Flags] - public enum KeyboardHookModifierKeys : uint + internal enum KeyboardHookModifierKeys : uint { Alt = 1, Control = 2, diff --git a/Helpers/Taskbar.cs b/Helpers/Taskbar.cs index 404ec02..cf1f55c 100644 --- a/Helpers/Taskbar.cs +++ b/Helpers/Taskbar.cs @@ -14,6 +14,7 @@ namespace SystemTrayMenu.Helper.Taskbar Bottom, } + //Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager do not have the bounds implemented? public sealed class Taskbar { private const string ClassName = "Shell_TrayWnd"; diff --git a/NativeDllImport/GetIcon.cs b/NativeDllImport/GetIcon.cs index 7917167..438b54b 100644 --- a/NativeDllImport/GetIcon.cs +++ b/NativeDllImport/GetIcon.cs @@ -5,33 +5,36 @@ namespace SystemTrayMenu.NativeDllImport { public static partial class NativeMethods { - [StructLayout(LayoutKind.Sequential)] - public struct SHITEMID - { - public ushort cb; - [MarshalAs(UnmanagedType.LPArray)] - public byte[] abID; - } + //[StructLayout(LayoutKind.Sequential)] + //[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "")] + //internal struct SHITEMID + //{ + // public ushort cb; + // [MarshalAs(UnmanagedType.LPArray)] + // public byte[] abID; + //} - [StructLayout(LayoutKind.Sequential)] - public struct ITEMIDLIST - { - public SHITEMID mkid; - } + //[StructLayout(LayoutKind.Sequential)] + //[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "")] + //internal struct ITEMIDLIST + //{ + // public SHITEMID mkid; + //} - [StructLayout(LayoutKind.Sequential)] - public struct BROWSEINFO - { - public IntPtr hwndOwner; - public IntPtr pidlRoot; - public IntPtr pszDisplayName; - [MarshalAs(UnmanagedType.LPTStr)] - public string lpszTitle; - public uint ulFlags; - public IntPtr lpfn; - public int lParam; - public IntPtr iImage; - } + //[StructLayout(LayoutKind.Sequential)] + //[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "")] + //internal struct BROWSEINFO + //{ + // public IntPtr hwndOwner; + // public IntPtr pidlRoot; + // public IntPtr pszDisplayName; + // [MarshalAs(UnmanagedType.LPTStr)] + // public string lpszTitle; + // public uint ulFlags; + // public IntPtr lpfn; + // public int lParam; + // public IntPtr iImage; + //} // Browsing for directory. //public const uint BIF_RETURNONLYFSDIRS = 0x0001; @@ -78,7 +81,7 @@ namespace SystemTrayMenu.NativeDllImport int i, int flags); - public static void Comctl32ImageList_GetIcon(IntPtr hIcon) + public static void Comctl32ImageListGetIcon(IntPtr hIcon) { _ = DestroyIcon(hIcon); } diff --git a/NativeDllImport/SHAppBarMessage.cs b/NativeDllImport/SHAppBarMessage.cs index 54b85c6..f030a77 100644 --- a/NativeDllImport/SHAppBarMessage.cs +++ b/NativeDllImport/SHAppBarMessage.cs @@ -8,12 +8,12 @@ namespace SystemTrayMenu.NativeDllImport [DllImport("shell32.dll", SetLastError = true)] private static extern IntPtr SHAppBarMessage(ABM dwMessage, [In] ref APPBARDATA pData); - public static IntPtr Shell32SHAppBarMessage(ABM dwMessage, [In] ref APPBARDATA pData) + internal static IntPtr Shell32SHAppBarMessage(ABM dwMessage, [In] ref APPBARDATA pData) { return SHAppBarMessage(dwMessage, ref pData); } - public enum ABM : uint + internal enum ABM : uint { New = 0x00000000, Remove = 0x00000001, @@ -28,7 +28,7 @@ namespace SystemTrayMenu.NativeDllImport SetState = 0x0000000A, } - public enum ABE : uint + internal enum ABE : uint { Left = 0, Top = 1, @@ -36,14 +36,14 @@ namespace SystemTrayMenu.NativeDllImport Bottom = 3 } - public static class ABS + internal static class ABS { public const int Autohide = 0x0000001; public const int AlwaysOnTop = 0x0000002; } [StructLayout(LayoutKind.Sequential)] - public struct APPBARDATA + internal struct APPBARDATA { public uint cbSize; public IntPtr hWnd; @@ -54,7 +54,7 @@ namespace SystemTrayMenu.NativeDllImport } [StructLayout(LayoutKind.Sequential)] - public struct RECT + internal struct RECT { public int left; public int top; diff --git a/NativeDllImport/SHGetFileInfo.cs b/NativeDllImport/SHGetFileInfo.cs index c7e6381..c7b2894 100644 --- a/NativeDllImport/SHGetFileInfo.cs +++ b/NativeDllImport/SHGetFileInfo.cs @@ -16,7 +16,7 @@ namespace SystemTrayMenu.NativeDllImport uint uFlags ); - public static IntPtr Shell32SHGetFileInfo( + internal static IntPtr Shell32SHGetFileInfo( string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, @@ -32,7 +32,7 @@ namespace SystemTrayMenu.NativeDllImport } [StructLayout(LayoutKind.Sequential)] - public struct SHFILEINFO + internal struct SHFILEINFO { public const int NAMESIZE = 80; public IntPtr hIcon; diff --git a/NativeDllImport/TrackPopupMenuEx.cs b/NativeDllImport/TrackPopupMenuEx.cs index 160938a..41ebd40 100644 --- a/NativeDllImport/TrackPopupMenuEx.cs +++ b/NativeDllImport/TrackPopupMenuEx.cs @@ -9,14 +9,14 @@ namespace SystemTrayMenu.NativeDllImport [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)] private static extern uint TrackPopupMenuEx(IntPtr hmenu, TPM flags, int x, int y, IntPtr hwnd, IntPtr lptpm); - public static uint User32TrackPopupMenuEx(IntPtr hmenu, TPM flags, int x, int y, IntPtr hwnd, IntPtr lptpm) + internal static uint User32TrackPopupMenuEx(IntPtr hmenu, TPM flags, int x, int y, IntPtr hwnd, IntPtr lptpm) { return TrackPopupMenuEx(hmenu, flags, x, y, hwnd, lptpm); } // Specifies how TrackPopupMenuEx positions the shortcut menu horizontally [Flags] - public enum TPM : uint + internal enum TPM : uint { LEFTBUTTON = 0x0000, RIGHTBUTTON = 0x0002, diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 304aadc..a90c7ae 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -35,5 +35,5 @@ using System.Runtime.InteropServices; // 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("0.9.2.11")] -[assembly: AssemblyFileVersion("0.9.2.11")] +[assembly: AssemblyVersion("0.9.2.12")] +[assembly: AssemblyFileVersion("0.9.2.12")] diff --git a/SystemTrayMenu.csproj b/SystemTrayMenu.csproj index afe6fdc..46b7e9b 100644 --- a/SystemTrayMenu.csproj +++ b/SystemTrayMenu.csproj @@ -138,7 +138,6 @@ - @@ -157,9 +156,7 @@ AskHotKeyForm.cs - - Form - + DragDropHintForm.cs @@ -181,11 +178,8 @@ - - - @@ -329,9 +323,6 @@ false - - - 2.9.8 diff --git a/UserInterface/AboutBox.cs b/UserInterface/AboutBox.cs index 5d087ca..fe11f85 100644 --- a/UserInterface/AboutBox.cs +++ b/UserInterface/AboutBox.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Specialized; using System.Drawing; +using System.Globalization; using System.IO; using System.Reflection; using System.Text.RegularExpressions; @@ -220,7 +221,7 @@ namespace SystemTrayMenu.UserInterface } else { - dt = DateTime.Parse("01/01/2000").AddDays(AssemblyVersion.Build).AddSeconds(AssemblyVersion.Revision * 2); + dt = DateTime.Parse("01/01/2000", CultureInfo.InvariantCulture).AddDays(AssemblyVersion.Build).AddSeconds(AssemblyVersion.Revision * 2); if (TimeZone.IsDaylightSavingTime(dt, TimeZone.CurrentTimeZone.GetDaylightChanges(dt.Year))) { dt = dt.AddHours(1); @@ -267,35 +268,35 @@ namespace SystemTrayMenu.UserInterface switch (TypeName) { case "System.CLSCompliantAttribute": - Value = ((CLSCompliantAttribute)attrib).IsCompliant.ToString(); break; + Value = ((CLSCompliantAttribute)attrib).IsCompliant.ToString(CultureInfo.InvariantCulture); break; case "System.Diagnostics.DebuggableAttribute": - Value = ((System.Diagnostics.DebuggableAttribute)attrib).IsJITTrackingEnabled.ToString(); break; + Value = ((System.Diagnostics.DebuggableAttribute)attrib).IsJITTrackingEnabled.ToString(CultureInfo.InvariantCulture); break; case "System.Reflection.AssemblyCompanyAttribute": - Value = ((AssemblyCompanyAttribute)attrib).Company.ToString(); break; + Value = ((AssemblyCompanyAttribute)attrib).Company.ToString(CultureInfo.InvariantCulture); break; case "System.Reflection.AssemblyConfigurationAttribute": - Value = ((AssemblyConfigurationAttribute)attrib).Configuration.ToString(); break; + Value = ((AssemblyConfigurationAttribute)attrib).Configuration.ToString(CultureInfo.InvariantCulture); break; case "System.Reflection.AssemblyCopyrightAttribute": - Value = ((AssemblyCopyrightAttribute)attrib).Copyright.ToString(); break; + Value = ((AssemblyCopyrightAttribute)attrib).Copyright.ToString(CultureInfo.InvariantCulture); break; case "System.Reflection.AssemblyDefaultAliasAttribute": - Value = ((AssemblyDefaultAliasAttribute)attrib).DefaultAlias.ToString(); break; + Value = ((AssemblyDefaultAliasAttribute)attrib).DefaultAlias.ToString(CultureInfo.InvariantCulture); break; case "System.Reflection.AssemblyDelaySignAttribute": - Value = ((AssemblyDelaySignAttribute)attrib).DelaySign.ToString(); break; + Value = ((AssemblyDelaySignAttribute)attrib).DelaySign.ToString(CultureInfo.InvariantCulture); break; case "System.Reflection.AssemblyDescriptionAttribute": - Value = ((AssemblyDescriptionAttribute)attrib).Description.ToString(); break; + Value = ((AssemblyDescriptionAttribute)attrib).Description.ToString(CultureInfo.InvariantCulture); break; case "System.Reflection.AssemblyInformationalVersionAttribute": - Value = ((AssemblyInformationalVersionAttribute)attrib).InformationalVersion.ToString(); break; + Value = ((AssemblyInformationalVersionAttribute)attrib).InformationalVersion.ToString(CultureInfo.InvariantCulture); break; case "System.Reflection.AssemblyKeyFileAttribute": - Value = ((AssemblyKeyFileAttribute)attrib).KeyFile.ToString(); break; + Value = ((AssemblyKeyFileAttribute)attrib).KeyFile.ToString(CultureInfo.InvariantCulture); break; case "System.Reflection.AssemblyProductAttribute": - Value = ((AssemblyProductAttribute)attrib).Product.ToString(); break; + Value = ((AssemblyProductAttribute)attrib).Product.ToString(CultureInfo.InvariantCulture); break; case "System.Reflection.AssemblyTrademarkAttribute": - Value = ((AssemblyTrademarkAttribute)attrib).Trademark.ToString(); break; + Value = ((AssemblyTrademarkAttribute)attrib).Trademark.ToString(CultureInfo.InvariantCulture); break; case "System.Reflection.AssemblyTitleAttribute": - Value = ((AssemblyTitleAttribute)attrib).Title.ToString(); break; + Value = ((AssemblyTitleAttribute)attrib).Title.ToString(CultureInfo.InvariantCulture); break; case "System.Resources.NeutralResourcesLanguageAttribute": - Value = ((System.Resources.NeutralResourcesLanguageAttribute)attrib).CultureName.ToString(); break; + Value = ((System.Resources.NeutralResourcesLanguageAttribute)attrib).CultureName.ToString(CultureInfo.InvariantCulture); break; case "System.Resources.SatelliteContractVersionAttribute": - Value = ((System.Resources.SatelliteContractVersionAttribute)attrib).Version.ToString(); break; + Value = ((System.Resources.SatelliteContractVersionAttribute)attrib).Version.ToString(CultureInfo.InvariantCulture); break; case "System.Runtime.InteropServices.ComCompatibleVersionAttribute": { System.Runtime.InteropServices.ComCompatibleVersionAttribute x; @@ -303,9 +304,9 @@ namespace SystemTrayMenu.UserInterface Value = x.MajorVersion + "." + x.MinorVersion + "." + x.RevisionNumber + "." + x.BuildNumber; break; } case "System.Runtime.InteropServices.ComVisibleAttribute": - Value = ((System.Runtime.InteropServices.ComVisibleAttribute)attrib).Value.ToString(); break; + Value = ((System.Runtime.InteropServices.ComVisibleAttribute)attrib).Value.ToString(CultureInfo.InvariantCulture); break; case "System.Runtime.InteropServices.GuidAttribute": - Value = ((System.Runtime.InteropServices.GuidAttribute)attrib).Value.ToString(); break; + Value = ((System.Runtime.InteropServices.GuidAttribute)attrib).Value.ToString(CultureInfo.InvariantCulture); break; case "System.Runtime.InteropServices.TypeLibVersionAttribute": { System.Runtime.InteropServices.TypeLibVersionAttribute x; @@ -343,7 +344,7 @@ namespace SystemTrayMenu.UserInterface } else { - nvc.Add("BuildDate", dt.ToString("yyyy-MM-dd hh:mm tt")); + nvc.Add("BuildDate", dt.ToString("yyyy-MM-dd hh:mm tt", CultureInfo.InvariantCulture)); } // location try @@ -524,7 +525,7 @@ namespace SystemTrayMenu.UserInterface } else { - return _EntryAssemblyAttribCollection[strName].ToString(); + return _EntryAssemblyAttribCollection[strName].ToString(CultureInfo.InvariantCulture); } } @@ -584,7 +585,7 @@ namespace SystemTrayMenu.UserInterface s = s.Replace("%company%", EntryAssemblyAttrib("company")); s = s.Replace("%product%", EntryAssemblyAttrib("product")); s = s.Replace("%trademark%", EntryAssemblyAttrib("trademark")); - s = s.Replace("%year%", DateTime.Now.Year.ToString()); + s = s.Replace("%year%", DateTime.Now.Year.ToString(CultureInfo.InvariantCulture)); s = s.Replace("%version%", EntryAssemblyAttrib("version")); s = s.Replace("%builddate%", EntryAssemblyAttrib("builddate")); return s; @@ -599,7 +600,7 @@ namespace SystemTrayMenu.UserInterface // this assembly property is only available in framework versions 1.1+ Populate(lvw, "Image Runtime Version", a.ImageRuntimeVersion); - Populate(lvw, "Loaded from GAC", a.GlobalAssemblyCache.ToString()); + Populate(lvw, "Loaded from GAC", a.GlobalAssemblyCache.ToString(CultureInfo.InvariantCulture)); NameValueCollection nvc = AssemblyAttribs(a); foreach (string strKey in nvc) @@ -714,7 +715,7 @@ namespace SystemTrayMenu.UserInterface string strAssemblyName; if (AssemblyInfoListView.SelectedItems.Count > 0) { - strAssemblyName = Convert.ToString(AssemblyInfoListView.SelectedItems[0].Tag); + strAssemblyName = Convert.ToString(AssemblyInfoListView.SelectedItems[0].Tag, CultureInfo.InvariantCulture); AssemblyNamesComboBox.SelectedIndex = AssemblyNamesComboBox.FindStringExact(strAssemblyName); TabPanelDetails.SelectedTab = TabPageAssemblyDetails; } @@ -725,7 +726,7 @@ namespace SystemTrayMenu.UserInterface // private void AssemblyNamesComboBox_SelectedIndexChanged(object sender, EventArgs e) { - string strAssemblyName = Convert.ToString(AssemblyNamesComboBox.SelectedItem); + string strAssemblyName = Convert.ToString(AssemblyNamesComboBox.SelectedItem, CultureInfo.InvariantCulture); PopulateAssemblyDetails(MatchAssemblyByName(strAssemblyName), AssemblyDetailsListView); } @@ -738,9 +739,9 @@ namespace SystemTrayMenu.UserInterface if (AssemblyInfoListView.Tag != null) { - if (Math.Abs(Convert.ToInt32(AssemblyInfoListView.Tag)) == intTargetCol) + if (Math.Abs(Convert.ToInt32(AssemblyInfoListView.Tag, CultureInfo.InvariantCulture)) == intTargetCol) { - intTargetCol = -Convert.ToInt32(AssemblyInfoListView.Tag); + intTargetCol = -Convert.ToInt32(AssemblyInfoListView.Tag, CultureInfo.InvariantCulture); } } AssemblyInfoListView.Tag = intTargetCol; @@ -790,9 +791,10 @@ namespace SystemTrayMenu.UserInterface public int Compare(object x, object y) { - int intResult = - string.Compare(((ListViewItem)x).SubItems[_intCol].Text, ((ListViewItem)y).SubItems[_intCol].Text); - + int intResult = string.Compare( + ((ListViewItem)x).SubItems[_intCol].Text, + ((ListViewItem)y).SubItems[_intCol].Text, + CultureInfo.InvariantCulture, CompareOptions.None); if (_IsAscending) { return intResult; diff --git a/UserInterface/AppContextMenu.cs b/UserInterface/AppContextMenu.cs index 9bcdc53..d998916 100644 --- a/UserInterface/AppContextMenu.cs +++ b/UserInterface/AppContextMenu.cs @@ -233,7 +233,7 @@ namespace SystemTrayMenu.Helper { List cultureList = CultureInfo.GetCultures(cultureType).ToList(); cultureList.Sort((p1, p2) => string.Compare( - p1.NativeName, p2.NativeName, true)); + p1.NativeName, p2.NativeName, true, CultureInfo.InvariantCulture)); return cultureList; } diff --git a/UserInterface/Menu.cs b/UserInterface/Menu.cs index f96bf30..fa1cdf1 100644 --- a/UserInterface/Menu.cs +++ b/UserInterface/Menu.cs @@ -31,7 +31,8 @@ namespace SystemTrayMenu.UserInterface public bool IsFadingOut => FadeForm.IsFadingOut; - public int Level = 0; + internal int Level = 0; + private readonly FadeForm FadeForm = null; private bool autoResizeRowsDone = false; diff --git a/UserInterface/ShellContextMenu/HookEventArgs.cs b/UserInterface/ShellContextMenu/HookEventArgs.cs deleted file mode 100644 index 9425474..0000000 --- a/UserInterface/ShellContextMenu/HookEventArgs.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace SystemTrayMenu.Helper -{ - public class HookEventArgs : EventArgs - { - public int HookCode; // Hook code - public IntPtr wParam; // WPARAM argument - public IntPtr lParam; // LPARAM argument - } -} diff --git a/UserInterface/ShellContextMenu/HookType.cs b/UserInterface/ShellContextMenu/HookType.cs deleted file mode 100644 index 9f2ce3e..0000000 --- a/UserInterface/ShellContextMenu/HookType.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace SystemTrayMenu.Helper -{ - public enum HookType : int - { - WH_JOURNALRECORD = 0, - WH_JOURNALPLAYBACK = 1, - WH_KEYBOARD = 2, - WH_GETMESSAGE = 3, - WH_CALLWNDPROC = 4, - WH_CBT = 5, - WH_SYSMSGFILTER = 6, - WH_MOUSE = 7, - WH_HARDWARE = 8, - WH_DEBUG = 9, - WH_SHELL = 10, - WH_FOREGROUNDIDLE = 11, - WH_CALLWNDPROCRET = 12, - WH_KEYBOARD_LL = 13, - WH_MOUSE_LL = 14 - } -} diff --git a/UserInterface/ShellContextMenu/LocalWindowsHook.cs b/UserInterface/ShellContextMenu/LocalWindowsHook.cs deleted file mode 100644 index 545c147..0000000 --- a/UserInterface/ShellContextMenu/LocalWindowsHook.cs +++ /dev/null @@ -1,100 +0,0 @@ -//using System; -//using System.Runtime.InteropServices; - -//namespace SystemTrayMenu.Helper -//{ -// public class LocalWindowsHook -// { -// // ************************************************************************ -// // Filter function delegate -// public delegate int HookProc(int code, IntPtr wParam, IntPtr lParam); -// // ************************************************************************ - -// // ************************************************************************ -// // Internal properties -// protected IntPtr m_hhook = IntPtr.Zero; -// protected HookProc m_filterFunc = null; -// protected HookType m_hookType; -// // ************************************************************************ - -// // ************************************************************************ -// // Event delegate -// public delegate void HookEventHandler(object sender, HookEventArgs e); -// // ************************************************************************ - -// // ************************************************************************ -// // Event: HookInvoked -// public event HookEventHandler HookInvoked; -// protected void OnHookInvoked(HookEventArgs e) -// { -// if (HookInvoked != null) -// { -// HookInvoked(this, e); -// } -// } -// // ************************************************************************ - -// // ************************************************************************ -// // Class constructor(s) -// public LocalWindowsHook(HookType hook) -// { -// m_hookType = hook; -// m_filterFunc = new HookProc(CoreHookProc); -// } -// public LocalWindowsHook(HookType hook, HookProc func) -// { -// m_hookType = hook; -// m_filterFunc = func; -// } -// // ************************************************************************ - -// // ************************************************************************ -// // Default filter function -// protected int CoreHookProc(int code, IntPtr wParam, IntPtr lParam) -// { -// if (code < 0) -// { -// return CallNextHookEx(m_hhook, code, wParam, lParam); -// } - -// // Let clients determine what to do -// HookEventArgs e = new HookEventArgs -// { -// HookCode = code, -// wParam = wParam, -// lParam = lParam -// }; -// OnHookInvoked(e); - -// // Yield to the next hook in the chain -// return CallNextHookEx(m_hhook, code, wParam, lParam); -// } - -// public void Install() -// { -// m_hhook = SetWindowsHookEx( -// m_hookType, -// m_filterFunc, -// IntPtr.Zero, -// AppDomain.GetCurrentThreadId()); -// } - -// public void Uninstall() -// { -// UnhookWindowsHookEx(m_hhook); -// } - -// [DllImport("user32.dll")] -// protected static extern IntPtr SetWindowsHookEx(HookType code, -// HookProc func, -// IntPtr hInstance, -// int threadID); - -// [DllImport("user32.dll")] -// protected static extern int UnhookWindowsHookEx(IntPtr hhook); - -// [DllImport("user32.dll")] -// protected static extern int CallNextHookEx(IntPtr hhook, -// int code, IntPtr wParam, IntPtr lParam); -// } -//} diff --git a/UserInterface/ShellContextMenu/ShellContextMenu.cs b/UserInterface/ShellContextMenu/ShellContextMenu.cs index e245187..d1b3f8c 100644 --- a/UserInterface/ShellContextMenu/ShellContextMenu.cs +++ b/UserInterface/ShellContextMenu/ShellContextMenu.cs @@ -583,37 +583,6 @@ namespace SystemTrayMenu.Utilities } #endregion - #region WindowsHookInvoked() - /// - /// Handle messages for context menu - /// - private void WindowsHookInvoked(object sender, HookEventArgs e) - { - CWPSTRUCT cwp = (CWPSTRUCT)Marshal.PtrToStructure(e.lParam, typeof(CWPSTRUCT)); - - if (_oContextMenu2 != null && - (cwp.message == (int)WM.INITMENUPOPUP || - cwp.message == (int)WM.MEASUREITEM || - cwp.message == (int)WM.DRAWITEM)) - { - if (_oContextMenu2.HandleMenuMsg((uint)cwp.message, cwp.wparam, cwp.lparam) == S_OK) - { - return; - } - } - - if (_oContextMenu3 != null && cwp.message == (int)WM.MENUCHAR) - { - if (_oContextMenu3.HandleMenuMsg2((uint)cwp.message, cwp.wparam, cwp.lparam, IntPtr.Zero) == S_OK) - { - return; - } - } - - return; - } - #endregion - #region Local variabled private IContextMenu _oContextMenu; private IContextMenu2 _oContextMenu2; diff --git a/UserInterface/ShellContextMenu/ShellContextMenuException.cs b/UserInterface/ShellContextMenu/ShellContextMenuException.cs index d6e0b50..aa44a0f 100644 --- a/UserInterface/ShellContextMenu/ShellContextMenuException.cs +++ b/UserInterface/ShellContextMenu/ShellContextMenuException.cs @@ -1,19 +1,31 @@ using System; +using System.Runtime.Serialization; namespace SystemTrayMenu.Helper { + [Serializable] public class ShellContextMenuException : Exception { - /// Default contructor public ShellContextMenuException() { + // Add any type-specific logic, and supply the default message. } - /// Constructor with message - /// Message - public ShellContextMenuException(string message) - : base(message) + public ShellContextMenuException(string message) : base(message) { + // Add any type-specific logic. + } + + public ShellContextMenuException(string message, Exception innerException) : + base(message, innerException) + { + // Add any type-specific logic for inner exceptions. + } + + protected ShellContextMenuException(SerializationInfo info, + StreamingContext context) : base(info, context) + { + // Implement type-specific serialization constructor logic. } } diff --git a/Utilities/File/FileLnk.cs b/Utilities/File/FileLnk.cs index f63ec06..db08480 100644 --- a/Utilities/File/FileLnk.cs +++ b/Utilities/File/FileLnk.cs @@ -126,12 +126,13 @@ namespace SystemTrayMenu.Utilities public interface IPersistFile : IPersist { new void GetClassID(out Guid pClassID); + [PreserveSig] int IsDirty(); [PreserveSig] void Load([In, MarshalAs(UnmanagedType.LPWStr)] - string pszFileName, uint dwMode); + string pszFileName, uint dwMode); [PreserveSig] void Save([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName, @@ -160,8 +161,6 @@ namespace SystemTrayMenu.Utilities { ShellLink link = new ShellLink(); ((IPersistFile)link).Load(filename, STGM_READ); - // TODO: if I can get hold of the hwnd call resolve first. This handles moved and renamed files. - // ((IShellLinkW)link).Resolve(hwnd, 0) StringBuilder sb = new StringBuilder(MAX_PATH); WIN32_FIND_DATAW data = new WIN32_FIND_DATAW(); ((IShellLinkW)link).GetPath(sb, sb.Capacity, out data, 0); @@ -199,7 +198,7 @@ namespace SystemTrayMenu.Utilities public static string ReplaceFirst(string text, string search, string replace) { - int pos = text.IndexOf(search); + int pos = text.IndexOf(search, StringComparison.InvariantCulture); if (pos < 0) { return text; diff --git a/Utilities/File/IconReader.cs b/Utilities/File/IconReader.cs index 0d39b0d..49b1abe 100644 --- a/Utilities/File/IconReader.cs +++ b/Utilities/File/IconReader.cs @@ -42,8 +42,8 @@ namespace SystemTrayMenu.Utilities { bool isExtensionWitSameIcon = true; List extensionsWithDiffIcons = new List - { ".exe", ".lnk", ".ico", ".url" }; - if (extensionsWithDiffIcons.Contains(fileExtension.ToLower())) + { ".EXE", ".LNK", ".ICO", ".URL" }; + if (extensionsWithDiffIcons.Contains(fileExtension.ToUpperInvariant())) { isExtensionWitSameIcon = false; }