Code quality fixes (NullReference checks, unused variables etc)

This commit is contained in:
RKrom 2014-04-26 00:34:06 +02:00
commit ac08533727
99 changed files with 1252 additions and 1312 deletions

View file

@ -7,8 +7,6 @@
//
//
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using GreenshotPlugin.UnmanagedHelpers;

View file

@ -18,43 +18,40 @@
* 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.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using Greenshot.Configuration;
using Greenshot.Destinations;
using Greenshot.Drawing;
using Greenshot.Forms;
using Greenshot.Helpers;
using Greenshot.IniFile;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using GreenshotPlugin.UnmanagedHelpers;
using Greenshot.IniFile;
using Greenshot.Interop;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using log4net;
namespace Greenshot.Helpers {
/// <summary>
/// CaptureHelper contains all the capture logic
/// </summary>
public class CaptureHelper {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(CaptureHelper));
private static readonly ILog LOG = LogManager.GetLogger(typeof(CaptureHelper));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
// TODO: when we get the screen capture code working correctly, this needs to be enabled
//private static ScreenCaptureHelper screenCapture = null;
private List<WindowDetails> windows = new List<WindowDetails>();
private WindowDetails selectedCaptureWindow = null;
private Rectangle captureRect = Rectangle.Empty;
private bool captureMouseCursor = false;
private ICapture capture = null;
private CaptureMode captureMode;
private ScreenCaptureMode screenCaptureMode = ScreenCaptureMode.Auto;
private Thread windowDetailsThread = null;
private List<WindowDetails> _windows = new List<WindowDetails>();
private WindowDetails _selectedCaptureWindow;
private Rectangle _captureRect = Rectangle.Empty;
private readonly bool _captureMouseCursor;
private ICapture _capture;
private CaptureMode _captureMode;
private ScreenCaptureMode _screenCaptureMode = ScreenCaptureMode.Auto;
/// <summary>
/// The public accessible Dispose
@ -76,10 +73,9 @@ namespace Greenshot.Helpers {
if (disposing) {
// Cleanup
}
windows = null;
selectedCaptureWindow = null;
windowDetailsThread = null;
capture = null;
_windows = null;
_selectedCaptureWindow = null;
_capture = null;
}
public static void CaptureClipboard() {
new CaptureHelper(CaptureMode.Clipboard).MakeCapture();
@ -96,7 +92,7 @@ namespace Greenshot.Helpers {
}
public static void CaptureFullscreen(bool captureMouse, ScreenCaptureMode screenCaptureMode) {
CaptureHelper captureHelper = new CaptureHelper(CaptureMode.FullScreen, captureMouse);
captureHelper.screenCaptureMode = screenCaptureMode;
captureHelper._screenCaptureMode = screenCaptureMode;
captureHelper.MakeCapture();
}
public static void CaptureLastRegion(bool captureMouse) {
@ -133,39 +129,39 @@ namespace Greenshot.Helpers {
public static void ImportCapture(ICapture captureToImport) {
CaptureHelper captureHelper = new CaptureHelper(CaptureMode.File);
captureHelper.capture = captureToImport;
captureHelper._capture = captureToImport;
captureHelper.HandleCapture();
}
public CaptureHelper AddDestination(IDestination destination) {
capture.CaptureDetails.AddDestination(destination);
_capture.CaptureDetails.AddDestination(destination);
return this;
}
public CaptureHelper(CaptureMode captureMode) {
this.captureMode = captureMode;
capture = new Capture();
_captureMode = captureMode;
_capture = new Capture();
}
public CaptureHelper(CaptureMode captureMode, bool captureMouseCursor) : this(captureMode) {
this.captureMouseCursor = captureMouseCursor;
_captureMouseCursor = captureMouseCursor;
}
public CaptureHelper(CaptureMode captureMode, bool captureMouseCursor, ScreenCaptureMode screenCaptureMode) : this(captureMode) {
this.captureMouseCursor = captureMouseCursor;
this.screenCaptureMode = screenCaptureMode;
_captureMouseCursor = captureMouseCursor;
_screenCaptureMode = screenCaptureMode;
}
public CaptureHelper(CaptureMode captureMode, bool captureMouseCursor, IDestination destination) : this(captureMode, captureMouseCursor) {
capture.CaptureDetails.AddDestination(destination);
_capture.CaptureDetails.AddDestination(destination);
}
public WindowDetails SelectedCaptureWindow {
get {
return selectedCaptureWindow;
return _selectedCaptureWindow;
}
set {
selectedCaptureWindow = value;
_selectedCaptureWindow = value;
}
}
@ -180,7 +176,7 @@ namespace Greenshot.Helpers {
/// </summary>
/// <param name="filename">filename</param>
private void MakeCapture(string filename) {
capture.CaptureDetails.Filename = filename;
_capture.CaptureDetails.Filename = filename;
MakeCapture();
}
@ -189,7 +185,7 @@ namespace Greenshot.Helpers {
/// </summary>
/// <param name="filename">filename</param>
private void MakeCapture(Rectangle region) {
captureRect = region;
_captureRect = region;
MakeCapture();
}
@ -211,25 +207,25 @@ namespace Greenshot.Helpers {
MainForm.Instance.NotifyIcon.Visible = false;
MainForm.Instance.NotifyIcon.Visible = true;
}
LOG.Debug(String.Format("Capturing with mode {0} and using Cursor {1}", captureMode, captureMouseCursor));
capture.CaptureDetails.CaptureMode = captureMode;
LOG.Debug(String.Format("Capturing with mode {0} and using Cursor {1}", _captureMode, _captureMouseCursor));
_capture.CaptureDetails.CaptureMode = _captureMode;
// Get the windows details in a seperate thread, only for those captures that have a Feedback
// As currently the "elements" aren't used, we don't need them yet
switch (captureMode) {
switch (_captureMode) {
case CaptureMode.Region:
// Check if a region is pre-supplied!
if (Rectangle.Empty.Equals(captureRect)) {
windowDetailsThread = PrepareForCaptureWithFeedback();
if (Rectangle.Empty.Equals(_captureRect)) {
PrepareForCaptureWithFeedback();
}
break;
case CaptureMode.Window:
windowDetailsThread = PrepareForCaptureWithFeedback();
PrepareForCaptureWithFeedback();
break;
}
// Add destinations if no-one passed a handler
if (capture.CaptureDetails.CaptureDestinations == null || capture.CaptureDetails.CaptureDestinations.Count == 0) {
if (_capture.CaptureDetails.CaptureDestinations == null || _capture.CaptureDetails.CaptureDestinations.Count == 0) {
AddConfiguredDestination();
}
@ -237,8 +233,8 @@ namespace Greenshot.Helpers {
WindowDetails previouslyActiveWindow = WindowDetails.GetActiveWindow();
// Workaround for changed DPI settings in Windows 7
using (Graphics graphics = Graphics.FromHwnd(MainForm.Instance.Handle)) {
capture.CaptureDetails.DpiX = graphics.DpiX;
capture.CaptureDetails.DpiY = graphics.DpiY;
_capture.CaptureDetails.DpiX = graphics.DpiX;
_capture.CaptureDetails.DpiY = graphics.DpiY;
}
if (previouslyActiveWindow != null) {
// Set previouslyActiveWindow as foreground window
@ -247,25 +243,25 @@ namespace Greenshot.Helpers {
// Delay for the Context menu
if (conf.CaptureDelay > 0) {
System.Threading.Thread.Sleep(conf.CaptureDelay);
Thread.Sleep(conf.CaptureDelay);
} else {
conf.CaptureDelay = 0;
}
// Capture Mousecursor if we are not loading from file or clipboard, only show when needed
if (captureMode != CaptureMode.File && captureMode != CaptureMode.Clipboard) {
capture = WindowCapture.CaptureCursor(capture);
if (captureMouseCursor) {
capture.CursorVisible = conf.CaptureMousepointer;
if (_captureMode != CaptureMode.File && _captureMode != CaptureMode.Clipboard) {
_capture = WindowCapture.CaptureCursor(_capture);
if (_captureMouseCursor) {
_capture.CursorVisible = conf.CaptureMousepointer;
} else {
capture.CursorVisible = false;
_capture.CursorVisible = false;
}
}
switch(captureMode) {
switch(_captureMode) {
case CaptureMode.Window:
capture = WindowCapture.CaptureScreen(capture);
capture.CaptureDetails.AddMetaData("source", "Screen");
_capture = WindowCapture.CaptureScreen(_capture);
_capture.CaptureDetails.AddMetaData("source", "Screen");
CaptureWithFeedback();
break;
case CaptureMode.ActiveWindow:
@ -277,31 +273,31 @@ namespace Greenshot.Helpers {
//capture.MoveElements(capture.ScreenBounds.Location.X-capture.Location.X, capture.ScreenBounds.Location.Y-capture.Location.Y);
// Capture worked, offset mouse according to screen bounds and capture location
capture.MoveMouseLocation(capture.ScreenBounds.Location.X-capture.Location.X, capture.ScreenBounds.Location.Y-capture.Location.Y);
capture.CaptureDetails.AddMetaData("source", "Window");
_capture.MoveMouseLocation(_capture.ScreenBounds.Location.X-_capture.Location.X, _capture.ScreenBounds.Location.Y-_capture.Location.Y);
_capture.CaptureDetails.AddMetaData("source", "Window");
} else {
captureMode = CaptureMode.FullScreen;
capture = WindowCapture.CaptureScreen(capture);
capture.CaptureDetails.AddMetaData("source", "Screen");
capture.CaptureDetails.Title = "Screen";
_captureMode = CaptureMode.FullScreen;
_capture = WindowCapture.CaptureScreen(_capture);
_capture.CaptureDetails.AddMetaData("source", "Screen");
_capture.CaptureDetails.Title = "Screen";
}
HandleCapture();
break;
case CaptureMode.IE:
if (IECaptureHelper.CaptureIE(capture, SelectedCaptureWindow) != null) {
capture.CaptureDetails.AddMetaData("source", "Internet Explorer");
if (IECaptureHelper.CaptureIE(_capture, SelectedCaptureWindow) != null) {
_capture.CaptureDetails.AddMetaData("source", "Internet Explorer");
HandleCapture();
}
break;
case CaptureMode.FullScreen:
// Check how we need to capture the screen
bool captureTaken = false;
switch (screenCaptureMode) {
switch (_screenCaptureMode) {
case ScreenCaptureMode.Auto:
Point mouseLocation = WindowCapture.GetCursorLocation();
foreach (Screen screen in Screen.AllScreens) {
if (screen.Bounds.Contains(mouseLocation)) {
capture = WindowCapture.CaptureRectangle(capture, screen.Bounds);
_capture = WindowCapture.CaptureRectangle(_capture, screen.Bounds);
captureTaken = true;
break;
}
@ -309,7 +305,7 @@ namespace Greenshot.Helpers {
break;
case ScreenCaptureMode.Fixed:
if (conf.ScreenToCapture > 0 && conf.ScreenToCapture <= Screen.AllScreens.Length) {
capture = WindowCapture.CaptureRectangle(capture, Screen.AllScreens[conf.ScreenToCapture].Bounds);
_capture = WindowCapture.CaptureRectangle(_capture, Screen.AllScreens[conf.ScreenToCapture].Bounds);
captureTaken = true;
}
break;
@ -318,28 +314,28 @@ namespace Greenshot.Helpers {
break;
}
if (!captureTaken) {
capture = WindowCapture.CaptureScreen(capture);
_capture = WindowCapture.CaptureScreen(_capture);
}
HandleCapture();
break;
case CaptureMode.Clipboard:
Image clipboardImage = ClipboardHelper.GetImage();
if (clipboardImage != null) {
if (capture != null) {
capture.Image = clipboardImage;
if (_capture != null) {
_capture.Image = clipboardImage;
} else {
capture = new Capture(clipboardImage);
_capture = new Capture(clipboardImage);
}
capture.CaptureDetails.Title = "Clipboard";
capture.CaptureDetails.AddMetaData("source", "Clipboard");
_capture.CaptureDetails.Title = "Clipboard";
_capture.CaptureDetails.AddMetaData("source", "Clipboard");
// Force Editor, keep picker
if (capture.CaptureDetails.HasDestination(Destinations.PickerDestination.DESIGNATION)) {
capture.CaptureDetails.ClearDestinations();
capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(Destinations.EditorDestination.DESIGNATION));
capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(Destinations.PickerDestination.DESIGNATION));
if (_capture.CaptureDetails.HasDestination(PickerDestination.DESIGNATION)) {
_capture.CaptureDetails.ClearDestinations();
_capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
_capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(PickerDestination.DESIGNATION));
} else {
capture.CaptureDetails.ClearDestinations();
capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(Destinations.EditorDestination.DESIGNATION));
_capture.CaptureDetails.ClearDestinations();
_capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
}
HandleCapture();
} else {
@ -348,15 +344,15 @@ namespace Greenshot.Helpers {
break;
case CaptureMode.File:
Image fileImage = null;
string filename = capture.CaptureDetails.Filename;
string filename = _capture.CaptureDetails.Filename;
if (!string.IsNullOrEmpty(filename)) {
try {
if (filename.ToLower().EndsWith("." + OutputFormat.greenshot)) {
ISurface surface = new Surface();
surface = ImageOutput.LoadGreenshotSurface(filename, surface);
surface.CaptureDetails = capture.CaptureDetails;
DestinationHelper.GetDestination(EditorDestination.DESIGNATION).ExportCapture(true, surface, capture.CaptureDetails);
surface.CaptureDetails = _capture.CaptureDetails;
DestinationHelper.GetDestination(EditorDestination.DESIGNATION).ExportCapture(true, surface, _capture.CaptureDetails);
break;
}
} catch (Exception e) {
@ -371,29 +367,29 @@ namespace Greenshot.Helpers {
}
}
if (fileImage != null) {
capture.CaptureDetails.Title = Path.GetFileNameWithoutExtension(filename);
capture.CaptureDetails.AddMetaData("file", filename);
capture.CaptureDetails.AddMetaData("source", "file");
if (capture != null) {
capture.Image = fileImage;
_capture.CaptureDetails.Title = Path.GetFileNameWithoutExtension(filename);
_capture.CaptureDetails.AddMetaData("file", filename);
_capture.CaptureDetails.AddMetaData("source", "file");
if (_capture != null) {
_capture.Image = fileImage;
} else {
capture = new Capture(fileImage);
_capture = new Capture(fileImage);
}
// Force Editor, keep picker, this is currently the only usefull destination
if (capture.CaptureDetails.HasDestination(PickerDestination.DESIGNATION)) {
capture.CaptureDetails.ClearDestinations();
capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(PickerDestination.DESIGNATION));
if (_capture.CaptureDetails.HasDestination(PickerDestination.DESIGNATION)) {
_capture.CaptureDetails.ClearDestinations();
_capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
_capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(PickerDestination.DESIGNATION));
} else {
capture.CaptureDetails.ClearDestinations();
capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
_capture.CaptureDetails.ClearDestinations();
_capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
}
HandleCapture();
}
break;
case CaptureMode.LastRegion:
if (!RuntimeConfig.LastCapturedRegion.IsEmpty) {
capture = WindowCapture.CaptureRectangle(capture, RuntimeConfig.LastCapturedRegion);
_capture = WindowCapture.CaptureRectangle(_capture, RuntimeConfig.LastCapturedRegion);
// TODO: Reactive / check if the elements code is activated
//if (windowDetailsThread != null) {
// windowDetailsThread.Join();
@ -403,42 +399,42 @@ namespace Greenshot.Helpers {
foreach (WindowDetails window in WindowDetails.GetVisibleWindows()) {
Point estimatedLocation = new Point(RuntimeConfig.LastCapturedRegion.X + (RuntimeConfig.LastCapturedRegion.Width / 2), RuntimeConfig.LastCapturedRegion.Y + (RuntimeConfig.LastCapturedRegion.Height / 2));
if (window.Contains(estimatedLocation)) {
selectedCaptureWindow = window;
capture.CaptureDetails.Title = selectedCaptureWindow.Text;
_selectedCaptureWindow = window;
_capture.CaptureDetails.Title = _selectedCaptureWindow.Text;
break;
}
}
// Move cursor, fixing bug #3569703
capture.MoveMouseLocation(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y);
_capture.MoveMouseLocation(_capture.ScreenBounds.Location.X - _capture.Location.X, _capture.ScreenBounds.Location.Y - _capture.Location.Y);
//capture.MoveElements(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y);
capture.CaptureDetails.AddMetaData("source", "screen");
_capture.CaptureDetails.AddMetaData("source", "screen");
HandleCapture();
}
break;
case CaptureMode.Region:
// Check if a region is pre-supplied!
if (Rectangle.Empty.Equals(captureRect)) {
capture = WindowCapture.CaptureScreen(capture);
capture.CaptureDetails.AddMetaData("source", "screen");
if (Rectangle.Empty.Equals(_captureRect)) {
_capture = WindowCapture.CaptureScreen(_capture);
_capture.CaptureDetails.AddMetaData("source", "screen");
CaptureWithFeedback();
} else {
capture = WindowCapture.CaptureRectangle(capture, captureRect);
capture.CaptureDetails.AddMetaData("source", "screen");
_capture = WindowCapture.CaptureRectangle(_capture, _captureRect);
_capture.CaptureDetails.AddMetaData("source", "screen");
HandleCapture();
}
break;
default:
LOG.Warn("Unknown capture mode: " + captureMode);
LOG.Warn("Unknown capture mode: " + _captureMode);
break;
}
// TODO: Reactive / check if the elements code is activated
//if (windowDetailsThread != null) {
// windowDetailsThread.Join();
//}
if (capture != null) {
if (_capture != null) {
LOG.Debug("Disposing capture");
capture.Dispose();
_capture.Dispose();
}
}
@ -446,12 +442,12 @@ namespace Greenshot.Helpers {
/// Pre-Initialization for CaptureWithFeedback, this will get all the windows before we change anything
/// </summary>
private Thread PrepareForCaptureWithFeedback() {
windows = new List<WindowDetails>();
_windows = new List<WindowDetails>();
// If the App Launcher is visisble, no other windows are active
WindowDetails appLauncherWindow = WindowDetails.GetAppLauncher();
if (appLauncherWindow != null && appLauncherWindow.Visible) {
windows.Add(appLauncherWindow);
_windows.Add(appLauncherWindow);
return null;
}
@ -481,8 +477,8 @@ namespace Greenshot.Helpers {
goLevelDeep = 20;
}
window.GetChildren(goLevelDeep);
lock (windows) {
windows.Add(window);
lock (_windows) {
_windows.Add(window);
}
// TODO: Following code should be enabled & checked if the editor can support "elements"
@ -535,7 +531,7 @@ namespace Greenshot.Helpers {
foreach(string destinationDesignation in conf.OutputDestinations) {
IDestination destination = DestinationHelper.GetDestination(destinationDesignation);
if (destination != null) {
capture.CaptureDetails.AddDestination(destination);
_capture.CaptureDetails.AddDestination(destination);
}
}
}
@ -546,26 +542,26 @@ namespace Greenshot.Helpers {
bool outputMade = false;
// Make sure the user sees that the capture is made
if (capture.CaptureDetails.CaptureMode == CaptureMode.File || capture.CaptureDetails.CaptureMode == CaptureMode.Clipboard) {
if (_capture.CaptureDetails.CaptureMode == CaptureMode.File || _capture.CaptureDetails.CaptureMode == CaptureMode.Clipboard) {
// Maybe not "made" but the original is still there... somehow
outputMade = true;
} else {
// Make sure the resolution is set correctly!
if (capture.CaptureDetails != null && capture.Image != null) {
((Bitmap)capture.Image).SetResolution(capture.CaptureDetails.DpiX, capture.CaptureDetails.DpiY);
if (_capture.CaptureDetails != null && _capture.Image != null) {
((Bitmap)_capture.Image).SetResolution(_capture.CaptureDetails.DpiX, _capture.CaptureDetails.DpiY);
}
DoCaptureFeedback();
}
LOG.Debug("A capture of: " + capture.CaptureDetails.Title);
LOG.Debug("A capture of: " + _capture.CaptureDetails.Title);
// check if someone has passed a destination
if (capture.CaptureDetails.CaptureDestinations == null || capture.CaptureDetails.CaptureDestinations.Count == 0) {
if (_capture.CaptureDetails.CaptureDestinations == null || _capture.CaptureDetails.CaptureDestinations.Count == 0) {
AddConfiguredDestination();
}
// Create Surface with capture, this way elements can be added automatically (like the mouse cursor)
Surface surface = new Surface(capture);
Surface surface = new Surface(_capture);
surface.Modified = !outputMade;
// Register notify events if this is wanted
@ -629,7 +625,7 @@ namespace Greenshot.Helpers {
}
} else {
if (!string.IsNullOrEmpty(surface.UploadURL)) {
System.Diagnostics.Process.Start(surface.UploadURL);
Process.Start(surface.UploadURL);
}
}
LOG.DebugFormat("Deregistering the BalloonTipClicked");
@ -648,28 +644,28 @@ namespace Greenshot.Helpers {
foreach(IProcessor processor in ProcessorHelper.GetAllProcessors()) {
if (processor.isActive) {
LOG.InfoFormat("Calling processor {0}", processor.Description);
processor.ProcessCapture(surface, capture.CaptureDetails);
processor.ProcessCapture(surface, _capture.CaptureDetails);
}
}
// As the surfaces copies the reference to the image, make sure the image is not being disposed (a trick to save memory)
capture.Image = null;
_capture.Image = null;
// Get CaptureDetails as we need it even after the capture is disposed
ICaptureDetails captureDetails = capture.CaptureDetails;
ICaptureDetails captureDetails = _capture.CaptureDetails;
bool canDisposeSurface = true;
if (captureDetails.HasDestination(Destinations.PickerDestination.DESIGNATION)) {
DestinationHelper.ExportCapture(false, Destinations.PickerDestination.DESIGNATION, surface, captureDetails);
if (captureDetails.HasDestination(PickerDestination.DESIGNATION)) {
DestinationHelper.ExportCapture(false, PickerDestination.DESIGNATION, surface, captureDetails);
captureDetails.CaptureDestinations.Clear();
canDisposeSurface = false;
}
// Disable capturing
captureMode = CaptureMode.None;
_captureMode = CaptureMode.None;
// Dispose the capture, we don't need it anymore (the surface copied all information and we got the title (if any)).
capture.Dispose();
capture = null;
_capture.Dispose();
_capture = null;
int destinationCount = captureDetails.CaptureDestinations.Count;
if (destinationCount > 0) {
@ -682,7 +678,7 @@ namespace Greenshot.Helpers {
LOG.InfoFormat("Calling destination {0}", destination.Description);
ExportInformation exportInformation = destination.ExportCapture(false, surface, captureDetails);
if (Destinations.EditorDestination.DESIGNATION.Equals(destination.Designation) && exportInformation.ExportMade) {
if (EditorDestination.DESIGNATION.Equals(destination.Designation) && exportInformation.ExportMade) {
canDisposeSurface = false;
}
}
@ -695,34 +691,34 @@ namespace Greenshot.Helpers {
private bool CaptureActiveWindow() {
bool presupplied = false;
LOG.Debug("CaptureActiveWindow");
if (selectedCaptureWindow != null) {
if (_selectedCaptureWindow != null) {
LOG.Debug("Using supplied window");
presupplied = true;
} else {
selectedCaptureWindow = WindowDetails.GetActiveWindow();
if (selectedCaptureWindow != null) {
LOG.DebugFormat("Capturing window: {0} with {1}", selectedCaptureWindow.Text, selectedCaptureWindow.WindowRectangle);
_selectedCaptureWindow = WindowDetails.GetActiveWindow();
if (_selectedCaptureWindow != null) {
LOG.DebugFormat("Capturing window: {0} with {1}", _selectedCaptureWindow.Text, _selectedCaptureWindow.WindowRectangle);
}
}
if (selectedCaptureWindow == null || (!presupplied && selectedCaptureWindow.Iconic)) {
if (_selectedCaptureWindow == null || (!presupplied && _selectedCaptureWindow.Iconic)) {
LOG.Warn("No window to capture!");
// Nothing to capture, code up in the stack will capture the full screen
return false;
}
if (!presupplied && selectedCaptureWindow != null && selectedCaptureWindow.Iconic) {
if (!presupplied && _selectedCaptureWindow != null && _selectedCaptureWindow.Iconic) {
// Restore the window making sure it's visible!
// This is done mainly for a screen capture, but some applications like Excel and TOAD have weird behaviour!
selectedCaptureWindow.Restore();
_selectedCaptureWindow.Restore();
}
selectedCaptureWindow = SelectCaptureWindow(selectedCaptureWindow);
if (selectedCaptureWindow == null) {
_selectedCaptureWindow = SelectCaptureWindow(_selectedCaptureWindow);
if (_selectedCaptureWindow == null) {
LOG.Warn("No window to capture, after SelectCaptureWindow!");
// Nothing to capture, code up in the stack will capture the full screen
return false;
}
// Fix for Bug #3430560
RuntimeConfig.LastCapturedRegion = selectedCaptureWindow.WindowRectangle;
bool returnValue = CaptureWindow(selectedCaptureWindow, capture, conf.WindowCaptureMode) != null;
RuntimeConfig.LastCapturedRegion = _selectedCaptureWindow.WindowRectangle;
bool returnValue = CaptureWindow(_selectedCaptureWindow, _capture, conf.WindowCaptureMode) != null;
return returnValue;
}
@ -954,17 +950,17 @@ namespace Greenshot.Helpers {
app.HideApp();
}
}
using (CaptureForm captureForm = new CaptureForm(capture, windows)) {
using (CaptureForm captureForm = new CaptureForm(_capture, _windows)) {
DialogResult result = captureForm.ShowDialog();
if (result == DialogResult.OK) {
selectedCaptureWindow = captureForm.SelectedCaptureWindow;
captureRect = captureForm.CaptureRectangle;
_selectedCaptureWindow = captureForm.SelectedCaptureWindow;
_captureRect = captureForm.CaptureRectangle;
// Get title
if (selectedCaptureWindow != null) {
capture.CaptureDetails.Title = selectedCaptureWindow.Text;
if (_selectedCaptureWindow != null) {
_capture.CaptureDetails.Title = _selectedCaptureWindow.Text;
}
if (captureRect.Height > 0 && captureRect.Width > 0) {
if (_captureRect.Height > 0 && _captureRect.Width > 0) {
// TODO: Reactive / check if the elements code is activated
//if (windowDetailsThread != null) {
// windowDetailsThread.Join();
@ -990,12 +986,12 @@ namespace Greenshot.Helpers {
// }
//}
// Take the captureRect, this already is specified as bitmap coordinates
capture.Crop(captureRect);
_capture.Crop(_captureRect);
// save for re-capturing later and show recapture context menu option
// Important here is that the location needs to be offsetted back to screen coordinates!
Rectangle tmpRectangle = captureRect.Clone();
tmpRectangle.Offset(capture.ScreenBounds.Location.X, capture.ScreenBounds.Location.Y);
Rectangle tmpRectangle = _captureRect;
tmpRectangle.Offset(_capture.ScreenBounds.Location.X, _capture.ScreenBounds.Location.Y);
RuntimeConfig.LastCapturedRegion = tmpRectangle;
HandleCapture();
}

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 System.Collections.Generic;
using System.Drawing;

View file

@ -42,7 +42,7 @@ namespace Greenshot.Helpers {
get {return commands;}
}
public CopyDataTransport() {
this.commands = new List<KeyValuePair<CommandEnum, string>>();
commands = new List<KeyValuePair<CommandEnum, string>>();
}
public CopyDataTransport(CommandEnum command) : this() {
@ -53,10 +53,10 @@ namespace Greenshot.Helpers {
AddCommand(command, commandData);
}
public void AddCommand(CommandEnum command) {
this.commands.Add(new KeyValuePair<CommandEnum, string>(command, null));
commands.Add(new KeyValuePair<CommandEnum, string>(command, null));
}
public void AddCommand(CommandEnum command, string commandData) {
this.commands.Add(new KeyValuePair<CommandEnum, string>(command, commandData));
commands.Add(new KeyValuePair<CommandEnum, string>(command, commandData));
}
}
@ -98,7 +98,7 @@ namespace Greenshot.Helpers {
/// messages sent by other instances of this class.
/// </summary>
/// <param name="m">The Windows Message information.</param>
protected override void WndProc (ref System.Windows.Forms.Message m ) {
protected override void WndProc (ref Message m ) {
if (m.Msg == WM_COPYDATA) {
COPYDATASTRUCT cds = new COPYDATASTRUCT();
cds = (COPYDATASTRUCT) Marshal.PtrToStructure(m.LParam, typeof(COPYDATASTRUCT));
@ -151,7 +151,7 @@ namespace Greenshot.Helpers {
/// </summary>
public CopyDataChannels Channels {
get {
return this.channels;
return channels;
}
}
@ -202,7 +202,7 @@ namespace Greenshot.Helpers {
/// </summary>
public string ChannelName {
get {
return this.channelName;
return channelName;
}
}
/// <summary>
@ -210,7 +210,7 @@ namespace Greenshot.Helpers {
/// </summary>
public Object Data {
get {
return this.data;
return data;
}
}
/// <summary>
@ -219,7 +219,7 @@ namespace Greenshot.Helpers {
/// </summary>
public DateTime Sent {
get {
return this.sent;
return sent;
}
}
/// <summary>
@ -228,7 +228,7 @@ namespace Greenshot.Helpers {
/// </summary>
public DateTime Received {
get {
return this.received;
return received;
}
}
/// <summary>
@ -241,7 +241,7 @@ namespace Greenshot.Helpers {
this.channelName = channelName;
this.data = data;
this.sent = sent;
this.received = DateTime.Now;
received = DateTime.Now;
}
}
@ -258,8 +258,8 @@ namespace Greenshot.Helpers {
/// </summary>
/// <returns>An enumerator for each of the CopyDataChannel objects
/// within this collection.</returns>
public new System.Collections.IEnumerator GetEnumerator ( ) {
return this.Dictionary.Values.GetEnumerator();
public new IEnumerator GetEnumerator ( ) {
return Dictionary.Values.GetEnumerator();
}
/// <summary>
@ -269,7 +269,7 @@ namespace Greenshot.Helpers {
get {
CopyDataChannel ret = null;
int i = 0;
foreach (CopyDataChannel cdc in this.Dictionary.Values) {
foreach (CopyDataChannel cdc in Dictionary.Values) {
i++;
if (i == index) {
ret = cdc;
@ -284,7 +284,7 @@ namespace Greenshot.Helpers {
/// </summary>
public CopyDataChannel this[string channelName] {
get {
return (CopyDataChannel) this.Dictionary[channelName];
return (CopyDataChannel) Dictionary[channelName];
}
}
/// <summary>
@ -293,21 +293,21 @@ namespace Greenshot.Helpers {
/// </summary>
public void Add(string channelName) {
CopyDataChannel cdc = new CopyDataChannel(owner, channelName);
this.Dictionary.Add(channelName , cdc);
Dictionary.Add(channelName , cdc);
}
/// <summary>
/// Removes an existing channel.
/// </summary>
/// <param name="channelName">The channel to remove</param>
public void Remove(string channelName) {
this.Dictionary.Remove(channelName);
Dictionary.Remove(channelName);
}
/// <summary>
/// Gets/sets whether this channel contains a CopyDataChannel
/// for the specified channelName.
/// </summary>
public bool Contains(string channelName) {
return this.Dictionary.Contains(channelName);
return Dictionary.Contains(channelName);
}
/// <summary>
@ -315,7 +315,7 @@ namespace Greenshot.Helpers {
/// object collected by this class are cleared up.
/// </summary>
protected override void OnClear() {
foreach (CopyDataChannel cdc in this.Dictionary.Values) {
foreach (CopyDataChannel cdc in Dictionary.Values) {
cdc.Dispose();
}
base.OnClear();
@ -328,7 +328,7 @@ namespace Greenshot.Helpers {
/// <param name="key">The channelName</param>
/// <param name="data">The CopyDataChannel object which has
/// just been removed</param>
protected override void OnRemoveComplete ( Object key , System.Object data ) {
protected override void OnRemoveComplete ( Object key , Object data ) {
( (CopyDataChannel) data).Dispose();
base.OnRemove(key, data);
}
@ -341,7 +341,7 @@ namespace Greenshot.Helpers {
/// the new handle has been assigned.
/// </summary>
public void OnHandleChange() {
foreach (CopyDataChannel cdc in this.Dictionary.Values) {
foreach (CopyDataChannel cdc in Dictionary.Values) {
cdc.OnHandleChange();
}
}
@ -393,7 +393,7 @@ namespace Greenshot.Helpers {
/// </summary>
public string ChannelName {
get {
return this.channelName;
return channelName;
}
}
@ -442,8 +442,8 @@ namespace Greenshot.Helpers {
// Send the data to each window identified on
// the channel:
foreach(WindowDetails window in WindowDetails.GetAllWindows()) {
if (!window.Handle.Equals(this.owner.Handle)) {
if (GetProp(window.Handle, this.channelName) != IntPtr.Zero) {
if (!window.Handle.Equals(owner.Handle)) {
if (GetProp(window.Handle, channelName) != IntPtr.Zero) {
COPYDATASTRUCT cds = new COPYDATASTRUCT();
cds.cbData = dataSize;
cds.dwData = IntPtr.Zero;
@ -464,12 +464,12 @@ namespace Greenshot.Helpers {
private void addChannel() {
// Tag this window with property "channelName"
SetProp(owner.Handle, this.channelName, (int)owner.Handle);
SetProp(owner.Handle, channelName, (int)owner.Handle);
}
private void removeChannel() {
// Remove the "channelName" property from this window
RemoveProp(owner.Handle, this.channelName);
RemoveProp(owner.Handle, channelName);
}
/// <summary>

View file

@ -23,15 +23,15 @@ using System.Collections.Generic;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using Greenshot.Destinations;
using Greenshot.IniFile;
using log4net;
namespace Greenshot.Helpers {
/// <summary>
/// Description of DestinationHelper.
/// </summary>
public static class DestinationHelper {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(DestinationHelper));
private static ILog LOG = LogManager.GetLogger(typeof(DestinationHelper));
private static Dictionary<string, IDestination> RegisteredDestinations = new Dictionary<string, IDestination>();
private static CoreConfiguration coreConfig = IniConfig.GetIniSection<CoreConfiguration>();

View file

@ -29,13 +29,14 @@ using GreenshotPlugin.UnmanagedHelpers;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
using Greenshot.Drawing;
using log4net;
namespace Greenshot.Helpers {
/// <summary>
/// Description of EnvironmentInfo.
/// </summary>
public static class EnvironmentInfo {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(EnvironmentInfo));
private static readonly ILog LOG = LogManager.GetLogger(typeof(EnvironmentInfo));
private static bool? isWindows = null;
public static bool IsWindows {
@ -157,8 +158,8 @@ namespace Greenshot.Helpers {
public static string BuildReport(Exception exception) {
StringBuilder exceptionText = new StringBuilder();
exceptionText.AppendLine(EnvironmentInfo.EnvironmentToString(true));
exceptionText.AppendLine(EnvironmentInfo.ExceptionToString(exception));
exceptionText.AppendLine(EnvironmentToString(true));
exceptionText.AppendLine(ExceptionToString(exception));
exceptionText.AppendLine("Configuration dump:");
using (TextWriter writer = new StringWriter(exceptionText)) {
IniConfig.GetIniSection<CoreConfiguration>().Write(writer, true);

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 System.Drawing;
namespace Greenshot.Helpers {

View file

@ -20,9 +20,7 @@
*/
using System;
using System.Collections.Generic;
using System.Text;
using GreenshotPlugin.UnmanagedHelpers;
using System.Diagnostics;
using GreenshotPlugin.Core;
namespace Greenshot.Helpers {

View file

@ -22,9 +22,8 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using Greenshot.Configuration;
using Greenshot.Drawing.Filters;
using Greenshot.Helpers.IEInterop;
using Greenshot.Interop;
using Greenshot.Interop.IE;
@ -33,6 +32,7 @@ using GreenshotPlugin.UnmanagedHelpers;
using GreenshotPlugin.Controls;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
using log4net;
namespace Greenshot.Helpers {
/// <summary>
@ -42,7 +42,7 @@ namespace Greenshot.Helpers {
/// Many thanks to all the people who contributed here!
/// </summary>
public static class IECaptureHelper {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(IECaptureHelper));
private static ILog LOG = LogManager.GetLogger(typeof(IECaptureHelper));
private static CoreConfiguration configuration = IniConfig.GetIniSection<CoreConfiguration>();
// Helper method to activate a certain IE Tab
@ -145,7 +145,7 @@ namespace Greenshot.Helpers {
try {
IHTMLDocument2 document2 = getHTMLDocument(ieWindow);
string title = document2.title;
System.Runtime.InteropServices.Marshal.ReleaseComObject(document2);
Marshal.ReleaseComObject(document2);
if (string.IsNullOrEmpty(title)) {
singleWindowText.Add(ieWindow.Text);
} else {

View file

@ -25,14 +25,14 @@ using System.Globalization;
using System.Runtime.InteropServices;
using GreenshotPlugin.Core;
using Greenshot.Plugin;
using Greenshot.Interop;
using Greenshot.Interop.IE;
using Greenshot.IniFile;
using log4net;
using IServiceProvider = Greenshot.Interop.IServiceProvider;
namespace Greenshot.Helpers.IEInterop {
public class DocumentContainer {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(DocumentContainer));
private static ILog LOG = LogManager.GetLogger(typeof(DocumentContainer));
private static CoreConfiguration configuration = IniConfig.GetIniSection<CoreConfiguration>();
private const int E_ACCESSDENIED = unchecked((int)0x80070005L);
private static readonly Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
@ -114,7 +114,7 @@ namespace Greenshot.Helpers.IEInterop {
private void Init(IHTMLDocument2 document2, WindowDetails contentWindow) {
this.document2 = document2;
this.contentWindow = contentWindow;
this.document3 = document2 as IHTMLDocument3;
document3 = document2 as IHTMLDocument3;
// Check what access method is needed for the document
IHTMLDocument5 document5 = (IHTMLDocument5)document2;
@ -298,7 +298,7 @@ namespace Greenshot.Helpers.IEInterop {
LOG.Warn("comEx.ErrorCode != E_ACCESSDENIED but", comEx);
return null;
}
} catch (System.UnauthorizedAccessException) {
} catch (UnauthorizedAccessException) {
// This error is okay, ignoring it
} catch (Exception ex1) {
LOG.Warn("Some error: ", ex1);
@ -310,12 +310,12 @@ namespace Greenshot.Helpers.IEInterop {
// IE tries to prevent a cross frame scripting security issue.
try {
// Convert IHTMLWindow2 to IWebBrowser2 using IServiceProvider.
Interop.IServiceProvider sp = (Interop.IServiceProvider)htmlWindow;
IServiceProvider sp = (IServiceProvider)htmlWindow;
// Use IServiceProvider.QueryService to get IWebBrowser2 object.
Object brws = null;
Guid webBrowserApp = IID_IWebBrowserApp.Clone();
Guid webBrowser2 = IID_IWebBrowser2.Clone();
Guid webBrowserApp = IID_IWebBrowserApp;
Guid webBrowser2 = IID_IWebBrowser2;
sp.QueryService(ref webBrowserApp, ref webBrowser2, out brws);
// Get the document from IWebBrowser2.
@ -543,7 +543,7 @@ namespace Greenshot.Helpers.IEInterop {
public Rectangle DestinationRectangle {
get {
return new Rectangle(this.DestinationLocation, this.DestinationSize);
return new Rectangle(DestinationLocation, DestinationSize);
}
}

View file

@ -21,22 +21,21 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
/// <summary>
/// Author: Andrew Baker
/// Datum: 10.03.2006
/// Available from: http://www.vbusers.com/codecsharp/codeget.asp?ThreadID=71&PostID=1
/// </summary>
using log4net;
namespace Greenshot.Helpers {
#region Public MapiMailMessage Class
@ -44,7 +43,7 @@ namespace Greenshot.Helpers {
/// Represents an email message to be sent through MAPI.
/// </summary>
public class MapiMailMessage {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(MapiMailMessage));
private static readonly ILog LOG = LogManager.GetLogger(typeof(MapiMailMessage));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
/// <summary>
@ -220,7 +219,7 @@ namespace Greenshot.Helpers {
/// </summary>
public void ShowDialog() {
// Create the mail message in an STA thread
Thread t = new Thread(new ThreadStart(_ShowMail));
Thread t = new Thread(_ShowMail);
t.IsBackground = true;
t.Name = "Create MAPI mail";
t.SetApartmentState(ApartmentState.STA);
@ -291,7 +290,7 @@ namespace Greenshot.Helpers {
int fsize = Marshal.SizeOf(fileDescType);
// Get the ptr to the files
IntPtr runptr = message.Files.Clone();
IntPtr runptr = message.Files;
// Release each file
for (int i = 0; i < message.FileCount; i++) {
Marshal.DestroyStructure(runptr, fileDescType);
@ -322,7 +321,7 @@ namespace Greenshot.Helpers {
MapiFileDescriptor mfd = new MapiFileDescriptor();
mfd.position = -1;
IntPtr runptr = ptra.Clone();
IntPtr runptr = ptra;
for (int i = 0; i < _files.Count; i++) {
string path = _files[i] as string;
mfd.name = Path.GetFileName(path);
@ -620,28 +619,28 @@ namespace Greenshot.Helpers {
/// Adds a new recipient with the specified address to this collection.
/// </summary>
public void Add(string address) {
this.Add(new Recipient(address));
Add(new Recipient(address));
}
/// <summary>
/// Adds a new recipient with the specified address and display name to this collection.
/// </summary>
public void Add(string address, string displayName) {
this.Add(new Recipient(address, displayName));
Add(new Recipient(address, displayName));
}
/// <summary>
/// Adds a new recipient with the specified address and recipient type to this collection.
/// </summary>
public void Add(string address, MapiMailMessage.RecipientType recipientType) {
this.Add(new Recipient(address, recipientType));
Add(new Recipient(address, recipientType));
}
/// <summary>
/// Adds a new recipient with the specified address, display name and recipient type to this collection.
/// </summary>
public void Add(string address, string displayName, MapiMailMessage.RecipientType recipientType) {
this.Add(new Recipient(address, displayName, recipientType));
Add(new Recipient(address, displayName, recipientType));
}
/// <summary>
@ -687,7 +686,7 @@ namespace Greenshot.Helpers {
_handle = Marshal.AllocHGlobal(_count * size);
// place all interop recipients into the memory just allocated
IntPtr ptr = _handle.Clone();
IntPtr ptr = _handle;
foreach (Recipient native in outer) {
MapiMailMessage.MAPIHelperInterop.MapiRecipDesc interop = native.GetInteropRepresentation();
@ -720,7 +719,7 @@ namespace Greenshot.Helpers {
int size = Marshal.SizeOf(type);
// destroy all the structures in the memory area
IntPtr ptr = _handle.Clone();
IntPtr ptr = _handle;
for (int i = 0; i < _count; i++) {
Marshal.DestroyStructure(ptr, type);
ptr = new IntPtr(ptr.ToInt64() + size);

View file

@ -24,11 +24,10 @@ using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Greenshot.Configuration;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
using log4net;
namespace Greenshot.Helpers {
/// <summary>
@ -36,7 +35,7 @@ namespace Greenshot.Helpers {
/// </summary>
[Serializable]
public class PluginHelper : IGreenshotHost {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PluginHelper));
private static readonly ILog LOG = LogManager.GetLogger(typeof(PluginHelper));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private static string pluginPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),Application.ProductName);
@ -118,7 +117,7 @@ namespace Greenshot.Helpers {
/// <param name="image">Image of which we need a Thumbnail</param>
/// <returns>Image with Thumbnail</returns>
public Image GetThumbnail(Image image, int width, int height) {
return image.GetThumbnailImage(width, height, new Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
return image.GetThumbnailImage(width, height, ThumbnailCallback, IntPtr.Zero);
}
/// <summary>
@ -220,7 +219,7 @@ namespace Greenshot.Helpers {
foreach (string pluginFile in Directory.GetFiles(path, "*.gsp", SearchOption.AllDirectories)) {
pluginFiles.Add(pluginFile);
}
} catch (System.UnauthorizedAccessException) {
} catch (UnauthorizedAccessException) {
return;
} catch (Exception ex) {
LOG.Error("Error loading plugin: ", ex);

View file

@ -24,19 +24,19 @@ using System.Drawing.Printing;
using System.Windows.Forms;
using Greenshot.Configuration;
using Greenshot.Drawing;
using Greenshot.Forms;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
using Greenshot.Core;
using log4net;
namespace Greenshot.Helpers {
/// <summary>
/// Description of PrintHelper.
/// </summary>
public class PrintHelper : IDisposable {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PrintHelper));
private static readonly ILog LOG = LogManager.GetLogger(typeof(PrintHelper));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private ISurface surface;

View file

@ -23,13 +23,14 @@ using System.Collections.Generic;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using log4net;
namespace Greenshot.Helpers {
/// <summary>
/// Description of ProcessorHelper.
/// </summary>
public static class ProcessorHelper {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ProcessorHelper));
private static ILog LOG = LogManager.GetLogger(typeof(ProcessorHelper));
private static Dictionary<string, IProcessor> RegisteredProcessors = new Dictionary<string, IProcessor>();
/// Initialize the Processors

View file

@ -22,6 +22,7 @@ using System;
using System.Drawing;
using System.Windows.Forms;
using Greenshot.Drawing;
using log4net;
namespace Greenshot.Helpers {
/// <summary>
@ -45,7 +46,7 @@ namespace Greenshot.Helpers {
Rational = 0x02
}
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ScaleHelper));
private static readonly ILog LOG = LogManager.GetLogger(typeof(ScaleHelper));
/// <summary>
/// calculates the Size an element must be resized to, in order to fit another element, keeping aspect ratio
@ -289,10 +290,10 @@ namespace Greenshot.Helpers {
public static void Scale(Rectangle boundsBeforeResize, int gripperPosition, int cursorX, int cursorY, ref RectangleF boundsAfterResize, IDoubleProcessor angleRoundBehavior) {
ScaleHelper.ScaleOptions opts = ScaleHelper.GetScaleOptions();
ScaleOptions opts = GetScaleOptions();
bool rationalScale = (opts & ScaleHelper.ScaleOptions.Rational) == ScaleHelper.ScaleOptions.Rational;
bool centeredScale = (opts & ScaleHelper.ScaleOptions.Centered) == ScaleHelper.ScaleOptions.Centered;
bool rationalScale = (opts & ScaleOptions.Rational) == ScaleOptions.Rational;
bool centeredScale = (opts & ScaleOptions.Centered) == ScaleOptions.Centered;
if(rationalScale) {
double angle = GeometryHelper.Angle2D(boundsBeforeResize.X, boundsBeforeResize.Y, cursorX, cursorY);
@ -320,7 +321,7 @@ namespace Greenshot.Helpers {
}
/// <returns>the current ScaleOptions depending on modifier keys held down</returns>
public static ScaleHelper.ScaleOptions GetScaleOptions() {
public static ScaleOptions GetScaleOptions() {
bool anchorAtCenter = (Control.ModifierKeys & Keys.Control) != 0;
bool maintainAspectRatio = ((Control.ModifierKeys & Keys.Shift) != 0);
ScaleOptions opts = ScaleOptions.Default;
@ -353,7 +354,7 @@ namespace Greenshot.Helpers {
this.fixedAngle = fixedAngle;
}
public double Process(double angle) {
return this.fixedAngle;
return fixedAngle;
}
}

View file

@ -19,20 +19,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using Greenshot;
using Greenshot.Configuration;
using Greenshot.Plugin;
using GreenshotPlugin.UnmanagedHelpers;
using GreenshotPlugin.Core;
using Greenshot.IniFile;

View file

@ -27,17 +27,18 @@ using GreenshotPlugin.UnmanagedHelpers;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
using System.IO;
/// <summary>
/// Create to fix the sometimes wrongly played sample, especially after first start from IDE
/// See: http://www.codeproject.com/KB/audio-video/soundplayerbug.aspx?msg=2487569
/// </summary>
using log4net;
namespace Greenshot.Helpers {
/// <summary>
/// Description of SoundHelper.
/// </summary>
public static class SoundHelper {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SoundHelper));
private static readonly ILog LOG = LogManager.GetLogger(typeof(SoundHelper));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private static GCHandle? gcHandle = null;
private static byte[] soundBuffer = null;

View file

@ -20,6 +20,7 @@
*/
using System;
using System.Windows.Forms;
using log4net;
using Microsoft.Win32;
using System.IO;
@ -28,14 +29,14 @@ namespace Greenshot.Helpers {
/// A helper class for the startup registry
/// </summary>
public static class StartupHelper {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(StartupHelper));
private static readonly ILog LOG = LogManager.GetLogger(typeof(StartupHelper));
private const string RUNKEY6432 = @"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run";
private const string RUNKEY = @"Software\Microsoft\Windows\CurrentVersion\Run";
private const string APPLICATIONNAME = "Greenshot";
private static string getExecutablePath() {
private static string GetExecutablePath() {
return "\"" + Application.ExecutablePath + "\"";
}
@ -43,7 +44,7 @@ namespace Greenshot.Helpers {
/// Return true if the current user can write the RUN key of the local machine.
/// </summary>
/// <returns>true if Greenshot can write key</returns>
public static bool canWriteRunAll() {
public static bool CanWriteRunAll() {
try {
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(RUNKEY, true)) {
}
@ -57,7 +58,7 @@ namespace Greenshot.Helpers {
/// Return true if the current user can write the RUN key of the current user.
/// </summary>
/// <returns>true if Greenshot can write key</returns>
public static bool canWriteRunUser() {
public static bool CanWriteRunUser() {
try {
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, true)) {
}
@ -71,7 +72,7 @@ namespace Greenshot.Helpers {
/// Return the RUN key value of the local machine
/// </summary>
/// <returns>the RUN key value of the local machine</returns>
public static Object getRunAllValue() {
public static Object GetRunAllValue() {
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(RUNKEY, false)) {
if (key != null) {
object runValue = key.GetValue(APPLICATIONNAME);
@ -98,7 +99,7 @@ namespace Greenshot.Helpers {
/// Return the RUN key value of the current user
/// </summary>
/// <returns>the RUN key value of the current user</returns>
public static Object getRunUserValue() {
public static Object GetRunUserValue() {
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, false)) {
if (key != null) {
object runValue = key.GetValue(APPLICATIONNAME);
@ -125,9 +126,9 @@ namespace Greenshot.Helpers {
/// Return true if the local machine has a RUN entry for Greenshot
/// </summary>
/// <returns>true if there is a run key</returns>
public static bool hasRunAll() {
public static bool HasRunAll() {
try {
return getRunAllValue() != null;
return GetRunAllValue() != null;
} catch (Exception e) {
LOG.Error("Error retrieving RunAllValue", e);
}
@ -138,10 +139,10 @@ namespace Greenshot.Helpers {
/// Return true if the current user has a RUN entry for Greenshot
/// </summary>
/// <returns>true if there is a run key</returns>
public static bool hasRunUser() {
public static bool HasRunUser() {
Object runValue = null;
try {
runValue = getRunUserValue();
runValue = GetRunUserValue();
} catch (Exception e) {
LOG.Error("Error retrieving RunUserValue", e);
}
@ -151,8 +152,8 @@ namespace Greenshot.Helpers {
/// <summary>
/// Delete the RUN key for the localmachine ("ALL")
/// </summary>
public static void deleteRunAll() {
if (hasRunAll()) {
public static void DeleteRunAll() {
if (HasRunAll()) {
try {
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(RUNKEY, true)) {
key.DeleteValue(APPLICATIONNAME);
@ -176,8 +177,8 @@ namespace Greenshot.Helpers {
/// <summary>
/// Delete the RUN key for the current user
/// </summary>
public static void deleteRunUser() {
if (hasRunUser()) {
public static void DeleteRunUser() {
if (HasRunUser()) {
try {
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, true)) {
key.DeleteValue(APPLICATIONNAME);
@ -201,10 +202,10 @@ namespace Greenshot.Helpers {
/// <summary>
/// Set the RUN key for the current user
/// </summary>
public static void setRunUser() {
public static void SetRunUser() {
try {
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RUNKEY, true)) {
key.SetValue(APPLICATIONNAME, getExecutablePath());
key.SetValue(APPLICATIONNAME, GetExecutablePath());
}
} catch (Exception e) {
LOG.Error("Error in setRunUser.", e);

View file

@ -21,22 +21,20 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Net;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Greenshot.Configuration;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
using log4net;
namespace Greenshot.Experimental {
/// <summary>
/// Description of RssFeedHelper.
/// </summary>
public static class UpdateHelper {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(UpdateHelper));
private static ILog LOG = LogManager.GetLogger(typeof(UpdateHelper));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private const string STABLE_DOWNLOAD_LINK = "http://getgreenshot.org/downloads/";
private const string VERSION_HISTORY_LINK = "http://getgreenshot.org/version-history/";
@ -79,7 +77,7 @@ namespace Greenshot.Experimental {
try {
latestGreenshot = null;
UpdateHelper.ProcessRSSInfo(currentVersion);
ProcessRSSInfo(currentVersion);
if (latestGreenshot != null) {
MainForm.Instance.NotifyIcon.BalloonTipClicked += HandleBalloonTipClick;
MainForm.Instance.NotifyIcon.BalloonTipClosed += CleanupBalloonTipClick;

View file

@ -19,9 +19,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Windows.Forms;
namespace Greenshot.Helpers {
public class WindowWrapper : System.Windows.Forms.IWin32Window {
public class WindowWrapper : IWin32Window {
public WindowWrapper(IntPtr handle) {
_hwnd = handle;
}