Update to allow preferring old dsm for #43

This commit is contained in:
soukoku 2015-03-27 19:11:10 -04:00
parent 1700e183c7
commit f0202e6776
4 changed files with 85 additions and 29 deletions

View File

@ -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.
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
newer data source manager (twaindsm.dll) from below installed.
By default NTwain will use the newer [data source manager](http://sourceforge.net/projects/twain-dsm/files/TWAIN%20DSM%202%20Win/)
(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.

View File

@ -1,10 +1,16 @@
<Window x:Class="Sample.WPF.Launcher"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:twain="clr-namespace:NTwain;assembly=NTwain"
Title="Scan Launcher" Height="200" Width="250"
ResizeMode="NoResize" Style="{StaticResource AppWindow}">
<Grid>
<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>
<TextBlock Text="This is to test opening/closing multiple twain sessions in an app" Margin="8"
TextWrapping="Wrap"></TextBlock>

View File

@ -1,4 +1,5 @@
using System;
using System.IO;
namespace NTwain
{
/// <summary>
@ -46,6 +47,14 @@ namespace NTwain
/// </value>
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>
/// Gets a value indicating whether the current runtime is mono.
/// </summary>

View File

@ -2,6 +2,7 @@
using NTwain.Triplets;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
@ -36,32 +37,13 @@ namespace NTwain
{
_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
var oldDsmPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), Dsm.WIN_OLD_DSM_NAME);
oldDsmPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), Dsm.WIN_OLD_DSM_NAME);
#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
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);
}
}
PreferNewDSM = true;
}
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>
/// Gets a value indicating whether the lib is expecting to use new DSM.
/// </summary>