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>
/// The bulk of the clean-up code is implemented in Dispose(bool)
/// </summary>

View file

@ -56,21 +56,8 @@ namespace Greenshot.Drawing {
get { return cursor; }
}
/**
* Destructor
*/
~CursorContainer() {
Dispose(false);
}
/**
* The public accessible Dispose
* Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
*/
public new void Dispose() {
Dispose(true);
public override void Dispose() {
base.Dispose();
GC.SuppressFinalize(this);
}
// 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.
* 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 (cursor != null) {
cursor.Dispose();
}
}
cursor = null;
base.Dispose(disposing);
}
public void Load(string filename) {

View file

@ -46,7 +46,28 @@ namespace Greenshot.Drawing {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(DrawableContainer));
protected static readonly EditorConfiguration editorConfig = IniConfig.GetIniSection<EditorConfiguration>();
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]
private 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 my;
private void gripperMouseDown(object sender, MouseEventArgs e) {

View file

@ -72,34 +72,18 @@ namespace Greenshot.Drawing {
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>
/// This Dispose is called from the Dispose and the Destructor.
/// </summary>
/// <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 (freehandPath != null) {
freehandPath.Dispose();
}
}
freehandPath = null;
base.Dispose(disposing);
}
/// <summary>

View file

@ -55,36 +55,18 @@ namespace Greenshot.Drawing {
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.
* 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 (icon != null) {
icon.Dispose();
}
}
icon = null;
base.Dispose(disposing);
}
public void Load(string filename) {

View file

@ -110,30 +110,13 @@ namespace Greenshot.Drawing {
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>
/// The bulk of the clean-up code is implemented in Dispose(bool)
/// This Dispose is called from the Dispose and the Destructor.
/// When disposing==true all non-managed resources should be freed too!
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing) {
protected override void Dispose(bool disposing) {
if (disposing) {
if (image != null) {
image.Dispose();
@ -144,6 +127,7 @@ namespace Greenshot.Drawing {
}
image = null;
shadowBitmap = null;
base.Dispose(disposing);
}
/// <summary>

View file

@ -320,7 +320,9 @@ namespace Greenshot.Drawing {
set {
drawingMode = value;
if (drawingModeChanged != null) {
drawingModeChanged.Invoke(this, drawingMode);
SurfaceDrawingModeEventArgs eventArgs = new SurfaceDrawingModeEventArgs();
eventArgs.DrawingMode = drawingMode;
drawingModeChanged.Invoke(this, eventArgs);
}
DeselectAllElements();
CreateUndrawnElement();
@ -437,28 +439,35 @@ namespace Greenshot.Drawing {
/// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
/// </summary>
public new void Dispose() {
Count--;
LOG.Debug("Disposing surface!");
if (buffer != null) {
buffer.Dispose();
buffer = null;
}
if (transparencyBackgroundBrush != null) {
transparencyBackgroundBrush.Dispose();
transparencyBackgroundBrush = null;
}
// Cleanup undo/redo stacks
while (undoStack != null && undoStack.Count > 0) {
undoStack.Pop().Dispose();
}
while (redoStack != null && redoStack.Count > 0) {
redoStack.Pop().Dispose();
}
Dispose(true);
base.Dispose();
GC.SuppressFinalize(this);
}
protected override void Dispose(bool disposing) {
if (disposing) {
Count--;
LOG.Debug("Disposing surface!");
if (buffer != null) {
buffer.Dispose();
buffer = null;
}
if (transparencyBackgroundBrush != null) {
transparencyBackgroundBrush.Dispose();
transparencyBackgroundBrush = null;
}
// Cleanup undo/redo stacks
while (undoStack != null && undoStack.Count > 0) {
undoStack.Pop().Dispose();
}
while (redoStack != null && redoStack.Count > 0) {
redoStack.Pop().Dispose();
}
}
base.Dispose(disposing);
}
/// <summary>
/// Undo the last action
/// </summary>
@ -833,7 +842,7 @@ namespace Greenshot.Drawing {
SetImage(newImage, false);
Invalidate();
if (surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size))) {
surfaceSizeChanged(this);
surfaceSizeChanged(this, null);
}
}
} finally {
@ -911,7 +920,7 @@ namespace Greenshot.Drawing {
SetImage(tmpImage, false);
elements.MoveBy(offset.X, offset.Y);
if (surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, tmpImage.Size))) {
surfaceSizeChanged(this);
surfaceSizeChanged(this, null);
}
Invalidate();
return true;
@ -929,7 +938,7 @@ namespace Greenshot.Drawing {
SetImage(previous, false);
elements.MoveBy(offset.X, offset.Y);
if (surfaceSizeChanged != null) {
surfaceSizeChanged(this);
surfaceSizeChanged(this, null);
}
Invalidate();
}
@ -1295,7 +1304,9 @@ namespace Greenshot.Drawing {
}
selectedElements.Clear();
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);
FieldAggregator.UnbindElement(container);
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);
}
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;
FieldAggregator.BindElement(container);
if (movingElementChanged != null) {
movingElementChanged(this, selectedElements);
SurfaceElementEventArgs eventArgs = new SurfaceElementEventArgs();
eventArgs.Elements = selectedElements;
movingElementChanged(this, eventArgs);
}
container.Invalidate();
}

