Beispiel #1
0
        ///////////////////////////////////////////////////////////////////////////////
        // Public Methods...
        ///////////////////////////////////////////////////////////////////////////////
        #region Public Methods...

        /// <summary>
        /// Our constructor...
        /// </summary>
        /// <param name="a_aszIdentity">list of scanners to show</param>
        /// <param name="a_szDefault">the default selection</param>
        public FormSelect(string[] a_aszIdentity, string a_szDefault)
        {
            string[] aszIdentity;
            string[] aszDefault;

            // Init stuff...
            InitializeComponent();

            // Explode the default...
            aszDefault = TWAINCSToolkit.CsvParse(a_szDefault);

            // Suspend updating...
            m_listboxSelect.BeginUpdate();

            // Populate our driver list...
            foreach (string sz in a_aszIdentity)
            {
                aszIdentity = TWAINCSToolkit.CsvParse(sz);
                m_listboxSelect.Items.Add(aszIdentity[11].ToString());
            }

            // Select the default...
            m_listboxSelect.SelectedIndex = m_listboxSelect.FindStringExact(aszDefault[11]);

            // Resume updating...
            m_listboxSelect.EndUpdate();
        }
Beispiel #2
0
        ///////////////////////////////////////////////////////////////////////////////
        // Public Methods...
        ///////////////////////////////////////////////////////////////////////////////
        #region Public Methods...

        /// <summary>
        /// Our constructor...
        /// </summary>
        public FormScan()
        {
            // Build our form...
            InitializeComponent();

            // Init other stuff...
            m_blIndicators    = false;
            m_blExit          = false;
            m_iUseBitmap      = 0;
            this.FormClosing += new FormClosingEventHandler(FormScan_FormClosing);

            // Create our image capture object...
            try
            {
                m_twaincstoolkit = new TWAINCSToolkit
                                   (
                    this.Handle,
                    WriteOutput,
                    ReportImage,
                    null,
                    "TWAIN Working Group",
                    "TWAIN Sharp",
                    "TWAIN Sharp Scan App",
                    2,
                    3,
                    new string[] { "DF_APP2", "DG_CONTROL", "DG_IMAGE" },
                    "USA",
                    "testing...",
                    "ENGLISH_USA",
                    1,
                    0,
                    false,
                    true
                                   );
            }
            catch
            {
                m_twaincstoolkit = null;
                m_blExit         = true;
                MessageBox.Show
                (
                    "Unable to start, the most likely reason is that the TWAIN\n" +
                    "Data Source Manager is not installed on your system.\n\n" +
                    "An internet search for 'TWAIN DSM' will locate it and once\n" +
                    "installed, you should be able to proceed.\n\n" +
                    "You can also try the following link:\n" +
                    "http://sourceforge.net/projects/twain-dsm/",
                    "Error Starting TWAIN CS Scan"
                );
                return;
            }

            // Init our picture box...
            InitImage();

            // Init our buttons...
            SetButtons(EBUTTONSTATE.CLOSED);
        }
Beispiel #3
0
 /// <summary>
 /// React to a change to the selection of TWAIN_32.DLL...
 /// </summary>
 /// <param name="sender">Originator</param>
 /// <param name="e">Arguments</param>
 private void m_checkboxUseTwain32_CheckedChanged(object sender, EventArgs e)
 {
     // TWAIN_32.DLL om Windows doesn't support callbacks, but the
     // legacy stuff on Linux and MacOsX does; in fact that's all
     // they support...
     if (m_checkboxUseTwain32.Checked)
     {
         if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
         {
             m_checkboxUseCallbacks.Checked = false;
         }
     }
 }
Beispiel #4
0
        private void ParseSources(string[] sources)
        {
            Sources = new List <Source>();
            cmbSources.Items.Clear();

            foreach (var source in sources)
            {
                var info = TWAINCSToolkit.CsvParse(source);
                Sources.Add(new Source()
                {
                    Identity      = source,
                    Manufacturer  = info[9],
                    ProductFamily = info[10],
                    ProductName   = info[11]
                });
            }

            cmbSources.Items.Add(Sources[0].ProductName);
            cmbSources.SelectedIndex = 0;
        }
Beispiel #5
0
        // ==================================================
        // Methods
        // ==================================================

        private void InitTwain()
        {
            try
            {
                TwainToolkit = new TWAINCSToolkit
                               (
                    Handle,
                    WriteOutput,
                    ReportImage,
                    null,
                    "TWAIN Working Group",
                    "TWAIN Sharp",
                    "TWAIN Sharp Scan App",
                    2,
                    3,
                    new string[] { "DF_APP2", "DG_CONTROL", "DG_IMAGE" },
                    "USA",
                    "testing...",
                    "ENGLISH_USA",
                    1,
                    0,
                    false,
                    true
                               );

                var defaultSource = string.Empty;
                var sources       = TwainToolkit.GetDrivers(ref defaultSource);

                if (!sources.Any())
                {
                    throw new Exception("TWAIN GetDrivers returned an empty list.");
                }

                ParseSources(sources);
            }
            catch (Exception error)
            {
                HandleError(Resources.ErrorCannotInitTwain, error);
                return;
            }
        }
Beispiel #6
0
        private void InitCore()
        {
            m_blIndicators = false;

            _scanCore = new TWAINCSToolkit(this.Handle,
                                           WriteOutput,
                                           ReportImage,
                                           null,
                                           "TWAIN Working Group",
                                           "TWAIN Sharp",
                                           "TWAIN Sharp Scan App",
                                           2,
                                           4,
                                           new string[] { "DF_APP2", "DG_CONTROL", "DG_IMAGE" },
                                           "USA",
                                           "testing...",
                                           "ENGLISH_USA",
                                           1,
                                           0,
                                           false,
                                           true,
                                           RunInUiThread,
                                           this);
        }
