From c280f72de1499bcedc8c1349894f7ec1e37bc7e0 Mon Sep 17 00:00:00 2001 From: Chord Date: Sun, 19 Jun 2016 16:02:10 -0400 Subject: [PATCH] Improve layout, add settings, kill button --- PS2ModLauncher/LauncherForm.Designer.cs | 156 +++---- PS2ModLauncher/LauncherForm.cs | 413 ++++++++---------- PS2ModLauncher/LauncherForm.resx | 51 ++- PS2ModLauncher/PSLauncher.csproj | 10 + .../Properties/Settings.Designer.cs | 36 ++ PS2ModLauncher/Properties/Settings.settings | 9 + PS2ModLauncher/SettingsForm.Designer.cs | 153 +++++++ PS2ModLauncher/SettingsForm.cs | 96 ++++ PS2ModLauncher/SettingsForm.resx | 123 ++++++ PS2ModLauncher/Util.cs | 23 + PS2ModLauncher/app.config | 9 + 11 files changed, 741 insertions(+), 338 deletions(-) create mode 100644 PS2ModLauncher/SettingsForm.Designer.cs create mode 100644 PS2ModLauncher/SettingsForm.cs create mode 100644 PS2ModLauncher/SettingsForm.resx create mode 100644 PS2ModLauncher/Util.cs diff --git a/PS2ModLauncher/LauncherForm.Designer.cs b/PS2ModLauncher/LauncherForm.Designer.cs index a4a9ed5..6a2875b 100644 --- a/PS2ModLauncher/LauncherForm.Designer.cs +++ b/PS2ModLauncher/LauncherForm.Designer.cs @@ -29,32 +29,29 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - this.findPTRDirDialogue = new System.Windows.Forms.FolderBrowserDialog(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LauncherForm)); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - this.planetsideVersion = new System.Windows.Forms.Label(); - this.launchArgs = new System.Windows.Forms.TextBox(); - this.launchProgress = new System.Windows.Forms.ProgressBar(); + this.hideShowOutput = new System.Windows.Forms.Button(); this.skipLauncher = new System.Windows.Forms.CheckBox(); this.passwordLabel = new System.Windows.Forms.Label(); this.usernameLabel = new System.Windows.Forms.Label(); this.password = new System.Windows.Forms.TextBox(); this.username = new System.Windows.Forms.TextBox(); - this.label10 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); this.launchGame = new System.Windows.Forms.Button(); - this.selectDirectory = new System.Windows.Forms.Button(); - this.planetside2PathTextField = new System.Windows.Forms.TextBox(); this.launchMessage = new System.Windows.Forms.Label(); + this.spinner = new System.Windows.Forms.PictureBox(); this.ps_consoleOutput = new System.Windows.Forms.TextBox(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.aboutToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.spinner)).BeginInit(); this.contextMenuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.toolStripContainer1.ContentPanel.SuspendLayout(); @@ -62,10 +59,6 @@ this.toolStripContainer1.SuspendLayout(); this.SuspendLayout(); // - // findPTRDirDialogue - // - this.findPTRDirDialogue.HelpRequest += new System.EventHandler(this.folderBrowserDialog1_HelpRequest); - // // splitContainer1 // this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; @@ -78,55 +71,35 @@ // splitContainer1.Panel1 // this.splitContainer1.Panel1.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.splitContainer1.Panel1.Controls.Add(this.planetsideVersion); - this.splitContainer1.Panel1.Controls.Add(this.launchArgs); - this.splitContainer1.Panel1.Controls.Add(this.launchProgress); + this.splitContainer1.Panel1.Controls.Add(this.hideShowOutput); this.splitContainer1.Panel1.Controls.Add(this.skipLauncher); this.splitContainer1.Panel1.Controls.Add(this.passwordLabel); this.splitContainer1.Panel1.Controls.Add(this.usernameLabel); this.splitContainer1.Panel1.Controls.Add(this.password); this.splitContainer1.Panel1.Controls.Add(this.username); - this.splitContainer1.Panel1.Controls.Add(this.label10); - this.splitContainer1.Panel1.Controls.Add(this.label2); this.splitContainer1.Panel1.Controls.Add(this.launchGame); - this.splitContainer1.Panel1.Controls.Add(this.selectDirectory); - this.splitContainer1.Panel1.Controls.Add(this.planetside2PathTextField); this.splitContainer1.Panel1.Controls.Add(this.launchMessage); - this.splitContainer1.Panel1MinSize = 125; + this.splitContainer1.Panel1.Controls.Add(this.spinner); + this.splitContainer1.Panel1MinSize = 95; // // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.ps_consoleOutput); - this.splitContainer1.Size = new System.Drawing.Size(584, 486); + this.splitContainer1.Size = new System.Drawing.Size(384, 287); this.splitContainer1.SplitterDistance = this.splitContainer1.Panel1MinSize; this.splitContainer1.TabIndex = 0; // - // planetsideVersion + // hideShowOutput // - this.planetsideVersion.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.planetsideVersion.Location = new System.Drawing.Point(419, 50); - this.planetsideVersion.Name = "planetsideVersion"; - this.planetsideVersion.Size = new System.Drawing.Size(132, 21); - this.planetsideVersion.TabIndex = 24; - // - // launchArgs - // - this.launchArgs.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.launchArgs.Location = new System.Drawing.Point(329, 96); - this.launchArgs.Name = "launchArgs"; - this.launchArgs.Size = new System.Drawing.Size(222, 20); - this.launchArgs.TabIndex = 6; - // - // launchProgress - // - this.launchProgress.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0))))); - this.launchProgress.Location = new System.Drawing.Point(9, 96); - this.launchProgress.Name = "launchProgress"; - this.launchProgress.Size = new System.Drawing.Size(246, 20); - this.launchProgress.TabIndex = 16; - this.launchProgress.Tag = ""; - this.launchProgress.UseWaitCursor = true; - this.launchProgress.Visible = false; + this.hideShowOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.hideShowOutput.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.hideShowOutput.Location = new System.Drawing.Point(297, 69); + this.hideShowOutput.Name = "hideShowOutput"; + this.hideShowOutput.Size = new System.Drawing.Size(84, 21); + this.hideShowOutput.TabIndex = 23; + this.hideShowOutput.Text = "vv Show vv"; + this.hideShowOutput.UseVisualStyleBackColor = true; + this.hideShowOutput.Click += new System.EventHandler(this.hideShowOutput_Click_1); // // skipLauncher // @@ -175,26 +148,6 @@ this.username.TabIndex = 0; this.username.TextChanged += new System.EventHandler(this.loginFormChanged); // - // label10 - // - this.label10.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.label10.AutoSize = true; - this.label10.Location = new System.Drawing.Point(326, 77); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(158, 13); - this.label10.TabIndex = 14; - this.label10.Text = "Additional command line options"; - // - // label2 - // - this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(326, 3); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(90, 13); - this.label2.TabIndex = 7; - this.label2.Text = "PlanetSide Folder"; - // // launchGame // this.launchGame.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); @@ -208,39 +161,28 @@ this.launchGame.UseVisualStyleBackColor = false; this.launchGame.Click += new System.EventHandler(this.button2_Click); // - // selectDirectory - // - this.selectDirectory.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.selectDirectory.Location = new System.Drawing.Point(329, 45); - this.selectDirectory.Name = "selectDirectory"; - this.selectDirectory.Size = new System.Drawing.Size(75, 23); - this.selectDirectory.TabIndex = 5; - this.selectDirectory.Text = "Choose"; - this.selectDirectory.UseVisualStyleBackColor = true; - this.selectDirectory.Click += new System.EventHandler(this.button1_Click); - // - // planetside2PathTextField - // - this.planetside2PathTextField.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.planetside2PathTextField.Location = new System.Drawing.Point(329, 19); - this.planetside2PathTextField.Name = "planetside2PathTextField"; - this.planetside2PathTextField.ReadOnly = true; - this.planetside2PathTextField.Size = new System.Drawing.Size(222, 20); - this.planetside2PathTextField.TabIndex = 4; - this.planetside2PathTextField.Text = "Path to PlanetSide folder"; - this.planetside2PathTextField.Click += new System.EventHandler(this.button1_Click); - // // launchMessage // this.launchMessage.ForeColor = System.Drawing.Color.Red; - this.launchMessage.Location = new System.Drawing.Point(8, 93); + this.launchMessage.Location = new System.Drawing.Point(202, 37); this.launchMessage.Name = "launchMessage"; - this.launchMessage.Size = new System.Drawing.Size(247, 27); + this.launchMessage.Size = new System.Drawing.Size(172, 27); this.launchMessage.TabIndex = 22; - this.launchMessage.Text = "label1"; + this.launchMessage.Text = "Error message"; this.launchMessage.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.launchMessage.Visible = false; // + // spinner + // + this.spinner.Enabled = false; + this.spinner.Image = ((System.Drawing.Image)(resources.GetObject("spinner.Image"))); + this.spinner.Location = new System.Drawing.Point(114, 67); + this.spinner.Name = "spinner"; + this.spinner.Size = new System.Drawing.Size(26, 24); + this.spinner.TabIndex = 24; + this.spinner.TabStop = false; + this.spinner.Visible = false; + // // ps_consoleOutput // this.ps_consoleOutput.BackColor = System.Drawing.Color.WhiteSmoke; @@ -250,7 +192,7 @@ this.ps_consoleOutput.Name = "ps_consoleOutput"; this.ps_consoleOutput.ReadOnly = true; this.ps_consoleOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.ps_consoleOutput.Size = new System.Drawing.Size(584, 357); + this.ps_consoleOutput.Size = new System.Drawing.Size(384, 188); this.ps_consoleOutput.TabIndex = 1; this.ps_consoleOutput.WordWrap = false; // @@ -271,13 +213,21 @@ // this.menuStrip1.Dock = System.Windows.Forms.DockStyle.None; this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.settingsToolStripMenuItem, this.aboutToolStripMenuItem1}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(584, 24); + this.menuStrip1.Size = new System.Drawing.Size(384, 24); this.menuStrip1.TabIndex = 2; this.menuStrip1.Text = "menuStrip1"; // + // settingsToolStripMenuItem + // + this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem"; + this.settingsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); + this.settingsToolStripMenuItem.Text = "Settings"; + this.settingsToolStripMenuItem.Click += new System.EventHandler(this.settingsToolStripMenuItem_Click); + // // aboutToolStripMenuItem1 // this.aboutToolStripMenuItem1.Name = "aboutToolStripMenuItem1"; @@ -291,13 +241,13 @@ // toolStripContainer1.ContentPanel // this.toolStripContainer1.ContentPanel.Controls.Add(this.splitContainer1); - this.toolStripContainer1.ContentPanel.Size = new System.Drawing.Size(584, 486); + this.toolStripContainer1.ContentPanel.Size = new System.Drawing.Size(384, 287); this.toolStripContainer1.Dock = System.Windows.Forms.DockStyle.Fill; this.toolStripContainer1.LeftToolStripPanelVisible = false; this.toolStripContainer1.Location = new System.Drawing.Point(0, 0); this.toolStripContainer1.Name = "toolStripContainer1"; this.toolStripContainer1.RightToolStripPanelVisible = false; - this.toolStripContainer1.Size = new System.Drawing.Size(584, 510); + this.toolStripContainer1.Size = new System.Drawing.Size(384, 311); this.toolStripContainer1.TabIndex = 3; this.toolStripContainer1.Text = "toolStripContainer1"; // @@ -310,10 +260,10 @@ this.AcceptButton = this.launchGame; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(584, 510); + this.ClientSize = new System.Drawing.Size(384, 311); this.Controls.Add(this.toolStripContainer1); this.MainMenuStrip = this.menuStrip1; - this.MinimumSize = new System.Drawing.Size(600, 350); + this.MinimumSize = new System.Drawing.Size(400, 350); this.Name = "LauncherForm"; this.Text = "PS1 GameLauncher"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.LauncherForm_FormClosing); @@ -326,6 +276,7 @@ this.splitContainer1.Panel2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.spinner)).EndInit(); this.contextMenuStrip1.ResumeLayout(false); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); @@ -339,19 +290,12 @@ } #endregion - private System.Windows.Forms.FolderBrowserDialog findPTRDirDialogue; private System.Windows.Forms.SplitContainer splitContainer1; - private System.Windows.Forms.Label label10; - private System.Windows.Forms.TextBox launchArgs; - private System.Windows.Forms.Label label2; private System.Windows.Forms.Button launchGame; - private System.Windows.Forms.Button selectDirectory; - private System.Windows.Forms.TextBox planetside2PathTextField; private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; private System.Windows.Forms.Label usernameLabel; private System.Windows.Forms.TextBox password; private System.Windows.Forms.TextBox username; - private System.Windows.Forms.ProgressBar launchProgress; private System.Windows.Forms.TextBox ps_consoleOutput; private System.Windows.Forms.Label passwordLabel; private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem; @@ -359,8 +303,10 @@ private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem1; private System.Windows.Forms.Label launchMessage; private System.Windows.Forms.CheckBox skipLauncher; - private System.Windows.Forms.Label planetsideVersion; private System.Windows.Forms.ToolStripContainer toolStripContainer1; + private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem; + private System.Windows.Forms.Button hideShowOutput; + private System.Windows.Forms.PictureBox spinner; } } diff --git a/PS2ModLauncher/LauncherForm.cs b/PS2ModLauncher/LauncherForm.cs index eda7a2b..0f9b460 100644 --- a/PS2ModLauncher/LauncherForm.cs +++ b/PS2ModLauncher/LauncherForm.cs @@ -19,54 +19,53 @@ namespace PSLauncher public enum LaunchDomain { - Live + Live, + PSForever } public enum GameState { Stopped, Launching, - Running + Running, + Stopping } public partial class LauncherForm : Form { Process psProcess; string USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/31.0"; - static string PS_EXE_NAME = "planetside.exe"; + int DEFAULT_WEB_TIMEOUT = 5000; - string planetsidePath = ""; - bool planetsidePathValid = false; bool bGameRunning = false; GameState gameState = GameState.Stopped; + System.Drawing.Size oldSize = new System.Drawing.Size(0, 0); LaunchDomain domain = LaunchDomain.Live; Dictionary domains = new Dictionary() { - { LaunchDomain.Live, "https://lpj.daybreakgames.com/ps/live" } + { LaunchDomain.Live, "https://lpj.daybreakgames.com/ps/live" }, + { LaunchDomain.PSForever, "https://login.psforever.net/" } }; public LauncherForm() { InitializeComponent(); - + + if (Debugger.IsAttached) + Settings.Default.Reset(); + string psDefault = getDefaultDirectory(); // first run with no settings or invalid starting path if (Settings.Default.PSPath == "" || !checkDirForPlanetSide(Settings.Default.PSPath)) { - // try setting the path. It may not be right, but this initializes state - setPlanetSidePath(Path.Combine(psDefault, PS_EXE_NAME), false); Settings.Default.PSPath = psDefault; } - else - { - setPlanetSidePath(Path.Combine(Settings.Default.PSPath, PS_EXE_NAME), false); - } - planetside2PathTextField.Text = Settings.Default.PSPath; - launchArgs.Text = Settings.Default.ExtraArgs; + setConsoleWindowState(Settings.Default.OutputShown); + skipLauncher.Checked = Settings.Default.SkipLauncher; } private void LauncherForm_FormClosing(object sender, FormClosingEventArgs e) @@ -81,143 +80,53 @@ namespace PSLauncher } } - private void button1_Click(object sender, EventArgs e) - { - // set the starting path for the dialog - if (planetside2PathTextField.Text != "") - findPTRDirDialogue.SelectedPath = planetside2PathTextField.Text; - - DialogResult r = findPTRDirDialogue.ShowDialog(); - - if (r == DialogResult.OK) - { - // combine the folder name with the standard PS.exe name - string psPath = Path.Combine(findPTRDirDialogue.SelectedPath, PS_EXE_NAME); - - planetside2PathTextField.Text = findPTRDirDialogue.SelectedPath; - setPlanetSidePath(psPath); - - Settings.Default.PSPath = findPTRDirDialogue.SelectedPath; - } - } - - private bool setPlanetSidePath(string path, bool alert = true) - { - planetsidePath = path; - planetsidePathValid = false; - - if(!File.Exists(path)) - { - planetsideVersion.Text = "Not found"; - planetsideVersion.ForeColor = System.Drawing.Color.Red; - - if(alert) - MessageBox.Show("Cannot open " + PS_EXE_NAME + " (check the selected directory)", - "Cannot Find Executable", MessageBoxButtons.OK, MessageBoxIcon.Error); - return planetsidePathValid; - } - - var versionInfo = FileVersionInfo.GetVersionInfo(path); - - planetsidePathValid = true; - - if (versionInfo.FileVersion != "") - { - planetsideVersion.Text = "Version " + versionInfo.FileVersion; - planetsideVersion.ForeColor = System.Drawing.Color.Green; - } - else - { - planetsideVersion.Text = "Unknown version"; - planetsideVersion.ForeColor = System.Drawing.Color.Yellow; - } - - return planetsidePathValid; - } - - private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e) - { - - } - private void stopLaunching() { - if (this.InvokeRequired) - { - this.Invoke((MethodInvoker)delegate - { - this.launchGame.Enabled = true; - this.launchGame.Text = "Launch"; - this.launchProgress.Visible = false; - }); - } - else - { - this.launchGame.Enabled = true; - this.launchGame.Text = "Launch"; - this.launchProgress.Visible = false; - } - - setProgress(0); + setButtonState(GameState.Stopped); + progressShown(false); gameState = GameState.Stopped; } private void startLaunching() { - if (this.InvokeRequired) - { - this.Invoke((MethodInvoker)delegate - { - this.launchGame.Enabled = false; - this.launchGame.Text = "Launching..."; - this.launchProgress.Visible = true; - setProgress(0); - }); - } - else - { - this.launchGame.Enabled = false; - this.launchGame.Text = "Launching..."; - this.launchProgress.Visible = true; - setProgress(0); - } + setButtonState(GameState.Launching); + progressShown(true); gameState = GameState.Launching; } - private void setProgress(int prog) + private void setButtonState(GameState state) { - if (this.InvokeRequired) + this.SafeInvoke(a => { - this.Invoke((MethodInvoker)delegate + switch (state) { - this.launchProgress.Value = prog; - }); - } - else - { - this.launchProgress.Value = prog; - } + case GameState.Launching: + this.launchGame.Enabled = false; + this.launchGame.Text = "Launching..."; + break; + case GameState.Running: + this.launchGame.BackColor = System.Drawing.Color.FromArgb(255, 128, 128); + this.launchGame.Enabled = true; + this.launchGame.Text = "Kill"; + break; + case GameState.Stopped: + this.launchGame.BackColor = System.Drawing.Color.FromArgb(128, 255, 128); + this.launchGame.Enabled = true; + this.launchGame.Text = "Launch"; + break; + case GameState.Stopping: + this.launchGame.Enabled = false; + this.launchGame.Text = "Killing..."; + break; + } + }); } private void setErrorMessage(string error) { - if (this.InvokeRequired) - { - this.Invoke((MethodInvoker)delegate - { - if (error == "") - { - this.launchMessage.Visible = false; - return; - } - - this.launchMessage.Visible = true; - this.launchMessage.Text = error; - }); - } - else + this.SafeInvoke(a => { if (error == "") { @@ -227,48 +136,46 @@ namespace PSLauncher this.launchMessage.Visible = true; this.launchMessage.Text = error; - } + }); } private void button2_Click(object sender, EventArgs e) { - startLaunching(); - setErrorMessage(""); + if(gameState == GameState.Running) // kill command + { + psProcess.Kill(); + return; + } - string path = planetside2PathTextField.Text; - string psExe = Path.Combine(path, PS_EXE_NAME); + if(Settings.Default.ClearOutputOnLaunch) + { + this.ps_consoleOutput.Clear(); + } + + string path = Settings.Default.PSPath; + string psExe = Path.Combine(path, SettingsForm.PS_EXE_NAME); if (!skipLauncher.Checked && (username.Text == String.Empty || password.Text == String.Empty)) { setErrorMessage("Username or password blank"); - stopLaunching(); return; } - if (!planetsidePathValid) + if (!checkDirForPlanetSide(path)) { setErrorMessage("Invalid planetside exe"); - stopLaunching(); return; } - if (String.IsNullOrWhiteSpace(launchArgs.Text)) - launchArgs.Text = ""; - - //And the extra launch args - if (Settings.Default.ExtraArgs != launchArgs.Text) - { - Settings.Default.ExtraArgs = this.launchArgs.Text; - } - if (skipLauncher.Checked) { // magic string to login to planetside from the actual game - startPlanetSide(planetsidePath, Path.GetDirectoryName(planetsidePath), "/K:StagingTest " + launchArgs.Text); - setProgress(100); + startPlanetSide(psExe, Path.GetDirectoryName(psExe), "/K:StagingTest " + Settings.Default.ExtraArgs); } else { + startLaunching(); + Task.Factory.StartNew(() => { this.doLogin(); @@ -293,8 +200,8 @@ namespace PSLauncher { long ts = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; - string path = planetside2PathTextField.Text; - string psExe = Path.Combine(path, PS_EXE_NAME); + string path = Settings.Default.PSPath; + string psExe = Path.Combine(path, SettingsForm.PS_EXE_NAME); ///////////////////////////////////////////////////////////////// // Step 1: Establish Session ID @@ -353,7 +260,6 @@ namespace PSLauncher addLine("PSWeb: session started"); r.Close(); - setProgress(25); ///////////////////////////////////////////////////////////////// // Step 2: Try logging in @@ -464,7 +370,6 @@ namespace PSLauncher string result = ""; r.Close(); addLine("PSWeb: logged in"); - setProgress(50); try { @@ -565,7 +470,6 @@ namespace PSLauncher result = ""; r.Close(); - setProgress(75); string token = ""; @@ -595,14 +499,13 @@ namespace PSLauncher addLine("PSWeb: got launch args " + token); string launch_args = token; - string ExtraLaunchArgs = launchArgs.Text; + string ExtraLaunchArgs = Settings.Default.ExtraArgs; if (ExtraLaunchArgs != String.Empty) launch_args += " " + ExtraLaunchArgs; startPlanetSide(psExe, path, launch_args); - - setProgress(100); + return; } @@ -625,7 +528,6 @@ namespace PSLauncher psProcess.BeginErrorReadLine(); psProcess.BeginOutputReadLine(); - gameRunning(); } @@ -640,34 +542,16 @@ namespace PSLauncher void addLine(String line) { - if(this.InvokeRequired) - { - this.Invoke((MethodInvoker)delegate - { - ps_consoleOutput.AppendText(line + Environment.NewLine); - }); - } - else + this.SafeInvoke(a => { ps_consoleOutput.AppendText(line + Environment.NewLine); - } + }); } void gameRunning() { - if (this.InvokeRequired) - { - this.Invoke((MethodInvoker)delegate - { - this.launchGame.Enabled = false; - this.launchGame.Text = "Running"; - }); - } - else - { - this.launchGame.Enabled = false; - this.launchGame.Text = "Running"; - } + setButtonState(GameState.Running); + progressShown(false); bGameRunning = true; gameState = GameState.Running; @@ -689,6 +573,121 @@ namespace PSLauncher } + private void progressShown(bool shown) + { + this.SafeInvoke(a => + { + if (shown) + { + this.spinner.Visible = true; + this.spinner.Enabled = true; + this.launchGame.Visible = false; + } + else + { + this.spinner.Visible = false; + this.spinner.Enabled = false; + this.launchGame.Visible = true; + } + }); + } + + private void aboutToolStripMenuItem1_Click(object sender, EventArgs e) + { + About a = new About(); + a.StartPosition = FormStartPosition.CenterParent; + a.ShowDialog(this); + } + + private void loginFormChanged(object sender, EventArgs e) + { + if (gameState == GameState.Stopped) + { + if (username.Text.Length > 0 && password.Text.Length > 0 || skipLauncher.Checked) + launchGame.Enabled = true; + else + launchGame.Enabled = false; + } + + if (skipLauncher.Checked) + { + Settings.Default.SkipLauncher = true; + username.Enabled = false; + password.Enabled = false; + } + else + { + Settings.Default.SkipLauncher = false; + username.Enabled = true; + password.Enabled = true; + } + } + + private void setConsoleWindowState(bool open) + { + if (!open) + { + oldSize = this.Size; + + this.hideShowOutput.Text = "vv Show vv"; + this.MinimumSize = this.MaximumSize = new System.Drawing.Size(400, 160); + + this.Size = new System.Drawing.Size(400, 190); + + this.WindowState = FormWindowState.Normal; + this.MaximizeBox = false; + } + else + { + this.hideShowOutput.Text = "^^ Hide ^^"; + this.MinimumSize = new System.Drawing.Size(400, 350); + this.MaximumSize = new System.Drawing.Size(0, 0); + + if (oldSize.IsEmpty) + this.Size = new System.Drawing.Size(400, 500); // default size to expand to + else + this.Size = oldSize; + + this.MaximizeBox = true; + } + + splitContainer1.Panel2Collapsed = !open; + } + + private void LauncherForm_ResizeBegin(object sender, EventArgs e) + { + splitContainer1.Panel2.SuspendLayout(); + } + + private void LauncherForm_ResizeEnd(object sender, EventArgs e) + { + Win32.SuspendPainting(splitContainer1.Panel2.Handle); + splitContainer1.Panel2.ResumeLayout(); + Win32.ResumePainting(splitContainer1.Panel2.Handle); + this.Refresh(); + } + + private void hideShowOutput_Click_1(object sender, EventArgs e) + { + if (splitContainer1.Panel2Collapsed) + { + Settings.Default.OutputShown = true; + setConsoleWindowState(true); + } + else + { + Settings.Default.OutputShown = false; + setConsoleWindowState(false); + } + } + + private void settingsToolStripMenuItem_Click(object sender, EventArgs e) + { + SettingsForm a = new SettingsForm(); + a.StartPosition = FormStartPosition.CenterParent; + a.ShowDialog(this); + } + private static string getDefaultDirectory() { RegistryKey key = null; @@ -733,7 +732,7 @@ namespace PSLauncher private static bool checkDirForPlanetSide(string dir) { - return File.Exists(Path.Combine(dir, PS_EXE_NAME)); + return File.Exists(Path.Combine(dir, SettingsForm.PS_EXE_NAME)); } private static string ProgramFilesx86() @@ -746,52 +745,6 @@ namespace PSLauncher return Environment.GetEnvironmentVariable("ProgramFiles"); } - - private void loginWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) - { - - } - - private void aboutToolStripMenuItem1_Click(object sender, EventArgs e) - { - About a = new About(); - a.ShowDialog(this); - } - - private void loginFormChanged(object sender, EventArgs e) - { - if(gameState == GameState.Stopped) - { - if (username.Text.Length > 0 && password.Text.Length > 0 || skipLauncher.Checked) - launchGame.Enabled = true; - else - launchGame.Enabled = false; - } - - if (skipLauncher.Checked) - { - username.Enabled = false; - password.Enabled = false; - } - else - { - username.Enabled = true; - password.Enabled = true; - } - } - - private void LauncherForm_ResizeBegin(object sender, EventArgs e) - { - splitContainer1.Panel2.SuspendLayout(); - } - - private void LauncherForm_ResizeEnd(object sender, EventArgs e) - { - Win32.SuspendPainting(splitContainer1.Panel2.Handle); - splitContainer1.Panel2.ResumeLayout(); - Win32.ResumePainting(splitContainer1.Panel2.Handle); - this.Refresh(); - } } public static class QueryExtensions diff --git a/PS2ModLauncher/LauncherForm.resx b/PS2ModLauncher/LauncherForm.resx index 1ab0a44..bec9d24 100644 --- a/PS2ModLauncher/LauncherForm.resx +++ b/PS2ModLauncher/LauncherForm.resx @@ -117,9 +117,54 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - + + + + 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 + nQAGArBTt8R8mLuyPyEAOwAAAAAAAAAAAA== + + 224, 17 diff --git a/PS2ModLauncher/PSLauncher.csproj b/PS2ModLauncher/PSLauncher.csproj index 66c061b..422c9cd 100644 --- a/PS2ModLauncher/PSLauncher.csproj +++ b/PS2ModLauncher/PSLauncher.csproj @@ -167,6 +167,13 @@ + + Form + + + SettingsForm.cs + + AboutBox1.cs @@ -183,6 +190,9 @@ Resources.resx True + + SettingsForm.cs + diff --git a/PS2ModLauncher/Properties/Settings.Designer.cs b/PS2ModLauncher/Properties/Settings.Designer.cs index b4c1633..a1c2d32 100644 --- a/PS2ModLauncher/Properties/Settings.Designer.cs +++ b/PS2ModLauncher/Properties/Settings.Designer.cs @@ -46,5 +46,41 @@ namespace PSLauncher.Properties { this["ExtraArgs"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool OutputShown { + get { + return ((bool)(this["OutputShown"])); + } + set { + this["OutputShown"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool SkipLauncher { + get { + return ((bool)(this["SkipLauncher"])); + } + set { + this["SkipLauncher"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool ClearOutputOnLaunch { + get { + return ((bool)(this["ClearOutputOnLaunch"])); + } + set { + this["ClearOutputOnLaunch"] = value; + } + } } } diff --git a/PS2ModLauncher/Properties/Settings.settings b/PS2ModLauncher/Properties/Settings.settings index a335411..a246997 100644 --- a/PS2ModLauncher/Properties/Settings.settings +++ b/PS2ModLauncher/Properties/Settings.settings @@ -8,5 +8,14 @@ + + False + + + False + + + True + \ No newline at end of file diff --git a/PS2ModLauncher/SettingsForm.Designer.cs b/PS2ModLauncher/SettingsForm.Designer.cs new file mode 100644 index 0000000..715fdeb --- /dev/null +++ b/PS2ModLauncher/SettingsForm.Designer.cs @@ -0,0 +1,153 @@ +namespace PSLauncher +{ + partial class SettingsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label2 = new System.Windows.Forms.Label(); + this.selectDirectory = new System.Windows.Forms.Button(); + this.planetside2PathTextField = new System.Windows.Forms.TextBox(); + this.launchArgs = new System.Windows.Forms.TextBox(); + this.label10 = new System.Windows.Forms.Label(); + this.planetsideVersion = new System.Windows.Forms.Label(); + this.findPTRDirDialogue = new System.Windows.Forms.FolderBrowserDialog(); + this.clearOnLaunch = new System.Windows.Forms.CheckBox(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(9, 17); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(90, 13); + this.label2.TabIndex = 10; + this.label2.Text = "PlanetSide Folder"; + // + // selectDirectory + // + this.selectDirectory.Location = new System.Drawing.Point(12, 59); + this.selectDirectory.Name = "selectDirectory"; + this.selectDirectory.Size = new System.Drawing.Size(75, 23); + this.selectDirectory.TabIndex = 9; + this.selectDirectory.Text = "Choose"; + this.selectDirectory.UseVisualStyleBackColor = true; + this.selectDirectory.Click += new System.EventHandler(this.button1_Click); + // + // planetside2PathTextField + // + this.planetside2PathTextField.Location = new System.Drawing.Point(12, 33); + this.planetside2PathTextField.Name = "planetside2PathTextField"; + this.planetside2PathTextField.ReadOnly = true; + this.planetside2PathTextField.Size = new System.Drawing.Size(222, 20); + this.planetside2PathTextField.TabIndex = 8; + this.planetside2PathTextField.Text = "Path to PlanetSide folder"; + // + // launchArgs + // + this.launchArgs.Location = new System.Drawing.Point(12, 117); + this.launchArgs.Name = "launchArgs"; + this.launchArgs.Size = new System.Drawing.Size(222, 20); + this.launchArgs.TabIndex = 15; + this.launchArgs.TextChanged += new System.EventHandler(this.launchArgs_TextChanged); + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(9, 98); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(158, 13); + this.label10.TabIndex = 16; + this.label10.Text = "Additional command line options"; + // + // planetsideVersion + // + this.planetsideVersion.Location = new System.Drawing.Point(102, 59); + this.planetsideVersion.Name = "planetsideVersion"; + this.planetsideVersion.Size = new System.Drawing.Size(132, 21); + this.planetsideVersion.TabIndex = 25; + // + // clearOnLaunch + // + this.clearOnLaunch.AutoSize = true; + this.clearOnLaunch.Location = new System.Drawing.Point(13, 157); + this.clearOnLaunch.Name = "clearOnLaunch"; + this.clearOnLaunch.Size = new System.Drawing.Size(133, 17); + this.clearOnLaunch.TabIndex = 26; + this.clearOnLaunch.Text = "Clear output on launch"; + this.clearOnLaunch.UseVisualStyleBackColor = true; + this.clearOnLaunch.CheckedChanged += new System.EventHandler(this.clearOnLaunch_CheckedChanged); + // + // button1 + // + this.button1.Anchor = System.Windows.Forms.AnchorStyles.Bottom; + this.button1.Location = new System.Drawing.Point(91, 186); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(62, 23); + this.button1.TabIndex = 27; + this.button1.Text = "OK"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click_1); + // + // SettingsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(244, 211); + this.Controls.Add(this.button1); + this.Controls.Add(this.clearOnLaunch); + this.Controls.Add(this.planetsideVersion); + this.Controls.Add(this.launchArgs); + this.Controls.Add(this.label10); + this.Controls.Add(this.label2); + this.Controls.Add(this.selectDirectory); + this.Controls.Add(this.planetside2PathTextField); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MaximumSize = new System.Drawing.Size(260, 250); + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(260, 250); + this.Name = "SettingsForm"; + this.Text = "Settings"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button selectDirectory; + private System.Windows.Forms.TextBox planetside2PathTextField; + private System.Windows.Forms.TextBox launchArgs; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.Label planetsideVersion; + private System.Windows.Forms.FolderBrowserDialog findPTRDirDialogue; + private System.Windows.Forms.CheckBox clearOnLaunch; + private System.Windows.Forms.Button button1; + } +} \ No newline at end of file diff --git a/PS2ModLauncher/SettingsForm.cs b/PS2ModLauncher/SettingsForm.cs new file mode 100644 index 0000000..e1eddc6 --- /dev/null +++ b/PS2ModLauncher/SettingsForm.cs @@ -0,0 +1,96 @@ +using PSLauncher.Properties; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace PSLauncher +{ + public partial class SettingsForm : Form + { + static public string PS_EXE_NAME = "planetside.exe"; + + public SettingsForm() + { + InitializeComponent(); + + planetside2PathTextField.Text = Settings.Default.PSPath; + launchArgs.Text = Settings.Default.ExtraArgs; + clearOnLaunch.Checked = Settings.Default.ClearOutputOnLaunch; + } + + private void button1_Click(object sender, EventArgs e) + { + // set the starting path for the dialog + if (planetside2PathTextField.Text != "") + findPTRDirDialogue.SelectedPath = planetside2PathTextField.Text; + + DialogResult r = findPTRDirDialogue.ShowDialog(); + + if (r == DialogResult.OK) + { + // combine the folder name with the standard PS.exe name + string psPath = Path.Combine(findPTRDirDialogue.SelectedPath, PS_EXE_NAME); + + planetside2PathTextField.Text = findPTRDirDialogue.SelectedPath; + + if (checkPath(psPath)) + Settings.Default.PSPath = findPTRDirDialogue.SelectedPath; + } + } + + private bool checkPath(string path, bool alert = true) + { + if (!File.Exists(path)) + { + planetsideVersion.Text = "Not found"; + planetsideVersion.ForeColor = System.Drawing.Color.Red; + + if (alert) + MessageBox.Show("Cannot open " + PS_EXE_NAME + " (check the selected directory)", + "Cannot Find Executable", MessageBoxButtons.OK, MessageBoxIcon.Error); + + return false; + } + + var versionInfo = FileVersionInfo.GetVersionInfo(path); + + if (versionInfo.FileVersion != "") + { + planetsideVersion.Text = "Version " + versionInfo.FileVersion; + planetsideVersion.ForeColor = System.Drawing.Color.Green; + } + else + { + planetsideVersion.Text = "Unknown version"; + planetsideVersion.ForeColor = System.Drawing.Color.Yellow; + } + + return true; + } + + private void launchArgs_TextChanged(object sender, EventArgs e) + { + if (Settings.Default.ExtraArgs != launchArgs.Text) + { + Settings.Default.ExtraArgs = this.launchArgs.Text; + } + } + + private void clearOnLaunch_CheckedChanged(object sender, EventArgs e) + { + Settings.Default.ClearOutputOnLaunch = this.clearOnLaunch.Checked; + } + + private void button1_Click_1(object sender, EventArgs e) + { + this.DialogResult = DialogResult.OK; + } + } +} diff --git a/PS2ModLauncher/SettingsForm.resx b/PS2ModLauncher/SettingsForm.resx new file mode 100644 index 0000000..113f692 --- /dev/null +++ b/PS2ModLauncher/SettingsForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/PS2ModLauncher/Util.cs b/PS2ModLauncher/Util.cs new file mode 100644 index 0000000..57569ef --- /dev/null +++ b/PS2ModLauncher/Util.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; + +namespace PSLauncher +{ + public static class ISynchronizeInvokeExtensions + { + public static void SafeInvoke(this T @this, Action action) where T : ISynchronizeInvoke + { + if (@this.InvokeRequired) + { + @this.Invoke(action, new object[] { @this }); + } + else + { + action(@this); + } + } + } +} diff --git a/PS2ModLauncher/app.config b/PS2ModLauncher/app.config index 81d3539..f921852 100644 --- a/PS2ModLauncher/app.config +++ b/PS2ModLauncher/app.config @@ -13,6 +13,15 @@ + + False + + + False + + + True + \ No newline at end of file