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:
RKrom 2014-11-11 13:23:59 +01:00
parent c50e5fa5ab
commit 61c2921b2a
16 changed files with 140 additions and 123 deletions

View file

@ -34,7 +34,10 @@ namespace Greenshot.Controls {
private static Image scaledCheckbox; private static Image scaledCheckbox;
protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) { protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) {
if (scaledCheckbox == null) { if (scaledCheckbox == null || scaledCheckbox.Size != coreConfiguration.IconSize) {
if (scaledCheckbox != null) {
scaledCheckbox.Dispose();
}
scaledCheckbox = ImageHelper.ResizeImage(e.Image, true, coreConfiguration.IconSize.Width, coreConfiguration.IconSize.Height, null); scaledCheckbox = ImageHelper.ResizeImage(e.Image, true, coreConfiguration.IconSize.Width, coreConfiguration.IconSize.Height, null);
} }
Rectangle old = e.ImageRectangle; Rectangle old = e.ImageRectangle;

View file

@ -1,22 +1,22 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2014 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2014 Thomas Braun, Jens Klingen, Robin Krom
* *
* For more information see: http://getgreenshot.org/ * For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or * the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using System.Drawing; using System.Drawing;

View file

@ -105,7 +105,6 @@ namespace Greenshot {
this.contextMenu.Name = "contextMenu"; this.contextMenu.Name = "contextMenu";
this.contextMenu.Closing += new System.Windows.Forms.ToolStripDropDownClosingEventHandler(this.ContextMenuClosing); this.contextMenu.Closing += new System.Windows.Forms.ToolStripDropDownClosingEventHandler(this.ContextMenuClosing);
this.contextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuOpening); this.contextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuOpening);
this.contextMenu.ImageScalingSize = coreConfiguration.IconSize;
this.contextMenu.Renderer = new Greenshot.Controls.ContextMenuToolStripProfessionalRenderer(); this.contextMenu.Renderer = new Greenshot.Controls.ContextMenuToolStripProfessionalRenderer();
// //
// contextmenu_capturearea // contextmenu_capturearea

View file

@ -336,7 +336,7 @@ namespace Greenshot {
public MainForm(CopyDataTransport dataTransport) { public MainForm(CopyDataTransport dataTransport) {
_instance = this; _instance = this;
// //
// The InitializeComponent() call is required for Windows Forms designer support. // The InitializeComponent() call is required for Windows Forms designer support.
// //
@ -388,6 +388,8 @@ namespace Greenshot {
} }
SoundHelper.Initialize(); SoundHelper.Initialize();
MainForm.ResetImageScalingSize();
// Set the Greenshot icon visibility depending on the configuration. (Added for feature #3521446) // Set the Greenshot icon visibility depending on the configuration. (Added for feature #3521446)
// Setting it to true this late prevents Problems with the context menu // Setting it to true this late prevents Problems with the context menu
notifyIcon.Visible = !_conf.HideTrayicon; notifyIcon.Visible = !_conf.HideTrayicon;
@ -549,6 +551,15 @@ namespace Greenshot {
} }
} }
/// <summary>
/// Reset ImageScalingSize
/// </summary>
/// <returns>Used for fixing scaling issues</returns>
public static void ResetImageScalingSize() {
MainForm thisForm = MainForm.Instance;
thisForm.contextMenu.ImageScalingSize = coreConfiguration.IconSize;
}
/// <summary> /// <summary>
/// Registers all hotkeys as configured, displaying a dialog in case of hotkey conflicts with other tools. /// Registers all hotkeys as configured, displaying a dialog in case of hotkey conflicts with other tools.
/// </summary> /// </summary>

View file

