From 91385b074e635098a390048ee7e3972c066486b3 Mon Sep 17 00:00:00 2001 From: RKrom Date: Wed, 19 Sep 2012 10:05:26 +0000 Subject: [PATCH] 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 --- Greenshot/Destinations/EmailDestination.cs | 8 +-- Greenshot/Destinations/ExcelDestination.cs | 6 +- Greenshot/Destinations/OneNoteDestination.cs | 6 +- .../Destinations/PowerpointDestination.cs | 6 +- Greenshot/Destinations/WordDestination.cs | 6 +- Greenshot/Languages/language-en-US.xml | 55 ++++++++++--------- .../ExternalCommandConfiguration.cs | 2 +- .../ExternalCommandPlugin.cs | 20 ++++++- GreenshotExternalCommandPlugin/IconCache.cs | 2 +- .../language_externalcommandplugin-en-US.xml | 5 +- .../OfficeCommunicatorDestination.cs | 4 +- GreenshotPlugin/Core/AbstractDestination.cs | 33 ----------- GreenshotPlugin/Core/PluginUtils.cs | 49 ++++++++++++++++- 13 files changed, 119 insertions(+), 83 deletions(-) diff --git a/Greenshot/Destinations/EmailDestination.cs b/Greenshot/Destinations/EmailDestination.cs index 0b04a5d04..3beb89055 100644 --- a/Greenshot/Destinations/EmailDestination.cs +++ b/Greenshot/Destinations/EmailDestination.cs @@ -69,12 +69,12 @@ namespace Greenshot.Destinations { mailIcon = GreenshotPlugin.Core.GreenshotResources.getImage("Email.Image"); if (isOutlookUsed) { - exePath = GetExePath("OUTLOOK.EXE"); + exePath = PluginUtils.GetExePath("OUTLOOK.EXE"); if (exePath != null && File.Exists(exePath)) { - applicationIcon = GetExeIcon(exePath, 0); + applicationIcon = PluginUtils.GetExeIcon(exePath, 0); WindowDetails.AddProcessToExcludeFromFreeze("outlook"); if (conf.OutlookAllowExportInMeetings) { - meetingIcon = GetExeIcon(exePath, 2); + meetingIcon = PluginUtils.GetExeIcon(exePath, 2); } } else { exePath = null; @@ -151,7 +151,7 @@ namespace Greenshot.Destinations { if (OlObjectClass.olAppointment.Equals(outlookInspectorType)) { // Make sure we loaded the icon, maybe the configuration has been changed! if (meetingIcon == null) { - meetingIcon = GetExeIcon(exePath, 2); + meetingIcon = PluginUtils.GetExeIcon(exePath, 2); } return meetingIcon; } else { diff --git a/Greenshot/Destinations/ExcelDestination.cs b/Greenshot/Destinations/ExcelDestination.cs index 7240f2a9b..f18f3764f 100644 --- a/Greenshot/Destinations/ExcelDestination.cs +++ b/Greenshot/Destinations/ExcelDestination.cs @@ -44,10 +44,10 @@ namespace Greenshot.Destinations { private string workbookName = null; static ExcelDestination() { - exePath = GetExePath("EXCEL.EXE"); + exePath = PluginUtils.GetExePath("EXCEL.EXE"); if (exePath != null && File.Exists(exePath)) { - applicationIcon = GetExeIcon(exePath, 0); - workbookIcon = GetExeIcon(exePath, 1); + applicationIcon = PluginUtils.GetExeIcon(exePath, 0); + workbookIcon = PluginUtils.GetExeIcon(exePath, 1); WindowDetails.AddProcessToExcludeFromFreeze("excel"); } else { exePath = null; diff --git a/Greenshot/Destinations/OneNoteDestination.cs b/Greenshot/Destinations/OneNoteDestination.cs index 78b8833e5..a120a0738 100644 --- a/Greenshot/Destinations/OneNoteDestination.cs +++ b/Greenshot/Destinations/OneNoteDestination.cs @@ -43,10 +43,10 @@ namespace Greenshot.Destinations { private OneNotePage page = null; static OneNoteDestination() { - exePath = GetExePath("ONENOTE.EXE"); + exePath = PluginUtils.GetExePath("ONENOTE.EXE"); if (exePath != null && File.Exists(exePath)) { - applicationIcon = GetExeIcon(exePath, 0); - notebookIcon = GetExeIcon(exePath, 0); + applicationIcon = PluginUtils.GetExeIcon(exePath, 0); + notebookIcon = PluginUtils.GetExeIcon(exePath, 0); WindowDetails.AddProcessToExcludeFromFreeze("onenote"); } else { exePath = null; diff --git a/Greenshot/Destinations/PowerpointDestination.cs b/Greenshot/Destinations/PowerpointDestination.cs index caffae3e6..9cf99c688 100644 --- a/Greenshot/Destinations/PowerpointDestination.cs +++ b/Greenshot/Destinations/PowerpointDestination.cs @@ -44,10 +44,10 @@ namespace Greenshot.Destinations { private string presentationName = null; static PowerpointDestination() { - exePath = GetExePath("POWERPNT.EXE"); + exePath = PluginUtils.GetExePath("POWERPNT.EXE"); if (exePath != null && File.Exists(exePath)) { - applicationIcon = GetExeIcon(exePath, 0); - presentationIcon = GetExeIcon(exePath, 1); + applicationIcon = PluginUtils.GetExeIcon(exePath, 0); + presentationIcon = PluginUtils.GetExeIcon(exePath, 1); WindowDetails.AddProcessToExcludeFromFreeze("powerpnt"); } else { exePath = null; diff --git a/Greenshot/Destinations/WordDestination.cs b/Greenshot/Destinations/WordDestination.cs index 15a8ac49f..2f11c3b1a 100644 --- a/Greenshot/Destinations/WordDestination.cs +++ b/Greenshot/Destinations/WordDestination.cs @@ -45,10 +45,10 @@ namespace Greenshot.Destinations { private string documentCaption = null; static WordDestination() { - exePath = GetExePath("WINWORD.EXE"); + exePath = PluginUtils.GetExePath("WINWORD.EXE"); if (exePath != null && File.Exists(exePath)) { - applicationIcon = GetExeIcon(exePath, 0); - documentIcon = GetExeIcon(exePath, 1); + applicationIcon = PluginUtils.GetExeIcon(exePath, 0); + documentIcon = PluginUtils.GetExeIcon(exePath, 1); } else { exePath = null; } diff --git a/Greenshot/Languages/language-en-US.xml b/Greenshot/Languages/language-en-US.xml index af61017a8..9db371e76 100644 --- a/Greenshot/Languages/language-en-US.xml +++ b/Greenshot/Languages/language-en-US.xml @@ -19,18 +19,18 @@ If you like Greenshot, you are welcome to support us: Greenshot is hosted by sourceforge.net at Icons from Yusuke Kamiyamane's Fugue icon set (Creative Commons Attribution 3.0 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. + 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. Details about the GNU General Public License: About Greenshot Greenshot - the revolutionary screenshot utility Close - Sorry, an unexpected error occured. - -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 add a meaningful summary and enclose any information you consider to be helpful for reproducing the issue. + Sorry, an unexpected error occured. + +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 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 :) Error An unexpected error occured while writing to the clipboard. @@ -126,7 +126,7 @@ Also, we would highly appreciate if you checked whether a tracker item already e Up to top Error An instance of Greenshot is already running. - Cannot save file to {0}. + Cannot save file to {0}. Please check write accessibility of the selected storage location. The file "{0}" could not be opened. Could not open link '{0}'. @@ -160,22 +160,22 @@ Please check write accessibility of the selected storage location. General JPEG quality Language - The following placeholders will be replaced automatically in the pattern defined: -${YYYY} year, 4 digits -${MM} month, 2 digits -${DD} day, 2 digits -${hh} hour, 2 digits -${mm} minute, 2 digits -${ss} second, 2 digits -${NUM} incrementing number, 6 digits -${title} Window title -${user} Windows user -${domain} Windows domain -${hostname} PC name - -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} -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 + The following placeholders will be replaced automatically in the pattern defined: +${YYYY} year, 4 digits +${MM} month, 2 digits +${DD} day, 2 digits +${hh} hour, 2 digits +${mm} minute, 2 digits +${ss} second, 2 digits +${NUM} incrementing number, 6 digits +${title} Window title +${user} Windows user +${domain} Windows domain +${hostname} PC name + +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} +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) Output Play camera sound @@ -196,8 +196,8 @@ time, e.g. 11_58_32 (plus extension defined in the settings) Milliseconds to wait before capture Right-click here or press the {0} key. Warning - 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). - + 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. Grayscale Insert window @@ -224,6 +224,7 @@ All Greenshot features still work directly from the tray icon context menu witho Suppress the save dialog when closing the editor Show window thumbnails in context menu (for Vista and windows 7) Exported to: {0} + An error occured while exporting to {0}: Capture screen Capture Internet Explorer Capture last region diff --git a/GreenshotExternalCommandPlugin/ExternalCommandConfiguration.cs b/GreenshotExternalCommandPlugin/ExternalCommandConfiguration.cs index 48c3224e6..6780aa0ac 100644 --- a/GreenshotExternalCommandPlugin/ExternalCommandConfiguration.cs +++ b/GreenshotExternalCommandPlugin/ExternalCommandConfiguration.cs @@ -49,7 +49,7 @@ namespace ExternalCommand { private static bool hasPaintDotNet = false; static ExternalCommandConfiguration() { try { - paintPath = AbstractDestination.GetExePath("pbrush.exe"); + paintPath = PluginUtils.GetExePath("pbrush.exe"); hasPaint = !string.IsNullOrEmpty(paintPath) && File.Exists(paintPath); paintDotNetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"Paint.NET\PaintDotNet.exe"); hasPaintDotNet = !string.IsNullOrEmpty(paintDotNetPath) && File.Exists(paintDotNetPath); diff --git a/GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs b/GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs index 66ad6441a..aadbec1a7 100644 --- a/GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs +++ b/GreenshotExternalCommandPlugin/ExternalCommandPlugin.cs @@ -24,6 +24,8 @@ using System.Diagnostics; using System.IO; using Greenshot.Plugin; using Greenshot.IniFile; +using System.Windows.Forms; +using GreenshotPlugin.Core; namespace ExternalCommand { /// @@ -65,13 +67,29 @@ namespace ExternalCommand { } this.host = pluginHost; 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; } public virtual void Shutdown() { LOG.Debug("Shutdown of " + myAttributes.Name); } - + + private void ConfigMenuClick(object sender, EventArgs eventArgs) { + Configure(); + } + /// /// Implementation of the IPlugin.Configure /// diff --git a/GreenshotExternalCommandPlugin/IconCache.cs b/GreenshotExternalCommandPlugin/IconCache.cs index 00bb99e6d..8a4a51b06 100644 --- a/GreenshotExternalCommandPlugin/IconCache.cs +++ b/GreenshotExternalCommandPlugin/IconCache.cs @@ -18,7 +18,7 @@ namespace ExternalCommand { Image icon = null; if (File.Exists(config.commandlines[exepath])) { try { - icon = AbstractDestination.GetExeIcon(config.commandlines[exepath], 0); + icon = PluginUtils.GetExeIcon(config.commandlines[exepath], 0); } catch (Exception ex) { LOG.Warn("Problem loading icon for " + config.commandlines[exepath], ex); } diff --git a/GreenshotExternalCommandPlugin/Languages/language_externalcommandplugin-en-US.xml b/GreenshotExternalCommandPlugin/Languages/language_externalcommandplugin-en-US.xml index 63f30a950..336edb63b 100644 --- a/GreenshotExternalCommandPlugin/Languages/language_externalcommandplugin-en-US.xml +++ b/GreenshotExternalCommandPlugin/Languages/language_externalcommandplugin-en-US.xml @@ -1,7 +1,10 @@  - + + Configure external commands + + External command settings diff --git a/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorDestination.cs b/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorDestination.cs index 8c9ee8589..8396db857 100644 --- a/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorDestination.cs +++ b/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorDestination.cs @@ -43,9 +43,9 @@ namespace GreenshotOfficeCommunicatorPlugin { private CommunicatorConversation conversation = null; static OfficeCommunicatorDestination() { - exePath = GetExePath("communicator.exe"); + exePath = PluginUtils.GetExePath("communicator.exe"); if (exePath != null && File.Exists(exePath)) { - applicationIcon = GetExeIcon(exePath, 0); + applicationIcon = PluginUtils.GetExeIcon(exePath, 0); } else { exePath = null; } diff --git a/GreenshotPlugin/Core/AbstractDestination.cs b/GreenshotPlugin/Core/AbstractDestination.cs index dc6c714cd..8c957aec1 100644 --- a/GreenshotPlugin/Core/AbstractDestination.cs +++ b/GreenshotPlugin/Core/AbstractDestination.cs @@ -36,41 +36,8 @@ namespace GreenshotPlugin.Core { /// Description of AbstractDestination. /// 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 CoreConfiguration configuration = IniConfig.GetIniSection(); - - 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; - } - - /// - /// Internaly used to create an icon - /// - /// path to the exe or dll - /// index of the icon - /// Bitmap with the icon or null if something happended - 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) { IDestination other = obj as IDestination; diff --git a/GreenshotPlugin/Core/PluginUtils.cs b/GreenshotPlugin/Core/PluginUtils.cs index a1cf4c906..e571619ea 100644 --- a/GreenshotPlugin/Core/PluginUtils.cs +++ b/GreenshotPlugin/Core/PluginUtils.cs @@ -23,13 +23,60 @@ using System.Drawing; using System.Windows.Forms; using Greenshot.Plugin; +using Microsoft.Win32; +using System.IO; namespace GreenshotPlugin.Core { /// /// Description of 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\"; + + /// + /// Get the path of an executable + /// + /// e.g. cmd.exe + /// Path to file + 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; + } + + /// + /// Get icon for executable + /// + /// path to the exe or dll + /// index of the icon + /// Bitmap with the icon or null if something happended + 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; + } + /// /// Helper method to add a MenuItem to the File MenuItem of an ImageEditor ///