Skip to content

Commit

Permalink
[Feature] Option to cache main menu (#232, #241), version 1.0.27.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofknecht committed Nov 18, 2021
1 parent 69e8cf4 commit c647cfe
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 24 deletions.
10 changes: 7 additions & 3 deletions Business/Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ static string[] GetDirectoriesInNetworkLocation(string networkLocationRootPath)
rowData.ContainsMenu = true;
rowData.HiddenEntry = hiddenEntry;
string resolvedLnkPath = string.Empty;
rowData.ReadIcon(true, ref resolvedLnkPath);
rowData.ReadIcon(true, ref resolvedLnkPath, level);
rowData.MenuLevel = level;
menuData.RowDatas.Add(rowData);
}
Expand Down Expand Up @@ -495,7 +495,7 @@ static string[] GetDirectoriesInNetworkLocation(string networkLocationRootPath)

RowData rowData = ReadRowData(file, false);
string resolvedLnkPath = string.Empty;
if (rowData.ReadIcon(false, ref resolvedLnkPath))
if (rowData.ReadIcon(false, ref resolvedLnkPath, level))
{
rowData = ReadRowData(resolvedLnkPath, true, rowData);
rowData.ContainsMenu = true;
Expand Down Expand Up @@ -918,7 +918,11 @@ private void MenuVisibleChanged(object sender, EventArgs e)
if (IconReader.ClearIfCacheTooBig())
{
GC.Collect();
MainPreload();

if (!Properties.Settings.Default.CacheMainMenu)
{
MainPreload();
}
}

openCloseState = OpenCloseState.Default;
Expand Down
28 changes: 13 additions & 15 deletions DataClasses/RowData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ internal void SetData(RowData data, DataTable dataTable)
row[2] = data;
}

internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath)
internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath, int level)
{
bool isLnkDirectory = false;

Expand All @@ -96,7 +96,7 @@ internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath)
}
else if (isDirectory)
{
icon = IconReader.GetFolderIconWithCache(TargetFilePathOrig, IconReader.FolderType.Closed, false, true, MenuLevel == 0, out bool loading);
icon = IconReader.GetFolderIconWithCache(TargetFilePathOrig, IconReader.FolderType.Closed, false, true, level == 0, out bool loading);
IconLoading = loading;
}
else
Expand All @@ -107,19 +107,17 @@ internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath)

if (fileExtension == ".lnk")
{
handled = SetLnk(
ref isLnkDirectory,
ref resolvedLnkPath);
handled = SetLnk(level, ref isLnkDirectory, ref resolvedLnkPath);
showOverlay = true;
}
else if (fileExtension == ".url")
{
handled = SetUrl();
handled = SetUrl(level);
showOverlay = true;
}
else if (fileExtension == ".sln")
{
handled = SetSln();
handled = SetSln(level);
}
else if (fileExtension == ".appref-ms")
{
Expand All @@ -131,7 +129,7 @@ internal bool ReadIcon(bool isDirectory, ref string resolvedLnkPath)
try
{
FilePathIcon = TargetFilePathOrig;
icon = IconReader.GetFileIconWithCache(FilePathIcon, showOverlay, true, MenuLevel == 0, out bool loading);
icon = IconReader.GetFileIconWithCache(FilePathIcon, showOverlay, true, level == 0, out bool loading);
IconLoading = loading;
}
catch (Exception ex)
Expand Down Expand Up @@ -256,7 +254,7 @@ private void OpenItem(MouseEventArgs e, ref bool toCloseByOpenItem)
}
}

private bool SetLnk(ref bool isLnkDirectory, ref string resolvedLnkPath)
private bool SetLnk(int level, ref bool isLnkDirectory, ref string resolvedLnkPath)
{
bool handled = false;
resolvedLnkPath = FileLnk.GetResolvedFileName(TargetFilePath);
Expand All @@ -267,7 +265,7 @@ private bool SetLnk(ref bool isLnkDirectory, ref string resolvedLnkPath)
}
else if (string.IsNullOrEmpty(Path.GetExtension(resolvedLnkPath)))
{
icon = IconReader.GetFolderIconWithCache(TargetFilePathOrig, IconReader.FolderType.Open, true, true, MenuLevel == 0, out bool loading);
icon = IconReader.GetFolderIconWithCache(TargetFilePathOrig, IconReader.FolderType.Open, true, true, level == 0, out bool loading);
IconLoading = loading;
handled = true;
isLnkDirectory = true;
Expand All @@ -290,7 +288,7 @@ private bool SetLnk(ref bool isLnkDirectory, ref string resolvedLnkPath)
return handled;
}

