コード例 #1
0
        private void GoButton_Click(object sender, RoutedEventArgs e)
        {
            ViewWindow v = null;

            Hide();
            Properties.Settings.Default.Port                     = _vm.Ports.SelectedItem;
            Properties.Settings.Default.Port2                    = _vm.Ports2.SelectedItem;
            Properties.Settings.Default.Source                   = _vm.Sources.GetSelectedId();
            Properties.Settings.Default.Skin                     = _vm.Skins.GetSelectedId();
            Properties.Settings.Default.Delay                    = _vm.DelayInMilliseconds;
            Properties.Settings.Default.Background               = _vm.Backgrounds.GetSelectedId();
            Properties.Settings.Default.Hostname                 = _vm.Hostname;
            Properties.Settings.Default.StaticViewerWindowName   = _vm.StaticViewerWindowName;
            Properties.Settings.Default.LegacyKeybindingBehavior = _vm.LegacyKeybindingBehavior;
            Properties.Settings.Default.FilterCOMPorts           = _vm.FilterCOMPorts;
            Properties.Settings.Default.DontSavePassword         = _vm.DontSavePassword;
            Properties.Settings.Default.UseLagFix                = _vm.UseLagFix;
            if (_vm.Sources.SelectedItem == InputSource.MISTER)
            {
                Properties.Settings.Default.MisterUsername = _vm.Username;
                Properties.Settings.Default.MisterPassword = _vm.DontSavePassword ? "" : txtPassword.Password;
            }
            else
            {
                Properties.Settings.Default.BeagleboneUsername = _vm.Username;
                Properties.Settings.Default.BeaglebonePassword = _vm.DontSavePassword ? "" : txtPassword.Password;
            }
            Properties.Settings.Default.Save();

            try
            {
                IControllerReader reader;
                if (_vm.Sources.SelectedItem == InputSource.PAD)
                {
                    reader = _vm.Sources.SelectedItem.BuildReader(_vm.XIAndGamepad.SelectedItem.ToString(CultureInfo.CurrentCulture), false);
                }
                else if (_vm.Sources.SelectedItem == InputSource.PC360)
                {
                    reader = _vm.Sources.SelectedItem.BuildReader(_vm.XIAndGamepad.SelectedItem.ToString(CultureInfo.CurrentCulture), false);
                }
                else if (_vm.Sources.SelectedItem == InputSource.PCKEYBOARD)
                {
                    reader = _vm.Sources.SelectedItem.BuildReader3;
                }
                else if (_vm.Sources.SelectedItem == InputSource.XBOX || _vm.Sources.SelectedItem == InputSource.PSCLASSIC ||
                         _vm.Sources.SelectedItem == InputSource.SWITCH || _vm.Sources.SelectedItem == InputSource.XBOX360 ||
                         _vm.Sources.SelectedItem == InputSource.GENMINI || _vm.Sources.SelectedItem == InputSource.C64MINI ||
                         _vm.Sources.SelectedItem == InputSource.NEOGEOMINI || _vm.Sources.SelectedItem == InputSource.PS3 ||
                         _vm.Sources.SelectedItem == InputSource.PS4 || _vm.Sources.SelectedItem == InputSource.TG16MINI ||
                         _vm.Sources.SelectedItem == InputSource.ATARIVCS || _vm.Sources.SelectedItem == InputSource.EVERCADE)
                {
                    reader = _vm.Sources.SelectedItem.BuildReader4(txtHostname.Text, txtUsername.Text, txtPassword.Password);
                }
                else if (_vm.Sources.SelectedItem == InputSource.MISTER)
                {
                    reader = _vm.Sources.SelectedItem.BuildReader5(txtHostname.Text, txtUsername.Text, txtPassword.Password, _vm.MisterGamepad.SelectedItem.ToString(CultureInfo.CurrentCulture));
                }
                else if (_vm.Sources.SelectedItem == InputSource.PADDLES || _vm.Sources.SelectedItem == InputSource.CD32 ||
                         _vm.Sources.SelectedItem == InputSource.ATARI5200 || _vm.Sources.SelectedItem == InputSource.COLECOVISION ||
                         _vm.Sources.SelectedItem == InputSource.GAMECUBE)
                {
                    if (_vm.Ports.SelectedItem == _vm.Ports2.SelectedItem)
                    {
                        throw new ConfigParseException(_resources.GetString("Port1And2CannotBeTheSame", CultureInfo.CurrentUICulture));
                    }

                    reader = _vm.Sources.SelectedItem.BuildReader2(_vm.Ports.SelectedItem, _vm.Ports2.SelectedItem, _vm.UseLagFix);
                }
                //else if (_vm.Sources.SelectedItem == InputSource.XBOX)
                //{
                //    reader = _vm.Sources.SelectedItem.BuildReader(_vm.XIAndGamepad.SelectedItem.ToString());
                //}
                //else if (_vm.Sources.SelectedItem == InputSource.WII)
                //{
                //    reader = _vm.Sources.SelectedItem.BuildReader(_vm.XIAndGamepad.SelectedItem.ToString());
                //}
                else
                {
                    reader = _vm.Sources.SelectedItem.BuildReader(_vm.Ports.SelectedItem, _vm.UseLagFix);
                }
                if (_vm.DelayInMilliseconds > 0)
                {
#pragma warning disable CA2000 // Dispose objects before losing scope
                    reader = new DelayedControllerReader(reader, _vm.DelayInMilliseconds, _vm.LegacyKeybindingBehavior);
#pragma warning restore CA2000 // Dispose objects before losing scope
                }

                if (_vm.Sources.SelectedItem == InputSource.PRINTER)
                {
                    _ = new GameBoyPrinterEmulatorWindow(reader).ShowDialog();
                }
                else
                {
                    _portListUpdateTimer.Stop();
                    v = new ViewWindow(_vm.Skins.SelectedItem,
                                       _vm.Backgrounds.SelectedItem,
                                       reader, _vm.StaticViewerWindowName);
                    v.ShowDialog();
                }
            }
            catch (ConfigParseException ex)
            {
                _ = MessageBox.Show(ex.Message, _resources.GetString("RetroSpy", CultureInfo.CurrentUICulture), MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (System.Net.Sockets.SocketException)
            {
                _ = MessageBox.Show(string.Format(new CultureInfo("en-US"), "Cannot connect to {0}.", txtHostname.Text), _resources.GetString("RetroSpy", CultureInfo.CurrentUICulture), MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (UnauthorizedAccessException ex)
            {
                _ = MessageBox.Show(ex.Message, _resources.GetString("RetroSpy", CultureInfo.CurrentUICulture), MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (SSHMonitorDisconnectException)
            {
                v?.Close();
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                _ = MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, _resources.GetString("RetroSpy", CultureInfo.CurrentUICulture), MessageBoxButton.OK, MessageBoxImage.Error);
                v?.Close();
            }

            _portListUpdateTimer.Start();
            Show();
        }
コード例 #2
0
 public static void Register(ViewWindow window)
 {
     new WindowAspectRatio(window);
 }