View file

@ -94,39 +94,23 @@ namespace Greenshot.Drawing {
Init();
UpdateFormat();
}
/**
* 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) {
protected override void Dispose(bool disposing) {
if (disposing) {
if (textBox != null) {
textBox.Dispose();
}
if (font != null) {
font.Dispose();
font = null;
}
if (stringFormat != null) {
stringFormat.Dispose();
stringFormat = null;
}
if (textBox != null) {
textBox.Dispose();
textBox = null;
}
}
textBox = null;
font = null;
base.Dispose(disposing);
}
private void Init() {

View file

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

View file

@ -144,7 +144,7 @@ namespace Greenshot {
surface.SurfaceSizeChanged += new SurfaceSizeChangeEventHandler(SurfaceSizeChanged);
surface.SurfaceMessage += new SurfaceMessageEventHandler(SurfaceMessageReceived);
surface.FieldAggregator.FieldChanged += new FieldChangedEventHandler(FieldAggregatorFieldChanged);
SurfaceSizeChanged(this.Surface);
SurfaceSizeChanged(this.Surface, null);
bindFieldControls();
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
/// </summary>
/// <param name="source"></param>
private void SurfaceSizeChanged(object source) {
private void SurfaceSizeChanged(object sender, EventArgs e) {
if (editorConfiguration.MatchSizeToCapture) {
// Set editor's initial size to the size of the surface plus the size of the chrome
Size imageSize = this.Surface.Image.Size;
@ -353,7 +353,7 @@ namespace Greenshot {
this.Size = new Size(newWidth, newHeight);
}
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) {
@ -391,8 +391,8 @@ namespace Greenshot {
this.Text = Path.GetFileName(fullpath) + " - " + Language.GetString(LangKey.editor_title);
}
void surface_DrawingModeChanged(object source, DrawingModes drawingMode) {
switch (drawingMode) {
void surface_DrawingModeChanged(object source, SurfaceDrawingModeEventArgs eventArgs) {
switch (eventArgs.DrawingMode) {
case DrawingModes.None:
SetButtonChecked(btnCursor);
break;

View file

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

View file

@ -330,7 +330,7 @@ namespace Greenshot {
} catch (ArgumentException ex) {
// 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");
throw ex;
throw;
}
this.notifyIcon.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
@ -1210,7 +1210,7 @@ namespace Greenshot {
} catch (Exception ex) {
// Make sure we show what we tried to open in the exception
ex.Data.Add("path", path);
throw ex;
throw;
}
break;
case ClickActions.OPEN_LAST_IN_EDITOR:
@ -1252,7 +1252,7 @@ namespace Greenshot {
} catch (Exception e) {
// Make sure we show what we tried to open in the exception
e.Data.Add("path", path);
throw e;
throw;
}
}

View file

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

View file

@ -457,20 +457,8 @@ namespace Greenshot.Helpers {
}
#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
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]

View file

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

View file

@ -72,7 +72,7 @@ namespace Greenshot.Helpers {
* This Dispose is called from the Dispose and the Destructor.
* 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 (image != null) {
image.Dispose();

View file

@ -43,24 +43,26 @@ namespace Greenshot.Helpers {
private static byte[] soundBuffer = null;
public static void Initialize() {
try {
ResourceManager resources = new ResourceManager("Greenshot.Sounds", Assembly.GetExecutingAssembly());
soundBuffer = (byte[])resources.GetObject("camera");
if (gcHandle == null) {
try {
ResourceManager resources = new ResourceManager("Greenshot.Sounds", Assembly.GetExecutingAssembly());
soundBuffer = (byte[])resources.GetObject("camera");
if (conf.NotificationSound != null && conf.NotificationSound.EndsWith(".wav")) {
try {
if (File.Exists(conf.NotificationSound)) {
soundBuffer = File.ReadAllBytes(conf.NotificationSound);
}
} catch (Exception ex) {
LOG.WarnFormat("couldn't load {0}: {1}", conf.NotificationSound, ex.Message);
}
}
// Pin sound so it can't be moved by the Garbage Collector, this was the cause for the bad sound
gcHandle = GCHandle.Alloc(soundBuffer, GCHandleType.Pinned);
} catch (Exception e) {
LOG.Error("Error initializing.", e);
}
if (conf.NotificationSound != null && conf.NotificationSound.EndsWith(".wav")) {
try {
if (File.Exists(conf.NotificationSound)) {
soundBuffer = File.ReadAllBytes(conf.NotificationSound);
}
} catch (Exception ex) {
LOG.WarnFormat("couldn't load {0}: {1}", conf.NotificationSound, ex.Message);
}
}
// Pin sound so it can't be moved by the Garbage Collector, this was the cause for the bad sound
gcHandle = GCHandle.Alloc(soundBuffer, GCHandleType.Pinned);
} catch (Exception e) {
LOG.Error("Error initializing.", e);
}
}
}
public static void Play() {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -41,6 +41,20 @@ namespace GreenshotBoxPlugin {
private ComponentResourceManager resources;
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() {
}
@ -76,7 +90,7 @@ namespace GreenshotBoxPlugin {
return true;
}
public void OnLanguageChanged() {
public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInConfig != null) {
itemPlugInConfig.Text = Language.GetString("box", LangKey.Configure);
}

View file

@ -91,7 +91,7 @@ namespace Confluence {
}
#endregion
public class ConfluenceConnector {
public class ConfluenceConnector : IDisposable {
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 V2_FAILED = "AXIS";
@ -104,6 +104,23 @@ namespace Confluence {
private string url;
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) {
this.timeout = timeout;
init(url);
@ -117,7 +134,7 @@ namespace Confluence {
}
~ConfluenceConnector() {
logout();
Dispose(false);
}
/// <summary>

View file

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

View file

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

View file

@ -41,6 +41,20 @@ namespace GreenshotDropboxPlugin {
private ComponentResourceManager resources;
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() {
}
@ -77,7 +91,7 @@ namespace GreenshotDropboxPlugin {
return true;
}
public void OnLanguageChanged() {
public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInConfig != null) {
itemPlugInConfig.Text = Language.GetString("dropbox", LangKey.Configure);
}

View file

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

View file

@ -37,6 +37,20 @@ namespace ExternalCommand {
private PluginAttribute myAttributes;
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() {
}
@ -83,7 +97,7 @@ namespace ExternalCommand {
return true;
}
public void OnLanguageChanged() {
public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInRoot != null) {
itemPlugInRoot.Text = Language.GetString("externalcommand", "contextmenu_configure");
}

View file

@ -42,6 +42,19 @@ namespace GreenshotFlickrPlugin
private ComponentResourceManager resources;
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() {
}
@ -79,7 +92,7 @@ namespace GreenshotFlickrPlugin
return true;
}
public void OnLanguageChanged() {
public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInConfig != null) {
itemPlugInConfig.Text = Language.GetString("flickr", LangKey.Configure);
}

View file

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

View file

@ -43,6 +43,24 @@ namespace GreenshotImgurPlugin {
private ToolStripMenuItem historyMenuItem = null;
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() {
}
@ -98,7 +116,7 @@ namespace GreenshotImgurPlugin {
return true;
}
public void OnLanguageChanged() {
public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInConfig != null) {
itemPlugInConfig.Text = Language.GetString("imgur", LangKey.configure);
}

View file

@ -131,7 +131,7 @@ namespace GreenshotImgurPlugin {
}
} catch (Exception ex) {
LOG.Error("Upload to imgur gave an exeption: ", ex);
throw ex;
throw;
}
} else {
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);
} catch (Exception ex) {
LOG.Error("Upload to imgur gave an exeption: ", ex);
throw ex;
throw;
} finally {
if (oAuth.Token != null) {
config.ImgurToken = oAuth.Token;
@ -212,7 +212,7 @@ namespace GreenshotImgurPlugin {
return null;
}
}
throw wE;
throw;
}
LOG.Debug(responseString);
ImgurInfo imgurInfo = ImgurInfo.ParseResponse(responseString);
@ -243,7 +243,7 @@ namespace GreenshotImgurPlugin {
// Allow "Bad request" this means we already deleted it
if (wE.Status == WebExceptionStatus.ProtocolError) {
if (((HttpWebResponse)wE.Response).StatusCode != HttpStatusCode.BadRequest) {
throw wE;
throw ;
}
}
}

View file

@ -95,7 +95,7 @@ namespace Jira {
}
#endregion
public class JiraConnector {
public class JiraConnector : IDisposable {
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 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 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) {
}
@ -138,7 +156,7 @@ namespace Jira {
}
~JiraConnector() {
logout();
Dispose(false);
}
/// <summary>
@ -152,7 +170,7 @@ namespace Jira {
LOG.DebugFormat("Loggin in");
try {
this.credentials = jira.login(user, password);
} catch(Exception ex) {
} catch (Exception) {
if (!url.EndsWith("wsdl")) {
url = url + "/rpc/soap/jirasoapservice-v2?wsdl";
// recreate the service with the new url
@ -162,7 +180,7 @@ namespace Jira {
config.Url = url;
IniConfig.Save();
} else {
throw ex;
throw;
}
}
@ -324,7 +342,7 @@ namespace Jira {
jira.addAttachmentsToIssue(credentials, issueKey, new string[] { filename }, (sbyte[])(Array)attachment.ToByteArray());
} catch (Exception ex2) {
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.Plugin;
using Jira;
using System;
namespace GreenshotJiraPlugin {
/// <summary>
@ -37,7 +38,21 @@ namespace GreenshotJiraPlugin {
private JiraConfiguration config = null;
private ComponentResourceManager resources;
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 {
get {
return instance;

View file

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

View file

@ -69,6 +69,20 @@ namespace GreenshotOCR {
private PluginAttribute myAttributes;
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 IEnumerable<IDestination> Destinations() {

View file

@ -70,8 +70,11 @@ namespace Greenshot.Interop.Office {
oneNoteApplication.GetHierarchy("", HierarchyScope.hsPages, out notebookXml, XMLSchema.xs2010);
if (!string.IsNullOrEmpty(notebookXml)) {
LOG.Debug(notebookXml);
using (StringReader reader = new StringReader(notebookXml)) {
StringReader reader = null;
try {
reader = new StringReader(notebookXml);
using (XmlTextReader xmlReader = new XmlTextReader(reader)) {
reader = null;
while (xmlReader.Read()) {
if ("one:Page".Equals(xmlReader.Name)) {
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);
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);
if (bodyString == null) {
bodyString = fallbackBody;

View file

@ -606,56 +606,6 @@ namespace Greenshot.Interop.Office {
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>
/// Tries to save the changes we just made
/// </summary>

View file

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

View file

@ -41,6 +41,20 @@ namespace GreenshotPhotobucketPlugin {
private ComponentResourceManager resources;
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() {
}
@ -79,7 +93,7 @@ namespace GreenshotPhotobucketPlugin {
return true;
}
public void OnLanguageChanged() {
public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInConfig != null) {
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);
} catch (Exception ex) {
LOG.Error("Error uploading to Photobucket.", ex);
throw ex;
throw;
} finally {
if (!string.IsNullOrEmpty(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);
} catch (Exception ex) {
LOG.Error("Error uploading to Photobucket.", ex);
throw ex;
throw;
} finally {
if (!string.IsNullOrEmpty(oAuth.Token)) {
config.Token = oAuth.Token;

View file

@ -40,6 +40,20 @@ namespace GreenshotPicasaPlugin {
private ComponentResourceManager resources;
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() {
}
@ -76,7 +90,7 @@ namespace GreenshotPicasaPlugin {
return true;
}
public void OnLanguageChanged() {
public void OnLanguageChanged(object sender, EventArgs e) {
if (itemPlugInRoot != null) {
itemPlugInRoot.Text = Language.GetString("picasa", LangKey.Configure);
}

View file

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

View file

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

View file

@ -31,7 +31,7 @@ namespace GreenshotPlugin.Controls {
/// Custom dialog for saving images, wraps SaveFileDialog.
/// For some reason SFD is sealed :(
/// </summary>
public class SaveImageFileDialog {
public class SaveImageFileDialog : IDisposable {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SaveImageFileDialog));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
protected SaveFileDialog saveFileDialog;
@ -39,6 +39,20 @@ namespace GreenshotPlugin.Controls {
private DirectoryInfo eagerlyCreatedDirectory;
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() {
init();
}

View file

@ -136,8 +136,14 @@ namespace GreenshotPlugin.Core {
public virtual IEnumerable<IDestination> DynamicDestinations() {
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 {

View file

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

View file

@ -43,9 +43,9 @@ namespace GreenshotPlugin.Core {
return num;
}
[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")]
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)]
[return: MarshalAs(UnmanagedType.Interface)]

View file

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

View file

@ -406,22 +406,23 @@ namespace GreenshotPlugin.Core {
/// <returns>Path to filename</returns>
public static string SaveWithDialog(ISurface surface, ICaptureDetails captureDetails) {
string returnValue = null;
SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails);
DialogResult dialogResult = saveImageFileDialog.ShowDialog();
if (dialogResult.Equals(DialogResult.OK)) {
try {
string fileNameWithExtension = saveImageFileDialog.FileNameWithExtension;
SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(FormatForFilename(fileNameWithExtension));
if (conf.OutputFilePromptQuality) {
QualityDialog qualityDialog = new QualityDialog(outputSettings);
qualityDialog.ShowDialog();
using (SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails)) {
DialogResult dialogResult = saveImageFileDialog.ShowDialog();
if (dialogResult.Equals(DialogResult.OK)) {
try {
string fileNameWithExtension = saveImageFileDialog.FileNameWithExtension;
SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(FormatForFilename(fileNameWithExtension));
if (conf.OutputFilePromptQuality) {
QualityDialog qualityDialog = new QualityDialog(outputSettings);
qualityDialog.ShowDialog();
}
// TODO: For now we always overwrite, should be changed
ImageOutput.Save(surface, fileNameWithExtension, true, outputSettings, conf.OutputFileCopyPathToClipboard);
returnValue = fileNameWithExtension;
IniConfig.Save();
} catch (System.Runtime.InteropServices.ExternalException) {
MessageBox.Show(Language.GetFormattedString("error_nowriteaccess", saveImageFileDialog.FileName).Replace(@"\\", @"\"), Language.GetString("error"));
}
// TODO: For now we always overwrite, should be changed
ImageOutput.Save(surface, fileNameWithExtension, true, outputSettings, conf.OutputFileCopyPathToClipboard);
returnValue = fileNameWithExtension;
IniConfig.Save();
} catch (System.Runtime.InteropServices.ExternalException) {
MessageBox.Show(Language.GetFormattedString("error_nowriteaccess", saveImageFileDialog.FileName).Replace(@"\\", @"\"), Language.GetString("error"));
}
}
return returnValue;

View file

@ -28,7 +28,7 @@ using Greenshot.IniFile;
using Microsoft.Win32;
namespace GreenshotPlugin.Core {
public delegate void LanguageChangedHandler();
public delegate void LanguageChangedHandler(object sender, EventArgs e);
/// <summary>
/// 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
@ -202,7 +202,7 @@ namespace GreenshotPlugin.Core {
Reload();
if (LanguageChanged != null) {
try {
LanguageChanged();
LanguageChanged(null, null);
} catch {
}
}

View file

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

View file

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

View file

@ -101,9 +101,16 @@ namespace GreenshotPlugin.Core {
private Bitmap resultBitmap;
public void Dispose() {
if (resultBitmap != null) {
resultBitmap.Dispose();
resultBitmap = null;
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (resultBitmap != null) {
resultBitmap.Dispose();
resultBitmap = null;
}
}
}

View file

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

View file

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

View file

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

View file

@ -56,11 +56,25 @@ namespace Greenshot.Plugin {
set;
}
}
public class SurfaceElementEventArgs : EventArgs {
public IList<IDrawableContainer> Elements {
get;
set;
}
}
public class SurfaceDrawingModeEventArgs : EventArgs {
public DrawingModes DrawingMode {
get;
set;
}
}
public delegate void SurfaceSizeChangeEventHandler(object source);
public delegate void SurfaceMessageEventHandler(object source, SurfaceMessageEventArgs eventArgs);
public delegate void SurfaceElementEventHandler(object source, IList<IDrawableContainer> element);
public delegate void SurfaceDrawingModeEventHandler(object source, DrawingModes drawingMode);
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 }
/// <summary>

View file

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

View file

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

View file

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