mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 10:47:02 -07:00
Code quality changes
This commit is contained in:
parent
f07ed83722
commit
610f45d082
189 changed files with 4609 additions and 5203 deletions
|
@ -148,11 +148,9 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
public static Color ColorizationColor {
|
||||
get {
|
||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(COLORIZATION_COLOR_KEY, false)) {
|
||||
if (key != null) {
|
||||
object dwordValue = key.GetValue("ColorizationColor");
|
||||
if (dwordValue != null) {
|
||||
return Color.FromArgb((Int32)dwordValue);
|
||||
}
|
||||
object dwordValue = key?.GetValue("ColorizationColor");
|
||||
if (dwordValue != null) {
|
||||
return Color.FromArgb((int)dwordValue);
|
||||
}
|
||||
}
|
||||
return Color.White;
|
||||
|
|
|
@ -168,7 +168,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
public class SafeCompatibleDCHandle : SafeDCHandle {
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DeleteDC(IntPtr hDC);
|
||||
private static extern bool DeleteDC(IntPtr hDC);
|
||||
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
|
@ -367,7 +367,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
// V5
|
||||
bV5RedMask = (uint)255 << 16;
|
||||
bV5GreenMask = (uint)255 << 8;
|
||||
bV5BlueMask = (uint)255;
|
||||
bV5BlueMask = 255;
|
||||
bV5AlphaMask = (uint)255 << 24;
|
||||
bV5CSType = 1934772034; // sRGB
|
||||
bV5Endpoints = new CIEXYZTRIPLE
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// GDIplus Helpers
|
||||
/// </summary>
|
||||
public static class GDIplus {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(GDIplus));
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(GDIplus));
|
||||
|
||||
[DllImport("gdiplus.dll", SetLastError = true, ExactSpelling = true)]
|
||||
private static extern int GdipBitmapApplyEffect(IntPtr bitmap, IntPtr effect, ref RECT rectOfInterest, bool useAuxData, IntPtr auxData, int auxDataSize);
|
||||
|
@ -170,15 +170,12 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// This accounts for the "bug" I reported here: http://social.technet.microsoft.com/Forums/en/w8itprogeneral/thread/99ddbe9d-556d-475a-8bab-84e25aa13a2c
|
||||
/// </summary>
|
||||
/// <param name="radius"></param>
|
||||
/// <returns></returns>
|
||||
/// <returns>false if blur is not possible</returns>
|
||||
public static bool IsBlurPossible(int radius) {
|
||||
if (!_isBlurEnabled) {
|
||||
return false;
|
||||
}
|
||||
if (Environment.OSVersion.Version.Minor >= 2 && radius < 20) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return Environment.OSVersion.Version.Minor < 2 || radius >= 20;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -197,18 +194,24 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
IntPtr hEffect = IntPtr.Zero;
|
||||
|
||||
try {
|
||||
// Create the GDI+ BlurEffect, using the Guid
|
||||
int status = GdipCreateEffect(BlurEffectGuid, out hEffect);
|
||||
if (status != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Create a BlurParams struct and set the values
|
||||
BlurParams blurParams = new BlurParams();
|
||||
blurParams.Radius = radius;
|
||||
blurParams.ExpandEdges = expandEdges;
|
||||
var blurParams = new BlurParams
|
||||
{
|
||||
Radius = radius,
|
||||
ExpandEdges = expandEdges
|
||||
};
|
||||
|
||||
// Allocate space in unmanaged memory
|
||||
hBlurParams = Marshal.AllocHGlobal(Marshal.SizeOf(blurParams));
|
||||
// Copy the structure to the unmanaged memory
|
||||
Marshal.StructureToPtr(blurParams, hBlurParams, false);
|
||||
|
||||
// Create the GDI+ BlurEffect, using the Guid
|
||||
int status = GdipCreateEffect(BlurEffectGuid, out hEffect);
|
||||
|
||||
// Set the blurParams to the effect
|
||||
GdipSetEffectParameters(hEffect, hBlurParams, (uint)Marshal.SizeOf(blurParams));
|
||||
|
@ -226,7 +229,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
return true;
|
||||
} catch (Exception ex) {
|
||||
_isBlurEnabled = false;
|
||||
LOG.Error("Problem using GdipBitmapApplyEffect: ", ex);
|
||||
Log.Error("Problem using GdipBitmapApplyEffect: ", ex);
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
|
@ -240,7 +243,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
}
|
||||
} catch (Exception ex) {
|
||||
_isBlurEnabled = false;
|
||||
LOG.Error("Problem cleaning up ApplyBlur: ", ex);
|
||||
Log.Error("Problem cleaning up ApplyBlur: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -258,20 +261,26 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
IntPtr hEffect = IntPtr.Zero;
|
||||
|
||||
try {
|
||||
// Create the GDI+ BlurEffect, using the Guid
|
||||
int status = GdipCreateEffect(BlurEffectGuid, out hEffect);
|
||||
if (status != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create a BlurParams struct and set the values
|
||||
BlurParams blurParams = new BlurParams();
|
||||
blurParams.Radius = radius;
|
||||
var blurParams = new BlurParams
|
||||
{
|
||||
Radius = radius,
|
||||
ExpandEdges = false
|
||||
};
|
||||
//blurParams.Padding = radius;
|
||||
blurParams.ExpandEdges = false;
|
||||
|
||||
// Allocate space in unmanaged memory
|
||||
hBlurParams = Marshal.AllocHGlobal(Marshal.SizeOf(blurParams));
|
||||
// Copy the structure to the unmanaged memory
|
||||
Marshal.StructureToPtr(blurParams, hBlurParams, true);
|
||||
|
||||
// Create the GDI+ BlurEffect, using the Guid
|
||||
int status = GdipCreateEffect(BlurEffectGuid, out hEffect);
|
||||
|
||||
// Set the blurParams to the effect
|
||||
GdipSetEffectParameters(hEffect, hBlurParams, (uint)Marshal.SizeOf(blurParams));
|
||||
|
||||
|
@ -283,15 +292,15 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
IntPtr hAttributes = GetNativeImageAttributes(imageAttributes);
|
||||
|
||||
// Create a RECT from the Rectangle
|
||||
RECTF sourceRECF = new RECTF(source);
|
||||
RECTF sourceRecf = new RECTF(source);
|
||||
// Apply the effect to the bitmap in the specified area
|
||||
GdipDrawImageFX(hGraphics, hBitmap, ref sourceRECF, hMatrix, hEffect, hAttributes, GpUnit.UnitPixel);
|
||||
GdipDrawImageFX(hGraphics, hBitmap, ref sourceRecf, hMatrix, hEffect, hAttributes, GpUnit.UnitPixel);
|
||||
|
||||
// Everything worked, return true
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
_isBlurEnabled = false;
|
||||
LOG.Error("Problem using GdipDrawImageFX: ", ex);
|
||||
Log.Error("Problem using GdipDrawImageFX: ", ex);
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
|
@ -305,7 +314,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
}
|
||||
} catch (Exception ex) {
|
||||
_isBlurEnabled = false;
|
||||
LOG.Error("Problem cleaning up DrawWithBlur: ", ex);
|
||||
Log.Error("Problem cleaning up DrawWithBlur: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -196,12 +196,12 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// </summary>
|
||||
/// <param name="filePath">The path to the file that contains an image.</param>
|
||||
/// <returns>The System.Drawing.Icon representation of the image contained in the specified file.</returns>
|
||||
public static Icon ExtractAssociatedIcon(String filePath) {
|
||||
public static Icon ExtractAssociatedIcon(string filePath) {
|
||||
int index = 0;
|
||||
|
||||
Uri uri;
|
||||
if (filePath == null) {
|
||||
throw new ArgumentException(String.Format("'{0}' is not valid for '{1}'", "null", "filePath"), "filePath");
|
||||
throw new ArgumentException("Null is not valid for filePath", nameof(filePath));
|
||||
}
|
||||
try {
|
||||
uri = new Uri(filePath);
|
||||
|
|
|
@ -30,10 +30,12 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
public SIZE(Size size) : this(size.Width, size.Height) {
|
||||
|
||||
}
|
||||
|
||||
public SIZE(int width, int height) {
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public Size ToSize() {
|
||||
return new Size(Width, Height);
|
||||
}
|
||||
|
@ -82,11 +84,11 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
public RECT(Rectangle rectangle)
|
||||
: this(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom) {
|
||||
}
|
||||
public RECT(int Left, int Top, int Right, int Bottom) {
|
||||
_Left = Left;
|
||||
_Top = Top;
|
||||
_Right = Right;
|
||||
_Bottom = Bottom;
|
||||
public RECT(int left, int top, int right, int bottom) {
|
||||
_Left = left;
|
||||
_Top = top;
|
||||
_Right = right;
|
||||
_Bottom = bottom;
|
||||
}
|
||||
|
||||
public int X {
|
||||
|
@ -172,17 +174,17 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
}
|
||||
}
|
||||
|
||||
public static implicit operator Rectangle(RECT Rectangle) {
|
||||
return new Rectangle(Rectangle.Left, Rectangle.Top, Rectangle.Width, Rectangle.Height);
|
||||
public static implicit operator Rectangle(RECT rectangle) {
|
||||
return new Rectangle(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
|
||||
}
|
||||
public static implicit operator RECT(Rectangle Rectangle) {
|
||||
return new RECT(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom);
|
||||
public static implicit operator RECT(Rectangle rectangle) {
|
||||
return new RECT(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom);
|
||||
}
|
||||
public static bool operator ==(RECT Rectangle1, RECT Rectangle2) {
|
||||
return Rectangle1.Equals(Rectangle2);
|
||||
public static bool operator ==(RECT rectangle1, RECT rectangle2) {
|
||||
return rectangle1.Equals(rectangle2);
|
||||
}
|
||||
public static bool operator !=(RECT Rectangle1, RECT Rectangle2) {
|
||||
return !Rectangle1.Equals(Rectangle2);
|
||||
public static bool operator !=(RECT rectangle1, RECT rectangle2) {
|
||||
return !rectangle1.Equals(rectangle2);
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
|
@ -193,8 +195,8 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
return ToString().GetHashCode();
|
||||
}
|
||||
|
||||
public bool Equals(RECT Rectangle) {
|
||||
return Rectangle.Left == _Left && Rectangle.Top == _Top && Rectangle.Right == _Right && Rectangle.Bottom == _Bottom;
|
||||
public bool Equals(RECT rectangle) {
|
||||
return rectangle.Left == _Left && rectangle.Top == _Top && rectangle.Right == _Right && rectangle.Bottom == _Bottom;
|
||||
}
|
||||
|
||||
public Rectangle ToRectangle() {
|
||||
|
@ -313,7 +315,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// The structure for the WindowInfo
|
||||
/// See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632610%28v=vs.85%29.aspx
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential), Serializable()]
|
||||
[StructLayout(LayoutKind.Sequential), Serializable]
|
||||
public struct WindowInfo {
|
||||
public uint cbSize;
|
||||
public RECT rcWindow;
|
||||
|
@ -326,8 +328,8 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
public ushort atomWindowType;
|
||||
public ushort wCreatorVersion;
|
||||
// Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)".
|
||||
public WindowInfo(Boolean? filler) : this() {
|
||||
cbSize = (UInt32)(Marshal.SizeOf(typeof(WindowInfo)));
|
||||
public WindowInfo(bool? filler) : this() {
|
||||
cbSize = (uint)(Marshal.SizeOf(typeof(WindowInfo)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -383,8 +385,8 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct CursorInfo {
|
||||
public Int32 cbSize;
|
||||
public Int32 flags;
|
||||
public int cbSize;
|
||||
public int flags;
|
||||
public IntPtr hCursor;
|
||||
public POINT ptScreenPos;
|
||||
}
|
||||
|
@ -392,8 +394,8 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct IconInfo {
|
||||
public bool fIcon;
|
||||
public Int32 xHotspot;
|
||||
public Int32 yHotspot;
|
||||
public int xHotspot;
|
||||
public int yHotspot;
|
||||
public IntPtr hbmMask;
|
||||
public IntPtr hbmColor;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
public const int MONITOR_DEFAULTTONULL = 0;
|
||||
public const int MONITOR_DEFAULTTOPRIMARY = 1;
|
||||
public const int MONITOR_DEFAULTTONEAREST = 2;
|
||||
public const Int32 CURSOR_SHOWING = 0x00000001;
|
||||
public const int CURSOR_SHOWING = 0x00000001;
|
||||
|
||||
#region DllImports
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
|
@ -382,7 +382,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// <summary>
|
||||
/// A WindowDC SafeHandle implementation
|
||||
/// </summary>
|
||||
public class SafeWindowDCHandle : SafeHandleZeroOrMinusOneIsInvalid {
|
||||
public class SafeWindowDcHandle : SafeHandleZeroOrMinusOneIsInvalid {
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
private static extern IntPtr GetWindowDC(IntPtr hWnd);
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
|
@ -393,12 +393,12 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
public SafeWindowDCHandle() : base(true)
|
||||
public SafeWindowDcHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public SafeWindowDCHandle(IntPtr hWnd, IntPtr preexistingHandle) : base(true) {
|
||||
public SafeWindowDcHandle(IntPtr hWnd, IntPtr preexistingHandle) : base(true) {
|
||||
_hWnd = hWnd;
|
||||
SetHandle(preexistingHandle);
|
||||
}
|
||||
|
@ -409,10 +409,10 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
return returnValue;
|
||||
}
|
||||
|
||||
public static SafeWindowDCHandle FromDesktop() {
|
||||
public static SafeWindowDcHandle FromDesktop() {
|
||||
IntPtr hWndDesktop = User32.GetDesktopWindow();
|
||||
IntPtr hDCDesktop = GetWindowDC(hWndDesktop);
|
||||
return new SafeWindowDCHandle(hWndDesktop, hDCDesktop);
|
||||
return new SafeWindowDcHandle(hWndDesktop, hDCDesktop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,10 +103,10 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
int error = (int)errorCode;
|
||||
|
||||
if ((error & 0x80000000) == 0x80000000) {
|
||||
return (long)error;
|
||||
return error;
|
||||
}
|
||||
|
||||
return (long)(0x80070000 | (uint)(error & 0xffff));
|
||||
return 0x80070000 | (uint)(error & 0xffff);
|
||||
}
|
||||
|
||||
public static string GetMessage(Win32Error errorCode) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue