Fixed issue with "Enter Key" form

This commit is contained in:
Sigmanor 2016-01-09 21:29:13 +02:00
parent 06abd965e9
commit c2fa34cdb4
4 changed files with 150 additions and 81 deletions

View file

@ -84,17 +84,17 @@ public void InitializeComponent()
this.lineStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.columnStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.searchTextBox = new System.Windows.Forms.TextBox();
this.chkMatchCase = new System.Windows.Forms.CheckBox();
this.chkMatchWholeWord = new System.Windows.Forms.CheckBox();
this.panel1 = new System.Windows.Forms.Panel();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.customRTB = new EncryptPad.CustomRichTextBox();
this.MainMenu.SuspendLayout();
this.contextMenuStrip1.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// MainMenu
@ -332,14 +332,14 @@ public void InitializeComponent()
// changeKeyToolStripMenuItem
//
this.changeKeyToolStripMenuItem.Name = "changeKeyToolStripMenuItem";
this.changeKeyToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.changeKeyToolStripMenuItem.Size = new System.Drawing.Size(139, 22);
this.changeKeyToolStripMenuItem.Text = "Change Key";
this.changeKeyToolStripMenuItem.Click += new System.EventHandler(this.changeKeyToolStripMenuItem_Click);
//
// settingsToolStripMenuItem
//
this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem";
this.settingsToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.settingsToolStripMenuItem.Size = new System.Drawing.Size(139, 22);
this.settingsToolStripMenuItem.Text = "Settings";
this.settingsToolStripMenuItem.Click += new System.EventHandler(this.settingsToolStripMenuItem_Click);
//
@ -355,7 +355,6 @@ public void InitializeComponent()
//
// documentationToolStripMenuItem
//
this.documentationToolStripMenuItem.Enabled = false;
this.documentationToolStripMenuItem.Name = "documentationToolStripMenuItem";
this.documentationToolStripMenuItem.Size = new System.Drawing.Size(189, 22);
this.documentationToolStripMenuItem.Text = "Documentation";
@ -534,6 +533,20 @@ public void InitializeComponent()
this.columnStripStatusLabel.Size = new System.Drawing.Size(56, 17);
this.columnStripStatusLabel.Text = "Column:";
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.Cursor = System.Windows.Forms.Cursors.Hand;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(670, 7);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(14, 14);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 14;
this.pictureBox1.TabStop = false;
this.toolTip1.SetToolTip(this.pictureBox1, "Close");
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
//
// searchTextBox
//
this.searchTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@ -585,20 +598,6 @@ public void InitializeComponent()
this.panel1.TabIndex = 13;
this.panel1.Visible = false;
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.Cursor = System.Windows.Forms.Cursors.Hand;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(670, 7);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(14, 14);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 14;
this.pictureBox1.TabStop = false;
this.toolTip1.SetToolTip(this.pictureBox1, "Close");
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
//
// customRTB
//
this.customRTB.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@ -643,9 +642,9 @@ public void InitializeComponent()
this.contextMenuStrip1.ResumeLayout(false);
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

View file

@ -17,6 +17,8 @@ public partial class MainWindow : Form
static extern int SendMessage(IntPtr hWnd, uint wMsg, UIntPtr wParam, IntPtr lParam);
public static string filename = "Unnamed.enp";
public static string key = "";
public static bool keyChanged = false;
public static bool settingsChanged = false;
public static int textSave = 0;
public static string[] args = Environment.GetCommandLineArgs();
Properties.Settings ps = Properties.Settings.Default;
@ -38,9 +40,11 @@ void SaltMAC()
if (ps.FirstLaunch == false)
{
DialogResult res = new DialogResult();
MessageBoxCenter.PrepToCenterMessageBoxOnForm(this);
res = MessageBox.Show("Get The Salt from mac address? (You can edit it by himself in Settings)", "The Salt",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
using (new CenterWinDialog(this))
{
res = MessageBox.Show("Get The Salt from mac address? (You can edit it by himself in Settings)", "The Salt",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
}
if (res == DialogResult.Yes)
{
@ -57,18 +61,19 @@ void SaltMAC()
private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
{
int Cikil = 0;
Form2 f2 = new Form2();
try
{
if (OpenFile.ShowDialog() != DialogResult.OK) return;
{
string NameWithotPath = Path.GetFileName(OpenFile.FileName);
string opnfile = File.ReadAllText(OpenFile.FileName);
Form2 f2 = new Form2();
string opnfile = File.ReadAllText(OpenFile.FileName);
f2.ShowDialog();
if (Form2.formClosing == true)
if (Form2.OkPressed == false)
{
return;
}
Form2.OkPressed = false;
string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
@ -89,31 +94,39 @@ void SaltMAC()
{
Cikil = 0;
MessageBoxCenter.PrepToCenterMessageBoxOnForm(this);
DialogResult dialogResult = MessageBox.Show("Wrong key!", "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (dialogResult == DialogResult.Retry)
using (new CenterWinDialog(this))
{
Form2 Form2 = new Form2();
Form2.ShowDialog();
try
DialogResult dialogResult = MessageBox.Show("Wrong key!", "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (dialogResult == DialogResult.Retry)
{
string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
f2.ShowDialog();
if (Form2.OkPressed == false)
{
return;
}
Form2.OkPressed = false;
try
{
string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
customRTB.Text = de;
toolStripStatusLabel1.Text = NameWithotPath;
toolStripStatusLabel1.ToolTipText = (OpenFile.FileName);
}
catch
{
Cikil = 1;
}
customRTB.Text = de;
toolStripStatusLabel1.Text = NameWithotPath;
toolStripStatusLabel1.ToolTipText = (OpenFile.FileName);
}
catch
if (dialogResult == DialogResult.Cancel)
{
Cikil = 1;
toolStripStatusLabel1.Text = "Ready";
}
}
if (dialogResult == DialogResult.Cancel)
{
toolStripStatusLabel1.Text = "Ready";
}
} while (Cikil == 1);
filename = OpenFile.FileName;
@ -139,10 +152,11 @@ private void openAsotiations()
string NameWithotPath = Path.GetFileName(args[1]);
string opnfile = File.ReadAllText(args[1]);
Form2.ShowDialog();
if (Form2.formClosing == true)
if (Form2.OkPressed == false)
{
return;
}
Form2.OkPressed = false;
string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
customRTB.Text = de;
@ -160,7 +174,14 @@ private void openAsotiations()
DialogResult dialogResult = MessageBox.Show("Wrong key!", "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (dialogResult == DialogResult.Retry)
{
Form2.OkPressed = false;
Form2.ShowDialog();
if (Form2.OkPressed == false)
{
return;
}
Form2.OkPressed = false;
try
{
string de = AES.Decrypt(opnfile, key, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
@ -190,16 +211,29 @@ private void openAsotiations()
private void новыйToolStripMenuItem_Click_1(object sender, EventArgs e)
{
customRTB.Clear();
Form2 Form2 = new Form2();
Form2.ShowDialog();
if (SaveFile.ShowDialog() != DialogResult.OK) return;
StreamWriter sw = new StreamWriter(SaveFile.FileName);
string NameWithotPath = Path.GetFileName(SaveFile.FileName);
toolStripStatusLabel1.Text = NameWithotPath;
toolStripStatusLabel1.ToolTipText = (SaveFile.FileName);
filename = SaveFile.FileName;
sw.Close();
Form2 f2 = new Form2();
f2.ShowDialog();
if (Form2.OkPressed == false)
{
return;
}
if (Form2.OkPressed == true)
{
Form2.OkPressed = false;
if (SaveFile.ShowDialog() != DialogResult.OK)
{
return;
}
customRTB.Clear();
StreamWriter sw = new StreamWriter(SaveFile.FileName);
string NameWithotPath = Path.GetFileName(SaveFile.FileName);
toolStripStatusLabel1.Text = NameWithotPath;
toolStripStatusLabel1.ToolTipText = (SaveFile.FileName);
filename = SaveFile.FileName;
sw.Close();
}
}
private async void сохранитьToolStripMenuItem_Click(object sender, EventArgs e)
@ -252,8 +286,9 @@ private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
if (customRTB.Text != "")
{
DialogResult res = new DialogResult();
MessageBoxCenter.PrepToCenterMessageBoxOnForm(this);
res = MessageBox.Show("Save changes in:\n" + filename + " ?",
using (new CenterWinDialog(this))
{
res = MessageBox.Show("Save changes in:\n" + filename + " ?",
"",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question);
@ -273,25 +308,25 @@ private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
}
try
{
if (res == DialogResult.No)
{
if (res == DialogResult.No)
{
Environment.Exit(0);
}
Environment.Exit(0);
}
if (res == DialogResult.Cancel)
{
if (res == DialogResult.Cancel)
{
e.Cancel = true;
}
e.Cancel = true;
}
}
catch (Exception)
{
}
}
}
}
}
@ -426,18 +461,22 @@ private void MainWindow_Load(object sender, EventArgs e)
{
if (filename != "Unnamed.enp")
{
MessageBoxCenter.PrepToCenterMessageBoxOnForm(this);
if (MessageBox.Show("Delete file: " + filename + " ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
using (new CenterWinDialog(this))
{
File.Delete(filename);
toolStripStatusLabel1.Text = filename + " deleted";
customRTB.Clear();
if (MessageBox.Show("Delete file: " + filename + " ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
File.Delete(filename);
toolStripStatusLabel1.Text = filename + " deleted";
customRTB.Clear();
}
}
}
if (filename == "Unnamed.enp")
{
MessageBoxCenter.PrepToCenterMessageBoxOnForm(this);
MessageBox.Show("No open files", "", MessageBoxButtons.OK, MessageBoxIcon.Question);
using (new CenterWinDialog(this))
{
MessageBox.Show("No open files", "", MessageBoxButtons.OK, MessageBoxIcon.Question);
}
}
}
@ -449,10 +488,11 @@ private void MainWindow_Load(object sender, EventArgs e)
}
if (filename == "Unnamed.enp")
{
MessageBoxCenter.PrepToCenterMessageBoxOnForm(this);
MessageBox.Show("No open files", "", MessageBoxButtons.OK, MessageBoxIcon.Question);
using (new CenterWinDialog(this))
{
MessageBox.Show("No open files", "", MessageBoxButtons.OK, MessageBoxIcon.Question);
}
}
}
private void переносПоСловамToolStripMenuItem_Click(object sender, EventArgs e)
@ -609,11 +649,21 @@ private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
sf.ShowDialog(this);
}
private void MainWindow_Activated(object sender, EventArgs e)
private async void MainWindow_Activated(object sender, EventArgs e)
{
customRTB.Font = new Font(ps.RichTextFont, ps.RichTextSize);
customRTB.ForeColor = ps.RichForeColor;
customRTB.BackColor = ps.RichBackColor;
if (settingsChanged == true)
{
customRTB.Font = new Font(ps.RichTextFont, ps.RichTextSize);
customRTB.ForeColor = ps.RichForeColor;
customRTB.BackColor = ps.RichBackColor;
}
if (keyChanged == true)
{
toolStripStatusLabel1.Text = "Key was changed";
await Task.Delay(4000);
toolStripStatusLabel1.Text = "Ready";
}
}
private void chkMatchCase_CheckedChanged(object sender, EventArgs e)

View file

@ -85,6 +85,9 @@ private void InitializeComponent()
this.Name = "Form2";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Enter the key";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form2_FormClosing);
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form2_FormClosed);
this.Load += new System.EventHandler(this.Form2_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

View file

@ -5,7 +5,7 @@ namespace EncryptPad
{
public partial class Form2 : Form
{
public static bool formClosing = false;
public static bool OkPressed = false;
public Form2()
{
InitializeComponent();
@ -16,6 +16,7 @@ private void button1_Click(object sender, EventArgs e)
MainWindow.key = textBox1.Text;
textBox1.Focus();
textBox1.Text = "";
OkPressed = true;
this.Hide();
}
@ -49,5 +50,21 @@ private void pictureBox1_Click(object sender, EventArgs e)
return;
}
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
textBox1.Focus();
textBox1.Text = "";
}
private void Form2_Load(object sender, EventArgs e)
{
}
}
}