This commit fixes two bugs: BUG-1809 & BUG-1835 and adds somewhat better Windows 10 support.

This commit is contained in:
RKrom 2015-10-04 22:50:18 +02:00
parent 4290333997
commit a1769dbc66
7 changed files with 302 additions and 122 deletions

View file

@ -270,6 +270,9 @@ namespace Greenshot {
return;
}
// BUG-1809: Add message filter, to filter out all the InputLangChanged messages which go to a target control with a handle > 32 bit.
Application.AddMessageFilter(new WmInputLangChangeRequestFilter());
// From here on we continue starting Greenshot
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

View file

@ -18,30 +18,33 @@
* 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.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using GreenshotPlugin.UnmanagedHelpers;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
using Greenshot.Drawing;
using GreenshotPlugin.UnmanagedHelpers;
using log4net;
namespace Greenshot.Helpers {
namespace Greenshot.Helpers
{
/// <summary>
/// Description of EnvironmentInfo.
/// </summary>
public static class EnvironmentInfo {
public static class EnvironmentInfo
{
private static readonly ILog LOG = LogManager.GetLogger(typeof(EnvironmentInfo));
private static bool? isWindows = null;
public static bool IsWindows {
get {
if (isWindows.HasValue) {
public static bool IsWindows
{
get
{
if (isWindows.HasValue)
{
return isWindows.Value;
}
isWindows = Environment.OSVersion.Platform.ToString().StartsWith("Win");
@ -49,12 +52,14 @@ namespace Greenshot.Helpers {
}
}
public static bool IsNet45OrNewer() {
public static bool IsNet45OrNewer()
{
// Class "ReflectionContext" exists from .NET 4.5 onwards.
return Type.GetType("System.Reflection.ReflectionContext", false) != null;
}
public static string EnvironmentToString(bool newline) {
public static string EnvironmentToString(bool newline)
{
StringBuilder environment = new StringBuilder();
environment.Append("Software version: " + Application.ProductVersion);
if (IniConfig.IsPortable) {
@ -62,62 +67,89 @@ namespace Greenshot.Helpers {
}
environment.Append(" (" + OSInfo.Bits + " bit)");
if (newline) {
if (newline)
{
environment.AppendLine();
} else {
}
else
{
environment.Append(", ");
}
environment.Append(".NET runtime version: " + Environment.Version);
if (IsNet45OrNewer()) {
if (IsNet45OrNewer())
{
environment.Append("+");
}
if (newline) {
if (newline)
{
environment.AppendLine();
} else {
}
else
{
environment.Append(", ");
}
environment.Append("Time: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss zzz"));
if (IsWindows) {
if (newline) {
if (IsWindows)
{
if (newline)
{
environment.AppendLine();
} else {
}
else
{
environment.Append(", ");
}
environment.Append(String.Format("OS: {0} {1} {2} (x{3}) {4}", OSInfo.Name, OSInfo.Edition, OSInfo.ServicePack, OSInfo.Bits, OSInfo.VersionString));
if (newline) {
if (newline)
{
environment.AppendLine();
} else {
}
else
{
environment.Append(", ");
}
// Get some important information for fixing GDI related Problems
environment.Append("GDI object count: " + User32.GetGuiResourcesGDICount());
if (newline) {
environment.AppendFormat("GDI object count: {0}", User32.GetGuiResourcesGDICount());
if (newline)
{
environment.AppendLine();
} else {
}
else
{
environment.Append(", ");
}
environment.Append("User object count: " + User32.GetGuiResourcesUserCount());
} else {
if (newline) {
environment.AppendFormat("User object count: {0}", User32.GetGuiResourcesUserCount());
}
else
{
if (newline)
{
environment.AppendLine();
} else {
}
else
{
environment.Append(", ");
}
environment.Append("OS: " + Environment.OSVersion.Platform.ToString());
environment.AppendFormat("OS: {0}", Environment.OSVersion.Platform);
}
if (newline) {
if (newline)
{
environment.AppendLine();
} else {
}
else
{
environment.Append(", ");
}
environment.Append("Surface count: " + Surface.Count);
// TODO: Is this needed?
// environment.AppendFormat("Surface count: {0}", Surface.Count);
return environment.ToString();
}
public static string ExceptionToString(Exception ex) {
public static string ExceptionToString(Exception ex)
{
if (ex == null)
return "null\r\n";
@ -125,44 +157,54 @@ namespace Greenshot.Helpers {
report.AppendLine("Exception: " + ex.GetType().ToString());
report.AppendLine("Message: " + ex.Message);
if (ex.Data != null && ex.Data.Count > 0) {
if (ex.Data != null && ex.Data.Count > 0)
{
report.AppendLine();
report.AppendLine("Additional Information:");
foreach (object key in ex.Data.Keys) {
foreach (object key in ex.Data.Keys)
{
object data = ex.Data[key];
if (data != null) {
if (data != null)
{
report.AppendLine(key + " : " + data);
}
}
}
if (ex is ExternalException) {
if (ex is ExternalException)
{
// e.g. COMException
report.AppendLine().AppendLine("ErrorCode: 0x" + (ex as ExternalException).ErrorCode.ToString("X"));
}
report.AppendLine().AppendLine("Stack:").AppendLine(ex.StackTrace);
if (ex is ReflectionTypeLoadException) {
if (ex is ReflectionTypeLoadException)
{
report.AppendLine().AppendLine("LoaderExceptions: ");
foreach (Exception cbE in (ex as ReflectionTypeLoadException).LoaderExceptions) {
foreach (Exception cbE in (ex as ReflectionTypeLoadException).LoaderExceptions)
{
report.AppendLine(cbE.Message);
}
}
if (ex.InnerException != null) {
if (ex.InnerException != null)
{
report.AppendLine("--- InnerException: ---");
report.AppendLine(ExceptionToString(ex.InnerException));
}
return report.ToString();
}
public static string BuildReport(Exception exception) {
public static string BuildReport(Exception exception)
{
StringBuilder exceptionText = new StringBuilder();
exceptionText.AppendLine(EnvironmentToString(true));
exceptionText.AppendLine(ExceptionToString(exception));
exceptionText.AppendLine("Configuration dump:");
using (TextWriter writer = new StringWriter(exceptionText)) {
IniConfig.GetIniSection<CoreConfiguration>().Write(writer, true);
using (TextWriter writer = new StringWriter(exceptionText))
{
// TODO: Create summary of properties
//var iniConfig = IniConfig.Current.WriteToStreamAsync();
}
return exceptionText.ToString();
@ -173,13 +215,16 @@ 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 {
static public class OSInfo
{
#region BITS
/// <summary>
/// Determines if the current application is 32 or 64-bit.
/// </summary>
static public int Bits {
get {
static public int Bits
{
get
{
return IntPtr.Size * 8;
}
}
@ -190,9 +235,12 @@ namespace Greenshot.Helpers {
/// <summary>
/// Gets the edition of the operating system running on this computer.
/// </summary>
static public string Edition {
get {
if (s_Edition != null) {
static public string Edition
{
get
{
if (s_Edition != null)
{
return s_Edition; //***** RETURN *****//
}
@ -202,22 +250,30 @@ namespace Greenshot.Helpers {
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
if (GetVersionEx(ref osVersionInfo)) {
if (GetVersionEx(ref osVersionInfo))
{
int majorVersion = osVersion.Version.Major;
int minorVersion = osVersion.Version.Minor;
byte productType = osVersionInfo.wProductType;
short suiteMask = osVersionInfo.wSuiteMask;
#region VERSION 4
if (majorVersion == 4) {
if (productType == VER_NT_WORKSTATION) {
if (majorVersion == 4)
{
if (productType == VER_NT_WORKSTATION)
{
// Windows NT 4.0 Workstation
edition = "Workstation";
} else if (productType == VER_NT_SERVER) {
if ((suiteMask & VER_SUITE_ENTERPRISE) != 0) {
}
else if (productType == VER_NT_SERVER)
{
if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
{
// Windows NT 4.0 Server Enterprise
edition = "Enterprise Server";
} else {
}
else
{
// Windows NT 4.0 Server
edition = "Standard Server";
}
@ -226,38 +282,60 @@ namespace Greenshot.Helpers {
#endregion VERSION 4
#region VERSION 5
else if (majorVersion == 5) {
if (productType == VER_NT_WORKSTATION) {
if ((suiteMask & VER_SUITE_PERSONAL) != 0) {
else if (majorVersion == 5)
{
if (productType == VER_NT_WORKSTATION)
{
if ((suiteMask & VER_SUITE_PERSONAL) != 0)
{
// Windows XP Home Edition
edition = "Home";
} else {
}
else
{
// Windows XP / Windows 2000 Professional
edition = "Professional";
}
} else if (productType == VER_NT_SERVER) {
if (minorVersion == 0) {
if ((suiteMask & VER_SUITE_DATACENTER) != 0) {
}
else if (productType == VER_NT_SERVER)
{
if (minorVersion == 0)
{
if ((suiteMask & VER_SUITE_DATACENTER) != 0)
{
// Windows 2000 Datacenter Server
edition = "Datacenter Server";
} else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0) {
}
else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
{
// Windows 2000 Advanced Server
edition = "Advanced Server";
} else {
}
else
{
// Windows 2000 Server
edition = "Server";
}
} else {
if ((suiteMask & VER_SUITE_DATACENTER) != 0) {
}
else
{
if ((suiteMask & VER_SUITE_DATACENTER) != 0)
{
// Windows Server 2003 Datacenter Edition
edition = "Datacenter";
} else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0) {
}
else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
{
// Windows Server 2003 Enterprise Edition
edition = "Enterprise";
} else if ((suiteMask & VER_SUITE_BLADE) != 0) {
}
else if ((suiteMask & VER_SUITE_BLADE) != 0)
{
// Windows Server 2003 Web Edition
edition = "Web Edition";
} else {
}
else
{
// Windows Server 2003 Standard Edition
edition = "Standard";
}
@ -267,10 +345,13 @@ namespace Greenshot.Helpers {
#endregion VERSION 5
#region VERSION 6
else if (majorVersion == 6) {
else if (majorVersion == 6)
{
int ed;
if (GetProductInfo(majorVersion, minorVersion, osVersionInfo.wServicePackMajor, osVersionInfo.wServicePackMinor, out ed)) {
switch (ed) {
if (GetProductInfo(majorVersion, minorVersion, osVersionInfo.wServicePackMajor, osVersionInfo.wServicePackMinor, out ed))
{
switch (ed)
{
case PRODUCT_BUSINESS:
edition = "Business";
break;
@ -399,9 +480,12 @@ namespace Greenshot.Helpers {
/// <summary>
/// Gets the name of the operating system running on this computer.
/// </summary>
static public string Name {
get {
if (s_Name != null) {
static public string Name
{
get
{
if (s_Name != null)
{
return s_Name; //***** RETURN *****//
}
@ -411,27 +495,37 @@ namespace Greenshot.Helpers {
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
if (GetVersionEx(ref osVersionInfo)) {
if (GetVersionEx(ref osVersionInfo))
{
int majorVersion = osVersion.Version.Major;
int minorVersion = osVersion.Version.Minor;
byte productType = osVersionInfo.wProductType;
short suiteMask = osVersionInfo.wSuiteMask;
switch (osVersion.Platform) {
switch (osVersion.Platform)
{
case PlatformID.Win32Windows:
if (majorVersion == 4) {
if (majorVersion == 4)
{
string csdVersion = osVersionInfo.szCSDVersion;
switch (minorVersion) {
switch (minorVersion)
{
case 0:
if (csdVersion == "B" || csdVersion == "C") {
if (csdVersion == "B" || csdVersion == "C")
{
name = "Windows 95 OSR2";
} else {
}
else
{
name = "Windows 95";
}
break;
case 10:
if (csdVersion == "A") {
if (csdVersion == "A")
{
name = "Windows 98 Second Edition";
} else {
}
else
{
name = "Windows 98";
}
break;
@ -442,12 +536,14 @@ namespace Greenshot.Helpers {
}
break;
case PlatformID.Win32NT:
switch (majorVersion) {
switch (majorVersion)
{
case 3:
name = "Windows NT 3.51";
break;
case 4:
switch (productType) {
switch (productType)
{
case 1:
name = "Windows NT 4.0";
break;
@ -457,12 +553,14 @@ namespace Greenshot.Helpers {
}
break;
case 5:
switch (minorVersion) {
switch (minorVersion)
{
case 0:
name = "Windows 2000";
break;
case 1:
switch (suiteMask) {
switch (suiteMask)
{
case 0x0200:
name = "Windows XP Professional";
break;
@ -472,7 +570,8 @@ namespace Greenshot.Helpers {
}
break;
case 2:
switch (suiteMask) {
switch (suiteMask)
{
case 0x0200:
name = "Windows XP Professional x64";
break;
@ -496,9 +595,11 @@ namespace Greenshot.Helpers {
}
break;
case 6:
switch (minorVersion) {
switch (minorVersion)
{
case 0:
switch (productType) {
switch (productType)
{
case 3:
name = "Windows Server 2008";
break;
@ -508,7 +609,8 @@ namespace Greenshot.Helpers {
}
break;
case 1:
switch (productType) {
switch (productType)
{
case 3:
name = "Windows Server 2008 R2";
break;
@ -520,8 +622,14 @@ namespace Greenshot.Helpers {
case 2:
name = "Windows 8";
break;
case 3:
name = "Windows 8.1";
break;
}
break;
case 10:
name = "Windows 10";
break;
}
break;
}
@ -553,7 +661,8 @@ namespace Greenshot.Helpers {
#region OSVERSIONINFOEX
[StructLayout(LayoutKind.Sequential)]
private struct OSVERSIONINFOEX {
private struct OSVERSIONINFOEX
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
@ -629,14 +738,17 @@ namespace Greenshot.Helpers {
/// <summary>
/// Gets the service pack information of the operating system running on this computer.
/// </summary>
static public string ServicePack {
get {
static public string ServicePack
{
get
{
string servicePack = String.Empty;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
if (GetVersionEx(ref osVersionInfo)) {
if (GetVersionEx(ref osVersionInfo))
{
servicePack = osVersionInfo.szCSDVersion;
}
@ -650,8 +762,10 @@ namespace Greenshot.Helpers {
/// <summary>
/// Gets the build version number of the operating system running on this computer.
/// </summary>
public static int BuildVersion {
get {
public static int BuildVersion
{
get
{
return Environment.OSVersion.Version.Build;
}
}
@ -662,8 +776,10 @@ namespace Greenshot.Helpers {
/// <summary>
/// Gets the full version string of the operating system running on this computer.
/// </summary>
static public string VersionString {
get {
static public string VersionString
{
get
{
return string.Format("{0}.{1} build {3} revision {2:X}", Environment.OSVersion.Version.Major, Environment.OSVersion.Version.Minor, Environment.OSVersion.Version.Revision, Environment.OSVersion.Version.Build);
}
}
@ -673,8 +789,10 @@ namespace Greenshot.Helpers {
/// <summary>
/// Gets the full version of the operating system running on this computer.
/// </summary>
static public Version Version {
get {
static public Version Version
{
get
{
return Environment.OSVersion.Version;
}
}
@ -685,8 +803,10 @@ namespace Greenshot.Helpers {
/// <summary>
/// Gets the major version number of the operating system running on this computer.
/// </summary>
static public int MajorVersion {
get {
static public int MajorVersion
{
get
{
return Environment.OSVersion.Version.Major;
}
}
@ -696,8 +816,10 @@ namespace Greenshot.Helpers {
/// <summary>
/// Gets the minor version number of the operating system running on this computer.
/// </summary>
static public int MinorVersion {
get {
static public int MinorVersion
{
get
{
return Environment.OSVersion.Version.Minor;
}
}
@ -707,8 +829,10 @@ namespace Greenshot.Helpers {
/// <summary>
/// Gets the revision version number of the operating system running on this computer.
/// </summary>
static public int RevisionVersion {
get {
static public int RevisionVersion
{
get
{
return Environment.OSVersion.Version.Revision;
}
}

View file

@ -9,14 +9,16 @@
</asmv3:application>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates app support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates app support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--The ID below indicates app support for Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!--The ID below indicates app support for Windows 8.1 -->
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!--Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
</application>
</compatibility>
<!-- Set UAC level to "asInvoker" and disable registry virtualization -->

View file

@ -9,6 +9,13 @@ All details to our tickets can be found here: https://greenshot.atlassian.net
@DETAILVERSION@
Bugs Resolved:
* BUG-1809: OverflowException when changing the windows input language
* BUG-1835: Imgur uploads were cancelled due to a timeout which was set too small
1.2.6.7-359dcf3 RELEASE
Bugs Resolved:
* BUG-1769: Switched to OAuth 2 for Picasa Authentication, OAuth 1.x will be terminated as of 20th of April 2015.
* BUG-1770: Fix problems when a font doesn't want to draw itself.

View file

@ -291,7 +291,7 @@ namespace GreenshotPlugin.Core {
}
}
[IniProperty("WebRequestTimeout", Description = "The connect timeout value for webrequets, these are seconds", DefaultValue = "10")]
[IniProperty("WebRequestTimeout", Description = "The connect timeout value for webrequets, these are seconds", DefaultValue = "100")]
public int WebRequestTimeout;
[IniProperty("WebRequestReadWriteTimeout", Description = "The read/write timeout value for webrequets, these are seconds", DefaultValue = "100")]
public int WebRequestReadWriteTimeout;
@ -509,8 +509,8 @@ namespace GreenshotPlugin.Core {
OutputFileReduceColorsTo = 256;
}
if (WebRequestTimeout < 1) {
WebRequestTimeout = 10;
if (WebRequestTimeout <= 10) {
WebRequestTimeout = 100;
}
if (WebRequestReadWriteTimeout < 1) {
WebRequestReadWriteTimeout = 100;

View file

@ -0,0 +1,43 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2015 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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 GreenshotPlugin.UnmanagedHelpers;
using System.Windows.Forms;
namespace GreenshotPlugin.Core
{
/// <summary>
/// This IMessageFilter filters out all WM_INPUTLANGCHANGEREQUEST messages which go to a handle which is >32 bits.
/// The need for this is documented here: http://stackoverflow.com/a/32021586
/// Unfortunately there is an error in the code example, should use HWnd instead of LParam for the handle.
/// </summary>
public class WmInputLangChangeRequestFilter : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == (int)WindowsMessages.WM_INPUTLANGCHANGEREQUEST || m.Msg == (int)WindowsMessages.WM_INPUTLANGCHANGE)
{
return m.HWnd.ToInt64() > 0x7FFFFFFF;
}
return false;
}
}
}

View file

@ -37,6 +37,7 @@
<Compile Include="Core\CaptureHandler.cs" />
<Compile Include="Core\EventDelay.cs" />
<Compile Include="Core\FastBitmap.cs" />
<Compile Include="Core\WmInputLangChangeRequestFilter.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="IEInterop\IHTMLBodyElement.cs" />
<Compile Include="IEInterop\IHTMLCurrentStyle.cs" />