Added pkg build script and cleaned up warnings.

This commit is contained in:
Eugene Wang
2021-04-25 18:36:29 -04:00
parent 80c6276f4c
commit f386f7da36
13 changed files with 380 additions and 363 deletions

4
Build.cmd Normal file
View File

@@ -0,0 +1,4 @@
@echo off
cls
dotnet pack -o build src\NTwain
dotnet pack -o build src\NTwain.Win

View File

@@ -9,7 +9,8 @@
<PackageProjectUrl>https://github.com/soukoku/ntwain</PackageProjectUrl> <PackageProjectUrl>https://github.com/soukoku/ntwain</PackageProjectUrl>
<PackageTags>twain scan</PackageTags> <PackageTags>twain scan</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIconUrl>https://github.com/soukoku/ntwain/blob/master/Scanner-Icon.png?raw=true</PackageIconUrl> <PackageIcon>Scanner-Icon.png</PackageIcon>
<!--<PackageIconUrl>https://github.com/soukoku/ntwain/blob/master/Scanner-Icon.png?raw=true</PackageIconUrl>-->
<RepositoryUrl>https://github.com/soukoku/ntwain</RepositoryUrl> <RepositoryUrl>https://github.com/soukoku/ntwain</RepositoryUrl>
<RepositoryType>GIT</RepositoryType> <RepositoryType>GIT</RepositoryType>
<NeutralLanguage>en-US</NeutralLanguage> <NeutralLanguage>en-US</NeutralLanguage>
@@ -20,7 +21,7 @@
<FileVersion>$(PkgVersion)</FileVersion> <FileVersion>$(PkgVersion)</FileVersion>
<LangVersion>7.1</LangVersion> <LangVersion>7.1</LangVersion>
<!--don't warn missing xml docs--> <!--don't warn missing xml docs-->
<NoWarn>1591</NoWarn> <NoWarn>1591,1572,1573</NoWarn>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'"> <PropertyGroup Condition="'$(Configuration)'=='Release'">
@@ -31,6 +32,10 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Include="../../Scanner-Icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" /> <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup> </ItemGroup>

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using TWAINWorkingGroup; using TWAINWorkingGroup;
@@ -69,7 +70,7 @@ namespace NTwain
return ValueReader.ReadRange<TValue>(_twain, twCap).ToList(); return ValueReader.ReadRange<TValue>(_twain, twCap).ToList();
} }
} }
return new TValue[0]; return EmptyArray<TValue>.Value;
} }
/// <summary> /// <summary>
@@ -99,7 +100,7 @@ namespace NTwain
return ValueReader.ReadRange<TValue>(_twain, twCap).CurrentValue; return ValueReader.ReadRange<TValue>(_twain, twCap).CurrentValue;
} }
} }
return default(TValue); return default;
} }
/// <summary> /// <summary>
@@ -129,7 +130,7 @@ namespace NTwain
return ValueReader.ReadRange<TValue>(_twain, twCap).DefaultValue; return ValueReader.ReadRange<TValue>(_twain, twCap).DefaultValue;
} }
} }
return default(TValue); return default;
} }
/// <summary> /// <summary>

View File

@@ -403,7 +403,7 @@ namespace NTwain
private CapWrapper<TWBO> _bitorderCodes; private CapWrapper<TWBO> _bitorderCodes;
/// <summary> /// <summary>
/// Gets the property to work with image CCITT compression <see cref="BitOrder"/> for the current source. /// Gets the property to work with image CCITT compression <see cref="TWBO"/> for the current source.
/// </summary> /// </summary>
/// <value> /// <value>
/// The image bit order for CCITT compression. /// The image bit order for CCITT compression.
@@ -419,7 +419,7 @@ namespace NTwain
private CapWrapper<TWPF> _pixelFlavorCodes; private CapWrapper<TWPF> _pixelFlavorCodes;
/// <summary> /// <summary>
/// Gets the property to work with image CCITT compression <see cref="PixelFlavor"/> for the current source. /// Gets the property to work with image CCITT compression <see cref="TWPF"/> for the current source.
/// </summary> /// </summary>
/// <value> /// <value>
/// The image pixel flavor for CCITT compression. /// The image pixel flavor for CCITT compression.
@@ -435,7 +435,7 @@ namespace NTwain
private CapWrapper<TWPT> _jpegPixelType; private CapWrapper<TWPT> _jpegPixelType;
/// <summary> /// <summary>
/// Gets the property to work with image jpeg compression <see cref="PixelType"/> for the current source. /// Gets the property to work with image jpeg compression <see cref="TWPT"/> for the current source.
/// </summary> /// </summary>
/// <value> /// <value>
/// The image pixel type for jpeg compression. /// The image pixel type for jpeg compression.
@@ -1621,7 +1621,7 @@ namespace NTwain
/// <summary> /// <summary>
/// Set the character to be used for filling the leading digits before the counter value if the /// Set the character to be used for filling the leading digits before the counter value if the
/// counter digits are fewer than <see cref="CapPrinterIndexNumDigits"/>. /// counter digits are fewer than <see cref="CAP_PRINTERINDEXNUMDIGITS"/>.
/// </summary> /// </summary>
/// <value> /// <value>
/// The printer leading string. /// The printer leading string.

13
src/NTwain/EmptyArray.cs Normal file
View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NTwain
{
static class EmptyArray<T>
{
public static readonly T[] Value = new T[0];
}
}

View File

@@ -3,22 +3,21 @@
<PropertyGroup> <PropertyGroup>
<PackageId>NTwain</PackageId> <PackageId>NTwain</PackageId>
<Description>Library containing the TWAIN API for dotnet.</Description> <Description>Library containing the TWAIN API for dotnet.</Description>
<TargetFrameworks>net45;netcoreapp3.1;net5.0</TargetFrameworks> <TargetFrameworks>net45;netstandard2.0;netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" /> <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup> </ItemGroup>
<!--<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"> <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Drawing.Common"> <!--<PackageReference Include="System.Drawing.Common">
<Version>5.0.2</Version> <Version>5.0.2</Version>
</PackageReference> </PackageReference>-->
<PackageReference Include="System.Security.Permissions"> <PackageReference Include="System.Text.Encoding.CodePages">
<Version>5.0.0</Version> <Version>5.0.0</Version>
</PackageReference> </PackageReference>
</ItemGroup>--> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'"> <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="System.Text.Encoding.CodePages"> <PackageReference Include="System.Text.Encoding.CodePages">

View File

@@ -67,9 +67,9 @@ namespace TWAINWorkingGroup
// dynamic is a cheap hack to sidestep the compiler restrictions if I know TValue is numeric // dynamic is a cheap hack to sidestep the compiler restrictions if I know TValue is numeric
class DynamicEnumerator : IEnumerator<TValue> class DynamicEnumerator : IEnumerator<TValue>
{ {
private TValue _min; private readonly TValue _min;
private TValue _max; private readonly TValue _max;
private TValue _step; private readonly TValue _step;
private TValue _cur; private TValue _cur;
bool started = false; bool started = false;

View File

@@ -221,11 +221,11 @@ namespace TWAINWorkingGroup
{ {
CSV csv = new CSV(); CSV csv = new CSV();
csv.Add(a_twentrypoint.Size.ToString()); csv.Add(a_twentrypoint.Size.ToString());
csv.Add("0x" + ((a_twentrypoint.DSM_Entry == null) ? "0" : a_twentrypoint.DSM_Entry.ToString("X"))); csv.Add("0x" + ((a_twentrypoint.DSM_Entry == IntPtr.Zero) ? "0" : a_twentrypoint.DSM_Entry.ToString("X")));
csv.Add("0x" + ((a_twentrypoint.DSM_MemAllocate == null) ? "0" : a_twentrypoint.DSM_MemAllocate.ToString("X"))); csv.Add("0x" + ((a_twentrypoint.DSM_MemAllocate == IntPtr.Zero) ? "0" : a_twentrypoint.DSM_MemAllocate.ToString("X")));
csv.Add("0x" + ((a_twentrypoint.DSM_MemFree == null) ? "0" : a_twentrypoint.DSM_MemFree.ToString("X"))); csv.Add("0x" + ((a_twentrypoint.DSM_MemFree == IntPtr.Zero) ? "0" : a_twentrypoint.DSM_MemFree.ToString("X")));
csv.Add("0x" + ((a_twentrypoint.DSM_MemLock == null) ? "0" : a_twentrypoint.DSM_MemLock.ToString("X"))); csv.Add("0x" + ((a_twentrypoint.DSM_MemLock == IntPtr.Zero) ? "0" : a_twentrypoint.DSM_MemLock.ToString("X")));
csv.Add("0x" + ((a_twentrypoint.DSM_MemUnlock == null) ? "0" : a_twentrypoint.DSM_MemUnlock.ToString("X"))); csv.Add("0x" + ((a_twentrypoint.DSM_MemUnlock == IntPtr.Zero) ? "0" : a_twentrypoint.DSM_MemUnlock.ToString("X")));
return (csv.Get()); return (csv.Get());
} }
catch (Exception exception) catch (Exception exception)
@@ -867,7 +867,7 @@ namespace TWAINWorkingGroup
/// Convert the contents of a pending xfers structure to a string that /// Convert the contents of a pending xfers structure to a string that
/// we can show in our simple GUI... /// we can show in our simple GUI...
/// </summary> /// </summary>
/// <param name="a_twsetupfilexfer">A TWAIN structure</param> /// <param name="a_twpendingxfers">A TWAIN structure</param>
/// <returns>A CSV string of the TWAIN structure</returns> /// <returns>A CSV string of the TWAIN structure</returns>
public static string PendingxfersToCsv(TW_PENDINGXFERS a_twpendingxfers) public static string PendingxfersToCsv(TW_PENDINGXFERS a_twpendingxfers)
{ {
@@ -888,8 +888,8 @@ namespace TWAINWorkingGroup
/// <summary> /// <summary>
/// Convert the contents of a string to a pendingxfers structure... /// Convert the contents of a string to a pendingxfers structure...
/// </summary> /// </summary>
/// <param name="a_twpassthru">A TWAIN structure</param> /// <param name="a_twpendingxfers">A TWAIN structure</param>
/// <param name="a_szPassthru">A CSV string of the TWAIN structure</param> /// <param name="a_szPendingxfers">A CSV string of the TWAIN structure</param>
/// <returns>True if the conversion is successful</returns> /// <returns>True if the conversion is successful</returns>
public static bool CsvToPendingXfers(ref TW_PENDINGXFERS a_twpendingxfers, string a_szPendingxfers) public static bool CsvToPendingXfers(ref TW_PENDINGXFERS a_twpendingxfers, string a_szPendingxfers)
{ {
@@ -995,8 +995,8 @@ namespace TWAINWorkingGroup
/// <summary> /// <summary>
/// Convert a string to a setupmemxfer... /// Convert a string to a setupmemxfer...
/// </summary> /// </summary>
/// <param name="a_twsetupfilexfer">A TWAIN structure</param> /// <param name="a_twsetupmemxfer">A TWAIN structure</param>
/// <param name="a_szSetupfilexfer">A CSV string of the TWAIN structure</param> /// <param name="a_szSetupmemxfer">A CSV string of the TWAIN structure</param>
/// <returns>True if the conversion is successful</returns> /// <returns>True if the conversion is successful</returns>
public static bool CsvToSetupmemxfer(ref TW_SETUPMEMXFER a_twsetupmemxfer, string a_szSetupmemxfer) public static bool CsvToSetupmemxfer(ref TW_SETUPMEMXFER a_twsetupmemxfer, string a_szSetupmemxfer)
{ {
@@ -1173,8 +1173,8 @@ namespace TWAINWorkingGroup
/// <summary> /// <summary>
/// Convert the contents of a string to a transfer group... /// Convert the contents of a string to a transfer group...
/// </summary> /// </summary>
/// <param name="a_twcustomdsdata">A TWAIN structure</param> /// <param name="a_u32Xfergroup">A TWAIN structure</param>
/// <param name="a_szCustomdsdata">A CSV string of the TWAIN structure</param> /// <param name="a_szXfergroup">A CSV string of the TWAIN structure</param>
/// <returns>True if the conversion is successful</returns> /// <returns>True if the conversion is successful</returns>
public static bool CsvToXfergroup(ref UInt32 a_u32Xfergroup, string a_szXfergroup) public static bool CsvToXfergroup(ref UInt32 a_u32Xfergroup, string a_szXfergroup)
{ {
@@ -1327,7 +1327,6 @@ namespace TWAINWorkingGroup
/// <summary> /// <summary>
/// This mess is what tries to turn readable stuff into numeric constants... /// This mess is what tries to turn readable stuff into numeric constants...
/// </summary> /// </summary>
/// <typeparam name="T">type for the conversion</typeparam>
/// <param name="a_szValue">value to convert</param> /// <param name="a_szValue">value to convert</param>
/// <returns></returns> /// <returns></returns>
private static string CvtCapValueFromTwlg(string a_szValue) private static string CvtCapValueFromTwlg(string a_szValue)
@@ -1479,7 +1478,7 @@ namespace TWAINWorkingGroup
/// Convert a value to the 'friendly' name, based on the capability... /// Convert a value to the 'friendly' name, based on the capability...
/// </summary> /// </summary>
/// <param name="a_cap">capability driving the conversion</param> /// <param name="a_cap">capability driving the conversion</param>
/// <param name="szValue">value to convert</param> /// <param name="a_szValue">value to convert</param>
/// <returns></returns> /// <returns></returns>
public static string CvtCapValueToEnum(CAP a_cap, string a_szValue) public static string CvtCapValueToEnum(CAP a_cap, string a_szValue)
{ {
@@ -1657,7 +1656,7 @@ namespace TWAINWorkingGroup
/// Convert a 'friendly' name to a numeric value... /// Convert a 'friendly' name to a numeric value...
/// </summary> /// </summary>
/// <param name="a_cap">capability driving the conversion</param> /// <param name="a_cap">capability driving the conversion</param>
/// <param name="szValue">value to convert</param> /// <param name="a_szValue">value to convert</param>
/// <returns></returns> /// <returns></returns>
public static string CvtCapValueFromEnum(CAP a_cap, string a_szValue) public static string CvtCapValueFromEnum(CAP a_cap, string a_szValue)
{ {

File diff suppressed because it is too large Load Diff

View File

@@ -371,8 +371,6 @@ namespace TWAINWorkingGroup
/// <summary> /// <summary>
/// Cleanup... /// Cleanup...
/// </summary> /// </summary>
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public void Dispose() public void Dispose()
{ {
Dispose(true); Dispose(true);
@@ -797,7 +795,6 @@ namespace TWAINWorkingGroup
/// </summary> /// </summary>
/// <param name="a_stateTarget">The TWAIN state that we want to end up at</param> /// <param name="a_stateTarget">The TWAIN state that we want to end up at</param>
static int s_iCloseDsmDelay = 0; static int s_iCloseDsmDelay = 0;
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public STATE Rollback(STATE a_stateTarget) public STATE Rollback(STATE a_stateTarget)
{ {
int iRetry; int iRetry;
@@ -4474,19 +4471,19 @@ namespace TWAINWorkingGroup
m_twentrypointdelegates = default(TW_ENTRYPOINT_DELEGATES); m_twentrypointdelegates = default(TW_ENTRYPOINT_DELEGATES);
m_twentrypointdelegates.Size = a_twentrypoint.Size; m_twentrypointdelegates.Size = a_twentrypoint.Size;
m_twentrypointdelegates.DSM_Entry = a_twentrypoint.DSM_Entry; m_twentrypointdelegates.DSM_Entry = a_twentrypoint.DSM_Entry;
if (a_twentrypoint.DSM_MemAllocate != null) if (a_twentrypoint.DSM_MemAllocate != IntPtr.Zero)
{ {
m_twentrypointdelegates.DSM_MemAllocate = (DSM_MEMALLOC)Marshal.GetDelegateForFunctionPointer(a_twentrypoint.DSM_MemAllocate, typeof(DSM_MEMALLOC)); m_twentrypointdelegates.DSM_MemAllocate = (DSM_MEMALLOC)Marshal.GetDelegateForFunctionPointer(a_twentrypoint.DSM_MemAllocate, typeof(DSM_MEMALLOC));
} }
if (a_twentrypoint.DSM_MemFree != null) if (a_twentrypoint.DSM_MemFree != IntPtr.Zero)
{ {
m_twentrypointdelegates.DSM_MemFree = (DSM_MEMFREE)Marshal.GetDelegateForFunctionPointer(a_twentrypoint.DSM_MemFree, typeof(DSM_MEMFREE)); m_twentrypointdelegates.DSM_MemFree = (DSM_MEMFREE)Marshal.GetDelegateForFunctionPointer(a_twentrypoint.DSM_MemFree, typeof(DSM_MEMFREE));
} }
if (a_twentrypoint.DSM_MemLock != null) if (a_twentrypoint.DSM_MemLock != IntPtr.Zero)
{ {
m_twentrypointdelegates.DSM_MemLock = (DSM_MEMLOCK)Marshal.GetDelegateForFunctionPointer(a_twentrypoint.DSM_MemLock, typeof(DSM_MEMLOCK)); m_twentrypointdelegates.DSM_MemLock = (DSM_MEMLOCK)Marshal.GetDelegateForFunctionPointer(a_twentrypoint.DSM_MemLock, typeof(DSM_MEMLOCK));
} }
if (a_twentrypoint.DSM_MemUnlock != null) if (a_twentrypoint.DSM_MemUnlock != IntPtr.Zero)
{ {
m_twentrypointdelegates.DSM_MemUnlock = (DSM_MEMUNLOCK)Marshal.GetDelegateForFunctionPointer(a_twentrypoint.DSM_MemUnlock, typeof(DSM_MEMUNLOCK)); m_twentrypointdelegates.DSM_MemUnlock = (DSM_MEMUNLOCK)Marshal.GetDelegateForFunctionPointer(a_twentrypoint.DSM_MemUnlock, typeof(DSM_MEMUNLOCK));
} }
@@ -10440,7 +10437,6 @@ namespace TWAINWorkingGroup
/// Cleanup... /// Cleanup...
/// </summary> /// </summary>
/// <param name="a_blDisposing">true if we need to clean up managed resources</param> /// <param name="a_blDisposing">true if we need to clean up managed resources</param>
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
internal void Dispose(bool a_blDisposing) internal void Dispose(bool a_blDisposing)
{ {
// Free managed resources... // Free managed resources...
@@ -11019,7 +11015,6 @@ namespace TWAINWorkingGroup
/// Automatically collect the condition code for TWRC_FAILURE's... /// Automatically collect the condition code for TWRC_FAILURE's...
/// </summary> /// </summary>
/// <param name="a_sts">The return code from the last operation</param> /// <param name="a_sts">The return code from the last operation</param>
/// <param name="a_sts">The return code from the last operation</param>
/// <returns>The final statue return</returns> /// <returns>The final statue return</returns>
private STS AutoDatStatus(STS a_sts) private STS AutoDatStatus(STS a_sts)
{ {
@@ -12540,10 +12535,10 @@ namespace TWAINWorkingGroup
/// </summary> /// </summary>
private AutoResetEvent m_autoreseteventThreadStarted; private AutoResetEvent m_autoreseteventThreadStarted;
/// <summary> ///// <summary>
/// The data we share with the thread... ///// The data we share with the thread...
/// </summary> ///// </summary>
//private ThreadData m_threaddata; ////private ThreadData m_threaddata;
/// <summary> /// <summary>
/// Our callback for device events... /// Our callback for device events...

View File

@@ -17,6 +17,7 @@ namespace NTwain
/// Starts work asynchronously and returns immediately. /// Starts work asynchronously and returns immediately.
/// </summary> /// </summary>
/// <param name="work"></param> /// <param name="work"></param>
/// <param name="args"></param>
void BeginInvoke(Delegate work, params object[] args); void BeginInvoke(Delegate work, params object[] args);
/// <summary> /// <summary>

View File

@@ -137,7 +137,7 @@ namespace NTwain
public TW_STATUS GetStatus() public TW_STATUS GetStatus()
{ {
TW_STATUS stat = default; TW_STATUS stat = default;
var sts = _twain.DatStatus(DG.CONTROL, MSG.GET, ref stat); _ = _twain.DatStatus(DG.CONTROL, MSG.GET, ref stat);
return stat; return stat;
} }
@@ -154,7 +154,7 @@ namespace NTwain
/// <summary> /// <summary>
/// Closes the TWAIN data source manager. /// Closes the TWAIN data source manager.
/// This is called when <see cref="Dispose"/> is invoked. /// This is called when <see cref="Dispose()"/> is invoked.
/// </summary> /// </summary>
public void Close() public void Close()
{ {

View File

@@ -18,7 +18,7 @@ namespace NTwain
public static TValue ReadOneValue<TValue>(TWAIN twain, TW_CAPABILITY cap, bool freeMemory = true) where TValue : struct public static TValue ReadOneValue<TValue>(TWAIN twain, TW_CAPABILITY cap, bool freeMemory = true) where TValue : struct
{ {
if (cap.hContainer == IntPtr.Zero) return default(TValue); if (cap.hContainer == IntPtr.Zero) return default;
var lockedPtr = twain.DsmMemLock(cap.hContainer); var lockedPtr = twain.DsmMemLock(cap.hContainer);
@@ -119,7 +119,7 @@ namespace NTwain
} }
public static IList<TValue> ReadArray<TValue>(TWAIN twain, TW_CAPABILITY cap, bool freeMemory = true) where TValue : struct public static IList<TValue> ReadArray<TValue>(TWAIN twain, TW_CAPABILITY cap, bool freeMemory = true) where TValue : struct
{ {
if (cap.hContainer == IntPtr.Zero) return new TValue[0]; if (cap.hContainer == IntPtr.Zero) return EmptyArray<TValue>.Value;
var lockedPtr = twain.DsmMemLock(cap.hContainer); var lockedPtr = twain.DsmMemLock(cap.hContainer);
@@ -412,7 +412,7 @@ namespace NTwain
{ {
return parsed; return parsed;
} }
return default(TEnum); return default;
} }
static T MarshalTo<T>(IntPtr ptr) => (T)Marshal.PtrToStructure(ptr, typeof(T)); static T MarshalTo<T>(IntPtr ptr) => (T)Marshal.PtrToStructure(ptr, typeof(T));