mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 05:53:27 -07:00
Code quality changes, and added the possibility to set the amount of colors for the Quantizer.
This commit is contained in:
parent
3b1560390b
commit
77a92d98c3
92 changed files with 690 additions and 653 deletions
|
@ -21,17 +21,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
/// Description of AbstractDestination.
|
||||
/// </summary>
|
||||
public abstract class AbstractDestination : IDestination {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AbstractDestination));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(AbstractDestination));
|
||||
private static CoreConfiguration configuration = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
public virtual int CompareTo(object obj) {
|
||||
|
@ -246,7 +248,7 @@ namespace GreenshotPlugin.Core {
|
|||
// Close
|
||||
menu.Items.Add(new ToolStripSeparator());
|
||||
ToolStripMenuItem closeItem = new ToolStripMenuItem(Language.GetString("editor_close"));
|
||||
closeItem.Image = GreenshotPlugin.Core.GreenshotResources.getImage("Close.Image");
|
||||
closeItem.Image = GreenshotResources.getImage("Close.Image");
|
||||
closeItem.Click += delegate {
|
||||
// This menu entry is the close itself, we can dispose the surface
|
||||
menu.Close();
|
||||
|
@ -285,7 +287,7 @@ namespace GreenshotPlugin.Core {
|
|||
while (true) {
|
||||
if (menu.Visible) {
|
||||
Application.DoEvents();
|
||||
System.Threading.Thread.Sleep(100);
|
||||
Thread.Sleep(100);
|
||||
} else {
|
||||
menu.Dispose();
|
||||
break;
|
||||
|
|
|
@ -23,6 +23,7 @@ using System.Collections.Generic;
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
using Accessibility;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
|
||||
|
@ -32,7 +33,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Maybe move the basic Accessible functions to WindowDetails!?
|
||||
/// </summary>
|
||||
public class Accessible {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(Accessible));
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(Accessible));
|
||||
|
||||
#region Interop
|
||||
private static int AccessibleObjectFromWindow(IntPtr hWnd, OBJID idObject, ref IAccessible acc) {
|
||||
|
|
|
@ -22,6 +22,7 @@ using System;
|
|||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Collections.Generic;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
|
||||
|
@ -99,9 +100,9 @@ namespace GreenshotPlugin.Core {
|
|||
this.first = first;
|
||||
this.last = last;
|
||||
this.frames = frames;
|
||||
this.current = first;
|
||||
this.EasingType = easingType;
|
||||
this.EasingMode = easingMode;
|
||||
current = first;
|
||||
EasingType = easingType;
|
||||
EasingMode = easingMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -159,10 +160,10 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="frames"></param>
|
||||
public void ChangeDestination(T newDestination, int frames) {
|
||||
queue.Clear();
|
||||
this.first = current;
|
||||
this.currentFrameNr = 0;
|
||||
first = current;
|
||||
currentFrameNr = 0;
|
||||
this.frames = frames;
|
||||
this.last = newDestination;
|
||||
last = newDestination;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -261,13 +262,13 @@ namespace GreenshotPlugin.Core {
|
|||
return true;
|
||||
}
|
||||
if (queue.Count > 0) {
|
||||
this.first = current;
|
||||
this.currentFrameNr = 0;
|
||||
first = current;
|
||||
currentFrameNr = 0;
|
||||
AnimationLeg<T> nextLeg = queue.Dequeue();
|
||||
this.last = nextLeg.Destination;
|
||||
this.frames = nextLeg.Frames;
|
||||
this.EasingType = nextLeg.EasingType;
|
||||
this.EasingMode = nextLeg.EasingMode;
|
||||
last = nextLeg.Destination;
|
||||
frames = nextLeg.Frames;
|
||||
EasingType = nextLeg.EasingType;
|
||||
EasingMode = nextLeg.EasingMode;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -297,7 +298,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Implementation of the RectangleAnimator
|
||||
/// </summary>
|
||||
public class RectangleAnimator : AnimatorBase<Rectangle> {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(RectangleAnimator));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(RectangleAnimator));
|
||||
|
||||
public RectangleAnimator(Rectangle first, Rectangle last, int frames)
|
||||
: base(first, last, frames, EasingType.Linear, EasingMode.EaseIn) {
|
||||
|
@ -336,7 +337,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Implementation of the PointAnimator
|
||||
/// </summary>
|
||||
public class PointAnimator : AnimatorBase<Point> {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PointAnimator));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(PointAnimator));
|
||||
public PointAnimator(Point first, Point last, int frames)
|
||||
: base(first, last, frames, EasingType.Linear, EasingMode.EaseIn) {
|
||||
}
|
||||
|
@ -369,7 +370,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Implementation of the SizeAnimator
|
||||
/// </summary>
|
||||
public class SizeAnimator : AnimatorBase<Size> {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SizeAnimator));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(SizeAnimator));
|
||||
public SizeAnimator(Size first, Size last, int frames)
|
||||
: base(first, last, frames, EasingType.Linear, EasingMode.EaseIn) {
|
||||
}
|
||||
|
@ -401,7 +402,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Implementation of the ColorAnimator
|
||||
/// </summary>
|
||||
public class ColorAnimator : AnimatorBase<Color> {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ColorAnimator));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(ColorAnimator));
|
||||
public ColorAnimator(Color first, Color last, int frames)
|
||||
: base(first, last, frames, EasingType.Linear, EasingMode.EaseIn) {
|
||||
}
|
||||
|
@ -437,7 +438,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Implementation of the IntAnimator
|
||||
/// </summary>
|
||||
public class IntAnimator : AnimatorBase<int> {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(IntAnimator));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(IntAnimator));
|
||||
public IntAnimator(int first, int last, int frames)
|
||||
: base(first, last, frames, EasingType.Linear, EasingMode.EaseIn) {
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Timers;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
|
@ -29,7 +30,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <typeparam name="TK">Type of key</typeparam>
|
||||
/// <typeparam name="TV">Type of value</typeparam>
|
||||
public class Cache<TK, TV> {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(Cache<TK, TV>));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(Cache<TK, TV>));
|
||||
private IDictionary<TK, TV> internalCache = new Dictionary<TK, TV>();
|
||||
private object lockObject = new object();
|
||||
private int secondsToExpire = 10;
|
||||
|
|
|
@ -31,13 +31,14 @@ using Greenshot.IniFile;
|
|||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
using System.Runtime.InteropServices;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
/// Description of ClipboardHelper.
|
||||
/// </summary>
|
||||
public static class ClipboardHelper {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ClipboardHelper));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(ClipboardHelper));
|
||||
private static readonly Object clipboardLockObject = new Object();
|
||||
private static readonly CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static readonly string FORMAT_FILECONTENTS = "FileContents";
|
||||
|
|
|
@ -113,6 +113,8 @@ namespace GreenshotPlugin.Core {
|
|||
public bool OutputFileReduceColors;
|
||||
[IniProperty("OutputFileAutoReduceColors", Description = "If set to true the amount of colors is counted and if smaller than 256 the color reduction is automatically used.", DefaultValue = "false")]
|
||||
public bool OutputFileAutoReduceColors;
|
||||
[IniProperty("OutputFileReduceColorsTo", Description = "Amount of colors to reduce to, when reducing", DefaultValue = "256")]
|
||||
public int OutputFileReduceColorsTo;
|
||||
|
||||
[IniProperty("OutputFileCopyPathToClipboard", Description="When saving a screenshot, copy the path to the clipboard?", DefaultValue="true")]
|
||||
public bool OutputFileCopyPathToClipboard;
|
||||
|
|
|
@ -95,10 +95,10 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="message">The message of the dialog (null will cause a system default message to be used).</param>
|
||||
/// <param name="banner">The image to display on the dialog (null will cause a system default image to be used).</param>
|
||||
public CredentialsDialog(string target, string caption, string message, Image banner) {
|
||||
this.Target = target;
|
||||
this.Caption = caption;
|
||||
this.Message = message;
|
||||
this.Banner = banner;
|
||||
Target = target;
|
||||
Caption = caption;
|
||||
Message = message;
|
||||
Banner = banner;
|
||||
}
|
||||
|
||||
private bool _alwaysDisplay = false;
|
||||
|
@ -307,21 +307,21 @@ namespace GreenshotPlugin.Core {
|
|||
/// <summary>Shows the credentials dialog.</summary>
|
||||
/// <returns>Returns a DialogResult indicating the user action.</returns>
|
||||
public DialogResult Show() {
|
||||
return Show(null, this.Name, this.Password, this.SaveChecked);
|
||||
return Show(null, Name, Password, SaveChecked);
|
||||
}
|
||||
|
||||
/// <summary>Shows the credentials dialog with the specified save checkbox status.</summary>
|
||||
/// <param name="saveChecked">True if the save checkbox is checked.</param>
|
||||
/// <returns>Returns a DialogResult indicating the user action.</returns>
|
||||
public DialogResult Show(bool saveChecked) {
|
||||
return Show(null, this.Name, this.Password, saveChecked);
|
||||
return Show(null, Name, Password, saveChecked);
|
||||
}
|
||||
|
||||
/// <summary>Shows the credentials dialog with the specified name.</summary>
|
||||
/// <param name="name">The name for the credentials.</param>
|
||||
/// <returns>Returns a DialogResult indicating the user action.</returns>
|
||||
public DialogResult Show(string name) {
|
||||
return Show(null, name, this.Password, this.SaveChecked);
|
||||
return Show(null, name, Password, SaveChecked);
|
||||
}
|
||||
|
||||
/// <summary>Shows the credentials dialog with the specified name and password.</summary>
|
||||
|
@ -329,7 +329,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="password">The password for the credentials.</param>
|
||||
/// <returns>Returns a DialogResult indicating the user action.</returns>
|
||||
public DialogResult Show(string name, string password) {
|
||||
return Show(null, name, password, this.SaveChecked);
|
||||
return Show(null, name, password, SaveChecked);
|
||||
}
|
||||
|
||||
/// <summary>Shows the credentials dialog with the specified name, password and save checkbox status.</summary>
|
||||
|
@ -345,7 +345,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="owner">The System.Windows.Forms.IWin32Window the dialog will display in front of.</param>
|
||||
/// <returns>Returns a DialogResult indicating the user action.</returns>
|
||||
public DialogResult Show(IWin32Window owner) {
|
||||
return Show(owner, this.Name, this.Password, this.SaveChecked);
|
||||
return Show(owner, Name, Password, SaveChecked);
|
||||
}
|
||||
|
||||
/// <summary>Shows the credentials dialog with the specified owner and save checkbox status.</summary>
|
||||
|
@ -353,7 +353,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="saveChecked">True if the save checkbox is checked.</param>
|
||||
/// <returns>Returns a DialogResult indicating the user action.</returns>
|
||||
public DialogResult Show(IWin32Window owner, bool saveChecked) {
|
||||
return Show(owner, this.Name, this.Password, saveChecked);
|
||||
return Show(owner, Name, Password, saveChecked);
|
||||
}
|
||||
|
||||
/// <summary>Shows the credentials dialog with the specified owner, name and password.</summary>
|
||||
|
@ -362,7 +362,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="password">The password for the credentials.</param>
|
||||
/// <returns>Returns a DialogResult indicating the user action.</returns>
|
||||
public DialogResult Show(IWin32Window owner, string name, string password) {
|
||||
return Show(owner, name, password, this.SaveChecked);
|
||||
return Show(owner, name, password, SaveChecked);
|
||||
}
|
||||
|
||||
/// <summary>Shows the credentials dialog with the specified owner, name, password and save checkbox status.</summary>
|
||||
|
@ -375,9 +375,9 @@ namespace GreenshotPlugin.Core {
|
|||
if ((Environment.OSVersion.Version.Major < 5) || ((Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor < 1))) {
|
||||
throw new ApplicationException("The Credential Management API requires Windows XP / Windows Server 2003 or later.");
|
||||
}
|
||||
this.Name = name;
|
||||
this.Password = password;
|
||||
this.SaveChecked = saveChecked;
|
||||
Name = name;
|
||||
Password = password;
|
||||
SaveChecked = saveChecked;
|
||||
|
||||
return ShowDialog(owner);
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <summary>Confirmation action to be applied.</summary>
|
||||
/// <param name="value">True if the credentials should be persisted.</param>
|
||||
public void Confirm(bool value) {
|
||||
switch (CREDUI.ConfirmCredentials(this.Target, value)) {
|
||||
switch (CREDUI.ConfirmCredentials(Target, value)) {
|
||||
case CREDUI.ReturnCodes.NO_ERROR:
|
||||
break;
|
||||
|
||||
|
@ -406,12 +406,12 @@ namespace GreenshotPlugin.Core {
|
|||
private DialogResult ShowDialog(IWin32Window owner) {
|
||||
// set the api call parameters
|
||||
StringBuilder name = new StringBuilder(CREDUI.MAX_USERNAME_LENGTH);
|
||||
name.Append(this.Name);
|
||||
name.Append(Name);
|
||||
|
||||
StringBuilder password = new StringBuilder(CREDUI.MAX_PASSWORD_LENGTH);
|
||||
password.Append(this.Password);
|
||||
password.Append(Password);
|
||||
|
||||
int saveChecked = Convert.ToInt32(this.SaveChecked);
|
||||
int saveChecked = Convert.ToInt32(SaveChecked);
|
||||
|
||||
CREDUI.INFO info = GetInfo(owner);
|
||||
CREDUI.FLAGS flags = GetFlags();
|
||||
|
@ -419,7 +419,7 @@ namespace GreenshotPlugin.Core {
|
|||
// make the api call
|
||||
CREDUI.ReturnCodes code = CREDUI.PromptForCredentials(
|
||||
ref info,
|
||||
this.Target,
|
||||
Target,
|
||||
IntPtr.Zero, 0,
|
||||
name, CREDUI.MAX_USERNAME_LENGTH,
|
||||
password, CREDUI.MAX_PASSWORD_LENGTH,
|
||||
|
@ -428,14 +428,14 @@ namespace GreenshotPlugin.Core {
|
|||
);
|
||||
|
||||
// clean up resources
|
||||
if (this.Banner != null) {
|
||||
if (Banner != null) {
|
||||
DeleteObject(info.hbmBanner);
|
||||
}
|
||||
|
||||
// set the accessors from the api call parameters
|
||||
this.Name = name.ToString();
|
||||
this.Password = password.ToString();
|
||||
this.SaveChecked = Convert.ToBoolean(saveChecked);
|
||||
Name = name.ToString();
|
||||
Password = password.ToString();
|
||||
SaveChecked = Convert.ToBoolean(saveChecked);
|
||||
|
||||
return GetDialogResult(code);
|
||||
}
|
||||
|
@ -445,10 +445,10 @@ namespace GreenshotPlugin.Core {
|
|||
private CREDUI.INFO GetInfo(IWin32Window owner) {
|
||||
CREDUI.INFO info = new CREDUI.INFO();
|
||||
if (owner != null) info.hwndParent = owner.Handle;
|
||||
info.pszCaptionText = this.Caption;
|
||||
info.pszMessageText = this.Message;
|
||||
if (this.Banner != null) {
|
||||
info.hbmBanner = new Bitmap(this.Banner, ValidBannerWidth, ValidBannerHeight).GetHbitmap();
|
||||
info.pszCaptionText = Caption;
|
||||
info.pszMessageText = Message;
|
||||
if (Banner != null) {
|
||||
info.hbmBanner = new Bitmap(Banner, ValidBannerWidth, ValidBannerHeight).GetHbitmap();
|
||||
}
|
||||
info.cbSize = Marshal.SizeOf(info);
|
||||
return info;
|
||||
|
@ -458,21 +458,21 @@ namespace GreenshotPlugin.Core {
|
|||
private CREDUI.FLAGS GetFlags() {
|
||||
CREDUI.FLAGS flags = CREDUI.FLAGS.GENERIC_CREDENTIALS;
|
||||
|
||||
if (this.IncorrectPassword) {
|
||||
if (IncorrectPassword) {
|
||||
flags = flags | CREDUI.FLAGS.INCORRECT_PASSWORD;
|
||||
}
|
||||
|
||||
if (this.AlwaysDisplay) {
|
||||
if (AlwaysDisplay) {
|
||||
flags = flags | CREDUI.FLAGS.ALWAYS_SHOW_UI;
|
||||
}
|
||||
|
||||
if (this.ExcludeCertificates) {
|
||||
if (ExcludeCertificates) {
|
||||
flags = flags | CREDUI.FLAGS.EXCLUDE_CERTIFICATES;
|
||||
}
|
||||
|
||||
if (this.Persist) {
|
||||
if (Persist) {
|
||||
flags = flags | CREDUI.FLAGS.EXPECT_CONFIRMATION;
|
||||
if (this.SaveDisplayed) {
|
||||
if (SaveDisplayed) {
|
||||
flags = flags | CREDUI.FLAGS.SHOW_SAVE_CHECK_BOX;
|
||||
} else {
|
||||
flags = flags | CREDUI.FLAGS.PERSIST;
|
||||
|
@ -481,7 +481,7 @@ namespace GreenshotPlugin.Core {
|
|||
flags = flags | CREDUI.FLAGS.DO_NOT_PERSIST;
|
||||
}
|
||||
|
||||
if (this.KeepName) {
|
||||
if (KeepName) {
|
||||
flags = flags | CREDUI.FLAGS.KEEP_USERNAME;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
|
||||
public DisplayKeyAttribute(string v) {
|
||||
this.value = v;
|
||||
value = v;
|
||||
}
|
||||
|
||||
public DisplayKeyAttribute() {
|
||||
|
|
|
@ -27,6 +27,7 @@ using Greenshot.Plugin.Drawing;
|
|||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using GreenshotPlugin.Core;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Core {
|
||||
/// <summary>
|
||||
|
@ -147,7 +148,7 @@ namespace Greenshot.Core {
|
|||
/// ReduceColorsEffect
|
||||
/// </summary>
|
||||
public class ReduceColorsEffect : IEffect {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ReduceColorsEffect));
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(ReduceColorsEffect));
|
||||
public ReduceColorsEffect() : base() {
|
||||
Colors = 256;
|
||||
}
|
||||
|
|
|
@ -22,10 +22,11 @@ using System;
|
|||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
public static class EncryptionHelper {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(EncryptionHelper));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(EncryptionHelper));
|
||||
private const string RGBIV = "dlgjowejgogkklwj";
|
||||
private const string KEY = "lsjvkwhvwujkagfauguwcsjgu2wueuff";
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
using System;
|
||||
namespace GreenshotPlugin.Core {
|
||||
public static class EnumerationExtensions {
|
||||
public static bool Has<T>(this System.Enum type, T value) {
|
||||
public static bool Has<T>(this Enum type, T value) {
|
||||
Type underlyingType = Enum.GetUnderlyingType(value.GetType());
|
||||
try {
|
||||
if (underlyingType == typeof(int)) {
|
||||
|
@ -34,7 +34,7 @@ namespace GreenshotPlugin.Core {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static bool Is<T>(this System.Enum type, T value) {
|
||||
public static bool Is<T>(this Enum type, T value) {
|
||||
Type underlyingType = Enum.GetUnderlyingType(value.GetType());
|
||||
try {
|
||||
if (underlyingType == typeof(int)) {
|
||||
|
@ -53,7 +53,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="type"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static T Add<T>(this System.Enum type, T value) {
|
||||
public static T Add<T>(this Enum type, T value) {
|
||||
Type underlyingType = Enum.GetUnderlyingType(value.GetType());
|
||||
try {
|
||||
if (underlyingType == typeof(int)) {
|
||||
|
@ -73,7 +73,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="type"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static T Remove<T>(this System.Enum type, T value) {
|
||||
public static T Remove<T>(this Enum type, T value) {
|
||||
Type underlyingType = Enum.GetUnderlyingType(value.GetType());
|
||||
try {
|
||||
if (underlyingType == typeof(int)) {
|
||||
|
|
|
@ -22,6 +22,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
|
||||
|
@ -283,7 +284,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// The base class for the fast bitmap implementation
|
||||
/// </summary>
|
||||
public unsafe abstract class FastBitmap : IFastBitmap, IFastBitmapWithClip, IFastBitmapWithOffset {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(FastBitmap));
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(FastBitmap));
|
||||
|
||||
protected const int PIXELFORMAT_INDEX_A = 3;
|
||||
protected const int PIXELFORMAT_INDEX_R = 2;
|
||||
|
@ -427,11 +428,11 @@ namespace GreenshotPlugin.Core {
|
|||
this.area = bitmapArea;
|
||||
}
|
||||
// As the lock takes care that only the specified area is made available we need to calculate the offset
|
||||
this.Left = area.Left;
|
||||
this.Top = area.Top;
|
||||
Left = area.Left;
|
||||
Top = area.Top;
|
||||
// Default cliping is done to the area without invert
|
||||
this.Clip = this.area;
|
||||
this.InvertClip = false;
|
||||
Clip = this.area;
|
||||
InvertClip = false;
|
||||
// Always lock, so we don't need to do this ourselves
|
||||
Lock();
|
||||
}
|
||||
|
@ -639,7 +640,7 @@ namespace GreenshotPlugin.Core {
|
|||
Unlock();
|
||||
}
|
||||
|
||||
graphics.DrawImage(this.bitmap, destinationRect, area, GraphicsUnit.Pixel);
|
||||
graphics.DrawImage(bitmap, destinationRect, area, GraphicsUnit.Pixel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -25,10 +25,11 @@ using System.Text.RegularExpressions;
|
|||
using System.Windows.Forms;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
public static class FilenameHelper {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(FilenameHelper));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(FilenameHelper));
|
||||
private static readonly Regex VAR_REGEXP = new Regex(@"\${(?<variable>[^:}]+)[:]?(?<parameters>[^}]*)}", RegexOptions.Compiled);
|
||||
private static readonly Regex SPLIT_REGEXP = new Regex(";(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", RegexOptions.Compiled);
|
||||
private const int MAX_TITLE_LENGTH = 80;
|
||||
|
@ -104,7 +105,7 @@ namespace GreenshotPlugin.Core {
|
|||
if (pattern == null || string.IsNullOrEmpty(pattern.Trim())) {
|
||||
pattern = "greenshot ${capturetime}";
|
||||
}
|
||||
return FilenameHelper.GetFilenameFromPattern(pattern, format, captureDetails);
|
||||
return GetFilenameFromPattern(pattern, format, captureDetails);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
WindowDetails tmpWD = browserWindowDetails;
|
||||
// Since IE 9 the TabBandClass is less deep!
|
||||
if (IEHelper.IEVersion() < 9) {
|
||||
if (IEVersion() < 9) {
|
||||
tmpWD = tmpWD.GetChild("CommandBarClass");
|
||||
if (tmpWD != null) {
|
||||
tmpWD = tmpWD.GetChild("ReBarWindow32");
|
||||
|
|
|
@ -29,6 +29,7 @@ using Greenshot.IniFile;
|
|||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
using Greenshot.Plugin;
|
||||
using Greenshot.Core;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
internal enum ExifOrientations : byte {
|
||||
|
@ -47,7 +48,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Description of ImageHelper.
|
||||
/// </summary>
|
||||
public static class ImageHelper {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImageHelper));
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(ImageHelper));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private const int EXIF_ORIENTATION_ID = 0x0112;
|
||||
|
||||
|
@ -143,7 +144,7 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
|
||||
Bitmap bmp = new Bitmap(thumbWidth, thumbHeight);
|
||||
using (Graphics graphics = System.Drawing.Graphics.FromImage(bmp)) {
|
||||
using (Graphics graphics = Graphics.FromImage(bmp)) {
|
||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||
|
@ -310,7 +311,7 @@ namespace GreenshotPlugin.Core {
|
|||
LOG.InfoFormat("Information about file {0}: {1}x{2}-{3} Resolution {4}x{5}", filename, fileImage.Width, fileImage.Height, fileImage.PixelFormat, fileImage.HorizontalResolution, fileImage.VerticalResolution);
|
||||
}
|
||||
// Make sure the orientation is set correctly so Greenshot can process the image correctly
|
||||
ImageHelper.Orientate(fileImage);
|
||||
Orientate(fileImage);
|
||||
return fileImage;
|
||||
}
|
||||
|
||||
|
@ -338,7 +339,7 @@ namespace GreenshotPlugin.Core {
|
|||
int iImageOffset = BitConverter.ToInt32(srcBuf, SizeICONDIR + SizeICONDIRENTRY * iIndex + 12);
|
||||
using (MemoryStream destStream = new MemoryStream()) {
|
||||
destStream.Write(srcBuf, iImageOffset, iImageSize);
|
||||
destStream.Seek(0, System.IO.SeekOrigin.Begin);
|
||||
destStream.Seek(0, SeekOrigin.Begin);
|
||||
bmpPngExtracted = new Bitmap(destStream); // This is PNG! :)
|
||||
}
|
||||
break;
|
||||
|
@ -857,7 +858,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="sourceImage">Bitmap to create a negative off</param>
|
||||
/// <returns>Negative bitmap</returns>
|
||||
public static Bitmap CreateNegative(Image sourceImage) {
|
||||
Bitmap clone = (Bitmap)ImageHelper.Clone(sourceImage);
|
||||
Bitmap clone = (Bitmap)Clone(sourceImage);
|
||||
ColorMatrix invertMatrix = new ColorMatrix(new float[][] {
|
||||
new float[] {-1, 0, 0, 0, 0},
|
||||
new float[] {0, -1, 0, 0, 0},
|
||||
|
@ -1036,7 +1037,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="sourceImage">Original bitmap</param>
|
||||
/// <returns>Bitmap with grayscale</returns>
|
||||
public static Image CreateGrayscale(Image sourceImage) {
|
||||
Bitmap clone = (Bitmap)ImageHelper.Clone(sourceImage);
|
||||
Bitmap clone = (Bitmap)Clone(sourceImage);
|
||||
ColorMatrix grayscaleMatrix = new ColorMatrix( new float[][] {
|
||||
new float[] {.3f, .3f, .3f, 0, 0},
|
||||
new float[] {.59f, .59f, .59f, 0, 0},
|
||||
|
@ -1334,22 +1335,22 @@ namespace GreenshotPlugin.Core {
|
|||
if (nPercentW == 1) {
|
||||
nPercentW = nPercentH;
|
||||
if (canvasUseNewSize) {
|
||||
destX = Math.Max(0, System.Convert.ToInt32((newWidth - (sourceImage.Width * nPercentW)) / 2));
|
||||
destX = Math.Max(0, Convert.ToInt32((newWidth - (sourceImage.Width * nPercentW)) / 2));
|
||||
}
|
||||
} else if (nPercentH == 1) {
|
||||
nPercentH = nPercentW;
|
||||
if (canvasUseNewSize) {
|
||||
destY = Math.Max(0, System.Convert.ToInt32((newHeight - (sourceImage.Height * nPercentH)) / 2));
|
||||
destY = Math.Max(0, Convert.ToInt32((newHeight - (sourceImage.Height * nPercentH)) / 2));
|
||||
}
|
||||
} else if (nPercentH != 0 && nPercentH < nPercentW) {
|
||||
nPercentW = nPercentH;
|
||||
if (canvasUseNewSize) {
|
||||
destX = Math.Max(0, System.Convert.ToInt32((newWidth - (sourceImage.Width * nPercentW)) / 2));
|
||||
destX = Math.Max(0, Convert.ToInt32((newWidth - (sourceImage.Width * nPercentW)) / 2));
|
||||
}
|
||||
} else {
|
||||
nPercentH = nPercentW;
|
||||
if (canvasUseNewSize) {
|
||||
destY = Math.Max(0, System.Convert.ToInt32((newHeight - (sourceImage.Height * nPercentH)) / 2));
|
||||
destY = Math.Max(0, Convert.ToInt32((newHeight - (sourceImage.Height * nPercentH)) / 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,29 +18,32 @@
|
|||
* 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 Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.Controls;
|
||||
using log4net;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.Controls;
|
||||
using Greenshot.Core;
|
||||
using System.Diagnostics;
|
||||
using System.Security.AccessControl;
|
||||
using Encoder = System.Drawing.Imaging.Encoder;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
/// Description of ImageOutput.
|
||||
/// </summary>
|
||||
public static class ImageOutput {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImageOutput));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(ImageOutput));
|
||||
private static readonly CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static readonly int PROPERTY_TAG_SOFTWARE_USED = 0x0131;
|
||||
private static Cache<string, string> tmpFileCache = new Cache<string, string>(10 * 60 * 60, new Cache<string, string>.CacheObjectExpired(RemoveExpiredTmpFile));
|
||||
private static Cache<string, string> tmpFileCache = new Cache<string, string>(10 * 60 * 60, RemoveExpiredTmpFile);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a PropertyItem (Metadata) to store with the image.
|
||||
|
@ -60,7 +63,7 @@ namespace GreenshotPlugin.Core {
|
|||
// Set the ID
|
||||
propertyItem.Id = id;
|
||||
// Set the text
|
||||
byte[] byteString = System.Text.ASCIIEncoding.ASCII.GetBytes(text + " ");
|
||||
byte[] byteString = Encoding.ASCII.GetBytes(text + " ");
|
||||
// Set Zero byte for String end.
|
||||
byteString[byteString.Length - 1] = 0;
|
||||
propertyItem.Value = byteString;
|
||||
|
@ -78,7 +81,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="stream">Stream to save to</param>
|
||||
/// <param name="outputSettings">SurfaceOutputSettings</param>
|
||||
public static void SaveToStream(ISurface surface, Stream stream, SurfaceOutputSettings outputSettings) {
|
||||
Image imageToSave = null;
|
||||
Image imageToSave;
|
||||
bool disposeImage = CreateImageFromSurface(surface, outputSettings, out imageToSave);
|
||||
SaveToStream(imageToSave, surface, stream, outputSettings);
|
||||
// cleanup if needed
|
||||
|
@ -97,7 +100,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="stream">Stream to save to</param>
|
||||
/// <param name="outputSettings">SurfaceOutputSettings</param>
|
||||
public static void SaveToStream(Image imageToSave, ISurface surface, Stream stream, SurfaceOutputSettings outputSettings) {
|
||||
ImageFormat imageFormat = null;
|
||||
ImageFormat imageFormat;
|
||||
bool useMemoryStream = false;
|
||||
MemoryStream memoryStream = null;
|
||||
if (outputSettings.Format == OutputFormat.greenshot && surface == null) {
|
||||
|
@ -118,8 +121,6 @@ namespace GreenshotPlugin.Core {
|
|||
case OutputFormat.tiff:
|
||||
imageFormat = ImageFormat.Tiff;
|
||||
break;
|
||||
case OutputFormat.greenshot:
|
||||
case OutputFormat.png:
|
||||
default:
|
||||
// Problem with non-seekable streams most likely doesn't happen with Windows 7 (OS Version 6.1 and later)
|
||||
// http://stackoverflow.com/questions/8349260/generic-gdi-error-on-one-machine-but-not-the-other
|
||||
|
@ -144,7 +145,7 @@ namespace GreenshotPlugin.Core {
|
|||
targetStream = memoryStream;
|
||||
}
|
||||
|
||||
if (imageFormat == ImageFormat.Jpeg) {
|
||||
if (Equals(imageFormat, ImageFormat.Jpeg)) {
|
||||
bool foundEncoder = false;
|
||||
foreach (ImageCodecInfo imageCodec in ImageCodecInfo.GetImageEncoders()) {
|
||||
if (imageCodec.FormatID == imageFormat.Guid) {
|
||||
|
@ -171,14 +172,14 @@ namespace GreenshotPlugin.Core {
|
|||
} else {
|
||||
bool needsDispose = false;
|
||||
// Removing transparency if it's not supported in the output
|
||||
if (imageFormat != ImageFormat.Png && Image.IsAlphaPixelFormat(imageToSave.PixelFormat)) {
|
||||
if (!Equals(imageFormat, ImageFormat.Png) && Image.IsAlphaPixelFormat(imageToSave.PixelFormat)) {
|
||||
imageToSave = ImageHelper.Clone(imageToSave, PixelFormat.Format24bppRgb);
|
||||
needsDispose = true;
|
||||
}
|
||||
AddTag(imageToSave);
|
||||
// Added for OptiPNG
|
||||
bool processed = false;
|
||||
if (imageFormat == ImageFormat.Png && !string.IsNullOrEmpty(conf.OptimizePNGCommand)) {
|
||||
if (Equals(imageFormat, ImageFormat.Png) && !string.IsNullOrEmpty(conf.OptimizePNGCommand)) {
|
||||
processed = ProcessPNGImageExternally(imageToSave, targetStream);
|
||||
}
|
||||
if (!processed) {
|
||||
|
@ -202,7 +203,7 @@ namespace GreenshotPlugin.Core {
|
|||
using (BinaryWriter writer = new BinaryWriter(tmpStream)) {
|
||||
writer.Write(bytesWritten);
|
||||
Version v = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
byte[] marker = System.Text.Encoding.ASCII.GetBytes(String.Format("Greenshot{0:00}.{1:00}", v.Major, v.Minor));
|
||||
byte[] marker = Encoding.ASCII.GetBytes(String.Format("Greenshot{0:00}.{1:00}", v.Major, v.Minor));
|
||||
writer.Write(marker);
|
||||
tmpStream.WriteTo(stream);
|
||||
}
|
||||
|
@ -249,19 +250,21 @@ namespace GreenshotPlugin.Core {
|
|||
processStartInfo.RedirectStandardError = true;
|
||||
processStartInfo.UseShellExecute = false;
|
||||
Process process = Process.Start(processStartInfo);
|
||||
process.WaitForExit();
|
||||
if (process.ExitCode == 0) {
|
||||
if (LOG.IsDebugEnabled) {
|
||||
LOG.DebugFormat("File size after processing {0}", new FileInfo(tmpFileName).Length);
|
||||
LOG.DebugFormat("Reading back tmp file: {0}", tmpFileName);
|
||||
if (process != null) {
|
||||
process.WaitForExit();
|
||||
if (process.ExitCode == 0) {
|
||||
if (LOG.IsDebugEnabled) {
|
||||
LOG.DebugFormat("File size after processing {0}", new FileInfo(tmpFileName).Length);
|
||||
LOG.DebugFormat("Reading back tmp file: {0}", tmpFileName);
|
||||
}
|
||||
byte[] processedImage = File.ReadAllBytes(tmpFileName);
|
||||
targetStream.Write(processedImage, 0, processedImage.Length);
|
||||
return true;
|
||||
}
|
||||
byte[] processedImage = File.ReadAllBytes(tmpFileName);
|
||||
targetStream.Write(processedImage, 0, processedImage.Length);
|
||||
return true;
|
||||
LOG.ErrorFormat("Error while processing PNG image: {0}", process.ExitCode);
|
||||
LOG.ErrorFormat("Output: {0}", process.StandardOutput.ReadToEnd());
|
||||
LOG.ErrorFormat("Error: {0}", process.StandardError.ReadToEnd());
|
||||
}
|
||||
LOG.ErrorFormat("Error while processing PNG image: {0}", process.ExitCode);
|
||||
LOG.ErrorFormat("Output: {0}", process.StandardOutput.ReadToEnd());
|
||||
LOG.ErrorFormat("Error: {0}", process.StandardError.ReadToEnd());
|
||||
} catch (Exception e) {
|
||||
LOG.Error("Error while processing PNG image: ", e);
|
||||
} finally {
|
||||
|
@ -282,26 +285,6 @@ namespace GreenshotPlugin.Core {
|
|||
/// <returns>true if the image must be disposed</returns>
|
||||
public static bool CreateImageFromSurface(ISurface surface, SurfaceOutputSettings outputSettings, out Image imageToSave) {
|
||||
bool disposeImage = false;
|
||||
ImageFormat imageFormat = null;
|
||||
switch (outputSettings.Format) {
|
||||
case OutputFormat.bmp:
|
||||
imageFormat = ImageFormat.Bmp;
|
||||
break;
|
||||
case OutputFormat.gif:
|
||||
imageFormat = ImageFormat.Gif;
|
||||
break;
|
||||
case OutputFormat.jpg:
|
||||
imageFormat = ImageFormat.Jpeg;
|
||||
break;
|
||||
case OutputFormat.tiff:
|
||||
imageFormat = ImageFormat.Tiff;
|
||||
break;
|
||||
case OutputFormat.greenshot:
|
||||
case OutputFormat.png:
|
||||
default:
|
||||
imageFormat = ImageFormat.Png;
|
||||
break;
|
||||
}
|
||||
|
||||
if (outputSettings.Format == OutputFormat.greenshot || outputSettings.SaveBackgroundOnly) {
|
||||
// We save the image of the surface, this should not be disposed
|
||||
|
@ -313,47 +296,50 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
|
||||
// The following block of modifications should be skipped when saving the greenshot format, no effects or otherwise!
|
||||
if (outputSettings.Format != OutputFormat.greenshot) {
|
||||
Image tmpImage;
|
||||
if (outputSettings.Effects != null && outputSettings.Effects.Count > 0) {
|
||||
// apply effects, if there are any
|
||||
Point ignoreOffset;
|
||||
tmpImage = ImageHelper.ApplyEffects((Bitmap)imageToSave, outputSettings.Effects, out ignoreOffset);
|
||||
if (tmpImage != null) {
|
||||
if (outputSettings.Format == OutputFormat.greenshot) {
|
||||
return disposeImage;
|
||||
}
|
||||
Image tmpImage;
|
||||
if (outputSettings.Effects != null && outputSettings.Effects.Count > 0) {
|
||||
// apply effects, if there are any
|
||||
Point ignoreOffset;
|
||||
tmpImage = ImageHelper.ApplyEffects(imageToSave, outputSettings.Effects, out ignoreOffset);
|
||||
if (tmpImage != null) {
|
||||
if (disposeImage) {
|
||||
imageToSave.Dispose();
|
||||
}
|
||||
imageToSave = tmpImage;
|
||||
disposeImage = true;
|
||||
}
|
||||
}
|
||||
|
||||
// check for color reduction, forced or automatically, only when the DisableReduceColors is false
|
||||
if (outputSettings.DisableReduceColors || (!conf.OutputFileAutoReduceColors && !outputSettings.ReduceColors)) {
|
||||
return disposeImage;
|
||||
}
|
||||
bool isAlpha = Image.IsAlphaPixelFormat(imageToSave.PixelFormat);
|
||||
if (outputSettings.ReduceColors || (!isAlpha && conf.OutputFileAutoReduceColors)) {
|
||||
using (var quantizer = new WuQuantizer((Bitmap)imageToSave)) {
|
||||
int colorCount = quantizer.GetColorCount();
|
||||
LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount);
|
||||
if (!outputSettings.ReduceColors && colorCount >= 256) {
|
||||
return disposeImage;
|
||||
}
|
||||
try {
|
||||
LOG.Info("Reducing colors on bitmap to 256.");
|
||||
tmpImage = quantizer.GetQuantizedImage(conf.OutputFileReduceColorsTo);
|
||||
if (disposeImage) {
|
||||
imageToSave.Dispose();
|
||||
}
|
||||
imageToSave = tmpImage;
|
||||
// Make sure the "new" image is disposed
|
||||
disposeImage = true;
|
||||
} catch (Exception e) {
|
||||
LOG.Warn("Error occurred while Quantizing the image, ignoring and using original. Error: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
// check for color reduction, forced or automatically, only when the DisableReduceColors is false
|
||||
if (!outputSettings.DisableReduceColors && (conf.OutputFileAutoReduceColors || outputSettings.ReduceColors)) {
|
||||
bool isAlpha = Image.IsAlphaPixelFormat(imageToSave.PixelFormat);
|
||||
if (outputSettings.ReduceColors || (!isAlpha && conf.OutputFileAutoReduceColors)) {
|
||||
using (WuQuantizer quantizer = new WuQuantizer((Bitmap)imageToSave)) {
|
||||
int colorCount = quantizer.GetColorCount();
|
||||
LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount);
|
||||
if (outputSettings.ReduceColors || colorCount < 256) {
|
||||
try {
|
||||
LOG.Info("Reducing colors on bitmap to 256.");
|
||||
tmpImage = quantizer.GetQuantizedImage(256);
|
||||
if (disposeImage) {
|
||||
imageToSave.Dispose();
|
||||
}
|
||||
imageToSave = tmpImage;
|
||||
// Make sure the "new" image is disposed
|
||||
disposeImage = true;
|
||||
} catch (Exception e) {
|
||||
LOG.Warn("Error occurred while Quantizing the image, ignoring and using original. Error: ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (isAlpha && !outputSettings.ReduceColors) {
|
||||
LOG.Info("Skipping 'optional' color reduction as the image has alpha");
|
||||
}
|
||||
}
|
||||
} else if (isAlpha && !outputSettings.ReduceColors) {
|
||||
LOG.Info("Skipping 'optional' color reduction as the image has alpha");
|
||||
}
|
||||
return disposeImage;
|
||||
}
|
||||
|
@ -378,12 +364,13 @@ namespace GreenshotPlugin.Core {
|
|||
/// Load a Greenshot surface
|
||||
/// </summary>
|
||||
/// <param name="fullPath"></param>
|
||||
/// <param name="returnSurface"></param>
|
||||
/// <returns></returns>
|
||||
public static ISurface LoadGreenshotSurface(string fullPath, ISurface returnSurface) {
|
||||
if (string.IsNullOrEmpty(fullPath)) {
|
||||
return null;
|
||||
}
|
||||
Image fileImage = null;
|
||||
Image fileImage;
|
||||
LOG.InfoFormat("Loading image from file {0}", fullPath);
|
||||
// Fixed lock problem Bug #3431881
|
||||
using (Stream surfaceFileStream = File.OpenRead(fullPath)) {
|
||||
|
@ -402,15 +389,14 @@ namespace GreenshotPlugin.Core {
|
|||
string greenshotMarker;
|
||||
using (StreamReader streamReader = new StreamReader(surfaceFileStream)) {
|
||||
greenshotMarker = streamReader.ReadToEnd();
|
||||
if (greenshotMarker == null || !greenshotMarker.StartsWith("Greenshot")) {
|
||||
if (!greenshotMarker.StartsWith("Greenshot")) {
|
||||
throw new ArgumentException(string.Format("{0} is not a Greenshot file!", fullPath));
|
||||
}
|
||||
LOG.InfoFormat("Greenshot file format: {0}", greenshotMarker);
|
||||
const int filesizeLocation = 8 + markerSize;
|
||||
surfaceFileStream.Seek(-filesizeLocation, SeekOrigin.End);
|
||||
long bytesWritten = 0;
|
||||
using (BinaryReader reader = new BinaryReader(surfaceFileStream)) {
|
||||
bytesWritten = reader.ReadInt64();
|
||||
long bytesWritten = reader.ReadInt64();
|
||||
surfaceFileStream.Seek(-(bytesWritten + filesizeLocation), SeekOrigin.End);
|
||||
returnSurface.LoadElementsFromStream(surfaceFileStream);
|
||||
}
|
||||
|
@ -431,9 +417,11 @@ namespace GreenshotPlugin.Core {
|
|||
string path = Path.GetDirectoryName(fullPath);
|
||||
|
||||
// check whether path exists - if not create it
|
||||
DirectoryInfo di = new DirectoryInfo(path);
|
||||
if (!di.Exists) {
|
||||
Directory.CreateDirectory(di.FullName);
|
||||
if (path != null) {
|
||||
DirectoryInfo di = new DirectoryInfo(path);
|
||||
if (!di.Exists) {
|
||||
Directory.CreateDirectory(di.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
if (!allowOverwrite && File.Exists(fullPath)) {
|
||||
|
@ -462,9 +450,7 @@ namespace GreenshotPlugin.Core {
|
|||
string extension = fullPath.Substring(fullPath.LastIndexOf(".") + 1);
|
||||
OutputFormat format = OutputFormat.png;
|
||||
try {
|
||||
if (extension != null) {
|
||||
format = (OutputFormat)Enum.Parse(typeof(OutputFormat), extension.ToLower());
|
||||
}
|
||||
format = (OutputFormat)Enum.Parse(typeof(OutputFormat), extension.ToLower());
|
||||
} catch (ArgumentException ae) {
|
||||
LOG.Warn("Couldn't parse extension: " + extension, ae);
|
||||
}
|
||||
|
@ -493,10 +479,10 @@ namespace GreenshotPlugin.Core {
|
|||
qualityDialog.ShowDialog();
|
||||
}
|
||||
// TODO: For now we always overwrite, should be changed
|
||||
ImageOutput.Save(surface, fileNameWithExtension, true, outputSettings, conf.OutputFileCopyPathToClipboard);
|
||||
Save(surface, fileNameWithExtension, true, outputSettings, conf.OutputFileCopyPathToClipboard);
|
||||
returnValue = fileNameWithExtension;
|
||||
IniConfig.Save();
|
||||
} catch (System.Runtime.InteropServices.ExternalException) {
|
||||
} catch (ExternalException) {
|
||||
MessageBox.Show(Language.GetFormattedString("error_nowriteaccess", saveImageFileDialog.FileName).Replace(@"\\", @"\"), Language.GetString("error"));
|
||||
}
|
||||
}
|
||||
|
@ -530,13 +516,13 @@ namespace GreenshotPlugin.Core {
|
|||
// Catching any exception to prevent that the user can't write in the directory.
|
||||
// This is done for e.g. bugs #2974608, #2963943, #2816163, #2795317, #2789218
|
||||
try {
|
||||
ImageOutput.Save(surface, tmpFile, true, outputSettings, false);
|
||||
Save(surface, tmpFile, true, outputSettings, false);
|
||||
tmpFileCache.Add(tmpFile, tmpFile);
|
||||
} catch (Exception e) {
|
||||
// Show the problem
|
||||
MessageBox.Show(e.Message, "Error");
|
||||
// when save failed we present a SaveWithDialog
|
||||
tmpFile = ImageOutput.SaveWithDialog(surface, captureDetails);
|
||||
tmpFile = SaveWithDialog(surface, captureDetails);
|
||||
}
|
||||
return tmpFile;
|
||||
}
|
||||
|
@ -555,7 +541,8 @@ namespace GreenshotPlugin.Core {
|
|||
tmpFileCache.Remove(tmpfile);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception) {
|
||||
} catch (Exception ex) {
|
||||
LOG.Warn("Error deleting tmp file: ", ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -563,7 +550,9 @@ namespace GreenshotPlugin.Core {
|
|||
/// <summary>
|
||||
/// Helper method to create a temp image file
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
/// <param name="surface"></param>
|
||||
/// <param name="outputSettings"></param>
|
||||
/// <param name="destinationPath"></param>
|
||||
/// <returns></returns>
|
||||
public static string SaveToTmpFile(ISurface surface, SurfaceOutputSettings outputSettings, string destinationPath) {
|
||||
string tmpFile = Path.GetRandomFileName() + "." + outputSettings.Format.ToString();
|
||||
|
@ -576,7 +565,7 @@ namespace GreenshotPlugin.Core {
|
|||
LOG.Debug("Creating TMP File : " + tmpPath);
|
||||
|
||||
try {
|
||||
ImageOutput.Save(surface, tmpPath, true, outputSettings, false);
|
||||
Save(surface, tmpPath, true, outputSettings, false);
|
||||
tmpFileCache.Add(tmpPath, tmpPath);
|
||||
} catch (Exception) {
|
||||
return null;
|
||||
|
@ -600,8 +589,8 @@ namespace GreenshotPlugin.Core {
|
|||
/// <summary>
|
||||
/// Cleanup handler for expired tempfiles
|
||||
/// </summary>
|
||||
/// <param name="filekey"></param>
|
||||
/// <param name="filename"></param>
|
||||
/// <param name="alsoTheFilename"></param>
|
||||
private static void RemoveExpiredTmpFile(string filekey, object filename) {
|
||||
string path = filename as string;
|
||||
if (path != null && File.Exists(path)) {
|
||||
|
|
|
@ -23,13 +23,14 @@ using System.Collections.Generic;
|
|||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Greenshot.Plugin;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
/// Description of InterfaceUtils.
|
||||
/// </summary>
|
||||
public static class InterfaceUtils {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(InterfaceUtils));
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(InterfaceUtils));
|
||||
|
||||
public static List<Type> GetSubclassesOf(Type type, bool excludeSystemTypes) {
|
||||
List<Type> list = new List<Type>();
|
||||
|
|
|
@ -25,6 +25,7 @@ using System.Reflection;
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
using Greenshot.IniFile;
|
||||
using log4net;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
|
@ -34,7 +35,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// The language resources are loaded from the language files found on fixed or supplied paths
|
||||
/// </summary>
|
||||
public class Language {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(Language));
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(Language));
|
||||
private static List<string> languagePaths = new List<string>();
|
||||
private static IDictionary<string, List<LanguageFile>> languageFiles = new Dictionary<string, List<LanguageFile>>();
|
||||
private static IDictionary<string, string> helpFiles = new Dictionary<string, string>();
|
||||
|
@ -534,8 +535,8 @@ namespace GreenshotPlugin.Core {
|
|||
public static string Translate(object key) {
|
||||
string typename = key.GetType().Name;
|
||||
string enumKey = typename + "." + key.ToString();
|
||||
if (Language.hasKey(enumKey)) {
|
||||
return Language.GetString(enumKey);
|
||||
if (hasKey(enumKey)) {
|
||||
return GetString(enumKey);
|
||||
}
|
||||
return key.ToString();
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ using log4net.Appender;
|
|||
using log4net.Config;
|
||||
using log4net.Repository.Hierarchy;
|
||||
using System;
|
||||
using log4net.Util;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
|
@ -98,8 +99,8 @@ namespace GreenshotPlugin.Core {
|
|||
/// <summary>
|
||||
/// A simple helper class to support the logging to the AppData location
|
||||
/// </summary>
|
||||
public class SpecialFolderPatternConverter : log4net.Util.PatternConverter {
|
||||
override protected void Convert(System.IO.TextWriter writer, object state) {
|
||||
public class SpecialFolderPatternConverter : PatternConverter {
|
||||
override protected void Convert(TextWriter writer, object state) {
|
||||
Environment.SpecialFolder specialFolder = (Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder), base.Option, true);
|
||||
writer.Write(Environment.GetFolderPath(specialFolder));
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
|
@ -29,18 +30,19 @@ using System.Text;
|
|||
using System.Text.RegularExpressions;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
/// Description of NetworkHelper.
|
||||
/// </summary>
|
||||
public static class NetworkHelper {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(NetworkHelper));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(NetworkHelper));
|
||||
private static CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
static NetworkHelper() {
|
||||
// Disable certificate checking
|
||||
System.Net.ServicePointManager.ServerCertificateValidationCallback +=
|
||||
ServicePointManager.ServerCertificateValidationCallback +=
|
||||
delegate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslError) {
|
||||
bool validationResult = true;
|
||||
return validationResult;
|
||||
|
@ -52,10 +54,10 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name=url">An Uri to specify the download location</param>
|
||||
/// <returns>string with the file content</returns>
|
||||
public static string GetAsString(Uri url) {
|
||||
HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
|
||||
HttpWebRequest webRequest = (HttpWebRequest)CreateWebRequest(url);
|
||||
webRequest.Method = "GET";
|
||||
webRequest.KeepAlive = true;
|
||||
webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
|
||||
webRequest.Credentials = CredentialCache.DefaultCredentials;
|
||||
return GetResponse(webRequest);
|
||||
}
|
||||
|
||||
|
@ -67,7 +69,7 @@ namespace GreenshotPlugin.Core {
|
|||
public static Bitmap DownloadFavIcon(Uri baseUri) {
|
||||
Uri url = new Uri(baseUri, new Uri("favicon.ico"));
|
||||
try {
|
||||
HttpWebRequest request = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
|
||||
HttpWebRequest request = (HttpWebRequest)CreateWebRequest(url);
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
if (request.HaveResponse) {
|
||||
using (Image image = Image.FromStream(response.GetResponseStream())) {
|
||||
|
@ -88,7 +90,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <returns>Bitmap</returns>
|
||||
public static Image DownloadImage(string url) {
|
||||
try {
|
||||
HttpWebRequest request = (HttpWebRequest)NetworkHelper.CreateWebRequest(url);
|
||||
HttpWebRequest request = (HttpWebRequest)CreateWebRequest(url);
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
if (request.HaveResponse) {
|
||||
using (Image image = Image.FromStream(response.GetResponseStream())) {
|
||||
|
@ -118,7 +120,7 @@ namespace GreenshotPlugin.Core {
|
|||
public static WebRequest CreateWebRequest(Uri uri) {
|
||||
WebRequest webRequest = WebRequest.Create(uri);
|
||||
if (config.UseProxy) {
|
||||
webRequest.Proxy = GreenshotPlugin.Core.NetworkHelper.CreateProxy(uri);
|
||||
webRequest.Proxy = CreateProxy(uri);
|
||||
//webRequest.Proxy.Credentials = CredentialCache.DefaultCredentials;
|
||||
}
|
||||
return webRequest;
|
||||
|
@ -166,7 +168,7 @@ namespace GreenshotPlugin.Core {
|
|||
public static string UrlEncode(string text) {
|
||||
if (!string.IsNullOrEmpty(text)) {
|
||||
// Sytem.Uri provides reliable parsing, but doesn't encode spaces.
|
||||
return System.Uri.EscapeDataString(text).Replace("%20", "+");
|
||||
return Uri.EscapeDataString(text).Replace("%20", "+");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -200,7 +202,7 @@ namespace GreenshotPlugin.Core {
|
|||
// pre-process for + sign space formatting since System.Uri doesn't handle it
|
||||
// plus literals are encoded as %2b normally so this should be safe
|
||||
text = text.Replace("+", " ");
|
||||
return System.Uri.UnescapeDataString(text);
|
||||
return Uri.UnescapeDataString(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -246,7 +248,7 @@ namespace GreenshotPlugin.Core {
|
|||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach(string key in queryParameters.Keys) {
|
||||
sb.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0}={1}&", key, UrlEncode(string.Format("{0}",queryParameters[key])));
|
||||
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}={1}&", key, UrlEncode(string.Format("{0}",queryParameters[key])));
|
||||
}
|
||||
sb.Remove(sb.Length-1,1);
|
||||
|
||||
|
@ -363,12 +365,12 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
public ByteContainer(byte[] file, string filename, string contenttype, int filesize) {
|
||||
this.file = file;
|
||||
this.fileName = filename;
|
||||
this.contentType = contenttype;
|
||||
fileName = filename;
|
||||
contentType = contenttype;
|
||||
if (filesize == 0) {
|
||||
this.fileSize = file.Length;
|
||||
fileSize = file.Length;
|
||||
} else {
|
||||
this.fileSize = filesize;
|
||||
fileSize = filesize;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -377,7 +379,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
/// <returns>string</returns>
|
||||
public string ToBase64String(Base64FormattingOptions formattingOptions) {
|
||||
return System.Convert.ToBase64String(file, 0, fileSize, formattingOptions);
|
||||
return Convert.ToBase64String(file, 0, fileSize, formattingOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -440,7 +442,7 @@ namespace GreenshotPlugin.Core {
|
|||
public BitmapContainer(Bitmap bitmap, SurfaceOutputSettings outputSettings, string filename) {
|
||||
this.bitmap = bitmap;
|
||||
this.outputSettings = outputSettings;
|
||||
this.fileName = filename;
|
||||
fileName = filename;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -451,7 +453,7 @@ namespace GreenshotPlugin.Core {
|
|||
public string ToBase64String(Base64FormattingOptions formattingOptions) {
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
ImageOutput.SaveToStream(bitmap, null, stream, outputSettings);
|
||||
return System.Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length, formattingOptions);
|
||||
return Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length, formattingOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -516,7 +518,7 @@ namespace GreenshotPlugin.Core {
|
|||
public SurfaceContainer(ISurface surface, SurfaceOutputSettings outputSettings, string filename) {
|
||||
this.surface = surface;
|
||||
this.outputSettings = outputSettings;
|
||||
this.fileName = filename;
|
||||
fileName = filename;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -527,7 +529,7 @@ namespace GreenshotPlugin.Core {
|
|||
public string ToBase64String(Base64FormattingOptions formattingOptions) {
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
ImageOutput.SaveToStream(surface, stream, outputSettings);
|
||||
return System.Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length, formattingOptions);
|
||||
return Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length, formattingOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,11 +21,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using GreenshotPlugin.Controls;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
|
@ -40,7 +43,7 @@ namespace GreenshotPlugin.Core {
|
|||
public enum HTTPMethod { GET, POST, PUT, DELETE };
|
||||
|
||||
public class OAuthSession {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OAuthSession));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(OAuthSession));
|
||||
protected const string OAUTH_VERSION = "1.0";
|
||||
protected const string OAUTH_PARAMETER_PREFIX = "oauth_";
|
||||
|
||||
|
@ -207,11 +210,11 @@ namespace GreenshotPlugin.Core {
|
|||
public OAuthSession(string consumerKey, string consumerSecret) {
|
||||
this.consumerKey = consumerKey;
|
||||
this.consumerSecret = consumerSecret;
|
||||
this.UseMultipartFormData = true;
|
||||
this.RequestTokenMethod = HTTPMethod.GET;
|
||||
this.AccessTokenMethod = HTTPMethod.GET;
|
||||
this.SignatureType = OAuthSignatureTypes.HMACSHA1;
|
||||
this.AutoLogin = true;
|
||||
UseMultipartFormData = true;
|
||||
RequestTokenMethod = HTTPMethod.GET;
|
||||
AccessTokenMethod = HTTPMethod.GET;
|
||||
SignatureType = OAuthSignatureTypes.HMACSHA1;
|
||||
AutoLogin = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -250,7 +253,7 @@ namespace GreenshotPlugin.Core {
|
|||
StringBuilder sb = new StringBuilder();
|
||||
foreach (string key in queryParameters.Keys) {
|
||||
if (queryParameters[key] is string) {
|
||||
sb.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0}={1}&", key, UrlEncode3986(string.Format("{0}",queryParameters[key])));
|
||||
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}={1}&", key, UrlEncode3986(string.Format("{0}",queryParameters[key])));
|
||||
}
|
||||
}
|
||||
sb.Remove(sb.Length - 1, 1);
|
||||
|
@ -318,9 +321,9 @@ namespace GreenshotPlugin.Core {
|
|||
LOG.DebugFormat("Request token response: {0}", response);
|
||||
requestTokenResponseParameters = NetworkHelper.ParseQueryString(response);
|
||||
if (requestTokenResponseParameters.ContainsKey(OAUTH_TOKEN_KEY)) {
|
||||
this.Token = requestTokenResponseParameters[OAUTH_TOKEN_KEY];
|
||||
this.TokenSecret = requestTokenResponseParameters[OAUTH_TOKEN_SECRET_KEY];
|
||||
ret = this.Token;
|
||||
Token = requestTokenResponseParameters[OAUTH_TOKEN_KEY];
|
||||
TokenSecret = requestTokenResponseParameters[OAUTH_TOKEN_SECRET_KEY];
|
||||
ret = Token;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -377,10 +380,10 @@ namespace GreenshotPlugin.Core {
|
|||
LOG.DebugFormat("Access token response: {0}", response);
|
||||
accessTokenResponseParameters = NetworkHelper.ParseQueryString(response);
|
||||
if (accessTokenResponseParameters.ContainsKey(OAUTH_TOKEN_KEY) && accessTokenResponseParameters[OAUTH_TOKEN_KEY] != null) {
|
||||
this.Token = accessTokenResponseParameters[OAUTH_TOKEN_KEY];
|
||||
Token = accessTokenResponseParameters[OAUTH_TOKEN_KEY];
|
||||
}
|
||||
if (accessTokenResponseParameters.ContainsKey(OAUTH_TOKEN_SECRET_KEY) && accessTokenResponseParameters[OAUTH_TOKEN_SECRET_KEY] != null) {
|
||||
this.TokenSecret = accessTokenResponseParameters[OAUTH_TOKEN_SECRET_KEY];
|
||||
TokenSecret = accessTokenResponseParameters[OAUTH_TOKEN_SECRET_KEY];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -392,9 +395,9 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
/// <returns>true if the process is completed</returns>
|
||||
public bool Authorize() {
|
||||
this.Token = null;
|
||||
this.TokenSecret = null;
|
||||
this.Verifier = null;
|
||||
Token = null;
|
||||
TokenSecret = null;
|
||||
Verifier = null;
|
||||
LOG.Debug("Creating Token");
|
||||
try {
|
||||
getRequestToken();
|
||||
|
@ -407,7 +410,7 @@ namespace GreenshotPlugin.Core {
|
|||
return false;
|
||||
}
|
||||
try {
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
Thread.Sleep(1000);
|
||||
return getAccessToken() != null;
|
||||
} catch (Exception ex) {
|
||||
LOG.Error(ex);
|
||||
|
@ -421,7 +424,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <returns>The url with a valid request token, or a null string.</returns>
|
||||
private string authorizationLink {
|
||||
get {
|
||||
return AuthorizeUrl + "?" + OAUTH_TOKEN_KEY + "=" + this.Token + "&" + OAUTH_CALLBACK_KEY + "=" + UrlEncode3986(CallbackUrl);
|
||||
return AuthorizeUrl + "?" + OAUTH_TOKEN_KEY + "=" + Token + "&" + OAUTH_CALLBACK_KEY + "=" + UrlEncode3986(CallbackUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -552,7 +555,7 @@ namespace GreenshotPlugin.Core {
|
|||
|
||||
// Add normalized URL
|
||||
Uri url = new Uri(requestURL);
|
||||
string normalizedUrl = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}://{1}", url.Scheme, url.Host);
|
||||
string normalizedUrl = string.Format(CultureInfo.InvariantCulture, "{0}://{1}", url.Scheme, url.Host);
|
||||
if (!((url.Scheme == "http" && url.Port == 80) || (url.Scheme == "https" && url.Port == 443))) {
|
||||
normalizedUrl += ":" + url.Port;
|
||||
}
|
||||
|
@ -587,7 +590,7 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
signatureBase.Append(UrlEncode3986(GenerateNormalizedParametersString(parameters)));
|
||||
LOG.DebugFormat("Signature base: {0}", signatureBase);
|
||||
string key = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}&{1}", UrlEncode3986(consumerSecret), string.IsNullOrEmpty(TokenSecret) ? string.Empty : UrlEncode3986(TokenSecret));
|
||||
string key = string.Format(CultureInfo.InvariantCulture, "{0}&{1}", UrlEncode3986(consumerSecret), string.IsNullOrEmpty(TokenSecret) ? string.Empty : UrlEncode3986(TokenSecret));
|
||||
switch (SignatureType) {
|
||||
case OAuthSignatureTypes.RSASHA1:
|
||||
// Code comes from here: http://www.dotnetfunda.com/articles/article1932-rest-service-call-using-oauth-10-authorization-with-rsa-sha1.aspx
|
||||
|
@ -601,7 +604,7 @@ namespace GreenshotPlugin.Core {
|
|||
// Create a RSA-SHA1 Hash object
|
||||
using (SHA1Managed shaHASHObject = new SHA1Managed()) {
|
||||
// Create Byte Array of Signature base string
|
||||
byte[] data = System.Text.Encoding.ASCII.GetBytes(signatureBase.ToString());
|
||||
byte[] data = Encoding.ASCII.GetBytes(signatureBase.ToString());
|
||||
// Create Hashmap of Signature base string
|
||||
byte[] hash = shaHASHObject.ComputeHash(data);
|
||||
// Create Sign Hash of base string
|
||||
|
@ -649,7 +652,7 @@ namespace GreenshotPlugin.Core {
|
|||
requestParameters = new Dictionary<string, object>();
|
||||
foreach (string parameterKey in parameters.Keys) {
|
||||
if (parameterKey.StartsWith(OAUTH_PARAMETER_PREFIX)) {
|
||||
authHeader.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0}=\"{1}\", ", parameterKey, UrlEncode3986(string.Format("{0}",parameters[parameterKey])));
|
||||
authHeader.AppendFormat(CultureInfo.InvariantCulture, "{0}=\"{1}\", ", parameterKey, UrlEncode3986(string.Format("{0}",parameters[parameterKey])));
|
||||
} else if (!requestParameters.ContainsKey(parameterKey)) {
|
||||
requestParameters.Add(parameterKey, parameters[parameterKey]);
|
||||
}
|
||||
|
@ -694,9 +697,9 @@ namespace GreenshotPlugin.Core {
|
|||
foreach (string parameterKey in requestParameters.Keys) {
|
||||
if (parameters[parameterKey] is IBinaryContainer) {
|
||||
IBinaryContainer binaryParameter = parameters[parameterKey] as IBinaryContainer;
|
||||
form.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0}={1}&", UrlEncode3986(parameterKey), UrlEncode3986(binaryParameter.ToBase64String(Base64FormattingOptions.None)));
|
||||
form.AppendFormat(CultureInfo.InvariantCulture, "{0}={1}&", UrlEncode3986(parameterKey), UrlEncode3986(binaryParameter.ToBase64String(Base64FormattingOptions.None)));
|
||||
} else {
|
||||
form.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0}={1}&", UrlEncode3986(parameterKey), UrlEncode3986(string.Format("{0}",parameters[parameterKey])));
|
||||
form.AppendFormat(CultureInfo.InvariantCulture, "{0}={1}&", UrlEncode3986(parameterKey), UrlEncode3986(string.Format("{0}",parameters[parameterKey])));
|
||||
}
|
||||
}
|
||||
// Remove trailing &
|
||||
|
|
|
@ -23,6 +23,7 @@ using System.Drawing;
|
|||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using Greenshot.Plugin;
|
||||
using log4net;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
|
@ -30,7 +31,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Description of PluginUtils.
|
||||
/// </summary>
|
||||
public static class PluginUtils {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(PluginUtils));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(PluginUtils));
|
||||
private const string PATH_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\";
|
||||
|
||||
/// <summary>
|
||||
|
@ -96,8 +97,8 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="tag">The TAG value</param>
|
||||
/// <param name="shortcutKeys">Keys which can be used as shortcut</param>
|
||||
/// <param name="handler">The onclick handler</param>
|
||||
public static void AddToFileMenu(IImageEditor imageEditor, Image image, string text, object tag, Keys? shortcutKeys, System.EventHandler handler) {
|
||||
System.Windows.Forms.ToolStripMenuItem item = new System.Windows.Forms.ToolStripMenuItem();
|
||||
public static void AddToFileMenu(IImageEditor imageEditor, Image image, string text, object tag, Keys? shortcutKeys, EventHandler handler) {
|
||||
ToolStripMenuItem item = new ToolStripMenuItem();
|
||||
item.Image = image;
|
||||
item.Text = text;
|
||||
item.Tag = tag;
|
||||
|
|
|
@ -23,6 +23,7 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
internal class WuColorCube {
|
||||
|
@ -70,7 +71,7 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
|
||||
public class WuQuantizer : IDisposable {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WuQuantizer));
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(WuQuantizer));
|
||||
|
||||
private const Int32 MAXCOLOR = 512;
|
||||
private const Int32 RED = 2;
|
||||
|
|
|
@ -24,6 +24,7 @@ using System.Globalization;
|
|||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
public class SourceforgeFile {
|
||||
|
@ -94,7 +95,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Description of SourceForgeHelper.
|
||||
/// </summary>
|
||||
public class SourceForgeHelper {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SourceForgeHelper));
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(SourceForgeHelper));
|
||||
private const String RSSFEED = "http://getgreenshot.org/project-feed/";
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -28,6 +28,7 @@ using System.Windows.Forms;
|
|||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
|
@ -132,7 +133,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Having the Bitmap, eventually the Windows Title and cursor all together.
|
||||
/// </summary>
|
||||
public class Capture : IDisposable, ICapture {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(Capture));
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(Capture));
|
||||
private List<ICaptureElement> elements = new List<ICaptureElement>();
|
||||
|
||||
private Rectangle screenBounds;
|
||||
|
@ -165,7 +166,7 @@ namespace GreenshotPlugin.Core {
|
|||
LOG.Debug("Converting Bitmap to PixelFormat.Format32bppArgb as we don't support: " + value.PixelFormat);
|
||||
try {
|
||||
// Default Bitmap PixelFormat is Format32bppArgb
|
||||
this.image = new Bitmap(value);
|
||||
image = new Bitmap(value);
|
||||
} finally {
|
||||
// Always dispose, even when a exception occured
|
||||
value.Dispose();
|
||||
|
@ -246,7 +247,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
/// <param name="newImage">Image</param>
|
||||
public Capture(Image newImage) : this() {
|
||||
this.Image = newImage;
|
||||
Image = newImage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -425,7 +426,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// The Window Capture code
|
||||
/// </summary>
|
||||
public class WindowCapture {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WindowCapture));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(WindowCapture));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
|
@ -33,13 +34,14 @@ using Greenshot.IniFile;
|
|||
using Greenshot.Interop;
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
|
||||
/// <summary>
|
||||
/// Code for handling with "windows"
|
||||
/// Main code is taken from vbAccelerator, location:
|
||||
/// http://www.vbaccelerator.com/home/NET/Code/Libraries/Windows/Enumerating_Windows/article.asp
|
||||
/// but a LOT of changes/enhancements were made to adapt it for Greenshot.
|
||||
/// </summary>
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotPlugin.Core {
|
||||
#region EnumWindows
|
||||
/// <summary>
|
||||
|
@ -56,7 +58,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
public List<WindowDetails> Items {
|
||||
get {
|
||||
return this.items;
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,9 +89,9 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="hWndParent">Window Handle to get children for</param>
|
||||
/// <param name="classname">Window Classname to copy, use null to copy all</param>
|
||||
public WindowsEnumerator GetWindows(IntPtr hWndParent, string classname) {
|
||||
this.items = new List<WindowDetails>();
|
||||
items = new List<WindowDetails>();
|
||||
List<WindowDetails> windows = new List<WindowDetails>();
|
||||
User32.EnumChildWindows(hWndParent, new EnumWindowsProc(this.WindowEnum), 0);
|
||||
User32.EnumChildWindows(hWndParent, new EnumWindowsProc(WindowEnum), 0);
|
||||
|
||||
bool hasParent = !IntPtr.Zero.Equals(hWndParent);
|
||||
string parentText = null;
|
||||
|
@ -120,7 +122,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="lParam">Application defined value</param>
|
||||
/// <returns>1 to continue enumeration, 0 to stop</returns>
|
||||
private int WindowEnum(IntPtr hWnd, int lParam) {
|
||||
if (this.OnWindowEnum(hWnd)) {
|
||||
if (OnWindowEnum(hWnd)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
|
@ -159,13 +161,13 @@ namespace GreenshotPlugin.Core {
|
|||
/// Provides details about a Window returned by the
|
||||
/// enumeration
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1049:TypesThatOwnNativeResourcesShouldBeDisposable")]
|
||||
[SuppressMessage("Microsoft.Design", "CA1049:TypesThatOwnNativeResourcesShouldBeDisposable")]
|
||||
public class WindowDetails : IEquatable<WindowDetails>{
|
||||
private const string METRO_WINDOWS_CLASS = "Windows.UI.Core.CoreWindow";
|
||||
private const string METRO_APPLAUNCHER_CLASS = "ImmersiveLauncher";
|
||||
private const string METRO_GUTTER_CLASS = "ImmersiveGutter";
|
||||
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(WindowDetails));
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(WindowDetails));
|
||||
private static Dictionary<string, List<string>> classnameTree = new Dictionary<string, List<string>>();
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static List<IntPtr> ignoreHandles = new List<IntPtr>();
|
||||
|
@ -241,19 +243,19 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
|
||||
public override bool Equals(object right) {
|
||||
return this.Equals(right as WindowDetails);
|
||||
return Equals(right as WindowDetails);
|
||||
}
|
||||
|
||||
public bool Equals(WindowDetails other) {
|
||||
if (Object.ReferenceEquals(other, null)) {
|
||||
if (ReferenceEquals(other, null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Object.ReferenceEquals(this, other)) {
|
||||
if (ReferenceEquals(this, other)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.GetType() != other.GetType()){
|
||||
if (GetType() != other.GetType()){
|
||||
return false;
|
||||
}
|
||||
return other.Handle == Handle;
|
||||
|
@ -292,7 +294,7 @@ namespace GreenshotPlugin.Core {
|
|||
public Image DisplayIcon {
|
||||
get {
|
||||
try {
|
||||
using (Icon appIcon = GetAppIcon(this.Handle)) {
|
||||
using (Icon appIcon = GetAppIcon(Handle)) {
|
||||
if (appIcon != null) {
|
||||
return appIcon.ToBitmap();
|
||||
}
|
||||
|
@ -590,7 +592,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
public IntPtr Handle {
|
||||
get {
|
||||
return this.hWnd;
|
||||
return hWnd;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -605,7 +607,7 @@ namespace GreenshotPlugin.Core {
|
|||
get {
|
||||
if (text == null) {
|
||||
StringBuilder title = new StringBuilder(260, 260);
|
||||
User32.GetWindowText(this.hWnd, title, title.Capacity);
|
||||
User32.GetWindowText(hWnd, title, title.Capacity);
|
||||
text = title.ToString();
|
||||
}
|
||||
return text;
|
||||
|
@ -619,7 +621,7 @@ namespace GreenshotPlugin.Core {
|
|||
public string ClassName {
|
||||
get {
|
||||
if (className == null) {
|
||||
className = GetClassName(this.hWnd);
|
||||
className = GetClassName(hWnd);
|
||||
}
|
||||
return className;
|
||||
}
|
||||
|
@ -633,13 +635,13 @@ namespace GreenshotPlugin.Core {
|
|||
if (isMetroApp) {
|
||||
return !Visible;
|
||||
}
|
||||
return User32.IsIconic(this.hWnd) || Location.X <= -32000;
|
||||
return User32.IsIconic(hWnd) || Location.X <= -32000;
|
||||
}
|
||||
set {
|
||||
if (value) {
|
||||
User32.SendMessage(this.hWnd, (int)WindowsMessages.WM_SYSCOMMAND, (IntPtr)User32.SC_MINIMIZE, IntPtr.Zero);
|
||||
User32.SendMessage(hWnd, (int)WindowsMessages.WM_SYSCOMMAND, (IntPtr)User32.SC_MINIMIZE, IntPtr.Zero);
|
||||
} else {
|
||||
User32.SendMessage(this.hWnd, (int)WindowsMessages.WM_SYSCOMMAND, (IntPtr)User32.SC_RESTORE, IntPtr.Zero);
|
||||
User32.SendMessage(hWnd, (int)WindowsMessages.WM_SYSCOMMAND, (IntPtr)User32.SC_RESTORE, IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -662,13 +664,13 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
return User32.IsZoomed(this.hWnd);
|
||||
return User32.IsZoomed(hWnd);
|
||||
}
|
||||
set {
|
||||
if (value) {
|
||||
User32.SendMessage(this.hWnd, (int)WindowsMessages.WM_SYSCOMMAND, (IntPtr)User32.SC_MAXIMIZE, IntPtr.Zero);
|
||||
User32.SendMessage(hWnd, (int)WindowsMessages.WM_SYSCOMMAND, (IntPtr)User32.SC_MAXIMIZE, IntPtr.Zero);
|
||||
} else {
|
||||
User32.SendMessage(this.hWnd, (int)WindowsMessages.WM_SYSCOMMAND, (IntPtr)User32.SC_MINIMIZE, IntPtr.Zero);
|
||||
User32.SendMessage(hWnd, (int)WindowsMessages.WM_SYSCOMMAND, (IntPtr)User32.SC_MINIMIZE, IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -718,7 +720,7 @@ namespace GreenshotPlugin.Core {
|
|||
if (isAppLauncher) {
|
||||
return IsAppLauncherVisible;
|
||||
}
|
||||
return User32.IsWindowVisible(this.hWnd);
|
||||
return User32.IsWindowVisible(hWnd);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -846,10 +848,10 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
public void Restore() {
|
||||
if (Iconic) {
|
||||
User32.SendMessage(this.hWnd, (int)WindowsMessages.WM_SYSCOMMAND, (IntPtr)User32.SC_RESTORE, IntPtr.Zero);
|
||||
User32.SendMessage(hWnd, (int)WindowsMessages.WM_SYSCOMMAND, (IntPtr)User32.SC_RESTORE, IntPtr.Zero);
|
||||
}
|
||||
User32.BringWindowToTop(this.hWnd);
|
||||
User32.SetForegroundWindow(this.hWnd);
|
||||
User32.BringWindowToTop(hWnd);
|
||||
User32.SetForegroundWindow(hWnd);
|
||||
// Make sure windows has time to perform the action
|
||||
while(Iconic) {
|
||||
Application.DoEvents();
|
||||
|
@ -861,10 +863,10 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
public WindowStyleFlags WindowStyle {
|
||||
get {
|
||||
return (WindowStyleFlags)User32.GetWindowLongWrapper(this.hWnd, (int)WindowLongIndex.GWL_STYLE);
|
||||
return (WindowStyleFlags)User32.GetWindowLongWrapper(hWnd, (int)WindowLongIndex.GWL_STYLE);
|
||||
}
|
||||
set {
|
||||
User32.SetWindowLongWrapper(this.hWnd, (int)WindowLongIndex.GWL_STYLE, (uint)value);
|
||||
User32.SetWindowLongWrapper(hWnd, (int)WindowLongIndex.GWL_STYLE, (uint)value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -874,11 +876,11 @@ namespace GreenshotPlugin.Core {
|
|||
public WindowPlacement WindowPlacement {
|
||||
get {
|
||||
WindowPlacement placement = WindowPlacement.Default;
|
||||
User32.GetWindowPlacement(this.Handle, ref placement);
|
||||
User32.GetWindowPlacement(Handle, ref placement);
|
||||
return placement;
|
||||
}
|
||||
set {
|
||||
User32.SetWindowPlacement(this.Handle, ref value);
|
||||
User32.SetWindowPlacement(Handle, ref value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -887,10 +889,10 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
public ExtendedWindowStyleFlags ExtendedWindowStyle {
|
||||
get {
|
||||
return (ExtendedWindowStyleFlags)User32.GetWindowLongWrapper(this.hWnd, (int)WindowLongIndex.GWL_EXSTYLE);
|
||||
return (ExtendedWindowStyleFlags)User32.GetWindowLongWrapper(hWnd, (int)WindowLongIndex.GWL_EXSTYLE);
|
||||
}
|
||||
set {
|
||||
User32.SetWindowLongWrapper(this.hWnd, (int)WindowLongIndex.GWL_EXSTYLE, (uint)value);
|
||||
User32.SetWindowLongWrapper(hWnd, (int)WindowLongIndex.GWL_EXSTYLE, (uint)value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1015,7 +1017,7 @@ namespace GreenshotPlugin.Core {
|
|||
try {
|
||||
// Check if we make a transparent capture
|
||||
if (windowCaptureMode == WindowCaptureMode.AeroTransparent) {
|
||||
frozen = this.FreezeWindow();
|
||||
frozen = FreezeWindow();
|
||||
// Use white, later black to capture transparent
|
||||
tempForm.BackColor = Color.White;
|
||||
// Make sure everything is visible
|
||||
|
@ -1073,7 +1075,7 @@ namespace GreenshotPlugin.Core {
|
|||
// Not needed for Windows 8
|
||||
if (!(Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor >= 2)) {
|
||||
// Only if the Inivalue is set, not maximized and it's not a tool window.
|
||||
if (conf.WindowCaptureRemoveCorners && !Maximised && (this.ExtendedWindowStyle & ExtendedWindowStyleFlags.WS_EX_TOOLWINDOW) == 0) {
|
||||
if (conf.WindowCaptureRemoveCorners && !Maximised && (ExtendedWindowStyle & ExtendedWindowStyleFlags.WS_EX_TOOLWINDOW) == 0) {
|
||||
// Remove corners
|
||||
if (!Image.IsAlphaPixelFormat(capturedBitmap.PixelFormat)) {
|
||||
LOG.Debug("Changing pixelformat to Alpha for the RemoveCorners");
|
||||
|
@ -1088,7 +1090,7 @@ namespace GreenshotPlugin.Core {
|
|||
} finally {
|
||||
// Make sure to ALWAYS unfreeze!!
|
||||
if (frozen) {
|
||||
this.UnfreezeWindow();
|
||||
UnfreezeWindow();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1251,7 +1253,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Set the window as foreground window
|
||||
/// </summary>
|
||||
public void ToForeground() {
|
||||
ToForeground(this.Handle);
|
||||
ToForeground(Handle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1290,7 +1292,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Warning: Use only if no other way!!
|
||||
/// </summary>
|
||||
private bool FreezeWindow() {
|
||||
Process proc = Process.GetProcessById(this.ProcessId.ToInt32());
|
||||
Process proc = Process.GetProcessById(ProcessId.ToInt32());
|
||||
string processName = proc.ProcessName;
|
||||
if (!CanFreezeOrUnfreeze(processName)) {
|
||||
LOG.DebugFormat("Not freezing {0}", processName);
|
||||
|
@ -1320,7 +1322,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Unfreeze the process belonging to the window
|
||||
/// </summary>
|
||||
public void UnfreezeWindow() {
|
||||
Process proc = Process.GetProcessById(this.ProcessId.ToInt32());
|
||||
Process proc = Process.GetProcessById(ProcessId.ToInt32());
|
||||
|
||||
string processName = proc.ProcessName;
|
||||
if (!CanFreezeOrUnfreeze(processName)) {
|
||||
|
@ -1390,7 +1392,7 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
if (!HasParent && this.Maximised) {
|
||||
if (!HasParent && Maximised) {
|
||||
LOG.Debug("Correcting for maximalization");
|
||||
Size borderSize = Size.Empty;
|
||||
GetBorderSize(out borderSize);
|
||||
|
@ -1417,13 +1419,13 @@ namespace GreenshotPlugin.Core {
|
|||
IntPtr hWnd = User32.GetForegroundWindow();
|
||||
if (hWnd != null && hWnd != IntPtr.Zero) {
|
||||
if (ignoreHandles.Contains(hWnd)) {
|
||||
return WindowDetails.GetDesktopWindow();
|
||||
return GetDesktopWindow();
|
||||
}
|
||||
|
||||
WindowDetails activeWindow = new WindowDetails(hWnd);
|
||||
// Invisible Windows should not be active
|
||||
if (!activeWindow.Visible) {
|
||||
return WindowDetails.GetDesktopWindow();
|
||||
return GetDesktopWindow();
|
||||
}
|
||||
return activeWindow;
|
||||
}
|
||||
|
@ -1507,7 +1509,7 @@ namespace GreenshotPlugin.Core {
|
|||
List<WindowDetails> windows = new List<WindowDetails>();
|
||||
Rectangle screenBounds = WindowCapture.GetScreenBounds();
|
||||
List<WindowDetails> allWindows = GetMetroApps();
|
||||
allWindows.AddRange(WindowDetails.GetAllWindows());
|
||||
allWindows.AddRange(GetAllWindows());
|
||||
foreach(WindowDetails window in allWindows) {
|
||||
// Ignore windows without title
|
||||
if (window.Text.Length == 0) {
|
||||
|
@ -1581,7 +1583,7 @@ namespace GreenshotPlugin.Core {
|
|||
public static List<WindowDetails> GetTopLevelWindows() {
|
||||
List<WindowDetails> windows = new List<WindowDetails>();
|
||||
var possibleTopLevelWindows = GetMetroApps();
|
||||
possibleTopLevelWindows.AddRange(WindowDetails.GetAllWindows());
|
||||
possibleTopLevelWindows.AddRange(GetAllWindows());
|
||||
foreach (WindowDetails window in possibleTopLevelWindows) {
|
||||
// Ignore windows without title
|
||||
if (window.Text.Length == 0) {
|
||||
|
@ -1621,7 +1623,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <returns></returns>
|
||||
public static WindowDetails GetLinkedWindow(WindowDetails windowToLinkTo) {
|
||||
IntPtr processIdSelectedWindow = windowToLinkTo.ProcessId;
|
||||
foreach(WindowDetails window in WindowDetails.GetAllWindows()) {
|
||||
foreach(WindowDetails window in GetAllWindows()) {
|
||||
// Ignore windows without title
|
||||
if (window.Text.Length == 0) {
|
||||
continue;
|
||||
|
@ -1657,7 +1659,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
/// <param name="oldWindows">List<WindowDetails> with old windows</param>
|
||||
public static void ActiveNewerWindows(List<WindowDetails> oldWindows) {
|
||||
List<WindowDetails> windowsAfter = WindowDetails.GetVisibleWindows();
|
||||
List<WindowDetails> windowsAfter = GetVisibleWindows();
|
||||
foreach(WindowDetails window in windowsAfter) {
|
||||
if (!oldWindows.Contains(window)) {
|
||||
window.ToForeground();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue