mirror of
https://github.com/soukoku/ntwain.git
synced 2025-09-18 17:47:57 +08:00
Added pkg build script and cleaned up warnings.
This commit is contained in:
4
Build.cmd
Normal file
4
Build.cmd
Normal file
@@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
cls
|
||||
dotnet pack -o build src\NTwain
|
||||
dotnet pack -o build src\NTwain.Win
|
@@ -9,7 +9,8 @@
|
||||
<PackageProjectUrl>https://github.com/soukoku/ntwain</PackageProjectUrl>
|
||||
<PackageTags>twain scan</PackageTags>
|
||||
<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>
|
||||
<RepositoryType>GIT</RepositoryType>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
@@ -20,7 +21,7 @@
|
||||
<FileVersion>$(PkgVersion)</FileVersion>
|
||||
<LangVersion>7.1</LangVersion>
|
||||
<!--don't warn missing xml docs-->
|
||||
<NoWarn>1591</NoWarn>
|
||||
<NoWarn>1591,1572,1573</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
@@ -31,6 +32,10 @@
|
||||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="../../Scanner-Icon.png" Pack="true" PackagePath="\"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TWAINWorkingGroup;
|
||||
|
||||
@@ -69,7 +70,7 @@ namespace NTwain
|
||||
return ValueReader.ReadRange<TValue>(_twain, twCap).ToList();
|
||||
}
|
||||
}
|
||||
return new TValue[0];
|
||||
return EmptyArray<TValue>.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,7 +100,7 @@ namespace NTwain
|
||||
return ValueReader.ReadRange<TValue>(_twain, twCap).CurrentValue;
|
||||
}
|
||||
}
|
||||
return default(TValue);
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,7 +130,7 @@ namespace NTwain
|
||||
return ValueReader.ReadRange<TValue>(_twain, twCap).DefaultValue;
|
||||
}
|
||||
}
|
||||
return default(TValue);
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -403,7 +403,7 @@ namespace NTwain
|
||||
private CapWrapper<TWBO> _bitorderCodes;
|
||||
|
||||
/// <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>
|
||||
/// <value>
|
||||
/// The image bit order for CCITT compression.
|
||||
@@ -419,7 +419,7 @@ namespace NTwain
|
||||
private CapWrapper<TWPF> _pixelFlavorCodes;
|
||||
|
||||
/// <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>
|
||||
/// <value>
|
||||
/// The image pixel flavor for CCITT compression.
|
||||
@@ -435,7 +435,7 @@ namespace NTwain
|
||||
private CapWrapper<TWPT> _jpegPixelType;
|
||||
|
||||
/// <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>
|
||||
/// <value>
|
||||
/// The image pixel type for jpeg compression.
|
||||
@@ -1621,7 +1621,7 @@ namespace NTwain
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// <value>
|
||||
/// The printer leading string.
|
||||
|
13
src/NTwain/EmptyArray.cs
Normal file
13
src/NTwain/EmptyArray.cs
Normal 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];
|
||||
}
|
||||
}
|
@@ -3,22 +3,21 @@
|
||||
<PropertyGroup>
|
||||
<PackageId>NTwain</PackageId>
|
||||
<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>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||
<PackageReference Include="System.Drawing.Common">
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||
<!--<PackageReference Include="System.Drawing.Common">
|
||||
<Version>5.0.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Security.Permissions">
|
||||
</PackageReference>-->
|
||||
<PackageReference Include="System.Text.Encoding.CodePages">
|
||||
<Version>5.0.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>-->
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
|
||||
<PackageReference Include="System.Text.Encoding.CodePages">
|
||||
|
@@ -67,9 +67,9 @@ namespace TWAINWorkingGroup
|
||||
// dynamic is a cheap hack to sidestep the compiler restrictions if I know TValue is numeric
|
||||
class DynamicEnumerator : IEnumerator<TValue>
|
||||
{
|
||||
private TValue _min;
|
||||
private TValue _max;
|
||||
private TValue _step;
|
||||
private readonly TValue _min;
|
||||
private readonly TValue _max;
|
||||
private readonly TValue _step;
|
||||
private TValue _cur;
|
||||
bool started = false;
|
||||
|
||||
|
@@ -221,11 +221,11 @@ namespace TWAINWorkingGroup
|
||||
{
|
||||
CSV csv = new CSV();
|
||||
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_MemAllocate == null) ? "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_MemLock == null) ? "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_Entry == IntPtr.Zero) ? "0" : a_twentrypoint.DSM_Entry.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 == IntPtr.Zero) ? "0" : a_twentrypoint.DSM_MemFree.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 == IntPtr.Zero) ? "0" : a_twentrypoint.DSM_MemUnlock.ToString("X")));
|
||||
return (csv.Get());
|
||||
}
|
||||
catch (Exception exception)
|
||||
@@ -867,7 +867,7 @@ namespace TWAINWorkingGroup
|
||||
/// Convert the contents of a pending xfers structure to a string that
|
||||
/// we can show in our simple GUI...
|
||||
/// </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>
|
||||
public static string PendingxfersToCsv(TW_PENDINGXFERS a_twpendingxfers)
|
||||
{
|
||||
@@ -888,8 +888,8 @@ namespace TWAINWorkingGroup
|
||||
/// <summary>
|
||||
/// Convert the contents of a string to a pendingxfers structure...
|
||||
/// </summary>
|
||||
/// <param name="a_twpassthru">A TWAIN structure</param>
|
||||
/// <param name="a_szPassthru">A CSV string of the TWAIN structure</param>
|
||||
/// <param name="a_twpendingxfers">A TWAIN structure</param>
|
||||
/// <param name="a_szPendingxfers">A CSV string of the TWAIN structure</param>
|
||||
/// <returns>True if the conversion is successful</returns>
|
||||
public static bool CsvToPendingXfers(ref TW_PENDINGXFERS a_twpendingxfers, string a_szPendingxfers)
|
||||
{
|
||||
@@ -995,8 +995,8 @@ namespace TWAINWorkingGroup
|
||||
/// <summary>
|
||||
/// Convert a string to a setupmemxfer...
|
||||
/// </summary>
|
||||
/// <param name="a_twsetupfilexfer">A TWAIN structure</param>
|
||||
/// <param name="a_szSetupfilexfer">A CSV string of the TWAIN structure</param>
|
||||
/// <param name="a_twsetupmemxfer">A TWAIN structure</param>
|
||||
/// <param name="a_szSetupmemxfer">A CSV string of the TWAIN structure</param>
|
||||
/// <returns>True if the conversion is successful</returns>
|
||||
public static bool CsvToSetupmemxfer(ref TW_SETUPMEMXFER a_twsetupmemxfer, string a_szSetupmemxfer)
|
||||
{
|
||||
@@ -1173,8 +1173,8 @@ namespace TWAINWorkingGroup
|
||||
/// <summary>
|
||||
/// Convert the contents of a string to a transfer group...
|
||||
/// </summary>
|
||||
/// <param name="a_twcustomdsdata">A TWAIN structure</param>
|
||||
/// <param name="a_szCustomdsdata">A CSV string of the TWAIN structure</param>
|
||||
/// <param name="a_u32Xfergroup">A TWAIN structure</param>
|
||||
/// <param name="a_szXfergroup">A CSV string of the TWAIN structure</param>
|
||||
/// <returns>True if the conversion is successful</returns>
|
||||
public static bool CsvToXfergroup(ref UInt32 a_u32Xfergroup, string a_szXfergroup)
|
||||
{
|
||||
@@ -1327,7 +1327,6 @@ namespace TWAINWorkingGroup
|
||||
/// <summary>
|
||||
/// This mess is what tries to turn readable stuff into numeric constants...
|
||||
/// </summary>
|
||||
/// <typeparam name="T">type for the conversion</typeparam>
|
||||
/// <param name="a_szValue">value to convert</param>
|
||||
/// <returns></returns>
|
||||
private static string CvtCapValueFromTwlg(string a_szValue)
|
||||
@@ -1479,7 +1478,7 @@ namespace TWAINWorkingGroup
|
||||
/// Convert a value to the 'friendly' name, based on the capability...
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public static string CvtCapValueToEnum(CAP a_cap, string a_szValue)
|
||||
{
|
||||
@@ -1657,7 +1656,7 @@ namespace TWAINWorkingGroup
|
||||
/// Convert a 'friendly' name to a numeric value...
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public static string CvtCapValueFromEnum(CAP a_cap, string a_szValue)
|
||||
{
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -371,8 +371,6 @@ namespace TWAINWorkingGroup
|
||||
/// <summary>
|
||||
/// Cleanup...
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
|
||||
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
@@ -797,7 +795,6 @@ namespace TWAINWorkingGroup
|
||||
/// </summary>
|
||||
/// <param name="a_stateTarget">The TWAIN state that we want to end up at</param>
|
||||
static int s_iCloseDsmDelay = 0;
|
||||
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
|
||||
public STATE Rollback(STATE a_stateTarget)
|
||||
{
|
||||
int iRetry;
|
||||
@@ -4474,19 +4471,19 @@ namespace TWAINWorkingGroup
|
||||
m_twentrypointdelegates = default(TW_ENTRYPOINT_DELEGATES);
|
||||
m_twentrypointdelegates.Size = a_twentrypoint.Size;
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
@@ -10440,7 +10437,6 @@ namespace TWAINWorkingGroup
|
||||
/// Cleanup...
|
||||
/// </summary>
|
||||
/// <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)
|
||||
{
|
||||
// Free managed resources...
|
||||
@@ -11019,7 +11015,6 @@ namespace TWAINWorkingGroup
|
||||
/// Automatically collect the condition code for TWRC_FAILURE's...
|
||||
/// </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>
|
||||
/// <returns>The final statue return</returns>
|
||||
private STS AutoDatStatus(STS a_sts)
|
||||
{
|
||||
@@ -12540,10 +12535,10 @@ namespace TWAINWorkingGroup
|
||||
/// </summary>
|
||||
private AutoResetEvent m_autoreseteventThreadStarted;
|
||||
|
||||
/// <summary>
|
||||
/// The data we share with the thread...
|
||||
/// </summary>
|
||||
//private ThreadData m_threaddata;
|
||||
///// <summary>
|
||||
///// The data we share with the thread...
|
||||
///// </summary>
|
||||
////private ThreadData m_threaddata;
|
||||
|
||||
/// <summary>
|
||||
/// Our callback for device events...
|
||||
|
@@ -17,6 +17,7 @@ namespace NTwain
|
||||
/// Starts work asynchronously and returns immediately.
|
||||
/// </summary>
|
||||
/// <param name="work"></param>
|
||||
/// <param name="args"></param>
|
||||
void BeginInvoke(Delegate work, params object[] args);
|
||||
|
||||
/// <summary>
|
||||
|
@@ -137,7 +137,7 @@ namespace NTwain
|
||||
public TW_STATUS GetStatus()
|
||||
{
|
||||
TW_STATUS stat = default;
|
||||
var sts = _twain.DatStatus(DG.CONTROL, MSG.GET, ref stat);
|
||||
_ = _twain.DatStatus(DG.CONTROL, MSG.GET, ref stat);
|
||||
return stat;
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ namespace NTwain
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
public void Close()
|
||||
{
|
||||
|
@@ -18,7 +18,7 @@ namespace NTwain
|
||||
|
||||
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);
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace NTwain
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -412,7 +412,7 @@ namespace NTwain
|
||||
{
|
||||
return parsed;
|
||||
}
|
||||
return default(TEnum);
|
||||
return default;
|
||||
}
|
||||
|
||||
static T MarshalTo<T>(IntPtr ptr) => (T)Marshal.PtrToStructure(ptr, typeof(T));
|
||||
|
Reference in New Issue
Block a user