Updated logic to look for twaindsm.dll in current folder as well (#60).

This commit is contained in:
Eugene Wang 2016-03-10 20:04:38 -05:00
parent 42cbd75765
commit abbbad16c9
2 changed files with 11 additions and 4 deletions

View File

@ -37,7 +37,9 @@ namespace NTwain
{ {
_defaultMemManager = new WinMemoryManager(); _defaultMemManager = new WinMemoryManager();
newDsmPath = Path.Combine(Environment.SystemDirectory, Dsm.WIN_NEW_DSM_NAME); // only the new dsm can be loaded outside of windows folder
newDsmPath = GetFirstFilePathThatExists(Dsm.WIN_NEW_DSM_NAME, Environment.CurrentDirectory, Environment.SystemDirectory) ??
Path.Combine(Environment.SystemDirectory, Dsm.WIN_NEW_DSM_NAME);
#if NET35 #if NET35
oldDsmPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), Dsm.WIN_OLD_DSM_NAME); oldDsmPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), Dsm.WIN_OLD_DSM_NAME);
#else #else
@ -59,6 +61,11 @@ namespace NTwain
} }
} }
static string GetFirstFilePathThatExists(string filename, params string[] folders)
{
return folders.Select(fdr => Path.Combine(fdr, filename)).FirstOrDefault(path => File.Exists(path));
}
string oldDsmPath; string oldDsmPath;
string newDsmPath; string newDsmPath;
@ -84,7 +91,7 @@ namespace NTwain
ExpectedDsmPath = newDsmPath; ExpectedDsmPath = newDsmPath;
IsSupported = DsmExists = File.Exists(ExpectedDsmPath); IsSupported = DsmExists = File.Exists(ExpectedDsmPath);
UseNewWinDSM = true; UseNewWinDSM = true;
Log.Debug("Using new dsm in windows."); Log.Debug("Using new dsm.");
} }
else else
{ {
@ -92,7 +99,7 @@ namespace NTwain
{ {
ExpectedDsmPath = newDsmPath; ExpectedDsmPath = newDsmPath;
UseNewWinDSM = IsSupported = DsmExists = true; UseNewWinDSM = IsSupported = DsmExists = true;
Log.Debug("Using new dsm in windows."); Log.Debug("Using new dsm.");
} }
else else
{ {

View File

@ -23,7 +23,7 @@ namespace NTwain
/// <summary> /// <summary>
/// The build release version number. /// The build release version number.
/// </summary> /// </summary>
public const string Build = "3.3.9.2"; // change this for each nuget release public const string Build = "3.3.9.3"; // change this for each nuget release
} }