mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
Refactored PluginUtils to have the GetExePath and GetExeIcon, which was needed for giving the ExternalCommandPlugin an icon.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2057 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
99e672a76d
commit
91385b074e
13 changed files with 119 additions and 83 deletions
|
@ -69,12 +69,12 @@ namespace Greenshot.Destinations {
|
||||||
mailIcon = GreenshotPlugin.Core.GreenshotResources.getImage("Email.Image");
|
mailIcon = GreenshotPlugin.Core.GreenshotResources.getImage("Email.Image");
|
||||||
|
|
||||||
if (isOutlookUsed) {
|
if (isOutlookUsed) {
|
||||||
exePath = GetExePath("OUTLOOK.EXE");
|
exePath = PluginUtils.GetExePath("OUTLOOK.EXE");
|
||||||
if (exePath != null && File.Exists(exePath)) {
|
if (exePath != null && File.Exists(exePath)) {
|
||||||
applicationIcon = GetExeIcon(exePath, 0);
|
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||||
WindowDetails.AddProcessToExcludeFromFreeze("outlook");
|
WindowDetails.AddProcessToExcludeFromFreeze("outlook");
|
||||||
if (conf.OutlookAllowExportInMeetings) {
|
if (conf.OutlookAllowExportInMeetings) {
|
||||||
meetingIcon = GetExeIcon(exePath, 2);
|
meetingIcon = PluginUtils.GetExeIcon(exePath, 2);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
exePath = null;
|
exePath = null;
|
||||||
|
@ -151,7 +151,7 @@ namespace Greenshot.Destinations {
|
||||||
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) {
|
if (meetingIcon == null) {
|
||||||
meetingIcon = GetExeIcon(exePath, 2);
|
meetingIcon = PluginUtils.GetExeIcon(exePath, 2);
|
||||||
}
|
}
|
||||||
return meetingIcon;
|
return meetingIcon;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -44,10 +44,10 @@ namespace Greenshot.Destinations {
|
||||||
private string workbookName = null;
|
private string workbookName = null;
|
||||||
|
|
||||||
static ExcelDestination() {
|
static ExcelDestination() {
|
||||||
exePath = GetExePath("EXCEL.EXE");
|
exePath = PluginUtils.GetExePath("EXCEL.EXE");
|
||||||
if (exePath != null && File.Exists(exePath)) {
|
if (exePath != null && File.Exists(exePath)) {
|
||||||
applicationIcon = GetExeIcon(exePath, 0);
|
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||||
workbookIcon = GetExeIcon(exePath, 1);
|
workbookIcon = PluginUtils.GetExeIcon(exePath, 1);
|
||||||
WindowDetails.AddProcessToExcludeFromFreeze("excel");
|
WindowDetails.AddProcessToExcludeFromFreeze("excel");
|
||||||
} else {
|
} else {
|
||||||
exePath = null;
|
exePath = null;
|
||||||
|
|
|
@ -43,10 +43,10 @@ namespace Greenshot.Destinations {
|
||||||
private OneNotePage page = null;
|
private OneNotePage page = null;
|
||||||
|
|
||||||
static OneNoteDestination() {
|
static OneNoteDestination() {
|
||||||
exePath = GetExePath("ONENOTE.EXE");
|
exePath = PluginUtils.GetExePath("ONENOTE.EXE");
|
||||||
if (exePath != null && File.Exists(exePath)) {
|
if (exePath != null && File.Exists(exePath)) {
|
||||||
applicationIcon = GetExeIcon(exePath, 0);
|
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||||
notebookIcon = GetExeIcon(exePath, 0);
|
notebookIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||||
WindowDetails.AddProcessToExcludeFromFreeze("onenote");
|
WindowDetails.AddProcessToExcludeFromFreeze("onenote");
|
||||||
} else {
|
} else {
|
||||||
exePath = null;
|
exePath = null;
|
||||||
|
|
|
@ -44,10 +44,10 @@ namespace Greenshot.Destinations {
|
||||||
private string presentationName = null;
|
private string presentationName = null;
|
||||||
|
|
||||||
static PowerpointDestination() {
|
static PowerpointDestination() {
|
||||||
exePath = GetExePath("POWERPNT.EXE");
|
exePath = PluginUtils.GetExePath("POWERPNT.EXE");
|
||||||
if (exePath != null && File.Exists(exePath)) {
|
if (exePath != null && File.Exists(exePath)) {
|
||||||
applicationIcon = GetExeIcon(exePath, 0);
|
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||||
presentationIcon = GetExeIcon(exePath, 1);
|
presentationIcon = PluginUtils.GetExeIcon(exePath, 1);
|
||||||
WindowDetails.AddProcessToExcludeFromFreeze("powerpnt");
|
WindowDetails.AddProcessToExcludeFromFreeze("powerpnt");
|
||||||
} else {
|
} else {
|
||||||
exePath = null;
|
exePath = null;
|
||||||
|
|
|
@ -45,10 +45,10 @@ namespace Greenshot.Destinations {
|
||||||
private string documentCaption = null;
|
private string documentCaption = null;
|
||||||
|
|
||||||
static WordDestination() {
|
static WordDestination() {
|
||||||
exePath = GetExePath("WINWORD.EXE");
|
exePath = PluginUtils.GetExePath("WINWORD.EXE");
|
||||||
if (exePath != null && File.Exists(exePath)) {
|
if (exePath != null && File.Exists(exePath)) {
|
||||||
applicationIcon = GetExeIcon(exePath, 0);
|
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||||
documentIcon = GetExeIcon(exePath, 1);
|
documentIcon = PluginUtils.GetExeIcon(exePath, 1);
|
||||||
} else {
|
} else {
|
||||||
exePath = null;
|
exePath = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,18 +19,18 @@
|
||||||
<resource name="about_donations">If you like Greenshot, you are welcome to support us:</resource>
|
<resource name="about_donations">If you like Greenshot, you are welcome to support us:</resource>
|
||||||
<resource name="about_host">Greenshot is hosted by sourceforge.net at</resource>
|
<resource name="about_host">Greenshot is hosted by sourceforge.net at</resource>
|
||||||
<resource name="about_icons">Icons from Yusuke Kamiyamane's Fugue icon set (Creative Commons Attribution 3.0 license)</resource>
|
<resource name="about_icons">Icons from Yusuke Kamiyamane's Fugue icon set (Creative Commons Attribution 3.0 license)</resource>
|
||||||
<resource name="about_license">Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
<resource name="about_license">Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
||||||
Greenshot comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.
|
Greenshot comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions.
|
||||||
Details about the GNU General Public License:</resource>
|
Details about the GNU General Public License:</resource>
|
||||||
<resource name="about_title">About Greenshot</resource>
|
<resource name="about_title">About Greenshot</resource>
|
||||||
<resource name="application_title">Greenshot - the revolutionary screenshot utility</resource>
|
<resource name="application_title">Greenshot - the revolutionary screenshot utility</resource>
|
||||||
<resource name="bugreport_cancel">Close</resource>
|
<resource name="bugreport_cancel">Close</resource>
|
||||||
<resource name="bugreport_info">Sorry, an unexpected error occured.
|
<resource name="bugreport_info">Sorry, an unexpected error occured.
|
||||||
|
|
||||||
The good news is: you can help us getting rid of it by filing a bug report.
|
The good news is: you can help us getting rid of it by filing a bug report.
|
||||||
Please visit the URL below, create a new bug report and paste the contents from the text area into the description.
|
Please visit the URL below, create a new bug report and paste the contents from the text area into the description.
|
||||||
|
|
||||||
Please add a meaningful summary and enclose any information you consider to be helpful for reproducing the issue.
|
Please add a meaningful summary and enclose any information you consider to be helpful for reproducing the issue.
|
||||||
Also, we would highly appreciate if you checked whether a tracker item already exists for this bug. (You can use the search to find those quickly.) Thank you :)</resource>
|
Also, we would highly appreciate if you checked whether a tracker item already exists for this bug. (You can use the search to find those quickly.) Thank you :)</resource>
|
||||||
<resource name="bugreport_title">Error</resource>
|
<resource name="bugreport_title">Error</resource>
|
||||||
<resource name="clipboard_error">An unexpected error occured while writing to the clipboard.</resource>
|
<resource name="clipboard_error">An unexpected error occured while writing to the clipboard.</resource>
|
||||||
|
@ -126,7 +126,7 @@ Also, we would highly appreciate if you checked whether a tracker item already e
|
||||||
<resource name="editor_uptotop">Up to top</resource>
|
<resource name="editor_uptotop">Up to top</resource>
|
||||||
<resource name="error">Error</resource>
|
<resource name="error">Error</resource>
|
||||||
<resource name="error_multipleinstances">An instance of Greenshot is already running.</resource>
|
<resource name="error_multipleinstances">An instance of Greenshot is already running.</resource>
|
||||||
<resource name="error_nowriteaccess">Cannot save file to {0}.
|
<resource name="error_nowriteaccess">Cannot save file to {0}.
|
||||||
Please check write accessibility of the selected storage location.</resource>
|
Please check write accessibility of the selected storage location.</resource>
|
||||||
<resource name="error_openfile">The file "{0}" could not be opened.</resource>
|
<resource name="error_openfile">The file "{0}" could not be opened.</resource>
|
||||||
<resource name="error_openlink">Could not open link '{0}'.</resource>
|
<resource name="error_openlink">Could not open link '{0}'.</resource>
|
||||||
|
@ -160,22 +160,22 @@ Please check write accessibility of the selected storage location.</resource>
|
||||||
<resource name="settings_general">General</resource>
|
<resource name="settings_general">General</resource>
|
||||||
<resource name="settings_jpegquality">JPEG quality</resource>
|
<resource name="settings_jpegquality">JPEG quality</resource>
|
||||||
<resource name="settings_language">Language</resource>
|
<resource name="settings_language">Language</resource>
|
||||||
<resource name="settings_message_filenamepattern">The following placeholders will be replaced automatically in the pattern defined:
|
<resource name="settings_message_filenamepattern">The following placeholders will be replaced automatically in the pattern defined:
|
||||||
${YYYY} year, 4 digits
|
${YYYY} year, 4 digits
|
||||||
${MM} month, 2 digits
|
${MM} month, 2 digits
|
||||||
${DD} day, 2 digits
|
${DD} day, 2 digits
|
||||||
${hh} hour, 2 digits
|
${hh} hour, 2 digits
|
||||||
${mm} minute, 2 digits
|
${mm} minute, 2 digits
|
||||||
${ss} second, 2 digits
|
${ss} second, 2 digits
|
||||||
${NUM} incrementing number, 6 digits
|
${NUM} incrementing number, 6 digits
|
||||||
${title} Window title
|
${title} Window title
|
||||||
${user} Windows user
|
${user} Windows user
|
||||||
${domain} Windows domain
|
${domain} Windows domain
|
||||||
${hostname} PC name
|
${hostname} PC name
|
||||||
|
|
||||||
You can also have Greenshot create directories dynamically, simply use the backslash symbol (\) to separate folders and filename.
|
You can also have Greenshot create directories dynamically, simply use the backslash symbol (\) to separate folders and filename.
|
||||||
Example: the pattern ${YYYY}-${MM}-${DD}\${hh}-${mm}-${ss}
|
Example: the pattern ${YYYY}-${MM}-${DD}\${hh}-${mm}-${ss}
|
||||||
will generate a folder for the current day in your default storage location, e.g. 2008-06-29, the contained screenshot file's name will be based on the current
|
will generate a folder for the current day in your default storage location, e.g. 2008-06-29, the contained screenshot file's name will be based on the current
|
||||||
time, e.g. 11_58_32 (plus extension defined in the settings)</resource>
|
time, e.g. 11_58_32 (plus extension defined in the settings)</resource>
|
||||||
<resource name="settings_output">Output</resource>
|
<resource name="settings_output">Output</resource>
|
||||||
<resource name="settings_playsound">Play camera sound</resource>
|
<resource name="settings_playsound">Play camera sound</resource>
|
||||||
|
@ -196,8 +196,8 @@ time, e.g. 11_58_32 (plus extension defined in the settings)</resource>
|
||||||
<resource name="settings_waittime">Milliseconds to wait before capture</resource>
|
<resource name="settings_waittime">Milliseconds to wait before capture</resource>
|
||||||
<resource name="tooltip_firststart">Right-click here or press the {0} key.</resource>
|
<resource name="tooltip_firststart">Right-click here or press the {0} key.</resource>
|
||||||
<resource name="warning">Warning</resource>
|
<resource name="warning">Warning</resource>
|
||||||
<resource name="warning_hotkeys">The hotkey(s) "{0}" could not be registered. This problem is probably caused by another tool claiming usage of the same hotkey(s)! You could either change your hotkey settings or deactivate/change the software making use of the hotkey(s).
|
<resource name="warning_hotkeys">The hotkey(s) "{0}" could not be registered. This problem is probably caused by another tool claiming usage of the same hotkey(s)! You could either change your hotkey settings or deactivate/change the software making use of the hotkey(s).
|
||||||
|
|
||||||
All Greenshot features still work directly from the tray icon context menu without hotkeys.</resource>
|
All Greenshot features still work directly from the tray icon context menu without hotkeys.</resource>
|
||||||
<resource name="editor_grayscale">Grayscale</resource>
|
<resource name="editor_grayscale">Grayscale</resource>
|
||||||
<resource name="editor_insertwindow">Insert window</resource>
|
<resource name="editor_insertwindow">Insert window</resource>
|
||||||
|
@ -224,6 +224,7 @@ All Greenshot features still work directly from the tray icon context menu witho
|
||||||
<resource name="expertsettings_suppresssavedialogatclose">Suppress the save dialog when closing the editor</resource>
|
<resource name="expertsettings_suppresssavedialogatclose">Suppress the save dialog when closing the editor</resource>
|
||||||
<resource name="expertsettings_thumbnailpreview">Show window thumbnails in context menu (for Vista and windows 7)</resource>
|
<resource name="expertsettings_thumbnailpreview">Show window thumbnails in context menu (for Vista and windows 7)</resource>
|
||||||
<resource name="exported_to">Exported to: {0}</resource>
|
<resource name="exported_to">Exported to: {0}</resource>
|
||||||
|
<resource name="exported_to_error">An error occured while exporting to {0}:</resource>
|
||||||
<resource name="hotkey_fullscreen">Capture screen</resource>
|
<resource name="hotkey_fullscreen">Capture screen</resource>
|
||||||
<resource name="hotkey_ie">Capture Internet Explorer</resource>
|
<resource name="hotkey_ie">Capture Internet Explorer</resource>
|
||||||
<resource name="hotkey_lastregion">Capture last region</resource>
|
<resource name="hotkey_lastregion">Capture last region</resource>
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace ExternalCommand {
|
||||||
private static bool hasPaintDotNet = false;
|
private static bool hasPaintDotNet = false;
|
||||||
static ExternalCommandConfiguration() {
|
static ExternalCommandConfiguration() {
|
||||||
try {
|
try {
|
||||||
paintPath = AbstractDestination.GetExePath("pbrush.exe");
|
paintPath = PluginUtils.GetExePath("pbrush.exe");
|
||||||
hasPaint = !string.IsNullOrEmpty(paintPath) && File.Exists(paintPath);
|
hasPaint = !string.IsNullOrEmpty(paintPath) && File.Exists(paintPath);
|
||||||
paintDotNetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"Paint.NET\PaintDotNet.exe");
|
paintDotNetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"Paint.NET\PaintDotNet.exe");
|
||||||
hasPaintDotNet = !string.IsNullOrEmpty(paintDotNetPath) && File.Exists(paintDotNetPath);
|
hasPaintDotNet = !string.IsNullOrEmpty(paintDotNetPath) && File.Exists(paintDotNetPath);
|
||||||
|
|
|
@ -24,6 +24,8 @@ using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Greenshot.Plugin;
|
using Greenshot.Plugin;
|
||||||
using Greenshot.IniFile;
|
using Greenshot.IniFile;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using GreenshotPlugin.Core;
|
||||||
|
|
||||||
namespace ExternalCommand {
|
namespace ExternalCommand {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -65,13 +67,29 @@ namespace ExternalCommand {
|
||||||
}
|
}
|
||||||
this.host = pluginHost;
|
this.host = pluginHost;
|
||||||
this.myAttributes = myAttributes;
|
this.myAttributes = myAttributes;
|
||||||
|
|
||||||
|
|
||||||
|
ToolStripMenuItem itemPlugInRoot = new ToolStripMenuItem();
|
||||||
|
itemPlugInRoot.Text = Language.GetString("externalcommand", "contextmenu_configure");
|
||||||
|
itemPlugInRoot.Tag = host;
|
||||||
|
string exePath = PluginUtils.GetExePath("cmd.exe");
|
||||||
|
if (exePath != null && File.Exists(exePath)) {
|
||||||
|
itemPlugInRoot.Image = PluginUtils.GetExeIcon(exePath, 0);
|
||||||
|
}
|
||||||
|
itemPlugInRoot.Click += new System.EventHandler(ConfigMenuClick);
|
||||||
|
|
||||||
|
PluginUtils.AddToContextMenu(host, itemPlugInRoot);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Shutdown() {
|
public virtual void Shutdown() {
|
||||||
LOG.Debug("Shutdown of " + myAttributes.Name);
|
LOG.Debug("Shutdown of " + myAttributes.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ConfigMenuClick(object sender, EventArgs eventArgs) {
|
||||||
|
Configure();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implementation of the IPlugin.Configure
|
/// Implementation of the IPlugin.Configure
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace ExternalCommand {
|
||||||
Image icon = null;
|
Image icon = null;
|
||||||
if (File.Exists(config.commandlines[exepath])) {
|
if (File.Exists(config.commandlines[exepath])) {
|
||||||
try {
|
try {
|
||||||
icon = AbstractDestination.GetExeIcon(config.commandlines[exepath], 0);
|
icon = PluginUtils.GetExeIcon(config.commandlines[exepath], 0);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.Warn("Problem loading icon for " + config.commandlines[exepath], ex);
|
LOG.Warn("Problem loading icon for " + config.commandlines[exepath], ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<language description="English" ietf="en-US" version="1.0.0">
|
<language description="English" ietf="en-US" version="1.0.0">
|
||||||
<resources>
|
<resources>
|
||||||
<resource name="settings_title">
|
<resource name="contextmenu_configure">
|
||||||
|
Configure external commands
|
||||||
|
</resource>
|
||||||
|
<resource name="settings_title">
|
||||||
External command settings
|
External command settings
|
||||||
</resource>
|
</resource>
|
||||||
<resource name="settings_detail_title">
|
<resource name="settings_detail_title">
|
||||||
|
|
|
@ -43,9 +43,9 @@ namespace GreenshotOfficeCommunicatorPlugin {
|
||||||
private CommunicatorConversation conversation = null;
|
private CommunicatorConversation conversation = null;
|
||||||
|
|
||||||
static OfficeCommunicatorDestination() {
|
static OfficeCommunicatorDestination() {
|
||||||
exePath = GetExePath("communicator.exe");
|
exePath = PluginUtils.GetExePath("communicator.exe");
|
||||||
if (exePath != null && File.Exists(exePath)) {
|
if (exePath != null && File.Exists(exePath)) {
|
||||||
applicationIcon = GetExeIcon(exePath, 0);
|
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
|
||||||
} else {
|
} else {
|
||||||
exePath = null;
|
exePath = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,41 +36,8 @@ namespace GreenshotPlugin.Core {
|
||||||
/// Description of AbstractDestination.
|
/// Description of AbstractDestination.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class AbstractDestination : IDestination {
|
public abstract class AbstractDestination : IDestination {
|
||||||
private const string PATH_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\";
|
|
||||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AbstractDestination));
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AbstractDestination));
|
||||||
private static CoreConfiguration configuration = IniConfig.GetIniSection<CoreConfiguration>();
|
private static CoreConfiguration configuration = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
|
||||||
public static string GetExePath(string exeName) {
|
|
||||||
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(PATH_KEY + exeName, false)) {
|
|
||||||
if (key != null) {
|
|
||||||
// "" is the default key, which should point to the outlook location
|
|
||||||
return (string)key.GetValue("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Internaly used to create an icon
|
|
||||||
/// </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 Bitmap GetExeIcon(string path, int index) {
|
|
||||||
if (!File.Exists(path)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
using (Icon appIcon = ImageHelper.ExtractAssociatedIcon(path, index, false)) {
|
|
||||||
if (appIcon != null) {
|
|
||||||
return appIcon.ToBitmap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception exIcon) {
|
|
||||||
LOG.Error("error retrieving icon: ", exIcon);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual int CompareTo(object obj) {
|
public virtual int CompareTo(object obj) {
|
||||||
IDestination other = obj as IDestination;
|
IDestination other = obj as IDestination;
|
||||||
|
|
|
@ -23,13 +23,60 @@ using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using Greenshot.Plugin;
|
using Greenshot.Plugin;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace GreenshotPlugin.Core {
|
namespace GreenshotPlugin.Core {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Description of PluginUtils.
|
/// Description of PluginUtils.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class PluginUtils {
|
public static class PluginUtils {
|
||||||
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PluginUtils));
|
||||||
|
private const string PATH_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the path of an executable
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="exeName">e.g. cmd.exe</param>
|
||||||
|
/// <returns>Path to file</returns>
|
||||||
|
public static string GetExePath(string exeName) {
|
||||||
|
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(PATH_KEY + exeName, false)) {
|
||||||
|
if (key != null) {
|
||||||
|
// "" is the default key, which should point to the requested location
|
||||||
|
return (string)key.GetValue("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (string test in (Environment.GetEnvironmentVariable("PATH") ?? "").Split(';')) {
|
||||||
|
string path = test.Trim();
|
||||||
|
if (!String.IsNullOrEmpty(path) && File.Exists(path = Path.Combine(path, exeName))) {
|
||||||
|
return Path.GetFullPath(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get icon for executable
|
||||||
|
/// </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 Bitmap GetExeIcon(string path, int index) {
|
||||||
|
if (!File.Exists(path)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
using (Icon appIcon = ImageHelper.ExtractAssociatedIcon(path, index, false)) {
|
||||||
|
if (appIcon != null) {
|
||||||
|
return appIcon.ToBitmap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception exIcon) {
|
||||||
|
LOG.Error("error retrieving icon: ", exIcon);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper method to add a MenuItem to the File MenuItem of an ImageEditor
|
/// Helper method to add a MenuItem to the File MenuItem of an ImageEditor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue