Example #1
0
        public void Run()
        {
            try
            {
                _cancellationTokenSource = new CancellationTokenSource();
                _cancellationTokenSource.Token.Register(Stop);

                var gameList = _gameList.SelectedGames;
                Log.Information("{selected} selected games out of {available} games", gameList.Count, _gameList.Games.Count);

                // Exit run method if there were no selected games
                if (!gameList.Any())
                {
                    Log.Information("No selected games available; screensaver exiting");
                    return;
                }

                // Verify that MAME can be run so we can return immediately if there are errors
                try
                {
                    _invoker.Run("-showconfig");
                }
                catch (Exception e)
                {
                    Log.Error(e, "Failure verifying MAME");
                    MessageBox.Show(@"Error running screensaver. Verify that your MAME path and and arguments are correct.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                var primaryScreen = GetPrimaryScreen();

                _screenManager.Initialise(_cancellationTokenSource);

                // Start listening for user input events
                _hotKeyManager.Initialise();

                // Start power management timer
                _powerManager.Initialise();

                // Initialise primary MAME screen
                _gamePlayManager.Initialise(primaryScreen, _cancellationTokenSource);
                _mameScreen.Initialise(primaryScreen);

                // Initialise all other screens
                var clonedScreens = new List <BlankScreen>();
                foreach (var otherScreen in Screen.AllScreens.Where(screen => !Equals(screen, primaryScreen)))
                {
                    var blankScreen = _screenFactory.Create();
                    _screenManager.RegisterScreen(blankScreen);

                    blankScreen.Initialise(otherScreen);
                    clonedScreens.Add(blankScreen);
                }

                // Clone mame screens to other screens if required
                if (_settings.CloneScreen)
                {
                    _screenCloner.StartCloning(clonedScreens);
                }

                // Run the application
                Application.EnableVisualStyles();

                var allForms = clonedScreens
                               .Concat(new List <BlankScreen> {
                    _mameScreen
                })
                               .Select(s => s.BackgroundForm)
                               .OfType <Form>()
                               .ToList();

                var context = new MultiFormApplicationContext(allForms);

                if (!_cancellationTokenSource.IsCancellationRequested)
                {
                    Application.Run(context);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to run screensaver");
                throw;
            }
        }
Example #2
0
        public void Run()
        {
            try
            {
                _cancellationTokenSource = new CancellationTokenSource();
                _cancellationTokenSource.Token.Register(Stop);

                var gameList = _gameList.SelectedGames;
                Log.Information("{selected} selected games out of {available} games", gameList.Count, _gameList.Games.Count);

                // Exit run method if there were no selected games
                if (!gameList.Any())
                {
                    Log.Information("No selected games available; screensaver exiting");
                    return;
                }

                // Start listening for user input events
                _screenManager.Initialise(_cancellationTokenSource);
                _hotKeyManager.Initialise();

                // Start power management timer
                _powerManager.Initialise();

                // Verify that MAME can be run so we can return immediately if there are errors
                _invoker.Run("-showconfig");

                // Find the best primary screen for MAME. As games are largely vertical and screens are wide, select the one with the greatest Y axis
                var bestPrimaryScreen = Screen.AllScreens.OrderByDescending(screen => screen.Bounds.Height).First();

                // Initialise primary MAME screen
                _gamePlayManager.Initialise(bestPrimaryScreen, _cancellationTokenSource);
                _mameScreen.Initialise(bestPrimaryScreen);

                // Initialise all other screens
                var clonedScreens = new List <BlankScreen>();
                foreach (var otherScreen in Screen.AllScreens.Where(screen => !Equals(screen, bestPrimaryScreen)))
                {
                    var blankScreen = _screenFactory.Create();
                    _screenManager.RegisterScreen(blankScreen);

                    blankScreen.Initialise(otherScreen);
                    clonedScreens.Add(blankScreen);
                }

                // Clone mame screens to other screens if required
                if (_settings.CloneScreen)
                {
                    _screenCloner.StartCloning(clonedScreens);
                }

                // Run the application
                Application.EnableVisualStyles();

                var allForms = clonedScreens
                               .Concat(new List <BlankScreen> {
                    _mameScreen
                })
                               .Select(s => s.BackgroundForm)
                               .OfType <Form>()
                               .ToList();

                var context = new MultiFormApplicationContext(allForms);

                if (!_cancellationTokenSource.IsCancellationRequested)
                {
                    Application.Run(context);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to run screensaver");
                throw;
            }
        }