diff --git a/Crypto Notepad/MainForm.cs b/Crypto Notepad/MainForm.cs index a49dfb4..5c97af7 100644 --- a/Crypto Notepad/MainForm.cs +++ b/Crypto Notepad/MainForm.cs @@ -1,6 +1,5 @@ using IWshRuntimeLibrary; using System; -using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Drawing; @@ -22,10 +21,7 @@ public partial class MainForm : Form string filePath = ""; string[] args = Environment.GetCommandLineArgs(); int caretPos = 0; - string appName = Assembly.GetExecutingAssembly().GetName().Name + " – "; - string currentFilename = ""; bool shiftPresed; - bool cancelPressed = false; bool noExit = false; string argsPath = ""; @@ -43,6 +39,7 @@ private void DecryptAES() f2.ShowDialog(); if (!PublicVar.okPressed) { + PublicVar.openFileName = Path.GetFileName(filePath); return; } if (SearchPanel.Visible) @@ -66,13 +63,11 @@ private void DecryptAES() CustomRTB.Text = de; - Text = appName + NameWithotPath; + Text = PublicVar.appName + " – " + NameWithotPath; filePath = OpenFile.FileName; string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); CustomRTB.Select(Convert.ToInt32(cc2), 0); - PublicVar.openFileName = Path.GetFileName(OpenFile.FileName); - currentFilename = Path.GetFileName(OpenFile.FileName); PublicVar.encryptionKey.Set(TypedPassword.Value); TypedPassword.Value = null; } @@ -88,8 +83,10 @@ private void DecryptAES() } if (dialogResult == DialogResult.Cancel) { + PublicVar.openFileName = Path.GetFileName(filePath); return; } + } } } @@ -99,7 +96,7 @@ private void OpenAsotiations() EnterKeyForm Form2 = new EnterKeyForm(); Form2.StartPosition = FormStartPosition.CenterScreen; string fileExtension = Path.GetExtension(args[1]); - + PublicVar.openFileName = Path.GetFileName(args[1]); if (fileExtension == ".cnp") { try @@ -146,8 +143,6 @@ private void OpenAsotiations() string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); CustomRTB.Select(Convert.ToInt32(cc2), 0); } - - currentFilename = Path.GetFileName(args[1]); } private void SendTo() @@ -162,6 +157,7 @@ private void SendTo() { string NameWithotPath = Path.GetFileName(argsPath); string opnfile = File.ReadAllText(argsPath); + PublicVar.openFileName = Path.GetFileName(argsPath); f2.ShowDialog(); if (!PublicVar.okPressed) @@ -179,7 +175,6 @@ private void SendTo() string cc = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); CustomRTB.Select(Convert.ToInt32(cc), 0); PublicVar.encryptionKey.Set(TypedPassword.Value); - currentFilename = Path.GetFileName(argsPath); TypedPassword.Value = null; } catch (CryptographicException) @@ -222,7 +217,6 @@ private void SendToShortcut() private void ContextMenuEncryptReplace() { - PublicVar.openFileName = Path.GetFileName(args[1]); if (args[1].Contains(".cnp")) { @@ -243,7 +237,8 @@ private void ContextMenuEncryptReplace() CustomRTB.Text = opnfile; string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); CustomRTB.Select(Convert.ToInt32(cc2), 0); - currentFilename = Path.GetFileName(args[1]); + PublicVar.openFileName = Path.GetFileName(args[1]); + string newFile = Path.GetDirectoryName(args[1]) + @"\" + Path.GetFileNameWithoutExtension(args[1]) + ".cnp"; EnterKeyForm f2 = new EnterKeyForm(); @@ -273,7 +268,8 @@ private void ContextMenuEncryptReplace() PublicVar.encryptionKey.Set(TypedPassword.Value); TypedPassword.Value = null; filePath = newFile; - currentFilename = Path.GetFileName(newFile); + PublicVar.openFileName = Path.GetFileName(newFile); + Text = PublicVar.appName + " – " + PublicVar.openFileName; CustomRTB.Text = noenc; } @@ -291,7 +287,6 @@ private void ContextMenuEncryptReplace() private void ContextMenuEncrypt() { - PublicVar.openFileName = Path.GetFileName(args[1]); if (!args[1].Contains(".cnp")) { string opnfile = File.ReadAllText(args[1]); @@ -300,7 +295,7 @@ private void ContextMenuEncrypt() Text = PublicVar.appName + NameWithotPath; string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); CustomRTB.Select(Convert.ToInt32(cc2), 0); - currentFilename = Path.GetFileName(args[1]); + PublicVar.openFileName = Path.GetFileName(args[1]); filePath = OpenFile.FileName; } @@ -351,9 +346,9 @@ private void SaveConfirm(bool exit) } else { - if (currentFilename == "") + if (PublicVar.openFileName == null) { - currentFilename = "Unnamed.cnp"; + PublicVar.openFileName = "Unnamed.cnp"; } if (CustomRTB.Text != "") @@ -362,11 +357,11 @@ private void SaveConfirm(bool exit) if (!PublicVar.keyChanged) { - messageBoxText = "Save file: " + "\"" + currentFilename + "\"" + " ? "; + messageBoxText = "Save file: " + "\"" + PublicVar.openFileName + "\"" + " ? "; } else { - messageBoxText = "Save file: " + "\"" + currentFilename + "\"" + " with a new key? "; + messageBoxText = "Save file: " + "\"" + PublicVar.openFileName + "\"" + " with a new key? "; } using (new CenterWinDialog(this)) @@ -393,7 +388,6 @@ private void SaveConfirm(bool exit) if (res == DialogResult.Cancel) { noExit = true; - cancelPressed = true; return; } } @@ -420,7 +414,7 @@ private void CheckForUpdates(bool autoCheck) { using (new CenterWinDialog(this)) { - DialogResult res = MessageBox.Show("New version is available. Install it now?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Information); + DialogResult res = MessageBox.Show("New version is available. Install it now?", PublicVar.appName, MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (res == DialogResult.Yes) { @@ -511,7 +505,7 @@ private void AutoLock(bool minimize) CustomRTB.Clear(); Text = PublicVar.appName; filePath = ""; - currentFilename = ""; + PublicVar.openFileName = null; Show(); return; } @@ -806,15 +800,11 @@ private void CustomRTB_KeyDown(object sender, KeyEventArgs e) private void CustomRTB_DragDrop(object sender, DragEventArgs e) { SaveConfirm(false); - if (cancelPressed) - { - cancelPressed = false; - return; - } string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false); foreach (string file in FileList) OpenFile.FileName = file; object fname = e.Data.GetData("FileDrop"); + PublicVar.openFileName = Path.GetFileName(OpenFile.FileName); if (fname != null) { var list = fname as string[]; @@ -828,11 +818,9 @@ private void CustomRTB_DragDrop(object sender, DragEventArgs e) Text = PublicVar.appName + " – " + NameWithotPath; string cc2 = CustomRTB.Text.Length.ToString(CultureInfo.InvariantCulture); CustomRTB.Select(Convert.ToInt32(cc2), 0); - currentFilename = Path.GetFileName(OpenFile.FileName); filePath = OpenFile.FileName; return; } - PublicVar.openFileName = Path.GetFileName(OpenFile.FileName); DecryptAES(); if (PublicVar.okPressed) { @@ -868,19 +856,24 @@ private void CustomRTB_TextChanged(object sender, EventArgs e) private void NewToolStripMenuItem_Click(object sender, EventArgs e) { SaveConfirm(false); - SaveFile.FileName = "Unnamed.cnp"; - PublicVar.openFileName = "Crypto Notepad"; + PublicVar.openFileName = "Unnamed.cnp"; EnterKeyForm f2 = new EnterKeyForm(); f2.ShowDialog(); - PublicVar.encryptionKey.Set(TypedPassword.Value); if (!PublicVar.okPressed) { + if (filePath != "") + { + PublicVar.openFileName = Path.GetFileName(filePath); + } TypedPassword.Value = null; return; } else { + SaveFile.FileName = "Unnamed.cnp"; + PublicVar.encryptionKey.Set(TypedPassword.Value); + PublicVar.okPressed = false; if (SaveFile.ShowDialog() != DialogResult.OK) { @@ -893,7 +886,7 @@ private void NewToolStripMenuItem_Click(object sender, EventArgs e) string NameWithotPath = Path.GetFileName(SaveFile.FileName); Text = PublicVar.appName + " – " + NameWithotPath; filePath = SaveFile.FileName; - currentFilename = Path.GetFileName(SaveFile.FileName); + PublicVar.openFileName = Path.GetFileName(SaveFile.FileName); sw.Close(); } TypedPassword.Value = null; @@ -903,11 +896,6 @@ private void OpenToolStripMenuItem_Click(object sender, EventArgs e) { OpenFile.FileName = ""; SaveConfirm(false); - if (cancelPressed) - { - cancelPressed = false; - return; - } if (OpenFile.ShowDialog() != DialogResult.OK) return; { @@ -959,7 +947,7 @@ private void SaveToolStripMenuItem_Click(object sender, EventArgs e) if (PublicVar.encryptionKey.Get() == null) { - SaveFile.FileName = "Unnamed.cnp"; + //SaveFile.FileName = "Unnamed.cnp"; SaveAsToolStripMenuItem_Click(this, new EventArgs()); if (!PublicVar.okPressed) { @@ -995,7 +983,15 @@ private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e) { int saveCaret = CustomRTB.SelectionStart; string NameWithotPath = Path.GetFileName(OpenFile.FileName); - SaveFile.FileName = currentFilename; + if (filePath != "") + { + PublicVar.openFileName = Path.GetFileName(filePath); + } + else + { + PublicVar.openFileName = "Unnamed.cnp"; + } + SaveFile.FileName = Path.GetFileName(filePath); EnterKeyForm f2 = new EnterKeyForm(); if (string.IsNullOrEmpty(PublicVar.encryptionKey.Get())) @@ -1038,7 +1034,7 @@ private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e) CustomRTB.Select(Convert.ToInt32(saveCaret), 0); PublicVar.encryptionKey.Set(TypedPassword.Value); TypedPassword.Value = null; - currentFilename = Path.GetFileName(SaveFile.FileName); + PublicVar.openFileName = Path.GetFileName(SaveFile.FileName); } private void OpenFileLocationToolStripMenuItem_Click(object sender, EventArgs e) @@ -1062,6 +1058,7 @@ private void DeleteFileToolStripMenuItem_Click(object sender, EventArgs e) ChangeKeyToolbarButton.Enabled = false; LockToolbarButton.Enabled = false; filePath = ""; + PublicVar.openFileName = null; Text = PublicVar.appName; return; } @@ -1076,7 +1073,7 @@ private void ExitToolStripMenuItem_Click(object sender, EventArgs e) private void FileToolStripMenuItem_DropDownOpened(object sender, EventArgs e) { - if (currentFilename == "") + if (filePath == "") { OpenFileLocationToolStripMenuItem.Enabled = false; DeleteFileToolStripMenuItem.Enabled = false; @@ -1092,7 +1089,6 @@ private void FileToolStripMenuItem_DropDownOpened(object sender, EventArgs e) /*Edit*/ private void UndoToolStripMenuItem_Click(object sender, EventArgs e) { - CustomRTB.Undo(); } diff --git a/Crypto Notepad/Program.cs b/Crypto Notepad/Program.cs index 98d5cd4..8b281ca 100644 --- a/Crypto Notepad/Program.cs +++ b/Crypto Notepad/Program.cs @@ -6,7 +6,7 @@ namespace Crypto_Notepad static class Program { /// - /// Главная точка входа для приложения. + /// The main entry point for the application. /// [STAThread] static void Main() @@ -24,8 +24,8 @@ static class PublicVar public static bool keyChanged = false; public static bool settingsChanged = false; public static bool okPressed = false; - public static string openFileName = "Crypto Notepad"; public const string appName = "Crypto Notepad"; + public static string openFileName; } static class TypedPassword