mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 21:43:24 -07:00
This change should make the UI Icon Size setting dynamic, clearing all cached icons when the size changes (in the settings UI) so if they have a dynamic size the best is selected.
This commit is contained in:
parent
c50e5fa5ab
commit
61c2921b2a
16 changed files with 140 additions and 123 deletions
|
@ -25,6 +25,7 @@ using GreenshotPlugin.UnmanagedHelpers;
|
|||
using log4net;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
@ -37,6 +38,7 @@ namespace GreenshotPlugin.Core {
|
|||
private static readonly ILog LOG = LogManager.GetLogger(typeof(PluginUtils));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private const string PATH_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\";
|
||||
private static IDictionary<string, Image> exeIconCache = new Dictionary<string, Image>();
|
||||
|
||||
/// <summary>
|
||||
/// Simple global property to get the Greenshot host
|
||||
|
@ -46,6 +48,21 @@ namespace GreenshotPlugin.Core {
|
|||
set;
|
||||
}
|
||||
|
||||
public static void ClearExeIconCache() {
|
||||
List<Image> cachedImages = new List<Image>();
|
||||
lock (exeIconCache) {
|
||||
foreach (string key in exeIconCache.Keys) {
|
||||
cachedImages.Add(exeIconCache[key]);
|
||||
}
|
||||
exeIconCache.Clear();
|
||||
}
|
||||
foreach (Image cachedImage in cachedImages) {
|
||||
if (cachedImage != null) {
|
||||
cachedImage.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the path of an executable
|
||||
/// </summary>
|
||||
|
@ -70,6 +87,28 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get icon for executable, from the cache
|
||||
/// </summary>
|
||||
/// <param name="path">path to the exe or dll</param>
|
||||
/// <param name="index">index of the icon</param>
|
||||
/// <returns>Bitmap with the icon or null if something happended</returns>
|
||||
public static Image GetCachedExeIcon(string path, int index) {
|
||||
string cacheKey = string.Format("{0}:{1}", path, index);
|
||||
Image returnValue;
|
||||
if (!exeIconCache.TryGetValue(cacheKey, out returnValue)) {
|
||||
lock (exeIconCache) {
|
||||
if (!exeIconCache.TryGetValue(cacheKey, out returnValue)) {
|
||||
returnValue = GetExeIcon(path, index);
|
||||
if (returnValue != null) {
|
||||
exeIconCache.Add(cacheKey, returnValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get icon for executable
|
||||
|
@ -77,7 +116,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="path">path to the exe or dll</param>
|
||||
/// <param name="index">index of the icon</param>
|
||||
/// <returns>Bitmap with the icon or null if something happended</returns>
|
||||
public static Bitmap GetExeIcon(string path, int index) {
|
||||
private static Bitmap GetExeIcon(string path, int index) {
|
||||
if (!File.Exists(path)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -170,7 +170,6 @@ namespace GreenshotPlugin.Core {
|
|||
private static Dictionary<string, List<string>> classnameTree = new Dictionary<string, List<string>>();
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static List<IntPtr> ignoreHandles = new List<IntPtr>();
|
||||
private static Dictionary<string, Image> iconCache = new Dictionary<string, Image>();
|
||||
private static List<string> excludeProcessesFromFreeze = new List<string>();
|
||||
private static IAppVisibility appVisibility = null;
|
||||
|
||||
|
@ -204,7 +203,6 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public bool isGutter {
|
||||
get {
|
||||
return METRO_GUTTER_CLASS.Equals(ClassName);
|
||||
|
@ -307,17 +305,7 @@ namespace GreenshotPlugin.Core {
|
|||
return null;
|
||||
}
|
||||
try {
|
||||
string filename = ProcessPath;
|
||||
if (!iconCache.ContainsKey(filename)) {
|
||||
Image icon = null;
|
||||
using (Icon appIcon = Shell32.ExtractAssociatedIcon(filename)) {
|
||||
if (appIcon != null) {
|
||||
icon = appIcon.ToBitmap();
|
||||
}
|
||||
}
|
||||
iconCache.Add(filename, icon);
|
||||
}
|
||||
return iconCache[filename];
|
||||
return PluginUtils.GetCachedExeIcon(ProcessPath, 0);
|
||||
} catch (Exception ex) {
|
||||
LOG.WarnFormat("Couldn't get icon for window {0} due to: {1}", Text, ex.Message);
|
||||
LOG.Warn(ex);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue