Skip to content

Commit

Permalink
improved windows support + dispose native libraries.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tentacule committed May 11, 2020
1 parent e64487c commit 95d525d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions PgsToSrt/PgsToSrt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<FileVersion>1.0.1.0</FileVersion>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<Version>1.1.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
2 changes: 1 addition & 1 deletion Tesseract/Tesseract.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Tncl.NativeLoader" Version="1.0.2" />
<PackageReference Include="Tncl.NativeLoader" Version="1.0.3" />
</ItemGroup>
</Project>
22 changes: 11 additions & 11 deletions Tesseract/TesseractEngine.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using Tesseract.Internal;
using Tesseract.Interop;
Expand All @@ -14,10 +13,8 @@ namespace Tesseract
/// </summary>
public class TesseractEngine : DisposableBase
{
private static readonly TraceSource trace = new TraceSource("Tesseract");

private readonly NativeLoader loader;
private HandleRef handle;

private int processCount = 0;

/// <summary>
Expand All @@ -38,7 +35,7 @@ public TesseractEngine(string datapath, string language, EngineMode engineMode)
: this(datapath, language, engineMode, new string[0], new Dictionary<string, object>(), false)
{
}

/// <summary>
/// Creates a new instance of <see cref="TesseractEngine"/> with the specified <paramref name="engineMode"/> and <paramref name="configFiles"/>.
/// </summary>
Expand All @@ -63,14 +60,16 @@ public TesseractEngine(string datapath, string language, EngineMode engineMode,

DefaultPageSegMode = PageSegMode.Auto;

var loader = new NativeLoader();
loader = new NativeLoader();
loader.WindowsOptions.UseSetDllDirectory = true;

TessApi.Initialize(loader);

handle = new HandleRef(this, TessApi.Native.BaseApiCreate());

Initialise(datapath, language, engineMode, configFiles, initialOptions, setOnlyNonDebugVariables);
}

internal HandleRef Handle
{
get { return handle; }
Expand Down Expand Up @@ -149,14 +148,16 @@ public Page Process(Pix image, string inputName, Rect region, PageSegMode? pageS
page.Disposed += OnIteratorDisposed;
return page;
}

protected override void Dispose(bool disposing)
{
if (handle.Handle != IntPtr.Zero)
{
TessApi.Native.BaseApiDelete(handle);
handle = new HandleRef(this, IntPtr.Zero);
}

loader.FreeAll();
}

private void Initialise(string datapath, string language, EngineMode engineMode, IEnumerable<string> configFiles, IDictionary<string, object> initialValues, bool setOnlyNonDebugVariables)
Expand Down Expand Up @@ -234,8 +235,7 @@ public PageSegMode DefaultPageSegMode
/// <returns>Returns <c>True</c> if successful; otherwise <c>False</c>.</returns>
public bool TryGetBoolVariable(string name, out bool value)
{
int val;
if (TessApi.Native.BaseApiGetBoolVariable(handle, name, out val) != 0)
if (TessApi.Native.BaseApiGetBoolVariable(handle, name, out var val) != 0)
{
value = (val != 0);
return true;
Expand Down

0 comments on commit 95d525d

Please sign in to comment.