예제 #1
0
        private static IDestination ShowVirtualDmd(IConfiguration config)
        {
            var dmd = new VirtualDmd {
                Left   = config.VirtualDmd.Left,
                Top    = config.VirtualDmd.Top,
                Width  = config.VirtualDmd.Width,
                Height = config.VirtualDmd.Height
            };

            dmd.Setup(config as Configuration, config is Configuration iniConfig ? iniConfig.GameName : null);
            var thread = new Thread(() => {
                // Create our context, and install it:
                SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(CurrentDispatcher));

                dmd.Dispatcher.Invoke(() => {
                    dmd.Dmd.Init();
                    dmd.Show();
                });

                // Start the Dispatcher Processing
                Run();
            });

            // On closing the window, shut down the dispatcher associated with the thread.
            // This will allow the thread to exit after the window is closed and all of
            // the events resulting from the window close have been processed.
            dmd.Closed += (s, e) => Dispatcher.FromThread(thread).BeginInvokeShutdown(DispatcherPriority.Background);

            // run the thread
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            return(dmd.VirtualControl);
        }
예제 #2
0
        /// <summary>
        /// Tuät ä nii Inschantz vom virtueuä DMD kreiärä und tuät drnah d
        /// Render-Graphä drabindä.
        /// </summary>
        private void CreateVirtualDmd()
        {
            // set up an event object to synchronize with the thread startup
            var ev = new EventWaitHandle(false, EventResetMode.AutoReset);

            // launch a thrtead for the virtual DMD window event handler
            var thread = new Thread(() => {
                // create the virtual DMD window and create the render grahps
                if (_config.VirtualDmd.Enabled)
                {
                    _virtualDmd = new VirtualDmd();
                    _virtualDmd.Setup(_config, _gameName);
                }

                SetupGraphs();

                // Create our context, and install it:
                SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher));

                // When the window closes, shut down the dispatcher
                if (_config.VirtualDmd.Enabled)
                {
                    _virtualDmd.Closed += (s, e) => _virtualDmd.Dispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
                    _virtualDmd.Dispatcher.Invoke(SetupVirtualDmd);
                }

                // we're done with the setup - let the calling thread proceed
                ev.Set();

                // Start the Dispatcher Processing
                Dispatcher.Run();
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            // wait until the virtual DMD window is fully set up, to avoid any
            // race conditions with the UI thread
            ev.WaitOne();
            ev.Dispose();
        }
예제 #3
0
        /// <summary>
        /// Sets the virtual DMD's parameters, initializes it and shows it.
        /// </summary>
        private void SetupVirtualDmd()
        {
            _virtualDmd.Setup(_config, _gameName);

            if (_config.VirtualDmd.UseRegistryPosition)
            {
                try {
                    var regPath = @"Software\Freeware\Visual PinMame\" + (_gameName.Length > 0 ? _gameName : "default");
                    var key     = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32);
                    key = key.OpenSubKey(regPath);

                    if (key == null)
                    {
                        // couldn't find the value in the 32-bit view so grab the 64-bit view
                        key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
                        key = key.OpenSubKey(regPath);
                    }

                    if (key != null)
                    {
                        var values = key.GetValueNames();
                        if (!values.Contains("dmd_pos_x") && values.Contains("dmd_pos_y") && values.Contains("dmd_width") && values.Contains("dmd_height"))
                        {
                            Logger.Warn("Not all values were found at HKEY_CURRENT_USER\\{0}. Trying default.", regPath);
                            key?.Dispose();
                            regPath = @"Software\Freeware\Visual PinMame\default";
                            key     = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32);
                            key     = key.OpenSubKey(regPath);
                        }
                    }
                    // still null?
                    if (key != null)
                    {
                        var values = key.GetValueNames();
                        if (values.Contains("dmd_pos_x") && values.Contains("dmd_pos_y") && values.Contains("dmd_width") && values.Contains("dmd_height"))
                        {
                            SetVirtualDmdDefaultPosition(
                                Convert.ToInt64(key.GetValue("dmd_pos_x").ToString()),
                                Convert.ToInt64(key.GetValue("dmd_pos_y").ToString()),
                                Convert.ToInt64(key.GetValue("dmd_width").ToString()),
                                Convert.ToInt64(key.GetValue("dmd_height").ToString())
                                );
                        }
                        else
                        {
                            Logger.Warn("Ignoring VPM registry for DMD position because not all values were found at HKEY_CURRENT_USER\\{0}. Found keys: [ {1} ]", regPath, string.Join(", ", values));
                            SetVirtualDmdDefaultPosition();
                        }
                    }
                    else
                    {
                        Logger.Warn("Ignoring VPM registry for DMD position because key was not found at HKEY_CURRENT_USER\\{0}", regPath);
                        SetVirtualDmdDefaultPosition();
                    }
                    key?.Dispose();
                } catch (Exception ex) {
                    Logger.Warn(ex, "Could not retrieve registry values for DMD position for game \"" + _gameName + "\".");
                    SetVirtualDmdDefaultPosition();
                }
            }
            else
            {
                Logger.Debug("DMD position: No registry because it's ignored.");
                SetVirtualDmdDefaultPosition();
            }

            _virtualDmd.Dmd.Init();
            _virtualDmd.Show();
        }