Merge remote-tracking branch 'remotes/origin/master' into release/1.2.9

This commit is contained in:
Robin 2016-05-24 13:13:48 +02:00
commit 0323705513
276 changed files with 5382 additions and 3666 deletions

View file

@ -61,12 +61,12 @@ namespace ExternalCommand {
public Dictionary<string, bool> runInbackground;
private const string MSPAINT = "MS Paint";
private static string paintPath;
private static bool hasPaint = false;
private static readonly string paintPath;
private static readonly bool hasPaint = false;
private const string PAINTDOTNET = "Paint.NET";
private static string paintDotNetPath;
private static bool hasPaintDotNet = false;
private static readonly string paintDotNetPath;
private static readonly bool hasPaintDotNet = false;
static ExternalCommandConfiguration() {
try {
paintPath = PluginUtils.GetExePath("pbrush.exe");

View file

@ -34,24 +34,24 @@ namespace ExternalCommand {
/// Description of OCRDestination.
/// </summary>
public class ExternalCommandDestination : AbstractDestination {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExternalCommandDestination));
private static Regex URI_REGEXP = new Regex(@"((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)");
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
private string presetCommand;
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExternalCommandDestination));
private static readonly Regex URI_REGEXP = new Regex(@"((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)");
private static readonly ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
private readonly string _presetCommand;
public ExternalCommandDestination(string commando) {
this.presetCommand = commando;
_presetCommand = commando;
}
public override string Designation {
get {
return "External " + presetCommand.Replace(',','_');
return "External " + _presetCommand.Replace(',','_');
}
}
public override string Description {
get {
return presetCommand;
return _presetCommand;
}
}
@ -61,20 +61,20 @@ namespace ExternalCommand {
public override Image DisplayIcon {
get {
return IconCache.IconForCommand(presetCommand);
return IconCache.IconForCommand(_presetCommand);
}
}
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
ExportInformation exportInformation = new ExportInformation(Designation, Description);
SurfaceOutputSettings outputSettings = new SurfaceOutputSettings();
if (presetCommand != null) {
if (!config.runInbackground.ContainsKey(presetCommand)) {
config.runInbackground.Add(presetCommand, true);
if (_presetCommand != null) {
if (!config.runInbackground.ContainsKey(_presetCommand)) {
config.runInbackground.Add(_presetCommand, true);
}
bool runInBackground = config.runInbackground[presetCommand];
bool runInBackground = config.runInbackground[_presetCommand];
string fullPath = captureDetails.Filename;
if (fullPath == null) {
fullPath = ImageOutput.SaveNamedTmpFile(surface, captureDetails, outputSettings);
@ -83,17 +83,20 @@ namespace ExternalCommand {
string output;
string error;
if (runInBackground) {
Thread commandThread = new Thread(delegate() {
CallExternalCommand(exportInformation, presetCommand, fullPath, out output, out error);
Thread commandThread = new Thread(delegate()
{
CallExternalCommand(exportInformation, fullPath, out output, out error);
ProcessExport(exportInformation, surface);
});
commandThread.Name = "Running " + presetCommand;
commandThread.IsBackground = true;
})
{
Name = "Running " + _presetCommand,
IsBackground = true
};
commandThread.SetApartmentState(ApartmentState.STA);
commandThread.Start();
exportInformation.ExportMade = true;
} else {
CallExternalCommand(exportInformation, presetCommand, fullPath, out output, out error);
CallExternalCommand(exportInformation, fullPath, out output, out error);
ProcessExport(exportInformation, surface);
}
}
@ -105,15 +108,14 @@ namespace ExternalCommand {
/// Call the external command, parse for URI, place to clipboard and set the export information
/// </summary>
/// <param name="exportInformation"></param>
/// <param name="commando"></param>
/// <param name="fullPath"></param>
/// <param name="output"></param>
/// <param name="error"></param>
private void CallExternalCommand(ExportInformation exportInformation, string commando, string fullPath, out string output, out string error) {
private void CallExternalCommand(ExportInformation exportInformation, string fullPath, out string output, out string error) {
output = null;
error = null;
try {
if (CallExternalCommand(presetCommand, fullPath, out output, out error) == 0) {
if (CallExternalCommand(_presetCommand, fullPath, out output, out error) == 0) {
exportInformation.ExportMade = true;
if (!string.IsNullOrEmpty(output)) {
MatchCollection uriMatches = URI_REGEXP.Matches(output);
@ -121,7 +123,7 @@ namespace ExternalCommand {
if (config.OutputToClipboard) {
ClipboardHelper.SetClipboardData(output);
}
if (uriMatches != null && uriMatches.Count > 0) {
if (uriMatches.Count > 0) {
exportInformation.Uri = uriMatches[0].Groups[1].Value;
LOG.InfoFormat("Got URI : {0} ", exportInformation.Uri);
if (config.UriToClipboard) {
@ -156,13 +158,13 @@ namespace ExternalCommand {
try {
return CallExternalCommand(commando, fullPath, "runas", out output, out error);
} catch {
w32ex.Data.Add("commandline", config.commandlines[presetCommand]);
w32ex.Data.Add("arguments", config.arguments[presetCommand]);
w32ex.Data.Add("commandline", config.commandlines[_presetCommand]);
w32ex.Data.Add("arguments", config.arguments[_presetCommand]);
throw;
}
} catch (Exception ex) {
ex.Data.Add("commandline", config.commandlines[presetCommand]);
ex.Data.Add("arguments", config.arguments[presetCommand]);
ex.Data.Add("commandline", config.commandlines[_presetCommand]);
ex.Data.Add("arguments", config.arguments[_presetCommand]);
throw;
}
}
@ -182,8 +184,16 @@ namespace ExternalCommand {
output = null;
error = null;
if (!string.IsNullOrEmpty(commandline)) {
using (Process process = new Process()) {
process.StartInfo.FileName = commandline;
using (Process process = new Process())
{
// Fix variables
commandline = FilenameHelper.FillVariables(commandline, true);
commandline = FilenameHelper.FillCmdVariables(commandline, true);
arguments = FilenameHelper.FillVariables(arguments, false);
arguments = FilenameHelper.FillCmdVariables(arguments, false);
process.StartInfo.FileName = FilenameHelper.FillCmdVariables(commandline, true);
process.StartInfo.Arguments = FormatArguments(arguments, fullPath);
process.StartInfo.UseShellExecute = false;
if (config.RedirectStandardOutput) {
@ -200,13 +210,13 @@ namespace ExternalCommand {
process.WaitForExit();
if (config.RedirectStandardOutput) {
output = process.StandardOutput.ReadToEnd();
if (config.ShowStandardOutputInLog && output != null && output.Trim().Length > 0) {
if (config.ShowStandardOutputInLog && output.Trim().Length > 0) {
LOG.InfoFormat("Output:\n{0}", output);
}
}
if (config.RedirectStandardError) {
error = process.StandardError.ReadToEnd();
if (error != null && error.Trim().Length > 0) {
if (error.Trim().Length > 0) {
LOG.WarnFormat("Error:\n{0}", error);
}
}
@ -219,7 +229,7 @@ namespace ExternalCommand {
public static string FormatArguments(string arguments, string fullpath)
{
return String.Format(arguments, fullpath);
return string.Format(arguments, fullpath);
}
}
}

View file

@ -34,11 +34,11 @@ namespace ExternalCommand {
/// </summary>
public class ExternalCommandPlugin : IGreenshotPlugin {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExternalCommandPlugin));
private static CoreConfiguration coreConfig = IniConfig.GetIniSection<CoreConfiguration>();
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
private IGreenshotHost host;
private PluginAttribute myAttributes;
private ToolStripMenuItem itemPlugInRoot;
private static readonly CoreConfiguration coreConfig = IniConfig.GetIniSection<CoreConfiguration>();
private static readonly ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
private IGreenshotHost _host;
private PluginAttribute _myAttributes;
private ToolStripMenuItem _itemPlugInRoot;
public void Dispose() {
Dispose(true);
@ -47,16 +47,13 @@ namespace ExternalCommand {
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (itemPlugInRoot != null) {
itemPlugInRoot.Dispose();
itemPlugInRoot = null;
if (_itemPlugInRoot != null) {
_itemPlugInRoot.Dispose();
_itemPlugInRoot = null;
}
}
}
public ExternalCommandPlugin() {
}
public IEnumerable<IDestination> Destinations() {
foreach(string command in config.commands) {
yield return new ExternalCommandDestination(command);
@ -87,7 +84,10 @@ namespace ExternalCommand {
LOG.WarnFormat("Found missing commandline for {0}", command);
return false;
}
if (!File.Exists(config.commandlines[command])) {
string commandline = FilenameHelper.FillVariables(config.commandlines[command], true);
commandline = FilenameHelper.FillCmdVariables(commandline, true);
if (!File.Exists(commandline)) {
LOG.WarnFormat("Found 'invalid' commandline {0} for command {1}", config.commandlines[command], command);
return false;
}
@ -118,17 +118,17 @@ namespace ExternalCommand {
config.commands.Remove(command);
}
this.host = pluginHost;
this.myAttributes = myAttributes;
_host = pluginHost;
_myAttributes = myAttributes;
itemPlugInRoot = new ToolStripMenuItem();
itemPlugInRoot.Tag = host;
_itemPlugInRoot = new ToolStripMenuItem();
_itemPlugInRoot.Tag = _host;
OnIconSizeChanged(this, new PropertyChangedEventArgs("IconSize"));
OnLanguageChanged(this, null);
itemPlugInRoot.Click += new System.EventHandler(ConfigMenuClick);
_itemPlugInRoot.Click += new EventHandler(ConfigMenuClick);
PluginUtils.AddToContextMenu(host, itemPlugInRoot);
PluginUtils.AddToContextMenu(_host, _itemPlugInRoot);
Language.LanguageChanged += OnLanguageChanged;
coreConfig.PropertyChanged += OnIconSizeChanged;
return true;
@ -144,7 +144,7 @@ namespace ExternalCommand {
try {
string exePath = PluginUtils.GetExePath("cmd.exe");
if (exePath != null && File.Exists(exePath)) {
itemPlugInRoot.Image = PluginUtils.GetCachedExeIcon(exePath, 0);
_itemPlugInRoot.Image = PluginUtils.GetCachedExeIcon(exePath, 0);
}
} catch (Exception ex) {
LOG.Warn("Couldn't get the cmd.exe image", ex);
@ -153,13 +153,13 @@ namespace ExternalCommand {
}
private void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInRoot != null) {
itemPlugInRoot.Text = Language.GetString("externalcommand", "contextmenu_configure");
if (_itemPlugInRoot != null) {
_itemPlugInRoot.Text = Language.GetString("externalcommand", "contextmenu_configure");
}
}
public virtual void Shutdown() {
LOG.Debug("Shutdown of " + myAttributes.Name);
LOG.Debug("Shutdown of " + _myAttributes.Name);
}
private void ConfigMenuClick(object sender, EventArgs eventArgs) {

View file

@ -1,5 +1,25 @@
using System;
using System.Collections.Generic;
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2015 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;
using System.Drawing;
using System.IO;
using Greenshot.IniFile;
@ -7,8 +27,8 @@ using GreenshotPlugin.Core;
namespace ExternalCommand {
public static class IconCache {
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(IconCache));
private static readonly ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(IconCache));
public static Image IconForCommand(string commandName) {
Image icon = null;

View file

@ -22,7 +22,6 @@
using Greenshot.Plugin;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information

View file

@ -30,7 +30,7 @@ namespace ExternalCommand {
/// </summary>
public partial class SettingsForm : ExternalCommandForm {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SettingsForm));
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
private static readonly ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
public SettingsForm() {
//

View file

@ -24,44 +24,45 @@ using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using GreenshotPlugin.Core;
namespace ExternalCommand {
/// <summary>
/// Description of SettingsFormDetail.
/// </summary>
public partial class SettingsFormDetail : ExternalCommandForm {
private string commando;
private int commandIndex;
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SettingsFormDetail));
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
private static readonly ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
private readonly string _commando;
private readonly int _commandIndex;
public SettingsFormDetail(string commando) {
InitializeComponent();
AcceptButton = buttonOk;
CancelButton = buttonCancel;
this.commando = commando;
_commando = commando;
if(commando != null) {
textBox_name.Text = commando;
textBox_commandline.Text = config.commandlines[commando];
textBox_arguments.Text = config.arguments[commando];
commandIndex = config.commands.FindIndex(delegate(string s) { return s == commando; });
_commandIndex = config.commands.FindIndex(delegate(string s) { return s == commando; });
} else {
textBox_arguments.Text = "\"{0}\"";
}
OKButtonState();
OkButtonState();
}
void ButtonOkClick(object sender, EventArgs e) {
string commandName = textBox_name.Text;
string commandLine = textBox_commandline.Text;
string arguments = textBox_arguments.Text;
if(commando != null) {
config.commands[commandIndex] = commandName;
config.commandlines.Remove(commando);
if(_commando != null) {
config.commands[_commandIndex] = commandName;
config.commandlines.Remove(_commando);
config.commandlines.Add(commandName, commandLine);
config.arguments.Remove(commando);
config.arguments.Remove(_commando);
config.arguments.Add(commandName, arguments);
} else {
config.commands.Add(commandName);
@ -71,15 +72,23 @@ namespace ExternalCommand {
}
void Button3Click(object sender, EventArgs e) {
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Executables (*.exe, *.bat, *.com)|*.exe; *.bat; *.com|All files (*)|*";
openFileDialog.FilterIndex = 1;
openFileDialog.CheckFileExists = true;
openFileDialog.Multiselect = false;
OpenFileDialog openFileDialog = new OpenFileDialog
{
Filter = "Executables (*.exe, *.bat, *.com)|*.exe; *.bat; *.com|All files (*)|*",
FilterIndex = 1,
CheckFileExists = true,
Multiselect = false
};
string initialPath = null;
try {
try
{
initialPath = Path.GetDirectoryName(textBox_commandline.Text);
} catch { }
}
catch (Exception ex)
{
LOG.WarnFormat("Can't get the initial path via {0}", textBox_commandline.Text);
LOG.Warn("Exception: ", ex);
}
if(initialPath != null && Directory.Exists(initialPath)) {
openFileDialog.InitialDirectory = initialPath;
} else {
@ -92,7 +101,7 @@ namespace ExternalCommand {
}
}
private void OKButtonState() {
private void OkButtonState() {
// Assume OK
buttonOk.Enabled = true;
textBox_name.BackColor = Color.White;
@ -103,7 +112,7 @@ namespace ExternalCommand {
buttonOk.Enabled = false;
}
// Check if commandname is unique
if(commando == null && !string.IsNullOrEmpty(textBox_name.Text) && config.commands.Contains(textBox_name.Text)) {
if(_commando == null && !string.IsNullOrEmpty(textBox_name.Text) && config.commands.Contains(textBox_name.Text)) {
buttonOk.Enabled = false;
textBox_name.BackColor = Color.Red;
}
@ -111,15 +120,27 @@ namespace ExternalCommand {
if(string.IsNullOrEmpty(textBox_commandline.Text)) {
buttonOk.Enabled = false;
}
// Is the command available?
if(!string.IsNullOrEmpty(textBox_commandline.Text) && !File.Exists(textBox_commandline.Text)) {
buttonOk.Enabled = false;
textBox_commandline.BackColor = Color.Red;
if (!string.IsNullOrEmpty(textBox_commandline.Text))
{
// Added this to be more flexible, using the Greenshot var format
string cmdPath = FilenameHelper.FillVariables(textBox_commandline.Text, true);
// And also replace the "DOS" Variables
cmdPath = FilenameHelper.FillCmdVariables(cmdPath, true);
// Is the command available?
if (!File.Exists(cmdPath))
{
buttonOk.Enabled = false;
textBox_commandline.BackColor = Color.Red;
}
}
// Are the arguments in a valid format?
try
// Are the arguments in a valid format?
try
{
ExternalCommandDestination.FormatArguments(textBox_arguments.Text, string.Empty);
string arguments = FilenameHelper.FillVariables(textBox_arguments.Text, false);
arguments = FilenameHelper.FillCmdVariables(arguments, false);
ExternalCommandDestination.FormatArguments(arguments, string.Empty);
}
catch
{
@ -129,16 +150,16 @@ namespace ExternalCommand {
}
private void textBox_name_TextChanged(object sender, EventArgs e) {
OKButtonState();
OkButtonState();
}
private void textBox_commandline_TextChanged(object sender, EventArgs e) {
OKButtonState();
OkButtonState();
}
private void textBox_arguments_TextChanged(object sender, EventArgs e)
{
OKButtonState();
OkButtonState();
}
}