@ -414,7 +414,14 @@ namespace Greenshot {
coreConfiguration.DWMBackgroundColor = colorButton_window_background.SelectedColor; coreConfiguration.DWMBackgroundColor = colorButton_window_background.SelectedColor;
coreConfiguration.UpdateCheckInterval = (int)numericUpDown_daysbetweencheck.Value; coreConfiguration.UpdateCheckInterval = (int)numericUpDown_daysbetweencheck.Value;
Size previousValue = coreConfiguration.IconSize;
coreConfiguration.IconSize = new Size((int)numericUpdownIconSize.Value, (int)numericUpdownIconSize.Value); coreConfiguration.IconSize = new Size((int)numericUpdownIconSize.Value, (int)numericUpdownIconSize.Value);
// Clear caches when changing the settings
if (previousValue != coreConfiguration.IconSize) {
PluginUtils.ClearExeIconCache();
MainForm.ResetImageScalingSize();
}
coreConfiguration.FixIconSize(); coreConfiguration.FixIconSize();
try { try {
if (checkbox_autostartshortcut.Checked) { if (checkbox_autostartshortcut.Checked) {

View file

@ -35,7 +35,8 @@ namespace Greenshot.Forms {
private static CoreConfiguration coreConfiguration = IniConfig.GetIniSection<CoreConfiguration>(); private static CoreConfiguration coreConfiguration = IniConfig.GetIniSection<CoreConfiguration>();
private bool multiCheckAllowed = false; private bool multiCheckAllowed = false;
private bool updateInProgress = false; private bool updateInProgress = false;
private static Image defaultImage = ImageHelper.CreateEmpty(coreConfiguration.IconSize.Width, coreConfiguration.IconSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb, Color.Transparent, 96f, 96f); private static Image defaultImage;
/// <summary> /// <summary>
/// Occurs when one of the list's child element's Checked state changes. /// Occurs when one of the list's child element's Checked state changes.
/// </summary> /// </summary>
@ -49,10 +50,16 @@ namespace Greenshot.Forms {
Identifier = identifier; Identifier = identifier;
CheckOnClick = false; CheckOnClick = false;
multiCheckAllowed = allowMultiCheck; multiCheckAllowed = allowMultiCheck;
if (defaultImage == null || defaultImage.Size != coreConfiguration.IconSize) {
if (defaultImage != null) {
defaultImage.Dispose();
}
defaultImage = ImageHelper.CreateEmpty(coreConfiguration.IconSize.Width, coreConfiguration.IconSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb, Color.Transparent, 96f, 96f);
}
Image = defaultImage; Image = defaultImage;
} }
public ToolStripMenuSelectList() : this(null,false) {} public ToolStripMenuSelectList() : this(null,false) {}
public ToolStripMenuSelectList(Object identifier) : this(identifier,false) {} public ToolStripMenuSelectList(object identifier) : this(identifier,false) {}
/// <summary> /// <summary>
/// gets or sets the currently checked item /// gets or sets the currently checked item

View file

@ -126,7 +126,7 @@ namespace ExternalCommand {
try { try {
string exePath = PluginUtils.GetExePath("cmd.exe"); string exePath = PluginUtils.GetExePath("cmd.exe");
if (exePath != null && File.Exists(exePath)) { if (exePath != null && File.Exists(exePath)) {
itemPlugInRoot.Image = PluginUtils.GetExeIcon(exePath, 0); itemPlugInRoot.Image = PluginUtils.GetCachedExeIcon(exePath, 0);
} }
} catch (Exception ex) { } catch (Exception ex) {
LOG.Warn("Couldn't get the cmd.exe image", ex); LOG.Warn("Couldn't get the cmd.exe image", ex);

View file

@ -7,29 +7,21 @@ using GreenshotPlugin.Core;
namespace ExternalCommand { namespace ExternalCommand {
public static class IconCache { public static class IconCache {
private static Dictionary<string, Image> iconCache = new Dictionary<string, Image>();
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>(); private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(IconCache)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(IconCache));
public static Image IconForCommand(string commandName) { public static Image IconForCommand(string commandName) {
Image icon = null;
if (commandName != null) { if (commandName != null) {
if (!iconCache.ContainsKey(commandName)) { if (config.commandlines.ContainsKey(commandName) && File.Exists(config.commandlines[commandName])) {
Image icon = null; try {
if (config.commandlines.ContainsKey(commandName) && File.Exists(config.commandlines[commandName])) { icon = PluginUtils.GetCachedExeIcon(config.commandlines[commandName], 0);
try { } catch (Exception ex) {
icon = PluginUtils.GetExeIcon(config.commandlines[commandName], 0); LOG.Warn("Problem loading icon for " + config.commandlines[commandName], ex);
} catch (Exception ex) {
LOG.Warn("Problem loading icon for " + config.commandlines[commandName], ex);
}
} }
// Also add null to the cache if nothing is found
iconCache.Add(commandName, icon);
}
if (iconCache.ContainsKey(commandName)) {
return iconCache[commandName];
} }
} }
return null; return icon;
} }
} }
} }

View file

@ -33,16 +33,8 @@ namespace GreenshotOCR {
private static OCRConfiguration config = IniConfig.GetIniSection<OCRConfiguration>(); private static OCRConfiguration config = IniConfig.GetIniSection<OCRConfiguration>();
private const int MIN_WIDTH = 130; private const int MIN_WIDTH = 130;
private const int MIN_HEIGHT = 130; private const int MIN_HEIGHT = 130;
private static Image icon = null;
private OcrPlugin plugin; private OcrPlugin plugin;
static OCRDestination() {
string exePath = PluginUtils.GetExePath("MSPVIEW.EXE");
if (exePath != null && File.Exists(exePath)) {
icon = PluginUtils.GetExeIcon(exePath, 0);
}
}
public override string Designation { public override string Designation {
get { get {
return "OCR"; return "OCR";
@ -57,7 +49,11 @@ namespace GreenshotOCR {
public override Image DisplayIcon { public override Image DisplayIcon {
get { get {
return icon; string exePath = PluginUtils.GetExePath("MSPVIEW.EXE");
if (exePath != null && File.Exists(exePath)) {
return PluginUtils.GetCachedExeIcon(exePath, 0);
}
return null;
} }
} }

View file

@ -36,16 +36,14 @@ namespace GreenshotOfficePlugin {
/// </summary> /// </summary>
public class ExcelDestination : AbstractDestination { public class ExcelDestination : AbstractDestination {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExcelDestination)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExcelDestination));
private const int ICON_APPLICATION = 0;
private const int ICON_WORKBOOK = 1;
private static string exePath = null; private static string exePath = null;
private static Image applicationIcon = null;
private static Image workbookIcon = null;
private string workbookName = null; private string workbookName = null;
static ExcelDestination() { static ExcelDestination() {
exePath = PluginUtils.GetExePath("EXCEL.EXE"); exePath = PluginUtils.GetExePath("EXCEL.EXE");
if (exePath != null && File.Exists(exePath)) { if (exePath != null && File.Exists(exePath)) {
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
workbookIcon = PluginUtils.GetExeIcon(exePath, 1);
WindowDetails.AddProcessToExcludeFromFreeze("excel"); WindowDetails.AddProcessToExcludeFromFreeze("excel");
} else { } else {
exePath = null; exePath = null;
@ -96,9 +94,9 @@ namespace GreenshotOfficePlugin {
public override Image DisplayIcon { public override Image DisplayIcon {
get { get {
if (!string.IsNullOrEmpty(workbookName)) { if (!string.IsNullOrEmpty(workbookName)) {
return workbookIcon; return PluginUtils.GetCachedExeIcon(exePath, ICON_WORKBOOK);
} }
return applicationIcon; return PluginUtils.GetCachedExeIcon(exePath, ICON_APPLICATION);
} }
} }

View file

@ -18,32 +18,26 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using Greenshot.Interop.Office;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Windows.Forms;
using GreenshotPlugin.Core;
using Greenshot.Plugin;
using Greenshot.Interop.Office;
using Greenshot.IniFile;
namespace GreenshotOfficePlugin { namespace GreenshotOfficePlugin {
public class OneNoteDestination : AbstractDestination { public class OneNoteDestination : AbstractDestination {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WordDestination)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WordDestination));
private const int ICON_APPLICATION = 0;
public const string DESIGNATION = "OneNote"; public const string DESIGNATION = "OneNote";
private static string exePath = null; private static string exePath = null;
private static Image applicationIcon = null;
private static Image notebookIcon = null;
private OneNotePage page = null; private OneNotePage page = null;
static OneNoteDestination() { static OneNoteDestination() {
exePath = PluginUtils.GetExePath("ONENOTE.EXE"); exePath = PluginUtils.GetExePath("ONENOTE.EXE");
if (exePath != null && File.Exists(exePath)) { if (exePath != null && File.Exists(exePath)) {
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
notebookIcon = PluginUtils.GetExeIcon(exePath, 0);
WindowDetails.AddProcessToExcludeFromFreeze("onenote"); WindowDetails.AddProcessToExcludeFromFreeze("onenote");
} else { } else {
exePath = null; exePath = null;
@ -94,10 +88,7 @@ namespace GreenshotOfficePlugin {
public override Image DisplayIcon { public override Image DisplayIcon {
get { get {
if (page != null) { return PluginUtils.GetCachedExeIcon(exePath, ICON_APPLICATION);
return notebookIcon;
}
return applicationIcon;
} }
} }

View file

@ -18,29 +18,29 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using System;
using Greenshot.IniFile;
using Greenshot.Interop.Office;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows.Forms;
using Greenshot.Interop.Office;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
namespace GreenshotOfficePlugin { namespace GreenshotOfficePlugin {
/// <summary> /// <summary>
/// Description of OutlookDestination. /// Description of OutlookDestination.
/// </summary> /// </summary>
public class OutlookDestination : AbstractDestination { public class OutlookDestination : AbstractDestination {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OutlookDestination)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OutlookDestination));
private const int ICON_APPLICATION = 0;
private const int ICON_MEETING = 2;
private static Image mailIcon = GreenshotPlugin.Core.GreenshotResources.getImage("Email.Image");
private static OfficeConfiguration conf = IniConfig.GetIniSection<OfficeConfiguration>(); private static OfficeConfiguration conf = IniConfig.GetIniSection<OfficeConfiguration>();
private static string exePath = null; private static string exePath = null;
private static Image applicationIcon = null;
private static Image mailIcon = GreenshotPlugin.Core.GreenshotResources.getImage("Email.Image");
private static Image meetingIcon = null;
private static bool isActiveFlag = false; private static bool isActiveFlag = false;
private static string mapiClient = "Microsoft Outlook"; private static string mapiClient = "Microsoft Outlook";
public const string DESIGNATION = "Outlook"; public const string DESIGNATION = "Outlook";
@ -53,11 +53,7 @@ namespace GreenshotOfficePlugin {
} }
exePath = PluginUtils.GetExePath("OUTLOOK.EXE"); exePath = PluginUtils.GetExePath("OUTLOOK.EXE");
if (exePath != null && File.Exists(exePath)) { if (exePath != null && File.Exists(exePath)) {
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
WindowDetails.AddProcessToExcludeFromFreeze("outlook"); WindowDetails.AddProcessToExcludeFromFreeze("outlook");
if (conf.OutlookAllowExportInMeetings) {
meetingIcon = PluginUtils.GetExeIcon(exePath, 2);
}
} else { } else {
exePath = null; exePath = null;
} }
@ -119,15 +115,12 @@ namespace GreenshotOfficePlugin {
if (outlookInspectorCaption != null) { if (outlookInspectorCaption != null) {
if (OlObjectClass.olAppointment.Equals(outlookInspectorType)) { if (OlObjectClass.olAppointment.Equals(outlookInspectorType)) {
// Make sure we loaded the icon, maybe the configuration has been changed! // Make sure we loaded the icon, maybe the configuration has been changed!
if (meetingIcon == null) { return PluginUtils.GetCachedExeIcon(exePath, ICON_MEETING);
meetingIcon = PluginUtils.GetExeIcon(exePath, 2);
}
return meetingIcon;
} else { } else {
return mailIcon; return mailIcon;
} }
} else { } else {
return applicationIcon; return PluginUtils.GetCachedExeIcon(exePath, ICON_APPLICATION);
} }
} }
} }

View file

@ -36,16 +36,15 @@ namespace GreenshotOfficePlugin {
/// </summary> /// </summary>
public class PowerpointDestination : AbstractDestination { public class PowerpointDestination : AbstractDestination {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PowerpointDestination)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PowerpointDestination));
private const int ICON_APPLICATION = 0;
private const int ICON_PRESENTATION = 1;
private static string exePath = null; private static string exePath = null;
private static Image applicationIcon = null;
private static Image presentationIcon = null;
private string presentationName = null; private string presentationName = null;
static PowerpointDestination() { static PowerpointDestination() {
exePath = PluginUtils.GetExePath("POWERPNT.EXE"); exePath = PluginUtils.GetExePath("POWERPNT.EXE");
if (exePath != null && File.Exists(exePath)) { if (exePath != null && File.Exists(exePath)) {
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
presentationIcon = PluginUtils.GetExeIcon(exePath, 1);
WindowDetails.AddProcessToExcludeFromFreeze("powerpnt"); WindowDetails.AddProcessToExcludeFromFreeze("powerpnt");
} else { } else {
exePath = null; exePath = null;
@ -96,10 +95,10 @@ namespace GreenshotOfficePlugin {
public override Image DisplayIcon { public override Image DisplayIcon {
get { get {
if (!string.IsNullOrEmpty(presentationName)) { if (!string.IsNullOrEmpty(presentationName)) {
return presentationIcon; return PluginUtils.GetCachedExeIcon(exePath, ICON_PRESENTATION);
} }
return applicationIcon; return PluginUtils.GetCachedExeIcon(exePath, ICON_APPLICATION);
} }
} }

View file

@ -18,17 +18,14 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using Greenshot.Interop.Office;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Windows.Forms;
using GreenshotPlugin.Core;
using Greenshot.Plugin;
using Greenshot.Interop.Office;
using Greenshot.IniFile;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace GreenshotOfficePlugin { namespace GreenshotOfficePlugin {
@ -37,17 +34,14 @@ namespace GreenshotOfficePlugin {
/// </summary> /// </summary>
public class WordDestination : AbstractDestination { public class WordDestination : AbstractDestination {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WordDestination)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WordDestination));
private const int ICON_APPLICATION = 0;
private const int ICON_DOCUMENT = 1;
private static string exePath = null; private static string exePath = null;
private static Image applicationIcon = null;
private static Image documentIcon = null;
private string documentCaption = null; private string documentCaption = null;
static WordDestination() { static WordDestination() {
exePath = PluginUtils.GetExePath("WINWORD.EXE"); exePath = PluginUtils.GetExePath("WINWORD.EXE");
if (exePath != null && File.Exists(exePath)) { if (exePath != null && !File.Exists(exePath)) {
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
documentIcon = PluginUtils.GetExeIcon(exePath, 1);
} else {
exePath = null; exePath = null;
} }
} }
@ -97,9 +91,9 @@ namespace GreenshotOfficePlugin {
public override Image DisplayIcon { public override Image DisplayIcon {
get { get {
if (!string.IsNullOrEmpty(documentCaption)) { if (!string.IsNullOrEmpty(documentCaption)) {
return documentIcon; return PluginUtils.GetCachedExeIcon(exePath, ICON_DOCUMENT);
} }
return applicationIcon; return PluginUtils.GetCachedExeIcon(exePath, ICON_APPLICATION);
} }
} }

View file

@ -25,6 +25,7 @@ using GreenshotPlugin.UnmanagedHelpers;
using log4net; using log4net;
using Microsoft.Win32; using Microsoft.Win32;
using System; using System;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
@ -37,6 +38,7 @@ namespace GreenshotPlugin.Core {
private static readonly ILog LOG = LogManager.GetLogger(typeof(PluginUtils)); private static readonly ILog LOG = LogManager.GetLogger(typeof(PluginUtils));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>(); private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private const string PATH_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"; private const string PATH_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\";
private static IDictionary<string, Image> exeIconCache = new Dictionary<string, Image>();
/// <summary> /// <summary>
/// Simple global property to get the Greenshot host /// Simple global property to get the Greenshot host
@ -46,6 +48,21 @@ namespace GreenshotPlugin.Core {
set; 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> /// <summary>
/// Get the path of an executable /// Get the path of an executable
/// </summary> /// </summary>
@ -70,6 +87,28 @@ namespace GreenshotPlugin.Core {
} }
return null; 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> /// <summary>
/// Get icon for executable /// Get icon for executable
@ -77,7 +116,7 @@ namespace GreenshotPlugin.Core {
/// <param name="path">path to the exe or dll</param> /// <param name="path">path to the exe or dll</param>
/// <param name="index">index of the icon</param> /// <param name="index">index of the icon</param>
/// <returns>Bitmap with the icon or null if something happended</returns> /// <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)) { if (!File.Exists(path)) {
return null; return null;
} }

View file

@ -170,7 +170,6 @@ namespace GreenshotPlugin.Core {
private static Dictionary<string, List<string>> classnameTree = new Dictionary<string, List<string>>(); private static Dictionary<string, List<string>> classnameTree = new Dictionary<string, List<string>>();
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>(); private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private static List<IntPtr> ignoreHandles = new List<IntPtr>(); 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 List<string> excludeProcessesFromFreeze = new List<string>();
private static IAppVisibility appVisibility = null; private static IAppVisibility appVisibility = null;
@ -204,7 +203,6 @@ namespace GreenshotPlugin.Core {
} }
} }
public bool isGutter { public bool isGutter {
get { get {
return METRO_GUTTER_CLASS.Equals(ClassName); return METRO_GUTTER_CLASS.Equals(ClassName);
@ -307,17 +305,7 @@ namespace GreenshotPlugin.Core {
return null; return null;
} }
try { try {
string filename = ProcessPath; return PluginUtils.GetCachedExeIcon(ProcessPath, 0);
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];
} catch (Exception ex) { } catch (Exception ex) {
LOG.WarnFormat("Couldn't get icon for window {0} due to: {1}", Text, ex.Message); LOG.WarnFormat("Couldn't get icon for window {0} due to: {1}", Text, ex.Message);
LOG.Warn(ex); LOG.Warn(ex);