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
|
|
|
|
|
|
{
|
2019-10-20 20:21:07 +00:00
|
|
|
|
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,
|
|
|
|
|
|
MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly);
|
2019-10-20 19:59:52 +00:00
|
|
|
|
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
|
|
|
|
{
|
2019-11-27 09:59:42 +00:00
|
|
|
|
public static EncryptedString password = new EncryptedString();
|
|
|
|
|
|
public static bool passwordChanged = false;
|
2016-01-27 17:19:25 +00:00
|
|
|
|
public static bool okPressed = false;
|
2019-11-05 19:23:13 +00:00
|
|
|
|
public static bool messageBoxCenterParent = 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;
|
2019-11-27 09:56:53 +00:00
|
|
|
|
public static bool metadataCorrupt = false;
|
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
|
|
|
|
}
|