First code analysis changes, this "should" make Greenshot more stable and implement things as is supposed.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2481 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2013-02-12 18:43:56 +00:00
parent 3f4d93f2b6
commit a394904aa3
64 changed files with 514 additions and 343 deletions

View file

@ -68,13 +68,6 @@ namespace Greenshot.Controls {
} }
} }
/// <summary>
/// Destructor
/// </summary>
~Pipette() {
Dispose(false);
}
/// <summary> /// <summary>
/// The bulk of the clean-up code is implemented in Dispose(bool) /// The bulk of the clean-up code is implemented in Dispose(bool)
/// </summary> /// </summary>

View file

@ -56,21 +56,8 @@ namespace Greenshot.Drawing {
get { return cursor; } get { return cursor; }
} }
/** public override void Dispose() {
* Destructor
*/
~CursorContainer() {
Dispose(false);
}
/**
* The public accessible Dispose
* Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
*/
public new void Dispose() {
Dispose(true);
base.Dispose(); base.Dispose();
GC.SuppressFinalize(this);
} }
// The bulk of the clean-up code is implemented in Dispose(bool) // The bulk of the clean-up code is implemented in Dispose(bool)
@ -79,13 +66,14 @@ namespace Greenshot.Drawing {
* This Dispose is called from the Dispose and the Destructor. * This Dispose is called from the Dispose and the Destructor.
* When disposing==true all non-managed resources should be freed too! * When disposing==true all non-managed resources should be freed too!
*/ */
protected virtual void Dispose(bool disposing) { protected override void Dispose(bool disposing) {
if (disposing) { if (disposing) {
if (cursor != null) { if (cursor != null) {
cursor.Dispose(); cursor.Dispose();
} }
} }
cursor = null; cursor = null;
base.Dispose(disposing);
} }
public void Load(string filename) { public void Load(string filename) {

View file

@ -47,6 +47,27 @@ namespace Greenshot.Drawing {
protected static readonly EditorConfiguration editorConfig = IniConfig.GetIniSection<EditorConfiguration>(); protected static readonly EditorConfiguration editorConfig = IniConfig.GetIniSection<EditorConfiguration>();
private bool isMadeUndoable = false; private bool isMadeUndoable = false;
public virtual void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
for (int i = 0; i < grippers.Length; i++) {
grippers[i].Dispose();
grippers[i] = null;
}
FieldAggregator aggProps = parent.FieldAggregator;
aggProps.UnbindElement(this);
}
}
~DrawableContainer() {
Dispose(false);
}
[NonSerialized] [NonSerialized]
private PropertyChangedEventHandler propertyChanged; private PropertyChangedEventHandler propertyChanged;
public event PropertyChangedEventHandler PropertyChanged { public event PropertyChangedEventHandler PropertyChanged {
@ -335,15 +356,6 @@ namespace Greenshot.Drawing {
} }
} }
public virtual void Dispose() {
for(int i=0; i<grippers.Length; i++) {
grippers[i].Dispose();
}
FieldAggregator aggProps = parent.FieldAggregator;
aggProps.UnbindElement(this);
}
int mx; int mx;
int my; int my;
private void gripperMouseDown(object sender, MouseEventArgs e) { private void gripperMouseDown(object sender, MouseEventArgs e) {

View file

@ -72,34 +72,18 @@ namespace Greenshot.Drawing {
RecalculatePath(); RecalculatePath();
} }
/// <summary>
/// Destructor
/// </summary>
~FreehandContainer() {
Dispose(false);
}
/// <summary>
/// The public accessible Dispose
/// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
/// </summary>
public new void Dispose() {
Dispose(true);
base.Dispose();
GC.SuppressFinalize(this);
}
/// <summary> /// <summary>
/// This Dispose is called from the Dispose and the Destructor. /// This Dispose is called from the Dispose and the Destructor.
/// </summary> /// </summary>
/// <param name="disposing">When disposing==true all non-managed resources should be freed too!</param> /// <param name="disposing">When disposing==true all non-managed resources should be freed too!</param>
protected virtual void Dispose(bool disposing) { protected override void Dispose(bool disposing) {
if (disposing) { if (disposing) {
if (freehandPath != null) { if (freehandPath != null) {
freehandPath.Dispose(); freehandPath.Dispose();
} }
} }
freehandPath = null; freehandPath = null;
base.Dispose(disposing);
} }
/// <summary> /// <summary>

View file

@ -55,36 +55,18 @@ namespace Greenshot.Drawing {
get { return icon; } get { return icon; }
} }
/**
* Destructor
*/
~IconContainer() {
Dispose(false);
}
/**
* The public accessible Dispose
* Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
*/
public new void Dispose() {
Dispose(true);
base.Dispose();
GC.SuppressFinalize(this);
}
// The bulk of the clean-up code is implemented in Dispose(bool)
/** /**
* This Dispose is called from the Dispose and the Destructor. * This Dispose is called from the Dispose and the Destructor.
* When disposing==true all non-managed resources should be freed too! * When disposing==true all non-managed resources should be freed too!
*/ */
protected virtual void Dispose(bool disposing) { protected override void Dispose(bool disposing) {
if (disposing) { if (disposing) {
if (icon != null) { if (icon != null) {
icon.Dispose(); icon.Dispose();
} }
} }
icon = null; icon = null;
base.Dispose(disposing);
} }
public void Load(string filename) { public void Load(string filename) {

View file

@ -110,30 +110,13 @@ namespace Greenshot.Drawing {
get { return image; } get { return image; }
} }
/// <summary>
/// Destructor
/// </summary>
~ImageContainer() {
Dispose(false);
}
/// <summary>
/// The public accessible Dispose
/// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
/// </summary>
public new void Dispose() {
Dispose(true);
base.Dispose();
GC.SuppressFinalize(this);
}
/// <summary> /// <summary>
/// The bulk of the clean-up code is implemented in Dispose(bool) /// The bulk of the clean-up code is implemented in Dispose(bool)
/// This Dispose is called from the Dispose and the Destructor. /// This Dispose is called from the Dispose and the Destructor.
/// When disposing==true all non-managed resources should be freed too! /// When disposing==true all non-managed resources should be freed too!
/// </summary> /// </summary>
/// <param name="disposing"></param> /// <param name="disposing"></param>
protected virtual void Dispose(bool disposing) { protected override void Dispose(bool disposing) {
if (disposing) { if (disposing) {
if (image != null) { if (image != null) {
image.Dispose(); image.Dispose();
@ -144,6 +127,7 @@ namespace Greenshot.Drawing {
} }
image = null; image = null;
shadowBitmap = null; shadowBitmap = null;
base.Dispose(disposing);
} }
/// <summary> /// <summary>

View file

@ -320,7 +320,9 @@ namespace Greenshot.Drawing {
set { set {
drawingMode = value; drawingMode = value;
if (drawingModeChanged != null) { if (drawingModeChanged != null) {
drawingModeChanged.Invoke(this, drawingMode); SurfaceDrawingModeEventArgs eventArgs = new SurfaceDrawingModeEventArgs();
eventArgs.DrawingMode = drawingMode;
drawingModeChanged.Invoke(this, eventArgs);
} }
DeselectAllElements(); DeselectAllElements();
CreateUndrawnElement(); CreateUndrawnElement();
@ -437,6 +439,13 @@ namespace Greenshot.Drawing {
/// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice /// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
/// </summary> /// </summary>
public new void Dispose() { public new void Dispose() {
Dispose(true);
base.Dispose();
GC.SuppressFinalize(this);
}
protected override void Dispose(bool disposing) {
if (disposing) {
Count--; Count--;
LOG.Debug("Disposing surface!"); LOG.Debug("Disposing surface!");
if (buffer != null) { if (buffer != null) {
@ -455,8 +464,8 @@ namespace Greenshot.Drawing {
while (redoStack != null && redoStack.Count > 0) { while (redoStack != null && redoStack.Count > 0) {
redoStack.Pop().Dispose(); redoStack.Pop().Dispose();
} }
base.Dispose(); }
GC.SuppressFinalize(this); base.Dispose(disposing);
} }
/// <summary> /// <summary>
@ -833,7 +842,7 @@ namespace Greenshot.Drawing {
SetImage(newImage, false); SetImage(newImage, false);
Invalidate(); Invalidate();
if (surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size))) { if (surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size))) {
surfaceSizeChanged(this); surfaceSizeChanged(this, null);
} }
} }
} finally { } finally {
@ -911,7 +920,7 @@ namespace Greenshot.Drawing {
SetImage(tmpImage, false); SetImage(tmpImage, false);
elements.MoveBy(offset.X, offset.Y); elements.MoveBy(offset.X, offset.Y);
if (surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, tmpImage.Size))) { if (surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, tmpImage.Size))) {
surfaceSizeChanged(this); surfaceSizeChanged(this, null);
} }
Invalidate(); Invalidate();
return true; return true;
@ -929,7 +938,7 @@ namespace Greenshot.Drawing {
SetImage(previous, false); SetImage(previous, false);
elements.MoveBy(offset.X, offset.Y); elements.MoveBy(offset.X, offset.Y);
if (surfaceSizeChanged != null) { if (surfaceSizeChanged != null) {
surfaceSizeChanged(this); surfaceSizeChanged(this, null);
} }
Invalidate(); Invalidate();
} }
@ -1295,7 +1304,9 @@ namespace Greenshot.Drawing {
} }
selectedElements.Clear(); selectedElements.Clear();
if (movingElementChanged != null) { if (movingElementChanged != null) {
movingElementChanged(this, selectedElements); SurfaceElementEventArgs eventArgs = new SurfaceElementEventArgs();
eventArgs.Elements = selectedElements;
movingElementChanged(this, eventArgs);
} }
} }
} }
@ -1414,7 +1425,9 @@ namespace Greenshot.Drawing {
selectedElements.Remove(container); selectedElements.Remove(container);
FieldAggregator.UnbindElement(container); FieldAggregator.UnbindElement(container);
if (movingElementChanged != null) { if (movingElementChanged != null) {
movingElementChanged(this, selectedElements); SurfaceElementEventArgs eventArgs = new SurfaceElementEventArgs();
eventArgs.Elements = selectedElements;
movingElementChanged(this, eventArgs);
} }
} }
@ -1432,7 +1445,9 @@ namespace Greenshot.Drawing {
FieldAggregator.UnbindElement(element); FieldAggregator.UnbindElement(element);
} }
if (movingElementChanged != null) { if (movingElementChanged != null) {
movingElementChanged(this, selectedElements); SurfaceElementEventArgs eventArgs = new SurfaceElementEventArgs();
eventArgs.Elements = selectedElements;
movingElementChanged(this, eventArgs);
} }
} }
} }
@ -1448,7 +1463,9 @@ namespace Greenshot.Drawing {
container.Selected = true; container.Selected = true;
FieldAggregator.BindElement(container); FieldAggregator.BindElement(container);
if (movingElementChanged != null) { if (movingElementChanged != null) {
movingElementChanged(this, selectedElements); SurfaceElementEventArgs eventArgs = new SurfaceElementEventArgs();
eventArgs.Elements = selectedElements;
movingElementChanged(this, eventArgs);
} }
container.Invalidate(); container.Invalidate();
} }

