2020-08-10 06:58:51 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2020-08-11 10:55:57 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows.Forms;
|
2020-08-10 06:58:51 +02:00
|
|
|
|
|
|
|
|
|
namespace Giants.Launcher
|
|
|
|
|
{
|
|
|
|
|
static class Program
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
static void Main()
|
|
|
|
|
{
|
|
|
|
|
using (Mutex mutex = new Mutex(true, "GiantsLauncherMutex"))
|
|
|
|
|
{
|
|
|
|
|
if (!mutex.WaitOne(TimeSpan.Zero, true))
|
|
|
|
|
{
|
|
|
|
|
// Another instance must be running, switch the first process we find with the same name to the foreground:
|
2020-08-11 10:55:57 +02:00
|
|
|
|
string appName = Process.GetCurrentProcess().MainModule.FileName;
|
2020-08-10 06:58:51 +02:00
|
|
|
|
Process[] processes = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(appName));
|
|
|
|
|
|
|
|
|
|
Process otherProcess = processes.FirstOrDefault(p => p.Id != Process.GetCurrentProcess().Id);
|
|
|
|
|
if (otherProcess != null)
|
|
|
|
|
{
|
|
|
|
|
NativeMethods.SetForegroundWindow(otherProcess.MainWindowHandle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Application.Exit();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Application.EnableVisualStyles();
|
|
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
2020-08-11 10:55:57 +02:00
|
|
|
|
|
2020-08-13 08:02:36 +02:00
|
|
|
|
Form form;
|
2020-08-11 10:55:57 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-08-13 08:02:36 +02:00
|
|
|
|
form = new LauncherForm();
|
2020-08-11 10:55:57 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(
|
2020-08-13 08:02:36 +02:00
|
|
|
|
text: string.Format(Resources.LauncherFatalError, ex.Message),
|
|
|
|
|
caption: Resources.Error,
|
2020-08-11 10:55:57 +02:00
|
|
|
|
buttons: MessageBoxButtons.OK,
|
|
|
|
|
icon: MessageBoxIcon.Error);
|
2020-08-13 08:02:36 +02:00
|
|
|
|
|
|
|
|
|
Application.Exit();
|
|
|
|
|
return;
|
2020-08-11 10:55:57 +02:00
|
|
|
|
}
|
2020-08-13 08:02:36 +02:00
|
|
|
|
|
|
|
|
|
Application.Run(form);
|
2020-08-10 06:58:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|