From 50c74a8c4673a1783ebed3e826eb77575656e71b Mon Sep 17 00:00:00 2001 From: integralfx Date: Thu, 7 Feb 2019 16:36:02 +1100 Subject: [PATCH] Bug fixes, added config file, window height --- MemTestHelper/Form1.Designer.cs | 72 +++++++++--- MemTestHelper/Form1.cs | 202 +++++++++++++++++++++++++++----- 2 files changed, 229 insertions(+), 45 deletions(-) diff --git a/MemTestHelper/Form1.Designer.cs b/MemTestHelper/Form1.Designer.cs index 80c91ab..da9e9fb 100644 --- a/MemTestHelper/Form1.Designer.cs +++ b/MemTestHelper/Form1.Designer.cs @@ -51,7 +51,7 @@ private void InitializeComponent() this.tab_settings = new System.Windows.Forms.TabPage(); this.chk_start_min = new System.Windows.Forms.CheckBox(); this.chk_stop_at_total = new System.Windows.Forms.CheckBox(); - this.chk_stop_at_err = new System.Windows.Forms.CheckBox(); + this.chk_stop_on_err = new System.Windows.Forms.CheckBox(); this.txt_stop_at = new System.Windows.Forms.TextBox(); this.chk_stop_at = new System.Windows.Forms.CheckBox(); this.cbo_rows = new System.Windows.Forms.ComboBox(); @@ -69,6 +69,8 @@ private void InitializeComponent() this.txt_discord = new System.Windows.Forms.TextBox(); this.lbl_discord = new System.Windows.Forms.Label(); this.lbl_version = new System.Windows.Forms.Label(); + this.lbl_win_height = new System.Windows.Forms.Label(); + this.ud_win_height = new System.Windows.Forms.NumericUpDown(); this.tab_control.SuspendLayout(); this.tab_main.SuspendLayout(); this.tab_settings.SuspendLayout(); @@ -77,10 +79,12 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.ud_x_spacing)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.ud_x_offset)).BeginInit(); this.tab_about.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.ud_win_height)).BeginInit(); this.SuspendLayout(); // // tab_control // + this.tab_control.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom))); this.tab_control.Controls.Add(this.tab_main); this.tab_control.Controls.Add(this.tab_settings); this.tab_control.Controls.Add(this.tab_about); @@ -128,6 +132,7 @@ private void InitializeComponent() // // lst_coverage // + this.lst_coverage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom))); this.lst_coverage.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.hdr_no, this.hdr_coverage, @@ -283,12 +288,14 @@ private void InitializeComponent() // this.tab_settings.Controls.Add(this.chk_start_min); this.tab_settings.Controls.Add(this.chk_stop_at_total); - this.tab_settings.Controls.Add(this.chk_stop_at_err); + this.tab_settings.Controls.Add(this.chk_stop_on_err); this.tab_settings.Controls.Add(this.txt_stop_at); this.tab_settings.Controls.Add(this.chk_stop_at); this.tab_settings.Controls.Add(this.cbo_rows); this.tab_settings.Controls.Add(this.btn_center); + this.tab_settings.Controls.Add(this.ud_win_height); this.tab_settings.Controls.Add(this.ud_y_offset); + this.tab_settings.Controls.Add(this.lbl_win_height); this.tab_settings.Controls.Add(this.lbl_y_offset); this.tab_settings.Controls.Add(this.ud_y_spacing); this.tab_settings.Controls.Add(this.lbl_rows); @@ -328,17 +335,17 @@ private void InitializeComponent() this.chk_stop_at_total.Text = "Total"; this.chk_stop_at_total.UseVisualStyleBackColor = true; // - // chk_stop_at_err + // chk_stop_on_err // - this.chk_stop_at_err.AutoSize = true; - this.chk_stop_at_err.Checked = true; - this.chk_stop_at_err.CheckState = System.Windows.Forms.CheckState.Checked; - this.chk_stop_at_err.Location = new System.Drawing.Point(21, 157); - this.chk_stop_at_err.Name = "chk_stop_at_err"; - this.chk_stop_at_err.Size = new System.Drawing.Size(87, 17); - this.chk_stop_at_err.TabIndex = 4; - this.chk_stop_at_err.Text = "Stop on error"; - this.chk_stop_at_err.UseVisualStyleBackColor = true; + this.chk_stop_on_err.AutoSize = true; + this.chk_stop_on_err.Checked = true; + this.chk_stop_on_err.CheckState = System.Windows.Forms.CheckState.Checked; + this.chk_stop_on_err.Location = new System.Drawing.Point(21, 157); + this.chk_stop_on_err.Name = "chk_stop_on_err"; + this.chk_stop_on_err.Size = new System.Drawing.Size(87, 17); + this.chk_stop_on_err.TabIndex = 4; + this.chk_stop_on_err.Text = "Stop on error"; + this.chk_stop_on_err.UseVisualStyleBackColor = true; // // txt_stop_at // @@ -538,18 +545,52 @@ private void InitializeComponent() this.lbl_version.TabIndex = 0; this.lbl_version.Text = "Version 1.9.1"; // + // lbl_win_height + // + this.lbl_win_height.AutoSize = true; + this.lbl_win_height.Location = new System.Drawing.Point(18, 204); + this.lbl_win_height.Name = "lbl_win_height"; + this.lbl_win_height.Size = new System.Drawing.Size(81, 13); + this.lbl_win_height.TabIndex = 0; + this.lbl_win_height.Text = "Window height:"; + // + // ud_win_height + // + this.ud_win_height.Location = new System.Drawing.Point(100, 202); + this.ud_win_height.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.ud_win_height.Minimum = new decimal(new int[] { + 420, + 0, + 0, + 0}); + this.ud_win_height.Name = "ud_win_height"; + this.ud_win_height.Size = new System.Drawing.Size(50, 20); + this.ud_win_height.TabIndex = 1; + this.ud_win_height.Value = new decimal(new int[] { + 420, + 0, + 0, + 0}); + this.ud_win_height.ValueChanged += new System.EventHandler(this.ud_win_height_ValueChanged); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(226, 381); this.Controls.Add(this.tab_control); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; + this.MaximumSize = new System.Drawing.Size(242, 1000); + this.MinimumSize = new System.Drawing.Size(242, 0); this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "MemTestHelper"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); + this.Load += new System.EventHandler(this.Form1_Load); this.Resize += new System.EventHandler(this.Form1_Resize); this.tab_control.ResumeLayout(false); this.tab_main.ResumeLayout(false); @@ -562,6 +603,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.ud_x_offset)).EndInit(); this.tab_about.ResumeLayout(false); this.tab_about.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.ud_win_height)).EndInit(); this.ResumeLayout(false); } @@ -603,12 +645,14 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox chk_stop_at_total; private System.Windows.Forms.TextBox txt_stop_at; private System.Windows.Forms.CheckBox chk_stop_at; - private System.Windows.Forms.CheckBox chk_stop_at_err; + private System.Windows.Forms.CheckBox chk_stop_on_err; private System.Windows.Forms.TextBox txt_discord; private System.Windows.Forms.Label lbl_discord; private System.Windows.Forms.Label lbl_version; private System.Windows.Forms.CheckBox chk_start_min; private System.Windows.Forms.Button btn_hide; + private System.Windows.Forms.NumericUpDown ud_win_height; + private System.Windows.Forms.Label lbl_win_height; } } diff --git a/MemTestHelper/Form1.cs b/MemTestHelper/Form1.cs index 9da3b96..842e1b1 100644 --- a/MemTestHelper/Form1.cs +++ b/MemTestHelper/Form1.cs @@ -118,21 +118,19 @@ public Form1() }); } - public int get_selected_num_threads() - { - return (int)cbo_threads.SelectedItem; - } + // event handling - public int get_selected_num_rows() + private void Form1_Load(object sender, EventArgs e) { - return (int)cbo_rows.SelectedItem; + load_cfg(); + update_form_height(); + update_lst_coverage_items(); } - // event handling - private void Form1_FormClosing(object sender, FormClosingEventArgs e) { close_memtests(); + save_cfg(); } private void Form1_Resize(object sender, EventArgs e) @@ -190,7 +188,6 @@ private void Form1_Resize(object sender, EventArgs e) TopMost = false; } })); - break; } } @@ -220,7 +217,7 @@ private void btn_run_Click(object sender, EventArgs e) chk_stop_at.Enabled = false; txt_stop_at.Enabled = false; chk_stop_at_total.Enabled = false; - chk_stop_at_err.Enabled = false; + chk_stop_on_err.Enabled = false; chk_start_min.Enabled = false; // run in background as start_memtests can block @@ -260,7 +257,7 @@ private void btn_stop_Click(object sender, EventArgs e) txt_stop_at.Enabled = true; chk_stop_at_total.Enabled = true; } - chk_stop_at_err.Enabled = true; + chk_stop_on_err.Enabled = true; chk_start_min.Enabled = true; // wait for all memtests to fully stop @@ -339,21 +336,7 @@ private void cbo_rows_SelectionChangeCommitted(object sender, EventArgs e) private void cbo_threads_SelectionChangeCommitted(object sender, EventArgs e) { - int threads = (int)cbo_threads.SelectedItem; - var items = lst_coverage.Items; - if (threads < items.Count) - { - for (int i = items.Count - 1; i > threads; i--) - items.RemoveAt(i); - } - else - { - for (int i = items.Count; i <= threads; i++) - { - string[] row = { i.ToString(), "-", "-" }; - lst_coverage.Items.Add(new ListViewItem(row)); - } - } + update_lst_coverage_items(); cbo_rows.Items.Clear(); init_cbo_rows(); @@ -374,8 +357,144 @@ private void chk_stop_at_CheckedChanged(object sender, EventArgs e) } } + private void ud_win_height_ValueChanged(object sender, EventArgs e) + { + update_form_height(); + } + // helper functions + // TODO: error checking + private bool load_cfg() + { + string[] valid_keys = { "ram", "threads", "x_offset", "y_offset", + "x_spacing", "y_spacing", "rows", "stop_at", + "stop_at_value", "stop_at_total", "stop_on_error", + "start_min", "win_height" }; + + try + { + string[] lines = File.ReadAllLines(CFG_FILENAME); + Dictionary cfg = new Dictionary(); + + foreach (string l in lines) + { + string[] s = l.Split('='); + if (s.Length != 2) continue; + s[0] = s[0].Trim(); + s[1] = s[1].Trim(); + + if (valid_keys.Contains(s[0])) + { + if (s[1].Length == 0) continue; + + int v; + if (Int32.TryParse(s[1], out v)) + cfg.Add(s[0], v); + else return false; + } + else return false; + } + + foreach (KeyValuePair kv in cfg) + { + switch (kv.Key) + { + case "ram": + txt_ram.Text = kv.Value.ToString(); + break; + case "threads": + cbo_threads.SelectedItem = kv.Value; + break; + + case "x_offset": + ud_x_offset.Value = kv.Value; + break; + case "y_offset": + ud_y_offset.Value = kv.Value; + break; + + case "x_spacing": + ud_x_spacing.Value = kv.Value; + break; + case "y_spacing": + ud_y_spacing.Value = kv.Value; + break; + + case "stop_at": + chk_stop_at.Checked = kv.Value != 0; + break; + case "stop_at_value": + txt_stop_at.Text = kv.Value.ToString(); + break; + case "stop_at_total": + chk_stop_at_total.Checked = kv.Value != 0; + break; + + case "stop_on_error": + chk_stop_on_err.Checked = kv.Value != 0; + break; + + case "start_min": + chk_start_min.Checked = kv.Value != 0; + break; + + case "win_height": + ud_win_height.Value = kv.Value; + break; + } + } + } + catch(FileNotFoundException e) + { + return false; + } + + return true; + } + + private bool save_cfg() + { + try { + var file = new StreamWriter(CFG_FILENAME); + List lines = new List(); + + lines.Add($"ram = {txt_ram.Text}"); + lines.Add($"threads = {(int)cbo_threads.SelectedItem}"); + + lines.Add($"x_offset = {ud_x_offset.Value}"); + lines.Add($"y_offset = {ud_y_offset.Value}"); + lines.Add($"x_spacing = {ud_x_spacing.Value}"); + lines.Add($"y_spacing = {ud_y_spacing.Value}"); + lines.Add($"rows = {cbo_rows.SelectedItem}"); + + lines.Add(string.Format("stop_at = {0}", chk_stop_at.Checked ? 1 : 0)); + lines.Add($"stop_at_value = {txt_stop_at.Text}"); + lines.Add(string.Format("stop_at_total = {0}", chk_stop_at_total.Checked ? 1 : 0)); + lines.Add(string.Format("stop_on_error = {0}", chk_stop_on_err.Checked ? 1 : 0)); + + lines.Add(string.Format("start_min = {0}", chk_start_min.Checked ? 1 : 0)); + + lines.Add($"win_height = {ud_win_height.Value}"); + + foreach (string l in lines) + file.WriteLine(l); + + file.Close(); + } + catch (Exception e) + { + return false; + } + + return true; + } + + private void update_form_height() + { + Size = new Size(Size.Width, (int)ud_win_height.Value); + } + private bool validate_input() { ComputerInfo ci = new ComputerInfo(); @@ -477,6 +596,25 @@ private void init_lst_coverage() } } + private void update_lst_coverage_items() + { + int threads = (int)cbo_threads.SelectedItem; + var items = lst_coverage.Items; + if (threads < items.Count) + { + for (int i = items.Count - 1; i > threads; i--) + items.RemoveAt(i); + } + else + { + for (int i = items.Count; i <= threads; i++) + { + string[] row = { i.ToString(), "-", "-" }; + lst_coverage.Items.Add(new ListViewItem(row)); + } + } + } + private void init_cbo_threads() { for (int i = 0; i < MAX_THREADS; i++) @@ -542,7 +680,8 @@ private void move_memtests() y_offset = (int)ud_y_offset.Value, x_spacing = (int)ud_x_spacing.Value - 5, y_spacing = (int)ud_y_spacing.Value - 3, - rows = (int)cbo_rows.SelectedItem; + rows = (int)cbo_rows.SelectedItem, + cols = (int)cbo_threads.SelectedItem / rows; Parallel.For(0, (int)cbo_threads.SelectedItem, i => { @@ -550,8 +689,8 @@ private void move_memtests() if (state == null) return; IntPtr hwnd = state.proc.MainWindowHandle; - int c = i / rows, - r = i % rows, + int r = i / cols, + c = i % cols, x = c * MEMTEST_WIDTH + c * x_spacing + x_offset, y = r * MEMTEST_HEIGHT + r * y_spacing + y_offset; @@ -643,7 +782,7 @@ private void update_coverage_info(bool should_check = true) } // check error count - if (chk_stop_at_err.Checked) + if (chk_stop_on_err.Checked) { if (errors > 0) { @@ -855,7 +994,8 @@ private string ControlGetText(IntPtr hwnd, string class_name) MEMTEST_EDT_RAM = "Edit1", MEMTEST_STATIC_COVERAGE = "Static1", // If you find this free version useful... - MEMTEST_STATIC_FREE_VER = "Static2"; + MEMTEST_STATIC_FREE_VER = "Static2", + CFG_FILENAME = "MemTestHelper.cfg"; private const int MEMTEST_WIDTH = 217, MEMTEST_HEIGHT = 247,