From 5678fd3e77ad3e41913647e11a13dba72cd52e30 Mon Sep 17 00:00:00 2001
From: Eugene Wang <8755753+soukoku@users.noreply.github.com>
Date: Tue, 4 Apr 2023 07:48:07 -0400
Subject: [PATCH] Renamed TwainSession to TwainAppSession. I love renaming
things.
---
README.md | 13 +++++-----
samples/WinForm32/Form1.cs | 10 ++++----
src/NTwain/DSM/DSMGenerator.tt | 18 ++++++-------
src/NTwain/DSM/Linux64DSM.cs | 2 +-
src/NTwain/DSM/LinuxBotched64DSM.cs | 2 +-
src/NTwain/DSM/LinuxDSM.cs | 2 +-
src/NTwain/DSM/OSXLegacyDSM.cs | 2 +-
src/NTwain/DSM/OSXNewDSM.cs | 2 +-
src/NTwain/DSM/WinLegacyDSM.cs | 2 +-
src/NTwain/DSM/WinNewDSM.cs | 2 +-
src/NTwain/Data/TWAINH_EXTRAS.cs | 3 +--
src/NTwain/ThreadMarshaller.Windows.cs | 4 +--
src/NTwain/Triplets/Readme.md | 25 +++++++++----------
...lbacks.cs => TwainAppSession.Callbacks.cs} | 2 +-
...ession.Caps.cs => TwainAppSession.Caps.cs} | 2 +-
...on.Memory.cs => TwainAppSession.Memory.cs} | 2 +-
...vents.cs => TwainAppSession.PropEvents.cs} | 10 ++++----
....Sources.cs => TwainAppSession.Sources.cs} | 2 +-
....Windows.cs => TwainAppSession.Windows.cs} | 2 +-
...sion.Xfers.cs => TwainAppSession.Xfers.cs} | 2 +-
.../{TwainSession.cs => TwainAppSession.cs} | 8 +++---
21 files changed, 58 insertions(+), 59 deletions(-)
rename src/NTwain/{TwainSession.Callbacks.cs => TwainAppSession.Callbacks.cs} (98%)
rename src/NTwain/{TwainSession.Caps.cs => TwainAppSession.Caps.cs} (99%)
rename src/NTwain/{TwainSession.Memory.cs => TwainAppSession.Memory.cs} (98%)
rename src/NTwain/{TwainSession.PropEvents.cs => TwainAppSession.PropEvents.cs} (90%)
rename src/NTwain/{TwainSession.Sources.cs => TwainAppSession.Sources.cs} (99%)
rename src/NTwain/{TwainSession.Windows.cs => TwainAppSession.Windows.cs} (98%)
rename src/NTwain/{TwainSession.Xfers.cs => TwainAppSession.Xfers.cs} (98%)
rename src/NTwain/{TwainSession.cs => TwainAppSession.cs} (97%)
diff --git a/README.md b/README.md
index a5fd588..23bb2f2 100644
--- a/README.md
+++ b/README.md
@@ -1,22 +1,23 @@
# TWAIN dotnet library
-NOTE: This is a rewrite test that internally uses parts of
-[twaincs](https://github.com/twain/twain-cs) from
-the TWAIN Working Group. It doesn't fully work yet.
+NOTE: This is a rewrite test that doesn't fully work yet.
Use V3 branch for the current version.
## Info
This is a dotnet library created to make working with
[TWAIN](http://twain.org/) devices easier in dotnet.
-V4 of this lib has these goals:
+It internally uses some parts of the
+[twaincs](https://github.com/twain/twain-cs) code from
+the TWAIN Working Group.
+V4 of this lib has these features:
* Targets latest TWAIN version (2.5).
-* Supports full framework and netcore apps (if the framework is still supported).
+* Runs under full framework (4.6.2+) and netcore variants (6.0+).
## Using the lib
-Before using this lib, you are recommended to become reasonably
+Before using this lib, you are required to be reasonably
familiar with the TWAIN spec and understand how it works in general.
The TWAIN spec can be downloaded from [twain.org](http://twain.org/).
diff --git a/samples/WinForm32/Form1.cs b/samples/WinForm32/Form1.cs
index d0f58cc..a0a75fd 100644
--- a/samples/WinForm32/Form1.cs
+++ b/samples/WinForm32/Form1.cs
@@ -10,7 +10,7 @@ namespace WinForm32
{
public partial class Form1 : Form
{
- private TwainSession twain;
+ private TwainAppSession twain;
public Form1()
{
@@ -18,7 +18,7 @@ namespace WinForm32
Text += TwainPlatform.Is32bit ? " 32bit" : " 64bit";
TwainPlatform.PreferLegacyDSM = false;
- twain = new TwainSession(new WinformMarshaller(this), Assembly.GetExecutingAssembly().Location);
+ twain = new TwainAppSession(new WinformMarshaller(this), Assembly.GetExecutingAssembly().Location);
twain.StateChanged += Twain_StateChanged;
twain.DefaultSourceChanged += Twain_DefaultSourceChanged;
twain.CurrentSourceChanged += Twain_CurrentSourceChanged;
@@ -31,17 +31,17 @@ namespace WinForm32
twain.Dispose();
}
- private void Twain_CurrentSourceChanged(TwainSession arg1, TW_IDENTITY_LEGACY ds)
+ private void Twain_CurrentSourceChanged(TwainAppSession arg1, TW_IDENTITY_LEGACY ds)
{
lblCurrent.Text = ds.ProductName;
}
- private void Twain_DefaultSourceChanged(TwainSession arg1, TW_IDENTITY_LEGACY ds)
+ private void Twain_DefaultSourceChanged(TwainAppSession arg1, TW_IDENTITY_LEGACY ds)
{
lblDefault.Text = ds.ProductName;
}
- private void Twain_StateChanged(TwainSession session, STATE state)
+ private void Twain_StateChanged(TwainAppSession session, STATE state)
{
lblState.Text = state.ToString();
}
diff --git a/src/NTwain/DSM/DSMGenerator.tt b/src/NTwain/DSM/DSMGenerator.tt
index 4f66f41..71407ac 100644
--- a/src/NTwain/DSM/DSMGenerator.tt
+++ b/src/NTwain/DSM/DSMGenerator.tt
@@ -6,14 +6,14 @@
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension="dummy" #>
<#
-List<(string className, string dllPath, string identityClass)> outputs = new() {
- ("OSXLegacyDSM", "/System/Library/Frameworks/framework/TWAIN", "TW_IDENTITY_MACOSX"),
- ("OSXNewDSM", "/Library/Frameworks/TWAINDSM.framework/TWAINDSM", "TW_IDENTITY_MACOSX"),
- ("LinuxDSM", "/usr/local/lib/libtwaindsm.so", "TW_IDENTITY_LEGACY"),
- ("Linux64DSM", "/usr/local/lib64/libtwaindsm.so", "TW_IDENTITY_LEGACY"),
- ("LinuxBotched64DSM", "/usr/local/lib/libtwaindsm.so.2.3.2", "TW_IDENTITY"),
- ("WinLegacyDSM", "twain_32.dll", "TW_IDENTITY_LEGACY"),
- ("WinNewDSM", "twaindsm.dll", "TW_IDENTITY_LEGACY")
+List<(string className, string dllPath, string identityClass, string addlInfo)> outputs = new() {
+ ("OSXLegacyDSM", "/System/Library/Frameworks/framework/TWAIN", "TW_IDENTITY_MACOSX", ""),
+ ("OSXNewDSM", "/Library/Frameworks/TWAINDSM.framework/TWAINDSM", "TW_IDENTITY_MACOSX", ""),
+ ("LinuxDSM", "/usr/local/lib/libtwaindsm.so", "TW_IDENTITY_LEGACY", ""),
+ ("Linux64DSM", "/usr/local/lib64/libtwaindsm.so", "TW_IDENTITY_LEGACY", "For versions since 2.4."),
+ ("LinuxBotched64DSM", "/usr/local/lib/libtwaindsm.so.2.3.2", "TW_IDENTITY", "For versions before 2.4."),
+ ("WinLegacyDSM", "twain_32.dll", "TW_IDENTITY_LEGACY", "For 32bit only."),
+ ("WinNewDSM", "twaindsm.dll", "TW_IDENTITY_LEGACY", "")
};
foreach(var file in outputs) {
@@ -25,7 +25,7 @@ using System.Runtime.InteropServices;
namespace NTwain.DSM
{
///
- /// Low-level pinvoke methods using <#= file.dllPath #>.
+ /// Low-level pinvoke methods using <#= file.dllPath #>. <#= file.addlInfo #>
///
public static class <#= file.className #>
{
diff --git a/src/NTwain/DSM/Linux64DSM.cs b/src/NTwain/DSM/Linux64DSM.cs
index ff32fb8..f9f0a53 100644
--- a/src/NTwain/DSM/Linux64DSM.cs
+++ b/src/NTwain/DSM/Linux64DSM.cs
@@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
namespace NTwain.DSM
{
///
- /// Low-level pinvoke methods using /usr/local/lib64/libtwaindsm.so.
+ /// Low-level pinvoke methods using /usr/local/lib64/libtwaindsm.so. For versions since 2.4.
///
public static class Linux64DSM
{
diff --git a/src/NTwain/DSM/LinuxBotched64DSM.cs b/src/NTwain/DSM/LinuxBotched64DSM.cs
index 46a0619..cd93707 100644
--- a/src/NTwain/DSM/LinuxBotched64DSM.cs
+++ b/src/NTwain/DSM/LinuxBotched64DSM.cs
@@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
namespace NTwain.DSM
{
///
- /// Low-level pinvoke methods using /usr/local/lib/libtwaindsm.so.2.3.2.
+ /// Low-level pinvoke methods using /usr/local/lib/libtwaindsm.so.2.3.2. For versions before 2.4.
///
public static class LinuxBotched64DSM
{
diff --git a/src/NTwain/DSM/LinuxDSM.cs b/src/NTwain/DSM/LinuxDSM.cs
index 9cbb3d8..4d1ae05 100644
--- a/src/NTwain/DSM/LinuxDSM.cs
+++ b/src/NTwain/DSM/LinuxDSM.cs
@@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
namespace NTwain.DSM
{
///
- /// Low-level pinvoke methods using /usr/local/lib/libtwaindsm.so.
+ /// Low-level pinvoke methods using /usr/local/lib/libtwaindsm.so.
///
public static class LinuxDSM
{
diff --git a/src/NTwain/DSM/OSXLegacyDSM.cs b/src/NTwain/DSM/OSXLegacyDSM.cs
index 1aa212e..2b17618 100644
--- a/src/NTwain/DSM/OSXLegacyDSM.cs
+++ b/src/NTwain/DSM/OSXLegacyDSM.cs
@@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
namespace NTwain.DSM
{
///
- /// Low-level pinvoke methods using /System/Library/Frameworks/framework/TWAIN.
+ /// Low-level pinvoke methods using /System/Library/Frameworks/framework/TWAIN.
///
public static class OSXLegacyDSM
{
diff --git a/src/NTwain/DSM/OSXNewDSM.cs b/src/NTwain/DSM/OSXNewDSM.cs
index 1d020a7..d0fce04 100644
--- a/src/NTwain/DSM/OSXNewDSM.cs
+++ b/src/NTwain/DSM/OSXNewDSM.cs
@@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
namespace NTwain.DSM
{
///
- /// Low-level pinvoke methods using /Library/Frameworks/TWAINDSM.framework/TWAINDSM.
+ /// Low-level pinvoke methods using /Library/Frameworks/TWAINDSM.framework/TWAINDSM.
///
public static class OSXNewDSM
{
diff --git a/src/NTwain/DSM/WinLegacyDSM.cs b/src/NTwain/DSM/WinLegacyDSM.cs
index 3032132..0e556ca 100644
--- a/src/NTwain/DSM/WinLegacyDSM.cs
+++ b/src/NTwain/DSM/WinLegacyDSM.cs
@@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
namespace NTwain.DSM
{
///
- /// Low-level pinvoke methods using twain_32.dll.
+ /// Low-level pinvoke methods using twain_32.dll. For 32bit only.
///
public static class WinLegacyDSM
{
diff --git a/src/NTwain/DSM/WinNewDSM.cs b/src/NTwain/DSM/WinNewDSM.cs
index 1c300d0..e46fc83 100644
--- a/src/NTwain/DSM/WinNewDSM.cs
+++ b/src/NTwain/DSM/WinNewDSM.cs
@@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
namespace NTwain.DSM
{
///
- /// Low-level pinvoke methods using twaindsm.dll.
+ /// Low-level pinvoke methods using twaindsm.dll.
///
public static class WinNewDSM
{
diff --git a/src/NTwain/Data/TWAINH_EXTRAS.cs b/src/NTwain/Data/TWAINH_EXTRAS.cs
index c94be17..44e105f 100644
--- a/src/NTwain/Data/TWAINH_EXTRAS.cs
+++ b/src/NTwain/Data/TWAINH_EXTRAS.cs
@@ -724,8 +724,7 @@ namespace NTwain.Data
//// unsafe method with 1 copy (does it work?)
//sbyte* bytes = (sbyte*)locked;
- //var str = new string(bytes, 0, length, Encoding.UTF8);
- //return str;
+ //val = new string(bytes, 0, length, Encoding.UTF8);
#else
val = Marshal.PtrToStringUTF8(locked, (int)Size);
#endif
diff --git a/src/NTwain/ThreadMarshaller.Windows.cs b/src/NTwain/ThreadMarshaller.Windows.cs
index a15f9c9..aa1d0e7 100644
--- a/src/NTwain/ThreadMarshaller.Windows.cs
+++ b/src/NTwain/ThreadMarshaller.Windows.cs
@@ -7,7 +7,7 @@ namespace NTwain
{
///
/// An that can be used
- /// to integrate with
+ /// to integrate with
/// an existing Winforms app.
///
public class WinformMarshaller : IThreadMarshaller
@@ -32,7 +32,7 @@ namespace NTwain
///
/// An that can be used
- /// to integrate with
+ /// to integrate with
/// an existing WPF app.
///
public class WpfMarshaller : IThreadMarshaller
diff --git a/src/NTwain/Triplets/Readme.md b/src/NTwain/Triplets/Readme.md
index a881735..bf4ab7f 100644
--- a/src/NTwain/Triplets/Readme.md
+++ b/src/NTwain/Triplets/Readme.md
@@ -1,21 +1,20 @@
All TWAIN operations are done through the a combination of
Data Group (DG), Data Argument Type (DAT), and Message (MSG)
triplets. Rather than dealing with all the combinations
-directly and risk passing the wrong thing, all valid triplet
-combinations are simply made available under this namespace.
+directly in the DSM pinvokes and risk passing the wrong thing,
+all valid triplet combinations are made available under this namespace.
Example:
-To get the status of the DS, just use the
-"Get" method (represents MSG), in the
-"Status" property (represnts DAT), in the
-"DGControl" class (represents DG).
+To get the status of the DS, the triplet is
+`DG_Control / DAT_STATUS / MSG_GET` in the documentation.
+With this wrapper you can use a similar call path:
-or better explained in code:
+```cs
+DGControl.Status.Get(...);
+```
-DGControl.Status.Get(...)
+Only triplets usable by the application-side are defined here.
-Only triplets usable by the
-application-side are defined here.
-
-These are still low-level calls and TwainSession is the higher
-level abstraction with some state keeping and other checks for ease of use.
+These are still relatively low-level calls and `TwainAppSession` is the next higher
+level abstraction with some state keeping and other dotnet-friendly methods
+and events for regular use.
diff --git a/src/NTwain/TwainSession.Callbacks.cs b/src/NTwain/TwainAppSession.Callbacks.cs
similarity index 98%
rename from src/NTwain/TwainSession.Callbacks.cs
rename to src/NTwain/TwainAppSession.Callbacks.cs
index 939c80e..23307d1 100644
--- a/src/NTwain/TwainSession.Callbacks.cs
+++ b/src/NTwain/TwainAppSession.Callbacks.cs
@@ -8,7 +8,7 @@ namespace NTwain
{
// this file contains callback methods
- partial class TwainSession
+ partial class TwainAppSession
{
delegate ushort LegacyIDCallbackDelegate(
diff --git a/src/NTwain/TwainSession.Caps.cs b/src/NTwain/TwainAppSession.Caps.cs
similarity index 99%
rename from src/NTwain/TwainSession.Caps.cs
rename to src/NTwain/TwainAppSession.Caps.cs
index e7eb158..9d46e86 100644
--- a/src/NTwain/TwainSession.Caps.cs
+++ b/src/NTwain/TwainAppSession.Caps.cs
@@ -7,7 +7,7 @@ namespace NTwain
{
// this file contains capability mgmt methods
- partial class TwainSession
+ partial class TwainAppSession
{
/////
///// Gets all the supported caps for the current source.
diff --git a/src/NTwain/TwainSession.Memory.cs b/src/NTwain/TwainAppSession.Memory.cs
similarity index 98%
rename from src/NTwain/TwainSession.Memory.cs
rename to src/NTwain/TwainAppSession.Memory.cs
index 597974a..4f6e414 100644
--- a/src/NTwain/TwainSession.Memory.cs
+++ b/src/NTwain/TwainAppSession.Memory.cs
@@ -7,7 +7,7 @@ namespace NTwain
{
// this file contains memory methods
- partial class TwainSession : IMemoryManager
+ partial class TwainAppSession : IMemoryManager
{
internal TW_ENTRYPOINT_DELEGATES _entryPoint;
diff --git a/src/NTwain/TwainSession.PropEvents.cs b/src/NTwain/TwainAppSession.PropEvents.cs
similarity index 90%
rename from src/NTwain/TwainSession.PropEvents.cs
rename to src/NTwain/TwainAppSession.PropEvents.cs
index c9d6be4..3a07809 100644
--- a/src/NTwain/TwainSession.PropEvents.cs
+++ b/src/NTwain/TwainAppSession.PropEvents.cs
@@ -7,7 +7,7 @@ namespace NTwain
{
// this file contains property and event definitions
- partial class TwainSession
+ partial class TwainAppSession
{
///
/// Gets the app identity.
@@ -119,22 +119,22 @@ namespace NTwain
///
/// Fires when changes.
///
- public event Action? StateChanged;
+ public event Action? StateChanged;
///
/// Fires when changes.
///
- public event Action? DefaultSourceChanged;
+ public event Action? DefaultSourceChanged;
///
/// Fires when changes.
///
- public event Action? CurrentSourceChanged;
+ public event Action? CurrentSourceChanged;
///
/// Fires when the source has some device event happening.
///
- public event Action? DeviceEvent;
+ public event Action? DeviceEvent;
///
/// Fires when there's an error during transfer.
diff --git a/src/NTwain/TwainSession.Sources.cs b/src/NTwain/TwainAppSession.Sources.cs
similarity index 99%
rename from src/NTwain/TwainSession.Sources.cs
rename to src/NTwain/TwainAppSession.Sources.cs
index da52f3e..476d5d7 100644
--- a/src/NTwain/TwainSession.Sources.cs
+++ b/src/NTwain/TwainAppSession.Sources.cs
@@ -6,7 +6,7 @@ namespace NTwain
{
// this file contains data source utilities
- partial class TwainSession
+ partial class TwainAppSession
{
///
/// Gets all available sources.
diff --git a/src/NTwain/TwainSession.Windows.cs b/src/NTwain/TwainAppSession.Windows.cs
similarity index 98%
rename from src/NTwain/TwainSession.Windows.cs
rename to src/NTwain/TwainAppSession.Windows.cs
index 4f34468..3f6deb1 100644
--- a/src/NTwain/TwainSession.Windows.cs
+++ b/src/NTwain/TwainAppSession.Windows.cs
@@ -15,7 +15,7 @@ namespace NTwain
// contains parts for winform/wpf message loop integration
- partial class TwainSession : IMessageFilter
+ partial class TwainAppSession : IMessageFilter
{
HwndSource? _wpfhook;
diff --git a/src/NTwain/TwainSession.Xfers.cs b/src/NTwain/TwainAppSession.Xfers.cs
similarity index 98%
rename from src/NTwain/TwainSession.Xfers.cs
rename to src/NTwain/TwainAppSession.Xfers.cs
index ae70904..f937ce8 100644
--- a/src/NTwain/TwainSession.Xfers.cs
+++ b/src/NTwain/TwainAppSession.Xfers.cs
@@ -10,7 +10,7 @@ namespace NTwain
{
// this file contains various xfer methods
- partial class TwainSession
+ partial class TwainAppSession
{
///
/// Start the transfer loop.
diff --git a/src/NTwain/TwainSession.cs b/src/NTwain/TwainAppSession.cs
similarity index 97%
rename from src/NTwain/TwainSession.cs
rename to src/NTwain/TwainAppSession.cs
index cd246a6..1192fff 100644
--- a/src/NTwain/TwainSession.cs
+++ b/src/NTwain/TwainAppSession.cs
@@ -11,7 +11,7 @@ namespace NTwain
{
// this file contains initialization/cleanup things.
- public partial class TwainSession : IDisposable
+ public partial class TwainAppSession : IDisposable
{
static bool __encodingRegistered;
@@ -22,7 +22,7 @@ namespace NTwain
///
///
///
- public TwainSession(IThreadMarshaller uiThreadMarshaller,
+ public TwainAppSession(IThreadMarshaller uiThreadMarshaller,
string exeFilePath,
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA) :
this(uiThreadMarshaller, FileVersionInfo.GetVersionInfo(exeFilePath), appLanguage, appCountry)
@@ -34,7 +34,7 @@ namespace NTwain
///
///
///
- public TwainSession(IThreadMarshaller uiThreadMarshaller,
+ public TwainAppSession(IThreadMarshaller uiThreadMarshaller,
FileVersionInfo appInfo,
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA) :
this(uiThreadMarshaller,
@@ -56,7 +56,7 @@ namespace NTwain
///
///
///
- public TwainSession(IThreadMarshaller uiThreadMarshaller,
+ public TwainAppSession(IThreadMarshaller uiThreadMarshaller,
string companyName, string productFamily, string productName,
Version productVersion, string productDescription = "",
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA,