Exemplo n.º 1
0
        private void OnCreateOrOKButtonClicked(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this.game.GameTitle))
            {
                Controls.MessageBox.Show(
                    "Can not save the game, because it has no title!",
                    ApplicationInfo.AppName,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);

                return;
            }

            if (this.creatingNewGame)
            {
                this.game.UpdateStatus();

                if (this.game.Status == Enums.GameStatus.OK)
                {
                    GameDataManager.Games.Add(this.game);
                    this.Close();
                }
                else
                {
                    if (this.game.GamePath == null)
                    {
                        Controls.MessageBox.Show(
                            "Can not create the game, because no exe file is choosen!",
                            ApplicationInfo.AppName,
                            MessageBoxButton.OK,
                            MessageBoxImage.Error);

                        return;
                    }

                    var errorMessage = new Converters.GameStatusToStringConverter().Convert(this.game.Status, typeof(string), null, null);
                    Controls.MessageBox.Show(
                        "Can not create the game, because of the following error: " + errorMessage,
                        ApplicationInfo.AppName,
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
            else
            {
                // No need to save anything, because the binding done this already
                this.game.UpdateStatus();
                this.Close();
            }
        }
Exemplo n.º 2
0
        public void TryStart()
        {
            var splitter = Helpers.SplitterHelper.TryFindSplitter();

            if (splitter == null)
            {
                throw new Exception("Unable to find the splitter");
            }

            if (splitter.EmulationManager == null)
            {
                throw new Exception("Splitter's Emulation manager is null");
            }

            if (splitter.EmulationManager.IsEmulationStarted)
            {
                throw new Exception("You must stop emulation, before starting a game!");
            }

            if (!File.Exists(this.gamePath))
            {
                throw new Exception("Can not run a game with non exsisting exe file!");
            }

            this.UpdateStatus();

            if (this.status != GameStatus.OK)
            {
                var errorMessage = new Converters.GameStatusToStringConverter().Convert(this.status, typeof(string), null, null);
                throw new Exception("Can not run the game: " + errorMessage);
            }

            var process = Process.Start(this.gamePath);

            process.EnableRaisingEvents = true;
            process.Exited += this.OnProcessExited;

            var slots = new ObservableCollection <SplitterCore.Emulation.IEmulationSlot>();

            foreach (var slotData in this.SlotsData)
            {
                var keyboard = SplitterCore.Input.Keyboard.None;
                var mouse    = SplitterCore.Input.Mouse.None;

                if (slotData.KeyboardHardwareId != string.Empty)
                {
                    keyboard = splitter.InputManager.Keyboards.Find(x => x.HardwareID == slotData.KeyboardHardwareId);
                }

                if (slotData.MouseHardwareId != string.Empty)
                {
                    mouse = splitter.InputManager.Mice.Find(x => x.HardwareID == slotData.MouseHardwareId);
                }

                var preset = PresetDataManager.CurrentPresets.First(x => x.Name == slotData.PresetName);
                slots.Add(new EmulationSlot(slotData.SlotNumber, new XboxGamepad(slotData.GamepadUserIndex), keyboard, mouse, preset));
            }

            var mainWindow = App.Current.MainWindow as MainWindow;

            mainWindow.SlotsCount = slots.Count;
            splitter.EmulationManager.Slots.Clear();
            foreach (var slot in slots)
            {
                splitter.EmulationManager.Slots.Add(slot);
            }

            splitter.EmulationManager.Start(true);
        }
Exemplo n.º 3
0
        public void TryStart()
        {
            var splitter = Helpers.SplitterHelper.TryFindSplitter();

            if (splitter == null)
            {
                throw new Exception("Unable to find the splitter");
            }

            if (splitter.EmulationManager == null)
            {
                throw new Exception("Splitter's Emulation manager is null");
            }

            if (splitter.EmulationManager.IsEmulationStarted)
            {
                throw new Exception("You must stop emulation, before starting a game!");
            }

            if (!File.Exists(this.gamePath))
            {
                throw new Exception("Can not run a game with non exsisting exe file!");
            }

            this.UpdateStatus();

            if (this.status != GameStatus.OK)
            {
                var errorMessage = new Converters.GameStatusToStringConverter().Convert(this.status, typeof(string), null, null);
                throw new Exception("Can not run the game: " + errorMessage);
            }

            var slots = new ObservableCollection <SplitterCore.Emulation.IEmulationSlot>();

            foreach (var slotData in this.SlotsData)
            {
                var keyboard = SplitterCore.Input.Keyboard.None;
                var mouse    = SplitterCore.Input.Mouse.None;

                if (slotData.KeyboardHardwareId != string.Empty)
                {
                    keyboard = splitter.InputManager.Keyboards.Find(x => x.HardwareID == slotData.KeyboardHardwareId);
                }

                if (slotData.MouseHardwareId != string.Empty)
                {
                    mouse = splitter.InputManager.Mice.Find(x => x.HardwareID == slotData.MouseHardwareId);
                }

                var preset = PresetDataManager.CurrentPresets.First(x => x.Name == slotData.PresetName);
                slots.Add(new EmulationSlot(slotData.SlotNumber, new XboxGamepad(slotData.GamepadUserIndex), keyboard, mouse, preset));
            }

            var mainWindow = App.Current.MainWindow as MainWindow;

            mainWindow.SlotsCount = slots.Count;
            splitter.EmulationManager.Slots.Clear();
            foreach (var slot in slots)
            {
                splitter.EmulationManager.Slots.Add(slot);
            }

            splitter.ShouldBlockKeyboards = this.blockKeyboards;
            splitter.ShouldBlockMice      = this.blockMice;
            splitter.EmulationManager.Start(true);

            var result = Controls.MessageBox.Show(
                "Your game settings are applied.\r\n\r\nWould you like to run the game now?",
                "Run a Keyboard Splitter Game?",
                MessageBoxButton.YesNo,
                MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                /*
                 * var process = Process.Start(this.gamePath);
                 * process.EnableRaisingEvents = true;
                 * process.Exited += this.OnProcessExited;
                 */
                var now = DateTime.Now;
                Task.Factory.StartNew(() =>
                {
                    var startInfo              = new ProcessStartInfo();
                    startInfo.FileName         = this.gamePath;
                    startInfo.WorkingDirectory = Path.GetDirectoryName(this.gamePath);
                    if (this.gameArguments != null)
                    {
                        startInfo.Arguments = this.gameArguments;
                    }

                    startInfo.UseShellExecute = true;
                    var process = Process.Start(startInfo);
                    process.WaitForExit();
                }).ContinueWith((task) =>
                {
                    if ((DateTime.Now - now).TotalSeconds > 3)
                    {
                        this.OnProcessExited();
                    }

                    return(task);
                });
            }
        }