From 28d4342b62f2dc869b5dc7f61f182a4289c825fb Mon Sep 17 00:00:00 2001 From: Sigmanor Date: Sun, 10 Jan 2016 14:37:37 +0200 Subject: [PATCH] Added 2 improvements Added warning message when open "Encrypt/Decrypt" tab; Added "Reset to defaults" button; --- Crypto Notepad/SettingsForm.Designer.cs | 24 +++- Crypto Notepad/SettingsForm.cs | 138 ++++++++++++++++------- Crypto Notepad/WarningMsgBox.Designer.cs | 119 +++++++++++++++++++ Crypto Notepad/WarningMsgBox.cs | 25 ++++ Crypto Notepad/WarningMsgBox.resx | 120 ++++++++++++++++++++ 5 files changed, 382 insertions(+), 44 deletions(-) create mode 100644 Crypto Notepad/WarningMsgBox.Designer.cs create mode 100644 Crypto Notepad/WarningMsgBox.cs create mode 100644 Crypto Notepad/WarningMsgBox.resx diff --git a/Crypto Notepad/SettingsForm.Designer.cs b/Crypto Notepad/SettingsForm.Designer.cs index ad93ff1..3b380a5 100644 --- a/Crypto Notepad/SettingsForm.Designer.cs +++ b/Crypto Notepad/SettingsForm.Designer.cs @@ -54,6 +54,7 @@ private void InitializeComponent() this.tabPage3 = new System.Windows.Forms.TabPage(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.checkBox1 = new System.Windows.Forms.CheckBox(); + this.button1 = new System.Windows.Forms.Button(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); this.tabPage2.SuspendLayout(); @@ -79,7 +80,7 @@ private void InitializeComponent() this.saveSettingsButton.Location = new System.Drawing.Point(183, 225); this.saveSettingsButton.Name = "saveSettingsButton"; this.saveSettingsButton.Size = new System.Drawing.Size(75, 23); - this.saveSettingsButton.TabIndex = 2; + this.saveSettingsButton.TabIndex = 4; this.saveSettingsButton.Text = "Save"; this.saveSettingsButton.UseVisualStyleBackColor = true; this.saveSettingsButton.Click += new System.EventHandler(this.saveSettingsButton_Click); @@ -103,6 +104,7 @@ private void InitializeComponent() this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(260, 218); this.tabControl1.TabIndex = 4; + this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged); // // tabPage1 // @@ -326,9 +328,9 @@ private void InitializeComponent() this.checkBox2.Enabled = false; this.checkBox2.Location = new System.Drawing.Point(7, 47); this.checkBox2.Name = "checkBox2"; - this.checkBox2.Size = new System.Drawing.Size(120, 17); + this.checkBox2.Size = new System.Drawing.Size(117, 17); this.checkBox2.TabIndex = 1; - this.checkBox2.Text = "Auto Check Update"; + this.checkBox2.Text = "Auto check update"; this.checkBox2.UseVisualStyleBackColor = true; // // checkBox1 @@ -336,16 +338,27 @@ private void InitializeComponent() this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(7, 18); this.checkBox1.Name = "checkBox1"; - this.checkBox1.Size = new System.Drawing.Size(166, 17); + this.checkBox1.Size = new System.Drawing.Size(179, 17); this.checkBox1.TabIndex = 0; - this.checkBox1.Text = "Associate with .enp extension"; + this.checkBox1.Text = "Associate with enp file extension"; this.checkBox1.UseVisualStyleBackColor = true; // + // button1 + // + this.button1.Location = new System.Drawing.Point(6, 225); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(98, 23); + this.button1.TabIndex = 5; + this.button1.Text = "Reset to defaults"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // // SettingsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(263, 254); + this.Controls.Add(this.button1); this.Controls.Add(this.tabControl1); this.Controls.Add(this.saveSettingsButton); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; @@ -395,5 +408,6 @@ private void InitializeComponent() private System.Windows.Forms.ComboBox comboBox4; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label7; + private System.Windows.Forms.Button button1; } } \ No newline at end of file diff --git a/Crypto Notepad/SettingsForm.cs b/Crypto Notepad/SettingsForm.cs index b4477cd..cdcf1a3 100644 --- a/Crypto Notepad/SettingsForm.cs +++ b/Crypto Notepad/SettingsForm.cs @@ -2,6 +2,7 @@ using System; using System.Drawing; using System.IO; +using System.Media; using System.Reflection; using System.Windows.Forms; @@ -9,7 +10,6 @@ namespace Crypto_Notepad { public partial class SettingsForm : Form { - Properties.Settings ps = Properties.Settings.Default; MainWindow ma = new MainWindow(); @@ -40,51 +40,42 @@ private void SettingsForm_Load(object sender, EventArgs e) private void saveSettingsButton_Click(object sender, EventArgs e) { - if (checkBox1.Checked == true) - { - AssociateExtension(Assembly.GetEntryAssembly().Location, "enp"); - } - - if (checkBox1.Checked == false) - { - DissociateExtension(Assembly.GetEntryAssembly().Location, "enp"); - } - - ps.RichForeColor = panel1.BackColor; - ps.RichBackColor = panel2.BackColor; - ps.HighlightsColor = panel3.BackColor; - ps.RichTextFont = comboBox1.Text; - ps.RichTextSize = Convert.ToInt32(comboBox2.Text.ToString()); - ps.AssociateCheck = checkBox1.Checked; - ps.HashAlgorithm = comboBox4.Text; - ps.KeySize = Convert.ToInt32(comboBox3.Text.ToString()); - ps.TheSalt = textBox1.Text; - ps.PasswordIterations = Convert.ToInt32(textBox2.Text.ToString()); - ps.Save(); - - MainWindow.settingsChanged = true; - - this.Hide(); + SetSettings("Save"); } public static void AssociateExtension(string applicationExecutablePath, string extension) - { - RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Classes", true); - key.CreateSubKey("." + extension).SetValue(string.Empty, extension + "_auto_file"); - key = key.CreateSubKey(extension + "_auto_file"); - key.CreateSubKey("DefaultIcon").SetValue(string.Empty, Path.GetDirectoryName(Application.ExecutablePath) + "\\EncryptPad.exe" + ",0"); - key = key.CreateSubKey("Shell"); - key.SetValue(string.Empty, "Open"); - key = key.CreateSubKey("Open"); - key.CreateSubKey("Command").SetValue(string.Empty, "\"" + applicationExecutablePath + "\" \"%1\""); - key.CreateSubKey("ddeexec\\Topic").SetValue(string.Empty, "System"); + { + try + { + RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Classes", true); + key.CreateSubKey("." + extension).SetValue(string.Empty, extension + "_auto_file"); + key = key.CreateSubKey(extension + "_auto_file"); + key.CreateSubKey("DefaultIcon").SetValue(string.Empty, Path.GetDirectoryName(Application.ExecutablePath) + "\\Crypto Notepad.exe" + ",0"); + key = key.CreateSubKey("Shell"); + key.SetValue(string.Empty, "Open"); + key = key.CreateSubKey("Open"); + key.CreateSubKey("Command").SetValue(string.Empty, "\"" + applicationExecutablePath + "\" \"%1\""); + key.CreateSubKey("ddeexec\\Topic").SetValue(string.Empty, "System"); + } + catch (Exception) + { + + } } public static void DissociateExtension(string applicationExecutablePath, string extension) { - RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Classes", true); - key.DeleteSubKeyTree(extension + "_auto_file"); - key.DeleteSubKeyTree("." + extension); + try + { + RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Classes", true); + key.DeleteSubKeyTree(extension + "_auto_file"); + key.DeleteSubKeyTree("." + extension); + } + catch (Exception) + { + + } + } private void panel1_Click_1(object sender, EventArgs e) @@ -116,5 +107,74 @@ private void panel3_Click(object sender, EventArgs e) } panel3.BackColor = colorDialog1.Color; } + + private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) + { + if ((tabControl1.SelectedTab == tabControl1.TabPages["tabPage2"]) && (ps.WarningMsg == false)) + { + SystemSounds.Beep.Play(); + WarningMsgBox w = new WarningMsgBox(); + w.ShowDialog(this); + } + } + + private void button1_Click(object sender, EventArgs e) + { + using (new CenterWinDialog(this)) + { + DialogResult result = MessageBox.Show("Reset to defaults?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Error); + + if (result == DialogResult.Yes) + { + SetSettings("Default"); + } + } + } + + private void SetSettings(string value) + { + if (value == "Save") + { + if (checkBox1.Checked == true) + { + AssociateExtension(Assembly.GetEntryAssembly().Location, "enp"); + } + + if (checkBox1.Checked == false) + { + DissociateExtension(Assembly.GetEntryAssembly().Location, "enp"); + } + + ps.RichForeColor = panel1.BackColor; + ps.RichBackColor = panel2.BackColor; + ps.HighlightsColor = panel3.BackColor; + ps.RichTextFont = comboBox1.Text; + ps.RichTextSize = Convert.ToInt32(comboBox2.Text.ToString()); + ps.AssociateCheck = checkBox1.Checked; + ps.HashAlgorithm = comboBox4.Text; + ps.KeySize = Convert.ToInt32(comboBox3.Text.ToString()); + ps.TheSalt = textBox1.Text; + ps.PasswordIterations = Convert.ToInt32(textBox2.Text.ToString()); + ps.Save(); + + MainWindow.settingsChanged = true; + + this.Hide(); + } + + if (value == "Default") + { + checkBox1.Checked = false; + panel1.BackColor = Color.FromArgb(228, 228, 228); + panel2.BackColor = Color.FromArgb(56, 56, 56); + panel3.BackColor = Color.FromArgb(101, 51, 6); + comboBox1.Text = "Consolas"; + comboBox2.Text = 11.ToString(); + checkBox1.Checked = false; + comboBox4.Text = "SHA1"; + comboBox3.Text = 192.ToString(); + textBox2.Text = 2.ToString(); + } + } } } diff --git a/Crypto Notepad/WarningMsgBox.Designer.cs b/Crypto Notepad/WarningMsgBox.Designer.cs new file mode 100644 index 0000000..803b7ae --- /dev/null +++ b/Crypto Notepad/WarningMsgBox.Designer.cs @@ -0,0 +1,119 @@ +namespace Crypto_Notepad +{ + partial class WarningMsgBox + { + /// + /// 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.button1 = new System.Windows.Forms.Button(); + this.panel1 = new System.Windows.Forms.Panel(); + this.label1 = new System.Windows.Forms.Label(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.checkBox1 = new System.Windows.Forms.CheckBox(); + this.panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(209, 98); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 0; + this.button1.Text = "OK"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // panel1 + // + this.panel1.BackColor = System.Drawing.Color.White; + this.panel1.Controls.Add(this.label1); + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(294, 87); + this.panel1.TabIndex = 1; + // + // label1 + // + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label1.Location = new System.Drawing.Point(84, 7); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(206, 69); + this.label1.TabIndex = 1; + this.label1.Text = "If you change settings in this tab, decrypt the previously encrypted files will n" + + "ot be possible."; + // + // pictureBox1 + // + this.pictureBox1.Image = global::Crypto_Notepad.Properties.Resources.Warning_icon_hi; + this.pictureBox1.Location = new System.Drawing.Point(7, 7); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(71, 69); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // checkBox1 + // + this.checkBox1.AutoSize = true; + this.checkBox1.Location = new System.Drawing.Point(12, 101); + this.checkBox1.Name = "checkBox1"; + this.checkBox1.Size = new System.Drawing.Size(172, 17); + this.checkBox1.TabIndex = 2; + this.checkBox1.Text = "Don\'t show this message again"; + this.checkBox1.UseVisualStyleBackColor = true; + // + // WarningMsgBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(294, 130); + this.Controls.Add(this.checkBox1); + this.Controls.Add(this.panel1); + this.Controls.Add(this.button1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "WarningMsgBox"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Warning"; + this.panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.CheckBox checkBox1; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Label label1; + } +} \ No newline at end of file diff --git a/Crypto Notepad/WarningMsgBox.cs b/Crypto Notepad/WarningMsgBox.cs new file mode 100644 index 0000000..923caa2 --- /dev/null +++ b/Crypto Notepad/WarningMsgBox.cs @@ -0,0 +1,25 @@ +using System; +using System.Windows.Forms; + +namespace Crypto_Notepad +{ + public partial class WarningMsgBox : Form + { + Properties.Settings ps = Properties.Settings.Default; + + public WarningMsgBox() + { + InitializeComponent(); + } + + private void button1_Click(object sender, EventArgs e) + { + if (checkBox1.Checked == true) + { + ps.WarningMsg = true; + ps.Save(); + } + this.Close(); + } + } +} diff --git a/Crypto Notepad/WarningMsgBox.resx b/Crypto Notepad/WarningMsgBox.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Crypto Notepad/WarningMsgBox.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file