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) // 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); _bitmap = ImageHelper.CreateEmpty(90, 90, PixelFormat.Format24bppRgb, BackColor, 96, 96);
pictureBox1.Image = _bitmap; 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")] // 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(); //Random rand = new Random();

View file

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

View file

@ -98,7 +98,20 @@ namespace Greenshot.Helpers
{ {
environment.Append(", "); 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) if (newline)
{ {
environment.AppendLine(); environment.AppendLine();
@ -236,17 +249,14 @@ namespace Greenshot.Helpers
string edition = string.Empty; string edition = string.Empty;
OperatingSystem osVersion = Environment.OSVersion; OperatingSystem osVersion = Environment.OSVersion;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX OSVERSIONINFOEX osVersionInfo = OSVERSIONINFOEX.Create();
{
dwOSVersionInfoSize = Marshal.SizeOf(typeof (OSVERSIONINFOEX))
};
if (GetVersionEx(ref osVersionInfo)) if (GetVersionEx(ref osVersionInfo))
{ {
int majorVersion = osVersion.Version.Major; int majorVersion = osVersion.Version.Major;
int minorVersion = osVersion.Version.Minor; int minorVersion = osVersion.Version.Minor;
byte productType = osVersionInfo.wProductType; byte productType = osVersionInfo.ProductType;
short suiteMask = osVersionInfo.wSuiteMask; ushort suiteMask = osVersionInfo.SuiteMask;
if (majorVersion == 4) if (majorVersion == 4)
{ {
@ -324,7 +334,7 @@ namespace Greenshot.Helpers
else if (majorVersion == 6) 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) switch (ed)
{ {
@ -465,23 +475,19 @@ namespace Greenshot.Helpers
string name = "unknown"; string name = "unknown";
OperatingSystem osVersion = Environment.OSVersion; OperatingSystem osVersion = Environment.OSVersion;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX OSVERSIONINFOEX osVersionInfo = OSVERSIONINFOEX.Create();
{
dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX))
};
if (GetVersionEx(ref osVersionInfo)) if (GetVersionEx(ref osVersionInfo))
{ {
int majorVersion = osVersion.Version.Major; int majorVersion = osVersion.Version.Major;
int minorVersion = osVersion.Version.Minor; int minorVersion = osVersion.Version.Minor;
byte productType = osVersionInfo.wProductType; byte productType = osVersionInfo.ProductType;
short suiteMask = osVersionInfo.wSuiteMask; ushort suiteMask = osVersionInfo.SuiteMask;
switch (osVersion.Platform) switch (osVersion.Platform)
{ {
case PlatformID.Win32Windows: case PlatformID.Win32Windows:
if (majorVersion == 4) if (majorVersion == 4)
{ {
string csdVersion = osVersionInfo.szCSDVersion; string csdVersion = osVersionInfo.ServicePackVersion;
switch (minorVersion) switch (minorVersion)
{ {
case 0: case 0:
@ -540,7 +546,7 @@ namespace Greenshot.Helpers
0x0002 => "Windows Server 2003 Enterprise", 0x0002 => "Windows Server 2003 Enterprise",
0x0080 => "Windows Server 2003 Data Center", 0x0080 => "Windows Server 2003 Data Center",
0x0400 => "Windows Server 2003 Web Edition", 0x0400 => "Windows Server 2003 Web Edition",
unchecked((short) 0x8000) => "Windows Home Server", 0x8000 => "Windows Home Server",
_ => "Windows Server 2003" _ => "Windows Server 2003"
}; };
break; break;
@ -597,21 +603,96 @@ namespace Greenshot.Helpers
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetVersionEx(ref OSVERSIONINFOEX osVersionInfo); private static extern bool GetVersionEx(ref OSVERSIONINFOEX osVersionInfo);
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private struct OSVERSIONINFOEX private unsafe struct OSVERSIONINFOEX
{ {
public int dwOSVersionInfoSize; /// <summary>
public readonly int dwMajorVersion; /// The size of this data structure, in bytes. Set this member to sizeof(OSVERSIONINFOEX).
public readonly int dwMinorVersion; /// </summary>
public readonly int dwBuildNumber; private int _dwOSVersionInfoSize;
public readonly int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] private readonly int _dwMajorVersion;
public readonly string szCSDVersion; private readonly int _dwMinorVersion;
public readonly short wServicePackMajor; private readonly int _dwBuildNumber;
public readonly short wServicePackMinor; private readonly int _dwPlatformId;
public readonly short wSuiteMask; private fixed char _szCSDVersion[128];
public readonly byte wProductType; private readonly short _wServicePackMajor;
public readonly byte wReserved; 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_UNDEFINED = 0x00000000;
@ -667,15 +748,11 @@ namespace Greenshot.Helpers
get get
{ {
string servicePack = string.Empty; string servicePack = string.Empty;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX OSVERSIONINFOEX osVersionInfo = OSVERSIONINFOEX.Create();
{
dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX))
};
if (GetVersionEx(ref osVersionInfo)) if (GetVersionEx(ref osVersionInfo))
{ {
servicePack = osVersionInfo.szCSDVersion; servicePack = osVersionInfo.ServicePackVersion;
} }
return servicePack; return servicePack;
@ -694,7 +771,11 @@ namespace Greenshot.Helpers
{ {
get 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using GreenshotPlugin.IniFile;
using GreenshotPlugin.Interfaces; using GreenshotPlugin.Interfaces;
using log4net; using log4net;
using ZXing; using ZXing;
@ -34,14 +30,9 @@ namespace Greenshot.Processors {
/// This processor processes a capture to see if there is a QR ode on it /// This processor processes a capture to see if there is a QR ode on it
/// </summary> /// </summary>
public class ZXingQrProcessor : AbstractProcessor { public class ZXingQrProcessor : AbstractProcessor {
private static readonly ILog LOG = LogManager.GetLogger(typeof(TitleFixProcessor)); private static readonly ILog LOG = LogManager.GetLogger(typeof(ZXingQrProcessor));
private static readonly CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
public ZXingQrProcessor() { public override string Designation => "ZXingQrProcessor";
}
public override string Designation => "QRProcessor";
public override string Description => Designation; public override string Description => Designation;
@ -51,13 +42,11 @@ namespace Greenshot.Processors {
// detect and decode the barcode inside the bitmap // detect and decode the barcode inside the bitmap
var result = reader.Decode((Bitmap)surface.Image); var result = reader.Decode((Bitmap)surface.Image);
// do something with the result // do something with the result
if (result != null) if (result == null) return false;
{
LOG.InfoFormat("Found QR of type {0} - {1}", result.BarcodeFormat, result.Text); LOG.InfoFormat("Found QR of type {0} - {1}", result.BarcodeFormat, result.Text);
captureDetails.QrResult = result; captureDetails.QrResult = result;
return true; return true;
} }
return false;
}
} }
} }

View file

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

View file

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
namespace GreenshotPlugin.Interfaces.Ocr namespace GreenshotPlugin.Interfaces.Ocr
@ -8,6 +9,11 @@ namespace GreenshotPlugin.Interfaces.Ocr
/// </summary> /// </summary>
public class OcrInformation public class OcrInformation
{ {
/// <summary>
/// Check if there is any content
/// </summary>
public bool HasContent => Lines.Any();
/// <summary> /// <summary>
/// The complete text /// The complete text
/// </summary> /// </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;
using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Interop; using System.Windows.Interop;
using System.Windows.Media;
using Windows.Storage; using Windows.Storage;
using Windows.Storage.Streams; using Windows.Storage.Streams;
using Color = Windows.UI.Color;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using System.Drawing;
using GreenshotWin10Plugin.Native;
using System.Windows.Media;
using GreenshotPlugin.Hooking; using GreenshotPlugin.Hooking;
using GreenshotPlugin.Interfaces; using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Plugin; using GreenshotPlugin.Interfaces.Plugin;
using GreenshotWin10Plugin.Internal; using GreenshotWin10Plugin.Internal;
using GreenshotWin10Plugin.Native;
using Color = Windows.UI.Color;
namespace GreenshotWin10Plugin namespace GreenshotWin10Plugin.Destinations
{ {
/// <summary> /// <summary>
/// This uses the Share from Windows 10 to make the capture available to apps. /// 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)); 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"; public override string Description { get; } = "Windows 10 share";
/// <summary> /// <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 System.Threading.Tasks;
using Windows.Graphics.Imaging; using Windows.Graphics.Imaging;
using Windows.Media.Ocr; using Windows.Media.Ocr;
using GreenshotPlugin.Core;
using Windows.Storage.Streams; using Windows.Storage.Streams;
using GreenshotPlugin.Core;
using GreenshotPlugin.Interfaces; using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Ocr; using GreenshotPlugin.Interfaces.Ocr;
using GreenshotPlugin.Interfaces.Plugin; using GreenshotPlugin.Interfaces.Plugin;
@ -36,25 +36,15 @@ namespace GreenshotWin10Plugin
/// <summary> /// <summary>
/// This uses the OcrEngine from Windows 10 to perform OCR on the captured image. /// This uses the OcrEngine from Windows 10 to perform OCR on the captured image.
/// </summary> /// </summary>
public class Win10OcrDestination : AbstractDestination, IOcrProvider public class Win10OcrProvider : IOcrProvider
{ {
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(Win10OcrDestination)); private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(Win10OcrProvider));
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);
/// <summary> /// <summary>
/// Constructor, this is only debug information /// Constructor, this is only debug information
/// </summary> /// </summary>
public Win10OcrDestination() public Win10OcrProvider()
{ {
// Set this as IOcrProvider
SimpleServiceProvider.Current.AddService<IOcrProvider>(this);
var languages = OcrEngine.AvailableRecognizerLanguages; var languages = OcrEngine.AvailableRecognizerLanguages;
foreach (var language in languages) foreach (var language in languages)
{ {
@ -147,38 +137,5 @@ namespace GreenshotWin10Plugin
return result; 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 System.Collections.Generic;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using GreenshotPlugin.Interfaces; using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Ocr;
using GreenshotPlugin.Interfaces.Plugin; using GreenshotPlugin.Interfaces.Plugin;
using GreenshotWin10Plugin.Destinations;
using GreenshotWin10Plugin.Processors;
namespace GreenshotWin10Plugin namespace GreenshotWin10Plugin
{ {
@ -50,27 +53,24 @@ namespace GreenshotWin10Plugin
throw new NotImplementedException(); 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> /// <summary>
/// Implementation of the IGreenshotPlugin.Initialize /// Implementation of the IGreenshotPlugin.Initialize
/// </summary> /// </summary>
/// <returns>true if plugin is initialized, false if not (doesn't show)</returns> /// <returns>true if plugin is initialized, false if not (doesn't show)</returns>
public bool Initialize() 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; return true;
} }