From d8f5259fe0d021320c2e026395068f1eac6844f9 Mon Sep 17 00:00:00 2001 From: "Krom, Robertus" Date: Tue, 25 Feb 2020 14:30:03 +0100 Subject: [PATCH] Fixed OS output, as it didn't display Windows 10. Fixed version string. Improved OCR and QR code a bit. --- Greenshot/Forms/AboutForm.cs | 24 ++- Greenshot/Forms/CaptureForm.cs | 2 - Greenshot/Helpers/EnvironmentInfo.cs | 161 +++++++++++++----- Greenshot/Processors/ZXingQrProcessor.cs | 27 +-- GreenshotPlugin/Core/Capture.cs | 2 + .../Interfaces/Ocr/OcrInformation.cs | 6 + .../Destinations/Win10OcrDestination.cs | 93 ++++++++++ .../Win10ShareDestination.cs | 12 +- .../Processors/Win10OcrProcessor.cs | 49 ++++++ ...0OcrDestination.cs => Win10OcrProvider.cs} | 53 +----- GreenshotWin10Plugin/Win10Plugin.cs | 30 ++-- 11 files changed, 327 insertions(+), 132 deletions(-) create mode 100644 GreenshotWin10Plugin/Destinations/Win10OcrDestination.cs rename GreenshotWin10Plugin/{ => Destinations}/Win10ShareDestination.cs (97%) create mode 100644 GreenshotWin10Plugin/Processors/Win10OcrProcessor.cs rename GreenshotWin10Plugin/{Win10OcrDestination.cs => Win10OcrProvider.cs} (72%) diff --git a/Greenshot/Forms/AboutForm.cs b/Greenshot/Forms/AboutForm.cs index 6ed63f2db..4d9f1c193 100644 --- a/Greenshot/Forms/AboutForm.cs +++ b/Greenshot/Forms/AboutForm.cs @@ -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(); + if (!string.IsNullOrEmpty(assemblyFileVersion?.Version)) + { + greenshotVersion = assemblyFileVersion.Version; + } + + // Use AssemblyInformationalVersion if available + var assemblyInformationalVersion = executingAssembly.GetCustomAttribute(); + 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(); diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index c6ca35666..b8e55b7be 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -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 { /// diff --git a/Greenshot/Helpers/EnvironmentInfo.cs b/Greenshot/Helpers/EnvironmentInfo.cs index 645639414..f467b423d 100644 --- a/Greenshot/Helpers/EnvironmentInfo.cs +++ b/Greenshot/Helpers/EnvironmentInfo.cs @@ -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 + { + /// + /// The size of this data structure, in bytes. Set this member to sizeof(OSVERSIONINFOEX). + /// + 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; + + /// + /// The major version number of the operating system. + /// + public int MajorVersion => _dwMajorVersion; + + /// + /// The minor version number of the operating system. + /// + public int MinorVersion => _dwMinorVersion; + + /// + /// The build number of the operating system. + /// + public int BuildNumber => _dwBuildNumber; + + /// + /// The operating system platform. This member can be VER_PLATFORM_WIN32_NT (2). + /// + public int PlatformId => _dwPlatformId; + + /// + /// 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. + /// + public string ServicePackVersion + { + get + { + fixed (char* servicePackVersion = _szCSDVersion) + { + return new string(servicePackVersion); + } + + } + } + + /// + /// 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. + /// + public short ServicePackMajor => _wServicePackMajor; + + /// + /// 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. + /// + public short ServicePackMinor => _wServicePackMinor; + + /// + /// A bit mask that identifies the product suites available on the system. This member can be a combination of the + /// following values. + /// + public ushort SuiteMask => _wSuiteMask; + + /// + /// Any additional information about the system. + /// + public byte ProductType => _wProductType; + + /// + /// Factory for an empty OsVersionInfoEx + /// + /// OSVERSIONINFOEX + 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}"; } } diff --git a/Greenshot/Processors/ZXingQrProcessor.cs b/Greenshot/Processors/ZXingQrProcessor.cs index 182344a4b..0fa9e08e4 100644 --- a/Greenshot/Processors/ZXingQrProcessor.cs +++ b/Greenshot/Processors/ZXingQrProcessor.cs @@ -19,12 +19,8 @@ * along with this program. If not, see . */ -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 /// public class ZXingQrProcessor : AbstractProcessor { - private static readonly ILog LOG = LogManager.GetLogger(typeof(TitleFixProcessor)); - private static readonly CoreConfiguration config = IniConfig.GetIniSection(); + 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; + } } } diff --git a/GreenshotPlugin/Core/Capture.cs b/GreenshotPlugin/Core/Capture.cs index dbdbca21c..78b93627b 100644 --- a/GreenshotPlugin/Core/Capture.cs +++ b/GreenshotPlugin/Core/Capture.cs @@ -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) { diff --git a/GreenshotPlugin/Interfaces/Ocr/OcrInformation.cs b/GreenshotPlugin/Interfaces/Ocr/OcrInformation.cs index 0e3b4f4c1..cd20eab00 100644 --- a/GreenshotPlugin/Interfaces/Ocr/OcrInformation.cs +++ b/GreenshotPlugin/Interfaces/Ocr/OcrInformation.cs @@ -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 /// public class OcrInformation { + /// + /// Check if there is any content + /// + public bool HasContent => Lines.Any(); + /// /// The complete text /// diff --git a/GreenshotWin10Plugin/Destinations/Win10OcrDestination.cs b/GreenshotWin10Plugin/Destinations/Win10OcrDestination.cs new file mode 100644 index 000000000..53cdf22bc --- /dev/null +++ b/GreenshotWin10Plugin/Destinations/Win10OcrDestination.cs @@ -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 . + */ + +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 +{ + /// + /// This uses the OcrEngine from Windows 10 to perform OCR on the captured image. + /// + 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"; + + /// + /// Icon for the OCR function, the icon was found via: http://help4windows.com/windows_8_imageres_dll.shtml + /// + public override Image DisplayIcon => PluginUtils.GetCachedExeIcon(FilenameHelper.FillCmdVariables(@"%windir%\system32\imageres.dll"), 97); + + /// + /// Constructor, this is only debug information + /// + public Win10OcrDestination() + { + var languages = OcrEngine.AvailableRecognizerLanguages; + foreach (var language in languages) + { + Log.DebugFormat("Found language {0} {1}", language.NativeName, language.LanguageTag); + } + } + + /// + /// Run the Windows 10 OCR engine to process the text on the captured image + /// + /// + /// + /// + /// ExportInformation + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) + { + var exportInformation = new ExportInformation(Designation, Description); + try + { + var ocrProvider = SimpleServiceProvider.Current.GetInstance(); + 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; + + } + } +} diff --git a/GreenshotWin10Plugin/Win10ShareDestination.cs b/GreenshotWin10Plugin/Destinations/Win10ShareDestination.cs similarity index 97% rename from GreenshotWin10Plugin/Win10ShareDestination.cs rename to GreenshotWin10Plugin/Destinations/Win10ShareDestination.cs index f7fd11370..7fc82a1b8 100644 --- a/GreenshotWin10Plugin/Win10ShareDestination.cs +++ b/GreenshotWin10Plugin/Destinations/Win10ShareDestination.cs @@ -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 { /// /// 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"; /// diff --git a/GreenshotWin10Plugin/Processors/Win10OcrProcessor.cs b/GreenshotWin10Plugin/Processors/Win10OcrProcessor.cs new file mode 100644 index 000000000..76f15429d --- /dev/null +++ b/GreenshotWin10Plugin/Processors/Win10OcrProcessor.cs @@ -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 . + */ + +using System.Threading.Tasks; +using GreenshotPlugin.Core; +using GreenshotPlugin.IniFile; +using GreenshotPlugin.Interfaces; +using GreenshotPlugin.Interfaces.Ocr; +using log4net; + +namespace GreenshotWin10Plugin.Processors { + /// + /// This processor processes a capture to see if there is text on it + /// + 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(); + var ocrResult = Task.Run(async () => await ocrProvider.DoOcrAsync(surface)).Result; + + if (!ocrResult.HasContent) return false; + + captureDetails.OcrInformation = ocrResult; + return true; + } + } +} diff --git a/GreenshotWin10Plugin/Win10OcrDestination.cs b/GreenshotWin10Plugin/Win10OcrProvider.cs similarity index 72% rename from GreenshotWin10Plugin/Win10OcrDestination.cs rename to GreenshotWin10Plugin/Win10OcrProvider.cs index 96b22b96c..9dc7dc032 100644 --- a/GreenshotWin10Plugin/Win10OcrDestination.cs +++ b/GreenshotWin10Plugin/Win10OcrProvider.cs @@ -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 /// /// This uses the OcrEngine from Windows 10 to perform OCR on the captured image. /// - 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"; - - /// - /// Icon for the OCR function, the icon was found via: http://help4windows.com/windows_8_imageres_dll.shtml - /// - public override Image DisplayIcon => PluginUtils.GetCachedExeIcon(FilenameHelper.FillCmdVariables(@"%windir%\system32\imageres.dll"), 97); + private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(Win10OcrProvider)); /// /// Constructor, this is only debug information /// - public Win10OcrDestination() + public Win10OcrProvider() { - // Set this as IOcrProvider - SimpleServiceProvider.Current.AddService(this); var languages = OcrEngine.AvailableRecognizerLanguages; foreach (var language in languages) { @@ -147,38 +137,5 @@ namespace GreenshotWin10Plugin return result; } - - /// - /// Run the Windows 10 OCR engine to process the text on the captured image - /// - /// - /// - /// - /// ExportInformation - 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; - - } - } + } } diff --git a/GreenshotWin10Plugin/Win10Plugin.cs b/GreenshotWin10Plugin/Win10Plugin.cs index 1bf1f5b1b..f760c9a52 100644 --- a/GreenshotWin10Plugin/Win10Plugin.cs +++ b/GreenshotWin10Plugin/Win10Plugin.cs @@ -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(); } - /// - /// yields the windows 10 destinations if Windows 10 is detected - /// - /// IEnumerable with the destinations - private IEnumerable Destinations() - { - if (!WindowsVersion.IsWindows10OrLater) - { - yield break; - } - yield return new Win10OcrDestination(); - yield return new Win10ShareDestination(); - } - /// /// Implementation of the IGreenshotPlugin.Initialize /// /// true if plugin is initialized, false if not (doesn't show) public bool Initialize() { - SimpleServiceProvider.Current.AddService(Destinations()); + if (!WindowsVersion.IsWindows10OrLater) + { + return false; + } + // Set this as IOcrProvider + SimpleServiceProvider.Current.AddService(new Win10OcrProvider()); + // Add the processor + SimpleServiceProvider.Current.AddService(new Win10OcrProcessor()); + + // Add the destinations + SimpleServiceProvider.Current.AddService(new Win10OcrDestination()); + SimpleServiceProvider.Current.AddService(new Win10ShareDestination()); return true; }