BF2Statistics.MainForm.MainForm C# (CSharp) Method

MainForm() public method

Constructor. Initializes and Displays the Applications main GUI
public MainForm ( ) : System
return System
        public MainForm()
        {
            // Set form Instance
            Instance = this;

            // Create Form Controls
            InitializeComponent();

            // Make sure the basic configuration settings are setup by the user,
            // and load the BF2 server and installed mods
            if (!SetupManager.Run())
            {
                this.Load += (s, e) => this.Close();
                return;
            }

            // Fill the Mod Select Dropdown with the loaded server mods
            LoadModList();

            // Set BF2Statistics Python Install / Ranked Status
            CheckPythonStatus();

            // Load Cross Session Settings
            ParamBox.Text = Config.ClientParams;
            GlobalServerSettings.Checked = Config.UseGlobalSettings;
            ShowConsole.Checked = Config.ShowServerConsole;
            MinimizeConsole.Checked = Config.MinimizeServerConsole;
            ForceAiBots.Checked = Config.ServerForceAi;
            FileMoniter.Checked = Config.ServerFileMoniter;
            labelTotalWebRequests.Text = Config.TotalASPRequests.ToString();
            HostsLockCheckbox.Checked = Config.LockHostsFile;
            HostsLockCheckbox.CheckedChanged += HostsLockCheckbox_CheckedChanged;

            // If we dont have a client path, disable the Launch Client button
            LaunchClientBtn.Enabled = (!String.IsNullOrWhiteSpace(Config.ClientPath) && File.Exists(Path.Combine(Config.ClientPath, "bf2.exe")));

            // Register for ASP server events
            HttpServer.Started += ASPServer_OnStart;
            HttpServer.Stopped += ASPServer_OnShutdown;
            HttpServer.RequestRecieved += ASPServer_ClientConnected;
            StatsManager.SnapshotProcessed += StatsManager_SnapshotProccessed;
            StatsManager.SnapshotReceived += StatsManager_SnapshotReceived;

            // Register for Gamespy server events
            GamespyEmulator.Started += GamespyServer_OnStart;
            GamespyEmulator.Stopped += GamespyServer_OnShutdown;
            GamespyEmulator.OnClientsUpdate += GamepsyServer_OnUpdate;
            GamespyEmulator.OnServerlistUpdate += (s, e) => BeginInvoke((Action)delegate 
            { 
                ServerListSize.Text = GamespyEmulator.ServerCount.ToString(); 
            });

            // Register for BF2 Server events
            BF2Server.Started += BF2Server_Started;
            BF2Server.Exited += BF2Server_Exited;
            BF2Server.ServerPathChanged += LoadModList;

            // Add administrator title to program title bar if in Admin mode
            if (Program.IsAdministrator)
                this.Text += " (Administrator)";

            // Set some tooltips
            Tipsy.SetToolTip(GamespyStatusPic, "Gamespy server is currently offline");
            Tipsy.SetToolTip(AspStatusPic, "Asp server is currently offline");
            Tipsy.SetToolTip(labelSnapshotsProc, "Processed / Received");
            SysIcon = NotificationIcon;

            // Check for updates last
            ProgramUpdater.CheckCompleted += Updater_CheckCompleted;
            if (Program.Config.UpdateCheck)
            {
                UpdateStatusPic.Show();
                UpdateLabel.Text = "(Checking For Updates...)";
                ProgramUpdater.CheckForUpdateAsync();
            }

            // Once the form is shown, asynchronously load the redirect service
            this.Shown += async (s, e) =>
            {
                // Since we werent registered for Bf2Server events before, do this here
                if (BF2Server.IsRunning)
                    BF2Server_Started();

                // Initialize the Gamespy Redirection Service
                bool AllSystemsGo = await Redirector.Initialize();

                // Check
                CheckRedirectService();
            };
        }
MainForm