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

@@ -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>