Files
ntwain/NTwain/PlatformInfo.cs

135 lines
4.3 KiB
C#
Raw Normal View History

2014-09-11 21:14:41 -04:00
using NTwain.Triplets;
using System;
2014-04-20 16:57:38 -04:00
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace NTwain
{
/// <summary>
/// Contains various platform requirements and conditions for TWAIN.
2014-04-20 16:57:38 -04:00
/// </summary>
public class PlatformInfo : IPlatformInfo
2014-04-20 16:57:38 -04:00
{
internal static readonly PlatformInfo __global = new PlatformInfo();
/// <summary>
/// Gets the current platform info related to TWAIN.
/// </summary>
/// <value>
/// The current info.
/// </value>
public static IPlatformInfo Current { get { return __global; } }
PlatformInfo()
2014-04-20 16:57:38 -04:00
{
IsApp64bit = IntPtr.Size == 8;
IsOnMono = Type.GetType("Mono.Runtime") != null;
IsWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
2014-04-20 16:57:38 -04:00
IsLinux = Environment.OSVersion.Platform == PlatformID.Unix;
2014-04-20 20:45:08 -04:00
if (IsWindows)
2014-09-02 19:10:35 -04:00
{
2014-09-11 21:14:41 -04:00
var newDsmPath = Path.Combine(Environment.SystemDirectory, Dsm.WIN_NEW_DSM_NAME);
var oldDsmPath = Path.Combine(Environment.SystemDirectory, Dsm.WIN_OLD_DSM_NAME);
2014-09-02 19:10:35 -04:00
if (IsApp64bit)
{
ExpectedDsmPath = newDsmPath;
IsSupported = DsmExists = File.Exists(ExpectedDsmPath);
2014-09-02 19:10:35 -04:00
UseNewWinDSM = true;
}
else
{
if (File.Exists(newDsmPath))
{
ExpectedDsmPath = newDsmPath;
2014-09-02 19:10:35 -04:00
UseNewWinDSM = IsSupported = DsmExists = true;
}
else
{
ExpectedDsmPath = oldDsmPath;
IsSupported = DsmExists = File.Exists(ExpectedDsmPath);
2014-09-02 19:10:35 -04:00
}
}
}
else if (IsLinux)
{
ExpectedDsmPath = Dsm.LINUX_DSM_PATH;
DsmExists = File.Exists(ExpectedDsmPath);
2014-09-02 19:10:35 -04:00
IsSupported = DsmExists && IsOnMono;
}
else
{
2014-09-11 21:14:41 -04:00
// mac? not gonna happen
2014-09-02 19:10:35 -04:00
}
2014-04-20 20:45:08 -04:00
_defaultMemManager = new WinMemoryManager();
2014-04-20 16:57:38 -04:00
}
internal readonly bool UseNewWinDSM;
internal readonly bool IsOnMono;
internal readonly bool IsWindows;
internal readonly bool IsLinux;
2014-04-20 16:57:38 -04:00
2014-09-11 21:14:41 -04:00
/// <summary>
/// Gets a value indicating whether the application is running in 64-bit.
/// </summary>
/// <value>
/// <c>true</c> if the application is 64-bit; otherwise, <c>false</c>.
/// </value>
public bool IsApp64bit { get; private set; }
2014-09-02 19:10:35 -04:00
/// <summary>
/// Gets a value indicating whether the applicable TWAIN DSM library exists in the operating system.
/// </summary>
/// <value>
/// <c>true</c> if the TWAIN DSM; otherwise, <c>false</c>.
/// </value>
public bool DsmExists { get; private set; }
/// <summary>
/// Gets the expected TWAIN DSM dll path.
/// </summary>
/// <value>
/// The expected DSM path.
/// </value>
public string ExpectedDsmPath { get; private set; }
2014-04-20 16:57:38 -04:00
/// <summary>
2014-09-02 19:10:35 -04:00
/// Gets a value indicating whether this library is supported on current OS.
2014-09-11 21:14:41 -04:00
/// Check the other platform properties to determine the reason if this is false.
2014-04-20 16:57:38 -04:00
/// </summary>
/// <value>
/// <c>true</c> if this library is supported; otherwise, <c>false</c>.
/// </value>
public bool IsSupported { get; private set; }
2014-04-20 16:57:38 -04:00
readonly IMemoryManager _defaultMemManager;
IMemoryManager _specifiedMemManager;
2014-04-20 16:57:38 -04:00
/// <summary>
/// Gets the <see cref="IMemoryManager"/> for communicating with data sources.
2014-09-11 21:14:41 -04:00
/// This should only be used when a <see cref="TwainSession"/> is open.
2014-04-20 16:57:38 -04:00
/// </summary>
/// <value>
/// The memory manager.
/// </value>
public IMemoryManager MemoryManager
2014-04-20 16:57:38 -04:00
{
get
{
if (_specifiedMemManager == null) { return _defaultMemManager; }
return _specifiedMemManager;
}
internal set
{
_specifiedMemManager = value;
}
}
}
}