Merged in sottobe/greenshot/BUG-1560 (pull request #10)

BUG-1560 added format-validation for the arguments-field
This commit is contained in:
Robin Krom 2014-12-11 22:45:48 +01:00
commit 5ae6c5dd0a
3 changed files with 24 additions and 2 deletions

View file

@ -184,7 +184,7 @@ namespace ExternalCommand {
if (!string.IsNullOrEmpty(commandline)) { if (!string.IsNullOrEmpty(commandline)) {
using (Process process = new Process()) { using (Process process = new Process()) {
process.StartInfo.FileName = commandline; process.StartInfo.FileName = commandline;
process.StartInfo.Arguments = String.Format(arguments, fullPath); process.StartInfo.Arguments = FormatArguments(arguments, fullPath);
process.StartInfo.UseShellExecute = false; process.StartInfo.UseShellExecute = false;
if (config.RedirectStandardOutput) { if (config.RedirectStandardOutput) {
process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardOutput = true;
@ -216,5 +216,10 @@ namespace ExternalCommand {
} }
return -1; return -1;
} }
}
public static string FormatArguments(string arguments, string fullpath)
{
return String.Format(arguments, fullpath);
}
}
} }

View file

@ -147,6 +147,7 @@ namespace ExternalCommand {
this.textBox_arguments.Name = "textBox_arguments"; this.textBox_arguments.Name = "textBox_arguments";
this.textBox_arguments.Size = new System.Drawing.Size(225, 20); this.textBox_arguments.Size = new System.Drawing.Size(225, 20);
this.textBox_arguments.TabIndex = 4; this.textBox_arguments.TabIndex = 4;
this.textBox_arguments.TextChanged += new System.EventHandler(this.textBox_arguments_TextChanged);
// //
// label1 // label1
// //

View file

@ -98,6 +98,7 @@ namespace ExternalCommand {
buttonOk.Enabled = true; buttonOk.Enabled = true;
textBox_name.BackColor = Color.White; textBox_name.BackColor = Color.White;
textBox_commandline.BackColor = Color.White; textBox_commandline.BackColor = Color.White;
textBox_arguments.BackColor = Color.White;
// Is there a text in the name field // Is there a text in the name field
if(string.IsNullOrEmpty(textBox_name.Text)) { if(string.IsNullOrEmpty(textBox_name.Text)) {
buttonOk.Enabled = false; buttonOk.Enabled = false;
@ -116,6 +117,16 @@ namespace ExternalCommand {
buttonOk.Enabled = false; buttonOk.Enabled = false;
textBox_commandline.BackColor = Color.Red; textBox_commandline.BackColor = Color.Red;
} }
// Are the arguments in a valid format?
try
{
ExternalCommandDestination.FormatArguments(textBox_arguments.Text, string.Empty);
}
catch
{
buttonOk.Enabled = false;
textBox_arguments.BackColor = Color.Red;
}
} }
private void textBox_name_TextChanged(object sender, EventArgs e) { private void textBox_name_TextChanged(object sender, EventArgs e) {
@ -126,5 +137,10 @@ namespace ExternalCommand {
OKButtonState(); OKButtonState();
} }
private void textBox_arguments_TextChanged(object sender, EventArgs e)
{
OKButtonState();
}
} }
} }