Modernize CItemManager::LoadCustomIcon

This commit is contained in:
ge0rdi
2020-09-18 14:12:04 +02:00
parent 2ca236c291
commit 728f982310

View File

@@ -2600,44 +2600,36 @@ void CItemManager::LoadCustomIcon( const wchar_t *iconPath, int iconIndex, int r
unsigned int hash = CalcFNVHash(iconPath, CalcFNVHash(&iconIndex, 4)); unsigned int hash = CalcFNVHash(iconPath, CalcFNVHash(&iconIndex, 4));
FindInCache(hash, refreshFlags, smallIcon, largeIcon, extraLargeIcon); FindInCache(hash, refreshFlags, smallIcon, largeIcon, extraLargeIcon);
if (!refreshFlags) return; if (!refreshFlags)
return;
auto ExtractIconAsBitmap = [&](int iconSize) -> HBITMAP {
HICON hIcon;
if (!*iconPath)
hIcon = (HICON)LoadImage(g_Instance, MAKEINTRESOURCE(-iconIndex), IMAGE_ICON, iconSize, iconSize, LR_DEFAULTCOLOR);
else
hIcon = ShExtractIcon(iconPath, iconIndex == -1 ? 0 : iconIndex, iconSize);
if (hIcon)
return BitmapFromIcon(hIcon, iconSize);
return nullptr;
};
// extract icon // extract icon
HBITMAP hSmallBitmap=NULL, hLargeBitmap=NULL, hExtraLargeBitmap=NULL; HBITMAP hSmallBitmap = nullptr, hLargeBitmap = nullptr, hExtraLargeBitmap = nullptr;
if (refreshFlags & INFO_SMALL_ICON) if (refreshFlags & INFO_SMALL_ICON)
{ hSmallBitmap = ExtractIconAsBitmap(SMALL_ICON_SIZE);
HICON hIcon;
if (!*iconPath)
hIcon=(HICON)LoadImage(g_Instance,MAKEINTRESOURCE(-iconIndex),IMAGE_ICON,SMALL_ICON_SIZE,SMALL_ICON_SIZE,LR_DEFAULTCOLOR);
else
hIcon=ShExtractIcon(iconPath,iconIndex==-1?0:iconIndex,SMALL_ICON_SIZE);
if (hIcon)
hSmallBitmap=BitmapFromIcon(hIcon,SMALL_ICON_SIZE);
}
if (refreshFlags & INFO_LARGE_ICON) if (refreshFlags & INFO_LARGE_ICON)
{ hLargeBitmap = ExtractIconAsBitmap(LARGE_ICON_SIZE);
HICON hIcon;
if (!*iconPath)
hIcon=(HICON)LoadImage(g_Instance,MAKEINTRESOURCE(-iconIndex),IMAGE_ICON,LARGE_ICON_SIZE,LARGE_ICON_SIZE,LR_DEFAULTCOLOR);
else
hIcon=ShExtractIcon(iconPath,iconIndex==-1?0:iconIndex,LARGE_ICON_SIZE);
if (hIcon)
hLargeBitmap=BitmapFromIcon(hIcon,LARGE_ICON_SIZE);
}
if (refreshFlags & INFO_EXTRA_LARGE_ICON) if (refreshFlags & INFO_EXTRA_LARGE_ICON)
{ hExtraLargeBitmap = ExtractIconAsBitmap(EXTRA_LARGE_ICON_SIZE);
HICON hIcon;
if (!*iconPath)
hIcon=(HICON)LoadImage(g_Instance,MAKEINTRESOURCE(-iconIndex),IMAGE_ICON,EXTRA_LARGE_ICON_SIZE,EXTRA_LARGE_ICON_SIZE,LR_DEFAULTCOLOR);
else
hIcon=ShExtractIcon(iconPath,iconIndex==-1?0:iconIndex,EXTRA_LARGE_ICON_SIZE);
if (hIcon)
hExtraLargeBitmap=BitmapFromIcon(hIcon,EXTRA_LARGE_ICON_SIZE);
}
StoreInCache(hash,bTemp?NULL:iconPath,hSmallBitmap,hLargeBitmap,hExtraLargeBitmap,refreshFlags,smallIcon,largeIcon,extraLargeIcon,bTemp,false); StoreInCache(hash, bTemp ? nullptr : iconPath, hSmallBitmap, hLargeBitmap, hExtraLargeBitmap, refreshFlags, smallIcon, largeIcon, extraLargeIcon, bTemp, false);
} }
// Recursive function to preload the items for a folder // Recursive function to preload the items for a folder