diff --git a/Test_Merge/F1TVEmulator.cs b/Test_Merge/F1TVEmulator.cs index c75fbaa..c50d654 100644 --- a/Test_Merge/F1TVEmulator.cs +++ b/Test_Merge/F1TVEmulator.cs @@ -66,36 +66,38 @@ namespace Test_Merge StartCookieRecovering(); string value = ""; List cookies = new List(); - using (var reader = new StreamReader(COOKIES_CSV_FILENAME)) + if (File.Exists(COOKIES_CSV_FILENAME)) { - // Read the header row and validate column order - string header = reader.ReadLine(); - string[] expectedColumns = { "host_key", "name", "value", "path", "expires_utc", "is_secure", "is_httponly" }; - string[] actualColumns = header.Split(','); - for (int i = 0; i < expectedColumns.Length; i++) + using (var reader = new StreamReader(COOKIES_CSV_FILENAME)) { - if (expectedColumns[i] != actualColumns[i]) + // Read the header row and validate column order + string header = reader.ReadLine(); + string[] expectedColumns = { "host_key", "name", "value", "path", "expires_utc", "is_secure", "is_httponly" }; + string[] actualColumns = header.Split(','); + for (int i = 0; i < expectedColumns.Length; i++) { - throw new InvalidOperationException($"Expected column '{expectedColumns[i]}' at index {i} but found '{actualColumns[i]}'"); + if (expectedColumns[i] != actualColumns[i]) + { + throw new InvalidOperationException($"Expected column '{expectedColumns[i]}' at index {i} but found '{actualColumns[i]}'"); + } } - } - // Read each data row and parse values into a Cookie object - while (!reader.EndOfStream) - { - string line = reader.ReadLine(); - string[] fields = line.Split(','); - - string hostname = fields[0]; - string cookieName = fields[1]; - - if (hostname == host && cookieName == name) + // Read each data row and parse values into a Cookie object + while (!reader.EndOfStream) { - value = fields[2]; + string line = reader.ReadLine(); + string[] fields = line.Split(','); + + string hostname = fields[0]; + string cookieName = fields[1]; + + if (hostname == host && cookieName == name) + { + value = fields[2]; + } } } } - return value; } /// @@ -111,8 +113,9 @@ namespace Test_Merge string loginCookieValue = GetCookie(COOKIE_HOST, loginCookieName); string loginSessionValue = GetCookie(COOKIE_HOST, loginSessionCookieName); - int windowWidth = 1920; - int windowHeight = 768; + //Cookie retreival has gone wrong (usually its because of python not being installed properly) + if (loginCookieValue == "" || loginSessionValue == "") + return 100; var service = FirefoxDriverService.CreateDefaultService(GECKODRIVER_FILENAME); service.Host = "127.0.0.1"; diff --git a/Test_Merge/Form1.cs b/Test_Merge/Form1.cs index ce44f9a..1f6089b 100644 --- a/Test_Merge/Form1.cs +++ b/Test_Merge/Form1.cs @@ -255,6 +255,9 @@ namespace Test_Merge string message = ""; switch (errorCode) { + case 100: + message = "Error " + errorCode + " Could not recover cookies. It could be because of an improper installation of python or bad cookies in the chrome database. Please try to log on to the F1TV using chrome again"; + break; case 101: message = "Error " + errorCode + " Could not start the driver. It could be because an other instance is runnin make sure you closed them all before trying again"; break; diff --git a/Test_Merge/Settings.Designer.cs b/Test_Merge/Settings.Designer.cs index 1064846..3f8dd57 100644 --- a/Test_Merge/Settings.Designer.cs +++ b/Test_Merge/Settings.Designer.cs @@ -226,6 +226,7 @@ // this.btnResetDriver.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnResetDriver.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51))))); + this.btnResetDriver.Enabled = false; this.btnResetDriver.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btnResetDriver.ForeColor = System.Drawing.Color.White; this.btnResetDriver.Location = new System.Drawing.Point(748, 20); @@ -246,7 +247,7 @@ this.btnRefresh.Name = "btnRefresh"; this.btnRefresh.Size = new System.Drawing.Size(193, 33); this.btnRefresh.TabIndex = 1; - this.btnRefresh.Text = "Get a newer image"; + this.btnRefresh.Text = "Start the browser"; this.btnRefresh.UseVisualStyleBackColor = false; this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click); // @@ -273,6 +274,7 @@ // btnCreateWindow // this.btnCreateWindow.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51))))); + this.btnCreateWindow.Enabled = false; this.btnCreateWindow.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btnCreateWindow.ForeColor = System.Drawing.Color.White; this.btnCreateWindow.Location = new System.Drawing.Point(213, 23); @@ -298,6 +300,7 @@ // btnCreatZone // this.btnCreatZone.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51))))); + this.btnCreatZone.Enabled = false; this.btnCreatZone.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btnCreatZone.ForeColor = System.Drawing.Color.White; this.btnCreatZone.Location = new System.Drawing.Point(6, 23); diff --git a/Test_Merge/Settings.cs b/Test_Merge/Settings.cs index 9d62ef2..358c268 100644 --- a/Test_Merge/Settings.cs +++ b/Test_Merge/Settings.cs @@ -311,6 +311,9 @@ namespace Test_Merge private async void btnRefresh_Click(object sender, EventArgs e) { btnRefresh.Enabled = false; + btnCreatZone.Enabled = false; + btnCreateWindow.Enabled = false; + btnResetDriver.Enabled = false; if (Emulator == null || Emulator.GrandPrixUrl != tbxGpUrl.Text) { Emulator = new F1TVEmulator(tbxGpUrl.Text); @@ -325,6 +328,9 @@ namespace Test_Merge string message; switch (errorCode) { + case 100: + message = "Error " + errorCode + " Could not recover cookies. It could be because of an improper installation of python or bad cookies in the chrome database. Please try to log on to the F1TV using chrome again"; + break; case 101: message = "Error " + errorCode + " Could not start the driver. It could be because an other instance is runnin make sure you closed them all before trying again"; break; @@ -359,6 +365,10 @@ namespace Test_Merge pbxPreview.Image = Emulator.Screenshot(); } btnRefresh.Enabled = true; + btnCreatZone.Enabled = true; + btnCreateWindow.Enabled = true; + btnResetDriver.Enabled = true; + btnRefresh.Text = "Get a newer image"; } private void Settings_FormClosing(object sender, FormClosingEventArgs e) @@ -462,6 +472,5 @@ namespace Test_Merge e.Graphics.DrawString(gpbx.Text, gpbx.Font, brush, textPosition); } } - } }