private bool SetUrl()
private bool SetUrl(int level)
{
bool handled = false;
string iconFile = string.Empty;
Expand All @@ -303,15 +301,15 @@ private bool SetUrl()
if (FileUrl.GetDefaultBrowserPath(out string browserPath))
{
FilePathIcon = browserPath;
icon = IconReader.GetFileIconWithCache(FilePathIcon, true, true, MenuLevel == 0, out bool loading);
icon = IconReader.GetFileIconWithCache(FilePathIcon, true, true, level == 0, out bool loading);
IconLoading = loading;
handled = true;
}
}
else if (File.Exists(iconFile))
{
FilePathIcon = iconFile;
icon = IconReader.GetFileIconWithCache(FilePathIcon, true, true, MenuLevel == 0, out bool loading);
icon = IconReader.GetFileIconWithCache(FilePathIcon, true, true, level == 0, out bool loading);
IconLoading = loading;
handled = true;
}
Expand All @@ -330,12 +328,12 @@ private bool SetUrl()
return handled;
}

private bool SetSln()
private bool SetSln(int level)
{
bool handled = false;
try
{
icon = IconReader.GetExtractAllIconsLastWithCache(TargetFilePathOrig, true, MenuLevel == 0, out bool loading);
icon = IconReader.GetExtractAllIconsLastWithCache(TargetFilePathOrig, true, level == 0, out bool loading);
IconLoading = loading;
handled = true;
}
Expand Down
15 changes: 13 additions & 2 deletions NativeDllImport/CreateRoundRectRgn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@ namespace SystemTrayMenu.DllImports
/// </summary>
public static partial class NativeMethods
{
public static IntPtr CreateRoundCorners(int width, int height, int widthEllipse, int heightEllipse)
public static bool GetRegionRoundCorners(int width, int height, int widthEllipse, int heightEllipse, out System.Drawing.Region region)
{
return CreateRoundRectRgn(0, 0, width, height, widthEllipse, heightEllipse);
bool success = false;
region = null;

IntPtr handle = CreateRoundRectRgn(0, 0, width, height, widthEllipse, heightEllipse);
if (handle != IntPtr.Zero)
{
region = System.Drawing.Region.FromHrgn(handle);
DeleteObject(handle);
success = true;
}

return success;
}

[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn", SetLastError = true, CharSet = CharSet.Unicode)]
Expand Down
19 changes: 19 additions & 0 deletions NativeDllImport/DeleteObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// <copyright file="DeleteObject.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>

namespace SystemTrayMenu.DllImports
{
using System;
using System.Runtime.InteropServices;

/// <summary>
/// wraps the methodcalls to native windows dll's.
/// </summary>
public static partial class NativeMethods
{
[DllImport("gdi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
[DefaultDllImportSearchPaths(DllImportSearchPath.UserDirectories)]
private static extern int DeleteObject(IntPtr hIcon);
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
// 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.27.3")]
[assembly: AssemblyFileVersion("1.0.27.3")]
[assembly: AssemblyVersion("1.0.27.5")]
[assembly: AssemblyFileVersion("1.0.27.5")]
11 changes: 9 additions & 2 deletions UserInterface/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,15 @@ internal void HideWithFade()

if (Properties.Settings.Default.RoundCorners)
{
Region = Region.FromHrgn(NativeMethods.CreateRoundCorners(Width + 1, Height + 1, 15, 15));
tableLayoutPanelMenu.Region = Region.FromHrgn(NativeMethods.CreateRoundCorners(Width - 1, Height - 1, 15, 15));
if (NativeMethods.GetRegionRoundCorners(Width + 1, Height + 1, 15, 15, out Region regionOutline))
{
Region = regionOutline;
}

if (NativeMethods.GetRegionRoundCorners(Width - 1, Height - 1, 15, 15, out Region region))
{
tableLayoutPanelMenu.Region = region;
}
}
}

Expand Down

0 comments on commit c647cfe

Please sign in to comment.