From cd5e8c99fe1a726bce4a7ec61433fac9b96be444 Mon Sep 17 00:00:00 2001 From: hbeham Date: Fri, 13 Nov 2015 15:50:56 +0100 Subject: [PATCH] - added command line parameter /background to start extraQL minimized (used by SteamServerBrowser when auto-starting extraQL) - added option to start / quit Steam Server Browser - fixed the "start minimized" option - removed option "allow other computers to use this extraQL server" (relic from old hook.js using a public extraQL master server) - removed option "install scripts to /baseq3/js" (not needed) - removed https left-overs --- readme.md | 8 +++ source/Config.cs | 30 +--------- source/MainForm.Designer.cs | 98 ++++++++++++++++----------------- source/MainForm.cs | 92 +++++++++++++++++++++++++------ source/Program.cs | 10 ++-- source/Win32.cs | 15 ++++- source/extraQL.csproj | 2 +- source/{DLL => }/steam_api.dll | Bin 8 files changed, 156 insertions(+), 99 deletions(-) rename source/{DLL => }/steam_api.dll (100%) diff --git a/readme.md b/readme.md index d7806d7..a571fd7 100644 --- a/readme.md +++ b/readme.md @@ -14,6 +14,14 @@ c:\program files (x86)\Steam\SteamApps\workshop\content\282440\539252269 Changelog ========= +Version 2.7 +--- +- added command line parameter /background to start extraQL minimized (used by SteamServerBrowser when auto-starting extraQL) +- added option to start / quit Steam Server Browser +- fixed the "start minimized" option +- removed option "allow other computers to use this extraQL server" (relic from old hook.js using a public extraQL master server) +- removed option "install scripts to /baseq3/js" (not needed) + Version 2.6 --- - using long living steam API session to prevent massive FPS drops after running the application for a while diff --git a/source/Config.cs b/source/Config.cs index c4debea..0c9710b 100644 --- a/source/Config.cs +++ b/source/Config.cs @@ -3,7 +3,6 @@ using System.IO; using System.Text; using System.Windows.Forms; -using Microsoft.Win32; namespace ExtraQL { @@ -27,15 +26,11 @@ public void LoadSettings() { this.settings.Clear(); this.settings["advanced"] = "0"; - this.settings["launcherExe"] = GetDefaultLauncherPath(); - this.settings["bindToAll"] = "0"; this.settings["systemTray"] = "0"; this.settings["startMinimized"] = "0"; - this.settings["checkUpdates"] = "1"; this.settings["autostart"] = "0"; this.settings["log"] = "0"; this.settings["followLog"] = "0"; - this.settings["https"] = "0"; this.settings["logAllRequests"] = "0"; this.settings["autoquit"] = "0"; this.settings["quakelive_steam.exe"] = ""; @@ -43,6 +38,9 @@ public void LoadSettings() this.settings["nickSteam"] = ""; this.settings["skipWorkshopNotice"] = "0"; this.settings["steamAppId"] = "349090"; + this.settings["startServerBrowser"] = "0"; + this.settings["closeServerBrowser"] = "0"; + var configFile = this.ConfigFile; if (File.Exists(configFile)) @@ -102,27 +100,5 @@ public void SaveSettings() #endregion - #region GetDefaultLauncherPath() - private string GetDefaultLauncherPath() - { - try - { - string path = Registry.GetValue(@"HKEY_CURRENT_USER\Software\id Software\Quake Live", null, null) as string; - if (path != null && File.Exists(path += "\\Launcher.exe")) - return path; - } - catch { } // fails on Mono - - try - { - string path = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Quake Live", "UninstallString", null) as string; - if (path != null && File.Exists(path = path.Replace("uninstall.exe", "Launcher.exe"))) - return path; - } - catch { } - return Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Quake Live\\Launcher.exe"; - } - #endregion - } } diff --git a/source/MainForm.Designer.cs b/source/MainForm.Designer.cs index 402e5d8..63ba590 100644 --- a/source/MainForm.Designer.cs +++ b/source/MainForm.Designer.cs @@ -51,7 +51,6 @@ private void InitializeComponent() this.cbAutostart = new System.Windows.Forms.CheckBox(); this.cbStartMinimized = new System.Windows.Forms.CheckBox(); this.cbSystemTray = new System.Windows.Forms.CheckBox(); - this.cbBindToAll = new System.Windows.Forms.CheckBox(); this.panelTop = new System.Windows.Forms.Panel(); this.cbLog = new System.Windows.Forms.CheckBox(); this.cbAdvanced = new System.Windows.Forms.CheckBox(); @@ -75,7 +74,8 @@ private void InitializeComponent() this.cbFollowLog = new System.Windows.Forms.CheckBox(); this.txtLog = new System.Windows.Forms.TextBox(); this.autoQuitTimer = new System.Windows.Forms.Timer(this.components); - this.cbInstallInBaseq3 = new System.Windows.Forms.CheckBox(); + this.cbStartServerBrowser = new System.Windows.Forms.CheckBox(); + this.cbCloseServerBrowser = new System.Windows.Forms.CheckBox(); this.panelAdvanced.SuspendLayout(); this.grpAdvanced.SuspendLayout(); this.panelTop.SuspendLayout(); @@ -99,9 +99,9 @@ private void InitializeComponent() this.panelAdvanced.BackColor = System.Drawing.Color.Transparent; this.panelAdvanced.Controls.Add(this.grpAdvanced); this.panelAdvanced.Dock = System.Windows.Forms.DockStyle.Fill; - this.panelAdvanced.Location = new System.Drawing.Point(0, 143); + this.panelAdvanced.Location = new System.Drawing.Point(0, 149); this.panelAdvanced.Name = "panelAdvanced"; - this.panelAdvanced.Size = new System.Drawing.Size(429, 234); + this.panelAdvanced.Size = new System.Drawing.Size(429, 230); this.panelAdvanced.TabIndex = 1; // // grpAdvanced @@ -109,25 +109,25 @@ private void InitializeComponent() this.grpAdvanced.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.grpAdvanced.Controls.Add(this.cbInstallInBaseq3); this.grpAdvanced.Controls.Add(this.btnNickEnd); + this.grpAdvanced.Controls.Add(this.cbCloseServerBrowser); + this.grpAdvanced.Controls.Add(this.cbStartServerBrowser); this.grpAdvanced.Controls.Add(this.btnNickStart); - this.grpAdvanced.Controls.Add(this.txtNickEnd); - this.grpAdvanced.Controls.Add(this.label2); - this.grpAdvanced.Controls.Add(this.txtNickStart); - this.grpAdvanced.Controls.Add(this.label1); this.grpAdvanced.Controls.Add(this.txtSteamExe); this.grpAdvanced.Controls.Add(this.lblSteamExe); + this.grpAdvanced.Controls.Add(this.txtNickEnd); this.grpAdvanced.Controls.Add(this.btnSteamExe); this.grpAdvanced.Controls.Add(this.cbAutoQuit); + this.grpAdvanced.Controls.Add(this.label2); this.grpAdvanced.Controls.Add(this.cbAutostart); this.grpAdvanced.Controls.Add(this.cbStartMinimized); + this.grpAdvanced.Controls.Add(this.txtNickStart); this.grpAdvanced.Controls.Add(this.cbSystemTray); - this.grpAdvanced.Controls.Add(this.cbBindToAll); + this.grpAdvanced.Controls.Add(this.label1); this.grpAdvanced.ForeColor = System.Drawing.Color.White; this.grpAdvanced.Location = new System.Drawing.Point(12, 7); this.grpAdvanced.Name = "grpAdvanced"; - this.grpAdvanced.Size = new System.Drawing.Size(405, 215); + this.grpAdvanced.Size = new System.Drawing.Size(405, 211); this.grpAdvanced.TabIndex = 0; this.grpAdvanced.TabStop = false; this.grpAdvanced.Text = "Options"; @@ -137,7 +137,7 @@ private void InitializeComponent() this.btnNickEnd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnNickEnd.BackColor = System.Drawing.SystemColors.ButtonFace; this.btnNickEnd.ForeColor = System.Drawing.Color.Black; - this.btnNickEnd.Location = new System.Drawing.Point(371, 85); + this.btnNickEnd.Location = new System.Drawing.Point(371, 90); this.btnNickEnd.Name = "btnNickEnd"; this.btnNickEnd.Size = new System.Drawing.Size(23, 21); this.btnNickEnd.TabIndex = 7; @@ -151,7 +151,7 @@ private void InitializeComponent() this.btnNickStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnNickStart.BackColor = System.Drawing.SystemColors.ButtonFace; this.btnNickStart.ForeColor = System.Drawing.Color.Black; - this.btnNickStart.Location = new System.Drawing.Point(171, 85); + this.btnNickStart.Location = new System.Drawing.Point(161, 90); this.btnNickStart.Name = "btnNickStart"; this.btnNickStart.Size = new System.Drawing.Size(23, 21); this.btnNickStart.TabIndex = 4; @@ -165,7 +165,7 @@ private void InitializeComponent() this.txtNickEnd.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txtNickEnd.ForeColor = System.Drawing.Color.Black; - this.txtNickEnd.Location = new System.Drawing.Point(209, 85); + this.txtNickEnd.Location = new System.Drawing.Point(209, 90); this.txtNickEnd.Name = "txtNickEnd"; this.txtNickEnd.Size = new System.Drawing.Size(163, 21); this.txtNickEnd.TabIndex = 6; @@ -173,7 +173,7 @@ private void InitializeComponent() // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(209, 69); + this.label2.Location = new System.Drawing.Point(206, 74); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(181, 13); this.label2.TabIndex = 5; @@ -184,7 +184,7 @@ private void InitializeComponent() this.txtNickStart.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txtNickStart.ForeColor = System.Drawing.Color.Black; - this.txtNickStart.Location = new System.Drawing.Point(10, 85); + this.txtNickStart.Location = new System.Drawing.Point(10, 90); this.txtNickStart.Name = "txtNickStart"; this.txtNickStart.Size = new System.Drawing.Size(163, 21); this.txtNickStart.TabIndex = 3; @@ -192,7 +192,7 @@ private void InitializeComponent() // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(10, 69); + this.label1.Location = new System.Drawing.Point(7, 74); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(186, 13); this.label1.TabIndex = 2; @@ -211,7 +211,7 @@ private void InitializeComponent() // lblSteamExe // this.lblSteamExe.AutoSize = true; - this.lblSteamExe.Location = new System.Drawing.Point(10, 19); + this.lblSteamExe.Location = new System.Drawing.Point(7, 21); this.lblSteamExe.Name = "lblSteamExe"; this.lblSteamExe.Size = new System.Drawing.Size(317, 13); this.lblSteamExe.TabIndex = 0; @@ -234,7 +234,7 @@ private void InitializeComponent() // cbAutoQuit // this.cbAutoQuit.AutoSize = true; - this.cbAutoQuit.Location = new System.Drawing.Point(209, 142); + this.cbAutoQuit.Location = new System.Drawing.Point(209, 153); this.cbAutoQuit.Name = "cbAutoQuit"; this.cbAutoQuit.Size = new System.Drawing.Size(159, 17); this.cbAutoQuit.TabIndex = 11; @@ -244,7 +244,7 @@ private void InitializeComponent() // cbAutostart // this.cbAutostart.AutoSize = true; - this.cbAutostart.Location = new System.Drawing.Point(10, 142); + this.cbAutostart.Location = new System.Drawing.Point(10, 153); this.cbAutostart.Name = "cbAutostart"; this.cbAutostart.Size = new System.Drawing.Size(128, 17); this.cbAutostart.TabIndex = 10; @@ -254,7 +254,7 @@ private void InitializeComponent() // cbStartMinimized // this.cbStartMinimized.AutoSize = true; - this.cbStartMinimized.Location = new System.Drawing.Point(209, 119); + this.cbStartMinimized.Location = new System.Drawing.Point(209, 130); this.cbStartMinimized.Name = "cbStartMinimized"; this.cbStartMinimized.Size = new System.Drawing.Size(98, 17); this.cbStartMinimized.TabIndex = 9; @@ -264,7 +264,7 @@ private void InitializeComponent() // cbSystemTray // this.cbSystemTray.AutoSize = true; - this.cbSystemTray.Location = new System.Drawing.Point(10, 119); + this.cbSystemTray.Location = new System.Drawing.Point(10, 130); this.cbSystemTray.Name = "cbSystemTray"; this.cbSystemTray.Size = new System.Drawing.Size(126, 17); this.cbSystemTray.TabIndex = 8; @@ -272,17 +272,6 @@ private void InitializeComponent() this.cbSystemTray.UseVisualStyleBackColor = true; this.cbSystemTray.CheckedChanged += new System.EventHandler(this.cbSystemTray_CheckedChanged); // - // cbBindToAll - // - this.cbBindToAll.AutoSize = true; - this.cbBindToAll.Location = new System.Drawing.Point(10, 165); - this.cbBindToAll.Name = "cbBindToAll"; - this.cbBindToAll.Size = new System.Drawing.Size(305, 17); - this.cbBindToAll.TabIndex = 12; - this.cbBindToAll.Text = "Allow other computers to access this extraQL HTTP server"; - this.cbBindToAll.UseVisualStyleBackColor = true; - this.cbBindToAll.CheckedChanged += new System.EventHandler(this.cbBindAll_CheckedChanged); - // // panelTop // this.panelTop.BackColor = System.Drawing.Color.Transparent; @@ -299,7 +288,7 @@ private void InitializeComponent() this.panelTop.Dock = System.Windows.Forms.DockStyle.Top; this.panelTop.Location = new System.Drawing.Point(0, 0); this.panelTop.Name = "panelTop"; - this.panelTop.Size = new System.Drawing.Size(429, 143); + this.panelTop.Size = new System.Drawing.Size(429, 149); this.panelTop.TabIndex = 0; // // cbLog @@ -352,7 +341,7 @@ private void InitializeComponent() this.btnStartQL.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnStartQL.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold); this.btnStartQL.ForeColor = System.Drawing.Color.Gold; - this.btnStartQL.Location = new System.Drawing.Point(11, 89); + this.btnStartQL.Location = new System.Drawing.Point(22, 89); this.btnStartQL.Name = "btnStartQL"; this.btnStartQL.Size = new System.Drawing.Size(135, 37); this.btnStartQL.TabIndex = 2; @@ -476,7 +465,7 @@ private void InitializeComponent() this.panelLog.Dock = System.Windows.Forms.DockStyle.Right; this.panelLog.Location = new System.Drawing.Point(429, 0); this.panelLog.Name = "panelLog"; - this.panelLog.Size = new System.Drawing.Size(495, 377); + this.panelLog.Size = new System.Drawing.Size(495, 379); this.panelLog.TabIndex = 2; // // grpLog @@ -491,7 +480,7 @@ private void InitializeComponent() this.grpLog.ForeColor = System.Drawing.Color.White; this.grpLog.Location = new System.Drawing.Point(12, 7); this.grpLog.Name = "grpLog"; - this.grpLog.Size = new System.Drawing.Size(471, 358); + this.grpLog.Size = new System.Drawing.Size(471, 360); this.grpLog.TabIndex = 0; this.grpLog.TabStop = false; this.grpLog.Text = "Log"; @@ -540,7 +529,7 @@ private void InitializeComponent() this.txtLog.Name = "txtLog"; this.txtLog.ReadOnly = true; this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.txtLog.Size = new System.Drawing.Size(453, 300); + this.txtLog.Size = new System.Drawing.Size(453, 302); this.txtLog.TabIndex = 3; // // autoQuitTimer @@ -549,22 +538,33 @@ private void InitializeComponent() this.autoQuitTimer.Interval = 2000; this.autoQuitTimer.Tick += new System.EventHandler(this.autoQuitTimer_Tick); // - // cbInstallInBaseq3 + // cbStartServerBrowser + // + this.cbStartServerBrowser.AutoSize = true; + this.cbStartServerBrowser.Location = new System.Drawing.Point(10, 176); + this.cbStartServerBrowser.Name = "cbStartServerBrowser"; + this.cbStartServerBrowser.Size = new System.Drawing.Size(176, 17); + this.cbStartServerBrowser.TabIndex = 12; + this.cbStartServerBrowser.Text = "Autostart SteamServerBrowser"; + this.cbStartServerBrowser.UseVisualStyleBackColor = true; + this.cbStartServerBrowser.CheckedChanged += new System.EventHandler(this.cbStartServerBrowser_CheckedChanged); + // + // cbCloseServerBrowser // - this.cbInstallInBaseq3.AutoSize = true; - this.cbInstallInBaseq3.Location = new System.Drawing.Point(10, 188); - this.cbInstallInBaseq3.Name = "cbInstallInBaseq3"; - this.cbInstallInBaseq3.Size = new System.Drawing.Size(342, 17); - this.cbInstallInBaseq3.TabIndex = 13; - this.cbInstallInBaseq3.Text = "Install scripts in /baseq3/js instead of workshop folder"; - this.cbInstallInBaseq3.UseVisualStyleBackColor = true; + this.cbCloseServerBrowser.AutoSize = true; + this.cbCloseServerBrowser.Location = new System.Drawing.Point(209, 176); + this.cbCloseServerBrowser.Name = "cbCloseServerBrowser"; + this.cbCloseServerBrowser.Size = new System.Drawing.Size(148, 17); + this.cbCloseServerBrowser.TabIndex = 13; + this.cbCloseServerBrowser.Text = "Auto-quit Server Browser"; + this.cbCloseServerBrowser.UseVisualStyleBackColor = true; // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); - this.ClientSize = new System.Drawing.Size(924, 377); + this.ClientSize = new System.Drawing.Size(924, 379); this.ControlBox = false; this.Controls.Add(this.panelAdvanced); this.Controls.Add(this.panelTop); @@ -608,7 +608,6 @@ private void InitializeComponent() private Label lblExtra; private PictureBox picClose; private PictureBox picMinimize; - private CheckBox cbBindToAll; private CheckBox cbSystemTray; private NotifyIcon trayIcon; private ContextMenuStrip mnuTrayIcon; @@ -636,7 +635,8 @@ private void InitializeComponent() private Label label1; private Button btnNickEnd; private Button btnNickStart; - private CheckBox cbInstallInBaseq3; + private CheckBox cbCloseServerBrowser; + private CheckBox cbStartServerBrowser; } } diff --git a/source/MainForm.cs b/source/MainForm.cs index 6b4f37a..202e7ad 100644 --- a/source/MainForm.cs +++ b/source/MainForm.cs @@ -11,7 +11,7 @@ namespace ExtraQL { public partial class MainForm : Form { - public const string Version = "2.6"; + public const string Version = "2.7"; private readonly Config config; private readonly HttpServer server; @@ -20,6 +20,7 @@ public partial class MainForm : Form private bool qlStarted; private bool skipWorkshopNotice; private int steamAppId; + private bool suppressInitialShow; #region ctor() public MainForm(Config config) @@ -33,9 +34,12 @@ public MainForm(Config config) this.lblExtra.Parent = this.picLogo; this.lblVersion.Parent = this.picLogo; this.trayIcon.Icon = this.Icon; + this.suppressInitialShow = Environment.CommandLine.Contains(Program.BackgroundSwitch) || this.cbStartMinimized.Checked; + if (this.suppressInitialShow) + this.WindowState = FormWindowState.Minimized; this.server = new HttpServer(null); - this.server.BindToAllInterfaces = this.cbBindToAll.Checked; + this.server.BindToAllInterfaces = false; this.server.LogAllRequests = this.cbLogAllRequests.Checked; this.scriptRepository = new ScriptRepository(config.AppBaseDir); @@ -48,6 +52,21 @@ public MainForm(Config config) } #endregion + #region WndProc() + protected override void WndProc(ref Message m) + { + // This hack is needed because none of the documented ways to start an application window in minimized state works. + // this.ShowWindowWithoutActivation gets never called, this.WindowState get overwritten somehow after setting this.Visible=true, ... + if (m.Msg == Win32.WM_SHOWWINDOW && this.suppressInitialShow && (int)m.WParam == 1) + { + m.Result = IntPtr.Zero; + this.suppressInitialShow = false; + return; + } + + base.WndProc(ref m); + } + #endregion #region OnShown() protected override void OnShown(EventArgs e) @@ -69,6 +88,12 @@ protected override void OnClosed(EventArgs e) try { this.SaveSettings(); } catch { } try { this.server.Stop(); } catch { } try { this.servlets.Dispose(); } catch { } + try + { + if (this.cbCloseServerBrowser.Checked) + this.CloseServerBrowser(); + } + catch { } base.OnClosed(e); } #endregion @@ -213,10 +238,11 @@ private void cbSystemTray_CheckedChanged(object sender, EventArgs e) } #endregion - #region cbBindAll_CheckedChanged - private void cbBindAll_CheckedChanged(object sender, EventArgs e) + #region cbStartServerBrowser_CheckedChanged + private void cbStartServerBrowser_CheckedChanged(object sender, EventArgs e) { - this.RestartHttpServer(); + if (this.cbStartServerBrowser.Checked) + this.StartServerBrowser(); } #endregion @@ -277,9 +303,13 @@ private void autoQuitTimer_Tick(object sender, EventArgs e) else if (qlStarted) servlets.SetSteamNick(this.txtNickEnd.Text); - if (this.cbAutoQuit.Checked && qlStarted && !running) - this.Close(); - + if (qlStarted && !running) + { + if (this.cbAutoQuit.Checked) + this.Close(); + if (this.cbCloseServerBrowser.Checked) + this.CloseServerBrowser(); + } this.qlStarted = running; } #endregion @@ -293,11 +323,8 @@ private void LoadSettings() this.txtNickStart.Text = config.GetString("nickQuake"); this.txtNickEnd.Text = config.GetString("nickSteam"); this.cbAdvanced.Checked = config.GetBool("advanced"); - this.cbBindToAll.Checked = config.GetBool("bindToAll"); this.cbSystemTray.Checked = config.GetBool("systemTray"); this.cbStartMinimized.Checked = config.GetBool("startMinimized"); - if (this.cbStartMinimized.Checked) - this.SetFormVisibility(false); this.cbAutostart.Checked = config.GetString("autostart") != "0"; this.cbLog.Checked = config.GetBool("log"); this.cbFollowLog.Checked = config.GetBool("followLog"); @@ -305,6 +332,8 @@ private void LoadSettings() this.cbAutoQuit.Checked = config.GetBool("autoquit"); this.skipWorkshopNotice = config.GetBool("skipWorkshopNotice"); int.TryParse(config.GetString("steamAppId"), out this.steamAppId); + this.cbStartServerBrowser.Checked = config.GetBool("startServerBrowser"); + this.cbCloseServerBrowser.Checked = config.GetBool("closeServerBrowser"); } #endregion @@ -318,7 +347,6 @@ private void SaveSettings() config.Set("nickQuake", this.txtNickStart.Text); config.Set("nickSteam", this.txtNickEnd.Text); config.Set("advanced", this.cbAdvanced.Checked); - config.Set("bindToAll", this.cbBindToAll.Checked); config.Set("systemTray", this.cbSystemTray.Checked); config.Set("startMinimized", this.cbStartMinimized.Checked); config.Set("autostart", this.cbAutostart.Checked ? "1" : "0"); @@ -327,6 +355,8 @@ private void SaveSettings() config.Set("logAllRequests", this.cbLogAllRequests.Checked); config.Set("autoquit", this.cbAutoQuit.Checked); config.Set("skipWorkshopNotice", this.skipWorkshopNotice); + config.Set("startServerBrowser", this.cbStartServerBrowser.Checked ? "1" : "0"); + config.Set("closeServerBrowser", this.cbCloseServerBrowser.Checked ? "1" : "0"); config.SaveSettings(); } catch (Exception ex) @@ -405,8 +435,8 @@ private void RestartHttpServer() if (this.server == null) return; this.server.Stop(); - this.server.BindToAllInterfaces = this.cbBindToAll.Checked; - this.servlets.EnablePrivateServlets = !this.cbBindToAll.Checked; + this.server.BindToAllInterfaces = false; + this.servlets.EnablePrivateServlets = true; if (this.server.Start()) this.Log("extraQL server listening on " + this.server.EndPointUrl); else @@ -433,7 +463,11 @@ private void Launch() UpdateServletSettings(); servlets.SetSteamNick(this.txtNickStart.Text); if ((ModifierKeys & Keys.Control) == 0) // use ctrl+Start button just re-installs the scripts (during development) + { + if (cbStartServerBrowser.Checked) + StartServerBrowser(); StartQuakeLive(); + } } #endregion @@ -441,7 +475,7 @@ private void Launch() private bool InstallScripts(bool force = false) { - bool installScriptsInQlFolder = this.cbInstallInBaseq3.Checked; + const bool installScriptsInQlFolder = false; // make sure we know quake's home directory string path = this.GetQuakeLivePath(); @@ -610,11 +644,37 @@ private void SetFormVisibility(bool visible) } else { + this.WindowState = FormWindowState.Minimized; if (this.cbSystemTray.Checked) this.Hide(); + } + } + #endregion + + #region StartServerBrowser() + private void StartServerBrowser() + { + var proc = Process.GetProcessesByName("ServerBrowser"); + if (proc.Length == 0) + { + var wsPath = this.GetSteamWorkshopPath(); + wsPath = Path.Combine(Path.GetDirectoryName(wsPath) ?? ".", @"543312745\ServerBrowser.exe"); + if (File.Exists(wsPath)) + Process.Start(wsPath); else - this.WindowState = FormWindowState.Minimized; + Log("Could not find " + wsPath + ".\nMake sure you have steam workshop item 543312745 installed."); } + else + Win32.ShowWindow(proc[0].MainWindowHandle, 1); + } + #endregion + + #region CloseServerBrowser() + private void CloseServerBrowser() + { + var proc = Process.GetProcessesByName("ServerBrowser"); + foreach (var p in proc) + Win32.SendMessage(p.MainWindowHandle, Win32.WM_CLOSE, 0, 0); } #endregion diff --git a/source/Program.cs b/source/Program.cs index 04ba147..369c2d9 100644 --- a/source/Program.cs +++ b/source/Program.cs @@ -6,6 +6,7 @@ namespace ExtraQL static class Program { public const string WinServiceSwitch = "-service"; + public const string BackgroundSwitch = "-background"; #region Main() [STAThread] @@ -18,7 +19,7 @@ static void Main() { Config config = new Config(); config.LoadSettings(); - if (ActivateRunningInstance(config.GetBool("https"))) + if (ActivateRunningInstance()) return; Application.EnableVisualStyles(); @@ -37,14 +38,15 @@ static void Main() #endregion #region ActivateRunningInstance() - private static bool ActivateRunningInstance(bool useHttps) + private static bool ActivateRunningInstance() { using (var client = new XWebClient(500)) { try { - var result = client.DownloadString((useHttps ? "https" : "http") + "://127.0.0.1:27963/bringToFront"); - if (result == "ok") + var servlet = Environment.CommandLine.Contains(BackgroundSwitch) ? "version" : "bringToFront"; + var result = client.DownloadString("http://127.0.0.1:27963/" + servlet); + if (result != null) return true; } catch diff --git a/source/Win32.cs b/source/Win32.cs index 2e6b199..47c72af 100644 --- a/source/Win32.cs +++ b/source/Win32.cs @@ -34,14 +34,21 @@ public static class Win32 [DllImport("user32.dll")] public static extern uint GetWindowLong(IntPtr hWnd, int nIndex); - [DllImportAttribute("user32.dll")] + [DllImport("user32.dll")] public static extern bool ReleaseCapture(); - [DllImportAttribute("user32.dll")] + [DllImport("user32.dll")] public static extern bool IsWindowUnicode(IntPtr hWnd); + [DllImport("user32.dll")] + public static extern bool ShowWindow(IntPtr handle, int flags); + public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr lParam); + public const int WM_ACTIVATE = 0x0006; + public const int WM_SETREDRAW = 0x000B; + public const int WM_CLOSE = 0x0010; + public const int WM_SHOWWINDOW = 0x0018; public const int WM_KEYDOWN = 0x0100; public const int WM_KEYUP = 0x0101; public const int WM_CHAR = 0x0102; @@ -56,7 +63,11 @@ public static class Win32 public const int WM_SYSKEYDOWN = 0x0104; public const int WM_SYSKEYUP = 0x0105; + public const int SWP_NOSIZE = 0x0001; + public const int SWP_NOMOVE = 0x0002; public const int SWP_NOACTIVATE = 0x0010; + public const int SWP_SHOWWINDOW = 0x0040; + public const int SWP_HIDEWINDOW = 0x0080; public const int SWP_NOOWNERZORDER = 0x0200; public const int SWP_NOSENDCHANGING = 0x0400; public const int SWP_NOZORDER = 0x0004; diff --git a/source/extraQL.csproj b/source/extraQL.csproj index 357522f..1ed49c6 100644 --- a/source/extraQL.csproj +++ b/source/extraQL.csproj @@ -141,7 +141,7 @@ - + diff --git a/source/DLL/steam_api.dll b/source/steam_api.dll similarity index 100% rename from source/DLL/steam_api.dll rename to source/steam_api.dll