View file

@ -95,39 +95,23 @@ namespace Greenshot.Drawing {
UpdateFormat(); UpdateFormat();
} }
/** protected override void Dispose(bool disposing) {
* Destructor
*/
~TextContainer() {
Dispose(false);
}
/**
* The public accessible Dispose
* Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
*/
public override void Dispose() {
Dispose(true);
base.Dispose();
GC.SuppressFinalize(this);
}
/**
* This Dispose is called from the Dispose and the Destructor.
* When disposing==true all non-managed resources should be freed too!
*/
protected virtual void Dispose(bool disposing) {
if (disposing) { if (disposing) {
if (textBox != null) {
textBox.Dispose();
}
if (font != null) { if (font != null) {
font.Dispose(); font.Dispose();
}
}
textBox = null;
font = null; font = null;
} }
if (stringFormat != null) {
stringFormat.Dispose();
stringFormat = null;
}
if (textBox != null) {
textBox.Dispose();
textBox = null;
}
}
base.Dispose(disposing);
}
private void Init() { private void Init() {
CreateTextBox(); CreateTextBox();

View file

@ -33,6 +33,7 @@ using Greenshot.Configuration;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using Greenshot.IniFile; using Greenshot.IniFile;
using GreenshotPlugin.Controls; using GreenshotPlugin.Controls;
using System.Security.Permissions;
namespace Greenshot { namespace Greenshot {
/// <summary> /// <summary>
@ -281,6 +282,7 @@ namespace Greenshot {
/// <param name="msg"></param> /// <param name="msg"></param>
/// <param name="keyData"></param> /// <param name="keyData"></param>
/// <returns></returns> /// <returns></returns>
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
try { try {
switch (keyData) { switch (keyData) {

View file

@ -144,7 +144,7 @@ namespace Greenshot {
surface.SurfaceSizeChanged += new SurfaceSizeChangeEventHandler(SurfaceSizeChanged); surface.SurfaceSizeChanged += new SurfaceSizeChangeEventHandler(SurfaceSizeChanged);
surface.SurfaceMessage += new SurfaceMessageEventHandler(SurfaceMessageReceived); surface.SurfaceMessage += new SurfaceMessageEventHandler(SurfaceMessageReceived);
surface.FieldAggregator.FieldChanged += new FieldChangedEventHandler(FieldAggregatorFieldChanged); surface.FieldAggregator.FieldChanged += new FieldChangedEventHandler(FieldAggregatorFieldChanged);
SurfaceSizeChanged(this.Surface); SurfaceSizeChanged(this.Surface, null);
bindFieldControls(); bindFieldControls();
refreshEditorControls(); refreshEditorControls();
@ -340,7 +340,7 @@ namespace Greenshot {
/// This is called when the size of the surface chances, used for resizing and displaying the size information /// This is called when the size of the surface chances, used for resizing and displaying the size information
/// </summary> /// </summary>
/// <param name="source"></param> /// <param name="source"></param>
private void SurfaceSizeChanged(object source) { private void SurfaceSizeChanged(object sender, EventArgs e) {
if (editorConfiguration.MatchSizeToCapture) { if (editorConfiguration.MatchSizeToCapture) {
// Set editor's initial size to the size of the surface plus the size of the chrome // Set editor's initial size to the size of the surface plus the size of the chrome
Size imageSize = this.Surface.Image.Size; Size imageSize = this.Surface.Image.Size;
@ -353,7 +353,7 @@ namespace Greenshot {
this.Size = new Size(newWidth, newHeight); this.Size = new Size(newWidth, newHeight);
} }
dimensionsLabel.Text = this.Surface.Image.Width + "x" + this.Surface.Image.Height; dimensionsLabel.Text = this.Surface.Image.Width + "x" + this.Surface.Image.Height;
ImageEditorFormResize(source, new EventArgs()); ImageEditorFormResize(sender, new EventArgs());
} }
private void ReloadConfiguration(object source, FileSystemEventArgs e) { private void ReloadConfiguration(object source, FileSystemEventArgs e) {
@ -391,8 +391,8 @@ namespace Greenshot {
this.Text = Path.GetFileName(fullpath) + " - " + Language.GetString(LangKey.editor_title); this.Text = Path.GetFileName(fullpath) + " - " + Language.GetString(LangKey.editor_title);
} }
void surface_DrawingModeChanged(object source, DrawingModes drawingMode) { void surface_DrawingModeChanged(object source, SurfaceDrawingModeEventArgs eventArgs) {
switch (drawingMode) { switch (eventArgs.DrawingMode) {
case DrawingModes.None: case DrawingModes.None:
SetButtonChecked(btnCursor); SetButtonChecked(btnCursor);
break; break;

View file

@ -34,6 +34,9 @@ namespace Greenshot {
if (components != null) { if (components != null) {
components.Dispose(); components.Dispose();
} }
if (copyData != null) {
copyData.Dispose();
}
} }
base.Dispose(disposing); base.Dispose(disposing);
} }

View file

@ -330,7 +330,7 @@ namespace Greenshot {
} catch (ArgumentException ex) { } catch (ArgumentException ex) {
// Added for Bug #1420, this doesn't solve the issue but maybe the user can do something with it. // Added for Bug #1420, this doesn't solve the issue but maybe the user can do something with it.
ex.Data.Add("more information here", "http://support.microsoft.com/kb/943140"); ex.Data.Add("more information here", "http://support.microsoft.com/kb/943140");
throw ex; throw;
} }
this.notifyIcon.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon(); this.notifyIcon.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon(); this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
@ -1210,7 +1210,7 @@ namespace Greenshot {
} catch (Exception ex) { } catch (Exception ex) {
// Make sure we show what we tried to open in the exception // Make sure we show what we tried to open in the exception
ex.Data.Add("path", path); ex.Data.Add("path", path);
throw ex; throw;
} }
break; break;
case ClickActions.OPEN_LAST_IN_EDITOR: case ClickActions.OPEN_LAST_IN_EDITOR:
@ -1252,7 +1252,7 @@ namespace Greenshot {
} catch (Exception e) { } catch (Exception e) {
// Make sure we show what we tried to open in the exception // Make sure we show what we tried to open in the exception
e.Data.Add("path", path); e.Data.Add("path", path);
throw e; throw;
} }
} }

View file

@ -91,7 +91,6 @@ namespace Greenshot.Helpers {
#region Member Variables #region Member Variables
private CopyDataChannels channels = null; private CopyDataChannels channels = null;
private bool disposed = false;
#endregion #endregion
/// <summary> /// <summary>
@ -156,15 +155,18 @@ namespace Greenshot.Helpers {
} }
} }
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary> /// <summary>
/// Clears up any resources associated with this object. /// Clears up any resources associated with this object.
/// </summary> /// </summary>
public void Dispose() { protected virtual void Dispose(bool disposing) {
if (!disposed) { if (disposing) {
channels.Clear(); channels.Clear();
channels = null; channels = null;
disposed = true;
GC.SuppressFinalize(this);
} }
} }
@ -360,15 +362,15 @@ namespace Greenshot.Helpers {
/// </summary> /// </summary>
public class CopyDataChannel : IDisposable { public class CopyDataChannel : IDisposable {
#region Unmanaged Code #region Unmanaged Code
[DllImport("user32", CharSet=CharSet.Auto, SetLastError = true)] [DllImport("user32", CharSet=CharSet.Unicode, SetLastError = true)]
private extern static int GetProp(IntPtr hwnd, string lpString); private extern static IntPtr GetProp(IntPtr hwnd, string lpString);
[DllImport("user32", CharSet=CharSet.Auto, SetLastError = true)] [DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
private extern static int SetProp(IntPtr hwnd, string lpString, int hData); private extern static IntPtr SetProp(IntPtr hwnd, string lpString, int hData);
[DllImport("user32", CharSet=CharSet.Auto, SetLastError = true)] [DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
private extern static int RemoveProp(IntPtr hwnd, string lpString); private extern static IntPtr RemoveProp(IntPtr hwnd, string lpString);
[DllImport("user32", CharSet=CharSet.Auto, SetLastError = true)] [DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
private extern static int SendMessage(IntPtr hwnd, int wMsg, int wParam, ref COPYDATASTRUCT lParam); private extern static IntPtr SendMessage(IntPtr hwnd, int wMsg, int wParam, ref COPYDATASTRUCT lParam);
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
private struct COPYDATASTRUCT { private struct COPYDATASTRUCT {
@ -382,7 +384,6 @@ namespace Greenshot.Helpers {
#region Member Variables #region Member Variables
private string channelName = ""; private string channelName = "";
private bool disposed = false;
private NativeWindow owner = null; private NativeWindow owner = null;
private bool recreateChannel = false; private bool recreateChannel = false;
#endregion #endregion
@ -406,10 +407,6 @@ namespace Greenshot.Helpers {
public int Send(object obj) { public int Send(object obj) {
int recipients = 0; int recipients = 0;
if (disposed) {
throw new InvalidOperationException("Object has been disposed");
}
if (recreateChannel) { if (recreateChannel) {
// handle has changed // handle has changed
addChannel(); addChannel();
@ -446,12 +443,12 @@ namespace Greenshot.Helpers {
// the channel: // the channel:
foreach(WindowDetails window in WindowDetails.GetAllWindows()) { foreach(WindowDetails window in WindowDetails.GetAllWindows()) {
if (!window.Handle.Equals(this.owner.Handle)) { if (!window.Handle.Equals(this.owner.Handle)) {
if (GetProp(window.Handle, this.channelName) != 0) { if (GetProp(window.Handle, this.channelName) != IntPtr.Zero) {
COPYDATASTRUCT cds = new COPYDATASTRUCT(); COPYDATASTRUCT cds = new COPYDATASTRUCT();
cds.cbData = dataSize; cds.cbData = dataSize;
cds.dwData = IntPtr.Zero; cds.dwData = IntPtr.Zero;
cds.lpData = ptrData; cds.lpData = ptrData;
int res = SendMessage(window.Handle, WM_COPYDATA, (int)owner.Handle, ref cds); SendMessage(window.Handle, WM_COPYDATA, (int)owner.Handle, ref cds);
recipients += (Marshal.GetLastWin32Error() == 0 ? 1 : 0); recipients += (Marshal.GetLastWin32Error() == 0 ? 1 : 0);
} }
} }
@ -487,17 +484,20 @@ namespace Greenshot.Helpers {
recreateChannel = true; recreateChannel = true;
} }
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary> /// <summary>
/// Clears up any resources associated with this channel. /// Clears up any resources associated with this channel.
/// </summary> /// </summary>
public void Dispose() { protected virtual void Dispose(bool disposing) {
if (!disposed) { if (disposing) {
if (channelName.Length > 0) { if (channelName.Length > 0) {
removeChannel(); removeChannel();
} }
channelName = ""; channelName = "";
disposed = true;
GC.SuppressFinalize(this);
} }
} }

View file

@ -458,18 +458,6 @@ namespace Greenshot.Helpers {
#endregion Constructors #endregion Constructors
#region Constants
public const int MAPI_LOGON_UI = 0x1;
#endregion Constants
#region APIs
[DllImport("MAPI32.DLL", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern int MAPILogon(IntPtr hwnd, string prf, string pw, int flg, int rsv, ref IntPtr sess);
#endregion APIs
#region Structs #region Structs

View file

@ -73,6 +73,7 @@ namespace Greenshot.Helpers {
public void Shutdown() { public void Shutdown() {
foreach(IGreenshotPlugin plugin in plugins.Values) { foreach(IGreenshotPlugin plugin in plugins.Values) {
plugin.Shutdown(); plugin.Shutdown();
plugin.Dispose();
} }
plugins.Clear(); plugins.Clear();
} }

View file

@ -72,7 +72,7 @@ namespace Greenshot.Helpers {
* This Dispose is called from the Dispose and the Destructor. * This Dispose is called from the Dispose and the Destructor.
* When disposing==true all non-managed resources should be freed too! * When disposing==true all non-managed resources should be freed too!
*/ */
protected void Dispose(bool disposing) { protected virtual void Dispose(bool disposing) {
if (disposing) { if (disposing) {
if (image != null) { if (image != null) {
image.Dispose(); image.Dispose();

View file

@ -43,6 +43,7 @@ namespace Greenshot.Helpers {
private static byte[] soundBuffer = null; private static byte[] soundBuffer = null;
public static void Initialize() { public static void Initialize() {
if (gcHandle == null) {
try { try {
ResourceManager resources = new ResourceManager("Greenshot.Sounds", Assembly.GetExecutingAssembly()); ResourceManager resources = new ResourceManager("Greenshot.Sounds", Assembly.GetExecutingAssembly());
soundBuffer = (byte[])resources.GetObject("camera"); soundBuffer = (byte[])resources.GetObject("camera");
@ -62,6 +63,7 @@ namespace Greenshot.Helpers {
LOG.Error("Error initializing.", e); LOG.Error("Error initializing.", e);
} }
} }
}
public static void Play() { public static void Play() {
if (soundBuffer != null) { if (soundBuffer != null) {

View file

@ -37,6 +37,14 @@ namespace Greenshot.Memento {
} }
public void Dispose() { public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
//if (disposing) { }
drawableContainer = null;
surface = null;
} }
public LangKey ActionLanguageKey { public LangKey ActionLanguageKey {

View file

@ -40,6 +40,13 @@ namespace Greenshot.Memento {
} }
public void Dispose() { public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
//if (disposing) { }
drawableContainer = null;
} }
public LangKey ActionLanguageKey { public LangKey ActionLanguageKey {

View file

@ -37,11 +37,18 @@ namespace Greenshot.Memento {
} }
public void Dispose() { public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (drawableContainer != null) { if (drawableContainer != null) {
drawableContainer.Dispose(); drawableContainer.Dispose();
drawableContainer = null; drawableContainer = null;
} }
} }
}
public LangKey ActionLanguageKey { public LangKey ActionLanguageKey {
get { get {

View file

@ -54,6 +54,13 @@ namespace Greenshot.Memento {
} }
public void Dispose() { public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
// if (disposing) { }
listOfdrawableContainer = null;
} }
public LangKey ActionLanguageKey { public LangKey ActionLanguageKey {

View file

@ -40,10 +40,18 @@ namespace Greenshot.Memento {
} }
public void Dispose() { public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (image != null) { if (image != null) {
image.Dispose(); image.Dispose();
image = null; image = null;
} }
surface = null;
}
} }
public bool Merge(IMemento otherMemento) { public bool Merge(IMemento otherMemento) {

View file

@ -36,6 +36,14 @@ namespace Greenshot.Memento {
} }
public void Dispose() { public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
textContainer = null;
}
} }
public LangKey ActionLanguageKey { public LangKey ActionLanguageKey {

View file

@ -41,6 +41,20 @@ namespace GreenshotBoxPlugin {
private ComponentResourceManager resources; private ComponentResourceManager resources;
private ToolStripMenuItem itemPlugInConfig; private ToolStripMenuItem itemPlugInConfig;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (itemPlugInConfig != null) {
itemPlugInConfig.Dispose();
itemPlugInConfig = null;
}
}
}
public BoxPlugin() { public BoxPlugin() {
} }
@ -76,7 +90,7 @@ namespace GreenshotBoxPlugin {
return true; return true;
} }
public void OnLanguageChanged() { public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInConfig != null) { if (itemPlugInConfig != null) {
itemPlugInConfig.Text = Language.GetString("box", LangKey.Configure); itemPlugInConfig.Text = Language.GetString("box", LangKey.Configure);
} }

View file

@ -91,7 +91,7 @@ namespace Confluence {
} }
#endregion #endregion
public class ConfluenceConnector { public class ConfluenceConnector : IDisposable {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceConnector)); private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceConnector));
private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.confluence.rpc.AuthenticationFailedException"; private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.confluence.rpc.AuthenticationFailedException";
private const string V2_FAILED = "AXIS"; private const string V2_FAILED = "AXIS";
@ -104,6 +104,23 @@ namespace Confluence {
private string url; private string url;
private Cache<string, RemotePage> pageCache = new Cache<string, RemotePage>(60 * config.Timeout); private Cache<string, RemotePage> pageCache = new Cache<string, RemotePage>(60 * config.Timeout);
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (confluence != null) {
logout();
}
if (disposing) {
if (confluence != null) {
confluence.Dispose();
confluence = null;
}
}
}
public ConfluenceConnector(string url, int timeout) { public ConfluenceConnector(string url, int timeout) {
this.timeout = timeout; this.timeout = timeout;
init(url); init(url);
@ -117,7 +134,7 @@ namespace Confluence {
} }
~ConfluenceConnector() { ~ConfluenceConnector() {
logout(); Dispose(false);
} }
/// <summary> /// <summary>

View file

@ -39,6 +39,15 @@ namespace GreenshotConfluencePlugin {
private static ConfluenceConfiguration config = null; private static ConfluenceConfiguration config = null;
private static IGreenshotHost host; private static IGreenshotHost host;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
//if (disposing) {}
}
private static void CreateConfluenceConntector() { private static void CreateConfluenceConntector() {
if (confluenceConnector == null) { if (confluenceConnector == null) {
if (config.Url.Contains("soap-axis")) { if (config.Url.Contains("soap-axis")) {

View file

@ -31,7 +31,6 @@ namespace GreenshotConfluencePlugin {
public partial class ConfluenceSearch : System.Windows.Controls.Page { public partial class ConfluenceSearch : System.Windows.Controls.Page {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceSearch)); private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceSearch));
private static ConfluenceConfiguration config = IniConfig.GetIniSection<ConfluenceConfiguration>(); private static ConfluenceConfiguration config = IniConfig.GetIniSection<ConfluenceConfiguration>();
private ConfluenceConnector confluenceConnector;
private ConfluenceUpload confluenceUpload; private ConfluenceUpload confluenceUpload;
public List<Confluence.Space> Spaces { public List<Confluence.Space> Spaces {
@ -48,7 +47,6 @@ namespace GreenshotConfluencePlugin {
} }
public ConfluenceSearch(ConfluenceUpload confluenceUpload) { public ConfluenceSearch(ConfluenceUpload confluenceUpload) {
this.confluenceConnector = ConfluencePlugin.ConfluenceConnector;
this.confluenceUpload = confluenceUpload; this.confluenceUpload = confluenceUpload;
this.DataContext = this; this.DataContext = this;
InitializeComponent(); InitializeComponent();
@ -81,7 +79,7 @@ namespace GreenshotConfluencePlugin {
void doSearch() { void doSearch() {
string spaceKey = (string)SpaceComboBox.SelectedValue; string spaceKey = (string)SpaceComboBox.SelectedValue;
config.SearchSpaceKey = spaceKey; config.SearchSpaceKey = spaceKey;
List<Confluence.Page> searchResult = confluenceConnector.searchPages(searchText.Text, spaceKey); List<Confluence.Page> searchResult = ConfluencePlugin.ConfluenceConnector.searchPages(searchText.Text, spaceKey);
pages.Clear(); pages.Clear();
foreach(Confluence.Page page in searchResult) { foreach(Confluence.Page page in searchResult) {
pages.Add(page); pages.Add(page);

View file

@ -41,6 +41,20 @@ namespace GreenshotDropboxPlugin {
private ComponentResourceManager resources; private ComponentResourceManager resources;
private ToolStripMenuItem itemPlugInConfig; private ToolStripMenuItem itemPlugInConfig;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (itemPlugInConfig != null) {
itemPlugInConfig.Dispose();
itemPlugInConfig = null;
}
}
}
public DropboxPlugin() { public DropboxPlugin() {
} }
@ -77,7 +91,7 @@ namespace GreenshotDropboxPlugin {
return true; return true;
} }
public void OnLanguageChanged() { public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInConfig != null) { if (itemPlugInConfig != null) {
itemPlugInConfig.Text = Language.GetString("dropbox", LangKey.Configure); itemPlugInConfig.Text = Language.GetString("dropbox", LangKey.Configure);
} }

View file

@ -53,7 +53,7 @@ namespace GreenshotDropboxPlugin {
LOG.DebugFormat("Upload response: {0}", uploadResponse); LOG.DebugFormat("Upload response: {0}", uploadResponse);
} catch (Exception ex) { } catch (Exception ex) {
LOG.Error("Upload error: ", ex); LOG.Error("Upload error: ", ex);
throw ex; throw;
} finally { } finally {
if (!string.IsNullOrEmpty(oAuth.Token)) { if (!string.IsNullOrEmpty(oAuth.Token)) {
config.DropboxToken = oAuth.Token; config.DropboxToken = oAuth.Token;

View file

@ -37,6 +37,20 @@ namespace ExternalCommand {
private PluginAttribute myAttributes; private PluginAttribute myAttributes;
private ToolStripMenuItem itemPlugInRoot; private ToolStripMenuItem itemPlugInRoot;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (itemPlugInRoot != null) {
itemPlugInRoot.Dispose();
itemPlugInRoot = null;
}
}
}
public ExternalCommandPlugin() { public ExternalCommandPlugin() {
} }
@ -83,7 +97,7 @@ namespace ExternalCommand {
return true; return true;
} }
public void OnLanguageChanged() { public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInRoot != null) { if (itemPlugInRoot != null) {
itemPlugInRoot.Text = Language.GetString("externalcommand", "contextmenu_configure"); itemPlugInRoot.Text = Language.GetString("externalcommand", "contextmenu_configure");
} }

View file

@ -42,6 +42,19 @@ namespace GreenshotFlickrPlugin
private ComponentResourceManager resources; private ComponentResourceManager resources;
private ToolStripMenuItem itemPlugInConfig; private ToolStripMenuItem itemPlugInConfig;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (itemPlugInConfig != null) {
itemPlugInConfig.Dispose();
itemPlugInConfig = null;
}
}
}
public FlickrPlugin() { public FlickrPlugin() {
} }
@ -79,7 +92,7 @@ namespace GreenshotFlickrPlugin
return true; return true;
} }
public void OnLanguageChanged() { public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInConfig != null) { if (itemPlugInConfig != null) {
itemPlugInConfig.Text = Language.GetString("flickr", LangKey.Configure); itemPlugInConfig.Text = Language.GetString("flickr", LangKey.Configure);
} }

View file

@ -87,7 +87,7 @@ namespace GreenshotFlickrPlugin {
return GetUrl(photoInfo); return GetUrl(photoInfo);
} catch (Exception ex) { } catch (Exception ex) {
LOG.Error("Upload error: ", ex); LOG.Error("Upload error: ", ex);
throw ex; throw;
} finally { } finally {
if (!string.IsNullOrEmpty(oAuth.Token)) { if (!string.IsNullOrEmpty(oAuth.Token)) {
config.FlickrToken = oAuth.Token; config.FlickrToken = oAuth.Token;

View file

@ -43,6 +43,24 @@ namespace GreenshotImgurPlugin {
private ToolStripMenuItem historyMenuItem = null; private ToolStripMenuItem historyMenuItem = null;
private ToolStripMenuItem itemPlugInConfig; private ToolStripMenuItem itemPlugInConfig;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (historyMenuItem != null) {
historyMenuItem.Dispose();
historyMenuItem = null;
}
if (itemPlugInConfig != null) {
itemPlugInConfig.Dispose();
itemPlugInConfig = null;
}
}
}
public ImgurPlugin() { public ImgurPlugin() {
} }
@ -98,7 +116,7 @@ namespace GreenshotImgurPlugin {
return true; return true;
} }
public void OnLanguageChanged() { public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInConfig != null) { if (itemPlugInConfig != null) {
itemPlugInConfig.Text = Language.GetString("imgur", LangKey.configure); itemPlugInConfig.Text = Language.GetString("imgur", LangKey.configure);
} }

View file

@ -131,7 +131,7 @@ namespace GreenshotImgurPlugin {
} }
} catch (Exception ex) { } catch (Exception ex) {
LOG.Error("Upload to imgur gave an exeption: ", ex); LOG.Error("Upload to imgur gave an exeption: ", ex);
throw ex; throw;
} }
} else { } else {
OAuthSession oAuth = new OAuthSession(ImgurCredentials.CONSUMER_KEY, ImgurCredentials.CONSUMER_SECRET); OAuthSession oAuth = new OAuthSession(ImgurCredentials.CONSUMER_KEY, ImgurCredentials.CONSUMER_SECRET);
@ -160,7 +160,7 @@ namespace GreenshotImgurPlugin {
responseString = oAuth.MakeOAuthRequest(HTTPMethod.POST, "http://api.imgur.com/2/account/images.xml", uploadParameters, otherParameters, null); responseString = oAuth.MakeOAuthRequest(HTTPMethod.POST, "http://api.imgur.com/2/account/images.xml", uploadParameters, otherParameters, null);
} catch (Exception ex) { } catch (Exception ex) {
LOG.Error("Upload to imgur gave an exeption: ", ex); LOG.Error("Upload to imgur gave an exeption: ", ex);
throw ex; throw;
} finally { } finally {
if (oAuth.Token != null) { if (oAuth.Token != null) {
config.ImgurToken = oAuth.Token; config.ImgurToken = oAuth.Token;
@ -212,7 +212,7 @@ namespace GreenshotImgurPlugin {
return null; return null;
} }
} }
throw wE; throw;
} }
LOG.Debug(responseString); LOG.Debug(responseString);
ImgurInfo imgurInfo = ImgurInfo.ParseResponse(responseString); ImgurInfo imgurInfo = ImgurInfo.ParseResponse(responseString);
@ -243,7 +243,7 @@ namespace GreenshotImgurPlugin {
// Allow "Bad request" this means we already deleted it // Allow "Bad request" this means we already deleted it
if (wE.Status == WebExceptionStatus.ProtocolError) { if (wE.Status == WebExceptionStatus.ProtocolError) {
if (((HttpWebResponse)wE.Response).StatusCode != HttpStatusCode.BadRequest) { if (((HttpWebResponse)wE.Response).StatusCode != HttpStatusCode.BadRequest) {
throw wE; throw ;
} }
} }
} }

View file

@ -95,7 +95,7 @@ namespace Jira {
} }
#endregion #endregion
public class JiraConnector { public class JiraConnector : IDisposable {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(JiraConnector)); private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(JiraConnector));
private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.jira.rpc.exception.RemoteAuthenticationException"; private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.jira.rpc.exception.RemoteAuthenticationException";
private static JiraConfiguration config = IniConfig.GetIniSection<JiraConfiguration>(); private static JiraConfiguration config = IniConfig.GetIniSection<JiraConfiguration>();
@ -110,6 +110,24 @@ namespace Jira {
private Cache<string, RemoteUser> userCache = new Cache<string, RemoteUser>(60 * config.Timeout); private Cache<string, RemoteUser> userCache = new Cache<string, RemoteUser>(60 * config.Timeout);
private bool suppressBackgroundForm = false; private bool suppressBackgroundForm = false;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (jira != null) {
logout();
}
if (disposing) {
if (jira != null) {
jira.Dispose();
jira = null;
}
}
}
public JiraConnector() : this(false) { public JiraConnector() : this(false) {
} }
@ -138,7 +156,7 @@ namespace Jira {
} }
~JiraConnector() { ~JiraConnector() {
logout(); Dispose(false);
} }
/// <summary> /// <summary>
@ -152,7 +170,7 @@ namespace Jira {
LOG.DebugFormat("Loggin in"); LOG.DebugFormat("Loggin in");
try { try {
this.credentials = jira.login(user, password); this.credentials = jira.login(user, password);
} catch(Exception ex) { } catch (Exception) {
if (!url.EndsWith("wsdl")) { if (!url.EndsWith("wsdl")) {
url = url + "/rpc/soap/jirasoapservice-v2?wsdl"; url = url + "/rpc/soap/jirasoapservice-v2?wsdl";
// recreate the service with the new url // recreate the service with the new url
@ -162,7 +180,7 @@ namespace Jira {
config.Url = url; config.Url = url;
IniConfig.Save(); IniConfig.Save();
} else { } else {
throw ex; throw;
} }
} }
@ -324,7 +342,7 @@ namespace Jira {
jira.addAttachmentsToIssue(credentials, issueKey, new string[] { filename }, (sbyte[])(Array)attachment.ToByteArray()); jira.addAttachmentsToIssue(credentials, issueKey, new string[] { filename }, (sbyte[])(Array)attachment.ToByteArray());
} catch (Exception ex2) { } catch (Exception ex2) {
LOG.WarnFormat("Failed to use alternative method, error was: {0}", ex2.Message); LOG.WarnFormat("Failed to use alternative method, error was: {0}", ex2.Message);
throw ex2; throw;
} }
} }
} }

View file

@ -24,6 +24,7 @@ using System.Windows.Forms;
using Greenshot.IniFile; using Greenshot.IniFile;
using Greenshot.Plugin; using Greenshot.Plugin;
using Jira; using Jira;
using System;
namespace GreenshotJiraPlugin { namespace GreenshotJiraPlugin {
/// <summary> /// <summary>
@ -38,6 +39,20 @@ namespace GreenshotJiraPlugin {
private ComponentResourceManager resources; private ComponentResourceManager resources;
private static JiraPlugin instance = null; private static JiraPlugin instance = null;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (jiraConnector != null) {
jiraConnector.Dispose();
jiraConnector = null;
}
}
}
public static JiraPlugin Instance { public static JiraPlugin Instance {
get { get {
return instance; return instance;

View file

@ -228,7 +228,6 @@ namespace Greenshot.Interop {
/// sure that the COM object is still cleaned up. /// sure that the COM object is still cleaned up.
/// </summary> /// </summary>
~COMWrapper() { ~COMWrapper() {
//LOG.DebugFormat("Finalize {0}", this._InterceptType.ToString());
this.Dispose(false); this.Dispose(false);
} }
@ -248,12 +247,10 @@ namespace Greenshot.Interop {
/// <see cref="IDisposable"/> interface. /// <see cref="IDisposable"/> interface.
/// </param> /// </param>
private void Dispose(bool disposing) { private void Dispose(bool disposing) {
if (null != this._COMObject) { if (disposing && null != this._COMObject) {
//LOG.DebugFormat("Disposing {0}", this._InterceptType.ToString());
if (Marshal.IsComObject(this._COMObject)) { if (Marshal.IsComObject(this._COMObject)) {
try { try {
while (Marshal.ReleaseComObject(this._COMObject) > 0) while (Marshal.ReleaseComObject(this._COMObject) > 0);
;
} catch (Exception) { } catch (Exception) {
//LOG.WarnFormat("Problem releasing {0}", _COMType); //LOG.WarnFormat("Problem releasing {0}", _COMType);
//LOG.Warn("Error: ", ex); //LOG.Warn("Error: ", ex);
@ -638,10 +635,10 @@ namespace Greenshot.Interop {
/// </summary> /// </summary>
public string TypeName { public string TypeName {
get { get {
throw new NotImplementedException(); throw new NotSupportedException();
} }
set { set {
throw new NotImplementedException(); throw new NotSupportedException();
} }
} }
} }

View file

@ -69,6 +69,20 @@ namespace GreenshotOCR {
private PluginAttribute myAttributes; private PluginAttribute myAttributes;
private ToolStripMenuItem ocrMenuItem = new ToolStripMenuItem(); private ToolStripMenuItem ocrMenuItem = new ToolStripMenuItem();
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (ocrMenuItem != null) {
ocrMenuItem.Dispose();
ocrMenuItem = null;
}
}
}
public OcrPlugin() { } public OcrPlugin() { }
public IEnumerable<IDestination> Destinations() { public IEnumerable<IDestination> Destinations() {

View file

@ -70,8 +70,11 @@ namespace Greenshot.Interop.Office {
oneNoteApplication.GetHierarchy("", HierarchyScope.hsPages, out notebookXml, XMLSchema.xs2010); oneNoteApplication.GetHierarchy("", HierarchyScope.hsPages, out notebookXml, XMLSchema.xs2010);
if (!string.IsNullOrEmpty(notebookXml)) { if (!string.IsNullOrEmpty(notebookXml)) {
LOG.Debug(notebookXml); LOG.Debug(notebookXml);
using (StringReader reader = new StringReader(notebookXml)) { StringReader reader = null;
try {
reader = new StringReader(notebookXml);
using (XmlTextReader xmlReader = new XmlTextReader(reader)) { using (XmlTextReader xmlReader = new XmlTextReader(reader)) {
reader = null;
while (xmlReader.Read()) { while (xmlReader.Read()) {
if ("one:Page".Equals(xmlReader.Name)) { if ("one:Page".Equals(xmlReader.Name)) {
if ("true".Equals(xmlReader.GetAttribute("isCurrentlyViewed"))) { if ("true".Equals(xmlReader.GetAttribute("isCurrentlyViewed"))) {
@ -87,6 +90,10 @@ namespace Greenshot.Interop.Office {
} }
} }
} }
} finally {
if (reader != null) {
reader.Dispose();
}
} }
} }
} }

View file

@ -348,7 +348,7 @@ namespace Greenshot.Interop.Office {
href = string.Format("<A HREF=\"{0}\">", url); href = string.Format("<A HREF=\"{0}\">", url);
hrefEnd = "</A>"; hrefEnd = "</A>";
} }
string htmlImgEmbedded = string.Format("<BR/>{0}<IMG border=0 hspace=0 alt=\"{1}\" align=baseline src=\"cid:{2}\"><BR/>", href, attachmentName, contentID, hrefEnd); string htmlImgEmbedded = string.Format("<BR/>{0}<IMG border=0 hspace=0 alt=\"{1}\" align=baseline src=\"cid:{2}\">{3}<BR/>", href, attachmentName, contentID, hrefEnd);
string fallbackBody = string.Format("<HTML><BODY>{0}</BODY></HTML>", htmlImgEmbedded); string fallbackBody = string.Format("<HTML><BODY>{0}</BODY></HTML>", htmlImgEmbedded);
if (bodyString == null) { if (bodyString == null) {
bodyString = fallbackBody; bodyString = fallbackBody;

View file

@ -606,56 +606,6 @@ namespace Greenshot.Interop.Office {
public long filler; public long filler;
} }
/// <summary>
/// Use MAPI32.DLL "HrGetOneProp" from managed code
/// </summary>
/// <param name="attachment"></param>
/// <param name="proptag"></param>
/// <returns></returns>
public static string GetMAPIProperty(Attachment attachment, PropTags proptag) {
object mapiObject = attachment.MAPIOBJECT;
if (mapiObject == null) {
return "";
}
string sProperty = "";
IntPtr pPropValue = IntPtr.Zero;
IntPtr IUnknown = IntPtr.Zero;
IntPtr IMAPIProperty = IntPtr.Zero;
try {
MAPIInitialize(IntPtr.Zero);
IUnknown = Marshal.GetIUnknownForObject(mapiObject);
Guid guidMAPIProp = new Guid(IID_IMAPIProp);
if (Marshal.QueryInterface(IUnknown, ref guidMAPIProp, out IMAPIProperty) != 0) {
return "";
}
try {
HrGetOneProp(IMAPIProperty, (uint)proptag, out pPropValue);
if (pPropValue == IntPtr.Zero) {
return "";
}
SPropValue propValue = (SPropValue)Marshal.PtrToStructure(pPropValue, typeof(SPropValue));
sProperty = Marshal.PtrToStringUni(propValue.Value);
} catch (System.Exception ex) {
throw ex;
}
} finally {
if (pPropValue != IntPtr.Zero) {
MAPIFreeBuffer(pPropValue);
}
if (IMAPIProperty != IntPtr.Zero) {
Marshal.Release(IMAPIProperty);
}
if (IUnknown != IntPtr.Zero) {
Marshal.Release(IUnknown);
}
MAPIUninitialize();
}
return sProperty;
}
/// <summary> /// <summary>
/// Tries to save the changes we just made /// Tries to save the changes we just made
/// </summary> /// </summary>

View file

@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
@ -32,6 +33,15 @@ namespace GreenshotOfficePlugin {
public static PluginAttribute Attributes; public static PluginAttribute Attributes;
private IGreenshotHost host; private IGreenshotHost host;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
//if (disposing) {}
}
public OfficePlugin() { public OfficePlugin() {
} }

View file

@ -41,6 +41,20 @@ namespace GreenshotPhotobucketPlugin {
private ComponentResourceManager resources; private ComponentResourceManager resources;
private ToolStripMenuItem itemPlugInConfig; private ToolStripMenuItem itemPlugInConfig;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (itemPlugInConfig != null) {
itemPlugInConfig.Dispose();
itemPlugInConfig = null;
}
}
}
public PhotobucketPlugin() { public PhotobucketPlugin() {
} }
@ -79,7 +93,7 @@ namespace GreenshotPhotobucketPlugin {
return true; return true;
} }
public void OnLanguageChanged() { public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInConfig != null) { if (itemPlugInConfig != null) {
itemPlugInConfig.Text = Language.GetString("photobucket", LangKey.configure); itemPlugInConfig.Text = Language.GetString("photobucket", LangKey.configure);
} }

View file

@ -74,7 +74,7 @@ namespace GreenshotPhotobucketPlugin {
responseString = oAuth.MakeOAuthRequest(HTTPMethod.POST, apiUrl, apiUrl.Replace("api.photobucket.com", config.SubDomain), signedParameters, unsignedParameters, null); responseString = oAuth.MakeOAuthRequest(HTTPMethod.POST, apiUrl, apiUrl.Replace("api.photobucket.com", config.SubDomain), signedParameters, unsignedParameters, null);
} catch (Exception ex) { } catch (Exception ex) {
LOG.Error("Error uploading to Photobucket.", ex); LOG.Error("Error uploading to Photobucket.", ex);
throw ex; throw;
} finally { } finally {
if (!string.IsNullOrEmpty(oAuth.Token)) { if (!string.IsNullOrEmpty(oAuth.Token)) {
config.Token = oAuth.Token; config.Token = oAuth.Token;
@ -148,7 +148,7 @@ namespace GreenshotPhotobucketPlugin {
responseString = oAuth.MakeOAuthRequest(HTTPMethod.GET, apiUrl, apiUrl.Replace("api.photobucket.com", config.SubDomain), signedParameters, null, null); responseString = oAuth.MakeOAuthRequest(HTTPMethod.GET, apiUrl, apiUrl.Replace("api.photobucket.com", config.SubDomain), signedParameters, null, null);
} catch (Exception ex) { } catch (Exception ex) {
LOG.Error("Error uploading to Photobucket.", ex); LOG.Error("Error uploading to Photobucket.", ex);
throw ex; throw;
} finally { } finally {
if (!string.IsNullOrEmpty(oAuth.Token)) { if (!string.IsNullOrEmpty(oAuth.Token)) {
config.Token = oAuth.Token; config.Token = oAuth.Token;

View file

@ -40,6 +40,20 @@ namespace GreenshotPicasaPlugin {
private ComponentResourceManager resources; private ComponentResourceManager resources;
private ToolStripMenuItem itemPlugInRoot; private ToolStripMenuItem itemPlugInRoot;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (itemPlugInRoot != null) {
itemPlugInRoot.Dispose();
itemPlugInRoot = null;
}
}
}
public PicasaPlugin() { public PicasaPlugin() {
} }
@ -76,7 +90,7 @@ namespace GreenshotPicasaPlugin {
return true; return true;
} }
public void OnLanguageChanged() { public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInRoot != null) { if (itemPlugInRoot != null) {
itemPlugInRoot.Text = Language.GetString("picasa", LangKey.Configure); itemPlugInRoot.Text = Language.GetString("picasa", LangKey.Configure);
} }

View file

@ -71,7 +71,7 @@ namespace GreenshotPicasaPlugin {
return ParseResponse(response); return ParseResponse(response);
} catch (Exception ex) { } catch (Exception ex) {
LOG.Error("Upload error: ", ex); LOG.Error("Upload error: ", ex);
throw ex; throw;
} finally { } finally {
if (!string.IsNullOrEmpty(oAuth.Token)) { if (!string.IsNullOrEmpty(oAuth.Token)) {
config.PicasaToken = oAuth.Token; config.PicasaToken = oAuth.Token;

View file

@ -94,7 +94,7 @@ namespace GreenshotPlugin.Controls {
LOG.DebugFormat("Finished {0}", title); LOG.DebugFormat("Finished {0}", title);
} catch (Exception ex) { } catch (Exception ex) {
LOG.Error(ex); LOG.Error(ex);
throw ex; throw;
} finally { } finally {
Close(); Close();
} }

View file

@ -31,7 +31,7 @@ namespace GreenshotPlugin.Controls {
/// Custom dialog for saving images, wraps SaveFileDialog. /// Custom dialog for saving images, wraps SaveFileDialog.
/// For some reason SFD is sealed :( /// For some reason SFD is sealed :(
/// </summary> /// </summary>
public class SaveImageFileDialog { public class SaveImageFileDialog : IDisposable {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SaveImageFileDialog)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SaveImageFileDialog));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>(); private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
protected SaveFileDialog saveFileDialog; protected SaveFileDialog saveFileDialog;
@ -39,6 +39,20 @@ namespace GreenshotPlugin.Controls {
private DirectoryInfo eagerlyCreatedDirectory; private DirectoryInfo eagerlyCreatedDirectory;
private ICaptureDetails captureDetails = null; private ICaptureDetails captureDetails = null;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (saveFileDialog != null) {
saveFileDialog.Dispose();
saveFileDialog = null;
}
}
}
public SaveImageFileDialog() { public SaveImageFileDialog() {
init(); init();
} }

View file

@ -137,7 +137,13 @@ namespace GreenshotPlugin.Core {
yield break; yield break;
} }
public virtual void Dispose() { public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
//if (disposing) {}
} }
public virtual bool isDynamic { public virtual bool isDynamic {

View file

@ -18,7 +18,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using System;
using Greenshot.Plugin; using Greenshot.Plugin;
@ -53,7 +53,13 @@ namespace GreenshotPlugin.Core {
} }
} }
public virtual void Dispose() { public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
//if (disposing) {}
} }
public virtual bool isActive { public virtual bool isActive {

View file

@ -43,9 +43,9 @@ namespace GreenshotPlugin.Core {
return num; return num;
} }
[DllImport("oleacc.dll")] [DllImport("oleacc.dll")]
public static extern int AccessibleObjectFromWindow(IntPtr hwnd, uint id, ref Guid iid, [In, Out, MarshalAs(UnmanagedType.IUnknown)] ref object ppvObject); private static extern int AccessibleObjectFromWindow(IntPtr hwnd, uint id, ref Guid iid, [In, Out, MarshalAs(UnmanagedType.IUnknown)] ref object ppvObject);
[DllImport("oleacc.dll")] [DllImport("oleacc.dll")]
public static extern int AccessibleChildren(IAccessible paccContainer, int iChildStart, int cChildren, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] object[] rgvarChildren, out int pcObtained); private static extern int AccessibleChildren(IAccessible paccContainer, int iChildStart, int cChildren, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] object[] rgvarChildren, out int pcObtained);
[DllImport("oleacc.dll", PreserveSig=false)] [DllImport("oleacc.dll", PreserveSig=false)]
[return: MarshalAs(UnmanagedType.Interface)] [return: MarshalAs(UnmanagedType.Interface)]

View file

@ -435,7 +435,7 @@ namespace GreenshotPlugin.Core {
// adding additional data for bug tracking // adding additional data for bug tracking
e.Data.Add("title", captureDetails.Title); e.Data.Add("title", captureDetails.Title);
e.Data.Add("pattern", pattern); e.Data.Add("pattern", pattern);
throw e; throw;
} }
} }
} }

View file

@ -406,7 +406,7 @@ namespace GreenshotPlugin.Core {
/// <returns>Path to filename</returns> /// <returns>Path to filename</returns>
public static string SaveWithDialog(ISurface surface, ICaptureDetails captureDetails) { public static string SaveWithDialog(ISurface surface, ICaptureDetails captureDetails) {
string returnValue = null; string returnValue = null;
SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails); using (SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails)) {
DialogResult dialogResult = saveImageFileDialog.ShowDialog(); DialogResult dialogResult = saveImageFileDialog.ShowDialog();
if (dialogResult.Equals(DialogResult.OK)) { if (dialogResult.Equals(DialogResult.OK)) {
try { try {
@ -424,6 +424,7 @@ namespace GreenshotPlugin.Core {
MessageBox.Show(Language.GetFormattedString("error_nowriteaccess", saveImageFileDialog.FileName).Replace(@"\\", @"\"), Language.GetString("error")); MessageBox.Show(Language.GetFormattedString("error_nowriteaccess", saveImageFileDialog.FileName).Replace(@"\\", @"\"), Language.GetString("error"));
} }
} }
}
return returnValue; return returnValue;
} }
#endregion #endregion

View file

@ -28,7 +28,7 @@ using Greenshot.IniFile;
using Microsoft.Win32; using Microsoft.Win32;
namespace GreenshotPlugin.Core { namespace GreenshotPlugin.Core {
public delegate void LanguageChangedHandler(); public delegate void LanguageChangedHandler(object sender, EventArgs e);
/// <summary> /// <summary>
/// This class supplies the GUI with translations, based upon keys. /// This class supplies the GUI with translations, based upon keys.
/// The language resources are loaded from the language files found on fixed or supplied paths /// The language resources are loaded from the language files found on fixed or supplied paths
@ -202,7 +202,7 @@ namespace GreenshotPlugin.Core {
Reload(); Reload();
if (LanguageChanged != null) { if (LanguageChanged != null) {
try { try {
LanguageChanged(); LanguageChanged(null, null);
} catch { } catch {
} }
} }

View file

@ -309,7 +309,7 @@ namespace GreenshotPlugin.Core {
using (Stream responseStream = response.GetResponseStream()) { using (Stream responseStream = response.GetResponseStream()) {
LOG.ErrorFormat("HTTP error {0} with content: {1}", response.StatusCode, new StreamReader(responseStream, true).ReadToEnd()); LOG.ErrorFormat("HTTP error {0} with content: {1}", response.StatusCode, new StreamReader(responseStream, true).ReadToEnd());
} }
throw e; throw;
} }
return responseData; return responseData;

View file

@ -405,7 +405,7 @@ namespace GreenshotPlugin.Core {
return getAccessToken() != null; return getAccessToken() != null;
} catch (Exception ex) { } catch (Exception ex) {
LOG.Error(ex); LOG.Error(ex);
throw ex; throw;
} }
} }
@ -518,7 +518,7 @@ namespace GreenshotPlugin.Core {
continue; continue;
} }
} }
throw wEx; throw;
} }
} }
if (lastException != null) { if (lastException != null) {

View file

@ -101,11 +101,18 @@ namespace GreenshotPlugin.Core {
private Bitmap resultBitmap; private Bitmap resultBitmap;
public void Dispose() { public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (resultBitmap != null) { if (resultBitmap != null) {
resultBitmap.Dispose(); resultBitmap.Dispose();
resultBitmap = null; resultBitmap = null;
} }
} }
}
/// <summary> /// <summary>
/// See <see cref="IColorQuantizer.Prepare"/> for more details. /// See <see cref="IColorQuantizer.Prepare"/> for more details.

View file

@ -196,7 +196,6 @@ namespace GreenshotPlugin.Core {
private WindowDetails parent = null; private WindowDetails parent = null;
private bool frozen = false; private bool frozen = false;
public bool isApp { public bool isApp {
get { get {
return METRO_WINDOWS_CLASS.Equals(ClassName); return METRO_WINDOWS_CLASS.Equals(ClassName);
@ -1105,6 +1104,7 @@ namespace GreenshotPlugin.Core {
tempForm.Close(); tempForm.Close();
} }
tempForm.Dispose(); tempForm.Dispose();
tempForm = null;
} }
} }

View file

@ -372,7 +372,7 @@ namespace Greenshot.IniFile {
if (valueString.Length > 0) { if (valueString.Length > 0) {
try { try {
return Enum.Parse(valueType, valueString); return Enum.Parse(valueType, valueString);
} catch (ArgumentException ae) { } catch (ArgumentException) {
//LOG.InfoFormat("Couldn't match {0} to {1}, trying case-insentive match", valueString, fieldType); //LOG.InfoFormat("Couldn't match {0} to {1}, trying case-insentive match", valueString, fieldType);
foreach (Enum enumValue in Enum.GetValues(valueType)) { foreach (Enum enumValue in Enum.GetValues(valueType)) {
if (enumValue.ToString().Equals(valueString, StringComparison.InvariantCultureIgnoreCase)) { if (enumValue.ToString().Equals(valueString, StringComparison.InvariantCultureIgnoreCase)) {
@ -380,7 +380,7 @@ namespace Greenshot.IniFile {
return enumValue; return enumValue;
} }
} }
throw ae; throw;
} }
} }
} }

View file

@ -28,7 +28,7 @@ namespace Greenshot.Plugin.Drawing {
public enum RenderMode {EDIT, EXPORT}; public enum RenderMode {EDIT, EXPORT};
public enum EditStatus {UNDRAWN, DRAWING, MOVING, RESIZING, IDLE}; public enum EditStatus {UNDRAWN, DRAWING, MOVING, RESIZING, IDLE};
public interface IDrawableContainer : INotifyPropertyChanged { public interface IDrawableContainer : INotifyPropertyChanged, IDisposable {
ISurface Parent { ISurface Parent {
get; get;
} }
@ -83,7 +83,6 @@ namespace Greenshot.Plugin.Drawing {
} }
void AlignToParent(HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment); void AlignToParent(HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment);
void Invalidate(); void Invalidate();
void Dispose();
bool ClickableAt(int x, int y); bool ClickableAt(int x, int y);
void HideGrippers(); void HideGrippers();
void ShowGrippers(); void ShowGrippers();

View file

@ -57,10 +57,24 @@ namespace Greenshot.Plugin {
} }
} }
public delegate void SurfaceSizeChangeEventHandler(object source); public class SurfaceElementEventArgs : EventArgs {
public delegate void SurfaceMessageEventHandler(object source, SurfaceMessageEventArgs eventArgs); public IList<IDrawableContainer> Elements {
public delegate void SurfaceElementEventHandler(object source, IList<IDrawableContainer> element); get;
public delegate void SurfaceDrawingModeEventHandler(object source, DrawingModes drawingMode); set;
}
}
public class SurfaceDrawingModeEventArgs : EventArgs {
public DrawingModes DrawingMode {
get;
set;
}
}
public delegate void SurfaceSizeChangeEventHandler(object sender, EventArgs eventArgs);
public delegate void SurfaceMessageEventHandler(object sender, SurfaceMessageEventArgs eventArgs);
public delegate void SurfaceElementEventHandler(object sender, SurfaceElementEventArgs eventArgs);
public delegate void SurfaceDrawingModeEventHandler(object sender, SurfaceDrawingModeEventArgs eventArgs);
public enum DrawingModes { None, Rect, Ellipse, Text, Line, Arrow, Crop, Highlight, Obfuscate, Bitmap, Path } public enum DrawingModes { None, Rect, Ellipse, Text, Line, Arrow, Crop, Highlight, Obfuscate, Bitmap, Path }
/// <summary> /// <summary>

View file

@ -225,7 +225,7 @@ namespace Greenshot.Plugin {
ICapture GetCapture(Image imageToCapture); ICapture GetCapture(Image imageToCapture);
} }
public interface IGreenshotPlugin { public interface IGreenshotPlugin : IDisposable {
/// <summary> /// <summary>
/// Is called after the plugin is instanciated, the Plugin should keep a copy of the host and pluginAttribute. /// Is called after the plugin is instanciated, the Plugin should keep a copy of the host and pluginAttribute.
/// </summary> /// </summary>

View file

@ -764,10 +764,10 @@ namespace Greenshot.Interop {
/// </summary> /// </summary>
public string TypeName { public string TypeName {
get { get {
throw new NotImplementedException(); throw new NotSupportedException();
} }
set { set {
throw new NotImplementedException(); throw new NotSupportedException();
} }
} }
} }

View file

@ -27,6 +27,7 @@ using System.Text;
using Microsoft.Win32.SafeHandles; using Microsoft.Win32.SafeHandles;
using System.Security; using System.Security;
using System.Security.Permissions;
namespace GreenshotPlugin.UnmanagedHelpers { namespace GreenshotPlugin.UnmanagedHelpers {
/// <summary> /// <summary>
@ -297,6 +298,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
this.SetHandle(hIcon); this.SetHandle(hIcon);
} }
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
protected override bool ReleaseHandle() { protected override bool ReleaseHandle() {
return User32.DestroyIcon(this.handle); return User32.DestroyIcon(this.handle);
} }
@ -322,6 +324,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
SetHandle(preexistingHandle); SetHandle(preexistingHandle);
} }
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)]
protected override bool ReleaseHandle() { protected override bool ReleaseHandle() {
bool returnValue = ReleaseDC(hWnd, handle); bool returnValue = ReleaseDC(hWnd, handle);
return returnValue; return returnValue;