mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 18:57:28 -07:00
Small cleanups [skip ci]
This commit is contained in:
parent
02a06a12b0
commit
98e6be5eb6
171 changed files with 1607 additions and 1769 deletions
|
@ -42,7 +42,7 @@ namespace Greenshot.Helpers {
|
|||
/// </summary>
|
||||
public class CaptureHelper : IDisposable {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(CaptureHelper));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static readonly CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
// TODO: when we get the screen capture code working correctly, this needs to be enabled
|
||||
//private static ScreenCaptureHelper screenCapture = null;
|
||||
private List<WindowDetails> _windows = new List<WindowDetails>();
|
||||
|
@ -404,7 +404,7 @@ namespace Greenshot.Helpers {
|
|||
|
||||
// Set capture title, fixing bug #3569703
|
||||
foreach (WindowDetails window in WindowDetails.GetVisibleWindows()) {
|
||||
Point estimatedLocation = new Point(conf.LastCapturedRegion.X + (conf.LastCapturedRegion.Width / 2), conf.LastCapturedRegion.Y + (conf.LastCapturedRegion.Height / 2));
|
||||
Point estimatedLocation = new Point(conf.LastCapturedRegion.X + conf.LastCapturedRegion.Width / 2, conf.LastCapturedRegion.Y + conf.LastCapturedRegion.Height / 2);
|
||||
if (window.Contains(estimatedLocation)) {
|
||||
_selectedCaptureWindow = window;
|
||||
_capture.CaptureDetails.Title = _selectedCaptureWindow.Text;
|
||||
|
@ -850,14 +850,14 @@ namespace Greenshot.Helpers {
|
|||
// check if GDI capture any good, by comparing it with the screen content
|
||||
int blackCountGDI = ImageHelper.CountColor(tmpCapture.Image, Color.Black, false);
|
||||
int GDIPixels = tmpCapture.Image.Width * tmpCapture.Image.Height;
|
||||
int blackPercentageGDI = (blackCountGDI * 100) / GDIPixels;
|
||||
int blackPercentageGDI = blackCountGDI * 100 / GDIPixels;
|
||||
if (blackPercentageGDI >= 1) {
|
||||
int screenPixels = windowRectangle.Width * windowRectangle.Height;
|
||||
using (ICapture screenCapture = new Capture()) {
|
||||
screenCapture.CaptureDetails = captureForWindow.CaptureDetails;
|
||||
if (WindowCapture.CaptureRectangleFromDesktopScreen(screenCapture, windowRectangle) != null) {
|
||||
int blackCountScreen = ImageHelper.CountColor(screenCapture.Image, Color.Black, false);
|
||||
int blackPercentageScreen = (blackCountScreen * 100) / screenPixels;
|
||||
int blackPercentageScreen = blackCountScreen * 100 / screenPixels;
|
||||
if (screenPixels == GDIPixels) {
|
||||
// "easy compare", both have the same size
|
||||
// If GDI has more black, use the screen capture.
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
@ -28,21 +29,21 @@ using System.Windows.Forms;
|
|||
|
||||
using GreenshotPlugin.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Code from vbAccelerator, location:
|
||||
/// http://www.vbaccelerator.com/home/NET/Code/Libraries/Windows_Messages/Simple_Interprocess_Communication/WM_COPYDATA_Demo_zip_SimpleInterprocessCommunicationsCS_CopyData_cs.asp
|
||||
/// </summary>
|
||||
namespace Greenshot.Helpers {
|
||||
public enum CommandEnum { OpenFile, Exit, FirstLaunch, ReloadConfig };
|
||||
|
||||
/// <summary>
|
||||
/// Code from vbAccelerator, location:
|
||||
/// http://www.vbaccelerator.com/home/NET/Code/Libraries/Windows_Messages/Simple_Interprocess_Communication/WM_COPYDATA_Demo_zip_SimpleInterprocessCommunicationsCS_CopyData_cs.asp
|
||||
/// </summary>
|
||||
[Serializable()]
|
||||
public class CopyDataTransport {
|
||||
List<KeyValuePair<CommandEnum, string>> commands;
|
||||
private readonly List<KeyValuePair<CommandEnum, string>> _commands;
|
||||
public List<KeyValuePair<CommandEnum, string>> Commands {
|
||||
get {return commands;}
|
||||
get {return _commands;}
|
||||
}
|
||||
public CopyDataTransport() {
|
||||
commands = new List<KeyValuePair<CommandEnum, string>>();
|
||||
_commands = new List<KeyValuePair<CommandEnum, string>>();
|
||||
}
|
||||
|
||||
public CopyDataTransport(CommandEnum command) : this() {
|
||||
|
@ -53,10 +54,10 @@ namespace Greenshot.Helpers {
|
|||
AddCommand(command, commandData);
|
||||
}
|
||||
public void AddCommand(CommandEnum command) {
|
||||
commands.Add(new KeyValuePair<CommandEnum, string>(command, null));
|
||||
_commands.Add(new KeyValuePair<CommandEnum, string>(command, null));
|
||||
}
|
||||
public void AddCommand(CommandEnum command, string commandData) {
|
||||
commands.Add(new KeyValuePair<CommandEnum, string>(command, commandData));
|
||||
_commands.Add(new KeyValuePair<CommandEnum, string>(command, commandData));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -81,16 +82,16 @@ namespace Greenshot.Helpers {
|
|||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct COPYDATASTRUCT {
|
||||
public IntPtr dwData;
|
||||
public int cbData;
|
||||
public IntPtr lpData;
|
||||
public readonly IntPtr dwData;
|
||||
public readonly int cbData;
|
||||
public readonly IntPtr lpData;
|
||||
}
|
||||
|
||||
private const int WM_COPYDATA = 0x4A;
|
||||
private const int WM_DESTROY = 0x2;
|
||||
|
||||
#region Member Variables
|
||||
private CopyDataChannels channels = null;
|
||||
private CopyDataChannels _channels;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
|
@ -109,7 +110,7 @@ namespace Greenshot.Helpers {
|
|||
BinaryFormatter b = new BinaryFormatter();
|
||||
CopyDataObjectData cdo = (CopyDataObjectData) b.Deserialize(stream);
|
||||
|
||||
if (channels != null && channels.Contains(cdo.Channel)) {
|
||||
if (_channels != null && _channels.Contains(cdo.Channel)) {
|
||||
CopyDataReceivedEventArgs d = new CopyDataReceivedEventArgs(cdo.Channel, cdo.Data, cdo.Sent);
|
||||
OnCopyDataReceived(d);
|
||||
m.Result = (IntPtr) 1;
|
||||
|
@ -119,8 +120,8 @@ namespace Greenshot.Helpers {
|
|||
// WM_DESTROY fires before OnHandleChanged and is
|
||||
// a better place to ensure that we've cleared
|
||||
// everything up.
|
||||
if (channels != null) {
|
||||
channels.OnHandleChange();
|
||||
if (_channels != null) {
|
||||
_channels.OnHandleChange();
|
||||
}
|
||||
base.OnHandleChange();
|
||||
}
|
||||
|
@ -131,8 +132,12 @@ namespace Greenshot.Helpers {
|
|||
/// Raises the DataReceived event from this class.
|
||||
/// </summary>
|
||||
/// <param name="e">The data which has been received.</param>
|
||||
protected void OnCopyDataReceived(CopyDataReceivedEventArgs e) {
|
||||
CopyDataReceived(this, e);
|
||||
protected void OnCopyDataReceived(CopyDataReceivedEventArgs e)
|
||||
{
|
||||
if (CopyDataReceived != null)
|
||||
{
|
||||
CopyDataReceived(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -144,8 +149,8 @@ namespace Greenshot.Helpers {
|
|||
/// </summary>
|
||||
protected override void OnHandleChange () {
|
||||
// need to clear up everything we had set.
|
||||
if (channels != null) {
|
||||
channels.OnHandleChange();
|
||||
if (_channels != null) {
|
||||
_channels.OnHandleChange();
|
||||
}
|
||||
base.OnHandleChange();
|
||||
}
|
||||
|
@ -155,7 +160,7 @@ namespace Greenshot.Helpers {
|
|||
/// </summary>
|
||||
public CopyDataChannels Channels {
|
||||
get {
|
||||
return channels;
|
||||
return _channels;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,9 +173,9 @@ namespace Greenshot.Helpers {
|
|||
/// Clears up any resources associated with this object.
|
||||
/// </summary>
|
||||
protected virtual void Dispose(bool disposing) {
|
||||
if (disposing && channels != null) {
|
||||
channels.Clear();
|
||||
channels = null;
|
||||
if (disposing && _channels != null) {
|
||||
_channels.Clear();
|
||||
_channels = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,7 +183,7 @@ namespace Greenshot.Helpers {
|
|||
/// Constructs a new instance of the CopyData class
|
||||
/// </summary>
|
||||
public CopyData() {
|
||||
channels = new CopyDataChannels(this);
|
||||
_channels = new CopyDataChannels(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -196,45 +201,28 @@ namespace Greenshot.Helpers {
|
|||
/// which has been sent from another application.
|
||||
/// </summary>
|
||||
public class CopyDataReceivedEventArgs : EventArgs {
|
||||
private string channelName = "";
|
||||
private object data = null;
|
||||
private DateTime sent;
|
||||
private DateTime received;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the channel name that this data was sent on.
|
||||
/// </summary>
|
||||
public string ChannelName {
|
||||
get {
|
||||
return channelName;
|
||||
}
|
||||
}
|
||||
public string ChannelName { get; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data object which was sent.
|
||||
/// </summary>
|
||||
public Object Data {
|
||||
get {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
public object Data { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time which at the data was sent
|
||||
/// by the sending application.
|
||||
/// </summary>
|
||||
public DateTime Sent {
|
||||
get {
|
||||
return sent;
|
||||
}
|
||||
}
|
||||
public DateTime Sent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time which this data item as
|
||||
/// received.
|
||||
/// </summary>
|
||||
public DateTime Received {
|
||||
get {
|
||||
return received;
|
||||
}
|
||||
}
|
||||
public DateTime Received { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an instance of this class.
|
||||
/// </summary>
|
||||
|
@ -242,10 +230,10 @@ namespace Greenshot.Helpers {
|
|||
/// <param name="data">The data which was sent</param>
|
||||
/// <param name="sent">The date and time the data was sent</param>
|
||||
internal CopyDataReceivedEventArgs(string channelName, object data, DateTime sent) {
|
||||
this.channelName = channelName;
|
||||
this.data = data;
|
||||
this.sent = sent;
|
||||
received = DateTime.Now;
|
||||
ChannelName = channelName;
|
||||
Data = data;
|
||||
Sent = sent;
|
||||
Received = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +242,7 @@ namespace Greenshot.Helpers {
|
|||
/// class.
|
||||
/// </summary>
|
||||
public class CopyDataChannels : DictionaryBase {
|
||||
private NativeWindow owner = null;
|
||||
private readonly NativeWindow _owner;
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator for each of the CopyDataChannel objects
|
||||
|
@ -296,7 +284,7 @@ namespace Greenshot.Helpers {
|
|||
/// receive messages.
|
||||
/// </summary>
|
||||
public void Add(string channelName) {
|
||||
CopyDataChannel cdc = new CopyDataChannel(owner, channelName);
|
||||
CopyDataChannel cdc = new CopyDataChannel(_owner, channelName);
|
||||
Dictionary.Add(channelName , cdc);
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -334,7 +322,7 @@ namespace Greenshot.Helpers {
|
|||
/// just been removed</param>
|
||||
protected override void OnRemoveComplete ( Object key , Object data ) {
|
||||
( (CopyDataChannel) data).Dispose();
|
||||
base.OnRemove(key, data);
|
||||
OnRemove(key, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -357,7 +345,7 @@ namespace Greenshot.Helpers {
|
|||
/// <param name="owner">The NativeWindow this collection
|
||||
/// will be associated with</param>
|
||||
internal CopyDataChannels(NativeWindow owner) {
|
||||
this.owner = owner;
|
||||
_owner = owner;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -367,14 +355,14 @@ namespace Greenshot.Helpers {
|
|||
public class CopyDataChannel : IDisposable {
|
||||
#region Unmanaged Code
|
||||
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private extern static IntPtr GetProp(IntPtr hwnd, string lpString);
|
||||
private static extern IntPtr GetProp(IntPtr hwnd, string lpString);
|
||||
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private extern static bool SetProp(IntPtr hwnd, string lpString, IntPtr hData);
|
||||
private static extern bool SetProp(IntPtr hwnd, string lpString, IntPtr hData);
|
||||
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private extern static IntPtr RemoveProp(IntPtr hwnd, string lpString);
|
||||
private static extern IntPtr RemoveProp(IntPtr hwnd, string lpString);
|
||||
|
||||
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private extern static IntPtr SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, ref COPYDATASTRUCT lParam);
|
||||
private static extern IntPtr SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, ref COPYDATASTRUCT lParam);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct COPYDATASTRUCT {
|
||||
|
@ -387,19 +375,15 @@ namespace Greenshot.Helpers {
|
|||
#endregion
|
||||
|
||||
#region Member Variables
|
||||
private string channelName = "";
|
||||
private NativeWindow owner = null;
|
||||
private bool recreateChannel = false;
|
||||
|
||||
private readonly NativeWindow _owner;
|
||||
private bool _recreateChannel;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name associated with this channel.
|
||||
/// </summary>
|
||||
public string ChannelName {
|
||||
get {
|
||||
return channelName;
|
||||
}
|
||||
}
|
||||
public string ChannelName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sends the specified object on this channel to any other
|
||||
|
@ -411,12 +395,12 @@ namespace Greenshot.Helpers {
|
|||
public int Send(object obj) {
|
||||
int recipients = 0;
|
||||
|
||||
if (recreateChannel) {
|
||||
if (_recreateChannel) {
|
||||
// handle has changed
|
||||
addChannel();
|
||||
AddChannel();
|
||||
}
|
||||
|
||||
CopyDataObjectData cdo = new CopyDataObjectData(obj, channelName);
|
||||
CopyDataObjectData cdo = new CopyDataObjectData(obj, ChannelName);
|
||||
|
||||
|
||||
// Try to do a binary serialization on obj.
|
||||
|
@ -446,14 +430,16 @@ namespace Greenshot.Helpers {
|
|||
// Send the data to each window identified on
|
||||
// the channel:
|
||||
foreach(WindowDetails window in WindowDetails.GetAllWindows()) {
|
||||
if (!window.Handle.Equals(owner.Handle)) {
|
||||
if (GetProp(window.Handle, channelName) != IntPtr.Zero) {
|
||||
COPYDATASTRUCT cds = new COPYDATASTRUCT();
|
||||
cds.cbData = dataSize;
|
||||
cds.dwData = IntPtr.Zero;
|
||||
cds.lpData = ptrData;
|
||||
SendMessage(window.Handle, WM_COPYDATA, owner.Handle, ref cds);
|
||||
recipients += (Marshal.GetLastWin32Error() == 0 ? 1 : 0);
|
||||
if (!window.Handle.Equals(_owner.Handle)) {
|
||||
if (GetProp(window.Handle, ChannelName) != IntPtr.Zero) {
|
||||
COPYDATASTRUCT cds = new COPYDATASTRUCT
|
||||
{
|
||||
cbData = dataSize,
|
||||
dwData = IntPtr.Zero,
|
||||
lpData = ptrData
|
||||
};
|
||||
SendMessage(window.Handle, WM_COPYDATA, _owner.Handle, ref cds);
|
||||
recipients += Marshal.GetLastWin32Error() == 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -466,14 +452,14 @@ namespace Greenshot.Helpers {
|
|||
return recipients;
|
||||
}
|
||||
|
||||
private void addChannel() {
|
||||
private void AddChannel() {
|
||||
// Tag this window with property "channelName"
|
||||
SetProp(owner.Handle, channelName, owner.Handle);
|
||||
SetProp(_owner.Handle, ChannelName, _owner.Handle);
|
||||
}
|
||||
|
||||
private void removeChannel() {
|
||||
private void RemoveChannel() {
|
||||
// Remove the "channelName" property from this window
|
||||
RemoveProp(owner.Handle, channelName);
|
||||
RemoveProp(_owner.Handle, ChannelName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -484,8 +470,8 @@ namespace Greenshot.Helpers {
|
|||
/// the new handle has been assigned.
|
||||
/// </summary>
|
||||
public void OnHandleChange() {
|
||||
removeChannel();
|
||||
recreateChannel = true;
|
||||
RemoveChannel();
|
||||
_recreateChannel = true;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
|
@ -498,10 +484,10 @@ namespace Greenshot.Helpers {
|
|||
/// </summary>
|
||||
protected virtual void Dispose(bool disposing) {
|
||||
if (disposing) {
|
||||
if (channelName.Length > 0) {
|
||||
removeChannel();
|
||||
if (ChannelName.Length > 0) {
|
||||
RemoveChannel();
|
||||
}
|
||||
channelName = "";
|
||||
ChannelName = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -513,9 +499,9 @@ namespace Greenshot.Helpers {
|
|||
/// <param name="channelName">The name of the channel to
|
||||
/// send messages on</param>
|
||||
internal CopyDataChannel(NativeWindow owner, string channelName) {
|
||||
this.owner = owner;
|
||||
this.channelName = channelName;
|
||||
addChannel();
|
||||
_owner = owner;
|
||||
ChannelName = channelName;
|
||||
AddChannel();
|
||||
}
|
||||
|
||||
~CopyDataChannel() {
|
||||
|
@ -552,7 +538,7 @@ namespace Greenshot.Helpers {
|
|||
Data = data;
|
||||
if (!data.GetType().IsSerializable) {
|
||||
throw new ArgumentException("Data object must be serializable.",
|
||||
"data");
|
||||
nameof(data));
|
||||
}
|
||||
Channel = channel;
|
||||
Sent = DateTime.Now;
|
||||
|
|
|
@ -31,9 +31,9 @@ namespace Greenshot.Helpers {
|
|||
/// Description of DestinationHelper.
|
||||
/// </summary>
|
||||
public static class DestinationHelper {
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(DestinationHelper));
|
||||
private static Dictionary<string, IDestination> RegisteredDestinations = new Dictionary<string, IDestination>();
|
||||
private static CoreConfiguration coreConfig = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(DestinationHelper));
|
||||
private static readonly Dictionary<string, IDestination> RegisteredDestinations = new Dictionary<string, IDestination>();
|
||||
private static readonly CoreConfiguration coreConfig = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
/// Initialize the destinations
|
||||
static DestinationHelper() {
|
||||
|
|
|
@ -20,14 +20,12 @@
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using Greenshot.IniFile;
|
||||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Helpers
|
||||
{
|
||||
|
@ -36,19 +34,18 @@ namespace Greenshot.Helpers
|
|||
/// </summary>
|
||||
public static class EnvironmentInfo
|
||||
{
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(EnvironmentInfo));
|
||||
private static bool? isWindows = null;
|
||||
private static bool? _isWindows;
|
||||
|
||||
public static bool IsWindows
|
||||
{
|
||||
get
|
||||
{
|
||||
if (isWindows.HasValue)
|
||||
if (_isWindows.HasValue)
|
||||
{
|
||||
return isWindows.Value;
|
||||
return _isWindows.Value;
|
||||
}
|
||||
isWindows = Environment.OSVersion.Platform.ToString().StartsWith("Win");
|
||||
return isWindows.Value;
|
||||
_isWindows = Environment.OSVersion.Platform.ToString().StartsWith("Win");
|
||||
return _isWindows.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +98,7 @@ namespace Greenshot.Helpers
|
|||
{
|
||||
environment.Append(", ");
|
||||
}
|
||||
environment.Append(String.Format("OS: {0} {1} {2} (x{3}) {4}", OSInfo.Name, OSInfo.Edition, OSInfo.ServicePack, OSInfo.Bits, OSInfo.VersionString));
|
||||
environment.Append(string.Format("OS: {0} {1} {2} (x{3}) {4}", OSInfo.Name, OSInfo.Edition, OSInfo.ServicePack, OSInfo.Bits, OSInfo.VersionString));
|
||||
if (newline)
|
||||
{
|
||||
environment.AppendLine();
|
||||
|
@ -201,11 +198,6 @@ namespace Greenshot.Helpers
|
|||
exceptionText.AppendLine(EnvironmentToString(true));
|
||||
exceptionText.AppendLine(ExceptionToString(exception));
|
||||
exceptionText.AppendLine("Configuration dump:");
|
||||
using (TextWriter writer = new StringWriter(exceptionText))
|
||||
{
|
||||
// TODO: Create summary of properties
|
||||
//var iniConfig = IniConfig.Current.WriteToStreamAsync();
|
||||
}
|
||||
|
||||
return exceptionText.ToString();
|
||||
}
|
||||
|
@ -215,13 +207,13 @@ namespace Greenshot.Helpers
|
|||
/// Provides detailed information about the host operating system.
|
||||
/// Code is available at: http://www.csharp411.com/determine-windows-version-and-edition-with-c/
|
||||
/// </summary>
|
||||
static public class OSInfo
|
||||
public static class OSInfo
|
||||
{
|
||||
#region BITS
|
||||
/// <summary>
|
||||
/// Determines if the current application is 32 or 64-bit.
|
||||
/// </summary>
|
||||
static public int Bits
|
||||
public static int Bits
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -231,24 +223,26 @@ namespace Greenshot.Helpers
|
|||
#endregion BITS
|
||||
|
||||
#region EDITION
|
||||
static private string s_Edition;
|
||||
private static string _sEdition;
|
||||
/// <summary>
|
||||
/// Gets the edition of the operating system running on this computer.
|
||||
/// </summary>
|
||||
static public string Edition
|
||||
public static string Edition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_Edition != null)
|
||||
if (_sEdition != null)
|
||||
{
|
||||
return s_Edition; //***** RETURN *****//
|
||||
return _sEdition; //***** RETURN *****//
|
||||
}
|
||||
|
||||
string edition = String.Empty;
|
||||
string edition = string.Empty;
|
||||
|
||||
OperatingSystem osVersion = Environment.OSVersion;
|
||||
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
|
||||
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
|
||||
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX
|
||||
{
|
||||
dwOSVersionInfoSize = Marshal.SizeOf(typeof (OSVERSIONINFOEX))
|
||||
};
|
||||
|
||||
if (GetVersionEx(ref osVersionInfo))
|
||||
{
|
||||
|
@ -469,18 +463,18 @@ namespace Greenshot.Helpers
|
|||
#endregion VERSION 6
|
||||
}
|
||||
|
||||
s_Edition = edition;
|
||||
_sEdition = edition;
|
||||
return edition;
|
||||
}
|
||||
}
|
||||
#endregion EDITION
|
||||
|
||||
#region NAME
|
||||
static private string s_Name;
|
||||
private static string s_Name;
|
||||
/// <summary>
|
||||
/// Gets the name of the operating system running on this computer.
|
||||
/// </summary>
|
||||
static public string Name
|
||||
public static string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -666,17 +660,17 @@ namespace Greenshot.Helpers
|
|||
private struct OSVERSIONINFOEX
|
||||
{
|
||||
public int dwOSVersionInfoSize;
|
||||
public int dwMajorVersion;
|
||||
public int dwMinorVersion;
|
||||
public int dwBuildNumber;
|
||||
public int dwPlatformId;
|
||||
public readonly int dwMajorVersion;
|
||||
public readonly int dwMinorVersion;
|
||||
public readonly int dwBuildNumber;
|
||||
public readonly int dwPlatformId;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||
public string szCSDVersion;
|
||||
public short wServicePackMajor;
|
||||
public short wServicePackMinor;
|
||||
public short wSuiteMask;
|
||||
public byte wProductType;
|
||||
public byte wReserved;
|
||||
public readonly string szCSDVersion;
|
||||
public readonly short wServicePackMajor;
|
||||
public readonly short wServicePackMinor;
|
||||
public readonly short wSuiteMask;
|
||||
public readonly byte wProductType;
|
||||
public readonly byte wReserved;
|
||||
}
|
||||
#endregion OSVERSIONINFOEX
|
||||
|
||||
|
@ -724,13 +718,9 @@ namespace Greenshot.Helpers
|
|||
|
||||
#region VERSIONS
|
||||
private const int VER_NT_WORKSTATION = 1;
|
||||
private const int VER_NT_DOMAIN_CONTROLLER = 2;
|
||||
private const int VER_NT_SERVER = 3;
|
||||
private const int VER_SUITE_SMALLBUSINESS = 1;
|
||||
private const int VER_SUITE_ENTERPRISE = 2;
|
||||
private const int VER_SUITE_TERMINAL = 16;
|
||||
private const int VER_SUITE_DATACENTER = 128;
|
||||
private const int VER_SUITE_SINGLEUSERTS = 256;
|
||||
private const int VER_SUITE_PERSONAL = 512;
|
||||
private const int VER_SUITE_BLADE = 1024;
|
||||
#endregion VERSIONS
|
||||
|
@ -740,11 +730,11 @@ namespace Greenshot.Helpers
|
|||
/// <summary>
|
||||
/// Gets the service pack information of the operating system running on this computer.
|
||||
/// </summary>
|
||||
static public string ServicePack
|
||||
public static string ServicePack
|
||||
{
|
||||
get
|
||||
{
|
||||
string servicePack = String.Empty;
|
||||
string servicePack = string.Empty;
|
||||
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
|
||||
|
||||
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
|
||||
|
@ -778,7 +768,7 @@ namespace Greenshot.Helpers
|
|||
/// <summary>
|
||||
/// Gets the full version string of the operating system running on this computer.
|
||||
/// </summary>
|
||||
static public string VersionString
|
||||
public static string VersionString
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -791,7 +781,7 @@ namespace Greenshot.Helpers
|
|||
/// <summary>
|
||||
/// Gets the full version of the operating system running on this computer.
|
||||
/// </summary>
|
||||
static public Version Version
|
||||
public static Version Version
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -805,7 +795,7 @@ namespace Greenshot.Helpers
|
|||
/// <summary>
|
||||
/// Gets the major version number of the operating system running on this computer.
|
||||
/// </summary>
|
||||
static public int MajorVersion
|
||||
public static int MajorVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -818,7 +808,7 @@ namespace Greenshot.Helpers
|
|||
/// <summary>
|
||||
/// Gets the minor version number of the operating system running on this computer.
|
||||
/// </summary>
|
||||
static public int MinorVersion
|
||||
public static int MinorVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -831,7 +821,7 @@ namespace Greenshot.Helpers
|
|||
/// <summary>
|
||||
/// Gets the revision version number of the operating system running on this computer.
|
||||
/// </summary>
|
||||
static public int RevisionVersion
|
||||
public static int RevisionVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
|
@ -37,9 +37,9 @@ namespace Greenshot.Helpers {
|
|||
//Our end result
|
||||
int result = 0;
|
||||
//Take x2-x1, then square it
|
||||
double part1 = Math.Pow((x2 - x1), 2);
|
||||
double part1 = Math.Pow(x2 - x1, 2);
|
||||
//Take y2-y1, then square it
|
||||
double part2 = Math.Pow((y2 - y1), 2);
|
||||
double part2 = Math.Pow(y2 - y1, 2);
|
||||
//Add both of the parts together
|
||||
double underRadical = part1 + part2;
|
||||
//Get the square root of the parts
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace Greenshot.Helpers {
|
|||
/// Many thanks to all the people who contributed here!
|
||||
/// </summary>
|
||||
public static class IECaptureHelper {
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(IECaptureHelper));
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(IECaptureHelper));
|
||||
private static readonly CoreConfiguration configuration = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
// Helper method to activate a certain IE Tab
|
||||
|
@ -69,7 +69,7 @@ namespace Greenshot.Helpers {
|
|||
if (ieWindow != null) {
|
||||
Rectangle wholeClient = someWindow.ClientRectangle;
|
||||
Rectangle partClient = ieWindow.ClientRectangle;
|
||||
int percentage = (int)(100*((float)(partClient.Width * partClient.Height)) / ((float)(wholeClient.Width * wholeClient.Height)));
|
||||
int percentage = (int)(100*(float)(partClient.Width * partClient.Height) / (float)(wholeClient.Width * wholeClient.Height));
|
||||
LOG.InfoFormat("Window {0}, ie part {1}, percentage {2}", wholeClient, partClient, percentage);
|
||||
if (percentage > minimumPercentage) {
|
||||
return true;
|
||||
|
@ -143,7 +143,7 @@ namespace Greenshot.Helpers {
|
|||
} else if (configuration.WindowClassesToCheckForIE != null && configuration.WindowClassesToCheckForIE.Contains(ieWindow.ClassName)) {
|
||||
List<string> singleWindowText = new List<string>();
|
||||
try {
|
||||
IHTMLDocument2 document2 = getHTMLDocument(ieWindow);
|
||||
IHTMLDocument2 document2 = GetHtmlDocument(ieWindow);
|
||||
string title = document2.title;
|
||||
Marshal.ReleaseComObject(document2);
|
||||
if (string.IsNullOrEmpty(title)) {
|
||||
|
@ -177,7 +177,7 @@ namespace Greenshot.Helpers {
|
|||
/// </summary>
|
||||
/// <param name="mainWindow"></param>
|
||||
/// <returns></returns>
|
||||
private static IHTMLDocument2 getHTMLDocument(WindowDetails mainWindow) {
|
||||
private static IHTMLDocument2 GetHtmlDocument(WindowDetails mainWindow) {
|
||||
WindowDetails ieServer;
|
||||
if ("Internet Explorer_Server".Equals(mainWindow.ClassName)) {
|
||||
ieServer = mainWindow;
|
||||
|
@ -249,7 +249,7 @@ namespace Greenshot.Helpers {
|
|||
|
||||
try {
|
||||
// Get the Document
|
||||
IHTMLDocument2 document2 = getHTMLDocument(ieWindow);
|
||||
IHTMLDocument2 document2 = GetHtmlDocument(ieWindow);
|
||||
if (document2 == null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ namespace Greenshot.Helpers {
|
|||
Bitmap returnBitmap = null;
|
||||
try {
|
||||
Size pageSize = PrepareCapture(documentContainer, capture);
|
||||
returnBitmap = capturePage(documentContainer, capture, pageSize);
|
||||
returnBitmap = CapturePage(documentContainer, pageSize);
|
||||
} catch (Exception captureException) {
|
||||
LOG.Error("Exception found, ignoring and returning nothing! Error was: ", captureException);
|
||||
}
|
||||
|
@ -554,8 +554,9 @@ namespace Greenshot.Helpers {
|
|||
/// Capture the actual page (document)
|
||||
/// </summary>
|
||||
/// <param name="documentContainer">The document wrapped in a container</param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <returns>Bitmap with the page content as an image</returns>
|
||||
private static Bitmap capturePage(DocumentContainer documentContainer, ICapture capture, Size pageSize) {
|
||||
private static Bitmap CapturePage(DocumentContainer documentContainer, Size pageSize) {
|
||||
WindowDetails contentWindowDetails = documentContainer.ContentWindow;
|
||||
|
||||
//Create a target bitmap to draw into with the calculated page size
|
||||
|
@ -567,7 +568,7 @@ namespace Greenshot.Helpers {
|
|||
graphicsTarget.Clear(clearColor);
|
||||
|
||||
// Get the base document & draw it
|
||||
drawDocument(documentContainer, contentWindowDetails, graphicsTarget);
|
||||
DrawDocument(documentContainer, contentWindowDetails, graphicsTarget);
|
||||
|
||||
// Loop over the frames and clear their source area so we don't see any artefacts
|
||||
foreach(DocumentContainer frameDocument in documentContainer.Frames) {
|
||||
|
@ -577,7 +578,7 @@ namespace Greenshot.Helpers {
|
|||
}
|
||||
// Loop over the frames and capture their content
|
||||
foreach(DocumentContainer frameDocument in documentContainer.Frames) {
|
||||
drawDocument(frameDocument, contentWindowDetails, graphicsTarget);
|
||||
DrawDocument(frameDocument, contentWindowDetails, graphicsTarget);
|
||||
}
|
||||
}
|
||||
return returnBitmap;
|
||||
|
@ -586,11 +587,11 @@ namespace Greenshot.Helpers {
|
|||
/// <summary>
|
||||
/// This method takes the actual capture of the document (frame)
|
||||
/// </summary>
|
||||
/// <param name="frameDocument"></param>
|
||||
/// <param name="documentContainer"></param>
|
||||
/// <param name="contentWindowDetails">Needed for referencing the location of the frame</param>
|
||||
/// <returns>Bitmap with the capture</returns>
|
||||
private static void drawDocument(DocumentContainer documentContainer, WindowDetails contentWindowDetails, Graphics graphicsTarget) {
|
||||
documentContainer.setAttribute("scroll", 1);
|
||||
private static void DrawDocument(DocumentContainer documentContainer, WindowDetails contentWindowDetails, Graphics graphicsTarget) {
|
||||
documentContainer.SetAttribute("scroll", 1);
|
||||
|
||||
//Get Browser Window Width & Height
|
||||
int pageWidth = documentContainer.ScrollWidth;
|
||||
|
@ -621,14 +622,14 @@ namespace Greenshot.Helpers {
|
|||
Point targetOffset = new Point();
|
||||
|
||||
// Loop of the pages and make a copy of the visible viewport
|
||||
while ((horizontalPage * viewportWidth) < pageWidth) {
|
||||
while (horizontalPage * viewportWidth < pageWidth) {
|
||||
// Scroll to location
|
||||
documentContainer.ScrollLeft = viewportWidth * horizontalPage;
|
||||
targetOffset.X = documentContainer.ScrollLeft;
|
||||
|
||||
// Variable used for looping vertically
|
||||
int verticalPage = 0;
|
||||
while ((verticalPage * viewportHeight) < pageHeight) {
|
||||
while (verticalPage * viewportHeight < pageHeight) {
|
||||
// Scroll to location
|
||||
documentContainer.ScrollTop = viewportHeight * verticalPage;
|
||||
//Shoot visible window
|
||||
|
|
|
@ -26,33 +26,31 @@ using System.Runtime.InteropServices;
|
|||
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.Interop.IE;
|
||||
using Greenshot.IniFile;
|
||||
using log4net;
|
||||
using IServiceProvider = Greenshot.Interop.IServiceProvider;
|
||||
|
||||
namespace Greenshot.Helpers.IEInterop {
|
||||
public class DocumentContainer {
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(DocumentContainer));
|
||||
private static CoreConfiguration configuration = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(DocumentContainer));
|
||||
private const int E_ACCESSDENIED = unchecked((int)0x80070005L);
|
||||
private static readonly Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
|
||||
private static readonly Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E");
|
||||
private static int counter = 0;
|
||||
private int id = counter++;
|
||||
private IHTMLDocument2 document2;
|
||||
private IHTMLDocument3 document3;
|
||||
private Point sourceLocation;
|
||||
private Point destinationLocation;
|
||||
private Point startLocation = Point.Empty;
|
||||
private Rectangle viewportRectangle = Rectangle.Empty;
|
||||
private string name = null;
|
||||
private string url;
|
||||
private bool isDTD;
|
||||
private DocumentContainer parent;
|
||||
private WindowDetails contentWindow;
|
||||
private double zoomLevelX = 1;
|
||||
private double zoomLevelY = 1;
|
||||
private List<DocumentContainer> frames = new List<DocumentContainer>();
|
||||
private static int _counter;
|
||||
private readonly int _id = _counter++;
|
||||
private IHTMLDocument2 _document2;
|
||||
private IHTMLDocument3 _document3;
|
||||
private Point _sourceLocation;
|
||||
private Point _destinationLocation;
|
||||
private Point _startLocation = Point.Empty;
|
||||
private Rectangle _viewportRectangle = Rectangle.Empty;
|
||||
private string _name;
|
||||
private string _url;
|
||||
private bool _isDtd;
|
||||
private DocumentContainer _parent;
|
||||
private WindowDetails _contentWindow;
|
||||
private double _zoomLevelX = 1;
|
||||
private double _zoomLevelY = 1;
|
||||
private readonly IList<DocumentContainer> _frames = new List<DocumentContainer>();
|
||||
|
||||
private DocumentContainer(IHTMLWindow2 frameWindow, WindowDetails contentWindow, DocumentContainer parent) {
|
||||
//IWebBrowser2 webBrowser2 = frame as IWebBrowser2;
|
||||
|
@ -60,22 +58,22 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
IHTMLDocument2 document2 = GetDocumentFromWindow(frameWindow);
|
||||
try {
|
||||
LOG.DebugFormat("frameWindow.name {0}", frameWindow.name);
|
||||
name = frameWindow.name;
|
||||
_name = frameWindow.name;
|
||||
} catch {
|
||||
|
||||
// Ignore
|
||||
}
|
||||
try {
|
||||
LOG.DebugFormat("document2.url {0}",document2.url);
|
||||
} catch {
|
||||
|
||||
// Ignore
|
||||
}
|
||||
try {
|
||||
LOG.DebugFormat("document2.title {0}", document2.title);
|
||||
} catch {
|
||||
|
||||
// Ignore
|
||||
}
|
||||
|
||||
this.parent = parent;
|
||||
_parent = parent;
|
||||
// Calculate startLocation for the frames
|
||||
IHTMLWindow2 window2 = document2.parentWindow;
|
||||
IHTMLWindow3 window3 = (IHTMLWindow3)window2;
|
||||
|
@ -87,13 +85,13 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
releaseCom(window2);
|
||||
releaseCom(window3);
|
||||
|
||||
startLocation = new Point(x, y);
|
||||
_startLocation = new Point(x, y);
|
||||
Init(document2, contentWindow);
|
||||
}
|
||||
|
||||
public DocumentContainer(IHTMLDocument2 document2, WindowDetails contentWindow) {
|
||||
Init(document2, contentWindow);
|
||||
LOG.DebugFormat("Creating DocumentContainer for Document {0} found in window with rectangle {1}", name, SourceRectangle);
|
||||
LOG.DebugFormat("Creating DocumentContainer for Document {0} found in window with rectangle {1}", _name, SourceRectangle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -112,17 +110,17 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
/// <param name="document2">IHTMLDocument2</param>
|
||||
/// <param name="contentWindow">WindowDetails</param>
|
||||
private void Init(IHTMLDocument2 document2, WindowDetails contentWindow) {
|
||||
this.document2 = document2;
|
||||
this.contentWindow = contentWindow;
|
||||
document3 = document2 as IHTMLDocument3;
|
||||
_document2 = document2;
|
||||
_contentWindow = contentWindow;
|
||||
_document3 = document2 as IHTMLDocument3;
|
||||
// Check what access method is needed for the document
|
||||
IHTMLDocument5 document5 = (IHTMLDocument5)document2;
|
||||
|
||||
//compatibility mode affects how height is computed
|
||||
isDTD = false;
|
||||
_isDtd = false;
|
||||
try {
|
||||
if ((document3.documentElement != null) && (!document5.compatMode.Equals("BackCompat"))) {
|
||||
isDTD = true;
|
||||
if (_document3 != null && (_document3.documentElement != null) && !document5.compatMode.Equals("BackCompat")) {
|
||||
_isDtd = true;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.Error("Error checking the compatibility mode:");
|
||||
|
@ -133,21 +131,21 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
Rectangle clientRectangle = contentWindow.WindowRectangle;
|
||||
try {
|
||||
IHTMLWindow2 window2 = (IHTMLWindow2)document2.parentWindow;
|
||||
IHTMLWindow2 window2 = document2.parentWindow;
|
||||
//IHTMLWindow3 window3 = (IHTMLWindow3)document2.parentWindow;
|
||||
IHTMLScreen screen = window2.screen;
|
||||
IHTMLScreen2 screen2 = (IHTMLScreen2)screen;
|
||||
if (parent != null) {
|
||||
if (_parent != null) {
|
||||
// Copy parent values
|
||||
zoomLevelX = parent.zoomLevelX;
|
||||
zoomLevelY = parent.zoomLevelY;
|
||||
viewportRectangle = parent.viewportRectangle;
|
||||
_zoomLevelX = _parent._zoomLevelX;
|
||||
_zoomLevelY = _parent._zoomLevelY;
|
||||
_viewportRectangle = _parent._viewportRectangle;
|
||||
} else {
|
||||
//DisableScrollbars(document2);
|
||||
|
||||
// Calculate zoom level
|
||||
zoomLevelX = (double)screen2.deviceXDPI/(double)screen2.logicalXDPI;
|
||||
zoomLevelY = (double)screen2.deviceYDPI/(double)screen2.logicalYDPI;
|
||||
_zoomLevelX = screen2.deviceXDPI/(double)screen2.logicalXDPI;
|
||||
_zoomLevelY = screen2.deviceYDPI/(double)screen2.logicalYDPI;
|
||||
|
||||
|
||||
// Calculate the viewport rectangle, needed if there is a frame around the html window
|
||||
|
@ -162,11 +160,11 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
if ((diffX == 4 || diffX >= 20) && (diffY == 4 || diffY >= 20)) {
|
||||
Point viewportOffset = new Point(2, 2);
|
||||
Size viewportSize = new Size(ClientWidth, ClientHeight);
|
||||
viewportRectangle = new Rectangle(viewportOffset, viewportSize);
|
||||
LOG.DebugFormat("viewportRect {0}", viewportRectangle);
|
||||
_viewportRectangle = new Rectangle(viewportOffset, viewportSize);
|
||||
LOG.DebugFormat("viewportRect {0}", _viewportRectangle);
|
||||
}
|
||||
}
|
||||
LOG.DebugFormat("Zoomlevel {0}, {1}", zoomLevelX, zoomLevelY);
|
||||
LOG.DebugFormat("Zoomlevel {0}, {1}", _zoomLevelX, _zoomLevelY);
|
||||
// Release com objects
|
||||
releaseCom(window2);
|
||||
releaseCom(screen);
|
||||
|
@ -177,23 +175,23 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
|
||||
try {
|
||||
LOG.DebugFormat("Calculated location {0} for {1}", startLocation, document2.title);
|
||||
if (name == null) {
|
||||
name = document2.title;
|
||||
LOG.DebugFormat("Calculated location {0} for {1}", _startLocation, document2.title);
|
||||
if (_name == null) {
|
||||
_name = document2.title;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.Warn("Problem while trying to get document title!", e);
|
||||
}
|
||||
|
||||
try {
|
||||
url = document2.url;
|
||||
_url = document2.url;
|
||||
} catch (Exception e) {
|
||||
LOG.Warn("Problem while trying to get document url!", e);
|
||||
}
|
||||
sourceLocation = new Point(ScaleX((int)startLocation.X), ScaleY((int)startLocation.Y));
|
||||
destinationLocation = new Point(ScaleX((int)startLocation.X), ScaleY((int)startLocation.Y));
|
||||
_sourceLocation = new Point(ScaleX(_startLocation.X), ScaleY(_startLocation.Y));
|
||||
_destinationLocation = new Point(ScaleX(_startLocation.X), ScaleY(_startLocation.Y));
|
||||
|
||||
if (parent != null) {
|
||||
if (_parent != null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
@ -203,9 +201,9 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
IHTMLWindow2 frameWindow = frameCollection.item(frame);
|
||||
DocumentContainer frameData = new DocumentContainer(frameWindow, contentWindow, this);
|
||||
// check if frame is hidden
|
||||
if (!frameData.isHidden) {
|
||||
LOG.DebugFormat("Creating DocumentContainer for Frame {0} found in window with rectangle {1}", frameData.name, frameData.SourceRectangle);
|
||||
frames.Add(frameData);
|
||||
if (!frameData.IsHidden) {
|
||||
LOG.DebugFormat("Creating DocumentContainer for Frame {0} found in window with rectangle {1}", frameData._name, frameData.SourceRectangle);
|
||||
_frames.Add(frameData);
|
||||
} else {
|
||||
LOG.DebugFormat("Skipping frame {0}", frameData.Name);
|
||||
}
|
||||
|
@ -223,7 +221,7 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
try {
|
||||
// Correct iframe locations
|
||||
foreach (IHTMLElement frameElement in document3.getElementsByTagName("IFRAME")) {
|
||||
foreach (IHTMLElement frameElement in _document3.getElementsByTagName("IFRAME")) {
|
||||
try {
|
||||
CorrectFrameLocations(frameElement);
|
||||
// Clean up frameElement
|
||||
|
@ -264,7 +262,7 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
// Release IHTMLRect
|
||||
releaseCom(rec);
|
||||
LOG.DebugFormat("Looking for iframe to correct at {0}", elementBoundingLocation);
|
||||
foreach(DocumentContainer foundFrame in frames) {
|
||||
foreach(DocumentContainer foundFrame in _frames) {
|
||||
Point frameLocation = foundFrame.SourceLocation;
|
||||
if (frameLocation.Equals(elementBoundingLocation)) {
|
||||
// Match found, correcting location
|
||||
|
@ -313,13 +311,13 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
IServiceProvider sp = (IServiceProvider)htmlWindow;
|
||||
|
||||
// Use IServiceProvider.QueryService to get IWebBrowser2 object.
|
||||
Object brws = null;
|
||||
object brws;
|
||||
Guid webBrowserApp = IID_IWebBrowserApp;
|
||||
Guid webBrowser2 = IID_IWebBrowser2;
|
||||
sp.QueryService(ref webBrowserApp, ref webBrowser2, out brws);
|
||||
|
||||
// Get the document from IWebBrowser2.
|
||||
IWebBrowser2 browser = (IWebBrowser2)(brws);
|
||||
IWebBrowser2 browser = (IWebBrowser2)brws;
|
||||
|
||||
return (IHTMLDocument2)browser.Document;
|
||||
} catch (Exception ex2) {
|
||||
|
@ -331,9 +329,9 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
public Color BackgroundColor {
|
||||
get {
|
||||
try {
|
||||
string bgColor = (string)document2.bgColor;
|
||||
string bgColor = (string)_document2.bgColor;
|
||||
if (bgColor != null) {
|
||||
int rgbInt = Int32.Parse(bgColor.Substring(1), NumberStyles.HexNumber);
|
||||
int rgbInt = int.Parse(bgColor.Substring(1), NumberStyles.HexNumber);
|
||||
return Color.FromArgb(rgbInt >> 16, (rgbInt >> 8) & 255, rgbInt & 255);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
@ -345,46 +343,46 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
public Rectangle ViewportRectangle {
|
||||
get {
|
||||
return viewportRectangle;
|
||||
return _viewportRectangle;
|
||||
}
|
||||
}
|
||||
|
||||
public WindowDetails ContentWindow {
|
||||
get {
|
||||
return contentWindow;
|
||||
return _contentWindow;
|
||||
}
|
||||
}
|
||||
|
||||
public DocumentContainer Parent {
|
||||
get {
|
||||
return parent;
|
||||
return _parent;
|
||||
}
|
||||
set {
|
||||
parent = value;
|
||||
_parent = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int ScaleX(int physicalValue) {
|
||||
return (int)Math.Round(physicalValue * zoomLevelX, MidpointRounding.AwayFromZero);
|
||||
return (int)Math.Round(physicalValue * _zoomLevelX, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
private int ScaleY(int physicalValue) {
|
||||
return (int)Math.Round(physicalValue * zoomLevelY, MidpointRounding.AwayFromZero);
|
||||
return (int)Math.Round(physicalValue * _zoomLevelY, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
private int UnscaleX(int physicalValue) {
|
||||
return (int)Math.Round(physicalValue / zoomLevelX, MidpointRounding.AwayFromZero);
|
||||
return (int)Math.Round(physicalValue / _zoomLevelX, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
private int UnscaleY(int physicalValue) {
|
||||
return (int)Math.Round(physicalValue / zoomLevelY, MidpointRounding.AwayFromZero);
|
||||
return (int)Math.Round(physicalValue / _zoomLevelY, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set/change an int attribute on a document
|
||||
/// </summary>
|
||||
public void setAttribute(string attribute, int value) {
|
||||
setAttribute(attribute, value.ToString());
|
||||
public void SetAttribute(string attribute, int value) {
|
||||
SetAttribute(attribute, value.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -392,14 +390,12 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
/// </summary>
|
||||
/// <param name="attribute">Attribute to set</param>
|
||||
/// <param name="value">Value to set</param>
|
||||
/// <param name="document2">The IHTMLDocument2</param>
|
||||
/// <param name="document3">The IHTMLDocument3</param>
|
||||
public void setAttribute(string attribute, string value) {
|
||||
public void SetAttribute(string attribute, string value) {
|
||||
IHTMLElement element = null;
|
||||
if (!isDTD) {
|
||||
element = document2.body;
|
||||
if (!_isDtd) {
|
||||
element = _document2.body;
|
||||
} else {
|
||||
element = document3.documentElement;
|
||||
element = _document3.documentElement;
|
||||
}
|
||||
element.setAttribute(attribute, value, 1);
|
||||
// Release IHTMLElement com object
|
||||
|
@ -410,18 +406,15 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
/// Get the attribute from a document
|
||||
/// </summary>
|
||||
/// <param name="attribute">Attribute to get</param>
|
||||
/// <param name="document2">The IHTMLDocument2</param>
|
||||
/// <param name="document3">The IHTMLDocument3</param>
|
||||
/// <returns>object with the attribute value</returns>
|
||||
public object getAttribute(string attribute) {
|
||||
IHTMLElement element = null;
|
||||
object retVal = 0;
|
||||
if (!isDTD) {
|
||||
element = document2.body;
|
||||
public object GetAttribute(string attribute) {
|
||||
IHTMLElement element;
|
||||
if (!_isDtd) {
|
||||
element = _document2.body;
|
||||
} else {
|
||||
element = document3.documentElement;
|
||||
element = _document3.documentElement;
|
||||
}
|
||||
retVal = element.getAttribute(attribute, 1);
|
||||
var retVal = element.getAttribute(attribute, 1);
|
||||
// Release IHTMLElement com object
|
||||
releaseCom(element);
|
||||
return retVal;
|
||||
|
@ -430,30 +423,30 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
/// <summary>
|
||||
/// Get the attribute as int from a document
|
||||
/// </summary>
|
||||
public int getAttributeAsInt(string attribute) {
|
||||
int retVal = (int)getAttribute(attribute);
|
||||
public int GetAttributeAsInt(string attribute) {
|
||||
int retVal = (int)GetAttribute(attribute);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public int ID {
|
||||
get {
|
||||
return id;
|
||||
return _id;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get {
|
||||
return name;
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
|
||||
public string Url {
|
||||
get {
|
||||
return url;
|
||||
return _url;
|
||||
}
|
||||
}
|
||||
|
||||
public bool isHidden {
|
||||
public bool IsHidden {
|
||||
get {
|
||||
return ClientWidth == 0 || ClientHeight == 0;
|
||||
}
|
||||
|
@ -461,34 +454,34 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
public int ClientWidth {
|
||||
get {
|
||||
return ScaleX(getAttributeAsInt("clientWidth"));
|
||||
return ScaleX(GetAttributeAsInt("clientWidth"));
|
||||
}
|
||||
}
|
||||
|
||||
public int ClientHeight {
|
||||
get {
|
||||
return ScaleY(getAttributeAsInt("clientHeight"));
|
||||
return ScaleY(GetAttributeAsInt("clientHeight"));
|
||||
}
|
||||
}
|
||||
|
||||
public int ScrollWidth {
|
||||
get {
|
||||
return ScaleX(getAttributeAsInt("scrollWidth"));
|
||||
return ScaleX(GetAttributeAsInt("scrollWidth"));
|
||||
}
|
||||
}
|
||||
|
||||
public int ScrollHeight {
|
||||
get {
|
||||
return ScaleY(getAttributeAsInt("scrollHeight"));
|
||||
return ScaleY(GetAttributeAsInt("scrollHeight"));
|
||||
}
|
||||
}
|
||||
|
||||
public Point SourceLocation {
|
||||
get {
|
||||
return sourceLocation;
|
||||
return _sourceLocation;
|
||||
}
|
||||
set {
|
||||
sourceLocation = value;
|
||||
_sourceLocation = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -506,34 +499,34 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
public int SourceLeft {
|
||||
get {
|
||||
return sourceLocation.X;
|
||||
return _sourceLocation.X;
|
||||
}
|
||||
}
|
||||
|
||||
public int SourceTop {
|
||||
get {
|
||||
return sourceLocation.Y;
|
||||
return _sourceLocation.Y;
|
||||
}
|
||||
}
|
||||
|
||||
public int SourceRight {
|
||||
get {
|
||||
return sourceLocation.X + ClientWidth;
|
||||
return _sourceLocation.X + ClientWidth;
|
||||
}
|
||||
}
|
||||
|
||||
public int SourceBottom {
|
||||
get {
|
||||
return sourceLocation.Y + ClientHeight;
|
||||
return _sourceLocation.Y + ClientHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public Point DestinationLocation {
|
||||
get {
|
||||
return destinationLocation;
|
||||
return _destinationLocation;
|
||||
}
|
||||
set {
|
||||
destinationLocation = value;
|
||||
_destinationLocation = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -552,55 +545,55 @@ namespace Greenshot.Helpers.IEInterop {
|
|||
|
||||
public int DestinationLeft {
|
||||
get {
|
||||
return destinationLocation.X;
|
||||
return _destinationLocation.X;
|
||||
}
|
||||
set {
|
||||
destinationLocation.X = value;
|
||||
_destinationLocation.X = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int DestinationTop {
|
||||
get {
|
||||
return destinationLocation.Y;
|
||||
return _destinationLocation.Y;
|
||||
}
|
||||
set {
|
||||
destinationLocation.Y = value;
|
||||
_destinationLocation.Y = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int DestinationRight {
|
||||
get {
|
||||
return destinationLocation.X + ScrollWidth;
|
||||
return _destinationLocation.X + ScrollWidth;
|
||||
}
|
||||
}
|
||||
|
||||
public int DestinationBottom {
|
||||
get {
|
||||
return destinationLocation.Y + ScrollHeight;
|
||||
return _destinationLocation.Y + ScrollHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public int ScrollLeft {
|
||||
get{
|
||||
return ScaleX(getAttributeAsInt("scrollLeft"));
|
||||
return ScaleX(GetAttributeAsInt("scrollLeft"));
|
||||
}
|
||||
set {
|
||||
setAttribute("scrollLeft", UnscaleX(value));
|
||||
SetAttribute("scrollLeft", UnscaleX(value));
|
||||
}
|
||||
}
|
||||
|
||||
public int ScrollTop {
|
||||
get{
|
||||
return ScaleY(getAttributeAsInt("scrollTop"));
|
||||
return ScaleY(GetAttributeAsInt("scrollTop"));
|
||||
}
|
||||
set {
|
||||
setAttribute("scrollTop", UnscaleY(value));
|
||||
SetAttribute("scrollTop", UnscaleY(value));
|
||||
}
|
||||
}
|
||||
|
||||
public List<DocumentContainer> Frames {
|
||||
public IList<DocumentContainer> Frames {
|
||||
get {
|
||||
return frames;
|
||||
return _frames;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,9 +97,9 @@ namespace Greenshot.Helpers {
|
|||
private class MapiFileDescriptor {
|
||||
public int reserved = 0;
|
||||
public int flags = 0;
|
||||
public int position = 0;
|
||||
public string path = null;
|
||||
public string name = null;
|
||||
public int position;
|
||||
public string path;
|
||||
public string name;
|
||||
public IntPtr type = IntPtr.Zero;
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,8 @@ namespace Greenshot.Helpers {
|
|||
/// <summary>
|
||||
/// Specifies the valid RecipientTypes for a Recipient.
|
||||
/// </summary>
|
||||
public enum RecipientType : int {
|
||||
public enum RecipientType
|
||||
{
|
||||
/// <summary>
|
||||
/// Recipient will be in the TO list.
|
||||
/// </summary>
|
||||
|
@ -497,25 +498,25 @@ namespace Greenshot.Helpers {
|
|||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class MapiMessage {
|
||||
public int Reserved = 0;
|
||||
public string Subject = null;
|
||||
public string NoteText = null;
|
||||
public string Subject;
|
||||
public string NoteText;
|
||||
public string MessageType = null;
|
||||
public string DateReceived = null;
|
||||
public string ConversationID = null;
|
||||
public int Flags = 0;
|
||||
public IntPtr Originator = IntPtr.Zero;
|
||||
public int RecipientCount = 0;
|
||||
public int RecipientCount;
|
||||
public IntPtr Recipients = IntPtr.Zero;
|
||||
public int FileCount = 0;
|
||||
public int FileCount;
|
||||
public IntPtr Files = IntPtr.Zero;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public class MapiRecipDesc {
|
||||
public int Reserved = 0;
|
||||
public int RecipientClass = 0;
|
||||
public string Name = null;
|
||||
public string Address = null;
|
||||
public int RecipientClass;
|
||||
public string Name;
|
||||
public string Address;
|
||||
public int eIDSize = 0;
|
||||
public IntPtr EntryID = IntPtr.Zero;
|
||||
}
|
||||
|
@ -542,12 +543,12 @@ namespace Greenshot.Helpers {
|
|||
/// <summary>
|
||||
/// The email address of this recipient.
|
||||
/// </summary>
|
||||
public string Address = null;
|
||||
public string Address;
|
||||
|
||||
/// <summary>
|
||||
/// The display name of this recipient.
|
||||
/// </summary>
|
||||
public string DisplayName = null;
|
||||
public string DisplayName;
|
||||
|
||||
/// <summary>
|
||||
/// How the recipient will receive this message (To, CC, BCC).
|
||||
|
|
|
@ -36,12 +36,12 @@ namespace Greenshot.Helpers {
|
|||
[Serializable]
|
||||
public class PluginHelper : IGreenshotHost {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(PluginHelper));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static readonly CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
private static string pluginPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),Application.ProductName);
|
||||
private static string applicationPath = Path.GetDirectoryName(Application.ExecutablePath);
|
||||
private static string pafPath = Path.Combine(Application.StartupPath, @"App\Greenshot");
|
||||
private static IDictionary<PluginAttribute, IGreenshotPlugin> plugins = new SortedDictionary<PluginAttribute, IGreenshotPlugin>();
|
||||
private static readonly string pluginPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),Application.ProductName);
|
||||
private static readonly string applicationPath = Path.GetDirectoryName(Application.ExecutablePath);
|
||||
private static readonly string pafPath = Path.Combine(Application.StartupPath, @"App\Greenshot");
|
||||
private static readonly IDictionary<PluginAttribute, IGreenshotPlugin> plugins = new SortedDictionary<PluginAttribute, IGreenshotPlugin>();
|
||||
private static readonly PluginHelper instance = new PluginHelper();
|
||||
public static PluginHelper Instance {
|
||||
get {
|
||||
|
@ -66,7 +66,7 @@ namespace Greenshot.Helpers {
|
|||
}
|
||||
|
||||
public bool HasPlugins() {
|
||||
return (plugins != null && plugins.Count > 0);
|
||||
return plugins != null && plugins.Count > 0;
|
||||
}
|
||||
|
||||
public void Shutdown() {
|
||||
|
|
|
@ -37,10 +37,10 @@ namespace Greenshot.Helpers {
|
|||
/// </summary>
|
||||
public class PrintHelper : IDisposable {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(PrintHelper));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static readonly CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
private ISurface surface;
|
||||
private ICaptureDetails captureDetails;
|
||||
private readonly ICaptureDetails captureDetails;
|
||||
private PrintDocument printDocument = new PrintDocument();
|
||||
private PrintDialog printDialog = new PrintDialog();
|
||||
|
||||
|
@ -218,7 +218,7 @@ namespace Greenshot.Helpers {
|
|||
if (conf.OutputPrintFooter) {
|
||||
//printRect = new RectangleF(0, 0, printRect.Width, printRect.Height - (dateStringHeight * 2));
|
||||
using (Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)) {
|
||||
e.Graphics.DrawString(footerString, f, Brushes.Black, pageRect.Width / 2 - (footerStringWidth / 2), pageRect.Height);
|
||||
e.Graphics.DrawString(footerString, f, Brushes.Black, pageRect.Width / 2 - footerStringWidth / 2, pageRect.Height);
|
||||
}
|
||||
}
|
||||
e.Graphics.DrawImage(image, printRect, imageRect, GraphicsUnit.Pixel);
|
||||
|
|
|
@ -30,8 +30,8 @@ namespace Greenshot.Helpers {
|
|||
/// Description of ProcessorHelper.
|
||||
/// </summary>
|
||||
public static class ProcessorHelper {
|
||||
private static ILog LOG = LogManager.GetLogger(typeof(ProcessorHelper));
|
||||
private static Dictionary<string, IProcessor> RegisteredProcessors = new Dictionary<string, IProcessor>();
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(ProcessorHelper));
|
||||
private static readonly Dictionary<string, IProcessor> RegisteredProcessors = new Dictionary<string, IProcessor>();
|
||||
|
||||
/// Initialize the Processors
|
||||
static ProcessorHelper() {
|
||||
|
|
|
@ -22,7 +22,6 @@ using System;
|
|||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using Greenshot.Drawing;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Helpers {
|
||||
/// <summary>
|
||||
|
@ -45,9 +44,7 @@ namespace Greenshot.Helpers {
|
|||
/// </summary>
|
||||
Rational = 0x02
|
||||
}
|
||||
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(ScaleHelper));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// calculates the Size an element must be resized to, in order to fit another element, keeping aspect ratio
|
||||
/// </summary>
|
||||
|
@ -77,7 +74,7 @@ namespace Greenshot.Helpers {
|
|||
newRect.X = (targetRect.Width - currentRect.Width) / 2;
|
||||
break;
|
||||
case ContentAlignment.TopRight:
|
||||
newRect.X = (targetRect.Width - currentRect.Width);
|
||||
newRect.X = targetRect.Width - currentRect.Width;
|
||||
break;
|
||||
case ContentAlignment.MiddleLeft:
|
||||
newRect.Y = (targetRect.Height - currentRect.Height) / 2;
|
||||
|
@ -88,18 +85,18 @@ namespace Greenshot.Helpers {
|
|||
break;
|
||||
case ContentAlignment.MiddleRight:
|
||||
newRect.Y = (targetRect.Height - currentRect.Height) / 2;
|
||||
newRect.X = (targetRect.Width - currentRect.Width);
|
||||
newRect.X = targetRect.Width - currentRect.Width;
|
||||
break;
|
||||
case ContentAlignment.BottomLeft:
|
||||
newRect.Y = (targetRect.Height - currentRect.Height);
|
||||
newRect.Y = targetRect.Height - currentRect.Height;
|
||||
break;
|
||||
case ContentAlignment.BottomCenter:
|
||||
newRect.Y = (targetRect.Height - currentRect.Height);
|
||||
newRect.Y = targetRect.Height - currentRect.Height;
|
||||
newRect.X = (targetRect.Width - currentRect.Width) / 2;
|
||||
break;
|
||||
case ContentAlignment.BottomRight:
|
||||
newRect.Y = (targetRect.Height - currentRect.Height);
|
||||
newRect.X = (targetRect.Width - currentRect.Width);
|
||||
newRect.Y = targetRect.Height - currentRect.Height;
|
||||
newRect.X = targetRect.Width - currentRect.Width;
|
||||
break;
|
||||
}
|
||||
return newRect;
|
||||
|
@ -323,7 +320,7 @@ namespace Greenshot.Helpers {
|
|||
/// <returns>the current ScaleOptions depending on modifier keys held down</returns>
|
||||
public static ScaleOptions GetScaleOptions() {
|
||||
bool anchorAtCenter = (Control.ModifierKeys & Keys.Control) != 0;
|
||||
bool maintainAspectRatio = ((Control.ModifierKeys & Keys.Shift) != 0);
|
||||
bool maintainAspectRatio = (Control.ModifierKeys & Keys.Shift) != 0;
|
||||
ScaleOptions opts = ScaleOptions.Default;
|
||||
if(anchorAtCenter) opts |= ScaleOptions.Centered;
|
||||
if(maintainAspectRatio) opts |= ScaleOptions.Rational;
|
||||
|
@ -349,7 +346,7 @@ namespace Greenshot.Helpers {
|
|||
}
|
||||
}
|
||||
public class FixedAngleRoundBehavior : IDoubleProcessor {
|
||||
private double fixedAngle;
|
||||
private readonly double fixedAngle;
|
||||
public FixedAngleRoundBehavior(double fixedAngle) {
|
||||
this.fixedAngle = fixedAngle;
|
||||
}
|
||||
|
|
|
@ -39,27 +39,27 @@ namespace Greenshot.Helpers {
|
|||
/// </summary>
|
||||
public static class SoundHelper {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(SoundHelper));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static GCHandle? gcHandle = null;
|
||||
private static byte[] soundBuffer = null;
|
||||
private static readonly CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static GCHandle? _gcHandle;
|
||||
private static byte[] _soundBuffer;
|
||||
|
||||
public static void Initialize() {
|
||||
if (gcHandle == null) {
|
||||
if (_gcHandle == null) {
|
||||
try {
|
||||
ResourceManager resources = new ResourceManager("Greenshot.Sounds", Assembly.GetExecutingAssembly());
|
||||
soundBuffer = (byte[])resources.GetObject("camera");
|
||||
_soundBuffer = (byte[])resources.GetObject("camera");
|
||||
|
||||
if (conf.NotificationSound != null && conf.NotificationSound.EndsWith(".wav")) {
|
||||
try {
|
||||
if (File.Exists(conf.NotificationSound)) {
|
||||
soundBuffer = File.ReadAllBytes(conf.NotificationSound);
|
||||
_soundBuffer = File.ReadAllBytes(conf.NotificationSound);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.WarnFormat("couldn't load {0}: {1}", conf.NotificationSound, ex.Message);
|
||||
}
|
||||
}
|
||||
// Pin sound so it can't be moved by the Garbage Collector, this was the cause for the bad sound
|
||||
gcHandle = GCHandle.Alloc(soundBuffer, GCHandleType.Pinned);
|
||||
_gcHandle = GCHandle.Alloc(_soundBuffer, GCHandleType.Pinned);
|
||||
} catch (Exception e) {
|
||||
LOG.Error("Error initializing.", e);
|
||||
}
|
||||
|
@ -67,11 +67,11 @@ namespace Greenshot.Helpers {
|
|||
}
|
||||
|
||||
public static void Play() {
|
||||
if (soundBuffer != null) {
|
||||
if (_soundBuffer != null) {
|
||||
//Thread playSoundThread = new Thread(delegate() {
|
||||
SoundFlags flags = SoundFlags.SND_ASYNC | SoundFlags.SND_MEMORY | SoundFlags.SND_NOWAIT | SoundFlags.SND_NOSTOP;
|
||||
try {
|
||||
WinMM.PlaySound(gcHandle.Value.AddrOfPinnedObject(), (UIntPtr)0, (uint)flags);
|
||||
WinMM.PlaySound(_gcHandle.Value.AddrOfPinnedObject(), (UIntPtr)0, (uint)flags);
|
||||
} catch (Exception e) {
|
||||
LOG.Error("Error in play.", e);
|
||||
}
|
||||
|
@ -84,10 +84,10 @@ namespace Greenshot.Helpers {
|
|||
|
||||
public static void Deinitialize() {
|
||||
try {
|
||||
if (gcHandle != null) {
|
||||
if (_gcHandle != null) {
|
||||
WinMM.PlaySound((byte[])null, (UIntPtr)0, (uint)0);
|
||||
gcHandle.Value.Free();
|
||||
gcHandle = null;
|
||||
_gcHandle.Value.Free();
|
||||
_gcHandle = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.Error("Error in deinitialize.", e);
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Greenshot.Experimental {
|
|||
/// </summary>
|
||||
public static class UpdateHelper {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(UpdateHelper));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static readonly CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private const string STABLE_DOWNLOAD_LINK = "http://getgreenshot.org/downloads/";
|
||||
private const string VERSION_HISTORY_LINK = "http://getgreenshot.org/version-history/";
|
||||
private static readonly object LockObject = new object();
|
||||
|
|
|
@ -31,6 +31,6 @@ namespace Greenshot.Helpers {
|
|||
get { return _hwnd; }
|
||||
}
|
||||
|
||||
private IntPtr _hwnd;
|
||||
private readonly IntPtr _hwnd;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue