diff --git a/Business/Menus.cs b/Business/Menus.cs index cb703fc..0bb0560 100644 --- a/Business/Menus.cs +++ b/Business/Menus.cs @@ -12,7 +12,6 @@ namespace SystemTrayMenu.Business using System.Drawing; using System.IO; using System.Linq; - using System.Security; using System.Windows.Forms; using SystemTrayMenu.DataClasses; using SystemTrayMenu.Handler; diff --git a/Config/Config.cs b/Config/Config.cs index 158a612..2ca6b47 100644 --- a/Config/Config.cs +++ b/Config/Config.cs @@ -424,9 +424,9 @@ namespace SystemTrayMenu str = str.Replace("#585858", htmlColorCode); byteArray = Encoding.UTF8.GetBytes(str); - using (var stream = new MemoryStream(byteArray)) + using (MemoryStream stream = new MemoryStream(byteArray)) { - var svgDocument = SvgDocument.Open(stream); + SvgDocument svgDocument = SvgDocument.Open(stream); svgDocument.Color = new SvgColourServer(Color.Black); return svgDocument.Draw(); } @@ -467,7 +467,7 @@ namespace SystemTrayMenu private static void UpgradeIfNotUpgraded() { - var path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming).FilePath; + string path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming).FilePath; path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); if (!Settings.Default.IsUpgraded) { diff --git a/DataClasses/RowData.cs b/DataClasses/RowData.cs index af13e81..e48af33 100644 --- a/DataClasses/RowData.cs +++ b/DataClasses/RowData.cs @@ -6,13 +6,10 @@ namespace SystemTrayMenu.DataClasses { using System; using System.Collections.Generic; - using System.ComponentModel; using System.Data; - using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; - using System.Security; using System.Text; using System.Windows.Forms; using IWshRuntimeLibrary; @@ -292,18 +289,6 @@ namespace SystemTrayMenu.DataClasses bool handled = false; resolvedLnkPath = FileLnk.GetResolvedFileName(TargetFilePath); -#if false // FileLnk.IsDirectory was very slow if it was a network path, PingHost was still slow if not exists therefore we used IsNetworkPath - if (FileLnk.IsNetworkPath(resolvedLnkPath)) - { - string nameOrAdress = resolvedLnkPath.Split(@"\\")[1].Split(@"\").First(); - if (!FileLnk.PingHost(nameOrAdress)) - { - return handled; - } - } - - if (FileLnk.IsDirectory(resolvedLnkPath)) -#endif if (string.IsNullOrEmpty(Path.GetExtension(resolvedLnkPath))) { icon = IconReader.GetFolderIconSTA(TargetFilePath, IconReader.FolderType.Open, true); @@ -318,7 +303,6 @@ namespace SystemTrayMenu.DataClasses { Log.Info($"Resolve *.LNK '{TargetFilePath}' has no icon"); } -#if false //icons were incorrect, performance increase when removing else { IWshShell shell = new WshShell(); @@ -326,27 +310,8 @@ namespace SystemTrayMenu.DataClasses as IWshShortcut; arguments = lnk.Arguments; workingDirectory = lnk.WorkingDirectory; - string iconLocation = lnk.IconLocation; - if (iconLocation.Length > 2) - { - iconLocation = iconLocation[0..^2]; - if (System.IO.File.Exists(iconLocation)) - { - try - { - icon = Icon.ExtractAssociatedIcon(iconLocation); - handled = true; - } - catch (ArgumentException ex) - { - Log.Warn($"iconLocation:'{iconLocation}'", ex); - } - } - } - TargetFilePath = resolvedLnkPath; } -#endif SetText(Path.GetFileNameWithoutExtension(TargetFilePathOrig)); diff --git a/Helpers/DragDropHelper.cs b/Helpers/DragDropHelper.cs index ad4f112..5ad739e 100644 --- a/Helpers/DragDropHelper.cs +++ b/Helpers/DragDropHelper.cs @@ -55,7 +55,7 @@ namespace SystemTrayMenu.Helpers private static void CreateShortcut(string url, string pathToStoreFile) { string pathToStoreIcons = Path.Combine(pathToStoreFile, "ico"); - var client = new WebClient(); + WebClient client = new WebClient(); if (!Directory.Exists(pathToStoreIcons)) { Directory.CreateDirectory(pathToStoreIcons); @@ -72,7 +72,7 @@ namespace SystemTrayMenu.Helpers ImagingHelper.ConvertToIcon(pathIconPng, pathIcon, 32); File.Delete(pathIconPng); - var title = url; + string title = url; title = title.Replace("/", " "). Replace("https", string.Empty). diff --git a/Helpers/ImagingHelper.cs b/Helpers/ImagingHelper.cs index e28b2e6..2a7f8db 100644 --- a/Helpers/ImagingHelper.cs +++ b/Helpers/ImagingHelper.cs @@ -5,6 +5,7 @@ namespace SystemTrayMenu.Helpers { using System.Drawing; + using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.IO; @@ -81,7 +82,7 @@ namespace SystemTrayMenu.Helpers iconWriter.Write((int)memoryStream.Length); // 12-15 offset of image data - iconWriter.Write((int)(6 + 16)); + iconWriter.Write(6 + 16); // write image data // png data must contain the whole png data file @@ -116,5 +117,35 @@ namespace SystemTrayMenu.Helpers return ConvertToIcon(inputStream, outputStream, size, preserveAspectRatio); } } + + public static Image RotateImage(Image img, float rotationAngle) + { + // create an empty Bitmap image + Bitmap bmp = new Bitmap(img.Width, img.Height); + + // turn the Bitmap into a Graphics object + Graphics gfx = Graphics.FromImage(bmp); + + // now we set the rotation point to the center of our image + gfx.TranslateTransform(0.5f + ((float)bmp.Width / 2), 0.5f + ((float)bmp.Height / 2)); + + // now rotate the image + gfx.RotateTransform(rotationAngle); + + gfx.TranslateTransform(0.5f - ((float)bmp.Width / 2), 0.5f - ((float)bmp.Height / 2)); + + // set the InterpolationMode to HighQualityBicubic so to ensure a high + // quality image once it is transformed to the specified size + gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; + + // now draw our new image onto the graphics object + gfx.DrawImage(img, new Point(0, 0)); + + // dispose of our Graphics object + gfx.Dispose(); + + // return the image + return bmp; + } } } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 80eb5a4..3350939 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -39,5 +39,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("1.0.20.4")] -[assembly: AssemblyFileVersion("1.0.20.4")] +[assembly: AssemblyVersion("1.0.20.5")] +[assembly: AssemblyFileVersion("1.0.20.5")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 03c022a..8fd10b9 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -120,186 +120,6 @@ namespace SystemTrayMenu.Properties { } } - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L010 { - get { - object obj = ResourceManager.GetObject("L010", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L020 { - get { - object obj = ResourceManager.GetObject("L020", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L030 { - get { - object obj = ResourceManager.GetObject("L030", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L040 { - get { - object obj = ResourceManager.GetObject("L040", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L050 { - get { - object obj = ResourceManager.GetObject("L050", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L060 { - get { - object obj = ResourceManager.GetObject("L060", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L070 { - get { - object obj = ResourceManager.GetObject("L070", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L080 { - get { - object obj = ResourceManager.GetObject("L080", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L090 { - get { - object obj = ResourceManager.GetObject("L090", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L100 { - get { - object obj = ResourceManager.GetObject("L100", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L110 { - get { - object obj = ResourceManager.GetObject("L110", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L120 { - get { - object obj = ResourceManager.GetObject("L120", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L130 { - get { - object obj = ResourceManager.GetObject("L130", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L140 { - get { - object obj = ResourceManager.GetObject("L140", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L150 { - get { - object obj = ResourceManager.GetObject("L150", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L160 { - get { - object obj = ResourceManager.GetObject("L160", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L170 { - get { - object obj = ResourceManager.GetObject("L170", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// - public static System.Drawing.Icon L180 { - get { - object obj = ResourceManager.GetObject("L180", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - /// /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index db9c720..6ede001 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -118,66 +118,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\Resources\LoadingIcon\L080.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L020.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L070.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L140.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L160.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L100.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L060.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L180.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\White50Percentage.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\LoadingIcon\L150.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L120.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L170.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\SystemTrayMenu.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\LoadingIcon\L090.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L040.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L010.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L030.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L050.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L130.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\LoadingIcon\L110.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\search.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/Resources/LoadingIcon/L010.ico b/Resources/LoadingIcon/L010.ico deleted file mode 100644 index c5287ff..0000000 Binary files a/Resources/LoadingIcon/L010.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L020.ico b/Resources/LoadingIcon/L020.ico deleted file mode 100644 index 0a95231..0000000 Binary files a/Resources/LoadingIcon/L020.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L030.ico b/Resources/LoadingIcon/L030.ico deleted file mode 100644 index 09a8647..0000000 Binary files a/Resources/LoadingIcon/L030.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L040.ico b/Resources/LoadingIcon/L040.ico deleted file mode 100644 index e21a608..0000000 Binary files a/Resources/LoadingIcon/L040.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L050.ico b/Resources/LoadingIcon/L050.ico deleted file mode 100644 index 3898518..0000000 Binary files a/Resources/LoadingIcon/L050.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L060.ico b/Resources/LoadingIcon/L060.ico deleted file mode 100644 index af72fdd..0000000 Binary files a/Resources/LoadingIcon/L060.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L070.ico b/Resources/LoadingIcon/L070.ico deleted file mode 100644 index eff1c80..0000000 Binary files a/Resources/LoadingIcon/L070.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L080.ico b/Resources/LoadingIcon/L080.ico deleted file mode 100644 index c62f41f..0000000 Binary files a/Resources/LoadingIcon/L080.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L090.ico b/Resources/LoadingIcon/L090.ico deleted file mode 100644 index 34488ce..0000000 Binary files a/Resources/LoadingIcon/L090.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L100.ico b/Resources/LoadingIcon/L100.ico deleted file mode 100644 index ced488e..0000000 Binary files a/Resources/LoadingIcon/L100.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L110.ico b/Resources/LoadingIcon/L110.ico deleted file mode 100644 index edf1b5f..0000000 Binary files a/Resources/LoadingIcon/L110.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L120.ico b/Resources/LoadingIcon/L120.ico deleted file mode 100644 index b7a37a7..0000000 Binary files a/Resources/LoadingIcon/L120.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L130.ico b/Resources/LoadingIcon/L130.ico deleted file mode 100644 index 6475d85..0000000 Binary files a/Resources/LoadingIcon/L130.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L140.ico b/Resources/LoadingIcon/L140.ico deleted file mode 100644 index c29be1d..0000000 Binary files a/Resources/LoadingIcon/L140.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L150.ico b/Resources/LoadingIcon/L150.ico deleted file mode 100644 index a165b91..0000000 Binary files a/Resources/LoadingIcon/L150.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L160.ico b/Resources/LoadingIcon/L160.ico deleted file mode 100644 index b9ec506..0000000 Binary files a/Resources/LoadingIcon/L160.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L170.ico b/Resources/LoadingIcon/L170.ico deleted file mode 100644 index 243ba51..0000000 Binary files a/Resources/LoadingIcon/L170.ico and /dev/null differ diff --git a/Resources/LoadingIcon/L180.ico b/Resources/LoadingIcon/L180.ico deleted file mode 100644 index d5338b1..0000000 Binary files a/Resources/LoadingIcon/L180.ico and /dev/null differ diff --git a/UserInterface/AboutBox.cs b/UserInterface/AboutBox.cs index 80487f0..2532870 100644 --- a/UserInterface/AboutBox.cs +++ b/UserInterface/AboutBox.cs @@ -10,7 +10,6 @@ namespace SystemTrayMenu.UserInterface using System.Globalization; using System.IO; using System.Reflection; - using System.Security; using System.Text.RegularExpressions; using System.Windows.Forms; using Microsoft.Win32; diff --git a/UserInterface/AppNotifyIcon.cs b/UserInterface/AppNotifyIcon.cs index 1ef5afa..51dbb85 100644 --- a/UserInterface/AppNotifyIcon.cs +++ b/UserInterface/AppNotifyIcon.cs @@ -5,39 +5,27 @@ namespace SystemTrayMenu.UserInterface { using System; - using System.Collections.Generic; using System.Drawing; - using System.Linq; using System.Windows.Forms; using SystemTrayMenu.Helper; + using SystemTrayMenu.Helpers; using SystemTrayMenu.Utilities; - using R = SystemTrayMenu.Properties.Resources; using Timer = System.Windows.Forms.Timer; internal class AppNotifyIcon : IDisposable { - private const int Interval60FPS = 16; // 60fps=>1s/60fps=~16.6ms - private static Icon systemTrayMenu = R.SystemTrayMenu; + private static readonly Icon LoadingIcon = Properties.Resources.Loading; + private static Icon systemTrayMenu = Properties.Resources.SystemTrayMenu; private readonly Timer load = new Timer(); private readonly NotifyIcon notifyIcon = new NotifyIcon(); - private readonly int indexLoad; - private readonly List bitmapsLoading = new List() - { - R.L010, R.L020, R.L030, - R.L040, R.L050, R.L060, R.L070, R.L080, R.L090, R.L100, R.L110, R.L120, - R.L130, R.L140, R.L150, R.L160, R.L170, R.L180, - }; - - private DateTime timeLoadingStart; private bool threadsLoading; - private int loadCount; + private int rotationAngle; public AppNotifyIcon() { - indexLoad = bitmapsLoading.Count; - notifyIcon.Icon = bitmapsLoading.First(); + notifyIcon.Icon = LoadingIcon; load.Tick += Load_Tick; - load.Interval = Interval60FPS; + load.Interval = 15; notifyIcon.Text = Translator.GetText("SystemTrayMenu"); notifyIcon.Visible = true; @@ -101,7 +89,6 @@ namespace SystemTrayMenu.UserInterface public void LoadingStart() { - timeLoadingStart = DateTime.Now; threadsLoading = true; load.Start(); } @@ -124,16 +111,27 @@ namespace SystemTrayMenu.UserInterface { if (threadsLoading) { - if (DateTime.Now - timeLoadingStart > new TimeSpan(0, 0, 0, 0, 500)) + rotationAngle = rotationAngle + 5; + using (Bitmap bitmapLoading = new Bitmap(ImagingHelper.RotateImage(LoadingIcon.ToBitmap(), rotationAngle))) { - notifyIcon.Icon = bitmapsLoading[loadCount++ % indexLoad]; + DisposeIconIfNotDefaultIcon(); + notifyIcon.Icon = Icon.FromHandle(bitmapLoading.GetHicon()); } } else { + DisposeIconIfNotDefaultIcon(); notifyIcon.Icon = systemTrayMenu; load.Stop(); } + + void DisposeIconIfNotDefaultIcon() + { + if (notifyIcon.Icon.GetHashCode() != systemTrayMenu.GetHashCode()) + { + notifyIcon.Icon?.Dispose(); + } + } } } } \ No newline at end of file diff --git a/UserInterface/CustomScrollbar/CustomScrollbar.cs b/UserInterface/CustomScrollbar/CustomScrollbar.cs index b178db8..ac315f8 100644 --- a/UserInterface/CustomScrollbar/CustomScrollbar.cs +++ b/UserInterface/CustomScrollbar/CustomScrollbar.cs @@ -6,10 +6,8 @@ namespace SystemTrayMenu.UserInterface { using System; using System.ComponentModel; - using System.Diagnostics; using System.Drawing; using System.Windows.Forms; - using System.Windows.Forms.Design; [Designer(typeof(ScrollbarControlDesigner))] public class CustomScrollbar : UserControl @@ -56,10 +54,7 @@ namespace SystemTrayMenu.UserInterface [Description("LargeChange")] public float LargeChange { - get - { - return largeChange; - } + get => largeChange; set { @@ -75,10 +70,7 @@ namespace SystemTrayMenu.UserInterface [Description("SmallChange")] public float SmallChange { - get - { - return smallChange; - } + get => smallChange; set { @@ -94,10 +86,7 @@ namespace SystemTrayMenu.UserInterface [Description("Minimum")] public int Minimum { - get - { - return minimum; - } + get => minimum; set { @@ -113,10 +102,7 @@ namespace SystemTrayMenu.UserInterface [Description("Maximum")] public int Maximum { - get - { - return maximum; - } + get => maximum; set { @@ -132,10 +118,7 @@ namespace SystemTrayMenu.UserInterface [Description("Value")] public int Value { - get - { - return value; - } + get => value; set { @@ -156,25 +139,13 @@ namespace SystemTrayMenu.UserInterface } } - public int Delta - { - get - { - return Value - lastValue; - } - } + public int Delta => Value - lastValue; public override bool AutoSize { - get - { - return base.AutoSize; - } + get => base.AutoSize; - set - { - base.AutoSize = value; - } + set => base.AutoSize = value; } public void CustomScrollbar_MouseWheel(object sender, MouseEventArgs e) diff --git a/UserInterface/CustomScrollbar/ScrollbarControlDesigner.cs b/UserInterface/CustomScrollbar/ScrollbarControlDesigner.cs index 89febfd..92c996b 100644 --- a/UserInterface/CustomScrollbar/ScrollbarControlDesigner.cs +++ b/UserInterface/CustomScrollbar/ScrollbarControlDesigner.cs @@ -4,11 +4,7 @@ namespace SystemTrayMenu.UserInterface { - using System; using System.ComponentModel; - using System.Diagnostics; - using System.Drawing; - using System.Windows.Forms; using System.Windows.Forms.Design; internal class ScrollbarControlDesigner : ControlDesigner diff --git a/UserInterface/Menu.ControlsTheDesignerRemoves.cs b/UserInterface/Menu.ControlsTheDesignerRemoves.cs index ecc954d..1c48bb7 100644 --- a/UserInterface/Menu.ControlsTheDesignerRemoves.cs +++ b/UserInterface/Menu.ControlsTheDesignerRemoves.cs @@ -4,7 +4,6 @@ namespace SystemTrayMenu.UserInterface { - using System; using System.Drawing; using System.Windows.Forms; using SystemTrayMenu.Utilities; @@ -38,7 +37,7 @@ namespace SystemTrayMenu.UserInterface labelTitle.AutoEllipsis = true; labelTitle.AutoSize = true; labelTitle.Dock = DockStyle.Fill; - labelTitle.Font = new Font("Segoe UI", 8.25F * Scaling.Factor, FontStyle.Bold, GraphicsUnit.Point, (byte)0); + labelTitle.Font = new Font("Segoe UI", 8.25F * Scaling.Factor, FontStyle.Bold, GraphicsUnit.Point, 0); labelTitle.ForeColor = Color.Black; labelTitle.Location = new Point(0, 0); labelTitle.Margin = new Padding(0); @@ -83,10 +82,10 @@ namespace SystemTrayMenu.UserInterface ColumnText, }); - dataGridViewCellStyle3.Font = new Font("Segoe UI", 7F * Scaling.Factor, FontStyle.Regular, GraphicsUnit.Pixel, (byte)0); + dataGridViewCellStyle3.Font = new Font("Segoe UI", 7F * Scaling.Factor, FontStyle.Regular, GraphicsUnit.Pixel, 0); dgv.RowsDefaultCellStyle = dataGridViewCellStyle3; - dgv.RowTemplate.DefaultCellStyle.Font = new Font("Segoe UI", 9F * Scaling.Factor, FontStyle.Regular, GraphicsUnit.Point, (byte)0); + dgv.RowTemplate.DefaultCellStyle.Font = new Font("Segoe UI", 9F * Scaling.Factor, FontStyle.Regular, GraphicsUnit.Point, 0); dgv.RowTemplate.Height = 20; dgv.RowTemplate.ReadOnly = true; @@ -119,8 +118,8 @@ namespace SystemTrayMenu.UserInterface Scaling.Scale(pictureBoxFilesCount.Width), Scaling.Scale(pictureBoxFilesCount.Height)); - labelFoldersCount.Font = new Font("Segoe UI", 7F * Scaling.Factor, FontStyle.Bold, GraphicsUnit.Point, (byte)0); - labelFilesCount.Font = new Font("Segoe UI", 7F * Scaling.Factor, FontStyle.Bold, GraphicsUnit.Point, (byte)0); + labelFoldersCount.Font = new Font("Segoe UI", 7F * Scaling.Factor, FontStyle.Bold, GraphicsUnit.Point, 0); + labelFilesCount.Font = new Font("Segoe UI", 7F * Scaling.Factor, FontStyle.Bold, GraphicsUnit.Point, 0); // tableLayoutPanelDgvAndScrollbar.ResumeLayout(false); // ((System.ComponentModel.ISupportInitialize)dgv).EndInit(); diff --git a/UserInterface/Menu.cs b/UserInterface/Menu.cs index 58078d0..5a7fddb 100644 --- a/UserInterface/Menu.cs +++ b/UserInterface/Menu.cs @@ -7,12 +7,9 @@ namespace SystemTrayMenu.UserInterface using System; using System.Data; using System.Drawing; - using System.Drawing.Drawing2D; using System.Globalization; - using System.IO; using System.Reflection; using System.Windows.Forms; - using Svg; using SystemTrayMenu.DataClasses; using SystemTrayMenu.DllImports; using SystemTrayMenu.Helpers; @@ -794,40 +791,10 @@ namespace SystemTrayMenu.UserInterface PictureBox pictureBox = (PictureBox)sender; rotationAngle = rotationAngle + 5; e.Graphics.DrawImage( - RotateImage(LoadingIcon.ToBitmap(), rotationAngle), + ImagingHelper.RotateImage(LoadingIcon.ToBitmap(), rotationAngle), new Rectangle(Point.Empty, new Size(pictureBox.ClientSize.Width - 2, pictureBox.ClientSize.Height - 2))); } - private Image RotateImage(Image img, float rotationAngle) - { - // create an empty Bitmap image - Bitmap bmp = new Bitmap(img.Width, img.Height); - - // turn the Bitmap into a Graphics object - Graphics gfx = Graphics.FromImage(bmp); - - // now we set the rotation point to the center of our image - gfx.TranslateTransform(0.5f + ((float)bmp.Width / 2), 0.5f + ((float)bmp.Height / 2)); - - // now rotate the image - gfx.RotateTransform(rotationAngle); - - gfx.TranslateTransform(0.5f - ((float)bmp.Width / 2), 0.5f - ((float)bmp.Height / 2)); - - // set the InterpolationMode to HighQualityBicubic so to ensure a high - // quality image once it is transformed to the specified size - gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; - - // now draw our new image onto the graphics object - gfx.DrawImage(img, new Point(0, 0)); - - // dispose of our Graphics object - gfx.Dispose(); - - // return the image - return bmp; - } - private void PictureBoxMenuOpenFolder_Paint(object sender, PaintEventArgs e) { PictureBox pictureBox = (PictureBox)sender; diff --git a/UserInterface/SettingsForm.cs b/UserInterface/SettingsForm.cs index 0407fdf..2b92fec 100644 --- a/UserInterface/SettingsForm.cs +++ b/UserInterface/SettingsForm.cs @@ -6,7 +6,6 @@ namespace SystemTrayMenu.UserInterface { using System; using System.Collections.Generic; - using System.Diagnostics; using System.Drawing; using System.IO; using System.Reflection; @@ -24,8 +23,8 @@ namespace SystemTrayMenu.UserInterface private static readonly Icon SystemTrayMenu = Resources.SystemTrayMenu; private readonly string newHotKey = string.Empty; + private readonly ColorConverter colorConverter = new ColorConverter(); private bool inHotkey; - private ColorConverter colorConverter = new ColorConverter(); public SettingsForm() { diff --git a/Utilities/File/FileLnk.cs b/Utilities/File/FileLnk.cs index ccb6382..b1ca89f 100644 --- a/Utilities/File/FileLnk.cs +++ b/Utilities/File/FileLnk.cs @@ -7,7 +7,6 @@ namespace SystemTrayMenu.Utilities using System; using System.IO; using System.Net.NetworkInformation; - using System.Runtime.InteropServices; using System.Threading; using Shell32; @@ -36,29 +35,6 @@ namespace SystemTrayMenu.Utilities return resolvedFilename; } -#if false // FileLnk.IsDirectory was very slow if it was a network path, PingHost was still slow if not exists therefore we used IsNetworkPath - public static bool IsDirectory(string filePath) - { - bool isDirectory = false; - if (Directory.Exists(filePath)) - { - FileAttributes attributes = File.GetAttributes(filePath); - if ((attributes & FileAttributes.Directory) == FileAttributes.Directory) - { - isDirectory = true; - } - } - - return isDirectory; - } - - public static bool IsNetworkPath(string path) - { - return path.StartsWith(@"\\", StringComparison.InvariantCulture) && - !path.StartsWith(@"\\?\", StringComparison.InvariantCulture); - } -#endif - public static bool IsNetworkRoot(string path) { return path.StartsWith(@"\\", StringComparison.InvariantCulture) && diff --git a/Utilities/File/IconReader.cs b/Utilities/File/IconReader.cs index 38fc0f7..bc8b004 100644 --- a/Utilities/File/IconReader.cs +++ b/Utilities/File/IconReader.cs @@ -49,7 +49,7 @@ namespace SystemTrayMenu.Utilities } } - internal static bool ClearIfCacheTooBig() + public static bool ClearIfCacheTooBig() { bool cleared = false; if (DictIconCache.Count > 200) @@ -64,7 +64,6 @@ namespace SystemTrayMenu.Utilities public static Icon GetFileIconWithCache(string filePath, bool linkOverlay, bool updateIconInBackground, out bool loading) { - Icon icon = null; loading = false; string extension = Path.GetExtension(filePath); IconSize size = IconSize.Small; @@ -79,7 +78,7 @@ namespace SystemTrayMenu.Utilities key = extension + linkOverlay; } - if (!DictIconCache.TryGetValue(key, out icon)) + if (!DictIconCache.TryGetValue(key, out Icon icon)) { icon = LoadingIcon; loading = true; diff --git a/Utilities/Log.cs b/Utilities/Log.cs index 4bb68ec..0819902 100644 --- a/Utilities/Log.cs +++ b/Utilities/Log.cs @@ -6,7 +6,6 @@ namespace SystemTrayMenu.Utilities { using System; using System.Collections.Generic; - using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Reflection; diff --git a/Utilities/Scaling.cs b/Utilities/Scaling.cs index 104e812..da0bead 100644 --- a/Utilities/Scaling.cs +++ b/Utilities/Scaling.cs @@ -5,7 +5,6 @@ namespace SystemTrayMenu.Utilities { using System; - using System.Drawing; internal static class Scaling { @@ -26,20 +25,5 @@ namespace SystemTrayMenu.Utilities { return (int)Math.Round(width * Factor, 0, MidpointRounding.AwayFromZero); } - - /// - /// https://stackoverflow.com/questions/5977445/how-to-get-windows-display-settings - /// Since .net core 3.1 not more necessary / always returns 1. - /// - private static void CalculateScalingFactor() - { - Graphics g = Graphics.FromHwnd(IntPtr.Zero); - IntPtr desktop = g.GetHdc(); - int logicalScreenHeight = DllImports.NativeMethods.Gdi32GetDeviceCaps( - desktop, (int)DeviceCap.VERTRES); - int physicalScreenHeight = DllImports.NativeMethods.Gdi32GetDeviceCaps( - desktop, (int)DeviceCap.DESKTOPVERTRES); - Factor = physicalScreenHeight / (float)logicalScreenHeight; - } } }