mirror of
https://github.com/soukoku/ntwain.git
synced 2025-08-20 06:46:51 +08:00
Add method to set filexfer options on xferready event.
This commit is contained in:
parent
b2fe1c1bcd
commit
e3dfa8f4dd
@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<!--change these in each release-->
|
||||
<VersionPrefix>4.0.0.0</VersionPrefix>
|
||||
<VersionSuffix>alpha.5</VersionSuffix>
|
||||
<VersionSuffix>alpha.6</VersionSuffix>
|
||||
|
||||
<!--keep it the same until major # changes-->
|
||||
<AssemblyVersion>4.0.0.0</AssemblyVersion>
|
||||
|
@ -8,11 +8,11 @@ namespace NTwain
|
||||
/// </summary>
|
||||
public class TransferReadyEventArgs : EventArgs
|
||||
{
|
||||
public TransferReadyEventArgs(TWSX imgXferMech, TWSX audXferMech, int pendingCount, TWEJ endOfJobFlag)
|
||||
public TransferReadyEventArgs(TwainAppSession twain, TWSX imgXferMech, TWSX audXferMech, int pendingCount, TWEJ endOfJobFlag)
|
||||
{
|
||||
_twain = twain;
|
||||
ImgXferMech = imgXferMech;
|
||||
AudXferMech = audXferMech;
|
||||
//_twain = twain;
|
||||
PendingCount = pendingCount;
|
||||
EndOfJobFlag = endOfJobFlag;
|
||||
}
|
||||
@ -43,9 +43,20 @@ namespace NTwain
|
||||
/// </summary>
|
||||
public int PendingCount { get; private set; }
|
||||
|
||||
//TW_IMAGEINFO? _imgInfo;
|
||||
//private readonly TwainAppSession _twain;
|
||||
private readonly TwainAppSession _twain;
|
||||
|
||||
/// <summary>
|
||||
/// If the transfer mech is file-related,
|
||||
/// setup the file transfer options here.
|
||||
/// </summary>
|
||||
/// <param name="fileXfer"></param>
|
||||
/// <returns></returns>
|
||||
public STS SetupFileTransfer(ref TW_SETUPFILEXFER fileXfer)
|
||||
{
|
||||
return _twain.SetFileXfer(ref fileXfer);
|
||||
}
|
||||
|
||||
//TW_IMAGEINFO? _imgInfo;
|
||||
///// <summary>
|
||||
///// Gets the tentative image information for the current transfer if applicable.
|
||||
///// This may differ from the final image depending on the transfer mode used (mostly when doing mem xfer).
|
||||
|
@ -3,45 +3,45 @@ using NTwain.Triplets;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace NTwain
|
||||
{
|
||||
// this file contains property and event definitions
|
||||
namespace NTwain;
|
||||
|
||||
partial class TwainAppSession
|
||||
{
|
||||
// this file contains property and event definitions
|
||||
|
||||
partial class TwainAppSession
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the app identity.
|
||||
/// </summary>
|
||||
public TW_IDENTITY_LEGACY AppIdentity
|
||||
{
|
||||
get => _appIdentity;
|
||||
get => _appIdentity;
|
||||
}
|
||||
TW_IDENTITY_LEGACY _appIdentity;
|
||||
internal TW_IDENTITY_LEGACY _appIdentity;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current (opened) data source.
|
||||
/// </summary>
|
||||
public TW_IDENTITY_LEGACY CurrentSource
|
||||
{
|
||||
get => _currentDS;
|
||||
protected set
|
||||
{
|
||||
_currentDS = value;
|
||||
try
|
||||
get => _currentDS;
|
||||
protected set
|
||||
{
|
||||
CurrentSourceChanged?.Invoke(this, value);
|
||||
_currentDS = value;
|
||||
try
|
||||
{
|
||||
CurrentSourceChanged?.Invoke(this, value);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
TW_IDENTITY_LEGACY _currentDS;
|
||||
internal TW_IDENTITY_LEGACY _currentDS;
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the default data source.
|
||||
/// </summary>
|
||||
public TW_IDENTITY_LEGACY DefaultSource
|
||||
{
|
||||
get => _defaultDS;
|
||||
get => _defaultDS;
|
||||
}
|
||||
TW_IDENTITY_LEGACY _defaultDS;
|
||||
|
||||
@ -51,19 +51,19 @@ namespace NTwain
|
||||
/// </summary>
|
||||
public STATE State
|
||||
{
|
||||
get => _state;
|
||||
protected set
|
||||
{
|
||||
if (_state != value)
|
||||
get => _state;
|
||||
protected set
|
||||
{
|
||||
_state = value;
|
||||
try
|
||||
{
|
||||
StateChanged?.Invoke(this, value);
|
||||
}
|
||||
catch { }
|
||||
if (_state != value)
|
||||
{
|
||||
_state = value;
|
||||
try
|
||||
{
|
||||
StateChanged?.Invoke(this, value);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
STATE _state = STATE.S1;
|
||||
|
||||
@ -74,49 +74,49 @@ namespace NTwain
|
||||
/// </summary>
|
||||
public byte[]? CustomDsData
|
||||
{
|
||||
get
|
||||
{
|
||||
var rc = DGControl.CustomDsData.Get(ref _appIdentity, ref _currentDS, out TW_CUSTOMDSDATA data);
|
||||
if (rc == TWRC.SUCCESS)
|
||||
get
|
||||
{
|
||||
if (data.hData != IntPtr.Zero && data.InfoLength > 0)
|
||||
{
|
||||
var rc = DGControl.CustomDsData.Get(ref _appIdentity, ref _currentDS, out TW_CUSTOMDSDATA data);
|
||||
if (rc == TWRC.SUCCESS)
|
||||
{
|
||||
if (data.hData != IntPtr.Zero && data.InfoLength > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var lockedPtr = Lock(data.hData);
|
||||
var bytes = new byte[data.InfoLength];
|
||||
Marshal.Copy(lockedPtr, bytes, 0, bytes.Length);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Unlock(data.hData);
|
||||
Free(data.hData);
|
||||
}
|
||||
}
|
||||
//return Array.Empty<byte>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null || value.Length == 0) return;
|
||||
|
||||
TW_CUSTOMDSDATA data = default;
|
||||
data.InfoLength = (uint)value.Length;
|
||||
data.hData = Alloc(data.InfoLength);
|
||||
try
|
||||
{
|
||||
var lockedPtr = Lock(data.hData);
|
||||
var bytes = new byte[data.InfoLength];
|
||||
Marshal.Copy(lockedPtr, bytes, 0, bytes.Length);
|
||||
var lockedPtr = Lock(data.hData);
|
||||
Marshal.Copy(value, 0, lockedPtr, value.Length);
|
||||
Unlock(data.hData);
|
||||
var rc = DGControl.CustomDsData.Set(ref _appIdentity, ref _currentDS, ref data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Unlock(data.hData);
|
||||
Free(data.hData);
|
||||
// should be freed already if no error but just in case
|
||||
if (data.hData != IntPtr.Zero) Free(data.hData);
|
||||
}
|
||||
}
|
||||
//return Array.Empty<byte>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null || value.Length == 0) return;
|
||||
|
||||
TW_CUSTOMDSDATA data = default;
|
||||
data.InfoLength = (uint)value.Length;
|
||||
data.hData = Alloc(data.InfoLength);
|
||||
try
|
||||
{
|
||||
var lockedPtr = Lock(data.hData);
|
||||
Marshal.Copy(value, 0, lockedPtr, value.Length);
|
||||
Unlock(data.hData);
|
||||
var rc = DGControl.CustomDsData.Set(ref _appIdentity, ref _currentDS, ref data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// should be freed already if no error but just in case
|
||||
if (data.hData != IntPtr.Zero) Free(data.hData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -166,5 +166,4 @@ namespace NTwain
|
||||
/// This is NOT raised on the UI thread for reasons.
|
||||
/// </summary>
|
||||
public event TwainEventDelegate<TransferredEventArgs>? Transferred;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,17 @@ namespace NTwain
|
||||
return WrapInSTS(DGImage.ExtImageInfo.Get(ref _appIdentity, ref _currentDS, ref container));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can only be called in state 6, so it's here and only exposed
|
||||
/// in transfer ready event.
|
||||
/// </summary>
|
||||
/// <param name="settings"></param>
|
||||
/// <returns></returns>
|
||||
internal STS SetFileXfer(ref TW_SETUPFILEXFER settings)
|
||||
{
|
||||
return WrapInSTS(DGControl.SetupFileXfer.Set(ref _appIdentity, ref _currentDS, ref settings));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Start the transfer loop.
|
||||
@ -66,7 +77,7 @@ namespace NTwain
|
||||
{
|
||||
do
|
||||
{
|
||||
var readyArgs = new TransferReadyEventArgs(imgXferMech, audXferMech, pending.Count, (TWEJ)pending.EOJ);
|
||||
var readyArgs = new TransferReadyEventArgs(this, imgXferMech, audXferMech, pending.Count, (TWEJ)pending.EOJ);
|
||||
try
|
||||
{
|
||||
TransferReady?.Invoke(this, readyArgs);
|
||||
|
Loading…
Reference in New Issue
Block a user