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.")]
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;
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;
}

View file

@ -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;
}
}
}

View file

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

View file

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

View file

@ -114,8 +114,18 @@ namespace GreenshotPlugin.Core {
/// <param name="key"></param>
/// <param name="value"></param>
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) {
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) {
if (internalCache.ContainsKey(cacheKey)) {
LOG.DebugFormat("Expiring object with Key: {0}", cacheKey);