From 37cec437e360b738519941419866cd5fcbb0915e Mon Sep 17 00:00:00 2001 From: Maurice Beckman Date: Wed, 21 May 2025 20:12:16 +0200 Subject: [PATCH 1/3] #46 new settings --- .../Forms/ConfigAndGenerate.Designer.cs | 86 ++++++++++++++----- .../Properties/AssemblyInfo.cs | 4 +- nppRandomStringGenerator/Storage/Settings.cs | 62 ++++++++----- .../Storage/SettingsModel.cs | 4 +- .../nppRandomStringGeneratorSettings.ini | 6 +- 5 files changed, 113 insertions(+), 49 deletions(-) diff --git a/nppRandomStringGenerator/Forms/ConfigAndGenerate.Designer.cs b/nppRandomStringGenerator/Forms/ConfigAndGenerate.Designer.cs index 958e4fb..dac5d21 100644 --- a/nppRandomStringGenerator/Forms/ConfigAndGenerate.Designer.cs +++ b/nppRandomStringGenerator/Forms/ConfigAndGenerate.Designer.cs @@ -55,6 +55,7 @@ private void InitializeComponent() this.RadioButtonInline = new System.Windows.Forms.RadioButton(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); + this.bReset = new System.Windows.Forms.Button(); this.label11 = new System.Windows.Forms.Label(); this.label13 = new System.Windows.Forms.Label(); this.RadioButtonCurrent = new System.Windows.Forms.RadioButton(); @@ -74,7 +75,6 @@ private void InitializeComponent() this.ButtonCancel = new System.Windows.Forms.Button(); this.TabControl1 = new System.Windows.Forms.TabControl(); this.TabPageRandom = new System.Windows.Forms.TabPage(); - this.bReset = new System.Windows.Forms.Button(); this.TabPageGUID = new System.Windows.Forms.TabPage(); this.button1 = new System.Windows.Forms.Button(); this.label20 = new System.Windows.Forms.Label(); @@ -83,6 +83,9 @@ private void InitializeComponent() this.NumericUpDownGUIDQuantity = new System.Windows.Forms.NumericUpDown(); this.label17 = new System.Windows.Forms.Label(); this.label18 = new System.Windows.Forms.Label(); + this.CheckboxDarkMode = new System.Windows.Forms.CheckBox(); + this.label21 = new System.Windows.Forms.Label(); + this.TextboxSuffix = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.NumericUpDownLength)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NumericUpDownQuantity)).BeginInit(); this.groupBox1.SuspendLayout(); @@ -354,7 +357,7 @@ private void InitializeComponent() // this.ButtonGenerate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.ButtonGenerate.Font = new System.Drawing.Font("Segoe UI Semibold", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.ButtonGenerate.Location = new System.Drawing.Point(275, 388); + this.ButtonGenerate.Location = new System.Drawing.Point(275, 406); this.ButtonGenerate.Name = "ButtonGenerate"; this.ButtonGenerate.Size = new System.Drawing.Size(120, 25); this.ButtonGenerate.TabIndex = 23; @@ -397,7 +400,7 @@ private void InitializeComponent() this.linkLabel1.AutoSize = true; this.linkLabel1.Font = new System.Drawing.Font("Segoe UI", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.AlwaysUnderline; - this.linkLabel1.Location = new System.Drawing.Point(296, 346); + this.linkLabel1.Location = new System.Drawing.Point(296, 341); this.linkLabel1.Name = "linkLabel1"; this.linkLabel1.Size = new System.Drawing.Size(58, 12); this.linkLabel1.TabIndex = 36; @@ -406,6 +409,18 @@ private void InitializeComponent() this.toolTip1.SetToolTip(this.linkLabel1, "Click here to reset to default settings"); this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); // + // bReset + // + this.bReset.Image = global::nppRandomStringGenerator.Properties.Resources.undo; + this.bReset.Location = new System.Drawing.Point(383, 166); + this.bReset.Margin = new System.Windows.Forms.Padding(0); + this.bReset.Name = "bReset"; + this.bReset.Size = new System.Drawing.Size(24, 24); + this.bReset.TabIndex = 42; + this.toolTip1.SetToolTip(this.bReset, "Restore default symbols"); + this.bReset.UseVisualStyleBackColor = true; + this.bReset.Click += new System.EventHandler(this.bReset_Click); + // // label11 // this.label11.AutoSize = true; @@ -442,7 +457,7 @@ private void InitializeComponent() this.groupBox1.Controls.Add(this.RadioButtonNew); this.groupBox1.Controls.Add(this.RadioButtonCurrent); this.groupBox1.Controls.Add(this.RadioButtonInline); - this.groupBox1.Location = new System.Drawing.Point(4, 315); + this.groupBox1.Location = new System.Drawing.Point(4, 333); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(265, 98); this.groupBox1.TabIndex = 30; @@ -493,7 +508,7 @@ private void InitializeComponent() this.CheckboxCloseNoMessage.Checked = true; this.CheckboxCloseNoMessage.CheckState = System.Windows.Forms.CheckState.Checked; this.CheckboxCloseNoMessage.Font = new System.Drawing.Font("Segoe UI", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.CheckboxCloseNoMessage.Location = new System.Drawing.Point(278, 361); + this.CheckboxCloseNoMessage.Location = new System.Drawing.Point(278, 356); this.CheckboxCloseNoMessage.Name = "CheckboxCloseNoMessage"; this.CheckboxCloseNoMessage.Size = new System.Drawing.Size(135, 16); this.CheckboxCloseNoMessage.TabIndex = 34; @@ -507,7 +522,7 @@ private void InitializeComponent() this.CheckboxSaveOnClose.Checked = true; this.CheckboxSaveOnClose.CheckState = System.Windows.Forms.CheckState.Checked; this.CheckboxSaveOnClose.Font = new System.Drawing.Font("Segoe UI", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.CheckboxSaveOnClose.Location = new System.Drawing.Point(275, 346); + this.CheckboxSaveOnClose.Location = new System.Drawing.Point(275, 341); this.CheckboxSaveOnClose.Name = "CheckboxSaveOnClose"; this.CheckboxSaveOnClose.Size = new System.Drawing.Size(15, 14); this.CheckboxSaveOnClose.TabIndex = 35; @@ -616,7 +631,7 @@ private void InitializeComponent() this.ButtonCancel.Enabled = false; this.ButtonCancel.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.ButtonCancel.ForeColor = System.Drawing.Color.White; - this.ButtonCancel.Location = new System.Drawing.Point(398, 389); + this.ButtonCancel.Location = new System.Drawing.Point(398, 407); this.ButtonCancel.Margin = new System.Windows.Forms.Padding(0); this.ButtonCancel.Name = "ButtonCancel"; this.ButtonCancel.Size = new System.Drawing.Size(54, 24); @@ -634,12 +649,14 @@ private void InitializeComponent() this.TabControl1.Multiline = true; this.TabControl1.Name = "TabControl1"; this.TabControl1.SelectedIndex = 0; - this.TabControl1.Size = new System.Drawing.Size(464, 313); + this.TabControl1.Size = new System.Drawing.Size(464, 331); this.TabControl1.TabIndex = 44; // // TabPageRandom // this.TabPageRandom.BackColor = System.Drawing.SystemColors.Control; + this.TabPageRandom.Controls.Add(this.label21); + this.TabPageRandom.Controls.Add(this.TextboxSuffix); this.TabPageRandom.Controls.Add(this.bReset); this.TabPageRandom.Controls.Add(this.label1); this.TabPageRandom.Controls.Add(this.NumericUpDownLength); @@ -674,22 +691,10 @@ private void InitializeComponent() this.TabPageRandom.Location = new System.Drawing.Point(4, 22); this.TabPageRandom.Name = "TabPageRandom"; this.TabPageRandom.Padding = new System.Windows.Forms.Padding(3); - this.TabPageRandom.Size = new System.Drawing.Size(456, 287); + this.TabPageRandom.Size = new System.Drawing.Size(456, 305); this.TabPageRandom.TabIndex = 0; this.TabPageRandom.Text = "Random strings"; // - // bReset - // - this.bReset.Image = global::nppRandomStringGenerator.Properties.Resources.undo; - this.bReset.Location = new System.Drawing.Point(383, 166); - this.bReset.Margin = new System.Windows.Forms.Padding(0); - this.bReset.Name = "bReset"; - this.bReset.Size = new System.Drawing.Size(24, 24); - this.bReset.TabIndex = 42; - this.toolTip1.SetToolTip(this.bReset, "Restore default symbols"); - this.bReset.UseVisualStyleBackColor = true; - this.bReset.Click += new System.EventHandler(this.bReset_Click); - // // TabPageGUID // this.TabPageGUID.BackColor = System.Drawing.SystemColors.Control; @@ -800,13 +805,46 @@ private void InitializeComponent() this.label18.TabIndex = 31; this.label18.Text = "(min:1, max:4.096.000)"; // + // CheckboxDarkMode + // + this.CheckboxDarkMode.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.CheckboxDarkMode.AutoSize = true; + this.CheckboxDarkMode.Checked = true; + this.CheckboxDarkMode.CheckState = System.Windows.Forms.CheckState.Checked; + this.CheckboxDarkMode.Font = new System.Drawing.Font("Segoe UI", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.CheckboxDarkMode.Location = new System.Drawing.Point(278, 373); + this.CheckboxDarkMode.Name = "CheckboxDarkMode"; + this.CheckboxDarkMode.Size = new System.Drawing.Size(67, 16); + this.CheckboxDarkMode.TabIndex = 45; + this.CheckboxDarkMode.Text = "Dark Mode"; + this.CheckboxDarkMode.UseVisualStyleBackColor = true; + this.CheckboxDarkMode.Visible = false; + // + // label21 + // + this.label21.AutoSize = true; + this.label21.Location = new System.Drawing.Point(15, 281); + this.label21.Name = "label21"; + this.label21.Size = new System.Drawing.Size(39, 13); + this.label21.TabIndex = 44; + this.label21.Text = "Suffix:"; + // + // TextboxSuffix + // + this.TextboxSuffix.Location = new System.Drawing.Point(179, 278); + this.TextboxSuffix.Name = "TextboxSuffix"; + this.TextboxSuffix.Size = new System.Drawing.Size(265, 22); + this.TextboxSuffix.TabIndex = 43; + // // ConfigAndGenerate // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.AutoSize = true; this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.ClientSize = new System.Drawing.Size(464, 420); + this.BackColor = System.Drawing.SystemColors.Control; + this.ClientSize = new System.Drawing.Size(464, 438); + this.Controls.Add(this.CheckboxDarkMode); this.Controls.Add(this.TabControl1); this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.linkLabel1); @@ -815,6 +853,7 @@ private void InitializeComponent() this.Controls.Add(this.groupBox1); this.Controls.Add(this.ButtonGenerate); this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.ForeColor = System.Drawing.SystemColors.ControlText; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.MaximizeBox = false; this.MinimizeBox = false; @@ -897,5 +936,8 @@ private void InitializeComponent() private System.Windows.Forms.Label label20; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button bReset; + private System.Windows.Forms.CheckBox CheckboxDarkMode; + private System.Windows.Forms.Label label21; + private System.Windows.Forms.TextBox TextboxSuffix; } } \ No newline at end of file diff --git a/nppRandomStringGenerator/Properties/AssemblyInfo.cs b/nppRandomStringGenerator/Properties/AssemblyInfo.cs index 404b9ed..388ea71 100644 --- a/nppRandomStringGenerator/Properties/AssemblyInfo.cs +++ b/nppRandomStringGenerator/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.9.5")] -[assembly: AssemblyFileVersion("1.9.5")] +[assembly: AssemblyVersion("1.9.6")] +[assembly: AssemblyFileVersion("1.9.6")] diff --git a/nppRandomStringGenerator/Storage/Settings.cs b/nppRandomStringGenerator/Storage/Settings.cs index f20922e..96d1f89 100644 --- a/nppRandomStringGenerator/Storage/Settings.cs +++ b/nppRandomStringGenerator/Storage/Settings.cs @@ -4,7 +4,8 @@ using System.Text; using System.Windows.Forms; using nppRandomStringGenerator.Storage.Models; -using System.Linq; +using System.Collections.Generic; +using System.Security.Cryptography; namespace nppRandomStringGenerator.Storage { @@ -44,21 +45,42 @@ public void Load(bool reset = false) { settings = DeserializeIni(FilePath); - - if (settings.Appversion != "1.9.0") + + if (settings.Appversion != "1.9.6") { SettingsModel defaults = DeserializeIniFromString(Resources.nppRandomStringGeneratorSettings); - for (int i=0; i < defaults.ConfigItems.Length; i++) + foreach (ConfigItem configitem in defaults.ConfigItems) { - if (settings.ConfigItems[i] == null) + if (!settings.ConfigItems.Exists(c => c.Name == configitem.Name)) { - settings.ConfigItems[i] = defaults.ConfigItems[i]; + settings.ConfigItems.Add(configitem); } } settings.Appname = "nppRandomStringGenerator"; - settings.Appversion = "1.9.0"; + settings.Appversion = "1.9.6"; } + //else + //{ + // string check = ""; + // foreach (ConfigItem configitem in settings.ConfigItems) + // { + // check += configitem.Name + "|"; + // } + // check = check.TrimEnd('|'); + + // string checkHash; + // using (MD5 md5 = MD5.Create()) + // { + // byte[] hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(check)); + // checkHash = BitConverter.ToString(hashBytes).Replace("-", "").ToUpperInvariant(); + // } + // if ( check != "392FD30BC7A07D4CBD4F176F9C57A835") + // { + // MessageBox.Show("Unknown settings found. Resetting to defaults.", "nppRandomStringGenerator", MessageBoxButtons.OK); + + // } + //} } catch (Exception ex) { @@ -68,8 +90,10 @@ public void Load(bool reset = false) private SettingsModel DeserializeIni(string ini) { - SettingsModel tmp = new SettingsModel(); - tmp.ConfigItems = new ConfigItem[25]; + SettingsModel tmp = new SettingsModel + { + ConfigItems = new List() + }; using (FileStream stream = new FileStream(ini, FileMode.Open, FileAccess.Read, FileShare.Read)) { @@ -83,16 +107,13 @@ private SettingsModel DeserializeIni(string ini) parts = line.Split('='); tmp.Appversion = parts[1]; - int i = 0; - while (!reader.EndOfStream || i >= 25) + while (!reader.EndOfStream) { line = reader.ReadLine(); if (line == "" || line == null) break; parts = line.Split(new char[] { '=' }, 2); - tmp.ConfigItems[i] = new ConfigItem { Name = parts[0], Value = parts[1] }; - - i++; + tmp.ConfigItems.Add(new ConfigItem { Name = parts[0], Value = parts[1] }); } } } @@ -102,8 +123,10 @@ private SettingsModel DeserializeIni(string ini) private SettingsModel DeserializeIniFromString(string ini) { - SettingsModel tmp = new SettingsModel(); - tmp.ConfigItems = new ConfigItem[25]; + SettingsModel tmp = new SettingsModel + { + ConfigItems = new List() + }; using (StringReader reader = new StringReader(ini)) { @@ -115,16 +138,13 @@ private SettingsModel DeserializeIniFromString(string ini) parts = line.Split('='); tmp.Appversion = parts[1]; - int i = 0; - while (line != "" || i >= 25) + while (line != "") { line = reader.ReadLine(); if (line == "" || line == null) break; parts = line.Split(new char[] { '=' }, 2); - tmp.ConfigItems[i] = new ConfigItem { Name = parts[0], Value = parts[1] }; - - i++; + tmp.ConfigItems.Add(new ConfigItem { Name = parts[0], Value = parts[1] }); } } diff --git a/nppRandomStringGenerator/Storage/SettingsModel.cs b/nppRandomStringGenerator/Storage/SettingsModel.cs index a274840..b009b2d 100644 --- a/nppRandomStringGenerator/Storage/SettingsModel.cs +++ b/nppRandomStringGenerator/Storage/SettingsModel.cs @@ -1,4 +1,4 @@ -using System; +using System.Collections.Generic; namespace nppRandomStringGenerator.Storage.Models { @@ -6,7 +6,7 @@ public class SettingsModel { public string Appname { get; set; } public string Appversion { get; set; } - public ConfigItem[] ConfigItems { get; set; } + public List ConfigItems { get; set; } } public class ConfigItem diff --git a/nppRandomStringGenerator/Storage/nppRandomStringGeneratorSettings.ini b/nppRandomStringGenerator/Storage/nppRandomStringGeneratorSettings.ini index a3b2c80..d8f2b04 100644 --- a/nppRandomStringGenerator/Storage/nppRandomStringGeneratorSettings.ini +++ b/nppRandomStringGenerator/Storage/nppRandomStringGeneratorSettings.ini @@ -1,5 +1,5 @@ appname=nppRandomStringGenerator -appversion=1.9.0 +appversion=1.9.6 NumericUpDownLength=32 NumericUpDownQuantity=8 CheckboxNumbers=true @@ -12,6 +12,7 @@ CheckboxSimilar=true CheckboxDuplicate=true CheckboxSequential=true TextboxPrefix=my_prefix +TextboxSuffix=my_suffix RadioButtonNew=true RadioButtonCurrent=false RadioButtonInline=false @@ -24,4 +25,5 @@ CheckboxDoRandom=False CheckboxMTA=True NumericUpDownGUIDQuantity=8 ComboBoxGUIDFormat=D -TabControl1=0 \ No newline at end of file +TabControl1=0 +CheckboxDarkMode=True \ No newline at end of file From 7b33c3e4a1dd820056460f1730e1e6d06394948a Mon Sep 17 00:00:00 2001 From: Maurice Beckman Date: Wed, 21 May 2025 20:12:16 +0200 Subject: [PATCH 2/3] #48 new settings --- .../Forms/ConfigAndGenerate.Designer.cs | 86 ++++++++++++++----- .../Properties/AssemblyInfo.cs | 4 +- nppRandomStringGenerator/Storage/Settings.cs | 62 ++++++++----- .../Storage/SettingsModel.cs | 4 +- .../nppRandomStringGeneratorSettings.ini | 6 +- 5 files changed, 113 insertions(+), 49 deletions(-) diff --git a/nppRandomStringGenerator/Forms/ConfigAndGenerate.Designer.cs b/nppRandomStringGenerator/Forms/ConfigAndGenerate.Designer.cs index 958e4fb..dac5d21 100644 --- a/nppRandomStringGenerator/Forms/ConfigAndGenerate.Designer.cs +++ b/nppRandomStringGenerator/Forms/ConfigAndGenerate.Designer.cs @@ -55,6 +55,7 @@ private void InitializeComponent() this.RadioButtonInline = new System.Windows.Forms.RadioButton(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); + this.bReset = new System.Windows.Forms.Button(); this.label11 = new System.Windows.Forms.Label(); this.label13 = new System.Windows.Forms.Label(); this.RadioButtonCurrent = new System.Windows.Forms.RadioButton(); @@ -74,7 +75,6 @@ private void InitializeComponent() this.ButtonCancel = new System.Windows.Forms.Button(); this.TabControl1 = new System.Windows.Forms.TabControl(); this.TabPageRandom = new System.Windows.Forms.TabPage(); - this.bReset = new System.Windows.Forms.Button(); this.TabPageGUID = new System.Windows.Forms.TabPage(); this.button1 = new System.Windows.Forms.Button(); this.label20 = new System.Windows.Forms.Label(); @@ -83,6 +83,9 @@ private void InitializeComponent() this.NumericUpDownGUIDQuantity = new System.Windows.Forms.NumericUpDown(); this.label17 = new System.Windows.Forms.Label(); this.label18 = new System.Windows.Forms.Label(); + this.CheckboxDarkMode = new System.Windows.Forms.CheckBox(); + this.label21 = new System.Windows.Forms.Label(); + this.TextboxSuffix = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.NumericUpDownLength)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NumericUpDownQuantity)).BeginInit(); this.groupBox1.SuspendLayout(); @@ -354,7 +357,7 @@ private void InitializeComponent() // this.ButtonGenerate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.ButtonGenerate.Font = new System.Drawing.Font("Segoe UI Semibold", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.ButtonGenerate.Location = new System.Drawing.Point(275, 388); + this.ButtonGenerate.Location = new System.Drawing.Point(275, 406); this.ButtonGenerate.Name = "ButtonGenerate"; this.ButtonGenerate.Size = new System.Drawing.Size(120, 25); this.ButtonGenerate.TabIndex = 23; @@ -397,7 +400,7 @@ private void InitializeComponent() this.linkLabel1.AutoSize = true; this.linkLabel1.Font = new System.Drawing.Font("Segoe UI", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.AlwaysUnderline; - this.linkLabel1.Location = new System.Drawing.Point(296, 346); + this.linkLabel1.Location = new System.Drawing.Point(296, 341); this.linkLabel1.Name = "linkLabel1"; this.linkLabel1.Size = new System.Drawing.Size(58, 12); this.linkLabel1.TabIndex = 36; @@ -406,6 +409,18 @@ private void InitializeComponent() this.toolTip1.SetToolTip(this.linkLabel1, "Click here to reset to default settings"); this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); // + // bReset + // + this.bReset.Image = global::nppRandomStringGenerator.Properties.Resources.undo; + this.bReset.Location = new System.Drawing.Point(383, 166); + this.bReset.Margin = new System.Windows.Forms.Padding(0); + this.bReset.Name = "bReset"; + this.bReset.Size = new System.Drawing.Size(24, 24); + this.bReset.TabIndex = 42; + this.toolTip1.SetToolTip(this.bReset, "Restore default symbols"); + this.bReset.UseVisualStyleBackColor = true; + this.bReset.Click += new System.EventHandler(this.bReset_Click); + // // label11 // this.label11.AutoSize = true; @@ -442,7 +457,7 @@ private void InitializeComponent() this.groupBox1.Controls.Add(this.RadioButtonNew); this.groupBox1.Controls.Add(this.RadioButtonCurrent); this.groupBox1.Controls.Add(this.RadioButtonInline); - this.groupBox1.Location = new System.Drawing.Point(4, 315); + this.groupBox1.Location = new System.Drawing.Point(4, 333); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(265, 98); this.groupBox1.TabIndex = 30; @@ -493,7 +508,7 @@ private void InitializeComponent() this.CheckboxCloseNoMessage.Checked = true; this.CheckboxCloseNoMessage.CheckState = System.Windows.Forms.CheckState.Checked; this.CheckboxCloseNoMessage.Font = new System.Drawing.Font("Segoe UI", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.CheckboxCloseNoMessage.Location = new System.Drawing.Point(278, 361); + this.CheckboxCloseNoMessage.Location = new System.Drawing.Point(278, 356); this.CheckboxCloseNoMessage.Name = "CheckboxCloseNoMessage"; this.CheckboxCloseNoMessage.Size = new System.Drawing.Size(135, 16); this.CheckboxCloseNoMessage.TabIndex = 34; @@ -507,7 +522,7 @@ private void InitializeComponent() this.CheckboxSaveOnClose.Checked = true; this.CheckboxSaveOnClose.CheckState = System.Windows.Forms.CheckState.Checked; this.CheckboxSaveOnClose.Font = new System.Drawing.Font("Segoe UI", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.CheckboxSaveOnClose.Location = new System.Drawing.Point(275, 346); + this.CheckboxSaveOnClose.Location = new System.Drawing.Point(275, 341); this.CheckboxSaveOnClose.Name = "CheckboxSaveOnClose"; this.CheckboxSaveOnClose.Size = new System.Drawing.Size(15, 14); this.CheckboxSaveOnClose.TabIndex = 35; @@ -616,7 +631,7 @@ private void InitializeComponent() this.ButtonCancel.Enabled = false; this.ButtonCancel.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.ButtonCancel.ForeColor = System.Drawing.Color.White; - this.ButtonCancel.Location = new System.Drawing.Point(398, 389); + this.ButtonCancel.Location = new System.Drawing.Point(398, 407); this.ButtonCancel.Margin = new System.Windows.Forms.Padding(0); this.ButtonCancel.Name = "ButtonCancel"; this.ButtonCancel.Size = new System.Drawing.Size(54, 24); @@ -634,12 +649,14 @@ private void InitializeComponent() this.TabControl1.Multiline = true; this.TabControl1.Name = "TabControl1"; this.TabControl1.SelectedIndex = 0; - this.TabControl1.Size = new System.Drawing.Size(464, 313); + this.TabControl1.Size = new System.Drawing.Size(464, 331); this.TabControl1.TabIndex = 44; // // TabPageRandom // this.TabPageRandom.BackColor = System.Drawing.SystemColors.Control; + this.TabPageRandom.Controls.Add(this.label21); + this.TabPageRandom.Controls.Add(this.TextboxSuffix); this.TabPageRandom.Controls.Add(this.bReset); this.TabPageRandom.Controls.Add(this.label1); this.TabPageRandom.Controls.Add(this.NumericUpDownLength); @@ -674,22 +691,10 @@ private void InitializeComponent() this.TabPageRandom.Location = new System.Drawing.Point(4, 22); this.TabPageRandom.Name = "TabPageRandom"; this.TabPageRandom.Padding = new System.Windows.Forms.Padding(3); - this.TabPageRandom.Size = new System.Drawing.Size(456, 287); + this.TabPageRandom.Size = new System.Drawing.Size(456, 305); this.TabPageRandom.TabIndex = 0; this.TabPageRandom.Text = "Random strings"; // - // bReset - // - this.bReset.Image = global::nppRandomStringGenerator.Properties.Resources.undo; - this.bReset.Location = new System.Drawing.Point(383, 166); - this.bReset.Margin = new System.Windows.Forms.Padding(0); - this.bReset.Name = "bReset"; - this.bReset.Size = new System.Drawing.Size(24, 24); - this.bReset.TabIndex = 42; - this.toolTip1.SetToolTip(this.bReset, "Restore default symbols"); - this.bReset.UseVisualStyleBackColor = true; - this.bReset.Click += new System.EventHandler(this.bReset_Click); - // // TabPageGUID // this.TabPageGUID.BackColor = System.Drawing.SystemColors.Control; @@ -800,13 +805,46 @@ private void InitializeComponent() this.label18.TabIndex = 31; this.label18.Text = "(min:1, max:4.096.000)"; // + // CheckboxDarkMode + // + this.CheckboxDarkMode.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.CheckboxDarkMode.AutoSize = true; + this.CheckboxDarkMode.Checked = true; + this.CheckboxDarkMode.CheckState = System.Windows.Forms.CheckState.Checked; + this.CheckboxDarkMode.Font = new System.Drawing.Font("Segoe UI", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.CheckboxDarkMode.Location = new System.Drawing.Point(278, 373); + this.CheckboxDarkMode.Name = "CheckboxDarkMode"; + this.CheckboxDarkMode.Size = new System.Drawing.Size(67, 16); + this.CheckboxDarkMode.TabIndex = 45; + this.CheckboxDarkMode.Text = "Dark Mode"; + this.CheckboxDarkMode.UseVisualStyleBackColor = true; + this.CheckboxDarkMode.Visible = false; + // + // label21 + // + this.label21.AutoSize = true; + this.label21.Location = new System.Drawing.Point(15, 281); + this.label21.Name = "label21"; + this.label21.Size = new System.Drawing.Size(39, 13); + this.label21.TabIndex = 44; + this.label21.Text = "Suffix:"; + // + // TextboxSuffix + // + this.TextboxSuffix.Location = new System.Drawing.Point(179, 278); + this.TextboxSuffix.Name = "TextboxSuffix"; + this.TextboxSuffix.Size = new System.Drawing.Size(265, 22); + this.TextboxSuffix.TabIndex = 43; + // // ConfigAndGenerate // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.AutoSize = true; this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.ClientSize = new System.Drawing.Size(464, 420); + this.BackColor = System.Drawing.SystemColors.Control; + this.ClientSize = new System.Drawing.Size(464, 438); + this.Controls.Add(this.CheckboxDarkMode); this.Controls.Add(this.TabControl1); this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.linkLabel1); @@ -815,6 +853,7 @@ private void InitializeComponent() this.Controls.Add(this.groupBox1); this.Controls.Add(this.ButtonGenerate); this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.ForeColor = System.Drawing.SystemColors.ControlText; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.MaximizeBox = false; this.MinimizeBox = false; @@ -897,5 +936,8 @@ private void InitializeComponent() private System.Windows.Forms.Label label20; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button bReset; + private System.Windows.Forms.CheckBox CheckboxDarkMode; + private System.Windows.Forms.Label label21; + private System.Windows.Forms.TextBox TextboxSuffix; } } \ No newline at end of file diff --git a/nppRandomStringGenerator/Properties/AssemblyInfo.cs b/nppRandomStringGenerator/Properties/AssemblyInfo.cs index 404b9ed..388ea71 100644 --- a/nppRandomStringGenerator/Properties/AssemblyInfo.cs +++ b/nppRandomStringGenerator/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.9.5")] -[assembly: AssemblyFileVersion("1.9.5")] +[assembly: AssemblyVersion("1.9.6")] +[assembly: AssemblyFileVersion("1.9.6")] diff --git a/nppRandomStringGenerator/Storage/Settings.cs b/nppRandomStringGenerator/Storage/Settings.cs index f20922e..96d1f89 100644 --- a/nppRandomStringGenerator/Storage/Settings.cs +++ b/nppRandomStringGenerator/Storage/Settings.cs @@ -4,7 +4,8 @@ using System.Text; using System.Windows.Forms; using nppRandomStringGenerator.Storage.Models; -using System.Linq; +using System.Collections.Generic; +using System.Security.Cryptography; namespace nppRandomStringGenerator.Storage { @@ -44,21 +45,42 @@ public void Load(bool reset = false) { settings = DeserializeIni(FilePath); - - if (settings.Appversion != "1.9.0") + + if (settings.Appversion != "1.9.6") { SettingsModel defaults = DeserializeIniFromString(Resources.nppRandomStringGeneratorSettings); - for (int i=0; i < defaults.ConfigItems.Length; i++) + foreach (ConfigItem configitem in defaults.ConfigItems) { - if (settings.ConfigItems[i] == null) + if (!settings.ConfigItems.Exists(c => c.Name == configitem.Name)) { - settings.ConfigItems[i] = defaults.ConfigItems[i]; + settings.ConfigItems.Add(configitem); } } settings.Appname = "nppRandomStringGenerator"; - settings.Appversion = "1.9.0"; + settings.Appversion = "1.9.6"; } + //else + //{ + // string check = ""; + // foreach (ConfigItem configitem in settings.ConfigItems) + // { + // check += configitem.Name + "|"; + // } + // check = check.TrimEnd('|'); + + // string checkHash; + // using (MD5 md5 = MD5.Create()) + // { + // byte[] hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(check)); + // checkHash = BitConverter.ToString(hashBytes).Replace("-", "").ToUpperInvariant(); + // } + // if ( check != "392FD30BC7A07D4CBD4F176F9C57A835") + // { + // MessageBox.Show("Unknown settings found. Resetting to defaults.", "nppRandomStringGenerator", MessageBoxButtons.OK); + + // } + //} } catch (Exception ex) { @@ -68,8 +90,10 @@ public void Load(bool reset = false) private SettingsModel DeserializeIni(string ini) { - SettingsModel tmp = new SettingsModel(); - tmp.ConfigItems = new ConfigItem[25]; + SettingsModel tmp = new SettingsModel + { + ConfigItems = new List() + }; using (FileStream stream = new FileStream(ini, FileMode.Open, FileAccess.Read, FileShare.Read)) { @@ -83,16 +107,13 @@ private SettingsModel DeserializeIni(string ini) parts = line.Split('='); tmp.Appversion = parts[1]; - int i = 0; - while (!reader.EndOfStream || i >= 25) + while (!reader.EndOfStream) { line = reader.ReadLine(); if (line == "" || line == null) break; parts = line.Split(new char[] { '=' }, 2); - tmp.ConfigItems[i] = new ConfigItem { Name = parts[0], Value = parts[1] }; - - i++; + tmp.ConfigItems.Add(new ConfigItem { Name = parts[0], Value = parts[1] }); } } } @@ -102,8 +123,10 @@ private SettingsModel DeserializeIni(string ini) private SettingsModel DeserializeIniFromString(string ini) { - SettingsModel tmp = new SettingsModel(); - tmp.ConfigItems = new ConfigItem[25]; + SettingsModel tmp = new SettingsModel + { + ConfigItems = new List() + }; using (StringReader reader = new StringReader(ini)) { @@ -115,16 +138,13 @@ private SettingsModel DeserializeIniFromString(string ini) parts = line.Split('='); tmp.Appversion = parts[1]; - int i = 0; - while (line != "" || i >= 25) + while (line != "") { line = reader.ReadLine(); if (line == "" || line == null) break; parts = line.Split(new char[] { '=' }, 2); - tmp.ConfigItems[i] = new ConfigItem { Name = parts[0], Value = parts[1] }; - - i++; + tmp.ConfigItems.Add(new ConfigItem { Name = parts[0], Value = parts[1] }); } } diff --git a/nppRandomStringGenerator/Storage/SettingsModel.cs b/nppRandomStringGenerator/Storage/SettingsModel.cs index a274840..b009b2d 100644 --- a/nppRandomStringGenerator/Storage/SettingsModel.cs +++ b/nppRandomStringGenerator/Storage/SettingsModel.cs @@ -1,4 +1,4 @@ -using System; +using System.Collections.Generic; namespace nppRandomStringGenerator.Storage.Models { @@ -6,7 +6,7 @@ public class SettingsModel { public string Appname { get; set; } public string Appversion { get; set; } - public ConfigItem[] ConfigItems { get; set; } + public List ConfigItems { get; set; } } public class ConfigItem diff --git a/nppRandomStringGenerator/Storage/nppRandomStringGeneratorSettings.ini b/nppRandomStringGenerator/Storage/nppRandomStringGeneratorSettings.ini index a3b2c80..d8f2b04 100644 --- a/nppRandomStringGenerator/Storage/nppRandomStringGeneratorSettings.ini +++ b/nppRandomStringGenerator/Storage/nppRandomStringGeneratorSettings.ini @@ -1,5 +1,5 @@ appname=nppRandomStringGenerator -appversion=1.9.0 +appversion=1.9.6 NumericUpDownLength=32 NumericUpDownQuantity=8 CheckboxNumbers=true @@ -12,6 +12,7 @@ CheckboxSimilar=true CheckboxDuplicate=true CheckboxSequential=true TextboxPrefix=my_prefix +TextboxSuffix=my_suffix RadioButtonNew=true RadioButtonCurrent=false RadioButtonInline=false @@ -24,4 +25,5 @@ CheckboxDoRandom=False CheckboxMTA=True NumericUpDownGUIDQuantity=8 ComboBoxGUIDFormat=D -TabControl1=0 \ No newline at end of file +TabControl1=0 +CheckboxDarkMode=True \ No newline at end of file From a840bf409a96041606784b3334b4ea34cf4fff84 Mon Sep 17 00:00:00 2001 From: Maurice Beckman Date: Thu, 22 May 2025 20:09:58 +0200 Subject: [PATCH 3/3] #48 generation --- .../Forms/ConfigAndGenerate.Designer.cs | 85 +++++++++++++++---- .../Forms/ConfigAndGenerate.cs | 11 ++- .../Modules/StringGenerator.cs | 25 ++++-- 3 files changed, 95 insertions(+), 26 deletions(-) diff --git a/nppRandomStringGenerator/Forms/ConfigAndGenerate.Designer.cs b/nppRandomStringGenerator/Forms/ConfigAndGenerate.Designer.cs index dac5d21..f2c8026 100644 --- a/nppRandomStringGenerator/Forms/ConfigAndGenerate.Designer.cs +++ b/nppRandomStringGenerator/Forms/ConfigAndGenerate.Designer.cs @@ -75,6 +75,8 @@ private void InitializeComponent() this.ButtonCancel = new System.Windows.Forms.Button(); this.TabControl1 = new System.Windows.Forms.TabControl(); this.TabPageRandom = new System.Windows.Forms.TabPage(); + this.label21 = new System.Windows.Forms.Label(); + this.TextboxSuffix = new System.Windows.Forms.TextBox(); this.TabPageGUID = new System.Windows.Forms.TabPage(); this.button1 = new System.Windows.Forms.Button(); this.label20 = new System.Windows.Forms.Label(); @@ -84,8 +86,9 @@ private void InitializeComponent() this.label17 = new System.Windows.Forms.Label(); this.label18 = new System.Windows.Forms.Label(); this.CheckboxDarkMode = new System.Windows.Forms.CheckBox(); - this.label21 = new System.Windows.Forms.Label(); - this.TextboxSuffix = new System.Windows.Forms.TextBox(); + this.tabPageAdvanced = new System.Windows.Forms.TabPage(); + this.label22 = new System.Windows.Forms.Label(); + this.numericUpDownCores = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.NumericUpDownLength)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NumericUpDownQuantity)).BeginInit(); this.groupBox1.SuspendLayout(); @@ -95,6 +98,8 @@ private void InitializeComponent() this.TabPageRandom.SuspendLayout(); this.TabPageGUID.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.NumericUpDownGUIDQuantity)).BeginInit(); + this.tabPageAdvanced.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCores)).BeginInit(); this.SuspendLayout(); // // NumericUpDownLength @@ -644,6 +649,7 @@ private void InitializeComponent() // this.TabControl1.Controls.Add(this.TabPageRandom); this.TabControl1.Controls.Add(this.TabPageGUID); + this.TabControl1.Controls.Add(this.tabPageAdvanced); this.TabControl1.Dock = System.Windows.Forms.DockStyle.Top; this.TabControl1.Location = new System.Drawing.Point(0, 0); this.TabControl1.Multiline = true; @@ -695,6 +701,22 @@ private void InitializeComponent() this.TabPageRandom.TabIndex = 0; this.TabPageRandom.Text = "Random strings"; // + // label21 + // + this.label21.AutoSize = true; + this.label21.Location = new System.Drawing.Point(15, 281); + this.label21.Name = "label21"; + this.label21.Size = new System.Drawing.Size(39, 13); + this.label21.TabIndex = 44; + this.label21.Text = "Suffix:"; + // + // TextboxSuffix + // + this.TextboxSuffix.Location = new System.Drawing.Point(179, 278); + this.TextboxSuffix.Name = "TextboxSuffix"; + this.TextboxSuffix.Size = new System.Drawing.Size(265, 22); + this.TextboxSuffix.TabIndex = 43; + // // TabPageGUID // this.TabPageGUID.BackColor = System.Drawing.SystemColors.Control; @@ -708,7 +730,7 @@ private void InitializeComponent() this.TabPageGUID.Location = new System.Drawing.Point(4, 22); this.TabPageGUID.Name = "TabPageGUID"; this.TabPageGUID.Padding = new System.Windows.Forms.Padding(3); - this.TabPageGUID.Size = new System.Drawing.Size(456, 287); + this.TabPageGUID.Size = new System.Drawing.Size(456, 305); this.TabPageGUID.TabIndex = 1; this.TabPageGUID.Text = "GUID\'s"; // @@ -820,21 +842,48 @@ private void InitializeComponent() this.CheckboxDarkMode.UseVisualStyleBackColor = true; this.CheckboxDarkMode.Visible = false; // - // label21 + // tabPageAdvanced // - this.label21.AutoSize = true; - this.label21.Location = new System.Drawing.Point(15, 281); - this.label21.Name = "label21"; - this.label21.Size = new System.Drawing.Size(39, 13); - this.label21.TabIndex = 44; - this.label21.Text = "Suffix:"; + this.tabPageAdvanced.Controls.Add(this.numericUpDownCores); + this.tabPageAdvanced.Controls.Add(this.label22); + this.tabPageAdvanced.Location = new System.Drawing.Point(4, 22); + this.tabPageAdvanced.Name = "tabPageAdvanced"; + this.tabPageAdvanced.Padding = new System.Windows.Forms.Padding(3); + this.tabPageAdvanced.Size = new System.Drawing.Size(456, 305); + this.tabPageAdvanced.TabIndex = 2; + this.tabPageAdvanced.Text = "Advanced"; // - // TextboxSuffix + // label22 // - this.TextboxSuffix.Location = new System.Drawing.Point(179, 278); - this.TextboxSuffix.Name = "TextboxSuffix"; - this.TextboxSuffix.Size = new System.Drawing.Size(265, 22); - this.TextboxSuffix.TabIndex = 43; + this.label22.AutoSize = true; + this.label22.Location = new System.Drawing.Point(8, 8); + this.label22.Name = "label22"; + this.label22.Size = new System.Drawing.Size(59, 13); + this.label22.TabIndex = 0; + this.label22.Text = "Use cores:"; + // + // numericUpDownCores + // + this.numericUpDownCores.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.numericUpDownCores.Location = new System.Drawing.Point(104, 6); + this.numericUpDownCores.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDownCores.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.numericUpDownCores.Name = "numericUpDownCores"; + this.numericUpDownCores.Size = new System.Drawing.Size(50, 22); + this.numericUpDownCores.TabIndex = 1; + this.numericUpDownCores.Value = new decimal(new int[] { + 2, + 0, + 0, + 0}); // // ConfigAndGenerate // @@ -875,6 +924,9 @@ private void InitializeComponent() this.TabPageGUID.ResumeLayout(false); this.TabPageGUID.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.NumericUpDownGUIDQuantity)).EndInit(); + this.tabPageAdvanced.ResumeLayout(false); + this.tabPageAdvanced.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCores)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -939,5 +991,8 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox CheckboxDarkMode; private System.Windows.Forms.Label label21; private System.Windows.Forms.TextBox TextboxSuffix; + private System.Windows.Forms.TabPage tabPageAdvanced; + private System.Windows.Forms.NumericUpDown numericUpDownCores; + private System.Windows.Forms.Label label22; } } \ No newline at end of file diff --git a/nppRandomStringGenerator/Forms/ConfigAndGenerate.cs b/nppRandomStringGenerator/Forms/ConfigAndGenerate.cs index a709fc8..1a0d6dd 100644 --- a/nppRandomStringGenerator/Forms/ConfigAndGenerate.cs +++ b/nppRandomStringGenerator/Forms/ConfigAndGenerate.cs @@ -3,15 +3,12 @@ using System.Drawing; using System.Linq; using System.Reflection; -using System.Text; using System.Text.RegularExpressions; -using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using Kbg.NppPluginNET.PluginInfrastructure; using nppRandomStringGenerator.Modules; using nppRandomStringGenerator.Storage; -using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button; namespace Kbg.NppPluginNET { @@ -44,6 +41,10 @@ public ConfigAndGenerate() this.Editor = new ScintillaGateway(PluginBase.GetCurrentScintilla()); this.Notepad = new NotepadPPGateway(); ButtonCancel.Enabled = false; + numericUpDownCores.Maximum = Environment.ProcessorCount; + numericUpDownCores.Value = (int)(Environment.ProcessorCount / 2); + CheckboxDarkMode.Visible = false; + TabControl1.TabPages.Remove(tabPageAdvanced); } public void LoadSettings() @@ -185,6 +186,7 @@ private async void ButtonGenerate_Click(Object sender, EventArgs e) IsDuplicate = CheckboxDuplicate.Checked, IsSequential = CheckboxSequential.Checked, Prefix = TextboxPrefix.Text, + Suffix = TextboxSuffix.Text, RandomMinimumLength = (int)NumericUpDownRandomMin.Value, RandomMaximumLength = (int)NumericUpDownRandomMax.Value, DoRandom = CheckboxDoRandom.Checked, @@ -194,7 +196,8 @@ private async void ButtonGenerate_Click(Object sender, EventArgs e) StringQuantity = (int)NumericUpDownQuantity.Value, DoGuids = TabControl1.SelectedTab == TabPageGUID, GuidFormat = ComboBoxGUIDFormat.Text, - GuidQuantity = (int)NumericUpDownGUIDQuantity.Value + GuidQuantity = (int)NumericUpDownGUIDQuantity.Value, + Cores = (int)numericUpDownCores.Value }; ButtonGenerate.Enabled = false; diff --git a/nppRandomStringGenerator/Modules/StringGenerator.cs b/nppRandomStringGenerator/Modules/StringGenerator.cs index 965ef20..ba6f6bd 100644 --- a/nppRandomStringGenerator/Modules/StringGenerator.cs +++ b/nppRandomStringGenerator/Modules/StringGenerator.cs @@ -23,12 +23,14 @@ internal class StringGenerator public bool IsSequential { get; set; } public bool IsDuplicate { get; set; } public string Prefix { get; set; } + public string Suffix { get; set; } public bool IsInline { get; set; } public bool IsCancelled { get; set; } public string TextSeperator { get; set; } public bool DoGuids { get; set; } public string GuidFormat { get; set; } public int GuidQuantity { get; set; } + public int Cores { get; set; } private TimeSpan InternalProcessTime; @@ -46,15 +48,15 @@ public TimeSpan ProcessTime public void GenerateStrings() { - int cores = Environment.ProcessorCount/2; + //int cores = Environment.ProcessorCount/2; - int WorkLoad = this.StringQuantity / cores; - int MissingWorkload = this.StringQuantity % cores; + int WorkLoad = this.StringQuantity / Cores; + int MissingWorkload = this.StringQuantity % Cores; if (DoGuids) { - WorkLoad = this.GuidQuantity / cores; - MissingWorkload = this.GuidQuantity % cores; + WorkLoad = this.GuidQuantity / Cores; + MissingWorkload = this.GuidQuantity % Cores; } CancelJob = new CancellationTokenSource(); @@ -62,7 +64,7 @@ public void GenerateStrings() ParallelOptions options = new ParallelOptions() { CancellationToken = CancelJob.Token, - MaxDegreeOfParallelism = cores + MaxDegreeOfParallelism = Cores }; if (this.IsInline) @@ -73,7 +75,7 @@ public void GenerateStrings() Stopwatch sw = Stopwatch.StartNew(); try { - Parallel.For(0, cores, options, (i, state) => + Parallel.For(0, Cores, options, (i, state) => { int idx = 0; int previousChar = 0; @@ -192,12 +194,21 @@ public void GenerateStrings() if (i > 0) line += MissingWorkload; + if (this.Suffix.Length > 0) + { + sb.Append(this.Suffix); + } + AllLines[line] += sb.ToString(); sb.Clear(); } else { + if (this.Suffix.Length > 0) + { + sb.Append(this.Suffix); + } sb.AppendLine(); BufferCount++;