Пример #1
0
        /// <summary>
        /// Called by either the launcher thread when the process is closed, or by the context menu attached to the system tray icon when searching for the process is cancelled.
        /// </summary>
        public void LaunchedProcessClosed()
        {
            Procedure action = () =>
            {
                try
                {
                    FileOperationList.Execute();
                }
                catch (Exception)
                {
                    // suppress cleanup errors
                }

                // If the system tray still has a context menu, then connecting must have been cancelled.
                // Don't apply the "close when finished" functionality in this case.
                if (!SystemTrayIcon.HasContextMenuStrip && Config.Settings.ServerBrowserCloseWhenFinished)
                {
                    SystemTrayIcon.Hide();
                    closeProgram = true;
                    Close();
                }
                else
                {
                    RestoreFromTray();
                    canOpenServer = true;
                }
            };

            if (Thread.CurrentThread != Dispatcher.Thread)
            {
                Dispatcher.Invoke(DispatcherPriority.Normal, action);
            }
            else
            {
                action();
            }
        }
Пример #2
0
        private void ConnectToServer(Server server)
        {
            if (server == null)
            {
                return;
            }

            if (server.State != Server.StateEnum.Succeeded)
            {
                return;
            }

            launcher = LauncherFactory.CreateLauncher(server.SourceEngine);
            launcher.JoiningServer        = true;
            launcher.ServerSourceEngine   = server.SourceEngine;
            launcher.ServerAddress        = server.Address;
            launcher.ServerGameFolderName = server.GameFolder;
            launcher.ServerMapName        = server.Map;
            launcher.Interface            = (ILauncher)this;

            try
            {
                launcher.Verify();
            }
            catch (Launcher.AbortLaunchException)
            {
                return;
            }
            catch (ApplicationException ex)
            {
                Common.Message(this, null, ex);
                return;
            }
            catch (Exception ex)
            {
                Common.Message(this, null, ex, MessageWindow.Flags.Error);
                return;
            }

            canOpenServer = false;
            MinimiseToTray();

            // launch the game
            try
            {
                launcher.Run();
            }
            catch (Exception ex)
            {
                RestoreFromTray();
                FileOperationList.Execute();
                canOpenServer = true;
                Common.Message(this, "Error launching game.", ex, MessageWindow.Flags.Error);
                return;
            }

            SystemTrayIcon.Text = "Looking for game process...";

            // enable the tray context menu
            TrayContextMenuEnable(true);
        }