Code cleaned up

This commit is contained in:
Alexander 2018-12-06 15:24:12 +02:00
parent f878110bd6
commit 740cdcf385
2 changed files with 19 additions and 20 deletions

View file

@ -6,7 +6,6 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Security.Cryptography;
using System.Threading;
@ -50,6 +49,7 @@ void DecryptAES()
{
string opnfile = File.ReadAllText(OpenFile.FileName);
string NameWithotPath = Path.GetFileName(OpenFile.FileName);
string de = AES.Decrypt(opnfile, publicVar.encryptionKey.Get(), ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
customRTB.Text = de;
@ -927,24 +927,26 @@ void AutoLock(bool minimize)
customRTB.SelectionStart = caretPos;
this.Show();
}
catch (CryptographicException)
catch (Exception ex)
{
DialogResult dialogResult = MessageBox.Show("Invalid key!", "Crypto Notepad", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (dialogResult == DialogResult.Retry)
if (ex is CryptographicException)
{
AutoLock(false);
}
if (dialogResult == DialogResult.Cancel)
{
publicVar.encryptionKey.Set(null);
customRTB.Clear();
this.Text = appName.Remove(14);
OpenFile.FileName = "";
this.Show();
return;
DialogResult dialogResult = MessageBox.Show("Invalid key!", "Crypto Notepad", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (dialogResult == DialogResult.Retry)
{
AutoLock(false);
}
if (dialogResult == DialogResult.Cancel)
{
publicVar.encryptionKey.Set(null);
customRTB.Clear();
this.Text = appName.Remove(14);
OpenFile.FileName = "";
this.Show();
return;
}
}
}
}
protected override void WndProc(ref Message m)
@ -1044,7 +1046,6 @@ private void customRTB_DragDrop(object sender, DragEventArgs e)
currentFilename = Path.GetFileName(OpenFile.FileName);
}
}
}
}
@ -1127,6 +1128,5 @@ private void customRTB_KeyUp(object sender, KeyEventArgs e)
shiftPresed = false;
}
}
}
}

View file

@ -18,7 +18,7 @@ private void SettingsForm_Load(object sender, EventArgs e)
{
foreach (FontFamily fonts in FontFamily.Families)
{
comboBox1.Items.Add(fonts.Name);
comboBox1.Items.Add(fonts.Name);
}
comboBox1.Text = ps.RichTextFont;
@ -78,7 +78,6 @@ private void SetSettings(string value)
ps.AutoLock = checkBox4.Checked;
ps.AutoSave = checkBox5.Checked;
ps.Save();
publicVar.settingsChanged = true;
this.Hide();
@ -116,7 +115,7 @@ public static void AssociateExtension(string applicationExecutablePath, string e
catch (Exception)
{
}
}
}
public static void DissociateExtension(string applicationExecutablePath, string extension)