Esempio n. 1
0
        /// <summary>Initialize SimGamePad, including the key driver for simulation.</summary>
        /// <param name="mayAutoInstallDriver">If true and the driver could not be loaded, asks the user if they'd like to install it, and automatically recovers if they do.</param>
        public void Initialize(bool mayAutoInstallDriver = true)
        {
            if (bus != null)
            {
                return; // Already initialized.
            }

            bool retryInit = false;
            do
            {
                try
                {
                    bus = new ScpBus();
                    retryInit = false;
                }
                catch (IOException)
                {
                    if (mayAutoInstallDriver)
                    {
                        var result = MessageBox.Show(NoDriverMessage, "Install", MessageBoxButtons.YesNo);
                        if (result == DialogResult.Yes)
                        {
                            ScpDriverInstaller.Install();
                            retryInit = true;
                        }
                        else
                        {
                            throw new UserDeclinedDriverException("ScpVBus");
                        }
                    }
                }
            } while (retryInit);
        }
Esempio n. 2
0
        /// <summary>Shut down and clean up any disposable resources held by SimGamePad.</summary>
        /// <remarks>
        /// This should be called before application shutdown is completed (whenever possible), as the underlying driver
        /// can be finicky. For example, you may want to call this upon Dispose of your main window/form or through other
        /// app shutdown eventing. This method can safely be called redundantly.
        /// </remarks>
        public void ShutDown()
        {
            if (bus != null)
            {
                // Automatically unplug simulated controllers that we can't drive anymore.
                for (var i = 0; i < 4; i++)
                {
                    Unplug(i);
                }

                bus.Dispose();
                bus = null;
            }
        }