2019-10-20 19:59:52 +00:00
using Crypto_Notepad.Properties ;
using System ;
using System.Diagnostics ;
using System.Runtime.InteropServices ;
using System.Threading ;
2016-01-06 14:47:38 +00:00
using System.Windows.Forms ;
2016-01-09 20:46:25 +00:00
namespace Crypto_Notepad
2016-01-06 14:47:38 +00:00
{
static class Program
{
2019-10-20 19:59:52 +00:00
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow ( IntPtr hWnd ) ;
2016-01-06 14:47:38 +00:00
/// <summary>
2019-01-07 10:09:52 +00:00
/// The main entry point for the application.
2016-01-06 14:47:38 +00:00
/// </summary>
[STAThread]
2016-01-15 16:17:44 +00:00
static void Main ( )
2016-01-06 14:47:38 +00:00
{
2019-10-20 19:59:52 +00:00
Settings settings = Settings . Default ;
using ( Mutex mutex = new Mutex ( true , PublicVar . appName , out bool createdNew ) )
{
if ( ! settings . singleInstance )
{
createdNew = true ;
}
if ( createdNew )
{
Application . EnableVisualStyles ( ) ;
Application . SetCompatibleTextRenderingDefault ( false ) ;
Application . Run ( new MainForm ( ) ) ;
}
else
{
DialogResult dialogResult = MessageBox . Show ( PublicVar . appName + " is already running.\nDo you still want to open a new copy of the app?" , PublicVar . appName , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) ;
if ( dialogResult = = DialogResult . Yes )
{
Application . EnableVisualStyles ( ) ;
Application . SetCompatibleTextRenderingDefault ( false ) ;
Application . Run ( new MainForm ( ) ) ;
}
if ( dialogResult = = DialogResult . No )
{
Process current = Process . GetCurrentProcess ( ) ;
foreach ( Process process in Process . GetProcessesByName ( current . ProcessName ) )
{
if ( process . Id ! = current . Id )
{
SetForegroundWindow ( process . MainWindowHandle ) ;
break ;
}
}
}
}
}
2016-01-06 14:47:38 +00:00
}
}
2016-01-26 17:07:17 +00:00
2018-12-17 10:52:40 +00:00
static class PublicVar
2016-01-26 17:07:17 +00:00
{
2018-12-01 02:29:19 +00:00
public static EncryptedString encryptionKey = new EncryptedString ( ) ;
2016-01-27 17:19:25 +00:00
public static bool keyChanged = false ;
public static bool okPressed = false ;
2019-01-07 10:08:47 +00:00
public const string appName = "Crypto Notepad" ;
2019-01-07 10:09:52 +00:00
public static string openFileName ;
2016-01-26 17:07:17 +00:00
}
2019-09-28 19:44:14 +00:00
2018-12-17 10:52:40 +00:00
static class TypedPassword
{
public static string Value { get ; set ; }
}
2016-01-27 17:19:25 +00:00
2016-01-06 14:47:38 +00:00
}