simplified ReadIcon

Removed code execution path that can never happen: Icon of an lnk's directory will be loaded directly within first call of ReadIcon, no need to call it again and then break as icon already exists
This commit is contained in:
Peter Kirmeier 2019-07-07 13:02:53 +02:00
parent a8aebe16e2
commit 9eceae46c7
3 changed files with 18 additions and 17 deletions

View file

@ -36,26 +36,30 @@ namespace SystemTrayMenu.Controls
public bool IsSelected;
public bool IsSelectedByKeyboard;
public bool ReadIcon(bool isDirectory, bool isResolvedLnk, ref string resolvedLnkPath)
/// <summary>
/// Loads the icon
/// </summary>
/// <param name="isDirectory">True = directory, false = file</param>
/// <param name="resolvedLnkPath">Discovered path when functions returns true</param>
/// <returns>True when linking to a different directory, otherwise false</returns>
public bool ReadIcon(bool isDirectory, ref string resolvedLnkPath)
{
bool isLnkDirectory = false;
Logger log = new Logger(nameof(RowData));
if (isResolvedLnk)
if (string.IsNullOrEmpty(TargetFilePath))
{
if (Icon == null)
{
Icon = IconReader.GetFolderIcon(TargetFilePath,
IconReader.FolderType.Open, true);
}
log.Warn($"ReadIcon called but TargetFilePath not set.");
return isLnkDirectory;
}
else if (isDirectory)
if (isDirectory)
{
Icon = IconReader.GetFolderIcon(TargetFilePath,
IconReader.FolderType.Closed, false);
}
else if (!string.IsNullOrEmpty(TargetFilePath))
else
{
bool handled = false;
string fileExtension = Path.GetExtension(TargetFilePath);

View file

@ -31,5 +31,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.1.240")]
[assembly: AssemblyFileVersion("0.9.1.240")]
[assembly: AssemblyVersion("0.9.1.241")]
[assembly: AssemblyFileVersion("0.9.1.241")]

View file

@ -424,7 +424,7 @@ namespace SystemTrayMenu
RowData menuButtonData = ReadMenuButtonData(directory, false);
menuButtonData.ContainsMenu = true;
string resolvedLnkPath = string.Empty;
menuButtonData.ReadIcon(true, false, ref resolvedLnkPath);
menuButtonData.ReadIcon(true, ref resolvedLnkPath);
menuData.RowDatas.Add(menuButtonData);
}
}
@ -453,18 +453,15 @@ namespace SystemTrayMenu
foreach (string file in files)
{
if (worker != null && worker.CancellationPending)
{
break;
}
RowData menuButtonData = ReadMenuButtonData(file, false);
string resolvedLnkPath = string.Empty;
if (menuButtonData.ReadIcon(false,
false, ref resolvedLnkPath))
if (menuButtonData.ReadIcon(false, ref resolvedLnkPath))
{
// file is pointing to a directory, so prepare submenu
menuButtonData = ReadMenuButtonData(resolvedLnkPath, true, menuButtonData);
menuButtonData.ContainsMenu = true;
menuButtonData.ReadIcon(true, true, ref resolvedLnkPath);
}
menuData.RowDatas.Add(menuButtonData);