2019-11-28 20:28:23 +00:00
using Crypto_Notepad.Properties ;
2021-03-28 17:46:45 +00:00
using Microsoft.Win32 ;
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 ;
2021-03-28 17:46:45 +00:00
FormWindowState currentWindowState ;
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 ;
2020-08-08 09:28:09 +00:00
const int SC_MAXIMIZE = 0xF030 ;
2019-12-28 22:26:58 +00:00
const int SC_RESTORE = 0xF120 ;
2019-10-28 18:33:14 +00:00
try
2019-10-15 17:13:07 +00:00
{
2019-12-28 22:26:58 +00:00
if ( m . Msg = = WM_SYSCOMMAND & m . WParam . ToInt32 ( ) = = SC_MINIMIZE )
2019-10-28 18:33:14 +00:00
{
richTextBox . Visible = false ;
}
2020-08-08 09:28:09 +00:00
if ( m . Msg = = WM_SYSCOMMAND & m . WParam . ToInt32 ( ) = = SC_RESTORE | m . WParam . ToInt32 ( ) = = SC_MAXIMIZE & ! fileLockedPanel . Visible )
2019-12-28 22:26:58 +00:00
{
2021-04-07 21:02:40 +00:00
if ( ! fileLockedPanel . Visible )
{
richTextBox . Visible = true ;
}
2019-12-28 22:26:58 +00:00
}
2021-03-28 17:46:45 +00:00
switch ( m . Msg )
{
case WM_SYSCOMMAND :
int command = m . WParam . ToInt32 ( ) & 0xfff0 ;
if ( command = = SC_MINIMIZE )
{
currentWindowState = WindowState ;
}
break ;
}
2019-10-28 18:33:14 +00:00
}
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-11-06 09:04:35 +00:00
private async Task DecryptAES ( )
2018-12-17 11:16:17 +00:00
{
2019-11-28 20:28:23 +00:00
EnterPasswordForm enterPasswordForm = new EnterPasswordForm ( ) ;
enterPasswordForm . Owner = this ;
enterPasswordForm . 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 ) ;
2020-08-23 21:07:27 +00:00
openFileDialog . FileName = filePath ;
2019-11-06 09:04:35 +00:00
mainMenu . Enabled = true ;
toolbarPanel . Enabled = true ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = true ;
2019-11-06 09:04:35 +00:00
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 ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = false ;
2019-11-06 09:04:35 +00:00
richTextBox . ReadOnly = true ;
string openedFileText = await reader . ReadToEndAsync ( ) ;
2019-11-27 09:56:53 +00:00
if ( string . IsNullOrEmpty ( settings . TheSalt ) )
{
richTextBox . Text = await AES . Decrypt ( openedFileText , TypedPassword . Value , null , settings . HashAlgorithm ,
Convert . ToInt32 ( settings . PasswordIterations ) , Convert . ToInt32 ( settings . KeySize ) ) ;
}
else
{
string currentRichTextBoxText = richTextBox . Text ;
richTextBox . Text = await AES . Decrypt ( openedFileText , TypedPassword . Value , settings . TheSalt , settings . HashAlgorithm ,
Convert . ToInt32 ( settings . PasswordIterations ) , Convert . ToInt32 ( settings . KeySize ) ) ;
if ( PublicVar . metadataCorrupt )
{
PublicVar . openFileName = Path . GetFileName ( filePath ) ;
PublicVar . metadataCorrupt = false ;
mainMenu . Enabled = true ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = true ;
2019-11-27 09:56:53 +00:00
toolbarPanel . Enabled = true ;
richTextBox . ReadOnly = false ;
UseWaitCursor = false ;
richTextBox . ResumeDrawing ( ) ;
richTextBox . Text = currentRichTextBoxText ;
richTextBox . Modified = false ;
return ;
}
}
2019-11-06 09:04:35 +00:00
}
2019-11-09 19:36:51 +00:00
Text = Path . GetFileName ( openFileDialog . FileName ) + " – " + PublicVar . appName ;
2019-09-28 19:57:03 +00:00
filePath = openFileDialog . FileName ;
PublicVar . openFileName = Path . GetFileName ( openFileDialog . FileName ) ;
2019-11-27 09:59:42 +00:00
PublicVar . password . Set ( TypedPassword . Value ) ;
2018-12-17 11:16:17 +00:00
TypedPassword . Value = null ;
2019-10-25 21:11:24 +00:00
StatusPanelFileInfo ( ) ;
2019-11-06 09:04:35 +00:00
mainMenu . Enabled = true ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = true ;
2019-11-06 09:04:35 +00:00
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 ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = true ;
2019-11-06 09:04:35 +00:00
toolbarPanel . Enabled = true ;
richTextBox . ReadOnly = false ;
UseWaitCursor = false ;
richTextBox . ResumeDrawing ( ) ;
if ( ! Visible )
{
Application . Exit ( ) ;
}
}
2018-12-17 11:16:17 +00:00
}
}
}
}
2020-08-23 21:07:27 +00:00
private async void TryToDecryptMessage ( string openedFilePath )
2018-12-17 11:16:17 +00:00
{
2020-08-23 21:07:27 +00:00
if ( Visible )
{
PublicVar . messageBoxCenterParent = true ;
}
PublicVar . password . Set ( null ) ;
if ( Path . GetExtension ( openedFilePath ) ! = ".cnp" )
2018-12-17 11:16:17 +00:00
{
2020-08-23 21:07:27 +00:00
if ( settings . openTxtUnencrypted )
2019-11-07 18:07:52 +00:00
{
2020-08-23 21:07:27 +00:00
richTextBox . Text = File . ReadAllText ( openedFilePath ) ;
Text = Path . GetFileName ( openedFilePath ) + " – " + PublicVar . appName ;
filePath = openedFilePath ;
2019-11-07 18:07:52 +00:00
StatusPanelFileInfo ( ) ;
}
2020-08-23 21:07:27 +00:00
else
{
using ( new CenterWinDialog ( this ) )
{
DialogResult res = MessageBox . Show ( this , "Try to decrypt \"" + PublicVar . openFileName + "\" file?" , PublicVar . appName ,
MessageBoxButtons . YesNo , MessageBoxIcon . Information ) ;
if ( res = = DialogResult . No )
{
richTextBox . Text = File . ReadAllText ( openedFilePath ) ;
Text = Path . GetFileName ( openedFilePath ) + " – " + PublicVar . appName ;
filePath = openedFilePath ;
StatusPanelFileInfo ( ) ;
}
else
{
await DecryptAES ( ) ;
}
}
}
}
else
{
await DecryptAES ( ) ;
2018-12-17 11:16:17 +00:00
}
}
2020-08-23 21:07:27 +00:00
private void OpenAsotiations ( )
{
PublicVar . openFileName = Path . GetFileName ( args [ 1 ] ) ;
openFileDialog . FileName = Path . GetFullPath ( args [ 1 ] ) ;
TryToDecryptMessage ( args [ 1 ] ) ;
}
private void SendTo ( )
2018-12-17 11:16:17 +00:00
{
2019-11-05 20:30:49 +00:00
PublicVar . openFileName = Path . GetFileName ( argsPath ) ;
2020-08-23 21:07:27 +00:00
openFileDialog . FileName = Path . GetFullPath ( argsPath ) ;
TryToDecryptMessage ( argsPath ) ;
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
{
2021-03-28 17:46:45 +00:00
DialogResult res = MessageBox . Show ( this , "This action will delete the source file and replace it with encrypted version. File must be in UTF-8 Encoding." , PublicVar . appName ,
2019-11-06 09:04:35 +00:00
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-28 20:28:23 +00:00
EnterPasswordForm enterPasswordForm = new EnterPasswordForm
2018-12-17 11:16:17 +00:00
{
2019-11-05 20:30:49 +00:00
Owner = this
} ;
2019-11-28 20:28:23 +00:00
enterPasswordForm . ShowDialog ( ) ;
2019-11-05 20:30:49 +00:00
File . Delete ( args [ 1 ] ) ;
2019-11-06 09:04:35 +00:00
string unencryptedText = richTextBox . Text ;
2021-03-28 17:46:45 +00:00
string encryptedText = await AES . Encrypt ( richTextBox . Text , TypedPassword . Value , null , settings . HashAlgorithm , Convert . ToInt32 ( settings . PasswordIterations ) ,
2019-11-06 09:04:35 +00:00
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-27 09:59:42 +00:00
PublicVar . password . Set ( TypedPassword . Value ) ;
2019-11-05 20:30:49 +00:00
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
}
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-11-27 09:59:42 +00:00
if ( ! PublicVar . passwordChanged )
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
}
}
2019-11-22 15:39:10 +00:00
private async Task 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
{
2019-11-22 15:39:10 +00:00
PublicVar . messageBoxCenterParent = true ;
2018-12-25 15:29:29 +00:00
WebClient client = new WebClient ( ) ;
2019-11-22 15:39:10 +00:00
Uri updateUrl = new Uri ( "https://raw.githubusercontent.com/Crypto-Notepad/Crypto-Notepad/master/version.txt" , UriKind . Absolute ) ;
Stream stream = await client . OpenReadTaskAsync ( updateUrl ) ;
2018-12-25 15:29:29 +00:00
StreamReader reader = new StreamReader ( stream ) ;
2019-11-22 15:39:10 +00:00
string content = await reader . ReadToEndAsync ( ) ;
2018-12-25 15:29:29 +00:00
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-11-09 18:19:19 +00:00
PublicVar . messageBoxCenterParent = true ;
2019-10-04 18:48:55 +00:00
if ( statusPanel . Visible )
{
StatusPanelMessage ( "update-needed" ) ;
2019-11-09 18:20:59 +00:00
return ;
2019-10-04 18:48:55 +00:00
}
else
{
using ( new CenterWinDialog ( this ) )
2019-09-28 19:37:04 +00:00
{
2019-11-24 07:34:52 +00:00
DialogResult res = MessageBox . Show ( this , "New version is available. Install it now?" , PublicVar . appName ,
2019-11-06 09:04:35 +00:00
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 + "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 )
{
2019-11-24 07:34:52 +00:00
using ( new CenterWinDialog ( this ) )
2019-09-28 19:14:24 +00:00
{
2019-11-24 07:34:52 +00:00
if ( statusPanel . Visible )
2019-09-28 19:14:24 +00:00
{
2019-11-24 07:34:52 +00:00
StatusPanelMessage ( "update-failed" ) ;
}
else
{
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-11-24 07:34:52 +00:00
}
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 ;
2020-01-17 21:43:15 +00:00
case "clipboard-clear" :
if ( statusPanelLabel . Text ! = "Clipboard cleared" )
{
statusPanelLabel . Text = "Clipboard cleared" ;
await Task . Delay ( 3000 ) ;
statusPanelLabel . Text = ready ;
}
break ;
2019-09-28 19:37:04 +00:00
}
}
2019-11-07 18:08:39 +00:00
protected internal void StatusPanelFileInfo ( )
2019-10-25 21:11:24 +00:00
{
2019-11-07 18:08:39 +00:00
if ( statusPanel . Visible )
{
if ( statusPanelModifiedLabel . Visible )
{
if ( ! string . IsNullOrEmpty ( filePath ) )
{
DateTime creation = File . GetLastWriteTime ( filePath ) ;
statusPanelModifiedLabel . Text = "Modified: " + creation . ToString ( "dd.MM.yyyy" ) ;
statusPanelModifiedLabel . ToolTipText = creation . ToString ( ) ;
}
}
if ( statusPanelSizeLabel . Visible )
{
if ( ! string . IsNullOrEmpty ( filePath ) )
{
long length = new FileInfo ( filePath ) . Length ;
2019-11-24 07:30:31 +00:00
statusPanelSizeLabel . Text = "Size: " + Methods . SizeSuffix ( length ) . ToString ( ) ;
2019-11-07 18:08:39 +00:00
StatusPanelTextInfo ( ) ;
}
}
2020-01-13 10:40:14 +00:00
statusPanelReadonlyLabel . Text = "Readonly: " + readOnlyMainMenu . Checked . ToString ( ) ;
2020-01-13 10:46:31 +00:00
statusPanelWordwrapLabel . Text = "Word Wrap: " + wordWrapMainMenu . Checked . ToString ( ) ;
2019-11-07 18:08:39 +00:00
}
2019-10-25 21:11:24 +00:00
}
2019-11-07 19:13:04 +00:00
protected internal void StatusPanelTextInfo ( )
2019-09-28 19:37:04 +00:00
{
2019-10-21 11:26:40 +00:00
if ( statusPanel . Visible )
2019-09-28 19:37:04 +00:00
{
2019-11-07 18:15:41 +00:00
if ( statusPanelLinesLabel . Visible )
{
int linesCount = richTextBox . Lines . Length ;
if ( linesCount = = 0 )
{
linesCount = 1 ;
}
statusPanelLinesLabel . Text = "Lines: " + linesCount ;
}
if ( statusPanelLengthLabel . Visible )
2019-10-21 11:26:40 +00:00
{
2019-11-07 18:15:41 +00:00
statusPanelLengthLabel . Text = "Length: " + richTextBox . TextLength ;
2019-10-21 11:26:40 +00:00
}
2019-09-28 19:37:04 +00:00
}
}
2019-11-07 18:15:41 +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
2020-01-13 10:44:46 +00:00
private void LockTimer_Tick ( object sender , EventArgs e )
{
LockMainMenu_Click ( this , new EventArgs ( ) ) ;
lockTimer . Enabled = false ;
}
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 ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = false ;
2019-11-06 09:04:35 +00:00
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 ,
2019-11-07 18:14:24 +00:00
Convert . ToInt32 ( settings . PasswordIterations ) , Convert . ToInt32 ( settings . KeySize ) ) ;
2019-11-06 09:04:35 +00:00
}
2019-11-07 18:05:30 +00:00
richTextBox . Modified = false ;
2019-10-13 11:59:01 +00:00
fileLockedPanel . Visible = false ;
2019-09-28 19:57:03 +00:00
richTextBox . SelectionStart = caretPos ;
2019-11-27 09:59:42 +00:00
PublicVar . password . Set ( TypedPassword . Value ) ;
2018-12-25 15:29:29 +00:00
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 ;
2021-04-07 11:28:22 +00:00
settingsToolStripMenuItem . Enabled = true ;
2019-11-06 09:04:35 +00:00
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 . windowLocation . ToString ( ) ! = "{X=0,Y=0}" )
{
Location = settings . windowLocation ;
}
2021-03-28 17:46:45 +00:00
if ( ! Methods . IsOnScreen ( this ) )
{
Location = new Point ( 1 , 1 ) ;
}
2019-10-04 18:44:30 +00:00
Size = settings . windowSize ;
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 ;
2021-03-28 17:46:45 +00:00
if ( settings . closeToTray | settings . minimizeToTray | settings . trayMenu )
2019-10-11 10:37:05 +00:00
{
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 ;
2019-11-07 18:23:05 +00:00
statusPanelLengthLabel . Visible = settings . statusPanelLength ;
statusPanelLinesLabel . Visible = settings . statusPanelLines ;
statusPanelModifiedLabel . Visible = settings . statusPanelModified ;
statusPanelSizeLabel . Visible = settings . statusPanelSize ;
2020-01-13 10:40:14 +00:00
statusPanelReadonlyLabel . Visible = settings . statusPanelReadonly ;
2020-01-13 10:46:31 +00:00
statusPanelWordwrapLabel . Visible = settings . statusPanelWordWrap ;
2021-04-07 11:19:36 +00:00
statusPanelPasteboardLabel . Visible = settings . statusPanelPasteboard ;
2019-10-04 18:44:30 +00:00
richTextBox . WordWrap = settings . editorWrap ;
2021-03-28 17:46:45 +00:00
richTextBox . ForeColor = settings . editorForeColor ;
2019-10-04 18:44:30 +00:00
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 ) ;
2021-03-28 17:46:45 +00:00
RegistryKey explorerAssociate = Registry . CurrentUser . OpenSubKey ( @"Software\Classes\.cnp\" , true ) ;
if ( settings . explorerAssociate & & explorerAssociate = = null )
{
Methods . AssociateExtension ( Assembly . GetEntryAssembly ( ) . Location , "cnp" ) ;
}
RegistryKey explorerIntegrate = Registry . CurrentUser . OpenSubKey ( @"Software\Classes\*\shell\Crypto Notepad\" , true ) ;
if ( settings . explorerIntegrate & & explorerIntegrate = = null )
{
Methods . MenuIntegrate ( "enable" ) ;
}
string shortcutPath = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) + @"\Microsoft\Windows\SendTo\Crypto Notepad.lnk" ;
if ( settings . explorerSendTo & & ! File . Exists ( shortcutPath ) )
{
Methods . SendToShortcut ( ) ;
}
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 ;
2020-08-23 21:07:27 +00:00
tryToDecryptMainMenu . Image = Resources . lock_pencil ;
2019-10-04 18:44:30 +00:00
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 ;
2020-01-17 21:43:15 +00:00
clearClipboardMainMenu . Image = Resources . clipboard_minus ;
2019-10-04 18:44:30 +00:00
wordWrapMainMenu . Image = Resources . wrap_option ;
2020-01-17 21:43:15 +00:00
readOnlyMainMenu . Image = Resources . document_pencil ;
2022-05-22 08:07:48 +00:00
insertDateTimeMainMenu . Image = Resources . clock_plus ;
2019-10-04 18:44:30 +00:00
clearMainMenu . Image = Resources . document ;
2019-11-28 20:36:43 +00:00
changePasswordMainMenu . Image = Resources . key ;
2019-10-04 18:44:30 +00:00
lockMainMenu . Image = Resources . lock_warning ;
settingsMainMenu . Image = Resources . gear ;
2021-04-07 11:19:36 +00:00
pasteBoardMainMenu . Image = Resources . clipboard_text ;
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 ;
2020-01-17 21:43:15 +00:00
saveCloseFileMainMenu . Image = Resources . disk_minus ;
2020-01-19 12:53:08 +00:00
passwordGeneratorMainMenu . Image = Resources . key_plus ;
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 ;
}
}
2021-03-28 17:46:45 +00:00
}
2020-01-19 12:50:46 +00:00
}
protected internal void ShortcutKeys ( bool shortcutKeys )
{
if ( shortcutKeys )
{
newMainMenu . ShortcutKeys = Keys . Control | Keys . N ;
openMainMenu . ShortcutKeys = Keys . Control | Keys . O ;
saveMainMenu . ShortcutKeys = Keys . Control | Keys . S ;
saveAsMainMenu . ShortcutKeys = Keys . Control | Keys . Shift | Keys . S ;
saveCloseFileMainMenu . ShortcutKeys = Keys . Alt | Keys . Shift | Keys . S ;
openFileLocationMainMenu . ShortcutKeys = Keys . Control | Keys . Shift | Keys . O ;
deleteFileMainMenu . ShortcutKeys = Keys . Control | Keys . Shift | Keys . D ;
2020-08-23 21:07:27 +00:00
tryToDecryptMainMenu . ShortcutKeys = Keys . Control | Keys . Shift | Keys . E ;
2020-01-19 12:50:46 +00:00
exitMainMenu . ShortcutKeys = Keys . Control | Keys . Q ;
undoMainMenu . ShortcutKeys = Keys . Control | Keys . Z ;
redoMainMenu . ShortcutKeys = Keys . Control | Keys . Y ;
cutMainMenu . ShortcutKeys = Keys . Control | Keys . X ;
copyMainMenu . ShortcutKeys = Keys . Control | Keys . C ;
pasteMainMenu . ShortcutKeys = Keys . Control | Keys . V ;
deleteMainMenu . ShortcutKeys = Keys . Delete ;
findMainMenu . ShortcutKeys = Keys . Control | Keys . F ;
selectAllMainMenu . ShortcutKeys = Keys . Control | Keys . A ;
2020-01-19 14:38:08 +00:00
clearClipboardMainMenu . ShortcutKeys = Keys . Control | Keys . D ;
2020-01-19 12:50:46 +00:00
wordWrapMainMenu . ShortcutKeys = Keys . Control | Keys . W ;
readOnlyMainMenu . ShortcutKeys = Keys . Control | Keys . R ;
clearMainMenu . ShortcutKeys = Keys . Control | Keys . Delete ;
alwaysOnTopMainMenu . ShortcutKeys = Keys . Control | Keys . T ;
passwordGeneratorMainMenu . ShortcutKeys = Keys . Control | Keys . P ;
changePasswordMainMenu . ShortcutKeys = Keys . Control | Keys . Shift | Keys . P ;
lockMainMenu . ShortcutKeys = Keys . Control | Keys . L ;
settingsMainMenu . ShortcutKeys = Keys . Control | Keys . Shift | Keys . T ;
documentationMainMenu . ShortcutKeys = Keys . Control | Keys . F1 ;
checkForUpdatesMainMenu . ShortcutKeys = Keys . Control | Keys . U ;
aboutMainMenu . ShortcutKeys = Keys . Control | Keys . Shift | Keys . A ;
}
else
{
newMainMenu . ShortcutKeys = Keys . None ;
openMainMenu . ShortcutKeys = Keys . None ;
saveMainMenu . ShortcutKeys = Keys . None ;
saveAsMainMenu . ShortcutKeys = Keys . None ;
saveCloseFileMainMenu . ShortcutKeys = Keys . None ;
openFileLocationMainMenu . ShortcutKeys = Keys . None ;
deleteFileMainMenu . ShortcutKeys = Keys . None ;
2020-08-23 21:07:27 +00:00
tryToDecryptMainMenu . ShortcutKeys = Keys . None ;
2020-01-19 12:50:46 +00:00
exitMainMenu . ShortcutKeys = Keys . None ;
undoMainMenu . ShortcutKeys = Keys . None ;
redoMainMenu . ShortcutKeys = Keys . None ;
cutMainMenu . ShortcutKeys = Keys . None ;
copyMainMenu . ShortcutKeys = Keys . None ;
pasteMainMenu . ShortcutKeys = Keys . None ;
deleteMainMenu . ShortcutKeys = Keys . None ;
findMainMenu . ShortcutKeys = Keys . None ;
selectAllMainMenu . ShortcutKeys = Keys . None ;
clearClipboardMainMenu . ShortcutKeys = Keys . None ;
wordWrapMainMenu . ShortcutKeys = Keys . None ;
readOnlyMainMenu . ShortcutKeys = Keys . None ;
clearMainMenu . ShortcutKeys = Keys . None ;
alwaysOnTopMainMenu . ShortcutKeys = Keys . None ;
passwordGeneratorMainMenu . ShortcutKeys = Keys . None ;
changePasswordMainMenu . ShortcutKeys = Keys . None ;
lockMainMenu . ShortcutKeys = Keys . None ;
settingsMainMenu . ShortcutKeys = Keys . None ;
documentationMainMenu . ShortcutKeys = Keys . None ;
checkForUpdatesMainMenu . ShortcutKeys = Keys . None ;
aboutMainMenu . ShortcutKeys = Keys . None ;
2018-12-29 16:26:51 +00:00
}
}
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 ;
2019-11-28 20:36:43 +00:00
changePasswordToolbarButton . Image = Resources . old_page_white_key ;
2019-10-02 16:24:52 +00:00
lockToolbarButton . Image = Resources . old_lock ;
2022-05-22 08:07:48 +00:00
insertDateTimeMainMenu . Image = Resources . old_clock_add ;
2020-08-23 21:07:27 +00:00
tryToDecryptToolbarButton . Image = Resources . old_lock_edit ;
2019-10-02 16:24:52 +00:00
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 ;
2019-11-28 20:36:43 +00:00
changePasswordToolbarButton . Image = Resources . key ;
2019-10-02 16:24:52 +00:00
lockToolbarButton . Image = Resources . lock_warning ;
2022-05-22 08:07:48 +00:00
insertDateTimeMainMenu . Image = Resources . clock_plus ;
2020-08-23 21:07:27 +00:00
tryToDecryptToolbarButton . Image = Resources . lock_pencil ;
2019-10-02 16:24:52 +00:00
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
}
}
2020-01-17 21:43:15 +00:00
public void ClipboardProgressbar ( )
{
if ( richTextBox . SelectionLength ! = 0 )
{
if ( ! string . IsNullOrEmpty ( settings . clipboardClearTime ) )
{
statusPanelClipboardProgressBar . Value = 100 ;
clipboardTimer . Interval = int . Parse ( settings . clipboardClearTime ) ;
clipboardTimer . Start ( ) ;
}
}
}
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 ( "*" ) )
{
2019-11-07 18:05:30 +00:00
Text = Text . Replace ( "*" , string . Empty ) ;
2019-11-05 20:54:16 +00:00
}
}
2022-05-22 08:07:48 +00:00
//if (richTextBox.Modified == true)
//{
// if (!Text.Contains("*"))
// {
// Text = Text.Insert(0, "*");
// if (string.IsNullOrEmpty(PublicVar.openFileName) & richTextBox.TextLength > 0)
// {
// Text = "Unnamed.cnp" + " – " + PublicVar.appName;
// Text = Text.Insert(0, "*");
// }
// }
//}
2019-11-05 20:54:16 +00:00
}
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
{
2021-03-28 17:46:45 +00:00
if ( WindowState = = FormWindowState . Minimized & settings . minimizeToTray )
2019-10-11 10:37:05 +00:00
{
2021-03-28 17:46:45 +00:00
Hide ( ) ;
2019-10-11 10:37:05 +00:00
}
2019-11-27 09:59:42 +00:00
if ( WindowState = = FormWindowState . Minimized & settings . autoLock & ! string . IsNullOrEmpty ( PublicVar . password . Get ( ) ) )
2018-12-17 11:16:17 +00:00
{
2021-04-07 21:39:45 +00:00
settingsToolStripMenuItem . Enabled = false ;
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 ( ) ;
2019-11-27 09:59:42 +00:00
if ( PublicVar . passwordChanged )
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
}
2020-01-13 10:44:46 +00:00
lockTimer . Enabled = false ;
}
private void MainForm_Deactivate ( object sender , EventArgs e )
{
if ( ! string . IsNullOrEmpty ( settings . lockTimeout ) & settings . lockTimeout ! = "0" & ! string . IsNullOrEmpty ( PublicVar . password . Get ( ) ) )
{
lockTimer . Interval = int . Parse ( settings . lockTimeout ) * 60000 ;
lockTimer . Enabled = 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-11-27 09:59:42 +00:00
if ( settings . autoLock & ! string . IsNullOrEmpty ( PublicVar . password . Get ( ) ) )
2019-10-13 11:59:01 +00:00
{
2021-04-07 21:39:45 +00:00
settingsToolStripMenuItem . Enabled = false ;
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 ;
2019-11-27 09:59:42 +00:00
if ( ! PublicVar . passwordChanged )
2019-10-13 11:59:01 +00:00
{
messageBoxText = "Save file: " + "\"" + PublicVar . openFileName + "\"" + " ? " ;
}
else
{
2019-11-27 09:59:42 +00:00
messageBoxText = "Save file: " + "\"" + PublicVar . openFileName + "\"" + " with a new password? " ;
2019-10-13 11:59:01 +00:00
}
2019-11-05 19:23:13 +00:00
if ( Visible )
{
PublicVar . messageBoxCenterParent = true ;
}
2019-11-07 18:10:55 +00:00
else
{
PublicVar . messageBoxCenterParent = false ;
}
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-11 17:42:18 +00:00
if ( string . IsNullOrEmpty ( filePath ) )
{
saveFileDialog . FileName = "Unnamed.cnp" ;
if ( saveFileDialog . ShowDialog ( ) ! = DialogResult . OK )
{
e . Cancel = true ;
return ;
}
2019-11-28 20:28:23 +00:00
EnterPasswordForm enterKeyForm = new EnterPasswordForm
2019-11-11 17:42:18 +00:00
{
Owner = this
} ;
enterKeyForm . ShowDialog ( ) ;
if ( ! PublicVar . okPressed )
{
PublicVar . openFileName = Path . GetFileName ( filePath ) ;
e . Cancel = true ;
return ;
}
2019-11-27 09:59:42 +00:00
PublicVar . password . Set ( TypedPassword . Value ) ;
2019-11-11 17:42:18 +00:00
filePath = saveFileDialog . FileName ;
}
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 ) )
{
2019-11-07 18:11:25 +00:00
string encryptedText = richTextBox . Text ;
2021-04-07 11:19:36 +00:00
Task . Run ( async ( ) = >
{
encryptedText = await AES . Encrypt ( encryptedText , PublicVar . password . Get ( ) , null , settings . HashAlgorithm ,
Convert . ToInt32 ( settings . PasswordIterations ) , Convert . ToInt32 ( settings . KeySize ) ) ;
} ) . Wait ( ) ;
2019-11-07 18:11:25 +00:00
writer . Write ( encryptedText ) ;
2019-11-06 09:04:35 +00:00
writer . Close ( ) ;
}
2020-01-19 12:52:38 +00:00
if ( settings . clearClipboardAtClose )
{
Clipboard . Clear ( ) ;
}
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
}
2020-01-19 12:52:38 +00:00
private void MainForm_FormClosed ( object sender , FormClosedEventArgs e )
{
if ( settings . clearClipboardAtClose )
{
Clipboard . Clear ( ) ;
}
}
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 ) )
{
2019-11-20 13:48:49 +00:00
DialogResult res = MessageBox . Show ( this , "Enable automatic update check at startup?\nThis action can be undone in settings." , PublicVar . appName , MessageBoxButtons . YesNo , MessageBoxIcon . Information ) ;
2019-10-31 19:50:51 +00:00
if ( res = = DialogResult . Yes )
{
settings . autoCheckUpdate = true ;
}
}
}
2021-03-28 17:46:45 +00:00
WindowState = settings . windowState ;
2019-09-28 19:57:03 +00:00
}
2018-12-29 16:26:51 +00:00
2019-11-22 15:39:10 +00:00
private async 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 ( ) ;
2019-11-24 07:30:31 +00:00
Methods . DeleteUpdateFiles ( ) ;
2019-10-04 18:44:30 +00:00
MenuIcons ( settings . menuIcons ) ;
2019-10-18 10:34:14 +00:00
ToolbarIcons ( settings . oldToolbarIcons ) ;
2020-01-19 12:50:46 +00:00
ShortcutKeys ( settings . shortcutKeys ) ;
2020-01-13 10:40:14 +00:00
statusPanelReadonlyLabel . Text = "Readonly: " + readOnlyMainMenu . Checked . ToString ( ) ;
2020-01-13 10:46:31 +00:00
statusPanelWordwrapLabel . Text = "Word Wrap: " + wordWrapMainMenu . Checked . ToString ( ) ;
2021-04-07 11:19:36 +00:00
statusPanelPasteboardLabel . Text = "Paste Board: " + pasteBoardMainMenu . Checked . ToString ( ) ;
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
}
2020-08-23 21:07:27 +00:00
if ( args . Contains ( "/o" ) ) /*decrypt & open*/
2018-12-25 15:29:29 +00:00
{
2020-08-23 21:07:27 +00:00
PublicVar . openFileName = Path . GetFileName ( args [ 1 ] ) ;
openFileDialog . FileName = Path . GetFullPath ( args [ 1 ] ) ;
await DecryptAES ( ) ;
2018-12-25 15:29:29 +00:00
}
if ( args . Contains ( "/er" ) ) /*encrypt and replace*/
{
ContextMenuEncryptReplace ( ) ;
}
2019-11-22 15:39:10 +00:00
if ( settings . autoCheckUpdate )
{
await CheckForUpdates ( false ) ;
}
2020-01-19 12:53:08 +00:00
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 ;
}
2020-01-17 21:43:15 +00:00
if ( e . Control & & e . KeyCode = = Keys . C | | e . Control & & e . KeyCode = = Keys . X )
{
ClipboardProgressbar ( ) ;
}
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
}
2020-08-23 21:07:27 +00:00
private 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
{
2020-08-23 21:07:27 +00:00
TryToDecryptMessage ( openFileDialog . FileName ) ;
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 )
{
2022-05-22 08:07:48 +00:00
statusPanelTimer . Start ( ) ;
2019-11-05 20:54:16 +00:00
if ( richTextBox . Modified )
{
if ( ! Text . Contains ( "*" ) )
{
2019-11-07 18:13:57 +00:00
Text = Text . Insert ( 0 , "*" ) ;
2019-11-11 19:00:29 +00:00
if ( string . IsNullOrEmpty ( PublicVar . openFileName ) & richTextBox . TextLength > 0 )
{
Text = "Unnamed.cnp" + " – " + PublicVar . appName ;
Text = Text . Insert ( 0 , "*" ) ;
}
2019-11-05 20:54:16 +00:00
}
}
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 ) )
{
2021-03-28 17:46:45 +00:00
DialogResult res = MessageBox . Show ( this , "New version is available. Install it now?" , PublicVar . appName ,
2019-11-06 09:04:35 +00:00
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 + "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 ( ) ;
}
}
}
}
2020-01-17 21:43:15 +00:00
private void ClipboardTimer_Tick ( object sender , EventArgs e )
{
if ( settings . statusPanelClipboard )
{
statusPanelClipboardProgressBar . Visible = true ;
}
statusPanelClipboardProgressBar . Value - - ;
if ( statusPanelClipboardProgressBar . Value = = 0 )
{
Clipboard . Clear ( ) ;
if ( settings . statusPanelClipboard )
{
statusPanelClipboardProgressBar . Visible = false ;
}
clipboardTimer . Stop ( ) ;
}
}
2019-09-28 19:37:04 +00:00
#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-11-28 20:28:23 +00:00
EnterPasswordForm enterKeyForm = new EnterPasswordForm
2019-09-28 19:57:03 +00:00
{
Owner = this
} ;
enterKeyForm . ShowDialog ( ) ;
2018-12-17 11:16:17 +00:00
2018-12-25 15:29:29 +00:00
if ( ! PublicVar . okPressed )
{
2019-11-19 14:08:12 +00:00
PublicVar . openFileName = "" ;
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-11-11 17:24:19 +00:00
saveFileDialog . FileName = "Unnamed.cnp" ;
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-11-27 09:59:42 +00:00
PublicVar . password . Set ( TypedPassword . Value ) ;
2019-09-28 19:57:03 +00:00
StreamWriter sw = new StreamWriter ( saveFileDialog . FileName ) ;
2019-11-09 19:36:51 +00:00
Text = Path . GetFileName ( saveFileDialog . FileName ) + " – " + PublicVar . appName ;
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
}
2020-08-23 21:07:27 +00:00
private 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 ) ;
2020-08-23 21:07:27 +00:00
TryToDecryptMessage ( openFileDialog . FileName ) ;
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-11-27 09:59:42 +00:00
if ( string . IsNullOrEmpty ( PublicVar . password . 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 ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = false ;
2019-11-06 09:04:35 +00:00
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
{
2021-03-28 17:46:45 +00:00
writer . Write ( await AES . Encrypt ( richTextBox . Text , PublicVar . password . Get ( ) , null , settings . HashAlgorithm ,
2019-11-06 09:04:35 +00:00
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 ;
2019-11-27 09:59:42 +00:00
PublicVar . passwordChanged = 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 ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = true ;
2019-11-06 09:04:35 +00:00
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-11-11 17:25:39 +00:00
if ( saveFileDialog . ShowDialog ( ) ! = DialogResult . OK )
{
return ;
}
2019-11-11 19:01:07 +00:00
PublicVar . openFileName = Path . GetFileName ( saveFileDialog . FileName ) ;
2019-11-28 20:28:23 +00:00
EnterPasswordForm enterKeyForm = new EnterPasswordForm
2019-09-28 19:57:03 +00:00
{
Owner = this
} ;
2019-11-27 09:59:42 +00:00
if ( string . IsNullOrEmpty ( PublicVar . password . 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-11-11 19:01:07 +00:00
if ( TypedPassword . Value = = null )
{
2019-11-27 09:59:42 +00:00
TypedPassword . Value = PublicVar . password . Get ( ) ;
2019-11-11 19:01:07 +00:00
}
2019-11-27 09:59:42 +00:00
PublicVar . password . Set ( TypedPassword . Value ) ;
2019-09-28 19:57:03 +00:00
filePath = saveFileDialog . FileName ;
2019-11-09 17:55:53 +00:00
mainMenu . Enabled = false ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = false ;
2019-11-09 17:55:53 +00:00
toolbarPanel . Enabled = false ;
richTextBox . ReadOnly = true ;
richTextBox . SuspendDrawing ( ) ;
UseWaitCursor = true ;
2019-08-30 10:05:29 +00:00
using ( StreamWriter writer = new StreamWriter ( filePath ) )
{
2019-11-27 09:59:42 +00:00
writer . Write ( await AES . Encrypt ( richTextBox . Text , PublicVar . password . Get ( ) , null , settings . HashAlgorithm ,
2019-11-09 17:55:53 +00:00
Convert . ToInt32 ( settings . PasswordIterations ) , Convert . ToInt32 ( settings . KeySize ) ) ) ;
2019-08-30 10:05:29 +00:00
writer . Close ( ) ;
}
2019-11-09 17:55:53 +00:00
richTextBox . ResumeDrawing ( ) ;
UseWaitCursor = false ;
mainMenu . Enabled = true ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = true ;
2019-11-09 17:55:53 +00:00
toolbarPanel . Enabled = true ;
richTextBox . ReadOnly = false ;
2019-09-28 19:57:03 +00:00
richTextBox . Modified = false ;
2019-11-09 19:36:11 +00:00
Text = Path . GetFileName ( filePath ) + " – " + PublicVar . appName ;
2018-12-25 15:29:29 +00:00
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
mainMenu . Enabled = false ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = false ;
2019-11-06 09:04:35 +00:00
toolbarPanel . Enabled = false ;
richTextBox . SuspendDrawing ( ) ;
UseWaitCursor = true ;
2019-11-05 20:00:38 +00:00
using ( StreamWriter writer = new StreamWriter ( filePath ) )
{
2019-11-27 09:59:42 +00:00
writer . Write ( await AES . Encrypt ( richTextBox . Text , PublicVar . password . Get ( ) , null , settings . HashAlgorithm ,
2019-11-06 09:04:35 +00:00
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 ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = true ;
2019-11-06 09:04:35 +00:00
toolbarPanel . Enabled = true ;
richTextBox . ReadOnly = false ;
2019-11-27 09:59:42 +00:00
PublicVar . password . Set ( null ) ;
2019-11-05 20:00:38 +00:00
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
{
2020-01-19 14:38:08 +00:00
if ( ! string . IsNullOrEmpty ( filePath ) )
{
Process . Start ( "explorer.exe" , @"/select, " + filePath ) ;
}
2018-12-25 15:29:29 +00:00
}
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
{
2019-11-19 14:05:29 +00:00
PublicVar . messageBoxCenterParent = true ;
2018-12-25 15:29:29 +00:00
using ( new CenterWinDialog ( this ) )
2018-12-17 11:16:17 +00:00
{
2021-03-28 17:46:45 +00:00
if ( MessageBox . Show ( this , "Delete file: " + "\"" + filePath + "\"" + " ?" , PublicVar . appName ,
2019-11-06 09:04:35 +00:00
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 ( ) ;
2019-11-27 09:59:42 +00:00
PublicVar . password . Set ( null ) ;
2019-09-28 19:57:03 +00:00
fileLocationToolbarButton . Enabled = false ;
deleteFileToolbarButton . Enabled = false ;
2019-11-28 20:36:43 +00:00
changePasswordToolbarButton . Enabled = false ;
2019-09-28 19:57:03 +00:00
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
}
}
}
}
2020-08-23 21:07:27 +00:00
private async void TryToDecryptMainMenu_Click ( object sender , EventArgs e )
{
if ( ! string . IsNullOrEmpty ( filePath ) )
{
await DecryptAES ( ) ;
}
}
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
}
/*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 )
2020-08-23 21:07:27 +00:00
{
}
private void FileMainMenu_DropDownOpening ( object sender , EventArgs e )
{
if ( ! string . IsNullOrEmpty ( filePath ) )
{
deleteFileMainMenu . Enabled = true ;
openFileLocationMainMenu . Enabled = true ;
}
else
{
deleteFileMainMenu . Enabled = false ;
openFileLocationMainMenu . Enabled = false ;
}
if ( ! string . IsNullOrEmpty ( PublicVar . password . Get ( ) ) & & ! string . IsNullOrEmpty ( filePath ) )
{
saveCloseFileMainMenu . Enabled = true ;
}
else
{
saveCloseFileMainMenu . Enabled = false ;
}
if ( string . IsNullOrEmpty ( PublicVar . password . Get ( ) ) & & richTextBox . TextLength > 0 & & ! string . IsNullOrEmpty ( filePath ) )
{
tryToDecryptMainMenu . Enabled = true ;
}
else
{
tryToDecryptMainMenu . Enabled = false ;
}
}
private void EditMainMenu_DropDownOpening ( object sender , EventArgs e )
2019-09-28 19:57:03 +00:00
{
if ( richTextBox . SelectionLength ! = 0 )
{
cutMainMenu . Enabled = true ;
copyMainMenu . Enabled = true ;
deleteMainMenu . Enabled = true ;
}
else
{
cutMainMenu . Enabled = false ;
copyMainMenu . Enabled = false ;
deleteMainMenu . Enabled = false ;
}
}
2020-08-23 21:07:27 +00:00
private void ToolsMainMenu_DropDownOpening ( object sender , EventArgs e )
{
if ( string . IsNullOrEmpty ( PublicVar . password . Get ( ) ) )
{
changePasswordMainMenu . Enabled = false ;
lockMainMenu . Enabled = false ;
}
else
{
changePasswordMainMenu . Enabled = true ;
lockMainMenu . Enabled = true ;
2021-04-07 11:19:36 +00:00
2020-08-23 21:07:27 +00:00
}
}
2019-09-28 19:57:03 +00:00
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 ( ) ;
2020-01-17 21:43:15 +00:00
ClipboardProgressbar ( ) ;
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 ( ) ;
2020-01-17 21:43:15 +00:00
ClipboardProgressbar ( ) ;
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
}
}
2020-01-17 20:23:02 +00:00
private void ClearClipboardMainMenu_Click ( object sender , EventArgs e )
{
2020-01-19 14:38:08 +00:00
if ( ! Clipboard . ContainsText ( ) )
{
return ;
}
2020-01-17 20:23:02 +00:00
Clipboard . Clear ( ) ;
2020-01-17 21:43:15 +00:00
if ( statusPanelClipboardProgressBar . Visible )
{
statusPanelClipboardProgressBar . Visible = false ;
clipboardTimer . Stop ( ) ;
}
StatusPanelMessage ( "clipboard-clear" ) ;
2020-01-17 20:23:02 +00:00
}
2020-01-13 10:40:14 +00:00
private void ReadOnlyMainMenu_Click ( object sender , EventArgs e )
{
richTextBox . ReadOnly = readOnlyMainMenu . Checked ;
statusPanelReadonlyLabel . Text = "Readonly: " + readOnlyMainMenu . Checked . ToString ( ) ;
}
2022-05-22 08:07:48 +00:00
private void InsertDateTimeMainMenu_Click ( object sender , EventArgs e )
{
DateTime now = DateTime . Now ;
2022-05-30 19:19:37 +00:00
richTextBox . SelectedText = now . ToString ( ) ;
2022-05-22 08:07:48 +00:00
richTextBox . Modified = true ;
if ( ! Text . Contains ( "*" ) )
{
Text = Text . Insert ( 0 , "*" ) ;
if ( string . IsNullOrEmpty ( PublicVar . openFileName ) & richTextBox . TextLength > 0 )
{
Text = "Unnamed.cnp" + " – " + PublicVar . appName ;
Text = Text . Insert ( 0 , "*" ) ;
}
}
}
2019-09-28 19:57:03 +00:00
private void WordWrapMainMenu_Click ( object sender , EventArgs e )
2018-12-25 15:29:29 +00:00
{
2020-01-13 10:46:31 +00:00
richTextBox . WordWrap = wordWrapMainMenu . Checked ;
2019-09-28 19:57:03 +00:00
settings . menuWrap = wordWrapMainMenu . Checked ;
settings . editorWrap = richTextBox . WordWrap ;
settings . Save ( ) ;
2020-01-13 10:40:14 +00:00
statusPanelWordwrapLabel . Text = "Word Wrap: " + wordWrapMainMenu . Checked . ToString ( ) ;
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
{
2020-01-13 10:40:14 +00:00
if ( ! readOnlyMainMenu . Checked )
{
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-11-11 17:19:29 +00:00
private void PasswordGeneratorMainMenu_Click ( object sender , EventArgs e )
{
PasswordGeneratorFrom passwordGeneratorFrom = new PasswordGeneratorFrom ( ) ;
passwordGeneratorFrom . ShowDialog ( this ) ;
}
2020-01-19 14:38:08 +00:00
private void ChangePasswordMainMenu_Click ( object sender , EventArgs e )
2018-12-17 11:16:17 +00:00
{
2020-01-19 14:38:08 +00:00
if ( ! string . IsNullOrEmpty ( PublicVar . password . Get ( ) ) )
2018-12-25 15:29:29 +00:00
{
2020-01-19 14:38:08 +00:00
ChangePasswordForm changePasswordForm = new ChangePasswordForm ( ) ;
changePasswordForm . ShowDialog ( this ) ;
2018-12-17 11:16:17 +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
{
2020-01-19 14:38:08 +00:00
if ( string . IsNullOrEmpty ( PublicVar . password . Get ( ) ) )
{
return ;
}
2019-11-06 09:04:35 +00:00
mainMenu . Enabled = false ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = false ;
2019-11-06 09:04:35 +00:00
toolbarPanel . Enabled = false ;
richTextBox . SuspendDrawing ( ) ;
UseWaitCursor = true ;
using ( StreamWriter writer = new StreamWriter ( filePath ) )
{
2019-11-27 09:59:42 +00:00
writer . Write ( await AES . Encrypt ( richTextBox . Text , PublicVar . password . Get ( ) , null , settings . HashAlgorithm ,
2019-11-06 09:04:35 +00:00
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*/
2021-04-07 11:19:36 +00:00
/*Paste Board*/
string clipboardLastText = "" ;
private void PasteBoardTimer_Tick ( object sender , EventArgs e )
{
string clipboardText = Clipboard . GetText ( ) ;
if ( ! string . IsNullOrEmpty ( clipboardText ) & & clipboardLastText ! = clipboardText )
{
clipboardLastText = clipboardText ;
if ( richTextBox . Text . Length > 0 )
{
richTextBox . AppendText ( "\n\n" + clipboardText ) ;
richTextBox . SelectionStart = richTextBox . Text . Length ;
richTextBox . ScrollToCaret ( ) ;
}
else
{
richTextBox . AppendText ( clipboardText ) ;
}
}
}
private void PasteBoardMainMenu_Click ( object sender , EventArgs e )
{
if ( pasteBoardMainMenu . Checked )
{
Clipboard . Clear ( ) ;
pasteBoardTimer . Start ( ) ;
statusPanelPasteboardLabel . Text = "Paste Board: " + pasteBoardMainMenu . Checked . ToString ( ) ;
}
else
{
pasteBoardTimer . Stop ( ) ;
statusPanelPasteboardLabel . Text = "Paste Board: " + pasteBoardMainMenu . Checked . ToString ( ) ;
}
}
/*Paste Board*/
2018-12-25 15:29:29 +00:00
/*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-11-22 15:39:10 +00:00
private async void CheckForUpdatesMainMenu_Click ( object sender , EventArgs e )
2018-12-25 15:29:29 +00:00
{
2019-11-22 15:39:10 +00:00
await 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 ( ) ;
2020-01-13 10:46:31 +00:00
aboutFrom . Owner = this ;
2019-09-28 19:57:03 +00:00
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
{
2020-01-13 10:40:14 +00:00
if ( ! readOnlyMainMenu . Checked )
{
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
}
2019-11-28 20:36:43 +00:00
private void ChangePasswordToolbarButton_Click ( object sender , EventArgs e )
2018-12-25 15:29:29 +00:00
{
2019-11-28 20:36:43 +00:00
ChangePasswordMainMenu_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
2020-08-23 21:07:27 +00:00
private void TryToDecryptToolbarButton_Click ( object sender , EventArgs e )
{
TryToDecryptMainMenu_Click ( this , new EventArgs ( ) ) ;
}
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-11-27 09:59:42 +00:00
if ( string . IsNullOrEmpty ( PublicVar . password . Get ( ) ) )
2019-10-11 10:38:15 +00:00
{
fileLocationToolbarButton . Enabled = false ;
deleteFileToolbarButton . Enabled = false ;
2019-11-28 20:36:43 +00:00
changePasswordToolbarButton . Enabled = false ;
2019-10-11 10:38:15 +00:00
lockToolbarButton . Enabled = false ;
}
else
{
fileLocationToolbarButton . Enabled = true ;
deleteFileToolbarButton . Enabled = true ;
2019-11-28 20:36:43 +00:00
changePasswordToolbarButton . Enabled = true ;
2019-10-11 10:38:15 +00:00
lockToolbarButton . Enabled = true ;
}
2020-08-23 21:07:27 +00:00
if ( string . IsNullOrEmpty ( PublicVar . password . Get ( ) ) & & richTextBox . TextLength > 0 & & ! string . IsNullOrEmpty ( filePath ) )
{
tryToDecryptToolbarButton . Enabled = true ;
}
else
{
tryToDecryptToolbarButton . Enabled = false ;
}
2019-10-11 10:38:15 +00:00
}
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-11-27 09:59:42 +00:00
PublicVar . password . Set ( null ) ;
2019-10-11 10:38:15 +00:00
caretPos = richTextBox . SelectionStart ;
richTextBox . Visible = false ;
2021-04-06 23:27:16 +00:00
settingsToolStripMenuItem . Enabled = false ;
2019-10-11 10:38:15 +00:00
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
{
2021-04-07 21:39:45 +00:00
settingsToolStripMenuItem . Enabled = true ;
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
2021-03-28 17:46:45 +00:00
private void ResetWindowLocationTrayMenu_Click ( object sender , EventArgs e )
{
Location = new Point ( 1 , 1 ) ;
}
private void SettingsToolStripMenuItem_Click ( object sender , EventArgs e )
{
SettingsForm settingsForm = new SettingsForm
{
Owner = this ,
StartPosition = FormStartPosition . CenterScreen
} ;
settingsForm . ShowDialog ( ) ;
}
2019-10-11 10:38:15 +00:00
private void TrayIcon_MouseDoubleClick ( object sender , MouseEventArgs e )
{
2019-10-25 21:11:24 +00:00
if ( e . Button = = MouseButtons . Left )
{
2021-03-28 17:46:45 +00:00
if ( ! Visible )
{
Show ( ) ;
WindowState = currentWindowState ;
2021-04-06 23:27:16 +00:00
if ( ! fileLockedPanel . Visible )
{
richTextBox . Visible = true ;
}
2021-03-28 17:46:45 +00:00
}
2019-10-13 11:54:45 +00:00
}
2019-10-11 10:38:15 +00:00
}
2021-03-28 17:46:45 +00:00
private void HideWindowTrayMenu_Click ( object sender , EventArgs e )
{
currentWindowState = WindowState ;
WindowState = FormWindowState . Minimized ;
Hide ( ) ;
}
private void ShowWindowTrayMenu_Click ( object sender , EventArgs e )
2019-10-11 10:38:15 +00:00
{
2021-03-28 17:46:45 +00:00
if ( ! Visible )
{
Show ( ) ;
WindowState = currentWindowState ;
2021-04-06 23:27:16 +00:00
if ( ! fileLockedPanel . Visible )
{
richTextBox . Visible = true ;
}
2021-03-28 17:46:45 +00:00
}
2019-10-11 10:38:15 +00:00
}
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
}
2021-03-28 17:46:45 +00:00
private void TrayMenu_Opening ( object sender , CancelEventArgs e )
{
if ( Visible )
{
showWindowTrayMenu . Enabled = false ;
}
else
{
showWindowTrayMenu . Enabled = true ;
}
if ( ! Visible )
{
hideWindowTrayMenu . Enabled = false ;
}
else
{
hideWindowTrayMenu . Enabled = true ;
}
}
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 ) ;
2021-04-07 11:19:36 +00:00
Debug . WriteLine ( "openFileDialog.FileName " + openFileDialog . FileName ) ;
2019-10-04 18:48:55 +00:00
Debug . WriteLine ( "filePath: " + filePath ) ;
2019-11-27 09:59:42 +00:00
Debug . WriteLine ( "encryptionKey: " + PublicVar . password . Get ( ) ) ;
2019-10-04 18:48:55 +00:00
Debug . WriteLine ( "TypedPassword: " + TypedPassword . Value ) ;
2019-11-27 09:59:42 +00:00
Debug . WriteLine ( "keyChanged: " + PublicVar . passwordChanged ) ;
2019-10-04 18:48:55 +00:00
Debug . WriteLine ( "okPressed: " + PublicVar . okPressed ) ;
Debug . WriteLine ( "RichTextBox.Modified: " + richTextBox . Modified ) ;
Debug . WriteLine ( "EditorMenuStrip: " + contextMenu . Enabled ) ;
2019-11-27 09:56:53 +00:00
Debug . WriteLine ( "metadataCorrupt: " + PublicVar . metadataCorrupt ) ;
2019-10-04 18:48:55 +00:00
#endif
2019-08-23 18:41:21 +00:00
}
2021-03-28 17:46:45 +00:00
2021-04-07 11:19:36 +00:00
2019-09-28 19:45:20 +00:00
2021-03-28 17:46:45 +00:00
2022-05-22 08:07:48 +00:00
#endregion
2021-04-07 11:19:36 +00:00
2018-12-17 11:16:17 +00:00
}
2019-08-21 11:15:16 +00:00
}