1
0
mirror of https://github.com/soukoku/ntwain.git synced 2025-04-05 20:59:23 +08:00

Attempt on file xfer.

This commit is contained in:
Eugene Wang 2023-04-07 23:07:44 -04:00
parent 54c7fc1d50
commit 443419ff64
3 changed files with 67 additions and 19 deletions

View File

@ -11,6 +11,14 @@ namespace NTwain
readonly TwainAppSession _twain;
readonly bool _isImage;
internal DataTransferredEventArgs(TwainAppSession twain, bool isImage, TW_SETUPFILEXFER xfer)
{
_twain = twain;
_isImage = isImage;
File = xfer;
}
/// <summary>
/// Ctor for array data;
/// </summary>
@ -33,6 +41,11 @@ namespace NTwain
/// </summary>
public byte[]? Data { get; }
/// <summary>
/// The file info if this was a file transfer.
/// </summary>
public TW_SETUPFILEXFER? File { get; }
/// <summary>
/// Gets the final image information if transfer was an image.

View File

@ -8,14 +8,23 @@ namespace NTwain.Triplets.ControlDATs
/// </summary>
public class SetupFileXfer
{
public TWRC Get(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, ref TW_SETUPFILEXFER data)
=> DoIt(ref app, ref ds, MSG.GET, ref data);
public TWRC Get(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, out TW_SETUPFILEXFER data)
{
data = default;
return DoIt(ref app, ref ds, MSG.GET, ref data);
}
public TWRC Set(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, ref TW_SETUPFILEXFER data)
=> DoIt(ref app, ref ds, MSG.SET, ref data);
public TWRC GetDefault(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, ref TW_SETUPFILEXFER data)
=> DoIt(ref app, ref ds, MSG.GETDEFAULT, ref data);
public TWRC Reset(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, ref TW_SETUPFILEXFER data)
=> DoIt(ref app, ref ds, MSG.RESET, ref data);
public TWRC GetDefault(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, out TW_SETUPFILEXFER data)
{
data = default;
return DoIt(ref app, ref ds, MSG.GETDEFAULT, ref data);
}
public TWRC Reset(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, out TW_SETUPFILEXFER data)
{
data = default;
return DoIt(ref app, ref ds, MSG.RESET, ref data);
}
static TWRC DoIt(ref TW_IDENTITY_LEGACY app, ref TW_IDENTITY_LEGACY ds, MSG msg, ref TW_SETUPFILEXFER data)

View File

@ -147,10 +147,10 @@ namespace NTwain
//{
//if (_closeDsRequested)
//{
_uiThreadMarshaller.BeginInvoke(() =>
{
DisableSource();
});
_uiThreadMarshaller.BeginInvoke(() =>
{
DisableSource();
});
//}
}
@ -176,7 +176,39 @@ namespace NTwain
private STS TransferFileImage()
{
return default;
STS sts = default;
try
{
// assuming user already configured the transfer in transferready event
// get what will be transferred
DGControl.SetupFileXfer.Get(ref _appIdentity, ref _currentDS, out TW_SETUPFILEXFER xfer);
// and just start it
sts = WrapInSTS(DGImage.ImageFileXfer.Get(ref _appIdentity, ref _currentDS));
if (sts.RC == TWRC.XFERDONE)
{
State = STATE.S7;
try
{
var args = new DataTransferredEventArgs(this, true, xfer);
DataTransferred?.Invoke(this, args);
}
catch { }
}
else
{
HandleNonSuccessXferCode(sts);
}
}
catch (Exception ex)
{
try
{
TransferError?.Invoke(this, new TransferErrorEventArgs(ex));
}
catch { }
}
return sts;
}
private STS TransferNativeImage()
@ -235,14 +267,8 @@ namespace NTwain
finally
{
State = STATE.S6;
if (lockedPtr != IntPtr.Zero)
{
Unlock(dataPtr);
}
if (dataPtr != IntPtr.Zero)
{
Free(dataPtr);
}
if (lockedPtr != IntPtr.Zero) Unlock(dataPtr);
if (dataPtr != IntPtr.Zero) Free(dataPtr);
}
return sts;
}