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:
RKrom 2012-09-24 14:57:02 +00:00
commit a5f900f92e
5 changed files with 79 additions and 29 deletions

View file

@ -40,6 +40,9 @@ namespace ExternalCommand {
[IniProperty("Argument", Description="The arguments for the output command.")] [IniProperty("Argument", Description="The arguments for the output command.")]
public Dictionary<string, string> arguments; 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 const string MSPAINT = "MS Paint";
private static string paintPath; private static string paintPath;
private static bool hasPaint = false; private static bool hasPaint = false;
@ -84,11 +87,22 @@ namespace ExternalCommand {
return commandlineDefaults; return commandlineDefaults;
case "Argument": case "Argument":
Dictionary<string, string> argumentDefaults = new Dictionary<string, string>(); Dictionary<string, string> argumentDefaults = new Dictionary<string, string>();
argumentDefaults.Add(PAINTDOTNET, "\"{0}\""); if (hasPaintDotNet) {
argumentDefaults.Add(PAINTDOTNET, "\"{0}\"");
}
if (hasPaint) { if (hasPaint) {
argumentDefaults.Add(MSPAINT, "\"{0}\""); 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; return null;
} }

View file

@ -70,29 +70,50 @@ namespace ExternalCommand {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
OutputSettings outputSettings = new OutputSettings(); 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) { if (presetCommand != null) {
Thread commandThread = new Thread (delegate() { if (!config.runInbackground.ContainsKey(presetCommand)) {
CallExternalCommand(presetCommand, fullPath); config.runInbackground.Add(presetCommand, true);
}); }
commandThread.Name = "Running " + presetCommand; bool runInBackground = config.runInbackground[presetCommand];
commandThread.IsBackground = true; string fullPath = captureDetails.Filename;
commandThread.Start(); if (fullPath == null) {
exportInformation.ExportMade = true; 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; //exportInformation.Uri = "file://" + fullPath;
} }
ProcessExport(exportInformation, surface); ProcessExport(exportInformation, surface);
return exportInformation; 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 commandline = config.commandlines[commando];
string arguments = config.arguments[commando]; string arguments = config.arguments[commando];
output = null;
if (commandline != null && commandline.Length > 0) { if (commandline != null && commandline.Length > 0) {
Process p = new Process(); Process p = new Process();
p.StartInfo.FileName = commandline; p.StartInfo.FileName = commandline;
@ -101,12 +122,15 @@ namespace ExternalCommand {
p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardOutput = true;
LOG.Info("Starting : " + p.StartInfo.FileName + " " + p.StartInfo.Arguments); LOG.Info("Starting : " + p.StartInfo.FileName + " " + p.StartInfo.Arguments);
p.Start(); p.Start();
string output = p.StandardOutput.ReadToEnd(); p.WaitForExit();
output = p.StandardOutput.ReadToEnd();
if (output != null && output.Trim().Length > 0) { if (output != null && output.Trim().Length > 0) {
LOG.Info("Output:\n" + output); LOG.Info("Output:\n" + output);
} }
LOG.Info("Finished : " + p.StartInfo.FileName + " " + p.StartInfo.Arguments); LOG.Info("Finished : " + p.StartInfo.FileName + " " + p.StartInfo.Arguments);
return p.ExitCode;
} }
return -1;
} }
} }
} }

View file

