mirror of
https://github.com/soukoku/ntwain.git
synced 2026-01-26 21:48:36 +08:00
Update to allow preferring old dsm for #43
This commit is contained in:
23
README.md
23
README.md
@@ -154,13 +154,24 @@ application due to their use of modal dialogs, so if you find yourself in that p
|
|||||||
you'll have to find another way to synchronize data to UI threads.
|
you'll have to find another way to synchronize data to UI threads.
|
||||||
|
|
||||||
|
|
||||||
64-bit OS
|
Using the new twaindsm.dll
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
If the application process is going to be running in 64-bit then you will need to have the
|
By default NTwain will use the newer [data source manager](http://sourceforge.net/projects/twain-dsm/files/TWAIN%20DSM%202%20Win/)
|
||||||
newer data source manager (twaindsm.dll) from below installed.
|
(twaindsm.dll) if available. To override this behavior
|
||||||
|
set the PlatformInfo's PreferNewDSM flag to false. Some older sources does not work with the newer dsm so it's
|
||||||
|
necessary to set it.
|
||||||
|
|
||||||
[DSM from TWAIN.org](http://sourceforge.net/projects/twain-dsm/files/TWAIN%20DSM%202%20Win/)
|
```
|
||||||
|
#!c#
|
||||||
|
// go back to using twain_32.dll under windows,
|
||||||
|
// do this once at app startup.
|
||||||
|
NTwain.PlatformInfo.Current.PreferNewDSM = false;
|
||||||
|
|
||||||
In fact, installing the new DSM is recommended whether you're running in 64-bit or not.
|
```
|
||||||
|
|
||||||
|
|
||||||
|
If the application process is going to be running in 64-bit then this flag will have no effect and you will
|
||||||
|
always need to have the newer dsm installed.
|
||||||
|
|
||||||
|
If the scanner's TWAIN driver is still 32-bit then you'll have need to compile the application exe in x86 or you won't see the driver.
|
||||||
|
|
||||||
If the scanner's TWAIN driver is still 32-bit then you'll have no choice but to compile the application exe in x86 or you won't see the driver.
|
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
<Window x:Class="Sample.WPF.Launcher"
|
<Window x:Class="Sample.WPF.Launcher"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:twain="clr-namespace:NTwain;assembly=NTwain"
|
||||||
Title="Scan Launcher" Height="200" Width="250"
|
Title="Scan Launcher" Height="200" Width="250"
|
||||||
ResizeMode="NoResize" Style="{StaticResource AppWindow}">
|
ResizeMode="NoResize" Style="{StaticResource AppWindow}">
|
||||||
<Grid>
|
<Grid>
|
||||||
<StackPanel VerticalAlignment="Center">
|
<StackPanel VerticalAlignment="Center">
|
||||||
|
<CheckBox DataContext="{x:Static twain:PlatformInfo.Current}"
|
||||||
|
IsChecked="{Binding PreferNewDSM}"
|
||||||
|
IsEnabled="{Binding IsWindows, Mode=OneWay}"
|
||||||
|
Content="Prefer new DSM"
|
||||||
|
HorizontalAlignment="Center"></CheckBox>
|
||||||
<Button Content="Open scan window" Click="Button_Click" Margin="4 0"></Button>
|
<Button Content="Open scan window" Click="Button_Click" Margin="4 0"></Button>
|
||||||
<TextBlock Text="This is to test opening/closing multiple twain sessions in an app" Margin="8"
|
<TextBlock Text="This is to test opening/closing multiple twain sessions in an app" Margin="8"
|
||||||
TextWrapping="Wrap"></TextBlock>
|
TextWrapping="Wrap"></TextBlock>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
namespace NTwain
|
namespace NTwain
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -46,6 +47,14 @@ namespace NTwain
|
|||||||
/// </value>
|
/// </value>
|
||||||
bool UseNewWinDSM { get; }
|
bool UseNewWinDSM { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether to prefer using the new DSM on Windows over old twain_32 dsm if applicable.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// <c>true</c> to prefer new DSM; otherwise, <c>false</c>.
|
||||||
|
/// </value>
|
||||||
|
bool PreferNewDSM { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether the current runtime is mono.
|
/// Gets a value indicating whether the current runtime is mono.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using NTwain.Triplets;
|
using NTwain.Triplets;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -36,32 +37,13 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
_defaultMemManager = new WinMemoryManager();
|
_defaultMemManager = new WinMemoryManager();
|
||||||
|
|
||||||
var newDsmPath = Path.Combine(Environment.SystemDirectory, Dsm.WIN_NEW_DSM_NAME);
|
newDsmPath = Path.Combine(Environment.SystemDirectory, Dsm.WIN_NEW_DSM_NAME);
|
||||||
#if NET35
|
#if NET35
|
||||||
var oldDsmPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), Dsm.WIN_OLD_DSM_NAME);
|
oldDsmPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), Dsm.WIN_OLD_DSM_NAME);
|
||||||
#else
|
#else
|
||||||
var oldDsmPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), Dsm.WIN_OLD_DSM_NAME);
|
oldDsmPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), Dsm.WIN_OLD_DSM_NAME);
|
||||||
#endif
|
#endif
|
||||||
|
PreferNewDSM = true;
|
||||||
if (IsApp64Bit)
|
|
||||||
{
|
|
||||||
ExpectedDsmPath = newDsmPath;
|
|
||||||
IsSupported = DsmExists = File.Exists(ExpectedDsmPath);
|
|
||||||
UseNewWinDSM = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (File.Exists(newDsmPath))
|
|
||||||
{
|
|
||||||
ExpectedDsmPath = newDsmPath;
|
|
||||||
UseNewWinDSM = IsSupported = DsmExists = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ExpectedDsmPath = oldDsmPath;
|
|
||||||
IsSupported = DsmExists = File.Exists(ExpectedDsmPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (IsLinux)
|
else if (IsLinux)
|
||||||
{
|
{
|
||||||
@@ -77,6 +59,54 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string oldDsmPath;
|
||||||
|
string newDsmPath;
|
||||||
|
|
||||||
|
private bool _preferNewDSM;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether to prefer using the new DSM on Windows over old twain_32 dsm if applicable.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// <c>true</c> to prefer new DSM; otherwise, <c>false</c>.
|
||||||
|
/// </value>
|
||||||
|
public bool PreferNewDSM
|
||||||
|
{
|
||||||
|
get { return _preferNewDSM; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (IsWindows)
|
||||||
|
{
|
||||||
|
_preferNewDSM = value;
|
||||||
|
|
||||||
|
if (IsApp64Bit)
|
||||||
|
{
|
||||||
|
ExpectedDsmPath = newDsmPath;
|
||||||
|
IsSupported = DsmExists = File.Exists(ExpectedDsmPath);
|
||||||
|
UseNewWinDSM = true;
|
||||||
|
Debug.WriteLine("Using new dsm in windows.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_preferNewDSM && File.Exists(newDsmPath))
|
||||||
|
{
|
||||||
|
ExpectedDsmPath = newDsmPath;
|
||||||
|
UseNewWinDSM = IsSupported = DsmExists = true;
|
||||||
|
Debug.WriteLine("Using new dsm in windows.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ExpectedDsmPath = oldDsmPath;
|
||||||
|
IsSupported = DsmExists = File.Exists(ExpectedDsmPath);
|
||||||
|
UseNewWinDSM = false;
|
||||||
|
Debug.WriteLine("Using old dsm in windows.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether the lib is expecting to use new DSM.
|
/// Gets a value indicating whether the lib is expecting to use new DSM.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user