2019-10-15 17:22:53 +00:00
|
|
|
|
using Crypto_Notepad.Properties;
|
2019-10-02 16:24:52 +00:00
|
|
|
|
using System;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Diagnostics;
|
2019-10-11 10:31:24 +00:00
|
|
|
|
using System.Drawing;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using System.Security.Cryptography;
|
2019-08-30 10:07:26 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Crypto_Notepad
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class MainForm : Form
|
|
|
|
|
|
{
|
2019-10-11 10:38:15 +00:00
|
|
|
|
Settings settings = Settings.Default;
|
2019-09-28 19:57:03 +00:00
|
|
|
|
readonly string[] args = Environment.GetCommandLineArgs();
|
2019-10-18 14:30:36 +00:00
|
|
|
|
string currentClipboardText;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
string filePath = "";
|
|
|
|
|
|
string argsPath = "";
|
2019-10-18 14:30:36 +00:00
|
|
|
|
bool cancelPressed = false;
|
2019-08-22 17:05:18 +00:00
|
|
|
|
int findPos = 0;
|
2019-10-11 10:38:15 +00:00
|
|
|
|
int caretPos;
|
2019-10-25 21:11:24 +00:00
|
|
|
|
static readonly string[] SizeSuffixes =
|
|
|
|
|
|
{ "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
|
2018-12-17 11:16:17 +00:00
|
|
|
|
public MainForm()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.DragDrop += new DragEventHandler(RichTextBox_DragDrop);
|
|
|
|
|
|
richTextBox.AllowDrop = true;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-15 17:13:07 +00:00
|
|
|
|
protected override void WndProc(ref Message m)
|
|
|
|
|
|
{
|
|
|
|
|
|
const int WM_SYSCOMMAND = 0x112;
|
|
|
|
|
|
const int SC_MINIMIZE = 0xF020;
|
2019-10-28 18:33:14 +00:00
|
|
|
|
try
|
2019-10-15 17:13:07 +00:00
|
|
|
|
{
|
2019-10-28 18:33:14 +00:00
|
|
|
|
if (m.Msg == WM_SYSCOMMAND & m.WParam.ToInt32() == SC_MINIMIZE & settings.autoLock & !string.IsNullOrEmpty(PublicVar.encryptionKey.Get()))
|
|
|
|
|
|
{
|
|
|
|
|
|
richTextBox.Visible = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (OverflowException)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2019-10-15 17:13:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
base.WndProc(ref m);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-29 18:41:13 +00:00
|
|
|
|
#region Methods
|
2019-10-29 18:37:52 +00:00
|
|
|
|
static string SizeSuffix(long value)
|
2019-10-25 21:11:24 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (value < 0) { return "-" + SizeSuffix(-value); }
|
|
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
decimal dValue = (decimal)value;
|
|
|
|
|
|
while (Math.Round(dValue / 1024) >= 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
dValue /= 1024;
|
|
|
|
|
|
i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return string.Format("{0:n1} {1}", dValue, SizeSuffixes[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-06 09:04:35 +00:00
|
|
|
|
private async Task DecryptAES()
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
EnterKeyForm enterKeyForm = new EnterKeyForm();
|
|
|
|
|
|
enterKeyForm.Owner = this;
|
2019-09-28 19:57:03 +00:00
|
|
|
|
enterKeyForm.ShowDialog();
|
2019-11-06 09:04:35 +00:00
|
|
|
|
richTextBox.SuspendDrawing();
|
|
|
|
|
|
UseWaitCursor = true;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
if (!PublicVar.okPressed)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-01-07 10:09:52 +00:00
|
|
|
|
PublicVar.openFileName = Path.GetFileName(filePath);
|
2019-11-06 09:04:35 +00:00
|
|
|
|
mainMenu.Enabled = true;
|
|
|
|
|
|
toolbarPanel.Enabled = true;
|
|
|
|
|
|
richTextBox.ReadOnly = false;
|
|
|
|
|
|
UseWaitCursor = false;
|
|
|
|
|
|
richTextBox.ResumeDrawing();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (searchPanel.Visible)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
FindMainMenu_Click(this, new EventArgs());
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
using (StreamReader reader = File.OpenText(openFileDialog.FileName))
|
|
|
|
|
|
{
|
|
|
|
|
|
mainMenu.Enabled = false;
|
|
|
|
|
|
toolbarPanel.Enabled = false;
|
|
|
|
|
|
richTextBox.ReadOnly = true;
|
|
|
|
|
|
string openedFileText = await reader.ReadToEndAsync();
|
|
|
|
|
|
richTextBox.Text = await AES.Decrypt(openedFileText, TypedPassword.Value, null, settings.HashAlgorithm,
|
|
|
|
|
|
Convert.ToInt32(settings.PasswordIterations), Convert.ToInt32(settings.KeySize)); ;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
string NameWithotPath = Path.GetFileName(openFileDialog.FileName);
|
2019-01-07 10:09:52 +00:00
|
|
|
|
Text = PublicVar.appName + " – " + NameWithotPath;
|
2019-09-28 19:57:03 +00:00
|
|
|
|
filePath = openFileDialog.FileName;
|
|
|
|
|
|
PublicVar.openFileName = Path.GetFileName(openFileDialog.FileName);
|
2018-12-17 11:16:17 +00:00
|
|
|
|
PublicVar.encryptionKey.Set(TypedPassword.Value);
|
|
|
|
|
|
TypedPassword.Value = null;
|
2019-10-25 21:11:24 +00:00
|
|
|
|
StatusPanelFileInfo();
|
2019-11-06 09:04:35 +00:00
|
|
|
|
mainMenu.Enabled = true;
|
|
|
|
|
|
toolbarPanel.Enabled = true;
|
|
|
|
|
|
richTextBox.ReadOnly = false;
|
|
|
|
|
|
UseWaitCursor = false;
|
|
|
|
|
|
richTextBox.ResumeDrawing();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-11-06 09:04:35 +00:00
|
|
|
|
catch (Exception ex)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
if (ex is FormatException | ex is CryptographicException)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
PublicVar.okPressed = false;
|
|
|
|
|
|
if (Visible)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-05 19:23:13 +00:00
|
|
|
|
PublicVar.messageBoxCenterParent = true;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-11-06 09:04:35 +00:00
|
|
|
|
using (new CenterWinDialog(this))
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
TypedPassword.Value = null;
|
|
|
|
|
|
DialogResult dialogResult = MessageBox.Show(this, "Invalid key!", PublicVar.appName, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
|
|
|
|
|
|
if (dialogResult == DialogResult.Retry)
|
|
|
|
|
|
{
|
|
|
|
|
|
await DecryptAES();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (dialogResult == DialogResult.Cancel)
|
|
|
|
|
|
{
|
|
|
|
|
|
PublicVar.openFileName = Path.GetFileName(filePath);
|
|
|
|
|
|
mainMenu.Enabled = true;
|
|
|
|
|
|
toolbarPanel.Enabled = true;
|
|
|
|
|
|
richTextBox.ReadOnly = false;
|
|
|
|
|
|
UseWaitCursor = false;
|
|
|
|
|
|
richTextBox.ResumeDrawing();
|
|
|
|
|
|
if (!Visible)
|
|
|
|
|
|
{
|
|
|
|
|
|
Application.Exit();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-06 09:04:35 +00:00
|
|
|
|
private async void OpenAsotiations()
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
EnterKeyForm enterKeyForm = new EnterKeyForm
|
|
|
|
|
|
{
|
|
|
|
|
|
Owner = this,
|
|
|
|
|
|
StartPosition = FormStartPosition.CenterScreen
|
|
|
|
|
|
};
|
2018-12-17 11:16:17 +00:00
|
|
|
|
string fileExtension = Path.GetExtension(args[1]);
|
2019-01-07 10:09:52 +00:00
|
|
|
|
PublicVar.openFileName = Path.GetFileName(args[1]);
|
2019-11-05 20:30:49 +00:00
|
|
|
|
openFileDialog.FileName = Path.GetFullPath(args[1]);
|
|
|
|
|
|
if (fileExtension != ".cnp")
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
DialogResult res = MessageBox.Show(this, "Try to decrypt \"" + PublicVar.openFileName + "\" file?", PublicVar.appName,
|
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Information);
|
2019-11-05 20:30:49 +00:00
|
|
|
|
if (res == DialogResult.No)
|
2019-10-15 17:18:04 +00:00
|
|
|
|
{
|
2019-11-05 20:30:49 +00:00
|
|
|
|
string opnfile = File.ReadAllText(args[1]);
|
|
|
|
|
|
string NameWithotPath = Path.GetFileName(args[1]);
|
|
|
|
|
|
richTextBox.Text = opnfile;
|
|
|
|
|
|
filePath = args[1];
|
|
|
|
|
|
Text = PublicVar.appName + " – " + NameWithotPath;
|
|
|
|
|
|
StatusPanelFileInfo();
|
|
|
|
|
|
return;
|
2019-10-15 16:09:51 +00:00
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-11-06 09:04:35 +00:00
|
|
|
|
await DecryptAES();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-06 09:04:35 +00:00
|
|
|
|
private async void SendTo()
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
EnterKeyForm enterKeyForm = new EnterKeyForm
|
|
|
|
|
|
{
|
|
|
|
|
|
Owner = this,
|
|
|
|
|
|
StartPosition = FormStartPosition.CenterScreen
|
|
|
|
|
|
};
|
2018-12-17 11:16:17 +00:00
|
|
|
|
string fileExtension = Path.GetExtension(argsPath);
|
2019-11-05 20:30:49 +00:00
|
|
|
|
openFileDialog.FileName = Path.GetFullPath(argsPath);
|
|
|
|
|
|
PublicVar.openFileName = Path.GetFileName(argsPath);
|
|
|
|
|
|
if (fileExtension != ".cnp")
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
DialogResult res = MessageBox.Show(this, "Try to decrypt \"" + PublicVar.openFileName + "\" file?", PublicVar.appName,
|
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Information);
|
2019-11-05 20:30:49 +00:00
|
|
|
|
if (res == DialogResult.No)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
|
|
|
|
|
string opnfile = File.ReadAllText(argsPath);
|
2019-11-05 20:30:49 +00:00
|
|
|
|
string NameWithotPath = Path.GetFileName(argsPath);
|
|
|
|
|
|
richTextBox.Text = opnfile;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
filePath = argsPath;
|
2019-11-05 20:30:49 +00:00
|
|
|
|
Text = PublicVar.appName + " – " + NameWithotPath;
|
2019-10-25 21:11:24 +00:00
|
|
|
|
StatusPanelFileInfo();
|
2019-11-05 20:30:49 +00:00
|
|
|
|
return;
|
2019-10-15 17:18:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-11-06 09:04:35 +00:00
|
|
|
|
await DecryptAES();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-06 09:04:35 +00:00
|
|
|
|
private async void ContextMenuEncryptReplace()
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
DialogResult res = MessageBox.Show(this, "This action will delete the source file and replace it with encrypted version", PublicVar.appName,
|
|
|
|
|
|
MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
|
2018-12-17 11:16:17 +00:00
|
|
|
|
if (res == DialogResult.Cancel)
|
|
|
|
|
|
{
|
2018-12-17 13:03:08 +00:00
|
|
|
|
Environment.Exit(0);
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-11-06 09:04:35 +00:00
|
|
|
|
richTextBox.Text = File.ReadAllText(args[1]);
|
2019-11-05 20:30:49 +00:00
|
|
|
|
PublicVar.openFileName = Path.GetFileName(args[1]);
|
2019-11-06 09:04:35 +00:00
|
|
|
|
string newFileName = Path.GetDirectoryName(args[1]) + @"\" + Path.GetFileNameWithoutExtension(args[1]) + ".cnp";
|
2019-11-05 20:30:49 +00:00
|
|
|
|
EnterKeyForm enterKeyForm = new EnterKeyForm
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-05 20:30:49 +00:00
|
|
|
|
Owner = this
|
|
|
|
|
|
};
|
|
|
|
|
|
enterKeyForm.ShowDialog();
|
|
|
|
|
|
File.Delete(args[1]);
|
2019-11-06 09:04:35 +00:00
|
|
|
|
string unencryptedText = richTextBox.Text;
|
|
|
|
|
|
string encryptedText = await AES.Encrypt(richTextBox.Text, TypedPassword.Value, null, settings.HashAlgorithm, Convert.ToInt32(settings.PasswordIterations),
|
|
|
|
|
|
Convert.ToInt32(settings.KeySize));
|
|
|
|
|
|
using (StreamWriter writer = new StreamWriter(newFileName))
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
writer.Write(encryptedText);
|
2019-11-05 20:30:49 +00:00
|
|
|
|
writer.Close();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-11-05 20:30:49 +00:00
|
|
|
|
PublicVar.encryptionKey.Set(TypedPassword.Value);
|
|
|
|
|
|
TypedPassword.Value = null;
|
2019-11-06 09:04:35 +00:00
|
|
|
|
filePath = newFileName;
|
|
|
|
|
|
PublicVar.openFileName = Path.GetFileName(newFileName);
|
2019-11-05 20:30:49 +00:00
|
|
|
|
Text = PublicVar.appName + " – " + PublicVar.openFileName;
|
2019-11-06 09:04:35 +00:00
|
|
|
|
richTextBox.Text = unencryptedText;
|
2019-11-05 20:30:49 +00:00
|
|
|
|
StatusPanelFileInfo();
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Modified = false;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-25 15:29:29 +00:00
|
|
|
|
private void DeleteUpdateFiles()
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
|
|
|
|
|
string exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\";
|
|
|
|
|
|
string UpdaterExe = exePath + "Updater.exe";
|
|
|
|
|
|
string UpdateZip = exePath + "Crypto-Notepad-Update.zip";
|
|
|
|
|
|
string ZipDll = exePath + "Ionic.Zip.dll";
|
|
|
|
|
|
if (File.Exists(UpdaterExe))
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Delete(UpdaterExe);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (File.Exists(UpdateZip))
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Delete(UpdateZip);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (File.Exists(ZipDll))
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Delete(ZipDll);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 11:59:01 +00:00
|
|
|
|
private void SaveConfirm()
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-15 17:19:06 +00:00
|
|
|
|
string messageBoxText;
|
2019-10-13 11:59:01 +00:00
|
|
|
|
if (richTextBox.Modified)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-15 16:48:17 +00:00
|
|
|
|
if (string.IsNullOrEmpty(PublicVar.openFileName))
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
PublicVar.openFileName = "Unnamed.cnp";
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-10-13 11:59:01 +00:00
|
|
|
|
if (!PublicVar.keyChanged)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
messageBoxText = "Save file: " + "\"" + PublicVar.openFileName + "\"" + " ? ";
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2019-10-13 11:59:01 +00:00
|
|
|
|
else
|
2019-08-22 19:31:10 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
messageBoxText = "Save file: " + "\"" + PublicVar.openFileName + "\"" + " with a new key? ";
|
2019-08-22 19:31:10 +00:00
|
|
|
|
}
|
2019-11-06 09:04:35 +00:00
|
|
|
|
if (Visible)
|
|
|
|
|
|
{
|
|
|
|
|
|
PublicVar.messageBoxCenterParent = true;
|
|
|
|
|
|
}
|
2019-10-13 11:59:01 +00:00
|
|
|
|
using (new CenterWinDialog(this))
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-13 11:57:47 +00:00
|
|
|
|
DialogResult res = MessageBox.Show(this, messageBoxText, PublicVar.appName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
2019-10-13 11:59:01 +00:00
|
|
|
|
if (res == DialogResult.Yes)
|
|
|
|
|
|
{
|
|
|
|
|
|
trayIcon.Visible = false;
|
2019-10-13 11:57:47 +00:00
|
|
|
|
SaveMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2019-10-13 11:59:01 +00:00
|
|
|
|
if (res == DialogResult.Cancel)
|
|
|
|
|
|
{
|
|
|
|
|
|
cancelPressed = true;
|
2019-10-25 21:11:24 +00:00
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-25 15:29:29 +00:00
|
|
|
|
private void CheckForUpdates(bool autoCheck)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2018-12-25 15:29:29 +00:00
|
|
|
|
try
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2018-12-25 15:29:29 +00:00
|
|
|
|
WebClient client = new WebClient();
|
2019-01-02 19:10:41 +00:00
|
|
|
|
Stream stream = client.OpenRead("https://raw.githubusercontent.com/Crypto-Notepad/Crypto-Notepad/master/version.txt");
|
2018-12-25 15:29:29 +00:00
|
|
|
|
StreamReader reader = new StreamReader(stream);
|
|
|
|
|
|
string content = reader.ReadToEnd();
|
|
|
|
|
|
string version = Application.ProductVersion;
|
|
|
|
|
|
string exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\";
|
|
|
|
|
|
int appVersion = Convert.ToInt32(version.Replace(".", "")), serverVersion = Convert.ToInt32(content.Replace(".", ""));
|
|
|
|
|
|
if (serverVersion > appVersion)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-04 18:48:55 +00:00
|
|
|
|
if (statusPanel.Visible)
|
|
|
|
|
|
{
|
|
|
|
|
|
StatusPanelMessage("update-needed");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
using (new CenterWinDialog(this))
|
2019-09-28 19:37:04 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
DialogResult res = MessageBox.Show(this, "New version is available. Install it now?", PublicVar.appName,
|
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Information);
|
2019-10-04 18:48:55 +00:00
|
|
|
|
if (res == DialogResult.Yes)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-04 18:48:55 +00:00
|
|
|
|
File.WriteAllBytes(exePath + "Ionic.Zip.dll", Resources.Ionic_Zip);
|
|
|
|
|
|
File.WriteAllBytes(exePath + "Updater.exe", Resources.Updater);
|
|
|
|
|
|
var pr = new Process();
|
|
|
|
|
|
pr.StartInfo.FileName = exePath + "Updater.exe";
|
|
|
|
|
|
pr.StartInfo.Arguments = "/u";
|
|
|
|
|
|
pr.Start();
|
|
|
|
|
|
Application.Exit();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-10-04 18:48:55 +00:00
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-25 15:29:29 +00:00
|
|
|
|
if (serverVersion <= appVersion && autoCheck)
|
|
|
|
|
|
{
|
2019-10-04 18:48:55 +00:00
|
|
|
|
using (new CenterWinDialog(this))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (statusPanel.Visible)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-04 18:48:55 +00:00
|
|
|
|
StatusPanelMessage("update-missing");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-10-13 11:57:47 +00:00
|
|
|
|
MessageBox.Show(this, "Crypto Notepad is up to date.", PublicVar.appName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2019-10-04 18:48:55 +00:00
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
catch
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:14:24 +00:00
|
|
|
|
if (autoCheck)
|
|
|
|
|
|
{
|
|
|
|
|
|
mainMenu.Invoke((Action)delegate
|
|
|
|
|
|
{
|
|
|
|
|
|
using (new CenterWinDialog(this))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (statusPanel.Visible)
|
|
|
|
|
|
{
|
|
|
|
|
|
StatusPanelMessage("update-failed");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
MessageBox.Show(this, "Checking for updates failed:\nConnection lost or the server is busy.", PublicVar.appName,
|
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2019-09-28 19:14:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-09-28 19:37:04 +00:00
|
|
|
|
|
|
|
|
|
|
private async void StatusPanelMessage(string type)
|
|
|
|
|
|
{
|
|
|
|
|
|
string ready = "Ready";
|
2019-10-13 11:59:01 +00:00
|
|
|
|
if (statusPanelLabel.Text == "New version is available")
|
2019-09-28 19:37:04 +00:00
|
|
|
|
{
|
|
|
|
|
|
ready = "New version is available";
|
|
|
|
|
|
}
|
|
|
|
|
|
switch (type)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "save":
|
2019-10-13 11:54:45 +00:00
|
|
|
|
if (statusPanelLabel.Text != "File Saved")
|
2019-09-28 19:37:04 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
statusPanelLabel.Text = "File Saved";
|
2019-09-28 19:37:04 +00:00
|
|
|
|
await Task.Delay(3000);
|
2019-10-13 11:54:45 +00:00
|
|
|
|
statusPanelLabel.Text = ready;
|
2019-09-28 19:37:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "update-missing":
|
2019-10-13 11:54:45 +00:00
|
|
|
|
statusPanelLabel.Text = "Crypto Notepad is up to date";
|
2019-09-28 19:37:04 +00:00
|
|
|
|
await Task.Delay(3000);
|
2019-10-13 11:54:45 +00:00
|
|
|
|
statusPanelLabel.Text = ready;
|
2019-09-28 19:37:04 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case "update-failed":
|
2019-10-13 11:54:45 +00:00
|
|
|
|
statusPanelLabel.Text = "Checking for updates failed";
|
2019-09-28 19:37:04 +00:00
|
|
|
|
await Task.Delay(3000);
|
2019-10-13 11:54:45 +00:00
|
|
|
|
statusPanelLabel.Text = ready;
|
2019-09-28 19:37:04 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case "update-needed":
|
2019-10-13 11:54:45 +00:00
|
|
|
|
statusPanelLabel.Text = "New version is available";
|
2019-09-28 19:37:04 +00:00
|
|
|
|
break;
|
2019-10-11 10:38:15 +00:00
|
|
|
|
case "always-top-on":
|
2019-10-13 11:54:45 +00:00
|
|
|
|
if (statusPanelLabel.Text != "Always on top ON")
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
statusPanelLabel.Text = "Always on top ON";
|
2019-10-11 10:38:15 +00:00
|
|
|
|
await Task.Delay(3000);
|
2019-10-13 11:54:45 +00:00
|
|
|
|
statusPanelLabel.Text = ready;
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "always-top-off":
|
2019-10-13 11:54:45 +00:00
|
|
|
|
if (statusPanelLabel.Text != "Always on top OFF")
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
statusPanelLabel.Text = "Always on top OFF";
|
2019-10-11 10:38:15 +00:00
|
|
|
|
await Task.Delay(3000);
|
2019-10-13 11:54:45 +00:00
|
|
|
|
statusPanelLabel.Text = ready;
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2019-09-28 19:37:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-25 21:11:24 +00:00
|
|
|
|
private void StatusPanelFileInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
DateTime creation = File.GetLastWriteTime(filePath);
|
|
|
|
|
|
statusPanelModifiedLabel.Text = "Modified: " + creation.ToString("dd.MM.yyyy");
|
|
|
|
|
|
statusPanelModifiedLabel.ToolTipText = creation.ToString();
|
|
|
|
|
|
long length = new FileInfo(filePath).Length;
|
|
|
|
|
|
statusPanelSizeLabel.Text = "Size: " + SizeSuffix(length).ToString();
|
|
|
|
|
|
StatusPanelTextInfo();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:37:04 +00:00
|
|
|
|
private void StatusPanelTextInfo()
|
|
|
|
|
|
{
|
2019-10-21 11:26:40 +00:00
|
|
|
|
if (statusPanel.Visible)
|
2019-09-28 19:37:04 +00:00
|
|
|
|
{
|
2019-10-25 21:11:24 +00:00
|
|
|
|
int linesCount = richTextBox.Lines.Length;
|
|
|
|
|
|
|
2019-10-21 11:26:40 +00:00
|
|
|
|
if (linesCount == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
linesCount = 1;
|
|
|
|
|
|
}
|
2019-10-21 12:20:40 +00:00
|
|
|
|
statusPanelLengthLabel.Text = "Length: " + richTextBox.TextLength;
|
2019-10-25 21:11:24 +00:00
|
|
|
|
statusPanelLinesLabel.Text = "Lines: " + linesCount;
|
2019-09-28 19:37:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-10-25 21:11:24 +00:00
|
|
|
|
private void StatusPanelTimer_Tick(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
StatusPanelTextInfo();
|
|
|
|
|
|
statusPanelTimer.Stop();
|
|
|
|
|
|
}
|
2019-09-28 19:37:04 +00:00
|
|
|
|
|
2019-11-06 09:04:35 +00:00
|
|
|
|
private async Task UnlockFile()
|
2019-10-25 21:04:05 +00:00
|
|
|
|
{
|
2018-12-25 15:29:29 +00:00
|
|
|
|
try
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
richTextBox.SuspendDrawing();
|
|
|
|
|
|
UseWaitCursor = true;
|
|
|
|
|
|
fileLockedPanel.Enabled = false;
|
2019-10-13 11:59:01 +00:00
|
|
|
|
TypedPassword.Value = fileLockedKeyTextBox.Text;
|
2019-11-06 09:04:35 +00:00
|
|
|
|
mainMenu.Enabled = false;
|
|
|
|
|
|
toolbarPanel.Enabled = false;
|
|
|
|
|
|
using (StreamReader reader = File.OpenText(openFileDialog.FileName))
|
|
|
|
|
|
{
|
|
|
|
|
|
string openedFileText = await reader.ReadToEndAsync();
|
|
|
|
|
|
richTextBox.Text = await AES.Decrypt(openedFileText, TypedPassword.Value, null, settings.HashAlgorithm,
|
|
|
|
|
|
Convert.ToInt32(settings.PasswordIterations), Convert.ToInt32(settings.KeySize)); ;
|
|
|
|
|
|
}
|
2019-10-13 11:59:01 +00:00
|
|
|
|
fileLockedPanel.Visible = false;
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.SelectionStart = caretPos;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
PublicVar.encryptionKey.Set(TypedPassword.Value);
|
|
|
|
|
|
TypedPassword.Value = null;
|
2019-10-15 17:19:06 +00:00
|
|
|
|
richTextBox.Focus();
|
2019-10-25 21:11:24 +00:00
|
|
|
|
StatusPanelFileInfo();
|
2019-11-06 09:04:35 +00:00
|
|
|
|
richTextBox.ResumeDrawing();
|
|
|
|
|
|
UseWaitCursor = false;
|
|
|
|
|
|
fileLockedPanel.Enabled = true;
|
|
|
|
|
|
mainMenu.Enabled = true;
|
|
|
|
|
|
toolbarPanel.Enabled = true;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
catch (Exception ex)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2018-12-25 15:29:29 +00:00
|
|
|
|
if (ex is CryptographicException)
|
|
|
|
|
|
{
|
|
|
|
|
|
TypedPassword.Value = null;
|
2019-11-05 19:23:13 +00:00
|
|
|
|
PublicVar.messageBoxCenterParent = true;
|
2019-10-11 10:38:15 +00:00
|
|
|
|
using (new CenterWinDialog(this))
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-13 11:57:47 +00:00
|
|
|
|
DialogResult dialogResult = MessageBox.Show(this, "Invalid key!", PublicVar.appName, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
|
2019-10-11 10:38:15 +00:00
|
|
|
|
if (dialogResult == DialogResult.Retry)
|
|
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
UseWaitCursor = false;
|
|
|
|
|
|
richTextBox.ResumeDrawing();
|
|
|
|
|
|
fileLockedPanel.Enabled = true;
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedKeyTextBox.Text = "";
|
|
|
|
|
|
fileLockedKeyTextBox.Focus();
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
if (dialogResult == DialogResult.Cancel)
|
|
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedPanel.Visible = false;
|
2019-10-11 10:38:15 +00:00
|
|
|
|
Text = PublicVar.appName;
|
|
|
|
|
|
filePath = "";
|
2019-10-15 16:48:17 +00:00
|
|
|
|
PublicVar.openFileName = "";
|
2019-11-06 09:04:35 +00:00
|
|
|
|
UseWaitCursor = false;
|
|
|
|
|
|
richTextBox.ResumeDrawing();
|
|
|
|
|
|
fileLockedPanel.Enabled = true;
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-04 18:44:30 +00:00
|
|
|
|
private void LoadSettings()
|
2019-09-28 19:57:03 +00:00
|
|
|
|
{
|
2019-10-04 18:44:30 +00:00
|
|
|
|
if (settings.editorRightToLeft)
|
|
|
|
|
|
{
|
|
|
|
|
|
richTextBox.RightToLeft = RightToLeft.Yes;
|
|
|
|
|
|
rightToLeftContextMenu.Checked = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
richTextBox.RightToLeft = RightToLeft.No;
|
|
|
|
|
|
rightToLeftContextMenu.Checked = false;
|
|
|
|
|
|
}
|
2019-10-13 11:54:45 +00:00
|
|
|
|
if (settings.insertKey == "Disable")
|
2019-10-04 18:44:30 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
insertMainMenu.ShortcutKeys = Keys.Insert;
|
2019-10-04 18:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
insertMainMenu.ShortcutKeys = Keys.None;
|
2019-10-04 18:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
if (settings.autoCheckUpdate)
|
|
|
|
|
|
{
|
|
|
|
|
|
CheckForUpdates(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (settings.windowLocation.ToString() != "{X=0,Y=0}")
|
|
|
|
|
|
{
|
|
|
|
|
|
Location = settings.windowLocation;
|
|
|
|
|
|
}
|
|
|
|
|
|
Size = settings.windowSize;
|
|
|
|
|
|
WindowState = settings.windowState;
|
|
|
|
|
|
if (settings.toolbarBorder)
|
|
|
|
|
|
{
|
|
|
|
|
|
toolbarPanel.BorderStyle = BorderStyle.FixedSingle;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
toolbarPanel.BorderStyle = BorderStyle.None;
|
|
|
|
|
|
}
|
2019-10-11 10:38:15 +00:00
|
|
|
|
TopMost = settings.alwaysOnTop;
|
|
|
|
|
|
alwaysOnTopMainMenu.Checked = settings.alwaysOnTop;
|
2019-10-11 10:37:05 +00:00
|
|
|
|
if (settings.closeToTray | settings.minimizeToTray)
|
|
|
|
|
|
{
|
|
|
|
|
|
trayIcon.Visible = true;
|
|
|
|
|
|
}
|
2019-10-15 18:00:19 +00:00
|
|
|
|
richTextBoxPanel.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle), settings.editorBorder);
|
2019-10-04 18:44:30 +00:00
|
|
|
|
wordWrapMainMenu.Checked = settings.editorWrap;
|
|
|
|
|
|
toolbarPanel.BackColor = settings.toolbarBackColor;
|
|
|
|
|
|
toolbarPanel.Visible = settings.toolbarVisible;
|
2019-10-17 21:37:08 +00:00
|
|
|
|
closeToolbarButton.Visible = settings.toolbarCloseButton;
|
2019-10-04 18:44:30 +00:00
|
|
|
|
mainMenu.Visible = settings.mainMenuVisible;
|
|
|
|
|
|
rightToLeftContextMenu.Checked = settings.editorRightToLeft;
|
|
|
|
|
|
statusPanel.ForeColor = settings.statusPanelFontColor;
|
|
|
|
|
|
statusPanel.BackColor = settings.statusPanelBackColor;
|
|
|
|
|
|
statusPanel.Visible = settings.statusPanelVisible;
|
|
|
|
|
|
richTextBox.WordWrap = settings.editorWrap;
|
|
|
|
|
|
richTextBox.ForeColor = settings.editroForeColor;
|
|
|
|
|
|
richTextBox.BackColor = settings.editorBackColor;
|
|
|
|
|
|
richTextBox.Font = settings.editorFont;
|
|
|
|
|
|
BackColor = settings.editorBackColor;
|
|
|
|
|
|
searchPanel.BackColor = settings.searchPanelBackColor;
|
|
|
|
|
|
searchPanel.ForeColor = settings.searchPanelForeColor;
|
|
|
|
|
|
searchTextBox.BackColor = settings.searchPanelBackColor;
|
|
|
|
|
|
searchTextBox.ForeColor = settings.searchPanelForeColor;
|
2019-10-13 11:54:45 +00:00
|
|
|
|
searchCaseSensitiveCheckBox.ForeColor = settings.searchPanelForeColor;
|
|
|
|
|
|
searchWholeWordCheckBox.ForeColor = settings.searchPanelForeColor;
|
|
|
|
|
|
searchFindNextButton.ForeColor = settings.searchPanelForeColor;
|
2019-10-17 21:11:47 +00:00
|
|
|
|
searchCloseButton.ForeColor = settings.searchPanelForeColor;
|
2019-10-17 21:27:17 +00:00
|
|
|
|
searchPanel.CellBorderStyle = (TableLayoutPanelCellBorderStyle)Enum.Parse(typeof(TableLayoutPanelCellBorderStyle), settings.searchPanelBorder);
|
2019-10-04 18:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void MenuIcons(bool menuIcons)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (menuIcons)
|
|
|
|
|
|
{
|
|
|
|
|
|
newMainMenu.Image = Resources.document_plus;
|
|
|
|
|
|
openMainMenu.Image = Resources.folder_open_document;
|
|
|
|
|
|
saveMainMenu.Image = Resources.disk_return_black;
|
|
|
|
|
|
saveAsMainMenu.Image = Resources.disks_black;
|
2019-10-13 12:55:13 +00:00
|
|
|
|
openFileLocationMainMenu.Image = Resources.folder_horizontal;
|
2019-10-04 18:44:30 +00:00
|
|
|
|
deleteFileMainMenu.Image = Resources.document_minus;
|
|
|
|
|
|
exitMainMenu.Image = Resources.cross_button;
|
|
|
|
|
|
undoMainMenu.Image = Resources.arrow_left;
|
|
|
|
|
|
redoMainMenu.Image = Resources.arrow_right;
|
|
|
|
|
|
cutMainMenu.Image = Resources.scissors;
|
|
|
|
|
|
copyMainMenu.Image = Resources.document_copy;
|
|
|
|
|
|
pasteMainMenu.Image = Resources.clipboard;
|
|
|
|
|
|
deleteMainMenu.Image = Resources.minus;
|
|
|
|
|
|
findMainMenu.Image = Resources.magnifier;
|
|
|
|
|
|
selectAllMainMenu.Image = Resources.selection_input;
|
|
|
|
|
|
wordWrapMainMenu.Image = Resources.wrap_option;
|
|
|
|
|
|
clearMainMenu.Image = Resources.document;
|
|
|
|
|
|
changeKeyMainMenu.Image = Resources.key;
|
|
|
|
|
|
lockMainMenu.Image = Resources.lock_warning;
|
|
|
|
|
|
settingsMainMenu.Image = Resources.gear;
|
2019-10-13 12:55:13 +00:00
|
|
|
|
documentationMainMenu.Image = Resources.document_text;
|
|
|
|
|
|
checkForUpdatesMainMenu.Image = Resources.upload_cloud;
|
2019-10-04 18:44:30 +00:00
|
|
|
|
aboutMainMenu.Image = Resources.information;
|
2019-10-11 10:31:24 +00:00
|
|
|
|
alwaysOnTopMainMenu.Image = Resources.applications_blue;
|
2019-11-05 20:00:38 +00:00
|
|
|
|
saveCloseFileMainMenu.Image = Resources.disk__minus;
|
2018-12-29 16:26:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
foreach (ToolStripItem item in mainMenu.Items)
|
2018-12-29 16:26:51 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (item is ToolStripDropDownItem)
|
|
|
|
|
|
foreach (ToolStripItem dropDownItem in ((ToolStripDropDownItem)item).DropDownItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
dropDownItem.Image = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-10-02 16:35:34 +00:00
|
|
|
|
|
2019-10-18 10:34:14 +00:00
|
|
|
|
public void ToolbarIcons(bool oldIcons)
|
2019-10-02 16:24:52 +00:00
|
|
|
|
{
|
2019-10-04 18:48:55 +00:00
|
|
|
|
if (oldIcons)
|
2019-10-02 16:24:52 +00:00
|
|
|
|
{
|
|
|
|
|
|
newToolbarButton.Image = Resources.old_page_white_add;
|
|
|
|
|
|
openToolbarButton.Image = Resources.old_folder_vertical_document;
|
|
|
|
|
|
saveToolbarButton.Image = Resources.old_diskette;
|
|
|
|
|
|
fileLocationToolbarButton.Image = Resources.old_folder_stand;
|
|
|
|
|
|
deleteFileToolbarButton.Image = Resources.old_page_white_delete;
|
|
|
|
|
|
cutToolbarButton.Image = Resources.old_cut_red;
|
|
|
|
|
|
copyToolbarButton.Image = Resources.old_page_white_copy;
|
|
|
|
|
|
pasteToolbarButton.Image = Resources.old_paste_plain;
|
|
|
|
|
|
changeKeyToolbarButton.Image = Resources.old_page_white_key;
|
|
|
|
|
|
lockToolbarButton.Image = Resources.old_lock;
|
|
|
|
|
|
settingsToolbarButton.Image = Resources.old_setting_tools;
|
2019-10-11 10:31:24 +00:00
|
|
|
|
alwaysOnTopToolbarButton.Image = Resources.old_application_double;
|
2019-10-02 16:24:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
newToolbarButton.Image = Resources.document_plus;
|
|
|
|
|
|
openToolbarButton.Image = Resources.folder_open_document;
|
|
|
|
|
|
saveToolbarButton.Image = Resources.disk_return_black;
|
|
|
|
|
|
fileLocationToolbarButton.Image = Resources.folder_horizontal;
|
|
|
|
|
|
deleteFileToolbarButton.Image = Resources.document_minus;
|
|
|
|
|
|
cutToolbarButton.Image = Resources.scissors;
|
|
|
|
|
|
copyToolbarButton.Image = Resources.document_copy;
|
|
|
|
|
|
pasteToolbarButton.Image = Resources.clipboard;
|
|
|
|
|
|
changeKeyToolbarButton.Image = Resources.key;
|
|
|
|
|
|
lockToolbarButton.Image = Resources.lock_warning;
|
|
|
|
|
|
settingsToolbarButton.Image = Resources.gear;
|
2019-10-11 10:31:24 +00:00
|
|
|
|
alwaysOnTopToolbarButton.Image = Resources.applications_blue;
|
2019-10-02 16:24:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
#endregion
|
2018-12-17 11:16:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
#region Event Handlers
|
2019-11-05 20:54:16 +00:00
|
|
|
|
private void RichTextBox_ModifiedChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (richTextBox.Modified == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Text.Contains("*"))
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = Text.Substring(0, Text.Length - 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-10-21 12:20:40 +00:00
|
|
|
|
private void StatusPanel_VisibleChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (statusPanel.Visible)
|
|
|
|
|
|
{
|
|
|
|
|
|
StatusPanelTextInfo();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-10-21 11:26:22 +00:00
|
|
|
|
|
2019-10-11 10:37:05 +00:00
|
|
|
|
private void MainForm_Resize(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-11 10:37:05 +00:00
|
|
|
|
if (settings.minimizeToTray)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (WindowState == FormWindowState.Minimized)
|
|
|
|
|
|
{
|
|
|
|
|
|
Hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-10-15 16:48:17 +00:00
|
|
|
|
if (WindowState == FormWindowState.Minimized & settings.autoLock & !string.IsNullOrEmpty(PublicVar.encryptionKey.Get()))
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedPanel.Visible = true;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-10-11 10:37:05 +00:00
|
|
|
|
if (WindowState == FormWindowState.Normal)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
if (fileLockedPanel.Visible)
|
2019-10-11 10:37:05 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedKeyTextBox.Focus();
|
2019-10-11 10:37:05 +00:00
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MainWindow_Activated(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
richTextBox.Focus();
|
|
|
|
|
|
|
|
|
|
|
|
if (PublicVar.keyChanged)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-11 10:38:15 +00:00
|
|
|
|
richTextBox.Modified = true;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-25 15:29:29 +00:00
|
|
|
|
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
if (WindowState == FormWindowState.Normal)
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.windowSize = Size;
|
|
|
|
|
|
settings.windowLocation = Location;
|
|
|
|
|
|
settings.windowState = WindowState;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (WindowState == FormWindowState.Maximized)
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.windowState = WindowState;
|
|
|
|
|
|
}
|
|
|
|
|
|
settings.Save();
|
2019-10-11 10:37:05 +00:00
|
|
|
|
if (settings.closeToTray)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
if (e.CloseReason == CloseReason.UserClosing)
|
2019-10-11 10:37:05 +00:00
|
|
|
|
{
|
2019-10-15 16:48:17 +00:00
|
|
|
|
if (settings.autoLock & !string.IsNullOrEmpty(PublicVar.encryptionKey.Get()))
|
2019-10-13 11:59:01 +00:00
|
|
|
|
{
|
|
|
|
|
|
fileLockedPanel.Visible = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
Hide();
|
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
|
return;
|
2019-10-11 10:37:05 +00:00
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2019-10-13 11:59:01 +00:00
|
|
|
|
if (richTextBox.Modified)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-15 16:48:17 +00:00
|
|
|
|
if (string.IsNullOrEmpty(PublicVar.openFileName))
|
2019-10-13 11:59:01 +00:00
|
|
|
|
{
|
|
|
|
|
|
PublicVar.openFileName = "Unnamed.cnp";
|
|
|
|
|
|
}
|
2019-10-15 16:48:17 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(richTextBox.Text))
|
2019-10-13 11:59:01 +00:00
|
|
|
|
{
|
|
|
|
|
|
string messageBoxText;
|
|
|
|
|
|
if (!PublicVar.keyChanged)
|
|
|
|
|
|
{
|
|
|
|
|
|
messageBoxText = "Save file: " + "\"" + PublicVar.openFileName + "\"" + " ? ";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
messageBoxText = "Save file: " + "\"" + PublicVar.openFileName + "\"" + " with a new key? ";
|
|
|
|
|
|
}
|
2019-11-05 19:23:13 +00:00
|
|
|
|
if (Visible)
|
|
|
|
|
|
{
|
|
|
|
|
|
PublicVar.messageBoxCenterParent = true;
|
|
|
|
|
|
}
|
2019-10-13 11:59:01 +00:00
|
|
|
|
using (new CenterWinDialog(this))
|
|
|
|
|
|
{
|
2019-10-13 11:57:47 +00:00
|
|
|
|
DialogResult res = MessageBox.Show(this, messageBoxText, PublicVar.appName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
|
|
|
|
|
if (res == DialogResult.Yes)
|
|
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
Hide();
|
2019-10-13 11:57:47 +00:00
|
|
|
|
trayIcon.Visible = false;
|
2019-11-06 09:04:35 +00:00
|
|
|
|
using (StreamWriter writer = new StreamWriter(filePath))
|
|
|
|
|
|
{
|
|
|
|
|
|
string enc = "";
|
|
|
|
|
|
Task.Run(async () => { enc = await AES.Encrypt(richTextBox.Text, PublicVar.encryptionKey.Get(), null, settings.HashAlgorithm, Convert.ToInt32(settings.PasswordIterations), Convert.ToInt32(settings.KeySize)); }).Wait();
|
|
|
|
|
|
writer.Write(enc);
|
|
|
|
|
|
writer.Close();
|
|
|
|
|
|
}
|
2019-10-13 11:59:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
if (res == DialogResult.Cancel)
|
|
|
|
|
|
{
|
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-10-25 21:11:24 +00:00
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void MainForm_Shown(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Visible = true;
|
2019-09-28 19:22:53 +00:00
|
|
|
|
richTextBox.SetInnerMargins(Convert.ToInt32(settings.editorPaddingLeft), 0, 0, 0);
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Modified = false;
|
2019-10-31 19:50:51 +00:00
|
|
|
|
|
2019-11-05 22:51:18 +00:00
|
|
|
|
if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "Crypto Notepad.settings"))
|
2019-10-31 19:50:51 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
if (Visible)
|
|
|
|
|
|
{
|
|
|
|
|
|
PublicVar.messageBoxCenterParent = true;
|
|
|
|
|
|
}
|
2019-10-31 19:50:51 +00:00
|
|
|
|
using (new CenterWinDialog(this))
|
|
|
|
|
|
{
|
|
|
|
|
|
DialogResult res = MessageBox.Show(this, "Enable automatic update check?", PublicVar.appName, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
|
|
|
|
|
|
if (res == DialogResult.Yes)
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.autoCheckUpdate = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
}
|
2018-12-29 16:26:51 +00:00
|
|
|
|
|
2018-12-25 15:29:29 +00:00
|
|
|
|
private void MainWindow_Load(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
Visible = false;
|
2019-10-04 18:44:30 +00:00
|
|
|
|
LoadSettings();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
DeleteUpdateFiles();
|
2019-10-04 18:44:30 +00:00
|
|
|
|
MenuIcons(settings.menuIcons);
|
2019-10-18 10:34:14 +00:00
|
|
|
|
ToolbarIcons(settings.oldToolbarIcons);
|
2019-08-21 13:19:10 +00:00
|
|
|
|
if (args.Length == 2) /*drag & drop to executable*/
|
2019-08-19 19:35:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
OpenAsotiations();
|
|
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
if (args.Contains("/s")) /*send to*/
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2018-12-25 15:29:29 +00:00
|
|
|
|
foreach (var arg in args)
|
|
|
|
|
|
{
|
|
|
|
|
|
argsPath = arg;
|
|
|
|
|
|
}
|
|
|
|
|
|
SendTo();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
if (args.Contains("/o")) /*decrypt & open cnp*/
|
|
|
|
|
|
{
|
|
|
|
|
|
OpenAsotiations();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (args.Contains("/er")) /*encrypt and replace*/
|
|
|
|
|
|
{
|
|
|
|
|
|
ContextMenuEncryptReplace();
|
|
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
|
2019-08-22 17:55:56 +00:00
|
|
|
|
private void RichTextBox_SelectionChanged(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (richTextBox.SelectionLength != 0)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
cutToolbarButton.Enabled = true;
|
|
|
|
|
|
copyToolbarButton.Enabled = true;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
cutToolbarButton.Enabled = false;
|
|
|
|
|
|
copyToolbarButton.Enabled = false;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-22 17:55:56 +00:00
|
|
|
|
private void RichTextBox_KeyDown(object sender, KeyEventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (e.KeyCode == Keys.Escape)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
searchTextBox.Text = "";
|
|
|
|
|
|
searchPanel.Visible = false;
|
|
|
|
|
|
richTextBox.Focus();
|
|
|
|
|
|
richTextBox.DeselectAll();
|
|
|
|
|
|
e.Handled = e.SuppressKeyPress = true;
|
|
|
|
|
|
findPos = 0;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2019-10-15 16:09:51 +00:00
|
|
|
|
if (e.KeyCode == Keys.Enter & searchPanel.Visible & !string.IsNullOrEmpty(searchTextBox.Text))
|
2019-08-22 17:05:18 +00:00
|
|
|
|
{
|
2019-10-18 10:37:33 +00:00
|
|
|
|
SearchFindNextButton_MouseUp(null, null);
|
2019-08-22 17:05:18 +00:00
|
|
|
|
e.Handled = e.SuppressKeyPress = true;
|
|
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-22 17:55:56 +00:00
|
|
|
|
private void RichTextBox_LinkClicked(object sender, LinkClickedEventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (settings.openLinks == "LMB Click")
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
|
|
|
|
|
Process.Start(e.LinkText);
|
|
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (settings.openLinks == "Shift+LMB")
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((ModifierKeys & Keys.Shift) != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Process.Start(e.LinkText);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (settings.openLinks == "Control+LMB")
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((ModifierKeys & Keys.Control) != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
Process.Start(e.LinkText);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-06 09:04:35 +00:00
|
|
|
|
private async void RichTextBox_DragDrop(object sender, DragEventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
SaveConfirm();
|
|
|
|
|
|
if (cancelPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
cancelPressed = false;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
|
2019-09-28 19:57:03 +00:00
|
|
|
|
foreach (string file in FileList) openFileDialog.FileName = file;
|
2019-10-15 17:21:28 +00:00
|
|
|
|
object fileName = e.Data.GetData("FileDrop");
|
2019-09-28 19:57:03 +00:00
|
|
|
|
PublicVar.openFileName = Path.GetFileName(openFileDialog.FileName);
|
2019-10-15 17:21:28 +00:00
|
|
|
|
if (fileName != null)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-15 17:21:28 +00:00
|
|
|
|
if (fileName is string[] list && !string.IsNullOrWhiteSpace(list[0]))
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (!openFileDialog.FileName.Contains(".cnp"))
|
|
|
|
|
|
{
|
2019-11-05 19:23:13 +00:00
|
|
|
|
if (Visible)
|
|
|
|
|
|
{
|
|
|
|
|
|
PublicVar.messageBoxCenterParent = true;
|
|
|
|
|
|
}
|
2019-11-05 20:30:49 +00:00
|
|
|
|
using (new CenterWinDialog(this))
|
|
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
DialogResult res = MessageBox.Show(this, "Try to decrypt \"" + PublicVar.openFileName + "\" file?", PublicVar.appName,
|
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Information);
|
2019-11-05 20:30:49 +00:00
|
|
|
|
if (res == DialogResult.No)
|
|
|
|
|
|
{
|
|
|
|
|
|
string opnfile = File.ReadAllText(openFileDialog.FileName);
|
|
|
|
|
|
string NameWithotPath = Path.GetFileName(openFileDialog.FileName);
|
|
|
|
|
|
richTextBox.Text = opnfile;
|
|
|
|
|
|
Text = PublicVar.appName + " – " + NameWithotPath;
|
|
|
|
|
|
filePath = openFileDialog.FileName;
|
|
|
|
|
|
StatusPanelFileInfo();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2019-11-06 09:04:35 +00:00
|
|
|
|
await DecryptAES();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:37:04 +00:00
|
|
|
|
private void RichTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-10-25 21:11:24 +00:00
|
|
|
|
statusPanelTimer.Start();
|
2019-11-05 20:54:16 +00:00
|
|
|
|
|
|
|
|
|
|
if (richTextBox.Modified)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Text.Contains("*"))
|
|
|
|
|
|
{
|
|
|
|
|
|
Text += "*";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Text.Contains("*"))
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = Text.Substring(0, Text.Length - 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (richTextBox.TextLength == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Text.Contains("*"))
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = Text.Substring(0, Text.Length - 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-09-28 19:37:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 11:59:01 +00:00
|
|
|
|
private void StatusPanelLabel_TextChanged(object sender, EventArgs e)
|
2019-09-28 19:37:04 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
if (statusPanelLabel.Text == "New version is available")
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
statusPanelLabel.IsLink = true;
|
2019-09-28 19:37:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
statusPanelLabel.IsLink = false;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 11:59:01 +00:00
|
|
|
|
private void StatusPanelLabel_Click(object sender, EventArgs e)
|
2019-09-28 19:37:04 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
if (statusPanelLabel.Text == "New version is available")
|
2019-09-28 19:37:04 +00:00
|
|
|
|
{
|
|
|
|
|
|
string exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\";
|
|
|
|
|
|
using (new CenterWinDialog(this))
|
|
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
DialogResult res = MessageBox.Show(this, "New version is available. Install it now?", PublicVar.appName,
|
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Information);
|
2019-09-28 19:37:04 +00:00
|
|
|
|
if (res == DialogResult.Yes)
|
|
|
|
|
|
{
|
2019-10-04 18:48:55 +00:00
|
|
|
|
File.WriteAllBytes(exePath + "Ionic.Zip.dll", Resources.Ionic_Zip);
|
|
|
|
|
|
File.WriteAllBytes(exePath + "Updater.exe", Resources.Updater);
|
2019-09-28 19:37:04 +00:00
|
|
|
|
var pr = new Process();
|
|
|
|
|
|
pr.StartInfo.FileName = exePath + "Updater.exe";
|
|
|
|
|
|
pr.StartInfo.Arguments = "/u";
|
|
|
|
|
|
pr.Start();
|
|
|
|
|
|
Application.Exit();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
2018-12-17 11:16:17 +00:00
|
|
|
|
|
2018-12-25 15:29:29 +00:00
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
#region Main Menu
|
2018-12-25 15:29:29 +00:00
|
|
|
|
/*File*/
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void NewMainMenu_Click(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
SaveConfirm();
|
|
|
|
|
|
if (cancelPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
cancelPressed = false;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2019-01-07 10:09:52 +00:00
|
|
|
|
PublicVar.openFileName = "Unnamed.cnp";
|
2019-09-28 19:57:03 +00:00
|
|
|
|
EnterKeyForm enterKeyForm = new EnterKeyForm
|
|
|
|
|
|
{
|
|
|
|
|
|
Owner = this
|
|
|
|
|
|
};
|
|
|
|
|
|
enterKeyForm.ShowDialog();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
|
2018-12-25 15:29:29 +00:00
|
|
|
|
if (!PublicVar.okPressed)
|
|
|
|
|
|
{
|
2019-10-15 16:48:17 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
2019-01-07 10:09:52 +00:00
|
|
|
|
{
|
|
|
|
|
|
PublicVar.openFileName = Path.GetFileName(filePath);
|
2019-08-21 11:15:16 +00:00
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
TypedPassword.Value = null;
|
2019-10-25 21:12:19 +00:00
|
|
|
|
PublicVar.okPressed = false;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (saveFileDialog.ShowDialog() != DialogResult.OK)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
|
|
|
|
|
TypedPassword.Value = null;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Clear();
|
2019-10-25 21:12:19 +00:00
|
|
|
|
saveFileDialog.FileName = "Unnamed.cnp";
|
|
|
|
|
|
PublicVar.encryptionKey.Set(TypedPassword.Value);
|
2019-09-28 19:57:03 +00:00
|
|
|
|
StreamWriter sw = new StreamWriter(saveFileDialog.FileName);
|
|
|
|
|
|
string NameWithotPath = Path.GetFileName(saveFileDialog.FileName);
|
2019-01-07 10:08:47 +00:00
|
|
|
|
Text = PublicVar.appName + " – " + NameWithotPath;
|
2019-09-28 19:57:03 +00:00
|
|
|
|
filePath = saveFileDialog.FileName;
|
|
|
|
|
|
PublicVar.openFileName = Path.GetFileName(saveFileDialog.FileName);
|
2018-12-25 15:29:29 +00:00
|
|
|
|
sw.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
TypedPassword.Value = null;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-06 09:04:35 +00:00
|
|
|
|
private async void OpenMainMenu_Click(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
SaveConfirm();
|
|
|
|
|
|
if (cancelPressed)
|
2019-09-28 19:57:03 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
cancelPressed = false;
|
2019-09-28 19:57:03 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2019-10-13 11:59:01 +00:00
|
|
|
|
openFileDialog.FileName = "";
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (openFileDialog.ShowDialog() != DialogResult.OK) return;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
PublicVar.openFileName = Path.GetFileName(openFileDialog.FileName);
|
|
|
|
|
|
if (!openFileDialog.FileName.Contains(".cnp"))
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
if (Visible)
|
|
|
|
|
|
{
|
|
|
|
|
|
PublicVar.messageBoxCenterParent = true;
|
|
|
|
|
|
}
|
2019-11-05 20:30:49 +00:00
|
|
|
|
using (new CenterWinDialog(this))
|
|
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
DialogResult res = MessageBox.Show(this, "Try to decrypt \"" + PublicVar.openFileName + "\" file?", PublicVar.appName,
|
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Information);
|
2019-11-05 20:30:49 +00:00
|
|
|
|
if (res == DialogResult.No)
|
|
|
|
|
|
{
|
|
|
|
|
|
string opnfile = File.ReadAllText(openFileDialog.FileName);
|
|
|
|
|
|
string NameWithotPath = Path.GetFileName(openFileDialog.FileName);
|
|
|
|
|
|
richTextBox.Text = opnfile;
|
|
|
|
|
|
Text = PublicVar.appName + " – " + NameWithotPath;
|
|
|
|
|
|
filePath = openFileDialog.FileName;
|
|
|
|
|
|
StatusPanelFileInfo();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2019-11-06 09:04:35 +00:00
|
|
|
|
await DecryptAES();
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Modified = false;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-06 09:04:35 +00:00
|
|
|
|
private async void SaveMainMenu_Click(object sender, EventArgs e)
|
2019-10-25 21:11:24 +00:00
|
|
|
|
{
|
2019-10-15 16:48:17 +00:00
|
|
|
|
if (string.IsNullOrEmpty(PublicVar.encryptionKey.Get()))
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
SaveAsMainMenu_Click(this, new EventArgs());
|
2019-10-15 16:48:17 +00:00
|
|
|
|
return;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2019-11-06 09:04:35 +00:00
|
|
|
|
mainMenu.Enabled = false;
|
|
|
|
|
|
toolbarPanel.Enabled = false;
|
|
|
|
|
|
richTextBox.ReadOnly = true;
|
|
|
|
|
|
richTextBox.SuspendDrawing();
|
|
|
|
|
|
UseWaitCursor = true;
|
2019-08-30 10:05:29 +00:00
|
|
|
|
using (StreamWriter writer = new StreamWriter(filePath))
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
writer.Write(await AES.Encrypt(richTextBox.Text, PublicVar.encryptionKey.Get(), null, settings.HashAlgorithm,
|
|
|
|
|
|
Convert.ToInt32(settings.PasswordIterations), Convert.ToInt32(settings.KeySize)));
|
2019-08-30 10:05:29 +00:00
|
|
|
|
writer.Close();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Modified = false;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
PublicVar.keyChanged = false;
|
2019-09-28 19:37:04 +00:00
|
|
|
|
StatusPanelMessage("save");
|
2019-10-25 21:11:24 +00:00
|
|
|
|
StatusPanelFileInfo();
|
2019-11-06 09:04:35 +00:00
|
|
|
|
richTextBox.ResumeDrawing();
|
|
|
|
|
|
UseWaitCursor = false;
|
|
|
|
|
|
mainMenu.Enabled = true;
|
|
|
|
|
|
toolbarPanel.Enabled = true;
|
|
|
|
|
|
richTextBox.ReadOnly = false;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-06 09:04:35 +00:00
|
|
|
|
private async void SaveAsMainMenu_Click(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-15 16:48:17 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
2019-01-07 10:09:52 +00:00
|
|
|
|
{
|
|
|
|
|
|
PublicVar.openFileName = Path.GetFileName(filePath);
|
2019-09-28 19:57:03 +00:00
|
|
|
|
saveFileDialog.FileName = Path.GetFileName(filePath);
|
2019-01-07 10:09:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
PublicVar.openFileName = "Unnamed.cnp";
|
2019-09-28 19:57:03 +00:00
|
|
|
|
saveFileDialog.FileName = "Unnamed.cnp";
|
2019-01-07 10:09:52 +00:00
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
EnterKeyForm enterKeyForm = new EnterKeyForm
|
|
|
|
|
|
{
|
|
|
|
|
|
Owner = this
|
|
|
|
|
|
};
|
2018-12-25 15:29:29 +00:00
|
|
|
|
if (string.IsNullOrEmpty(PublicVar.encryptionKey.Get()))
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
enterKeyForm.ShowDialog();
|
2019-10-15 17:22:53 +00:00
|
|
|
|
if (!PublicVar.okPressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
PublicVar.openFileName = Path.GetFileName(filePath);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (saveFileDialog.ShowDialog() != DialogResult.OK)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
if (TypedPassword.Value == null)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2018-12-25 15:29:29 +00:00
|
|
|
|
TypedPassword.Value = PublicVar.encryptionKey.Get();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
filePath = saveFileDialog.FileName;
|
2019-11-06 09:04:35 +00:00
|
|
|
|
string enc = await AES.Encrypt(richTextBox.Text, TypedPassword.Value, null, settings.HashAlgorithm,
|
|
|
|
|
|
Convert.ToInt32(settings.PasswordIterations), Convert.ToInt32(settings.KeySize));
|
2019-08-30 10:05:29 +00:00
|
|
|
|
using (StreamWriter writer = new StreamWriter(filePath))
|
|
|
|
|
|
{
|
|
|
|
|
|
writer.Write(enc);
|
|
|
|
|
|
writer.Close();
|
|
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Modified = false;
|
2019-01-07 10:08:47 +00:00
|
|
|
|
Text = PublicVar.appName + " – " + Path.GetFileName(filePath);
|
2018-12-25 15:29:29 +00:00
|
|
|
|
PublicVar.encryptionKey.Set(TypedPassword.Value);
|
|
|
|
|
|
TypedPassword.Value = null;
|
2019-09-28 19:57:03 +00:00
|
|
|
|
PublicVar.openFileName = Path.GetFileName(saveFileDialog.FileName);
|
2019-09-28 19:37:04 +00:00
|
|
|
|
StatusPanelMessage("save");
|
2019-10-25 21:11:24 +00:00
|
|
|
|
StatusPanelFileInfo();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-05 20:00:38 +00:00
|
|
|
|
private async void SaveCloseFileMainMenu_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
//using (StreamWriter writer = new StreamWriter(filePath))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// writer.Write(AES.Encrypt(richTextBox.Text, PublicVar.encryptionKey.Get(), null, settings.HashAlgorithm,
|
|
|
|
|
|
// Convert.ToInt32(settings.PasswordIterations), Convert.ToInt32(settings.KeySize)));
|
|
|
|
|
|
// writer.Close();
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
mainMenu.Enabled = false;
|
|
|
|
|
|
toolbarPanel.Enabled = false;
|
|
|
|
|
|
richTextBox.SuspendDrawing();
|
|
|
|
|
|
UseWaitCursor = true;
|
2019-11-05 20:00:38 +00:00
|
|
|
|
using (StreamWriter writer = new StreamWriter(filePath))
|
|
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
writer.Write(await AES.Encrypt(richTextBox.Text, PublicVar.encryptionKey.Get(), null, settings.HashAlgorithm,
|
|
|
|
|
|
Convert.ToInt32(settings.PasswordIterations), Convert.ToInt32(settings.KeySize)));
|
2019-11-05 20:00:38 +00:00
|
|
|
|
writer.Close();
|
|
|
|
|
|
}
|
2019-11-06 09:04:35 +00:00
|
|
|
|
richTextBox.ResumeDrawing();
|
|
|
|
|
|
UseWaitCursor = false;
|
|
|
|
|
|
mainMenu.Enabled = true;
|
|
|
|
|
|
toolbarPanel.Enabled = true;
|
|
|
|
|
|
richTextBox.ReadOnly = false;
|
2019-11-05 20:00:38 +00:00
|
|
|
|
PublicVar.encryptionKey.Set(null);
|
|
|
|
|
|
richTextBox.Clear();
|
|
|
|
|
|
PublicVar.openFileName = "";
|
|
|
|
|
|
filePath = "";
|
|
|
|
|
|
Text = PublicVar.appName;
|
|
|
|
|
|
statusPanelModifiedLabel.Text = "Modified";
|
|
|
|
|
|
statusPanelModifiedLabel.ToolTipText = null;
|
|
|
|
|
|
statusPanelSizeLabel.Text = "Size";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 12:55:13 +00:00
|
|
|
|
private void OpenFileLocationMainMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
|
|
|
|
|
Process.Start("explorer.exe", @"/select, " + filePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DeleteFileToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-10-15 16:48:17 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(filePath))
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
|
|
|
|
|
using (new CenterWinDialog(this))
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
if (MessageBox.Show(this, "Delete file: " + "\"" + filePath + "\"" + " ?", PublicVar.appName,
|
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2018-12-25 15:29:29 +00:00
|
|
|
|
File.Delete(filePath);
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Clear();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
PublicVar.encryptionKey.Set(null);
|
2019-09-28 19:57:03 +00:00
|
|
|
|
fileLocationToolbarButton.Enabled = false;
|
|
|
|
|
|
deleteFileToolbarButton.Enabled = false;
|
|
|
|
|
|
changeKeyToolbarButton.Enabled = false;
|
|
|
|
|
|
lockToolbarButton.Enabled = false;
|
2018-12-19 22:56:59 +00:00
|
|
|
|
filePath = "";
|
2019-10-15 16:48:17 +00:00
|
|
|
|
PublicVar.openFileName = "";
|
2019-01-07 10:08:47 +00:00
|
|
|
|
Text = PublicVar.appName;
|
2019-10-25 21:11:24 +00:00
|
|
|
|
StatusPanelTextInfo();
|
2019-11-03 18:31:06 +00:00
|
|
|
|
statusPanelModifiedLabel.Text = "Modified";
|
2019-10-25 21:11:24 +00:00
|
|
|
|
statusPanelSizeLabel.Text = "Size";
|
|
|
|
|
|
statusPanelModifiedLabel.ToolTipText = null;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void ExitMainMenu_Click(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-13 11:59:01 +00:00
|
|
|
|
Application.Exit();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
|
2019-10-13 12:24:47 +00:00
|
|
|
|
private void FileMainMenu_DropDownOpened(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-15 16:48:17 +00:00
|
|
|
|
if (string.IsNullOrEmpty(filePath))
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-13 12:55:13 +00:00
|
|
|
|
openFileLocationMainMenu.Enabled = false;
|
2019-09-28 19:57:03 +00:00
|
|
|
|
deleteFileMainMenu.Enabled = false;
|
2019-11-05 20:00:38 +00:00
|
|
|
|
saveCloseFileMainMenu.Enabled = false;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-10-13 12:55:13 +00:00
|
|
|
|
openFileLocationMainMenu.Enabled = true;
|
2019-09-28 19:57:03 +00:00
|
|
|
|
deleteFileMainMenu.Enabled = true;
|
2019-11-05 20:00:38 +00:00
|
|
|
|
saveCloseFileMainMenu.Enabled = true;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
/*File*/
|
2018-12-17 11:16:17 +00:00
|
|
|
|
|
2018-12-25 15:29:29 +00:00
|
|
|
|
/*Edit*/
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void EditMainMenu_DropDownOpened(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (richTextBox.SelectionLength != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
cutMainMenu.Enabled = true;
|
|
|
|
|
|
copyMainMenu.Enabled = true;
|
|
|
|
|
|
deleteMainMenu.Enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
cutMainMenu.Enabled = false;
|
|
|
|
|
|
copyMainMenu.Enabled = false;
|
|
|
|
|
|
deleteMainMenu.Enabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UndoMainMenu_Click(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Undo();
|
|
|
|
|
|
richTextBox.DeselectAll();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
public void RedoMainMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Redo();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void CutMainMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Cut();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void CopyMainMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Copy();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void PasteMainMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (richTextBox.Focused)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Paste(DataFormats.GetFormat(DataFormats.Text));
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (searchTextBox.Focused)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
searchTextBox.Paste();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void DeleteMainMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.SelectedText = "";
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void FindMainMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-11 10:38:15 +00:00
|
|
|
|
if (!richTextBox.Visible) return;
|
2019-10-25 21:11:24 +00:00
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (searchPanel.Visible)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
searchTextBox.Text = "";
|
|
|
|
|
|
searchPanel.Visible = false;
|
|
|
|
|
|
richTextBox.Focus();
|
|
|
|
|
|
richTextBox.DeselectAll();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
searchPanel.Visible = true;
|
|
|
|
|
|
searchTextBox.Focus();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void SelectAllMainMenu_Click(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (richTextBox.Focused)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.SelectAll();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (searchTextBox.Focused)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
searchTextBox.SelectAll();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void WordWrapMainMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (wordWrapMainMenu.Checked)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.WordWrap = true;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.WordWrap = false;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
settings.menuWrap = wordWrapMainMenu.Checked;
|
|
|
|
|
|
settings.editorWrap = richTextBox.WordWrap;
|
|
|
|
|
|
settings.Save();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void ClearMainMenu_Click(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.SelectAll();
|
|
|
|
|
|
richTextBox.SelectedText = " ";
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
/*Edit*/
|
2018-12-17 11:16:17 +00:00
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
/*Tools*/
|
2019-10-11 10:31:24 +00:00
|
|
|
|
private void AlwaysOnTopMainMenu_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (alwaysOnTopMainMenu.Checked)
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.alwaysOnTop = true;
|
|
|
|
|
|
TopMost = true;
|
|
|
|
|
|
StatusPanelMessage("always-top-on");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.alwaysOnTop = false;
|
|
|
|
|
|
TopMost = false;
|
|
|
|
|
|
StatusPanelMessage("always-top-off");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-10-11 10:38:15 +00:00
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void ToolsMainMenu_DropDownOpened(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-10-15 16:48:17 +00:00
|
|
|
|
if (string.IsNullOrEmpty(PublicVar.encryptionKey.Get()))
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
changeKeyMainMenu.Enabled = false;
|
|
|
|
|
|
lockMainMenu.Enabled = false;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
changeKeyMainMenu.Enabled = true;
|
|
|
|
|
|
lockMainMenu.Enabled = true;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void ChangeKeyMainMenu_Click(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
ChangeKeyForm changeKeyForm = new ChangeKeyForm();
|
|
|
|
|
|
changeKeyForm.ShowDialog(this);
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-06 09:04:35 +00:00
|
|
|
|
private async void LockMainMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
//SaveMainMenu_Click(this, new EventArgs());
|
|
|
|
|
|
mainMenu.Enabled = false;
|
|
|
|
|
|
toolbarPanel.Enabled = false;
|
|
|
|
|
|
richTextBox.SuspendDrawing();
|
|
|
|
|
|
UseWaitCursor = true;
|
|
|
|
|
|
using (StreamWriter writer = new StreamWriter(filePath))
|
|
|
|
|
|
{
|
|
|
|
|
|
writer.Write(await AES.Encrypt(richTextBox.Text, PublicVar.encryptionKey.Get(), null, settings.HashAlgorithm,
|
|
|
|
|
|
Convert.ToInt32(settings.PasswordIterations), Convert.ToInt32(settings.KeySize)));
|
|
|
|
|
|
writer.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
richTextBox.ResumeDrawing();
|
|
|
|
|
|
UseWaitCursor = false;
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedPanel.Visible = true;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void SettingsMainMenu_Click(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
SettingsForm settingsForm = new SettingsForm
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
Owner = this
|
|
|
|
|
|
};
|
|
|
|
|
|
settingsForm.ShowDialog();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
/*Tools*/
|
|
|
|
|
|
|
|
|
|
|
|
/*Help*/
|
2019-10-13 12:55:13 +00:00
|
|
|
|
private void DocumentationMainMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-01-02 19:10:41 +00:00
|
|
|
|
Process.Start("https://github.com/Crypto-Notepad/Crypto-Notepad/wiki/Documentation");
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 12:55:13 +00:00
|
|
|
|
private void CheckForUpdatesMainMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-02 16:35:34 +00:00
|
|
|
|
CheckForUpdates(true);
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void AboutMainMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
AboutFrom aboutFrom = new AboutFrom();
|
|
|
|
|
|
aboutFrom.ShowDialog(this);
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
/*Help*/
|
2019-09-28 19:57:03 +00:00
|
|
|
|
#endregion
|
2018-12-25 15:29:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
#region Editor Menu
|
|
|
|
|
|
private void ContextMenu_Opening(object sender, CancelEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (richTextBox.SelectionLength != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
cutContextMenu.Enabled = true;
|
|
|
|
|
|
copyContextMenu.Enabled = true;
|
|
|
|
|
|
deleteContextMenu.Enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
cutContextMenu.Enabled = false;
|
|
|
|
|
|
copyContextMenu.Enabled = false;
|
|
|
|
|
|
deleteContextMenu.Enabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void UndoContextMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
UndoMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void RedoContextMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
RedoMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void CutContextMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-25 21:11:24 +00:00
|
|
|
|
CutMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void CopyContextMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
CopyMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void PasteContextMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
PasteMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void DeleteContextMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
DeleteMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void SelectAllContextMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
SelectAllMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
|
2019-09-28 19:29:24 +00:00
|
|
|
|
private void RightToLeftContextMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:22:59 +00:00
|
|
|
|
{
|
2019-09-28 19:29:24 +00:00
|
|
|
|
if (rightToLeftContextMenu.Checked)
|
2018-12-25 15:22:59 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
if (!richTextBox.WordWrap)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
string rtbTxt = richTextBox.Text;
|
|
|
|
|
|
richTextBox.Clear();
|
2019-09-28 19:29:24 +00:00
|
|
|
|
richTextBox.RightToLeft = RightToLeft.Yes;
|
2018-12-25 15:22:59 +00:00
|
|
|
|
Application.DoEvents();
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Text = rtbTxt;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2018-12-25 15:22:59 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
string rtbTxt = richTextBox.Text;
|
|
|
|
|
|
richTextBox.Clear();
|
2019-09-28 19:29:24 +00:00
|
|
|
|
richTextBox.RightToLeft = RightToLeft.Yes;
|
2019-09-28 19:57:03 +00:00
|
|
|
|
Application.DoEvents();
|
|
|
|
|
|
richTextBox.Text = rtbTxt;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-09-28 19:29:24 +00:00
|
|
|
|
settings.editorRightToLeft = true;
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Modified = false;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2018-12-25 15:22:59 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-09-28 19:29:24 +00:00
|
|
|
|
richTextBox.RightToLeft = RightToLeft.No;
|
|
|
|
|
|
settings.editorRightToLeft = false;
|
2019-09-28 19:57:03 +00:00
|
|
|
|
richTextBox.Modified = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
settings.Save();
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void ClearContextMenu_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
ClearMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
#endregion
|
2018-12-17 11:16:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
#region Toolbar
|
2018-12-25 15:29:29 +00:00
|
|
|
|
private void NewToolbarButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
NewMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
|
2018-12-25 15:29:29 +00:00
|
|
|
|
private void OpenToolbarButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
OpenMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SaveToolbarButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
SaveMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void FileLocationToolbarButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-10-13 12:55:13 +00:00
|
|
|
|
OpenFileLocationMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DeleteFileToolbarButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
DeleteFileToolStripMenuItem_Click(this, new EventArgs());
|
|
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
|
2018-12-25 15:29:29 +00:00
|
|
|
|
private void CutToolbarButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
CutMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CopyToolbarButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
CopyMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void PasteToolbarButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
PasteMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ChangeKeyToolbarButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
ChangeKeyMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SettingsToolbarButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
SettingsMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-04 12:14:12 +00:00
|
|
|
|
private void LockToolbarButton_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
LockMainMenu_Click(this, new EventArgs());
|
2019-01-04 12:17:03 +00:00
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void CloseToolbarButton_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-09-28 19:57:03 +00:00
|
|
|
|
toolbarPanel.Visible = false;
|
2019-10-04 18:48:55 +00:00
|
|
|
|
settings.toolbarVisible = false;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void CloseToolbarButton_MouseEnter(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-17 21:00:03 +00:00
|
|
|
|
closeToolbarButton.ForeColor = Color.DimGray;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
|
2019-09-28 19:57:03 +00:00
|
|
|
|
private void CloseToolbarButton_MouseLeave(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-17 21:00:03 +00:00
|
|
|
|
closeToolbarButton.ForeColor = Color.DarkGray;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-10-11 10:31:24 +00:00
|
|
|
|
|
|
|
|
|
|
private void AlwaysOnTopToolbarButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (settings.alwaysOnTop)
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.alwaysOnTop = false;
|
|
|
|
|
|
TopMost = settings.alwaysOnTop;
|
|
|
|
|
|
alwaysOnTopMainMenu.Checked = settings.alwaysOnTop;
|
|
|
|
|
|
StatusPanelMessage("always-top-off");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.alwaysOnTop = true;
|
|
|
|
|
|
TopMost = settings.alwaysOnTop;
|
|
|
|
|
|
alwaysOnTopMainMenu.Checked = settings.alwaysOnTop;
|
|
|
|
|
|
StatusPanelMessage("always-top-on");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-10-11 10:38:15 +00:00
|
|
|
|
|
|
|
|
|
|
private void ToolbarPanel_MouseEnter(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (richTextBox.SelectionLength != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
cutToolbarButton.Enabled = true;
|
|
|
|
|
|
copyToolbarButton.Enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
cutToolbarButton.Enabled = false;
|
|
|
|
|
|
copyToolbarButton.Enabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-15 16:48:17 +00:00
|
|
|
|
if (string.IsNullOrEmpty(PublicVar.encryptionKey.Get()))
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
|
|
|
|
|
fileLocationToolbarButton.Enabled = false;
|
|
|
|
|
|
deleteFileToolbarButton.Enabled = false;
|
|
|
|
|
|
changeKeyToolbarButton.Enabled = false;
|
|
|
|
|
|
lockToolbarButton.Enabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
fileLocationToolbarButton.Enabled = true;
|
|
|
|
|
|
deleteFileToolbarButton.Enabled = true;
|
|
|
|
|
|
changeKeyToolbarButton.Enabled = true;
|
|
|
|
|
|
lockToolbarButton.Enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-09-28 19:57:03 +00:00
|
|
|
|
#endregion
|
2018-12-25 15:29:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-09-28 19:54:34 +00:00
|
|
|
|
#region Search Panel
|
2018-12-25 15:29:29 +00:00
|
|
|
|
private void SearchTextBox_TextChanged(object sender, EventArgs e)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-08-22 17:05:18 +00:00
|
|
|
|
findPos = 0;
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SearchTextBox_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.KeyCode == Keys.Escape)
|
2018-12-17 11:16:17 +00:00
|
|
|
|
{
|
2019-09-28 19:54:34 +00:00
|
|
|
|
searchTextBox.Text = "";
|
|
|
|
|
|
searchPanel.Visible = false;
|
|
|
|
|
|
richTextBox.Focus();
|
|
|
|
|
|
richTextBox.DeselectAll();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
e.Handled = e.SuppressKeyPress = true;
|
2019-08-22 17:05:18 +00:00
|
|
|
|
findPos = 0;
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-10-15 16:09:51 +00:00
|
|
|
|
if (e.KeyCode == Keys.Enter & searchPanel.Visible & !string.IsNullOrEmpty(searchTextBox.Text))
|
2019-09-28 19:54:34 +00:00
|
|
|
|
{
|
2019-10-18 10:37:33 +00:00
|
|
|
|
SearchFindNextButton_MouseUp(null, null);
|
2019-09-28 19:54:34 +00:00
|
|
|
|
e.Handled = e.SuppressKeyPress = true;
|
|
|
|
|
|
}
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
|
2019-10-17 21:00:03 +00:00
|
|
|
|
private void SearchCloseButton_Click(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-10-17 21:00:03 +00:00
|
|
|
|
FindMainMenu_Click(this, new EventArgs());
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 11:54:45 +00:00
|
|
|
|
private void SearchCaseSensitiveCheckBox_CheckedChanged(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-08-22 17:05:18 +00:00
|
|
|
|
findPos = 0;
|
2019-09-28 19:54:34 +00:00
|
|
|
|
richTextBox.DeselectAll();
|
2019-10-17 21:00:03 +00:00
|
|
|
|
searchTextBox.Focus();
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 11:54:45 +00:00
|
|
|
|
private void SearchWholeWordCheckBox_CheckedChanged(object sender, EventArgs e)
|
2018-12-25 15:29:29 +00:00
|
|
|
|
{
|
2019-08-22 17:05:18 +00:00
|
|
|
|
findPos = 0;
|
2019-09-28 19:54:34 +00:00
|
|
|
|
richTextBox.DeselectAll();
|
2019-10-17 21:00:03 +00:00
|
|
|
|
searchTextBox.Focus();
|
2019-08-22 17:05:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-27 07:04:44 +00:00
|
|
|
|
private void FindText(string text, RichTextBoxFinds findOptions)
|
2019-08-22 17:05:18 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (text.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2019-09-28 19:54:34 +00:00
|
|
|
|
findPos = richTextBox.Find(searchTextBox.Text, findPos, findOptions);
|
2019-08-22 17:05:18 +00:00
|
|
|
|
if (findPos == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
findPos = 0;
|
2019-09-28 19:54:34 +00:00
|
|
|
|
searchTextBox.Focus();
|
2019-08-22 17:05:18 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2019-09-28 19:54:34 +00:00
|
|
|
|
richTextBox.Focus();
|
|
|
|
|
|
richTextBox.Select(findPos, searchTextBox.Text.Length);
|
|
|
|
|
|
findPos += searchTextBox.Text.Length + 1;
|
2019-08-22 17:05:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
findPos = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-09-28 19:54:34 +00:00
|
|
|
|
|
2019-10-18 10:37:33 +00:00
|
|
|
|
private void SearchFindNextButton_MouseUp(object sender, MouseEventArgs e)
|
2019-08-22 17:05:18 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
if ((!searchWholeWordCheckBox.Checked) & (!searchCaseSensitiveCheckBox.Checked))
|
2019-08-22 17:05:18 +00:00
|
|
|
|
{
|
2019-09-28 19:54:34 +00:00
|
|
|
|
FindText(searchTextBox.Text, RichTextBoxFinds.None);
|
2019-08-22 17:05:18 +00:00
|
|
|
|
}
|
2019-10-18 10:40:01 +00:00
|
|
|
|
else if (searchWholeWordCheckBox.Checked & searchCaseSensitiveCheckBox.Checked)
|
2019-08-22 17:05:18 +00:00
|
|
|
|
{
|
2019-09-28 19:54:34 +00:00
|
|
|
|
FindText(searchTextBox.Text, RichTextBoxFinds.MatchCase | RichTextBoxFinds.WholeWord);
|
2019-08-22 17:05:18 +00:00
|
|
|
|
}
|
2019-10-18 10:40:01 +00:00
|
|
|
|
else if (searchCaseSensitiveCheckBox.Checked)
|
2019-08-22 17:05:18 +00:00
|
|
|
|
{
|
2019-09-28 19:54:34 +00:00
|
|
|
|
FindText(searchTextBox.Text, RichTextBoxFinds.MatchCase);
|
2019-08-22 17:05:18 +00:00
|
|
|
|
}
|
2019-10-18 10:40:01 +00:00
|
|
|
|
else if (searchWholeWordCheckBox.Checked)
|
2019-08-22 17:05:18 +00:00
|
|
|
|
{
|
2019-09-28 19:54:34 +00:00
|
|
|
|
FindText(searchTextBox.Text, RichTextBoxFinds.WholeWord);
|
2019-08-22 17:05:18 +00:00
|
|
|
|
}
|
2018-12-25 15:29:29 +00:00
|
|
|
|
}
|
2019-10-18 14:30:36 +00:00
|
|
|
|
|
|
|
|
|
|
private void SearchFindNextButton_MouseEnter(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentClipboardText = Clipboard.GetText();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SearchFindNextButton_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Clipboard.SetText(currentClipboardText);
|
|
|
|
|
|
}
|
2019-09-28 19:54:34 +00:00
|
|
|
|
#endregion
|
2018-12-25 15:29:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-10-11 10:38:15 +00:00
|
|
|
|
#region AutoLock
|
2019-10-13 11:54:45 +00:00
|
|
|
|
private void FileLockedKeyTextBox_TextChanged(object sender, EventArgs e)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
if (fileLockedKeyTextBox.Text.Length > 0)
|
2019-10-13 12:08:51 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedOkButton.Enabled = true;
|
2019-10-13 12:08:51 +00:00
|
|
|
|
}
|
2019-10-11 10:38:15 +00:00
|
|
|
|
else
|
2019-10-13 12:08:51 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedOkButton.Enabled = false;
|
2019-10-13 12:08:51 +00:00
|
|
|
|
}
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 11:54:45 +00:00
|
|
|
|
private void FileLockedPanel_VisibleChanged(object sender, EventArgs e)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
if (fileLockedPanel.Visible)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-13 12:25:32 +00:00
|
|
|
|
foreach (ToolStripItem item in mainMenu.Items)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item is ToolStripDropDownItem)
|
|
|
|
|
|
foreach (ToolStripItem dropDownItem in ((ToolStripDropDownItem)item).DropDownItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
dropDownItem.Enabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-10-17 20:57:57 +00:00
|
|
|
|
if (searchPanel.Visible)
|
|
|
|
|
|
{
|
|
|
|
|
|
searchTextBox.Text = "";
|
|
|
|
|
|
searchPanel.Visible = false;
|
|
|
|
|
|
}
|
2019-10-11 10:38:15 +00:00
|
|
|
|
PublicVar.encryptionKey.Set(null);
|
|
|
|
|
|
caretPos = richTextBox.SelectionStart;
|
|
|
|
|
|
richTextBox.Visible = false;
|
|
|
|
|
|
toolbarPanel.Enabled = false;
|
|
|
|
|
|
mainMenu.Enabled = false;
|
|
|
|
|
|
richTextBox.Clear();
|
2019-10-25 21:11:24 +00:00
|
|
|
|
StatusPanelTextInfo();
|
2019-11-03 18:31:06 +00:00
|
|
|
|
statusPanelModifiedLabel.Text = "Modified";
|
2019-11-06 09:05:18 +00:00
|
|
|
|
statusPanelModifiedLabel.ToolTipText = null;
|
2019-10-25 21:11:24 +00:00
|
|
|
|
statusPanelSizeLabel.Text = "Size";
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedKeyTextBox.Focus();
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-10-13 12:25:32 +00:00
|
|
|
|
foreach (ToolStripItem item in mainMenu.Items)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item is ToolStripDropDownItem)
|
|
|
|
|
|
foreach (ToolStripItem dropDownItem in ((ToolStripDropDownItem)item).DropDownItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
dropDownItem.Enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-11 10:38:15 +00:00
|
|
|
|
richTextBox.Visible = true;
|
|
|
|
|
|
toolbarPanel.Enabled = true;
|
|
|
|
|
|
searchPanel.Enabled = true;
|
|
|
|
|
|
mainMenu.Enabled = true;
|
2019-10-15 16:48:17 +00:00
|
|
|
|
fileLockedKeyTextBox.Text = "";
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-06 09:04:35 +00:00
|
|
|
|
private async void FileLockedOkButton_Click(object sender, EventArgs e)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-11-06 09:04:35 +00:00
|
|
|
|
await UnlockFile();
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 11:54:45 +00:00
|
|
|
|
private void FileLockedCloseButton_MouseClick(object sender, MouseEventArgs e)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedPanel.Visible = false;
|
2019-10-11 10:38:15 +00:00
|
|
|
|
Text = PublicVar.appName;
|
2019-10-15 16:48:17 +00:00
|
|
|
|
filePath = "";
|
2019-10-25 21:11:24 +00:00
|
|
|
|
PublicVar.openFileName = "";
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 11:54:45 +00:00
|
|
|
|
private void FileLockedShowKey_Click(object sender, EventArgs e)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
if (fileLockedKeyTextBox.UseSystemPasswordChar)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedKeyTextBox.UseSystemPasswordChar = false;
|
|
|
|
|
|
fileLockedShowKey.Image = Resources.eye;
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedKeyTextBox.UseSystemPasswordChar = true;
|
|
|
|
|
|
fileLockedShowKey.Image = Resources.eye_half;
|
2019-10-25 21:11:24 +00:00
|
|
|
|
}
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 11:54:45 +00:00
|
|
|
|
private void FileLockedKeyTextBox_KeyDown(object sender, KeyEventArgs e)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-15 16:13:08 +00:00
|
|
|
|
if (e.KeyCode == Keys.Enter)
|
|
|
|
|
|
{
|
|
|
|
|
|
e.SuppressKeyPress = true;
|
|
|
|
|
|
}
|
2019-10-13 11:54:45 +00:00
|
|
|
|
if (e.KeyCode == Keys.Enter & fileLockedOkButton.Enabled)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
FileLockedOkButton_Click(sender, e);
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 11:54:45 +00:00
|
|
|
|
private void FileLockedCloseButton_MouseEnter(object sender, EventArgs e)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedCloseButton.ForeColor = Color.Silver;
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 11:54:45 +00:00
|
|
|
|
private void FileLockedCloseButton_MouseLeave(object sender, EventArgs e)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
fileLockedCloseButton.ForeColor = Color.DimGray;
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Tray
|
|
|
|
|
|
private void TrayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
|
{
|
2019-10-25 21:11:24 +00:00
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
Show();
|
|
|
|
|
|
WindowState = FormWindowState.Normal;
|
|
|
|
|
|
}
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
2019-10-13 12:55:13 +00:00
|
|
|
|
private void ShowTrayMenu_Click(object sender, EventArgs e)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
|
|
|
|
|
Show();
|
|
|
|
|
|
WindowState = FormWindowState.Normal;
|
|
|
|
|
|
}
|
2019-10-13 12:55:13 +00:00
|
|
|
|
private void ExitTrayMenu_Click(object sender, EventArgs e)
|
2019-10-11 10:38:15 +00:00
|
|
|
|
{
|
2019-10-13 11:54:45 +00:00
|
|
|
|
Application.Exit();
|
2019-10-11 10:38:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-28 19:45:20 +00:00
|
|
|
|
#region Debug Menu
|
|
|
|
|
|
private void VariablesMainMenu_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-10-04 18:48:55 +00:00
|
|
|
|
#if DEBUG
|
|
|
|
|
|
string formattedTime = DateTime.Now.ToString("yyyy.MM.dd hh:mm:ss");
|
|
|
|
|
|
Debug.WriteLine("\nTime: " + formattedTime);
|
|
|
|
|
|
Debug.WriteLine("PublicVar.openFileName: " + PublicVar.openFileName);
|
|
|
|
|
|
Debug.WriteLine("filePath: " + filePath);
|
|
|
|
|
|
Debug.WriteLine("encryptionKey: " + PublicVar.encryptionKey.Get());
|
|
|
|
|
|
Debug.WriteLine("TypedPassword: " + TypedPassword.Value);
|
|
|
|
|
|
Debug.WriteLine("keyChanged: " + PublicVar.keyChanged);
|
|
|
|
|
|
Debug.WriteLine("okPressed: " + PublicVar.okPressed);
|
|
|
|
|
|
Debug.WriteLine("RichTextBox.Modified: " + richTextBox.Modified);
|
|
|
|
|
|
Debug.WriteLine("EditorMenuStrip: " + contextMenu.Enabled);
|
|
|
|
|
|
#endif
|
2019-08-23 18:41:21 +00:00
|
|
|
|
}
|
2019-09-28 19:45:20 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-17 11:16:17 +00:00
|
|
|
|
}
|
2019-08-21 11:15:16 +00:00
|
|
|
|
}
|