Beispiel #7
0
        public FormSetup(ref TWAINCSToolkit a_twaincstoolkit, string a_szProductDirectory)
        {
            TWAIN.STS sts;
            string    szStatus;
            string    szCapability;
            string    szUsrUiSettings;

            // Init stuff...
            InitializeComponent();

            // More init stuff...
            this.FormClosing += new FormClosingEventHandler(FormSetup_FormClosing);

            // Init more stuff (the order matters).  ApplicationData means the following:
            // Windows:     C:\Users\USERNAME\AppData\Roaming (or C:\Documents and Settings\USERNAME\Application Data on XP)
            // Linux:       /home/USERNAME/.config (or /root/.config for superuser)
            // Mac OS X:    /Users/USERNAME/.config (or /var/root/.config for superuser)
            m_twaincstoolkit    = a_twaincstoolkit;
            m_szTwainscanFolder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "twain"), "twaincsscan");
            m_szSettingsFolder  = Path.Combine(m_szTwainscanFolder, "settings");
            m_szSettingsFolder  = Path.Combine(m_szSettingsFolder, a_szProductDirectory);
            if (!Directory.Exists(m_szTwainscanFolder))
            {
                try
                {
                    Directory.CreateDirectory(m_szTwainscanFolder);
                }
                catch (Exception exception)
                {
                    TWAINWorkingGroup.Log.Error("exception - " + exception.Message);
                    m_szTwainscanFolder = Directory.GetCurrentDirectory();
                }
            }

            // Restore values...
            m_textboxFolder.Text        = RestoreFolder();
            m_textboxUseUiSettings.Text = "";

            // Make sure we prime the value...
            m_twaincstoolkit.SetImagePath(m_textboxFolder.Text, 0);

            // Check for support of Custom DS Data...
            szStatus     = "";
            szCapability = "CAP_CUSTOMDSDATA";
            sts          = m_twaincstoolkit.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_GETCURRENT", ref szCapability, ref szStatus);
            if ((sts != TWAIN.STS.SUCCESS) || !szCapability.EndsWith(",1"))
            {
                m_labelUseUiSettings.Enabled   = false;
                m_textboxUseUiSettings.Enabled = false;
                m_buttonSaveUiSettings.Enabled = false;
                m_buttonUseUiSettings.Enabled  = false;
            }

            // Restore the last saved snapshot...
            else
            {
                m_textboxUseUiSettings.Text = RestoreSetting();
                if (m_textboxUseUiSettings.Text != "")
                {
                    szUsrUiSettings = Path.Combine(m_szSettingsFolder, m_textboxUseUiSettings.Text);
                    if (File.Exists(szUsrUiSettings))
                    {
                        m_twaincstoolkit.RestoreSnapshot(szUsrUiSettings);
                    }
                    else
                    {
                        m_textboxUseUiSettings.Text = "";
                    }
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Create and destroy our toolkit object, as needed...
        /// </summary>
        /// <param name="a_szDg">Data group</param>
        /// <param name="a_szDat">Data argument type</param>
        /// <param name="a_szMsg">Operation</param>
        private void ManageToolkit(string a_szDg, string a_szDat, string a_szMsg)
        {
            // Handle MSG_OPENDSM...
            if (a_szMsg == "MSG_OPENDSM")
            {
                // Init stuff...
                m_blClosing = false;

                // Validate...
                if (m_twaincstoolkit != null)
                {
                    WriteTriplet(a_szDg, a_szDat, a_szMsg, "(already open)");
                    return;
                }

                // Create our image capture object...
                try
                {
                    m_twaincstoolkit = new TWAINCSToolkit
                                       (
                        this.Handle,
                        WriteOutput,
                        ReportImage,
                        SetMessageFilter,
                        "TWAIN Working Group",
                        "TWAIN Sharp",
                        "TWAIN Sharp Test App",
                        2,
                        3,
                        new string[] { "DF_APP2", "DG_CONTROL", "DG_IMAGE" },
                        "USA",
                        "testing...",
                        "ENGLISH_USA",
                        1,
                        0,
                        m_checkboxUseTwain32.Checked,
                        m_checkboxUseCallbacks.Checked
                                       );
                }
                catch
                {
                    WriteTriplet(a_szDg, a_szDat, a_szMsg, "(unable to start)");
                    m_twaincstoolkit = null;
                    return;
                }
                WriteTriplet(a_szDg, a_szDat, a_szMsg, TWAINCSToolkit.STS.SUCCESS.ToString());

                // Fix our controls...
                if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
                {
                    m_checkboxUseTwain32.Enabled   = false;
                    m_checkboxUseCallbacks.Enabled = false;
                }

                // Help the user...
                AutoDropdown(a_szDg, a_szDat, a_szMsg);
            }

            // Handle MSG_CLOSEDSM...
            else if (a_szMsg == "MSG_CLOSEDSM")
            {
                // Issue the command...
                WriteTriplet(a_szDg, a_szDat, a_szMsg, TWAINCSToolkit.STS.SUCCESS.ToString());
                m_blClosing = true;
                m_twaincstoolkit.Cleanup();
                m_twaincstoolkit = null;

                // Fix our controls...
                if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
                {
                    m_checkboxUseTwain32.Enabled   = (TWAINCSToolkit.GetMachineWordBitSize() == 32);
                    m_checkboxUseCallbacks.Enabled = true;
                }

                // Help the user...
                AutoDropdown(a_szDg, a_szDat, a_szMsg);
            }

            // Handle anything else...
            else
            {
                WriteTriplet(a_szDg, a_szDat, a_szMsg, TWAINCSToolkit.STS.BADPROTOCOL.ToString());
            }
        }
Beispiel #9
0
        ///////////////////////////////////////////////////////////////////////////////
        // Public Functions...
        ///////////////////////////////////////////////////////////////////////////////
        #region Public Functions...

        /// <summary>
        /// Init our form, and our TWAIN class.  You might want to consider
        /// moving TWAIN into its own thread, or even running it from a
        /// separate process, so that the main application is always responsive
        /// no matter what's going on in the driver...
        /// </summary>
        public FormMain()
        {
            ContextMenu contextmenu;
            MenuItem    menuitem;

            // Init our form...
            InitializeComponent();

            // Make sure we cleanup if unexpectedly closed...
            this.FormClosing += new FormClosingEventHandler(FormMain_FormClosing);

            // This next bit establishes the rules for the various DSM's on the
            // various operating systems.

            // Windows controls...
            if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
            {
                m_checkboxUseTwain32.Enabled   = (TWAINCSToolkit.GetMachineWordBitSize() == 32);
                m_checkboxUseCallbacks.Enabled = true;
                m_checkboxUseTwain32.Checked   = false;
                m_checkboxUseCallbacks.Checked = true;
            }

            // Linux controls...
            else if (TWAINCSToolkit.GetPlatform() == "LINUX")
            {
                m_checkboxUseTwain32.Checked   = false;
                m_checkboxUseCallbacks.Checked = true;
                m_checkboxUseTwain32.Enabled   = false;
                m_checkboxUseCallbacks.Enabled = false;
            }

            // Mac OS X controls...
            else if (TWAINCSToolkit.GetPlatform() == "MACOSX")
            {
                m_checkboxUseTwain32.Checked   = false;
                m_checkboxUseCallbacks.Checked = true;
                m_checkboxUseTwain32.Enabled   = false;
                m_checkboxUseCallbacks.Enabled = false;
            }

            // Autoscroll the text in our output box...
            m_richtextboxOutput.HideSelection      = false;
            m_richtextboxOutput.SelectionProtected = false;

            // Init other stuff...
            m_twaincstoolkit = null;

            // Init our image controls...
            InitImage();

            // Load our triplet dropdown...
            this.m_comboboxDG.Items.AddRange(TWAINCSToolkit.GetTwainDg());
            this.m_comboboxDAT.Items.AddRange(TWAINCSToolkit.GetTwainDat());
            this.m_comboboxMSG.Items.AddRange(TWAINCSToolkit.GetTwainMsg());

            // Init our triplet dropdown...
            AutoDropdown("", "", "");

            // Context menu for our value box...
            contextmenu     = new ContextMenu();
            menuitem        = new MenuItem("Copy");
            menuitem.Click += new EventHandler(richtextboxcapability_Copy);
            contextmenu.MenuItems.Add(menuitem);
            menuitem        = new MenuItem("Paste");
            menuitem.Click += new EventHandler(richtextboxcapability_Paste);
            contextmenu.MenuItems.Add(menuitem);
            m_richtextboxCapability.ContextMenu = contextmenu;
            contextmenu = null;

            // Context menu for our output box...
            contextmenu     = new ContextMenu();
            menuitem        = new MenuItem("Copy");
            menuitem.Click += new EventHandler(richtextboxoutput_Copy);
            contextmenu.MenuItems.Add(menuitem);
            menuitem        = new MenuItem("Paste");
            menuitem.Click += new EventHandler(richtextboxoutput_Paste);
            contextmenu.MenuItems.Add(menuitem);
            m_richtextboxOutput.ContextMenu = contextmenu;
            contextmenu = null;
        }
Beispiel #10
0
        /// <summary>
        /// Create and destroy our toolkit object, as needed...
        /// </summary>
        /// <param name="a_szDg">Data group</param>
        /// <param name="a_szDat">Data argument type</param>
        /// <param name="a_szMsg">Operation</param>
        private void ManageToolkit(string a_szDg, string a_szDat, string a_szMsg)
        {
            // Handle MSG_OPENDSM...
            if (a_szMsg == "MSG_OPENDSM")
            {
                // Init stuff...
                m_blClosing = false;

                // Validate...
                if (m_twaincstoolkit != null)
                {
                    WriteTriplet(a_szDg, a_szDat, a_szMsg, "(already open)");
                    return;
                }

                // Create our image capture object...
                try
                {
                    string[] aszTwidentity = m_richtextboxCapability.Text.Split(',');
                    if ((aszTwidentity == null) || (aszTwidentity.Length < 9))
                    {
                        m_twaincstoolkit = new TWAINCSToolkit
                                           (
                            this.Handle,
                            WriteOutput,
                            ReportImage,
                            SetMessageFilter,
                            "TWAIN Working Group",
                            "TWAIN Sharp",
                            "TWAIN Sharp Test App",
                            2,
                            4,
                            new string[] { "DF_APP2", "DG_CONTROL", "DG_IMAGE" },
                            "USA",
                            "testing...",
                            "ENGLISH_USA",
                            1,
                            0,
                            m_checkboxUseTwain32.Checked,
                            m_checkboxUseCallbacks.Checked,
                            RunInUiThread,
                            this
                                           );
                    }
                    else
                    {
                        m_twaincstoolkit = new TWAINCSToolkit
                                           (
                            this.Handle,
                            WriteOutput,
                            ReportImage,
                            SetMessageFilter,
                            aszTwidentity[0],
                            aszTwidentity[1],
                            aszTwidentity[2],
                            ushort.Parse(aszTwidentity[3]),
                            ushort.Parse(aszTwidentity[4]),
                            new string[] { "DF_APP2", "DG_CONTROL", "DG_IMAGE" },
                            aszTwidentity[6],
                            aszTwidentity[7],
                            aszTwidentity[8],
                            1,
                            0,
                            m_checkboxUseTwain32.Checked,
                            m_checkboxUseCallbacks.Checked,
                            RunInUiThread,
                            this
                                           );
                    }
                }
                catch (Exception exception)
                {
                    TWAINWorkingGroup.Log.Error("exception - " + exception.Message);
                    WriteTriplet(a_szDg, a_szDat, a_szMsg, "(unable to start)");
                    m_twaincstoolkit = null;
                    return;
                }
                WriteTriplet(a_szDg, a_szDat, a_szMsg, TWAIN.STS.SUCCESS.ToString());

                // Fix our controls...
                if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
                {
                    m_checkboxUseTwain32.Enabled   = false;
                    m_checkboxUseCallbacks.Enabled = false;
                }

                // Help the user...
                AutoDropdown(a_szDg, a_szDat, a_szMsg);
            }

            // Handle MSG_CLOSEDSM...
            else if (a_szMsg == "MSG_CLOSEDSM")
            {
                // Issue the command...
                WriteTriplet(a_szDg, a_szDat, a_szMsg, TWAIN.STS.SUCCESS.ToString());
                m_blClosing = true;
                m_twaincstoolkit.Cleanup();
                m_twaincstoolkit = null;

                // Fix our controls...
                if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
                {
                    m_checkboxUseTwain32.Enabled   = (TWAINCSToolkit.GetMachineWordBitSize() == 32);
                    m_checkboxUseCallbacks.Enabled = true;
                }

                // Help the user...
                AutoDropdown(a_szDg, a_szDat, a_szMsg);
            }

            // Handle anything else...
            else
            {
                WriteTriplet(a_szDg, a_szDat, a_szMsg, TWAIN.STS.BADPROTOCOL.ToString());
            }
        }
Beispiel #11
0
        ///////////////////////////////////////////////////////////////////////////////
        // Public Functions...
        ///////////////////////////////////////////////////////////////////////////////
        #region Public Functions...

        /// <summary>
        /// Init our form, and our TWAIN class.  You might want to consider
        /// moving TWAIN into its own thread, or even running it from a
        /// separate process, so that the main application is always responsive
        /// no matter what's going on in the driver...
        /// </summary>
        public FormMain()
        {
            ContextMenu contextmenu;
            MenuItem    menuitem;

            // Init our form...
            InitializeComponent();

            // Open the log in our working folder, and say hi...
            TWAINWorkingGroup.Log.Open("TWAINCSTst", ".", 1);
            TWAINWorkingGroup.Log.Info("TWAINCSTst v" + System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString());

            // Make sure we cleanup if unexpectedly closed...
            this.FormClosing += new FormClosingEventHandler(FormMain_FormClosing);

            // This next bit establishes the rules for the various DSM's on the
            // various operating systems.

            // Windows controls...
            if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
            {
                // Choose between TWAIN_32 and TWAINDSM, note that we always default
                // to the open source TWAIN DSM...
                m_checkboxUseTwain32.Enabled   = (TWAINCSToolkit.GetMachineWordBitSize() == 32);
                m_checkboxUseCallbacks.Enabled = true;
                m_checkboxUseTwain32.Checked   = false;
                m_checkboxUseCallbacks.Checked = true;
            }

            // Linux controls...
            else if (TWAINCSToolkit.GetPlatform() == "LINUX")
            {
                // We don't give the user control between the DSM versions, because
                // the 64-bit problem is handled as seamlessly as possible...
                m_checkboxUseTwain32.Enabled   = false;
                m_checkboxUseCallbacks.Enabled = false;
                m_checkboxUseTwain32.Checked   = false;
                m_checkboxUseCallbacks.Checked = true;
            }

            // Mac OS X controls...
            else if (TWAINCSToolkit.GetPlatform() == "MACOSX")
            {
                // Choose between /System/Library/Frameworks/TWAIN.framework and
                // /Library/Frameworks/TWAINDSM.framework, note that we always default
                // to the open source TWAIN DSM...
                m_checkboxUseTwain32.Enabled   = true;
                m_checkboxUseCallbacks.Enabled = false;
                m_checkboxUseTwain32.Checked   = false;
                m_checkboxUseCallbacks.Checked = true;
            }

            // Autoscroll the text in our output box...
            m_richtextboxOutput.HideSelection      = false;
            m_richtextboxOutput.SelectionProtected = false;

            // Init other stuff...
            m_twaincstoolkit = null;

            // Init our image controls...
            InitImage();

            // Load our triplet dropdown...
            this.m_comboboxDG.Items.AddRange(TWAINCSToolkit.GetTwainDg());
            this.m_comboboxDAT.Items.AddRange(TWAINCSToolkit.GetTwainDat());
            this.m_comboboxMSG.Items.AddRange(TWAINCSToolkit.GetTwainMsg());

            // Init our triplet dropdown...
            AutoDropdown("", "", "");

            // Context menu for our value box...
            contextmenu     = new ContextMenu();
            menuitem        = new MenuItem("Copy");
            menuitem.Click += new EventHandler(richtextboxcapability_Copy);
            contextmenu.MenuItems.Add(menuitem);
            menuitem        = new MenuItem("Paste");
            menuitem.Click += new EventHandler(richtextboxcapability_Paste);
            contextmenu.MenuItems.Add(menuitem);
            m_richtextboxCapability.ContextMenu = contextmenu;
            contextmenu = null;

            // Context menu for our output box...
            contextmenu     = new ContextMenu();
            menuitem        = new MenuItem("Copy");
            menuitem.Click += new EventHandler(richtextboxoutput_Copy);
            contextmenu.MenuItems.Add(menuitem);
            menuitem        = new MenuItem("Paste");
            menuitem.Click += new EventHandler(richtextboxoutput_Paste);
            contextmenu.MenuItems.Add(menuitem);
            m_richtextboxOutput.ContextMenu = contextmenu;
            contextmenu = null;

            // Set the capbility box to our app info...
            m_richtextboxCapability.Text =
                "TWAIN Working Group," +
                "TWAIN Sharp," +
                "TWAIN Sharp Test App," +
                "2," +
                "4," +
                "0x20000003," +
                "USA," +
                "testing...," +
                "ENGLISH_USA";
        }
Beispiel #12
0
        /// <summary>
        /// Select the mode for this session, batch or interactive,
        /// based on the arguments.  Don't be weirded out by this
        /// function calling TWAIN Local On Twain and then that function using
        /// Sword.  This is a static function, it's just a convenience
        /// to use the Sword object to hold it, it could go anywhere
        /// and later on probably will (like as a function inside of
        /// the Program module).
        /// </summary>
        /// <returns>true for batch mode, false for interactive mode</returns>
        public static bool SelectMode()
        {
            int    iPid = 0;
            long   lResponseCharacterOffset;
            string szIpc;
            string szTaskFile;
            bool   blTestPdfRaster;
            bool   blTestTwainLocalOnTwain;
            bool   blTestJson;
            bool   blTestDnssd;

            // Check the arguments...
            string szWriteFolder    = Config.Get("writeFolder", null);
            string szExecutableName = Config.Get("executableName", null);

            szTaskFile              = Config.Get("task", null);
            blTestPdfRaster         = (Config.Get("testpdfraster", null) != null);
            blTestTwainLocalOnTwain = (Config.Get("testtwainlocalontwain", null) != null);
            blTestJson              = (Config.Get("testjson", null) != null);
            blTestDnssd             = (Config.Get("testdnssd", null) != null);
            szIpc = Config.Get("ipc", null);
            iPid  = int.Parse(Config.Get("parentpid", "0"));

            // Run in IPC mode.  The caller has set up a 'pipe' for us, so we'll use
            // that to send commands back and forth.  This is the normal mode when
            // we're running with a scanner...
            if (szIpc != null)
            {
                // With Windows we need a window for the driver, but we can hide it...
                if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new FormTwain(szWriteFolder, szIpc, iPid, RunInUiThread));
                    return(true);
                }

                // Linux and Mac OS X are okay without a window...
                else
                {
                    TwainLocalOnTwain twainlocalontwain;

                    // Create our object...
                    twainlocalontwain = new TwainLocalOnTwain(szWriteFolder, szIpc, iPid, null, null, IntPtr.Zero);

                    // Run our object...
                    twainlocalontwain.Run();

                    // All done...
                    return(true);
                }
            }

            // Handle the TWAIN list, we use this during registration to find out
            // what drivers we can use, and collect some info about them...
            string szTwainList = Config.Get("twainlist", null);

            if (szTwainList != null)
            {
                if (szTwainList == "")
                {
                    szTwainList = Path.Combine(Config.Get("writeFolder", ""), "twainlist.txt");
                }
                System.IO.File.WriteAllText(szTwainList, Sword.TwainListDrivers());
                return(true);
            }

            // Test PDF/Raster...
            if (blTestPdfRaster)
            {
                TestPdfRaster testpdfraster;

                // Create our object...
                testpdfraster = new TestPdfRaster();

                // Do the test...
                testpdfraster.Test();

                // All done...
                TWAINWorkingGroup.Log.Close();
                return(true);
            }

            // Test TWAIN Local on TWAIN...
            if (blTestTwainLocalOnTwain)
            {
                TestTwainLocalOnTwain testtwainlocalontwain;

                // Create our object...
                testtwainlocalontwain = new TestTwainLocalOnTwain(Config.Get("scanner", null), szWriteFolder, iPid, szTaskFile);

                // Do the test...
                testtwainlocalontwain.Test();

                // All done...
                return(true);
            }

            // Test JSON...
            if (blTestJson)
            {
                TwainDirectSupport.JsonLookup jsonlookup = new TwainDirectSupport.JsonLookup();

                string szTest =
                    "{\n" +
                    "    \"array\": [\n" +
                    "        {\n" +
                    "            \\\"aaa\\\": 0,\n" +
                    "            'bbb': 1\n" +
                    "        },\n" +
                    "        {\n" +
                    "            ccc : 2,\n" +
                    "            'ddd' : 3,\n" +
                    "            \"xxx\": [\n" +
                    "                {\n" +
                    "                    \"mmm\": 111\n" +
                    "                },\n" +
                    "                {\n" +
                    "                    \"nnn\": 222\n" +
                    "                },\n" +
                    "                {\n" +
                    "                    \"ooo\": 333\n" +
                    "                }\n" +
                    "            ]\n" +
                    "        },\n" +
                    "        {\n" +
                    "            \"eee\": 4,\n" +
                    "            \"fff\": 5\n" +
                    "        }\n" +
                    "    ],\n" +
                    "    \"string\": \"value\"\n" +
                    "}";

                // Load something interesting...
                bool blSuccess = jsonlookup.Load(szTest, out lResponseCharacterOffset);
                if (!blSuccess)
                {
                    string sz = szTest.Substring(0, (int)lResponseCharacterOffset);
                }

                NativeMethods.AllocConsole();
                jsonlookup.Dump();

                // Find something interesting...
                string szValue;
                TwainDirectSupport.JsonLookup.EPROPERTYTYPE epropertytype;
                blSuccess = jsonlookup.GetCheck("array[0].aaa", out szValue, out epropertytype, true);

                // Test...
                string[] aszFile = Directory.GetFiles("C:/Users/l252353/Desktop/TwainDirect/source/TwainDirectOnTwain/bin/x86/Debug/data");
                if (aszFile != null)
                {
                    foreach (string szFile in aszFile)
                    {
                        // Skip non-.json files...
                        if (!szFile.Contains("pass0.json"))
                        {
                            continue;
                        }

                        // Read it...
                        string szJson = File.ReadAllText(szFile);

                        // Load it...
                        blSuccess = jsonlookup.Load(szJson, out lResponseCharacterOffset);

                        // File we're working on...
                        Console.WriteLine("\r\n*******************************************************************************");
                        Console.WriteLine(szFile);

                        // Fail file results...
                        if (szFile.Contains("fail"))
                        {
                            if (blSuccess)
                            {
                                Console.WriteLine("FAILED ON THE FAIL...");
                            }
                            else
                            {
                                Console.WriteLine("Error at offset: " + lResponseCharacterOffset);
                                Console.WriteLine(szJson.Substring(0, (int)lResponseCharacterOffset) + "^ERROR^" + szJson.Substring((int)lResponseCharacterOffset));
                            }
                        }

                        // Pass file results...
                        else
                        {
                            if (blSuccess)
                            {
                                jsonlookup.Dump();
                                jsonlookup.GetCheck("devices[0].id", out szValue, out epropertytype, true);
                            }
                            else
                            {
                                Console.WriteLine("Error at offset: " + lResponseCharacterOffset);
                                Console.WriteLine(szJson.Substring(0, (int)lResponseCharacterOffset) + "^ERROR^" + szJson.Substring((int)lResponseCharacterOffset));
                            }
                        }
                    }
                }

                // All done...
                return(true);
            }

            /// Test DNS-SD...
            if (blTestDnssd)
            {
                // Do the test...
                int tt;
                int jj;
                TwainDirectSupport.Dnssd.DnssdDeviceInfo[] adnssddeviceinfo = null;
                NativeMethods.AllocConsole();
                TwainDirectSupport.Dnssd dnssd = new TwainDirectSupport.Dnssd(TwainDirectSupport.Dnssd.Reason.Monitor);
                dnssd.MonitorStart();
                for (tt = 0; tt < 6000000; tt++)
                {
                    bool blUpdated;
                    TwainDirectSupport.Dnssd.DnssdDeviceInfo[] adnssddeviceinfoNew;
                    TwainDirectSupport.Dnssd.DnssdDeviceInfo[] adnssddeviceinfoCompare = adnssddeviceinfo;
                    adnssddeviceinfoNew = dnssd.GetSnapshot(adnssddeviceinfoCompare, out blUpdated);
                    adnssddeviceinfo    = adnssddeviceinfoNew;
                    adnssddeviceinfoNew = null;
                    if (adnssddeviceinfo == null)
                    {
                        if (blUpdated)
                        {
                            Console.Out.WriteLine("");
                            Console.Out.WriteLine("*** empty list ***");
                        }
                        System.Threading.Thread.Sleep(1000);
                        continue;
                    }
                    if (blUpdated)
                    {
                        Console.Out.WriteLine("");
                        for (jj = 0; jj < adnssddeviceinfo.Length; jj++)
                        {
                            Console.Out.WriteLine
                            (
                                adnssddeviceinfo[jj].szServiceName + Environment.NewLine +
                                "  " + adnssddeviceinfo[jj].szLinkLocal +
                                " " + adnssddeviceinfo[jj].lInterface +
                                ((adnssddeviceinfo[jj].szIpv4 == null) ? " NoIpv4" : (" " + adnssddeviceinfo[jj].szIpv4)) +
                                ((adnssddeviceinfo[jj].szIpv6 == null) ? " NoIpv6" : (" " + adnssddeviceinfo[jj].szIpv6)) +
                                " " + adnssddeviceinfo[jj].lPort +
                                ((adnssddeviceinfo[jj].aszText == null) ? "" : (Environment.NewLine + "  " + string.Join(" ", adnssddeviceinfo[jj].aszText)))
                            );
                        }
                    }
                    System.Threading.Thread.Sleep(1000);
                }
                dnssd.MonitorStop();

                // All done...
                return(true);
            }

            // Execute the specified task...
            if (File.Exists(szTaskFile))
            {
                bool      blSetAppCapabilities = false;
                Sword     sword;
                SwordTask swordtask;

                // Init stuff...
                swordtask = new SwordTask();

                // Create our object...
                sword = new Sword(null);

                // Run our task...
                sword.BatchMode(Config.Get("scanner", null), szTaskFile, false, ref swordtask, ref blSetAppCapabilities);

                // All done...
                return(true);
            }

            // Otherwise let the user interact with us...
            TWAINWorkingGroup.Log.Info("Interactive mode...");
            return(false);
        }
Beispiel #13
0
        /// <summary>
        /// Select the mode for this session, batch or interactive,
        /// based on the arguments.  Don't be weirded out by this
        /// function calling TWAIN Local On Twain and then that function using
        /// Sword.  This is a static function, it's just a convenience
        /// to use the Sword object to hold it, it could go anywhere
        /// and later on probably will (like as a function inside of
        /// the Program module).
        /// </summary>
        /// <returns>true for batch mode, false for interactive mode</returns>
        public static bool SelectMode()
        {
            int    iPid = 0;
            string szIpc;
            string szTaskFile;
            string szImagesFolder;
            bool   blTestPdfRaster;
            string szTestDnssd;

            // Check the arguments...
            string szWriteFolder    = Config.Get("writeFolder", null);
            string szExecutableName = Config.Get("executableName", null);

            szTaskFile      = Config.Get("task", null);
            blTestPdfRaster = (Config.Get("testpdfraster", null) != null);
            szTestDnssd     = Config.Get("testdnssd", null);
            szIpc           = Config.Get("ipc", null);
            szImagesFolder  = Config.Get("images", null);
            if (string.IsNullOrEmpty(szImagesFolder))
            {
                szImagesFolder = Path.Combine(szWriteFolder, "images");
            }
            iPid = int.Parse(Config.Get("parentpid", "0"));

            // Run in IPC mode.  The caller has set up a 'pipe' for us, so we'll use
            // that to send commands back and forth.  This is the normal mode when
            // we're running with a scanner...
            if (szIpc != null)
            {
                // With Windows we need a window for the driver, but we can hide it...
                if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new FormTwain(szWriteFolder, szImagesFolder, szIpc, iPid, RunInUiThread));
                    return(true);
                }

                // Linux and Mac OS X are okay without a window...
                else
                {
                    TwainLocalOnTwain twainlocalontwain;

                    // Create our object...
                    twainlocalontwain = new TwainLocalOnTwain(szWriteFolder, szImagesFolder, szIpc, iPid, null, null, IntPtr.Zero);

                    // Run our object...
                    twainlocalontwain.Run();

                    // All done...
                    return(true);
                }
            }

            // Handle the TWAIN list, we use this during registration to find out
            // what drivers we can use, and collect some info about them...
            string szTwainList = Config.Get("twainlist", null);

            if (szTwainList != null)
            {
                if (szTwainList == "")
                {
                    szTwainList = Path.Combine(Config.Get("writeFolder", ""), "twainlist.txt");
                }
                System.IO.File.WriteAllText(szTwainList, ProcessSwordTask.TwainListDrivers());
                return(true);
            }

            /// Test DNS-SD...
            if (!string.IsNullOrEmpty(szTestDnssd))
            {
                if (szTestDnssd == "monitor")
                {
                    int   ii;
                    int   jj;
                    Dnssd dnssd;
                    Interpreter.CreateConsole();
                    Dnssd.DnssdDeviceInfo[] adnssddeviceinfo = null;
                    dnssd = new Dnssd(Dnssd.Reason.Monitor);
                    dnssd.MonitorStart(null, IntPtr.Zero);
                    for (ii = 0; ii < 60; ii++)
                    {
                        bool blUpdated = false;
                        Thread.Sleep(1000);
                        adnssddeviceinfo = dnssd.GetSnapshot(adnssddeviceinfo, out blUpdated);
                        if (blUpdated)
                        {
                            Console.Out.WriteLine("");
                            if ((adnssddeviceinfo == null) || (adnssddeviceinfo.Length == 0))
                            {
                                Console.Out.WriteLine("***empty***");
                            }
                            else
                            {
                                for (jj = 0; jj < adnssddeviceinfo.Length; jj++)
                                {
                                    Console.Out.WriteLine(adnssddeviceinfo[jj].GetInterface() + " " + adnssddeviceinfo[jj].GetServiceName());
                                }
                            }
                        }
                    }
                    dnssd.MonitorStop();
                    dnssd.Dispose();
                }
                else if (szTestDnssd == "register")
                {
                    Dnssd dnssd;
                    Interpreter.CreateConsole();
                    dnssd = new Dnssd(Dnssd.Reason.Register);
                    dnssd.RegisterStart("Instance", 55556, "Ty", "", "Note");
                    Thread.Sleep(60000);
                    dnssd.RegisterStop();
                    dnssd.Dispose();
                }

                // All done...
                return(true);
            }

            // Otherwise let the user interact with us...
            TWAINWorkingGroup.Log.Info("Interactive mode...");
            return(false);
        }
Beispiel #14
0
        /// <summary>
        /// 初始化设备
        /// </summary>
        /// <param name="devName"></param>
        public bool InitDevice(string devName)
        {
            _scanDevName = devName;

            string szStatus = "";

            if (_scanCore == null)
            {
                InitCore();
            }

            _scanCore.Send("DG_CONTROL", "DAT_IDENTITY", "MSG_SET", ref _scanDevName, ref szStatus);

            // Open it...

            TWAIN.STS sts = _scanCore.Send("DG_CONTROL", "DAT_IDENTITY", "MSG_OPENDS", ref _scanDevName, ref szStatus);
            if (sts != TWAIN.STS.SUCCESS)
            {
                //MessageBox.Show("Unable to open scanner (it is turned on and plugged in?)");

                return(false);
            }

            // Strip off unsafe chars.  Sadly, mono let's us down here...
            m_szProductDirectory = TWAINCSToolkit.CsvParse(_scanDevName)[11];
            foreach (char c in new char[41]
            {
                '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
                '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12',
                '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D',
                '\x1E', '\x1F', '\x22', '\x3C', '\x3E', '\x7C', ':', '*', '?', '\\', '/'
            }
                     )
            {
                m_szProductDirectory = m_szProductDirectory.Replace(c, '_');
            }


            szStatus = "";
            string szCapability = "ICAP_XFERMECH,TWON_ONEVALUE,TWTY_UINT16,2";

            sts = _scanCore.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref szCapability, ref szStatus);
            if (sts != TWAIN.STS.SUCCESS)
            {
                return(false);
            }

            // Decide whether or not to show the driver's window messages...
            szStatus     = "";
            szCapability = "CAP_INDICATORS,TWON_ONEVALUE,TWTY_BOOL," + (m_blIndicators ? "1" : "0");
            sts          = _scanCore.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref szCapability, ref szStatus);
            if (sts != TWAIN.STS.SUCCESS)
            {
                return(false);
            }

            if (m_formsetup == null)
            {
                m_formsetup = new FormSetup(ref _scanCore, m_szProductDirectory);
            }


            return(true);
        }
Beispiel #15
0
        /// <summary>
        /// Select and open a TWAIN driver...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_buttonOpen_Click(object sender, EventArgs e)
        {
            string szIdentity;
            string szCapability;
            string szDefault;
            string szStatus;

            string[]     aszIdentity;
            FormSelect   formselect;
            DialogResult dialogresult;

            TWAIN.STS sts;

            // Find out which driver we're using...
            szDefault   = "";
            aszIdentity = m_twaincstoolkit.GetDrivers(ref szDefault);
            if (aszIdentity == null)
            {
                MessageBox.Show("There are no TWAIN drivers installed on this system...");
                return;
            }

            // Instantiate our form...
            formselect = new FormSelect(aszIdentity, szDefault);
            formselect.StartPosition = FormStartPosition.CenterParent;
            dialogresult             = formselect.ShowDialog(this);
            if (dialogresult != System.Windows.Forms.DialogResult.OK)
            {
                m_blExit = true;
                return;
            }

            // Get all the identities...
            szIdentity = formselect.GetSelectedDriver();
            if (szIdentity == null)
            {
                m_blExit = true;
                return;
            }

            // Get the selected identity...
            m_blExit = true;
            foreach (string sz in aszIdentity)
            {
                if (sz.Contains(szIdentity))
                {
                    m_blExit   = false;
                    szIdentity = sz;
                    break;
                }
            }
            if (m_blExit)
            {
                return;
            }

            // Make it the default, we don't care if this succeeds...
            szStatus = "";
            m_twaincstoolkit.Send("DG_CONTROL", "DAT_IDENTITY", "MSG_SET", ref szIdentity, ref szStatus);

            // Open it...
            szStatus = "";
            sts      = m_twaincstoolkit.Send("DG_CONTROL", "DAT_IDENTITY", "MSG_OPENDS", ref szIdentity, ref szStatus);
            if (sts != TWAIN.STS.SUCCESS)
            {
                MessageBox.Show("Unable to open scanner (it is turned on and plugged in?)");
                m_blExit = true;
                return;
            }

            // Strip off unsafe chars.  Sadly, mono let's us down here...
            m_szProductDirectory = TWAINCSToolkit.CsvParse(szIdentity)[11];
            foreach (char c in new char [41]
            {
                '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
                '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12',
                '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D',
                '\x1E', '\x1F', '\x22', '\x3C', '\x3E', '\x7C', ':', '*', '?', '\\', '/'
            }
                     )
            {
                m_szProductDirectory = m_szProductDirectory.Replace(c, '_');
            }

            // We're doing memory transfers (TWSX_MEMORY == 2)...
            szStatus     = "";
            szCapability = "ICAP_XFERMECH,TWON_ONEVALUE,TWTY_UINT16,2";
            sts          = m_twaincstoolkit.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref szCapability, ref szStatus);
            if (sts != TWAIN.STS.SUCCESS)
            {
                m_blExit = true;
                return;
            }

            // Decide whether or not to show the driver's window messages...
            szStatus     = "";
            szCapability = "CAP_INDICATORS,TWON_ONEVALUE,TWTY_BOOL," + (m_blIndicators?"1":"0");
            sts          = m_twaincstoolkit.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref szCapability, ref szStatus);
            if (sts != TWAIN.STS.SUCCESS)
            {
                m_blExit = true;
                return;
            }

            // New state...
            SetButtons(EBUTTONSTATE.OPEN);

            // Create the setup form...
            m_formsetup = new FormSetup(ref m_twaincstoolkit, m_szProductDirectory);
        }
Beispiel #16
0
        ///////////////////////////////////////////////////////////////////////////////
        // Public Methods...
        ///////////////////////////////////////////////////////////////////////////////
        #region Public Methods...

        /// <summary>
        /// Our constructor...
        /// </summary>
        public FormScan()
        {
            // Build our form...
            InitializeComponent();

            // Open the log in our working folder, and say hi...
            TWAINWorkingGroup.Log.Open("TWAINCSScan", ".", 1);
            TWAINWorkingGroup.Log.Info("TWAINCSScan v" + System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString());

            // Init other stuff...
            m_blIndicators    = false;
            m_blExit          = false;
            m_iUseBitmap      = 0;
            this.FormClosing += new FormClosingEventHandler(FormScan_FormClosing);

            // Create our image capture object...
            try
            {
                m_twaincstoolkit = new TWAINCSToolkit
                                   (
                    this.Handle,
                    WriteOutput,
                    ReportImage,
                    null,
                    "TWAIN Working Group",
                    "TWAIN Sharp",
                    "TWAIN Sharp Scan App",
                    2,
                    4,
                    new string[] { "DF_APP2", "DG_CONTROL", "DG_IMAGE" },
                    "USA",
                    "testing...",
                    "ENGLISH_USA",
                    1,
                    0,
                    false,
                    true,
                    RunInUiThread,
                    this
                                   );
            }
            catch (Exception exception)
            {
                TWAINWorkingGroup.Log.Error("exception - " + exception.Message);
                m_twaincstoolkit = null;
                m_blExit         = true;
                MessageBox.Show
                (
                    "Unable to start, the most likely reason is that the TWAIN\n" +
                    "Data Source Manager is not installed on your system.\n\n" +
                    "An internet search for 'TWAIN DSM' will locate it and once\n" +
                    "installed, you should be able to proceed.\n\n" +
                    "You can also try the following link:\n" +
                    "http://sourceforge.net/projects/twain-dsm/",
                    "Error Starting TWAIN CS Scan"
                );
                return;
            }

            // Init our picture box...
            InitImage();

            // Init our buttons...
            SetButtons(EBUTTONSTATE.CLOSED);
        }
Beispiel #17
0
        /// <summary>
        /// Select the mode for this session, batch or interactive,
        /// based on the arguments.  Don't be weirded out by this
        /// function calling TWAIN Local On Twain and then that function using
        /// Sword.  This is a static function, it's just a convenience
        /// to use the Sword object to hold it, it could go anywhere
        /// and later on probably will (like as a function inside of
        /// the Program module).
        /// </summary>
        /// <returns>true for batch mode, false for interactive mode</returns>
        public static bool SelectMode()
        {
            int    iPid = 0;
            string szIpc;
            string szTask;
            string szTaskFile;
            string szImagesFolder;
            bool   blTestPdfRaster;
            string szTestDnssd;
            bool   blSuccess;

            // Check the arguments...
            string szWriteFolder    = Config.Get("writeFolder", null);
            string szExecutableName = Config.Get("executableName", null);

            szTaskFile      = Config.Get("task", null);
            blTestPdfRaster = (Config.Get("testpdfraster", null) != null);
            szTestDnssd     = Config.Get("testdnssd", null);
            szIpc           = Config.Get("ipc", null);
            szImagesFolder  = Config.Get("images", null);
            if (string.IsNullOrEmpty(szImagesFolder))
            {
                szImagesFolder = Path.Combine(szWriteFolder, "images");
            }
            iPid = int.Parse(Config.Get("parentpid", "0"));

            // Test ProcessSwordTask...
            if (!string.IsNullOrEmpty(Config.Get("testtask", null)))
            {
                // Create our object...
                ProcessSwordTask processswordtask = new ProcessSwordTask(szImagesFolder, null, null);

                // Did we get a valid filename?
                if ((szTaskFile == null) || !File.Exists(szTaskFile))
                {
                    Console.Out.WriteLine("");
                    Console.Out.WriteLine("Please provide a valid task=file argument...");
                    return(false);
                }

                // Load the file...
                szTask = File.ReadAllText(szTaskFile);

                // Handle certification files...
                string[] aszTask = szTask.Split(new string[] { "***DATADATADATA***" }, StringSplitOptions.RemoveEmptyEntries);
                if ((aszTask == null) || (aszTask.Length == 0))
                {
                    Console.Out.WriteLine("");
                    Console.Out.WriteLine("Please provide a task file with data...");
                    return(false);
                }

                // Get our task data...
                if (aszTask.Length == 1)
                {
                    szTask = aszTask[0];
                }
                else
                {
                    szTask = aszTask[1];
                }

                // Run a test...
                bool blSetAppCapabilities = true;
                blSuccess = processswordtask.BatchMode(null, szTask, true, ref blSetAppCapabilities);
                //blSuccess = processswordtask.Deserialize(szTask, "211a1e90-11e1-11e5-9493-1697f925ec7b");
                if (blSuccess)
                {
                    //blSuccess = processswordtask.ProcessAndRun();
                }

                // All done...
                return(true);
            }

            // Run in IPC mode.  The caller has set up a 'pipe' for us, so we'll use
            // that to send commands back and forth.  This is the normal mode when
            // we're running with a scanner...
            if (szIpc != null)
            {
                // With Windows we need a window for the driver, but we can hide it...
                if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new FormTwain(szWriteFolder, szImagesFolder, szIpc, iPid, RunInUiThread));
                    return(true);
                }

                // Linux and Mac OS X are okay without a window...
                else
                {
                    TwainLocalOnTwain twainlocalontwain;

                    // Create our object...
                    twainlocalontwain = new TwainLocalOnTwain(szWriteFolder, szImagesFolder, szIpc, iPid, null, null, IntPtr.Zero);

                    // Run our object...
                    twainlocalontwain.Run();

                    // All done...
                    return(true);
                }
            }

            // Handle the TWAIN list, we use this during registration to find out
            // what drivers we can use, and collect some info about them...
            string szTwainList = Config.Get("twainlist", null);

            if (szTwainList != null)
            {
                if (szTwainList == "")
                {
                    szTwainList = Path.Combine(Config.Get("writeFolder", ""), "twainlist.txt");
                }
                System.IO.File.WriteAllText(szTwainList, ProcessSwordTask.TwainListDrivers());
                return(true);
            }

            /// Test DNS-SD...
            if (!string.IsNullOrEmpty(szTestDnssd))
            {
                if (szTestDnssd == "monitor")
                {
                    int   ii;
                    int   jj;
                    Dnssd dnssd;
                    Interpreter.CreateConsole();
                    Dnssd.DnssdDeviceInfo[] adnssddeviceinfo = null;
                    dnssd = new Dnssd(Dnssd.Reason.Monitor);
                    dnssd.MonitorStart(null, IntPtr.Zero);
                    for (ii = 0; ii < 60; ii++)
                    {
                        bool blUpdated = false;
                        Thread.Sleep(1000);
                        adnssddeviceinfo = dnssd.GetSnapshot(adnssddeviceinfo, out blUpdated);
                        if (blUpdated)
                        {
                            Console.Out.WriteLine("");
                            if ((adnssddeviceinfo == null) || (adnssddeviceinfo.Length == 0))
                            {
                                Console.Out.WriteLine("***empty***");
                            }
                            else
                            {
                                for (jj = 0; jj < adnssddeviceinfo.Length; jj++)
                                {
                                    Console.Out.WriteLine(adnssddeviceinfo[jj].GetInterface() + " " + adnssddeviceinfo[jj].GetServiceName());
                                }
                            }
                        }
                    }
                    dnssd.MonitorStop();
                    dnssd.Dispose();
                }
                else if (szTestDnssd == "register")
                {
                    Dnssd dnssd;
                    Interpreter.CreateConsole();
                    dnssd = new Dnssd(Dnssd.Reason.Register);
                    dnssd.RegisterStart("Instance", 55556, "Ty", "", "Note");
                    Thread.Sleep(60000);
                    dnssd.RegisterStop();
                    dnssd.Dispose();
                }

                // All done...
                return(true);
            }

            // Execute the specified task...
            if (File.Exists(szTaskFile))
            {
                bool             blSetAppCapabilities = false;
                ProcessSwordTask processswordtask;

                // Init stuff...
                processswordtask = new ProcessSwordTask(szImagesFolder, null, null);

                // Run our task...
                processswordtask.BatchMode(Config.Get("scanner", null), szTaskFile, false, ref blSetAppCapabilities);

                // All done...
                return(true);
            }

            // Otherwise let the user interact with us...
            TWAINWorkingGroup.Log.Info("Interactive mode...");
            return(false);
        }