From 44c022494b0ab28a276f2ec931074991893dcf50 Mon Sep 17 00:00:00 2001 From: Eugene Wang Date: Sun, 18 Nov 2018 11:52:24 -0500 Subject: [PATCH] Added FileSystem triplets and simplified other triplet classes. --- src/NTwain/Triplets/Control/CustomDSData.cs | 52 ++--- src/NTwain/Triplets/Control/FileSystem.cs | 179 +++++++++++++++++ src/NTwain/Triplets/Control/Identity.cs | 190 +++---------------- src/NTwain/Triplets/Control/PendingXfers.cs | 116 +++-------- src/NTwain/Triplets/Control/UserInterface.cs | 85 +++------ src/NTwain/Triplets/Control/XferGroup.cs | 56 ++---- src/NTwain/Triplets/DGControl.cs | 6 + 7 files changed, 297 insertions(+), 387 deletions(-) create mode 100644 src/NTwain/Triplets/Control/FileSystem.cs diff --git a/src/NTwain/Triplets/Control/CustomDSData.cs b/src/NTwain/Triplets/Control/CustomDSData.cs index 33e56f5..8361ee0 100644 --- a/src/NTwain/Triplets/Control/CustomDSData.cs +++ b/src/NTwain/Triplets/Control/CustomDSData.cs @@ -7,60 +7,42 @@ namespace NTwain.Triplets.Control { internal CustomDSData(TwainSession session) : base(session) { } - public ReturnCode Get(ref TW_CUSTOMDSDATA data) + ReturnCode DoIt(Message msg, ref TW_CUSTOMDSDATA data) { if (Is32Bit) { if (IsWin) return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.CustomDSData, Message.Get, ref data); + DataGroups.Control, DataArgumentType.CustomDSData, msg, ref data); if (IsLinux) return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.CustomDSData, Message.Get, ref data); + DataGroups.Control, DataArgumentType.CustomDSData, msg, ref data); if (IsMac) return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.CustomDSData, Message.Get, ref data); + DataGroups.Control, DataArgumentType.CustomDSData, msg, ref data); } if (IsWin) return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.CustomDSData, Message.Get, ref data); + DataGroups.Control, DataArgumentType.CustomDSData, msg, ref data); if (IsLinux) return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.CustomDSData, Message.Get, ref data); + DataGroups.Control, DataArgumentType.CustomDSData, msg, ref data); if (IsMac) return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.CustomDSData, Message.Get, ref data); - - return ReturnCode.Failure; - } - - public ReturnCode Set(ref TW_CUSTOMDSDATA customData) - { - if (Is32Bit) - { - if (IsWin) - return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.CustomDSData, Message.Set, ref data); - if (IsLinux) - return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.CustomDSData, Message.Set, ref data); - if (IsMac) - return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.CustomDSData, Message.Set, ref data); - } - - if (IsWin) - return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.CustomDSData, Message.Set, ref data); - if (IsLinux) - return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.CustomDSData, Message.Set, ref data); - if (IsMac) - return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.CustomDSData, Message.Set, ref data); + DataGroups.Control, DataArgumentType.CustomDSData, msg, ref data); return ReturnCode.Failure; } + + public ReturnCode Get(ref TW_CUSTOMDSDATA data) + { + return DoIt(Message.Get, ref data); + } + + public ReturnCode Set(ref TW_CUSTOMDSDATA data) + { + return DoIt(Message.Set, ref data); + } } } \ No newline at end of file diff --git a/src/NTwain/Triplets/Control/FileSystem.cs b/src/NTwain/Triplets/Control/FileSystem.cs new file mode 100644 index 0000000..a6546f6 --- /dev/null +++ b/src/NTwain/Triplets/Control/FileSystem.cs @@ -0,0 +1,179 @@ +using NTwain.Data; +using NTwain.Internals; + +namespace NTwain.Triplets.Control +{ + /// + /// Represents . + /// + public sealed class FileSystem : BaseTriplet + { + internal FileSystem(TwainSession session) : base(session) { } + + ReturnCode DoIt(Message msg, ref TW_FILESYSTEM fileSystem) + { + if (Is32Bit) + { + if (IsWin) + return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, + DataGroups.Control, DataArgumentType.FileSystem, msg, ref fileSystem); + if (IsLinux) + return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, + DataGroups.Control, DataArgumentType.FileSystem, msg, ref fileSystem); + if (IsMac) + return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, + DataGroups.Control, DataArgumentType.FileSystem, msg, ref fileSystem); + } + + if (IsWin) + return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, + DataGroups.Control, DataArgumentType.FileSystem, msg, ref fileSystem); + if (IsLinux) + return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, + DataGroups.Control, DataArgumentType.FileSystem, msg, ref fileSystem); + if (IsMac) + return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, + DataGroups.Control, DataArgumentType.FileSystem, msg, ref fileSystem); + + return ReturnCode.Failure; + } + + /// + /// This operation selects the destination directory within the Source (camera, storage, etc), where + /// images captured using CapAutomaticCapture will be stored. This command only selects + /// the destination directory (a file of type Directory). The directory must exist and be + /// accessible to the Source. The creation of images within the directory is at the discretion of the + /// Source, and may result in the creation of additional sub-directories. + /// + /// The file system. + /// + public ReturnCode AutomaticCaptureDirectory(ref TW_FILESYSTEM fileSystem) + { + return DoIt(Message.AutomaticCaptureDirectory, ref fileSystem); + } + + /// + /// This operation selects the current device within the Source (camera, storage, etc). If the device is + /// a , then this command enters a directory that can contain files. If the + /// device is a , then this command enters a directory that can contain + /// files. If the device is a , then this command enters a + /// directory that can contain or files. + /// + /// The file system. + /// + public ReturnCode ChangeDirectory(ref TW_FILESYSTEM fileSystem) + { + return DoIt(Message.ChangeDirectory, ref fileSystem); + } + + /// + /// This operation copies a file or directory. Absolute and relative pathnames are supported. A file + /// may not be overwritten with this command. If an Application wishes to do this, it must first + /// delete the unwanted file and then reissue the Copy command. + /// The Application specifies the path and name of the entry to be copied in InputName. The + /// Application specifies the new patch and name in OutputName. + /// It is not permitted to copy files into the root directory. + /// + /// The file system. + /// + public ReturnCode Copy(ref TW_FILESYSTEM fileSystem) + { + return DoIt(Message.Copy, ref fileSystem); + } + + /// + /// This operation creates a new directory within the current directory. Pathnames are not allowed, + /// only the name of the new directory can be specified. + /// + /// The file system. + /// + public ReturnCode CreateDirectory(ref TW_FILESYSTEM fileSystem) + { + return DoIt(Message.CreateDirectory, ref fileSystem); + } + + /// + /// This operation deletes a file or directory on the device. Pathnames are not allowed, only the + /// name of the file or directory to be deleted can be specified. Recursive deletion can be specified + /// by setting the Recursive to TRUE. + /// + /// The file system. + /// + public ReturnCode Delete(ref TW_FILESYSTEM fileSystem) + { + return DoIt(Message.Delete, ref fileSystem); + } + + /// + /// This operation formats the specified storage. This operation destroys all images and subdirectories + /// under the selected device. Use with caution. + /// + /// The file system. + /// + public ReturnCode FormatMedia(ref TW_FILESYSTEM fileSystem) + { + return DoIt(Message.FormatMedia, ref fileSystem); + } + + /// + /// The operation frees the Context field in fileSystem. + /// Every call to GetFirstFile must be matched by + /// a call to GetClose to release the Context field. + /// + /// The file system. + /// + public ReturnCode GetClose(ref TW_FILESYSTEM fileSystem) + { + return DoIt(Message.GetClose, ref fileSystem); + } + + /// + /// This operation gets the first filename in a directory, and returns information about that file (the + /// same information that can be retrieved with GetInfo). + /// + /// The file system. + /// + public ReturnCode GetFirstFile(ref TW_FILESYSTEM fileSystem) + { + return DoIt(Message.GetFirstFile, ref fileSystem); + } + + /// + /// This operation fills the information fields in fileSystem. + /// InputName contains the absolute or relative path and filename of the requested file. + /// OutputName returns the absolute path to the file. + /// + /// The file system. + /// + public ReturnCode GetInfo(ref TW_FILESYSTEM fileSystem) + { + return DoIt(Message.GetInfo, ref fileSystem); + } + + /// + /// This operation gets the next filename in a directory, and returns information about that file (the + /// same information that can be retrieved with GetInfo). + /// + /// The file system. + /// + public ReturnCode GetNextFile(ref TW_FILESYSTEM fileSystem) + { + return DoIt(Message.GetNextFile, ref fileSystem); + } + + /// + /// This operation renames (and optionally moves) a file or directory. Absolute and relative path + /// names are supported. A file may not be overwritten with this command. If an Application + /// wishes to do this it must first delete the unwanted file, then issue the rename command. + /// The Application specifies the path and name of the entry to be renamed in InputName. The + /// Application specifies the new path and name in OutputName. + /// Filenames in the root directory cannot be moved or renamed. + /// + /// The file system. + /// + public ReturnCode Rename(ref TW_FILESYSTEM fileSystem) + { + return DoIt(Message.Rename, ref fileSystem); + } + } +} \ No newline at end of file diff --git a/src/NTwain/Triplets/Control/Identity.cs b/src/NTwain/Triplets/Control/Identity.cs index d315be0..3957f57 100644 --- a/src/NTwain/Triplets/Control/Identity.cs +++ b/src/NTwain/Triplets/Control/Identity.cs @@ -8,35 +8,40 @@ namespace NTwain.Triplets.Control { internal Identity(TwainSession session) : base(session) { } - public ReturnCode CloseDS(TW_IDENTITY source) + ReturnCode DoIt(Message msg, TW_IDENTITY source) { - var rc = ReturnCode.Failure; - if (Is32Bit) { if (IsWin) - rc = NativeMethods.DsmWin32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.CloseDS, source); + return NativeMethods.DsmWin32(Session.Config.App32, IntPtr.Zero, + DataGroups.Control, DataArgumentType.Identity, msg, source); else if (IsLinux) - rc = NativeMethods.DsmLinux32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.CloseDS, source); + return NativeMethods.DsmLinux32(Session.Config.App32, IntPtr.Zero, + DataGroups.Control, DataArgumentType.Identity, msg, source); else if (IsMac) - rc = NativeMethods.DsmMac32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.CloseDS, source); + return NativeMethods.DsmMac32(Session.Config.App32, IntPtr.Zero, + DataGroups.Control, DataArgumentType.Identity, msg, source); } else { if (IsWin) - rc = NativeMethods.DsmWin64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.CloseDS, source); + return NativeMethods.DsmWin64(Session.Config.App32, IntPtr.Zero, + DataGroups.Control, DataArgumentType.Identity, msg, source); else if (IsLinux) - rc = NativeMethods.DsmLinux64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.CloseDS, source); + return NativeMethods.DsmLinux64(Session.Config.App32, IntPtr.Zero, + DataGroups.Control, DataArgumentType.Identity, msg, source); else if (IsMac) - rc = NativeMethods.DsmMac64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.CloseDS, source); + return NativeMethods.DsmMac64(Session.Config.App32, IntPtr.Zero, + DataGroups.Control, DataArgumentType.Identity, msg, source); } + return ReturnCode.Failure; + } + + public ReturnCode CloseDS(TW_IDENTITY source) + { + var rc = DoIt(Message.CloseDS, source); + if (rc == ReturnCode.Success) { Session.State = TwainState.S3; @@ -48,33 +53,8 @@ namespace NTwain.Triplets.Control public ReturnCode OpenDS(TW_IDENTITY source) { Session.StepDown(TwainState.DsmOpened); - var rc = ReturnCode.Failure; - - if (Is32Bit) - { - if (IsWin) - rc = NativeMethods.DsmWin32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.OpenDS, source); - else if (IsLinux) - rc = NativeMethods.DsmLinux32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.OpenDS, source); - else if (IsMac) - rc = NativeMethods.DsmMac32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.OpenDS, source); - } - else - { - if (IsWin) - rc = NativeMethods.DsmWin64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.OpenDS, source); - else if (IsLinux) - rc = NativeMethods.DsmLinux64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.OpenDS, source); - else if (IsMac) - rc = NativeMethods.DsmMac64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.OpenDS, source); - } - + var rc = DoIt(Message.OpenDS, source); + if (rc == ReturnCode.Success) { Session.CurrentSource = Session.GetSourceSingleton(source); @@ -87,145 +67,31 @@ namespace NTwain.Triplets.Control public ReturnCode GetDefault(out TW_IDENTITY source) { source = new TW_IDENTITY(); - if (Is32Bit) - { - if (IsWin) - return NativeMethods.DsmWin32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetDefault, source); - if (IsLinux) - return NativeMethods.DsmLinux32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetDefault, source); - if (IsMac) - return NativeMethods.DsmMac32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetDefault, source); - } - - if (IsWin) - return NativeMethods.DsmWin64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetDefault, source); - if (IsLinux) - return NativeMethods.DsmLinux64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetDefault, source); - if (IsMac) - return NativeMethods.DsmMac64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetDefault, source); - - return ReturnCode.Failure; + return DoIt(Message.GetDefault, source); } public ReturnCode GetFirst(out TW_IDENTITY source) { source = new TW_IDENTITY(); - if (Is32Bit) - { - if (IsWin) - return NativeMethods.DsmWin32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetFirst, source); - if (IsLinux) - return NativeMethods.DsmLinux32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetFirst, source); - if (IsMac) - return NativeMethods.DsmMac32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetFirst, source); - } - - if (IsWin) - return NativeMethods.DsmWin64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetFirst, source); - if (IsLinux) - return NativeMethods.DsmLinux64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetFirst, source); - if (IsMac) - return NativeMethods.DsmMac64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetFirst, source); - - return ReturnCode.Failure; + return DoIt(Message.GetFirst, source); } public ReturnCode GetNext(out TW_IDENTITY source) { source = new TW_IDENTITY(); - if (Is32Bit) - { - if (IsWin) - return NativeMethods.DsmWin32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetNext, source); - if (IsLinux) - return NativeMethods.DsmLinux32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetNext, source); - if (IsMac) - return NativeMethods.DsmMac32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetNext, source); - } - - if (IsWin) - return NativeMethods.DsmWin64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetNext, source); - if (IsLinux) - return NativeMethods.DsmLinux64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetNext, source); - if (IsMac) - return NativeMethods.DsmMac64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.GetNext, source); - - return ReturnCode.Failure; + return DoIt(Message.GetNext, source); } public ReturnCode Set(DataSource source) { - if (Is32Bit) - { - if (IsWin) - return NativeMethods.DsmWin32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.Set, source?.Identity32); - if (IsLinux) - return NativeMethods.DsmLinux32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.Set, source?.Identity32); - if (IsMac) - return NativeMethods.DsmMac32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.Set, source?.Identity32); - } - - if (IsWin) - return NativeMethods.DsmWin64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.Set, source?.Identity32); - if (IsLinux) - return NativeMethods.DsmLinux64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.Set, source?.Identity32); - if (IsMac) - return NativeMethods.DsmMac64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.Set, source?.Identity32); - - return ReturnCode.Failure; + // TODO: platform handling + return DoIt(Message.Set, source?.Identity32); } public ReturnCode UserSelect(out TW_IDENTITY source) { source = new TW_IDENTITY(); - if (Is32Bit) - { - if (IsWin) - return NativeMethods.DsmWin32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.UserSelect, source); - if (IsLinux) - return NativeMethods.DsmLinux32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.UserSelect, source); - if (IsMac) - return NativeMethods.DsmMac32(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.UserSelect, source); - } - - if (IsWin) - return NativeMethods.DsmWin64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.UserSelect, source); - if (IsLinux) - return NativeMethods.DsmLinux64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.UserSelect, source); - if (IsMac) - return NativeMethods.DsmMac64(Session.Config.App32, IntPtr.Zero, - DataGroups.Control, DataArgumentType.Identity, Message.UserSelect, source); - - return ReturnCode.Failure; + return DoIt(Message.UserSelect, source); } } } \ No newline at end of file diff --git a/src/NTwain/Triplets/Control/PendingXfers.cs b/src/NTwain/Triplets/Control/PendingXfers.cs index 2b5f331..1c68249 100644 --- a/src/NTwain/Triplets/Control/PendingXfers.cs +++ b/src/NTwain/Triplets/Control/PendingXfers.cs @@ -7,42 +7,47 @@ namespace NTwain.Triplets { internal PendingXfers(TwainSession session) : base(session) { } - /// - /// This triplet is used to cancel or terminate a transfer. Issued in state 6, this triplet cancels the next - /// pending transfer, discards the transfer data, and decrements the pending transfers count. In - /// state 7, this triplet terminates the current transfer. If any data has not been transferred (this is - /// only possible during a memory transfer) that data is discarded. - /// - /// The pending xfers. - /// - internal ReturnCode EndXfer(TW_PENDINGXFERS pendingXfers) + ReturnCode DoIt(Message msg, ref TW_PENDINGXFERS pendingXfers) { if (Is32Bit) { if (IsWin) return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.EndXfer, ref pendingXfers); + DataGroups.Control, DataArgumentType.PendingXfers, msg, ref pendingXfers); if (IsLinux) return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.EndXfer, ref pendingXfers); + DataGroups.Control, DataArgumentType.PendingXfers, msg, ref pendingXfers); if (IsMac) return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.EndXfer, ref pendingXfers); + DataGroups.Control, DataArgumentType.PendingXfers, msg, ref pendingXfers); } if (IsWin) return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.EndXfer, ref pendingXfers); + DataGroups.Control, DataArgumentType.PendingXfers, msg, ref pendingXfers); if (IsLinux) return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.EndXfer, ref pendingXfers); + DataGroups.Control, DataArgumentType.PendingXfers, msg, ref pendingXfers); if (IsMac) return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.EndXfer, ref pendingXfers); + DataGroups.Control, DataArgumentType.PendingXfers, msg, ref pendingXfers); return ReturnCode.Failure; } + /// + /// This triplet is used to cancel or terminate a transfer. Issued in state 6, this triplet cancels the next + /// pending transfer, discards the transfer data, and decrements the pending transfers count. In + /// state 7, this triplet terminates the current transfer. If any data has not been transferred (this is + /// only possible during a memory transfer) that data is discarded. + /// + /// The pending xfers. + /// + internal ReturnCode EndXfer(ref TW_PENDINGXFERS pendingXfers) + { + return DoIt(Message.EndXfer, ref pendingXfers); + } + /// /// Returns the number of transfers the Source is ready to supply to the application, upon demand. /// If DAT_XFERGROUP is set to DG_Image, this is the number of images. If DAT_XFERGROUP is set @@ -51,32 +56,9 @@ namespace NTwain.Triplets /// /// The pending xfers. /// - public ReturnCode Get(TW_PENDINGXFERS pendingXfers) + public ReturnCode Get(ref TW_PENDINGXFERS pendingXfers) { - if (Is32Bit) - { - if (IsWin) - return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.Get, ref pendingXfers); - if (IsLinux) - return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.Get, ref pendingXfers); - if (IsMac) - return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.Get, ref pendingXfers); - } - - if (IsWin) - return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.Get, ref pendingXfers); - if (IsLinux) - return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.Get, ref pendingXfers); - if (IsMac) - return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.Get, ref pendingXfers); - - return ReturnCode.Failure; + return DoIt(Message.Get, ref pendingXfers); } /// @@ -84,32 +66,9 @@ namespace NTwain.Triplets /// /// The pending xfers. /// - internal ReturnCode Reset(TW_PENDINGXFERS pendingXfers) + internal ReturnCode Reset(ref TW_PENDINGXFERS pendingXfers) { - if (Is32Bit) - { - if (IsWin) - return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.Reset, ref pendingXfers); - if (IsLinux) - return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.Reset, ref pendingXfers); - if (IsMac) - return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.Reset, ref pendingXfers); - } - - if (IsWin) - return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.Reset, ref pendingXfers); - if (IsLinux) - return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.Reset, ref pendingXfers); - if (IsMac) - return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.Reset, ref pendingXfers); - - return ReturnCode.Failure; + return DoIt(Message.Reset, ref pendingXfers); } /// @@ -118,32 +77,9 @@ namespace NTwain.Triplets /// /// The pending xfers. /// - public ReturnCode StopFeeder(TW_PENDINGXFERS pendingXfers) + public ReturnCode StopFeeder(ref TW_PENDINGXFERS pendingXfers) { - if (Is32Bit) - { - if (IsWin) - return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.StopFeeder, ref pendingXfers); - if (IsLinux) - return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.StopFeeder, ref pendingXfers); - if (IsMac) - return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.StopFeeder, ref pendingXfers); - } - - if (IsWin) - return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.StopFeeder, ref pendingXfers); - if (IsLinux) - return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.StopFeeder, ref pendingXfers); - if (IsMac) - return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.PendingXfers, Message.StopFeeder, ref pendingXfers); - - return ReturnCode.Failure; + return DoIt(Message.StopFeeder, ref pendingXfers); } } } \ No newline at end of file diff --git a/src/NTwain/Triplets/Control/UserInterface.cs b/src/NTwain/Triplets/Control/UserInterface.cs index 428fdf0..a61347f 100644 --- a/src/NTwain/Triplets/Control/UserInterface.cs +++ b/src/NTwain/Triplets/Control/UserInterface.cs @@ -10,35 +10,40 @@ namespace NTwain.Triplets.Control { internal UserInterface(TwainSession session) : base(session) { } - public ReturnCode DisableDS(ref TW_USERINTERFACE ui, bool wasUIonly) + ReturnCode DoIt(Message msg, ref TW_USERINTERFACE ui) { - var rc = ReturnCode.Failure; - if (Is32Bit) { if (IsWin) - rc = NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.DisableDS, ref ui); + return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, + DataGroups.Control, DataArgumentType.UserInterface, msg, ref ui); else if (IsLinux) - rc = NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.DisableDS, ref ui); + return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, + DataGroups.Control, DataArgumentType.UserInterface, msg, ref ui); else if (IsMac) - rc = NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.DisableDS, ref ui); + return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, + DataGroups.Control, DataArgumentType.UserInterface, msg, ref ui); } else { if (IsWin) - rc = NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.DisableDS, ref ui); + return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, + DataGroups.Control, DataArgumentType.UserInterface, msg, ref ui); else if (IsLinux) - rc = NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.DisableDS, ref ui); + return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, + DataGroups.Control, DataArgumentType.UserInterface, msg, ref ui); else if (IsMac) - rc = NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.DisableDS, ref ui); + return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, + DataGroups.Control, DataArgumentType.UserInterface, msg, ref ui); } + return ReturnCode.Failure; + } + + public ReturnCode DisableDS(ref TW_USERINTERFACE ui, bool wasUIonly) + { + var rc = DoIt(Message.DisableDS, ref ui); + if (rc == ReturnCode.Success) { Session.State = TwainState.S4; @@ -58,30 +63,7 @@ namespace NTwain.Triplets.Control { Session.State = TwainState.S5; //tentative - if (Is32Bit) - { - if (IsWin) - rc = NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDS, ref ui); - else if (IsLinux) - rc = NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDS, ref ui); - else if (IsMac) - rc = NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDS, ref ui); - } - else - { - if (IsWin) - rc = NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDS, ref ui); - else if (IsLinux) - rc = NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDS, ref ui); - else if (IsMac) - rc = NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.DisableDS, ref ui); - } + rc = DoIt(Message.EnableDS, ref ui); if (!(rc == ReturnCode.Success && (ui.ShowUI == 0 && rc == ReturnCode.CheckStatus))) @@ -99,30 +81,7 @@ namespace NTwain.Triplets.Control { Session.State = TwainState.S5; //tentative - if (Is32Bit) - { - if (IsWin) - rc = NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDSUIOnly, ref ui); - else if (IsLinux) - rc = NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDSUIOnly, ref ui); - else if (IsMac) - rc = NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDSUIOnly, ref ui); - } - else - { - if (IsWin) - rc = NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDSUIOnly, ref ui); - else if (IsLinux) - rc = NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDSUIOnly, ref ui); - else if (IsMac) - rc = NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.UserInterface, Message.EnableDSUIOnly, ref ui); - } + rc = DoIt(Message.EnableDSUIOnly, ref ui); if (rc != ReturnCode.Success) { diff --git a/src/NTwain/Triplets/Control/XferGroup.cs b/src/NTwain/Triplets/Control/XferGroup.cs index da1480f..9188ea3 100644 --- a/src/NTwain/Triplets/Control/XferGroup.cs +++ b/src/NTwain/Triplets/Control/XferGroup.cs @@ -10,38 +10,43 @@ namespace NTwain.Triplets.Control { internal XferGroup(TwainSession session) : base(session) { } - /// - /// Returns the Data Group (the type of data) for the upcoming transfer. The Source is required to - /// only supply one of the DGs specified in the SupportedGroups field of origin. - /// - /// The value. - /// - public ReturnCode Get(ref DataGroups value) + ReturnCode DoIt(Message msg, ref DataGroups value) { if (Is32Bit) { if (IsWin) return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value); + DataGroups.Control, DataArgumentType.XferGroup, msg, ref value); if (IsLinux) return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value); + DataGroups.Control, DataArgumentType.XferGroup, msg, ref value); if (IsMac) return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value); + DataGroups.Control, DataArgumentType.XferGroup, msg, ref value); } if (IsWin) return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value); + DataGroups.Control, DataArgumentType.XferGroup, msg, ref value); if (IsLinux) return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value); + DataGroups.Control, DataArgumentType.XferGroup, msg, ref value); if (IsMac) return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.XferGroup, Message.Get, ref value); + DataGroups.Control, DataArgumentType.XferGroup, msg, ref value); return ReturnCode.Failure; + } + + /// + /// Returns the Data Group (the type of data) for the upcoming transfer. The Source is required to + /// only supply one of the DGs specified in the SupportedGroups field of origin. + /// + /// The value. + /// + public ReturnCode Get(ref DataGroups value) + { + return DoIt(Message.Get, ref value); } /// @@ -53,30 +58,7 @@ namespace NTwain.Triplets.Control /// public ReturnCode Set(DataGroups value) { - if (Is32Bit) - { - if (IsWin) - return NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value); - if (IsLinux) - return NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value); - if (IsMac) - return NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value); - } - - if (IsWin) - return NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value); - if (IsLinux) - return NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value); - if (IsMac) - return NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, - DataGroups.Control, DataArgumentType.XferGroup, Message.Set, ref value); - - return ReturnCode.Failure; + return DoIt(Message.Set, ref value); } } } \ No newline at end of file diff --git a/src/NTwain/Triplets/DGControl.cs b/src/NTwain/Triplets/DGControl.cs index 42da90d..4c38499 100644 --- a/src/NTwain/Triplets/DGControl.cs +++ b/src/NTwain/Triplets/DGControl.cs @@ -63,6 +63,12 @@ namespace NTwain.Triplets /// public SetupMemXfer SetupMemXfer => _memXfer ?? (_memXfer = new SetupMemXfer(Session)); + FileSystem _fs; + /// + /// Gets the operations defined for DAT_FILESYSTEM. + /// + public FileSystem FileSystem => _fs ?? (_fs = new FileSystem(Session)); + XferGroup _xferGroup; /// /// Gets the operations defined for DAT_XFERGROUP.