Fixed OS output, as it didn't display Windows 10.

Fixed version string.
Improved OCR and QR code a bit.
This commit is contained in:
Krom, Robertus 2020-02-25 14:30:03 +01:00
commit d8f5259fe0
11 changed files with 327 additions and 132 deletions

View file

@ -149,10 +149,30 @@ namespace Greenshot {
// Use the self drawn image, first we create the background to be the backcolor (as we animate from this)
_bitmap = ImageHelper.CreateEmpty(90, 90, PixelFormat.Format24bppRgb, BackColor, 96, 96);
pictureBox1.Image = _bitmap;
Version v = Assembly.GetExecutingAssembly().GetName().Version;
var executingAssembly = Assembly.GetExecutingAssembly();
// Use assembly version
string greenshotVersion = executingAssembly.GetName().Version.ToString();
// Use AssemblyFileVersion if available
var v = executingAssembly.GetName().Version;
var assemblyFileVersion = executingAssembly.GetCustomAttribute<AssemblyFileVersionAttribute>();
if (!string.IsNullOrEmpty(assemblyFileVersion?.Version))
{
greenshotVersion = assemblyFileVersion.Version;
}
// Use AssemblyInformationalVersion if available
var assemblyInformationalVersion = executingAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
if (!string.IsNullOrEmpty(assemblyInformationalVersion?.InformationalVersion))
{
greenshotVersion = assemblyInformationalVersion.InformationalVersion;
}
greenshotVersion = greenshotVersion.Replace("+", " - ");
// Format is like this: AssemblyVersion("Major.Minor.Build.Revision")]
lblTitle.Text = "Greenshot " + v.Major + "." + v.Minor + "." + v.Build + " Build " + v.Revision + (IniConfig.IsPortable ? " Portable" : "") + (" (" + OsInfo.Bits) + " bit)";
lblTitle.Text = "Greenshot " + greenshotVersion + (IniConfig.IsPortable ? " Portable" : "") + (" (" + OsInfo.Bits) + " bit)";
//Random rand = new Random();

View file

@ -36,11 +36,9 @@ using System.Security.Permissions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Threading;
using GreenshotPlugin.IniFile;
using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Ocr;
using ZXing;
namespace Greenshot.Forms {
/// <summary>

View file

@ -98,7 +98,20 @@ namespace Greenshot.Helpers
{
environment.Append(", ");
}
environment.Append($"OS: {OsInfo.Name} {OsInfo.Edition} {OsInfo.ServicePack} (x{OsInfo.Bits}) {OsInfo.VersionString}");
environment.Append($"OS: {OsInfo.Name}");
if (!string.IsNullOrEmpty(OsInfo.Edition))
{
environment.Append($" {OsInfo.Edition}");
}
if (!string.IsNullOrEmpty(OsInfo.ServicePack))
{
environment.Append($" {OsInfo.ServicePack}");
}
environment.Append($" x{OsInfo.Bits}");
environment.Append($" {OsInfo.VersionString}");
if (newline)
{
environment.AppendLine();
@ -236,17 +249,14 @@ namespace Greenshot.Helpers
string edition = string.Empty;
OperatingSystem osVersion = Environment.OSVersion;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX
{
dwOSVersionInfoSize = Marshal.SizeOf(typeof (OSVERSIONINFOEX))
};
OSVERSIONINFOEX osVersionInfo = OSVERSIONINFOEX.Create();
if (GetVersionEx(ref osVersionInfo))
{
int majorVersion = osVersion.Version.Major;
int minorVersion = osVersion.Version.Minor;
byte productType = osVersionInfo.wProductType;
short suiteMask = osVersionInfo.wSuiteMask;
byte productType = osVersionInfo.ProductType;
ushort suiteMask = osVersionInfo.SuiteMask;
if (majorVersion == 4)
{
@ -324,7 +334,7 @@ namespace Greenshot.Helpers
else if (majorVersion == 6)
{
if (GetProductInfo(majorVersion, minorVersion, osVersionInfo.wServicePackMajor, osVersionInfo.wServicePackMinor, out var ed))
if (GetProductInfo(majorVersion, minorVersion, osVersionInfo.ServicePackMajor, osVersionInfo.ServicePackMinor, out var ed))
{
switch (ed)
{
@ -465,23 +475,19 @@ namespace Greenshot.Helpers
string name = "unknown";
OperatingSystem osVersion = Environment.OSVersion;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX
{
dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX))
};
OSVERSIONINFOEX osVersionInfo = OSVERSIONINFOEX.Create();
if (GetVersionEx(ref osVersionInfo))
{
int majorVersion = osVersion.Version.Major;
int minorVersion = osVersion.Version.Minor;
byte productType = osVersionInfo.wProductType;
short suiteMask = osVersionInfo.wSuiteMask;
byte productType = osVersionInfo.ProductType;
ushort suiteMask = osVersionInfo.SuiteMask;
switch (osVersion.Platform)
{
case PlatformID.Win32Windows:
if (majorVersion == 4)
{
string csdVersion = osVersionInfo.szCSDVersion;
string csdVersion = osVersionInfo.ServicePackVersion;
switch (minorVersion)
{
case 0:
@ -540,7 +546,7 @@ namespace Greenshot.Helpers
0x0002 => "Windows Server 2003 Enterprise",
0x0080 => "Windows Server 2003 Data Center",
0x0400 => "Windows Server 2003 Web Edition",
unchecked((short) 0x8000) => "Windows Home Server",
0x8000 => "Windows Home Server",
_ => "Windows Server 2003"
};
break;
@ -597,22 +603,97 @@ namespace Greenshot.Helpers
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetVersionEx(ref OSVERSIONINFOEX osVersionInfo);
[StructLayout(LayoutKind.Sequential)]
private struct OSVERSIONINFOEX
{
public int dwOSVersionInfoSize;
public readonly int dwMajorVersion;
public readonly int dwMinorVersion;
public readonly int dwBuildNumber;
public readonly int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public readonly string szCSDVersion;
public readonly short wServicePackMajor;
public readonly short wServicePackMinor;
public readonly short wSuiteMask;
public readonly byte wProductType;
public readonly byte wReserved;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private unsafe struct OSVERSIONINFOEX
{
/// <summary>
/// The size of this data structure, in bytes. Set this member to sizeof(OSVERSIONINFOEX).
/// </summary>
private int _dwOSVersionInfoSize;
private readonly int _dwMajorVersion;
private readonly int _dwMinorVersion;
private readonly int _dwBuildNumber;
private readonly int _dwPlatformId;
private fixed char _szCSDVersion[128];
private readonly short _wServicePackMajor;
private readonly short _wServicePackMinor;
private readonly ushort _wSuiteMask;
private readonly byte _wProductType;
private readonly byte _wReserved;
/// <summary>
/// The major version number of the operating system.
/// </summary>
public int MajorVersion => _dwMajorVersion;
/// <summary>
/// The minor version number of the operating system.
/// </summary>
public int MinorVersion => _dwMinorVersion;
/// <summary>
/// The build number of the operating system.
/// </summary>
public int BuildNumber => _dwBuildNumber;
/// <summary>
/// The operating system platform. This member can be VER_PLATFORM_WIN32_NT (2).
/// </summary>
public int PlatformId => _dwPlatformId;
/// <summary>
/// A null-terminated string, such as "Service Pack 3", that indicates the latest Service Pack installed on the system.
/// If no Service Pack has been installed, the string is empty.
/// </summary>
public string ServicePackVersion
{
get
{
fixed (char* servicePackVersion = _szCSDVersion)
{
return new string(servicePackVersion);
}
}
}
/// <summary>
/// The major version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the
/// major version number is 3.
/// If no Service Pack has been installed, the value is zero.
/// </summary>
public short ServicePackMajor => _wServicePackMajor;
/// <summary>
/// The minor version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the
/// minor version number is 0.
/// </summary>
public short ServicePackMinor => _wServicePackMinor;
/// <summary>
/// A bit mask that identifies the product suites available on the system. This member can be a combination of the
/// following values.
/// </summary>
public ushort SuiteMask => _wSuiteMask;
/// <summary>
/// Any additional information about the system.
/// </summary>
public byte ProductType => _wProductType;
/// <summary>
/// Factory for an empty OsVersionInfoEx
/// </summary>
/// <returns>OSVERSIONINFOEX</returns>
public static OSVERSIONINFOEX Create()
{
return new OSVERSIONINFOEX
{
_dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX))
};
}
}
private const int PRODUCT_UNDEFINED = 0x00000000;
private const int PRODUCT_ULTIMATE = 0x00000001;
@ -667,15 +748,11 @@ namespace Greenshot.Helpers
get
{
string servicePack = string.Empty;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX
{
dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX))
};
OSVERSIONINFOEX osVersionInfo = OSVERSIONINFOEX.Create();
if (GetVersionEx(ref osVersionInfo))
{
servicePack = osVersionInfo.szCSDVersion;
servicePack = osVersionInfo.ServicePackVersion;
}
return servicePack;
@ -694,7 +771,11 @@ namespace Greenshot.Helpers
{
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);
if (Environment.OSVersion.Version.Revision != 0)
{
return $"{Environment.OSVersion.Version.Major}.{Environment.OSVersion.Version.Minor} build {Environment.OSVersion.Version.Build} revision {Environment.OSVersion.Version.Revision:X}";
}
return $"{Environment.OSVersion.Version.Major}.{Environment.OSVersion.Version.Minor} build {Environment.OSVersion.Version.Build}";
}
}

View file

@ -19,12 +19,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using GreenshotPlugin.Core;
using GreenshotPlugin.IniFile;
using GreenshotPlugin.Interfaces;
using log4net;
using ZXing;
@ -34,14 +30,9 @@ namespace Greenshot.Processors {
/// This processor processes a capture to see if there is a QR ode on it
/// </summary>
public class ZXingQrProcessor : AbstractProcessor {
private static readonly ILog LOG = LogManager.GetLogger(typeof(TitleFixProcessor));
private static readonly CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
private static readonly ILog LOG = LogManager.GetLogger(typeof(ZXingQrProcessor));
public ZXingQrProcessor() {
}
public override string Designation => "QRProcessor";
public override string Designation => "ZXingQrProcessor";
public override string Description => Designation;
@ -51,13 +42,11 @@ namespace Greenshot.Processors {
// detect and decode the barcode inside the bitmap
var result = reader.Decode((Bitmap)surface.Image);
// do something with the result
if (result != null)
{
LOG.InfoFormat("Found QR of type {0} - {1}", result.BarcodeFormat, result.Text);
captureDetails.QrResult = result;
return true;
}
return false;
}
if (result == null) return false;
LOG.InfoFormat("Found QR of type {0} - {1}", result.BarcodeFormat, result.Text);
captureDetails.QrResult = result;
return true;
}
}
}

View file

@ -177,9 +177,11 @@ namespace GreenshotPlugin.Core
// MoveElements(-cropRectangle.Location.X, -cropRectangle.Location.Y);
// Offset the OCR information
// TODO: Remove invisible lines/words?
CaptureDetails.OcrInformation?.Offset(-cropRectangle.Location.X, -cropRectangle.Location.Y);
// Offset the Qr information
// TODO: Remove invisible QR codes?
var oldQrResult = CaptureDetails.QrResult;
if (oldQrResult != null)
{

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GreenshotPlugin.Interfaces.Ocr
@ -8,6 +9,11 @@ namespace GreenshotPlugin.Interfaces.Ocr
/// </summary>
public class OcrInformation
{
/// <summary>
/// Check if there is any content
/// </summary>
public bool HasContent => Lines.Any();
/// <summary>
/// The complete text
/// </summary>

View file

@ -0,0 +1,93 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on GitHub https://github.com/greenshot/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 System;
using System.Drawing;
using System.Threading.Tasks;
using Windows.Media.Ocr;
using GreenshotPlugin.Core;
using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Ocr;
namespace GreenshotWin10Plugin.Destinations
{
/// <summary>
/// This uses the OcrEngine from Windows 10 to perform OCR on the captured image.
/// </summary>
public class Win10OcrDestination : AbstractDestination
{
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(Win10OcrDestination));
public override string Designation { get; } = "Windows10OCR";
public override string Description { get; } = "Windows 10 OCR";
/// <summary>
/// Icon for the OCR function, the icon was found via: http://help4windows.com/windows_8_imageres_dll.shtml
/// </summary>
public override Image DisplayIcon => PluginUtils.GetCachedExeIcon(FilenameHelper.FillCmdVariables(@"%windir%\system32\imageres.dll"), 97);
/// <summary>
/// Constructor, this is only debug information
/// </summary>
public Win10OcrDestination()
{
var languages = OcrEngine.AvailableRecognizerLanguages;
foreach (var language in languages)
{
Log.DebugFormat("Found language {0} {1}", language.NativeName, language.LanguageTag);
}
}
/// <summary>
/// Run the Windows 10 OCR engine to process the text on the captured image
/// </summary>
/// <param name="manuallyInitiated"></param>
/// <param name="surface"></param>
/// <param name="captureDetails"></param>
/// <returns>ExportInformation</returns>
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
{
var exportInformation = new ExportInformation(Designation, Description);
try
{
var ocrProvider = SimpleServiceProvider.Current.GetInstance<IOcrProvider>();
var ocrResult = Task.Run(async () => await ocrProvider.DoOcrAsync(surface)).Result;
// Check if we found text
if (!string.IsNullOrWhiteSpace(ocrResult.Text))
{
// Place the OCR text on the
ClipboardHelper.SetClipboardData(ocrResult.Text);
}
exportInformation.ExportMade = true;
}
catch (Exception ex)
{
exportInformation.ExportMade = false;
exportInformation.ErrorMessage = ex.Message;
}
ProcessExport(exportInformation, surface);
return exportInformation;
}
}
}

View file

@ -20,24 +20,24 @@
*/
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using Windows.Storage;
using Windows.Storage.Streams;
using Color = Windows.UI.Color;
using GreenshotPlugin.Core;
using System.Drawing;
using GreenshotWin10Plugin.Native;
using System.Windows.Media;
using GreenshotPlugin.Hooking;
using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Plugin;
using GreenshotWin10Plugin.Internal;
using GreenshotWin10Plugin.Native;
using Color = Windows.UI.Color;
namespace GreenshotWin10Plugin
namespace GreenshotWin10Plugin.Destinations
{
/// <summary>
/// This uses the Share from Windows 10 to make the capture available to apps.
@ -46,7 +46,7 @@ namespace GreenshotWin10Plugin
{
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(Win10ShareDestination));
public override string Designation { get; } = "WIN10Share";
public override string Designation { get; } = "Windows10Share";
public override string Description { get; } = "Windows 10 share";
/// <summary>

View file

@ -0,0 +1,49 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on GitHub https://github.com/greenshot/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 System.Threading.Tasks;
using GreenshotPlugin.Core;
using GreenshotPlugin.IniFile;
using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Ocr;
using log4net;
namespace GreenshotWin10Plugin.Processors {
/// <summary>
/// This processor processes a capture to see if there is text on it
/// </summary>
public class Win10OcrProcessor : AbstractProcessor {
public override string Designation => "Windows10OcrProcessor";
public override string Description => Designation;
public override bool ProcessCapture(ISurface surface, ICaptureDetails captureDetails)
{
var ocrProvider = SimpleServiceProvider.Current.GetInstance<IOcrProvider>();
var ocrResult = Task.Run(async () => await ocrProvider.DoOcrAsync(surface)).Result;
if (!ocrResult.HasContent) return false;
captureDetails.OcrInformation = ocrResult;
return true;
}
}
}

View file

@ -25,8 +25,8 @@ using System.IO;
using System.Threading.Tasks;
using Windows.Graphics.Imaging;
using Windows.Media.Ocr;
using GreenshotPlugin.Core;
using Windows.Storage.Streams;
using GreenshotPlugin.Core;
using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Ocr;
using GreenshotPlugin.Interfaces.Plugin;
@ -36,25 +36,15 @@ namespace GreenshotWin10Plugin
/// <summary>
/// This uses the OcrEngine from Windows 10 to perform OCR on the captured image.
/// </summary>
public class Win10OcrDestination : AbstractDestination, IOcrProvider
public class Win10OcrProvider : IOcrProvider
{
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(Win10OcrDestination));
public override string Designation { get; } = "WIN10OCR";
public override string Description { get; } = "Windows 10 OCR";
/// <summary>
/// Icon for the OCR function, the icon was found via: http://help4windows.com/windows_8_imageres_dll.shtml
/// </summary>
public override Image DisplayIcon => PluginUtils.GetCachedExeIcon(FilenameHelper.FillCmdVariables(@"%windir%\system32\imageres.dll"), 97);
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(Win10OcrProvider));
/// <summary>
/// Constructor, this is only debug information
/// </summary>
public Win10OcrDestination()
public Win10OcrProvider()
{
// Set this as IOcrProvider
SimpleServiceProvider.Current.AddService<IOcrProvider>(this);
var languages = OcrEngine.AvailableRecognizerLanguages;
foreach (var language in languages)
{
@ -147,38 +137,5 @@ namespace GreenshotWin10Plugin
return result;
}
/// <summary>
/// Run the Windows 10 OCR engine to process the text on the captured image
/// </summary>
/// <param name="manuallyInitiated"></param>
/// <param name="surface"></param>
/// <param name="captureDetails"></param>
/// <returns>ExportInformation</returns>
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
{
var exportInformation = new ExportInformation(Designation, Description);
try
{
var ocrResult = Task.Run(async () => await DoOcrAsync(surface)).Result;
// Check if we found text
if (!string.IsNullOrWhiteSpace(ocrResult.Text))
{
// Place the OCR text on the
ClipboardHelper.SetClipboardData(ocrResult.Text);
}
exportInformation.ExportMade = true;
}
catch (Exception ex)
{
exportInformation.ExportMade = false;
exportInformation.ErrorMessage = ex.Message;
}
ProcessExport(exportInformation, surface);
return exportInformation;
}
}
}
}

View file

@ -23,7 +23,10 @@ using System;
using System.Collections.Generic;
using GreenshotPlugin.Core;
using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Ocr;
using GreenshotPlugin.Interfaces.Plugin;
using GreenshotWin10Plugin.Destinations;
using GreenshotWin10Plugin.Processors;
namespace GreenshotWin10Plugin
{
@ -50,27 +53,24 @@ namespace GreenshotWin10Plugin
throw new NotImplementedException();
}
/// <summary>
/// yields the windows 10 destinations if Windows 10 is detected
/// </summary>
/// <returns>IEnumerable with the destinations</returns>
private IEnumerable<IDestination> Destinations()
{
if (!WindowsVersion.IsWindows10OrLater)
{
yield break;
}
yield return new Win10OcrDestination();
yield return new Win10ShareDestination();
}
/// <summary>
/// Implementation of the IGreenshotPlugin.Initialize
/// </summary>
/// <returns>true if plugin is initialized, false if not (doesn't show)</returns>
public bool Initialize()
{
SimpleServiceProvider.Current.AddService(Destinations());
if (!WindowsVersion.IsWindows10OrLater)
{
return false;
}
// Set this as IOcrProvider
SimpleServiceProvider.Current.AddService<IOcrProvider>(new Win10OcrProvider());
// Add the processor
SimpleServiceProvider.Current.AddService<IProcessor>(new Win10OcrProcessor());
// Add the destinations
SimpleServiceProvider.Current.AddService<IDestination>(new Win10OcrDestination());
SimpleServiceProvider.Current.AddService<IDestination>(new Win10ShareDestination());
return true;
}