mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -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
|
@ -34,7 +34,10 @@ namespace Greenshot.Controls {
|
|||
private static Image scaledCheckbox;
|
||||
|
||||
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);
|
||||
}
|
||||
Rectangle old = e.ImageRectangle;
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2014 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2014 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Drawing;
|
||||
|
|
1
Greenshot/Forms/MainForm.Designer.cs
generated
1
Greenshot/Forms/MainForm.Designer.cs
generated
|
@ -105,7 +105,6 @@ namespace Greenshot {
|
|||
this.contextMenu.Name = "contextMenu";
|
||||
this.contextMenu.Closing += new System.Windows.Forms.ToolStripDropDownClosingEventHandler(this.ContextMenuClosing);
|
||||
this.contextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuOpening);
|
||||
this.contextMenu.ImageScalingSize = coreConfiguration.IconSize;
|
||||
this.contextMenu.Renderer = new Greenshot.Controls.ContextMenuToolStripProfessionalRenderer();
|
||||
//
|
||||
// contextmenu_capturearea
|
||||
|
|
|
@ -336,7 +336,7 @@ namespace Greenshot {
|
|||
|
||||
public MainForm(CopyDataTransport dataTransport) {
|
||||
_instance = this;
|
||||
|
||||
|
||||
//
|
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
//
|
||||
|
@ -388,6 +388,8 @@ namespace Greenshot {
|
|||
}
|
||||
SoundHelper.Initialize();
|
||||
|
||||
MainForm.ResetImageScalingSize();
|
||||
|
||||
// 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
|
||||
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>
|
||||
/// Registers all hotkeys as configured, displaying a dialog in case of hotkey conflicts with other tools.
|
||||
/// </summary>
|
||||
|
|
|
@ -414,7 +414,14 @@ namespace Greenshot {
|
|||
coreConfiguration.DWMBackgroundColor = colorButton_window_background.SelectedColor;
|
||||
coreConfiguration.UpdateCheckInterval = (int)numericUpDown_daysbetweencheck.Value;
|
||||
|
||||
Size previousValue = coreConfiguration.IconSize;
|
||||
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();
|
||||
try {
|
||||
if (checkbox_autostartshortcut.Checked) {
|
||||
|
|
|
@ -35,7 +35,8 @@ namespace Greenshot.Forms {
|
|||
private static CoreConfiguration coreConfiguration = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private bool multiCheckAllowed = 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>
|
||||
/// Occurs when one of the list's child element's Checked state changes.
|
||||
/// </summary>
|
||||
|
@ -49,10 +50,16 @@ namespace Greenshot.Forms {
|
|||
Identifier = identifier;
|
||||
CheckOnClick = false;
|
||||
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;
|
||||
}
|
||||
public ToolStripMenuSelectList() : this(null,false) {}
|
||||
public ToolStripMenuSelectList(Object identifier) : this(identifier,false) {}
|
||||
public ToolStripMenuSelectList(object identifier) : this(identifier,false) {}
|
||||
|
||||
/// <summary>
|
||||
/// gets or sets the currently checked item
|
||||
|
|
|
@ -126,7 +126,7 @@ namespace ExternalCommand {
|
|||
try {
|
||||
string exePath = PluginUtils.GetExePath("cmd.exe");
|
||||
if (exePath != null && File.Exists(exePath)) {
|
||||
itemPlugInRoot.Image = PluginUtils.GetExeIcon(exePath, 0);
|
||||
itemPlugInRoot.Image = PluginUtils.GetCachedExeIcon(exePath, 0);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.Warn("Couldn't get the cmd.exe image", ex);
|
||||
|
|
|
@ -7,29 +7,21 @@ using GreenshotPlugin.Core;
|
|||
|
||||
namespace ExternalCommand {
|
||||
public static class IconCache {
|
||||
private static Dictionary<string, Image> iconCache = new Dictionary<string, Image>();
|
||||
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(IconCache));
|
||||
|
||||
public static Image IconForCommand(string commandName) {
|
||||
Image icon = null;
|
||||
if (commandName != null) {
|
||||
if (!iconCache.ContainsKey(commandName)) {
|
||||
Image icon = null;
|
||||
if (config.commandlines.ContainsKey(commandName) && File.Exists(config.commandlines[commandName])) {
|
||||
try {
|
||||
icon = PluginUtils.GetExeIcon(config.commandlines[commandName], 0);
|
||||
} catch (Exception ex) {
|
||||
LOG.Warn("Problem loading icon for " + config.commandlines[commandName], ex);
|
||||
}
|
||||
if (config.commandlines.ContainsKey(commandName) && File.Exists(config.commandlines[commandName])) {
|
||||
try {
|
||||
icon = PluginUtils.GetCachedExeIcon(config.commandlines[commandName], 0);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,16 +33,8 @@ namespace GreenshotOCR {
|
|||
private static OCRConfiguration config = IniConfig.GetIniSection<OCRConfiguration>();
|
||||
private const int MIN_WIDTH = 130;
|
||||
private const int MIN_HEIGHT = 130;
|
||||
private static Image icon = null;
|
||||
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 {
|
||||
get {
|
||||
return "OCR";
|
||||
|
@ -57,7 +49,11 @@ namespace GreenshotOCR {
|
|||
|
||||
public override Image DisplayIcon {
|
||||
get {
|
||||
return icon;
|
||||
string exePath = PluginUtils.GetExePath("MSPVIEW.EXE");
|
||||
if (exePath != null && File.Exists(exePath)) {
|
||||
return PluginUtils.GetCachedExeIcon(exePath, 0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,16 +36,14 @@ namespace GreenshotOfficePlugin {
|
|||
/// </summary>
|
||||
public class ExcelDestination : AbstractDestination {
|
||||
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 Image applicationIcon = null;
|
||||
private static Image workbookIcon = null;
|
||||
private string workbookName = null;
|
||||
|
||||
static ExcelDestination() {
|
||||
exePath = PluginUtils.GetExePath("EXCEL.EXE");
|
||||
if (exePath != null && File.Exists(exePath)) {
|
||||
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||
workbookIcon = PluginUtils.GetExeIcon(exePath, 1);
|
||||
WindowDetails.AddProcessToExcludeFromFreeze("excel");
|
||||
} else {
|
||||
exePath = null;
|
||||
|
@ -96,9 +94,9 @@ namespace GreenshotOfficePlugin {
|
|||
public override Image DisplayIcon {
|
||||
get {
|
||||
if (!string.IsNullOrEmpty(workbookName)) {
|
||||
return workbookIcon;
|
||||
return PluginUtils.GetCachedExeIcon(exePath, ICON_WORKBOOK);
|
||||
}
|
||||
return applicationIcon;
|
||||
return PluginUtils.GetCachedExeIcon(exePath, ICON_APPLICATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,32 +18,26 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* 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.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.Plugin;
|
||||
using Greenshot.Interop.Office;
|
||||
using Greenshot.IniFile;
|
||||
|
||||
namespace GreenshotOfficePlugin {
|
||||
public class OneNoteDestination : AbstractDestination {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WordDestination));
|
||||
private const int ICON_APPLICATION = 0;
|
||||
public const string DESIGNATION = "OneNote";
|
||||
private static string exePath = null;
|
||||
private static Image applicationIcon = null;
|
||||
private static Image notebookIcon = null;
|
||||
private OneNotePage page = null;
|
||||
|
||||
static OneNoteDestination() {
|
||||
exePath = PluginUtils.GetExePath("ONENOTE.EXE");
|
||||
if (exePath != null && File.Exists(exePath)) {
|
||||
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||
notebookIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||
WindowDetails.AddProcessToExcludeFromFreeze("onenote");
|
||||
} else {
|
||||
exePath = null;
|
||||
|
@ -94,10 +88,7 @@ namespace GreenshotOfficePlugin {
|
|||
|
||||
public override Image DisplayIcon {
|
||||
get {
|
||||
if (page != null) {
|
||||
return notebookIcon;
|
||||
}
|
||||
return applicationIcon;
|
||||
return PluginUtils.GetCachedExeIcon(exePath, ICON_APPLICATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,29 +18,29 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* 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.Drawing;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Interop.Office;
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
|
||||
namespace GreenshotOfficePlugin {
|
||||
/// <summary>
|
||||
/// Description of OutlookDestination.
|
||||
/// </summary>
|
||||
public class OutlookDestination : AbstractDestination {
|
||||
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 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 string mapiClient = "Microsoft Outlook";
|
||||
public const string DESIGNATION = "Outlook";
|
||||
|
@ -53,11 +53,7 @@ namespace GreenshotOfficePlugin {
|
|||
}
|
||||
exePath = PluginUtils.GetExePath("OUTLOOK.EXE");
|
||||
if (exePath != null && File.Exists(exePath)) {
|
||||
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||
WindowDetails.AddProcessToExcludeFromFreeze("outlook");
|
||||
if (conf.OutlookAllowExportInMeetings) {
|
||||
meetingIcon = PluginUtils.GetExeIcon(exePath, 2);
|
||||
}
|
||||
} else {
|
||||
exePath = null;
|
||||
}
|
||||
|
@ -119,15 +115,12 @@ namespace GreenshotOfficePlugin {
|
|||
if (outlookInspectorCaption != null) {
|
||||
if (OlObjectClass.olAppointment.Equals(outlookInspectorType)) {
|
||||
// Make sure we loaded the icon, maybe the configuration has been changed!
|
||||
if (meetingIcon == null) {
|
||||
meetingIcon = PluginUtils.GetExeIcon(exePath, 2);
|
||||
}
|
||||
return meetingIcon;
|
||||
return PluginUtils.GetCachedExeIcon(exePath, ICON_MEETING);
|
||||
} else {
|
||||
return mailIcon;
|
||||
}
|
||||
} else {
|
||||
return applicationIcon;
|
||||
return PluginUtils.GetCachedExeIcon(exePath, ICON_APPLICATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,16 +36,15 @@ namespace GreenshotOfficePlugin {
|
|||
/// </summary>
|
||||
public class PowerpointDestination : AbstractDestination {
|
||||
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 Image applicationIcon = null;
|
||||
private static Image presentationIcon = null;
|
||||
private string presentationName = null;
|
||||
|
||||
static PowerpointDestination() {
|
||||
exePath = PluginUtils.GetExePath("POWERPNT.EXE");
|
||||
if (exePath != null && File.Exists(exePath)) {
|
||||
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||
presentationIcon = PluginUtils.GetExeIcon(exePath, 1);
|
||||
WindowDetails.AddProcessToExcludeFromFreeze("powerpnt");
|
||||
} else {
|
||||
exePath = null;
|
||||
|
@ -96,10 +95,10 @@ namespace GreenshotOfficePlugin {
|
|||
public override Image DisplayIcon {
|
||||
get {
|
||||
if (!string.IsNullOrEmpty(presentationName)) {
|
||||
return presentationIcon;
|
||||
return PluginUtils.GetCachedExeIcon(exePath, ICON_PRESENTATION);
|
||||
}
|
||||
|
||||
return applicationIcon;
|
||||
return PluginUtils.GetCachedExeIcon(exePath, ICON_APPLICATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,17 +18,14 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* 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.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.Plugin;
|
||||
using Greenshot.Interop.Office;
|
||||
using Greenshot.IniFile;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace GreenshotOfficePlugin {
|
||||
|
@ -37,17 +34,14 @@ namespace GreenshotOfficePlugin {
|
|||
/// </summary>
|
||||
public class WordDestination : AbstractDestination {
|
||||
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 Image applicationIcon = null;
|
||||
private static Image documentIcon = null;
|
||||
private string documentCaption = null;
|
||||
|
||||
static WordDestination() {
|
||||
exePath = PluginUtils.GetExePath("WINWORD.EXE");
|
||||
if (exePath != null && File.Exists(exePath)) {
|
||||
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||
documentIcon = PluginUtils.GetExeIcon(exePath, 1);
|
||||
} else {
|
||||
if (exePath != null && !File.Exists(exePath)) {
|
||||
exePath = null;
|
||||
}
|
||||
}
|
||||
|
@ -97,9 +91,9 @@ namespace GreenshotOfficePlugin {
|
|||
public override Image DisplayIcon {
|
||||
get {
|
||||
if (!string.IsNullOrEmpty(documentCaption)) {
|
||||
return documentIcon;
|
||||
return PluginUtils.GetCachedExeIcon(exePath, ICON_DOCUMENT);
|
||||
}
|
||||
return applicationIcon;
|
||||
return PluginUtils.GetCachedExeIcon(exePath, ICON_APPLICATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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