mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 10:47:02 -07:00
Some small fixes for different parts of code.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2087 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
3411432a0e
commit
a5f900f92e
5 changed files with 79 additions and 29 deletions
|
@ -39,7 +39,10 @@ namespace ExternalCommand {
|
|||
|
||||
[IniProperty("Argument", Description="The arguments for the output command.")]
|
||||
public Dictionary<string, string> arguments;
|
||||
|
||||
|
||||
[IniProperty("RunInbackground", Description = "Should the command be started in the background.")]
|
||||
public Dictionary<string, bool> runInbackground;
|
||||
|
||||
private const string MSPAINT = "MS Paint";
|
||||
private static string paintPath;
|
||||
private static bool hasPaint = false;
|
||||
|
@ -84,11 +87,22 @@ namespace ExternalCommand {
|
|||
return commandlineDefaults;
|
||||
case "Argument":
|
||||
Dictionary<string, string> argumentDefaults = new Dictionary<string, string>();
|
||||
argumentDefaults.Add(PAINTDOTNET, "\"{0}\"");
|
||||
if (hasPaintDotNet) {
|
||||
argumentDefaults.Add(PAINTDOTNET, "\"{0}\"");
|
||||
}
|
||||
if (hasPaint) {
|
||||
argumentDefaults.Add(MSPAINT, "\"{0}\"");
|
||||
}
|
||||
return argumentDefaults;
|
||||
return argumentDefaults;
|
||||
case "RunInBackground":
|
||||
Dictionary<string, bool> runInBackground = new Dictionary<string, bool>();
|
||||
if (hasPaintDotNet) {
|
||||
runInBackground.Add(PAINTDOTNET, true);
|
||||
}
|
||||
if (hasPaint) {
|
||||
runInBackground.Add(MSPAINT, true);
|
||||
}
|
||||
return runInBackground;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -70,29 +70,50 @@ namespace ExternalCommand {
|
|||
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
|
||||
OutputSettings outputSettings = new OutputSettings();
|
||||
|
||||
string fullPath = captureDetails.Filename;
|
||||
if (fullPath == null) {
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
fullPath = host.SaveNamedTmpFile(image, captureDetails, outputSettings);
|
||||
}
|
||||
}
|
||||
|
||||
if (presetCommand != null) {
|
||||
Thread commandThread = new Thread (delegate() {
|
||||
CallExternalCommand(presetCommand, fullPath);
|
||||
});
|
||||
commandThread.Name = "Running " + presetCommand;
|
||||
commandThread.IsBackground = true;
|
||||
commandThread.Start();
|
||||
exportInformation.ExportMade = true;
|
||||
if (!config.runInbackground.ContainsKey(presetCommand)) {
|
||||
config.runInbackground.Add(presetCommand, true);
|
||||
}
|
||||
bool runInBackground = config.runInbackground[presetCommand];
|
||||
string fullPath = captureDetails.Filename;
|
||||
if (fullPath == null) {
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
fullPath = host.SaveNamedTmpFile(image, captureDetails, outputSettings);
|
||||
}
|
||||
}
|
||||
|
||||
string output = null;
|
||||
if (runInBackground) {
|
||||
Thread commandThread = new Thread(delegate() {
|
||||
CallExternalCommand(presetCommand, fullPath, out output);
|
||||
});
|
||||
commandThread.Name = "Running " + presetCommand;
|
||||
commandThread.IsBackground = true;
|
||||
commandThread.Start();
|
||||
exportInformation.ExportMade = true;
|
||||
} else {
|
||||
try {
|
||||
if (CallExternalCommand(presetCommand, fullPath, out output) == 0) {
|
||||
exportInformation.ExportMade = true;
|
||||
} else {
|
||||
exportInformation.ErrorMessage = output;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
exportInformation.ErrorMessage = ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
//exportInformation.Uri = "file://" + fullPath;
|
||||
}
|
||||
ProcessExport(exportInformation, surface);
|
||||
return exportInformation;
|
||||
}
|
||||
|
||||
private void CallExternalCommand(string commando, string fullPath) {
|
||||
private int CallExternalCommand(string commando, string fullPath, out string output) {
|
||||
string commandline = config.commandlines[commando];
|
||||
string arguments = config.arguments[commando];
|
||||
output = null;
|
||||
if (commandline != null && commandline.Length > 0) {
|
||||
Process p = new Process();
|
||||
p.StartInfo.FileName = commandline;
|
||||
|
@ -101,12 +122,15 @@ namespace ExternalCommand {
|
|||
p.StartInfo.RedirectStandardOutput = true;
|
||||
LOG.Info("Starting : " + p.StartInfo.FileName + " " + p.StartInfo.Arguments);
|
||||
p.Start();
|
||||
string output = p.StandardOutput.ReadToEnd();
|
||||
p.WaitForExit();
|
||||
output = p.StandardOutput.ReadToEnd();
|
||||
if (output != null && output.Trim().Length > 0) {
|
||||
LOG.Info("Output:\n" + output);
|
||||
}
|
||||
LOG.Info("Finished : " + p.StartInfo.FileName + " " + p.StartInfo.Arguments);
|
||||
}
|
||||
return p.ExitCode;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue