From 2f34d81f55c063103220f0d477967e08c4c61b36 Mon Sep 17 00:00:00 2001 From: jarig Date: Tue, 19 Jan 2016 10:32:21 +0200 Subject: [PATCH] http redirection bugfix(on login), UI improvements --- EliteReporter/Forms/LoginForm.cs | 4 +- EliteReporter/Forms/ReportForm.Designer.cs | 2 +- EliteReporter/Forms/ReportForm.cs | 44 +++++++++++++--------- EliteReporter/Utils/EDAPI.cs | 26 ++++++++----- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/EliteReporter/Forms/LoginForm.cs b/EliteReporter/Forms/LoginForm.cs index 3e663a9..57c0245 100644 --- a/EliteReporter/Forms/LoginForm.cs +++ b/EliteReporter/Forms/LoginForm.cs @@ -48,8 +48,7 @@ private void loginButton_Click(object sender, EventArgs e) var profile = edapi.getProfile(); if (profile != null) { - MessageBox.Show("Greetings commander " + profile.CommanderName, "Welcome!"); - Dispose(); + this.DialogResult = DialogResult.OK; } else { @@ -66,6 +65,7 @@ private void loginButton_Click(object sender, EventArgs e) private void closeButton_Click(object sender, EventArgs e) { + this.DialogResult = DialogResult.Cancel; this.Dispose(); } diff --git a/EliteReporter/Forms/ReportForm.Designer.cs b/EliteReporter/Forms/ReportForm.Designer.cs index 5885817..5c86b05 100644 --- a/EliteReporter/Forms/ReportForm.Designer.cs +++ b/EliteReporter/Forms/ReportForm.Designer.cs @@ -56,7 +56,7 @@ private void InitializeComponent() this.activateButton.Name = "activateButton"; this.activateButton.Size = new System.Drawing.Size(86, 40); this.activateButton.TabIndex = 0; - this.activateButton.Text = "Activate"; + this.activateButton.Text = "Login"; this.activateButton.UseVisualStyleBackColor = true; this.activateButton.Click += new System.EventHandler(this.activateButton_Click); // diff --git a/EliteReporter/Forms/ReportForm.cs b/EliteReporter/Forms/ReportForm.cs index 27a3a40..b36686f 100644 --- a/EliteReporter/Forms/ReportForm.cs +++ b/EliteReporter/Forms/ReportForm.cs @@ -103,6 +103,11 @@ private void analyzeScreenShot(string pathToBmp) private void activateButton_Click(object sender, EventArgs e) { + if (string.IsNullOrEmpty(commanderName)) + { + initialize(); + return; + } // Begin watching. if (watcher != null && watcher.EnableRaisingEvents) { @@ -165,12 +170,6 @@ private void ReportForm_Load(object sender, EventArgs e) } - private void showLoginForm() - { - var loginForm = new LoginForm(edapi); - loginForm.Show(); - } - private void ReportForm_FormClosing(object sender, FormClosingEventArgs e) { @@ -187,26 +186,35 @@ private void button1_Click(object sender, EventArgs e) Dispose(); } - private void ReportForm_Shown(object sender, EventArgs e) + private void initialize() { if (edapi.isLoginRequired()) { //show login form - showLoginForm(); + var loginForm = new LoginForm(edapi); + if (loginForm.ShowDialog(this) != DialogResult.OK) + { + toolStripStatusLabel1.Text = "Login was cancelled."; + activateButton.Text = "Login"; + return; + } + else + loginForm.Dispose(); } + commanderName = edapi.getProfile().CommanderName; + if (!string.IsNullOrEmpty(commanderName)) + toolStripStatusLabel1.Text = "Welcome CMDR " + commanderName + ". "; + if (Directory.Exists(Properties.Settings.Default.PicturesFolder)) + activateButton_Click(null, null); else { - commanderName = edapi.getProfile().CommanderName; - if (!string.IsNullOrEmpty(commanderName)) - toolStripStatusLabel1.Text = "Welcome CMDR " + commanderName + ". "; - if (Directory.Exists(Properties.Settings.Default.PicturesFolder)) - activateButton_Click(null, null); - else - { - toolStripStatusLabel1.Text = "Configure pictures folder in settings and press Activate button to start watching for missions!"; - } + toolStripStatusLabel1.Text = "Configure pictures folder in settings and press Activate button to start watching for missions!"; } - + } + + private void ReportForm_Shown(object sender, EventArgs e) + { + initialize(); } } } diff --git a/EliteReporter/Utils/EDAPI.cs b/EliteReporter/Utils/EDAPI.cs index 9cbae3b..c7fe168 100644 --- a/EliteReporter/Utils/EDAPI.cs +++ b/EliteReporter/Utils/EDAPI.cs @@ -44,7 +44,7 @@ public EDAPI() } } - private ResponseData makeRequest(string uri, Dictionary values = null) + private ResponseData makeRequest(string uri, Dictionary values = null, string rawData = "", string method = null) { if (uri.Equals("/")) uri = ""; @@ -53,20 +53,26 @@ private ResponseData makeRequest(string uri, Dictionary values = request.UserAgent = agent; var cc = new CookieContainer(); cc.Add(cookieContainer.GetCookies(new Uri(baseUrl))); - request.CookieContainer = cookieContainer; - if (values == null) + request.CookieContainer = cc; + if (values == null && string.IsNullOrEmpty(rawData)) request.Method = "GET"; else { - request.Method = "POST"; - string postData = ""; + if (method == null) + request.Method = "POST"; + else + request.Method = method; + string postData = rawData; - foreach (string key in values.Keys) + if (values != null) { - postData += HttpUtility.UrlEncode(key) + "=" - + HttpUtility.UrlEncode(values[key]) + "&"; + foreach (string key in values.Keys) + { + postData += HttpUtility.UrlEncode(key) + "=" + + HttpUtility.UrlEncode(values[key]) + "&"; + } + postData = postData.TrimEnd('&'); } - postData = postData.TrimEnd('&'); byte[] data = Encoding.ASCII.GetBytes(postData); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; @@ -117,7 +123,7 @@ private ResponseData makeRequest(string uri, Dictionary values = } } if (resp.Headers["Location"] != null) - return makeRequest(resp.Headers["Location"], values); + return makeRequest(resp.Headers["Location"], null, responseText, resp.Method); return new ResponseData() { Text = responseText,