mirror of
https://github.com/Crypto-Notepad/Crypto-Notepad.git
synced 2026-03-11 08:55:25 +00:00
Public variables now stored in program.cs
This commit is contained in:
parent
57326babd9
commit
71b13ca6fb
5 changed files with 48 additions and 44 deletions
|
|
@ -14,10 +14,10 @@ public ChangeKeyForm()
|
|||
|
||||
private async void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (textBox1.Text == MainWindow.encryptionKey & textBox1.Text != textBox2.Text)
|
||||
if (textBox1.Text == publicVar.encryptionKey & textBox1.Text != textBox2.Text)
|
||||
{
|
||||
MainWindow.encryptionKey = textBox2.Text;
|
||||
MainWindow.keyChanged = true;
|
||||
publicVar.encryptionKey = textBox2.Text;
|
||||
publicVar.keyChanged = true;
|
||||
textBox1.Text = "";
|
||||
textBox2.Text = "";
|
||||
statusLabel.Text = "Key was successfully changed!";
|
||||
|
|
@ -28,7 +28,7 @@ private async void button1_Click(object sender, EventArgs e)
|
|||
return;
|
||||
}
|
||||
|
||||
if (textBox1.Text != MainWindow.encryptionKey)
|
||||
if (textBox1.Text != publicVar.encryptionKey)
|
||||
{
|
||||
SystemSounds.Beep.Play();
|
||||
statusLabel.Text = "Invalid old key!";
|
||||
|
|
|
|||
|
|
@ -16,12 +16,9 @@ namespace Crypto_Notepad
|
|||
{
|
||||
public partial class MainWindow : Form
|
||||
{
|
||||
public static string encryptionKey = "";
|
||||
public static bool keyChanged = false;
|
||||
public static bool settingsChanged = false;
|
||||
Properties.Settings ps = Properties.Settings.Default;
|
||||
string filename = "Unnamed.cnp";
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
Properties.Settings ps = Properties.Settings.Default;
|
||||
int caretPos = 0;
|
||||
string appName = Assembly.GetExecutingAssembly().GetName().Name;
|
||||
|
||||
|
|
@ -72,18 +69,18 @@ void DecryptAES()
|
|||
{
|
||||
Form2 f2 = new Form2();
|
||||
f2.ShowDialog();
|
||||
if (Form2.OkPressed == false)
|
||||
if (publicVar.okPressed == false)
|
||||
{
|
||||
OpenFile.FileName = "";
|
||||
return;
|
||||
}
|
||||
Form2.OkPressed = false;
|
||||
publicVar.okPressed = false;
|
||||
|
||||
try
|
||||
{
|
||||
string opnfile = File.ReadAllText(OpenFile.FileName);
|
||||
string NameWithotPath = Path.GetFileName(OpenFile.FileName);
|
||||
string de = AES.Decrypt(opnfile, encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
|
||||
string de = AES.Decrypt(opnfile, publicVar.encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
|
||||
customRTB.Text = de;
|
||||
|
||||
this.Text = appName + " - " + NameWithotPath;
|
||||
|
|
@ -135,14 +132,14 @@ private void openAsotiations()
|
|||
string opnfile = File.ReadAllText(args[1]);
|
||||
|
||||
Form2.ShowDialog();
|
||||
if (Form2.OkPressed == false)
|
||||
if (publicVar.okPressed == false)
|
||||
{
|
||||
OpenFile.FileName = "";
|
||||
return;
|
||||
}
|
||||
Form2.OkPressed = false;
|
||||
publicVar.okPressed = false;
|
||||
|
||||
string de = AES.Decrypt(opnfile, encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
|
||||
string de = AES.Decrypt(opnfile, publicVar.encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
|
||||
customRTB.Text = de;
|
||||
|
||||
this.Text = appName + " - " + NameWithotPath;
|
||||
|
|
@ -168,14 +165,14 @@ private void newToolStripMenuItem_Click_1(object sender, EventArgs e)
|
|||
Form2 f2 = new Form2();
|
||||
f2.ShowDialog();
|
||||
|
||||
if (Form2.OkPressed == false)
|
||||
if (publicVar.okPressed == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Form2.OkPressed == true)
|
||||
if (publicVar.okPressed == true)
|
||||
{
|
||||
Form2.OkPressed = false;
|
||||
publicVar.okPressed = false;
|
||||
if (SaveFile.ShowDialog() != DialogResult.OK)
|
||||
{
|
||||
return;
|
||||
|
|
@ -193,15 +190,15 @@ private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
{
|
||||
string NameWithotPath = Path.GetFileName(OpenFile.FileName);
|
||||
|
||||
if (string.IsNullOrEmpty(encryptionKey))
|
||||
if (string.IsNullOrEmpty(publicVar.encryptionKey))
|
||||
{
|
||||
Form2 Form2 = new Form2();
|
||||
Form2.ShowDialog();
|
||||
if (Form2.OkPressed == false)
|
||||
if (publicVar.okPressed == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Form2.OkPressed = false;
|
||||
publicVar.okPressed = false;
|
||||
}
|
||||
|
||||
if (SaveFile.ShowDialog() != DialogResult.OK)
|
||||
|
|
@ -212,7 +209,7 @@ private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
filename = SaveFile.FileName;
|
||||
|
||||
string noenc = customRTB.Text;
|
||||
string en = AES.Encrypt(customRTB.Text, encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
|
||||
string en = AES.Encrypt(customRTB.Text, publicVar.encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
|
||||
customRTB.Text = en;
|
||||
StreamWriter sw = new StreamWriter(filename);
|
||||
int i = customRTB.Lines.Count();
|
||||
|
|
@ -269,11 +266,11 @@ private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
|
|||
DialogResult res = new DialogResult();
|
||||
string messageBoxText = "";
|
||||
|
||||
if (keyChanged == false)
|
||||
if (publicVar.keyChanged == false)
|
||||
{
|
||||
messageBoxText = "Save file: " + "\"" + NameWithotPath + "\"" + " ? ";
|
||||
}
|
||||
if (keyChanged == true)
|
||||
if (publicVar.keyChanged == true)
|
||||
{
|
||||
messageBoxText = "Save file: " + "\"" + NameWithotPath + "\"" + " with a new key? ";
|
||||
}
|
||||
|
|
@ -402,16 +399,16 @@ private void saveToolStripMenuItem1_Click_1(object sender, EventArgs e)
|
|||
SaveFile.FileName = noname;
|
||||
saveAsToolStripMenuItem_Click(this, new EventArgs());
|
||||
|
||||
if (Form2.OkPressed == false)
|
||||
if (publicVar.okPressed == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Form2.OkPressed = false;
|
||||
publicVar.okPressed = false;
|
||||
}
|
||||
|
||||
string noenc = customRTB.Text;
|
||||
string en = AES.Encrypt(customRTB.Text, encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
|
||||
string en = AES.Encrypt(customRTB.Text, publicVar.encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
|
||||
customRTB.Text = en;
|
||||
StreamWriter sw = new StreamWriter(filename);
|
||||
int i = customRTB.Lines.Count();
|
||||
|
|
@ -493,7 +490,7 @@ private void deleteFileToolStripMenuItem_Click_1(object sender, EventArgs e)
|
|||
{
|
||||
File.Delete(filename);
|
||||
customRTB.Clear();
|
||||
encryptionKey = "";
|
||||
publicVar.encryptionKey = "";
|
||||
pictureBox11.Enabled = false;
|
||||
filename = "Unnamed.cnp";
|
||||
this.Text = appName;
|
||||
|
|
@ -670,7 +667,7 @@ private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
||||
private void MainWindow_Activated(object sender, EventArgs e)
|
||||
{
|
||||
if (settingsChanged == true)
|
||||
if (publicVar.settingsChanged == true)
|
||||
{
|
||||
customRTB.Font = new Font(ps.RichTextFont, ps.RichTextSize);
|
||||
customRTB.ForeColor = ps.RichForeColor;
|
||||
|
|
@ -695,12 +692,12 @@ private void MainWindow_Activated(object sender, EventArgs e)
|
|||
}
|
||||
}
|
||||
|
||||
if (keyChanged == true)
|
||||
if (publicVar.keyChanged == true)
|
||||
{
|
||||
customRTB.Modified = true;
|
||||
}
|
||||
|
||||
if (encryptionKey == "")
|
||||
if (publicVar.encryptionKey == "")
|
||||
{
|
||||
pictureBox11.Enabled = false;
|
||||
pictureBox13.Enabled = false;
|
||||
|
|
@ -708,7 +705,7 @@ private void MainWindow_Activated(object sender, EventArgs e)
|
|||
pictureBox7.Enabled = false;
|
||||
}
|
||||
|
||||
if (encryptionKey != "")
|
||||
if (publicVar.encryptionKey != "")
|
||||
{
|
||||
pictureBox11.Enabled = true;
|
||||
pictureBox13.Enabled = true;
|
||||
|
|
@ -761,13 +758,13 @@ private void documentationToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
||||
private void сервисToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
|
||||
{
|
||||
if (encryptionKey == "")
|
||||
if (publicVar.encryptionKey == "")
|
||||
{
|
||||
changeKeyToolStripMenuItem.Enabled = false;
|
||||
lockToolStripMenuItem.Enabled = false;
|
||||
}
|
||||
|
||||
if (encryptionKey != "")
|
||||
if (publicVar.encryptionKey != "")
|
||||
{
|
||||
changeKeyToolStripMenuItem.Enabled = true;
|
||||
lockToolStripMenuItem.Enabled = true;
|
||||
|
|
@ -928,7 +925,7 @@ private void pictureBox1_MouseLeave(object sender, EventArgs e)
|
|||
void AutoLock(bool minimize)
|
||||
{
|
||||
Form2 f2 = new Form2();
|
||||
encryptionKey = "";
|
||||
publicVar.encryptionKey = "";
|
||||
caretPos = customRTB.SelectionStart;
|
||||
this.Hide();
|
||||
if (minimize == true)
|
||||
|
|
@ -937,23 +934,23 @@ void AutoLock(bool minimize)
|
|||
}
|
||||
f2.ShowDialog();
|
||||
|
||||
if (Form2.OkPressed == false)
|
||||
if (publicVar.okPressed == false)
|
||||
{
|
||||
encryptionKey = "";
|
||||
publicVar.encryptionKey = "";
|
||||
customRTB.Clear();
|
||||
this.Text = appName;
|
||||
OpenFile.FileName = "";
|
||||
this.Show();
|
||||
return;
|
||||
}
|
||||
Form2.OkPressed = false;
|
||||
publicVar.okPressed = false;
|
||||
|
||||
try
|
||||
{
|
||||
OpenFile.FileName = filename;
|
||||
string opnfile = File.ReadAllText(OpenFile.FileName);
|
||||
string NameWithotPath = Path.GetFileName(OpenFile.FileName);
|
||||
string de = AES.Decrypt(opnfile, encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
|
||||
string de = AES.Decrypt(opnfile, publicVar.encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
|
||||
|
||||
this.Text = appName + " - " + NameWithotPath;
|
||||
filename = OpenFile.FileName;
|
||||
|
|
@ -971,7 +968,7 @@ void AutoLock(bool minimize)
|
|||
}
|
||||
if (dialogResult == DialogResult.Cancel)
|
||||
{
|
||||
encryptionKey = "";
|
||||
publicVar.encryptionKey = "";
|
||||
customRTB.Clear();
|
||||
this.Text = appName;
|
||||
OpenFile.FileName = "";
|
||||
|
|
@ -987,7 +984,7 @@ protected override void WndProc(ref Message m)
|
|||
const int WM_SYSCOMMAND = 0x112;
|
||||
const int SC_MINIMIZE = 0xF020;
|
||||
|
||||
if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE && ps.AutoLock == true && encryptionKey != "")
|
||||
if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE && ps.AutoLock == true && publicVar.encryptionKey != "")
|
||||
{
|
||||
AutoLock(true);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ namespace Crypto_Notepad
|
|||
{
|
||||
public partial class Form2 : Form
|
||||
{
|
||||
public static bool OkPressed = false;
|
||||
public Form2()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
|
@ -13,10 +12,10 @@ public Form2()
|
|||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
MainWindow.encryptionKey = textBox1.Text;
|
||||
publicVar.encryptionKey = textBox1.Text;
|
||||
textBox1.Focus();
|
||||
textBox1.Text = "";
|
||||
OkPressed = true;
|
||||
publicVar.okPressed = true;
|
||||
this.Hide();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,4 +16,12 @@ static void Main()
|
|||
Application.Run(new MainWindow());
|
||||
}
|
||||
}
|
||||
|
||||
static class publicVar
|
||||
{
|
||||
public static string encryptionKey { get; set; }
|
||||
public static bool keyChanged { get; set; }
|
||||
public static bool settingsChanged{ get; set; }
|
||||
public static bool okPressed { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ private void SetSettings(string value)
|
|||
ps.AutoLock = checkBox4.Checked;
|
||||
ps.Save();
|
||||
|
||||
MainWindow.settingsChanged = true;
|
||||
publicVar.settingsChanged = true;
|
||||
|
||||
this.Hide();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue