mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
Reduced ctors for TwainAppSession.
This commit is contained in:
parent
d68e9800ba
commit
f25587cab2
@ -11,7 +11,7 @@ namespace WinConsole32
|
|||||||
var libVer = FileVersionInfo.GetVersionInfo(typeof(TwainAppSession).Assembly.Location).ProductVersion;
|
var libVer = FileVersionInfo.GetVersionInfo(typeof(TwainAppSession).Assembly.Location).ProductVersion;
|
||||||
Console.WriteLine($"Console sample {(TWPlatform.Is32bit ? " 32bit" : " 64bit")} on NTwain {libVer}");
|
Console.WriteLine($"Console sample {(TWPlatform.Is32bit ? " 32bit" : " 64bit")} on NTwain {libVer}");
|
||||||
|
|
||||||
TwainAppSession session = new TwainAppSession(Environment.ProcessPath!);
|
TwainAppSession session = new TwainAppSession(new TW_IDENTITY_LEGACY(Environment.ProcessPath!));
|
||||||
|
|
||||||
session.StateChanged += Session_StateChanged;
|
session.StateChanged += Session_StateChanged;
|
||||||
session.SourceDisabled += Session_SourceDisabled1;
|
session.SourceDisabled += Session_SourceDisabled1;
|
||||||
|
@ -37,7 +37,7 @@ namespace WinFormSample
|
|||||||
|
|
||||||
TWPlatform.PreferLegacyDSM = false;
|
TWPlatform.PreferLegacyDSM = false;
|
||||||
|
|
||||||
twain = new TwainAppSession(Assembly.GetExecutingAssembly().Location);
|
twain = new TwainAppSession(new TW_IDENTITY_LEGACY(Assembly.GetExecutingAssembly().Location));
|
||||||
twain.StateChanged += Twain_StateChanged;
|
twain.StateChanged += Twain_StateChanged;
|
||||||
twain.DefaultSourceChanged += Twain_DefaultSourceChanged;
|
twain.DefaultSourceChanged += Twain_DefaultSourceChanged;
|
||||||
twain.CurrentSourceChanged += Twain_CurrentSourceChanged;
|
twain.CurrentSourceChanged += Twain_CurrentSourceChanged;
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace NTwain.Data
|
namespace NTwain.Data
|
||||||
{
|
{
|
||||||
@ -32,6 +34,7 @@ namespace NTwain.Data
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
IsWindows = true;
|
IsWindows = true;
|
||||||
@ -657,6 +660,68 @@ namespace NTwain.Data
|
|||||||
}
|
}
|
||||||
partial struct TW_IDENTITY_LEGACY
|
partial struct TW_IDENTITY_LEGACY
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates app info derived an executable file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="exeFilePath"></param>
|
||||||
|
/// <param name="appLanguage"></param>
|
||||||
|
/// <param name="appCountry"></param>
|
||||||
|
public TW_IDENTITY_LEGACY(
|
||||||
|
string exeFilePath,
|
||||||
|
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA) :
|
||||||
|
this(FileVersionInfo.GetVersionInfo(exeFilePath), appLanguage, appCountry)
|
||||||
|
{ }
|
||||||
|
/// <summary>
|
||||||
|
/// Creates app info derived from a <see cref="FileVersionInfo"/> object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="appInfo"></param>
|
||||||
|
/// <param name="appLanguage"></param>
|
||||||
|
/// <param name="appCountry"></param>
|
||||||
|
public TW_IDENTITY_LEGACY(
|
||||||
|
FileVersionInfo appInfo,
|
||||||
|
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA) :
|
||||||
|
this(
|
||||||
|
appInfo.CompanyName ?? "",
|
||||||
|
appInfo.ProductName ?? "",
|
||||||
|
appInfo.ProductName ?? "",
|
||||||
|
new Version(appInfo.FileVersion ?? "1.0"),
|
||||||
|
appInfo.FileDescription ?? "", appLanguage, appCountry)
|
||||||
|
{ }
|
||||||
|
/// <summary>
|
||||||
|
/// Creates id with explicit app info.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="companyName"></param>
|
||||||
|
/// <param name="productFamily"></param>
|
||||||
|
/// <param name="productName"></param>
|
||||||
|
/// <param name="productVersion"></param>
|
||||||
|
/// <param name="productDescription"></param>
|
||||||
|
/// <param name="appLanguage"></param>
|
||||||
|
/// <param name="appCountry"></param>
|
||||||
|
/// <param name="supportedTypes"></param>
|
||||||
|
public TW_IDENTITY_LEGACY(
|
||||||
|
string companyName, string productFamily, string productName,
|
||||||
|
Version productVersion, string productDescription = "",
|
||||||
|
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA,
|
||||||
|
DG supportedTypes = DG.IMAGE)
|
||||||
|
{
|
||||||
|
Manufacturer = companyName;
|
||||||
|
ProductFamily = productFamily;
|
||||||
|
ProductName = productName;
|
||||||
|
ProtocolMajor = (ushort)TWON_PROTOCOL.MAJOR;
|
||||||
|
ProtocolMinor = (ushort)TWON_PROTOCOL.MINOR;
|
||||||
|
SupportedGroups = (uint)(supportedTypes | DG.CONTROL | DG.APP2);
|
||||||
|
Version = new TW_VERSION
|
||||||
|
{
|
||||||
|
Country = appCountry,
|
||||||
|
Info = productDescription,
|
||||||
|
Language = appLanguage,
|
||||||
|
MajorNum = (ushort)productVersion.Major,
|
||||||
|
MinorNum = (ushort)productVersion.Minor,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A simplified check on whether this has valid data from DSM.
|
/// A simplified check on whether this has valid data from DSM.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
using NTwain.Data;
|
using NTwain.Data;
|
||||||
using NTwain.Triplets;
|
using NTwain.Triplets;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
|
||||||
|
|
||||||
namespace NTwain
|
namespace NTwain
|
||||||
{
|
{
|
||||||
@ -15,81 +12,16 @@ namespace NTwain
|
|||||||
|
|
||||||
public partial class TwainAppSession : IDisposable
|
public partial class TwainAppSession : IDisposable
|
||||||
{
|
{
|
||||||
static bool __encodingRegistered;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates TWAIN session with app info derived an executable file.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="exeFilePath"></param>
|
|
||||||
/// <param name="appLanguage"></param>
|
|
||||||
/// <param name="appCountry"></param>
|
|
||||||
public TwainAppSession(
|
|
||||||
string exeFilePath,
|
|
||||||
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA) :
|
|
||||||
this(FileVersionInfo.GetVersionInfo(exeFilePath), appLanguage, appCountry)
|
|
||||||
{ }
|
|
||||||
/// <summary>
|
|
||||||
/// Creates TWAIN session with app info derived from a <see cref="FileVersionInfo"/> object.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="appInfo"></param>
|
|
||||||
/// <param name="appLanguage"></param>
|
|
||||||
/// <param name="appCountry"></param>
|
|
||||||
public TwainAppSession(
|
|
||||||
FileVersionInfo appInfo,
|
|
||||||
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA) :
|
|
||||||
this(
|
|
||||||
appInfo.CompanyName ?? "",
|
|
||||||
appInfo.ProductName ?? "",
|
|
||||||
appInfo.ProductName ?? "",
|
|
||||||
new Version(appInfo.FileVersion ?? "1.0"),
|
|
||||||
appInfo.FileDescription ?? "", appLanguage, appCountry)
|
|
||||||
{ }
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates TWAIN session with explicit app info.
|
/// Creates TWAIN session with explicit app info.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="companyName"></param>
|
/// <param name="appId"></param>
|
||||||
/// <param name="productFamily"></param>
|
public TwainAppSession(TW_IDENTITY_LEGACY appId)
|
||||||
/// <param name="productName"></param>
|
|
||||||
/// <param name="productVersion"></param>
|
|
||||||
/// <param name="productDescription"></param>
|
|
||||||
/// <param name="appLanguage"></param>
|
|
||||||
/// <param name="appCountry"></param>
|
|
||||||
/// <param name="supportedTypes"></param>
|
|
||||||
public TwainAppSession(
|
|
||||||
string companyName, string productFamily, string productName,
|
|
||||||
Version productVersion, string productDescription = "",
|
|
||||||
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA,
|
|
||||||
DG supportedTypes = DG.IMAGE)
|
|
||||||
{
|
{
|
||||||
#if WINDOWS || NETFRAMEWORK
|
#if WINDOWS || NETFRAMEWORK
|
||||||
DSM.DsmLoader.TryLoadCustomDSM();
|
DSM.DsmLoader.TryLoadCustomDSM();
|
||||||
#endif
|
#endif
|
||||||
// todo: find a better place for this
|
_appIdentity = appId;
|
||||||
if (!__encodingRegistered)
|
|
||||||
{
|
|
||||||
#if !NETFRAMEWORK
|
|
||||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
||||||
#endif
|
|
||||||
__encodingRegistered = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_appIdentity = new()
|
|
||||||
{
|
|
||||||
Manufacturer = companyName,
|
|
||||||
ProductFamily = productFamily,
|
|
||||||
ProductName = productName,
|
|
||||||
ProtocolMajor = (ushort)TWON_PROTOCOL.MAJOR,
|
|
||||||
ProtocolMinor = (ushort)TWON_PROTOCOL.MINOR,
|
|
||||||
SupportedGroups = (uint)(supportedTypes | DG.CONTROL | DG.APP2),
|
|
||||||
Version = new TW_VERSION
|
|
||||||
{
|
|
||||||
Country = appCountry,
|
|
||||||
Info = productDescription,
|
|
||||||
Language = appLanguage,
|
|
||||||
MajorNum = (ushort)productVersion.Major,
|
|
||||||
MinorNum = (ushort)productVersion.Minor,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
_legacyCallbackDelegate = LegacyCallbackHandler;
|
_legacyCallbackDelegate = LegacyCallbackHandler;
|
||||||
_osxCallbackDelegate = OSXCallbackHandler;
|
_osxCallbackDelegate = OSXCallbackHandler;
|
||||||
@ -97,6 +29,7 @@ namespace NTwain
|
|||||||
StartTransferThread();
|
StartTransferThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal IntPtr _hwnd;
|
internal IntPtr _hwnd;
|
||||||
internal TW_USERINTERFACE _userInterface; // kept around for disable to use
|
internal TW_USERINTERFACE _userInterface; // kept around for disable to use
|
||||||
#if WINDOWS || NETFRAMEWORK
|
#if WINDOWS || NETFRAMEWORK
|
||||||
|
Loading…
Reference in New Issue
Block a user