@ -99,7 +99,7 @@ namespace Greenshot.Interop {
} else { } else {
//LOG.Warn("Error getting active object for " + progId, comE); //LOG.Warn("Error getting active object for " + progId, comE);
} }
} catch (Exception e) { } catch (Exception) {
//LOG.Warn("Error getting active object for " + progId, e); //LOG.Warn("Error getting active object for " + progId, e);
} }
@ -157,14 +157,14 @@ namespace Greenshot.Interop {
} else { } else {
//LOG.Warn("Error getting active object for " + progId, comE); //LOG.Warn("Error getting active object for " + progId, comE);
} }
} catch (Exception e) { } catch (Exception) {
//LOG.Warn("Error getting active object for " + progId, e); //LOG.Warn("Error getting active object for " + progId, e);
} }
// Did we get the current instance? If not, try to create a new // Did we get the current instance? If not, try to create a new
if (comObject == null) { if (comObject == null) {
try { try {
comType = Type.GetTypeFromProgID(progId, true); comType = Type.GetTypeFromProgID(progId, true);
} catch (Exception ex) { } catch (Exception) {
//LOG.Warn("Error type for " + progId, ex); //LOG.Warn("Error type for " + progId, ex);
} }
if (comType != null) { if (comType != null) {
@ -173,7 +173,7 @@ namespace Greenshot.Interop {
if (comObject != null) { if (comObject != null) {
//LOG.DebugFormat("Created new instance of {0} object.", progId); //LOG.DebugFormat("Created new instance of {0} object.", progId);
} }
} catch (Exception e) { } catch (Exception) {
//LOG.Warn("Error creating object for " + progId, e); //LOG.Warn("Error creating object for " + progId, e);
} }
} }
@ -254,7 +254,7 @@ namespace Greenshot.Interop {
try { try {
while (Marshal.ReleaseComObject(this._COMObject) > 0) while (Marshal.ReleaseComObject(this._COMObject) > 0)
; ;
} catch (Exception ex) { } catch (Exception) {
//LOG.WarnFormat("Problem releasing {0}", _COMType); //LOG.WarnFormat("Problem releasing {0}", _COMType);
//LOG.Warn("Error: ", ex); //LOG.Warn("Error: ", ex);
} }
@ -407,21 +407,21 @@ namespace Greenshot.Interop {
foreach (MemberInfo memberInfo in type.GetMembers()) { foreach (MemberInfo memberInfo in type.GetMembers()) {
//LOG.InfoFormat("Member: {0};", memberInfo.ToString()); //LOG.InfoFormat("Member: {0};", memberInfo.ToString());
} }
} catch (Exception memberException) { } catch (Exception) {
//LOG.Error(memberException); //LOG.Error(memberException);
} }
try { try {
foreach (PropertyInfo propertyInfo in type.GetProperties()) { foreach (PropertyInfo propertyInfo in type.GetProperties()) {
//LOG.InfoFormat("Property: {0};", propertyInfo.ToString()); //LOG.InfoFormat("Property: {0};", propertyInfo.ToString());
} }
} catch (Exception propertyException) { } catch (Exception) {
//LOG.Error(propertyException); //LOG.Error(propertyException);
} }
try { try {
foreach (FieldInfo fieldInfo in type.GetFields()) { foreach (FieldInfo fieldInfo in type.GetFields()) {
//LOG.InfoFormat("Field: {0};", fieldInfo.ToString()); //LOG.InfoFormat("Field: {0};", fieldInfo.ToString());
} }
} catch (Exception fieldException) { } catch (Exception) {
//LOG.Error(fieldException); //LOG.Error(fieldException);
} }
//LOG.InfoFormat("Type information end."); //LOG.InfoFormat("Type information end.");

View file

@ -58,6 +58,8 @@ namespace GreenshotPlugin.Controls {
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon(); this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
this.Text = browserTitle; this.Text = browserTitle;
this.addressTextBox.Text = authorizationLink; this.addressTextBox.Text = authorizationLink;
browser.ScriptErrorsSuppressed = true;
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted); browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
browser.Navigate(new Uri(authorizationLink)); browser.Navigate(new Uri(authorizationLink));

View file

@ -114,8 +114,18 @@ namespace GreenshotPlugin.Core {
/// <param name="key"></param> /// <param name="key"></param>
/// <param name="value"></param> /// <param name="value"></param>
public void Add(TK key, TV value) { public void Add(TK key, TV value) {
Add(key, value, null);
}
/// <summary>
/// Add a value to the cache
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="secondsToExpire?">optional value for the seconds to expire</param>
public void Add(TK key, TV value, int? secondsToExpire) {
lock (lockObject) { lock (lockObject) {
var cachedItem = new CachedItem(key, value, secondsToExpire); var cachedItem = new CachedItem(key, value, secondsToExpire.HasValue ? secondsToExpire.Value : this.secondsToExpire);
cachedItem.Expired += delegate(TK cacheKey, TV cacheValue) { cachedItem.Expired += delegate(TK cacheKey, TV cacheValue) {
if (internalCache.ContainsKey(cacheKey)) { if (internalCache.ContainsKey(cacheKey)) {
LOG.DebugFormat("Expiring object with Key: {0}", cacheKey); LOG.DebugFormat("Expiring object with Key: {0}", cacheKey);