CreamInstaller/CreamInstaller/Program.cs

90 lines
3.4 KiB
C#
Raw Normal View History

2021-07-26 09:08:46 +05:00
using System;
2021-07-30 03:19:59 +05:00
using System.Diagnostics;
using System.Linq;
2021-07-26 09:08:46 +05:00
using System.Threading;
using System.Windows.Forms;
using CreamInstaller.Forms;
using CreamInstaller.Platforms.Steam;
using CreamInstaller.Utility;
2021-07-26 09:08:46 +05:00
namespace CreamInstaller;
internal static class Program
2021-07-26 09:08:46 +05:00
{
2022-09-20 19:38:27 +05:00
internal static readonly string Name = Application.CompanyName;
private static readonly string Description = Application.ProductName;
2022-09-20 19:38:27 +05:00
internal static readonly string Version = Application.ProductVersion;
internal const string RepositoryOwner = "pointfeev";
internal static readonly string RepositoryName = Name;
internal static readonly string RepositoryPackage = Name + ".zip";
2023-04-06 11:43:11 +05:00
internal static readonly string RepositoryExecutable = Name + ".exe";
2022-06-12 08:37:32 +05:00
#if DEBUG
2022-09-20 19:38:27 +05:00
internal static readonly string ApplicationName = Name + " v" + Version + "-debug: " + Description;
internal static readonly string ApplicationNameShort = Name + " v" + Version + "-debug";
2022-06-12 08:37:32 +05:00
#else
2022-09-20 19:38:27 +05:00
internal static readonly string ApplicationName = Name + " v" + Version + ": " + Description;
internal static readonly string ApplicationNameShort = Name + " v" + Version;
2022-06-12 08:37:32 +05:00
#endif
2022-02-25 09:12:48 +05:00
private static readonly Process CurrentProcess = Process.GetCurrentProcess();
internal static readonly string CurrentProcessFilePath = CurrentProcess.MainModule?.FileName;
2023-04-06 11:43:11 +05:00
internal static readonly int CurrentProcessId = CurrentProcess.Id;
internal static bool BlockProtectedGames = true;
2022-08-22 00:48:38 +05:00
internal static readonly string[] ProtectedGames = { "PAYDAY 2" };
internal static readonly string[] ProtectedGameDirectories = { @"\EasyAntiCheat", @"\BattlEye" };
internal static readonly string[] ProtectedGameDirectoryExceptions = Array.Empty<string>();
internal static bool IsGameBlocked(string name, string directory = null)
=> BlockProtectedGames && (ProtectedGames.Contains(name) || directory is not null && !ProtectedGameDirectoryExceptions.Contains(name)
&& ProtectedGameDirectories.Any(path => (directory + path).DirectoryExists()));
2022-02-25 09:12:48 +05:00
[STAThread]
private static void Main()
{
2022-09-20 19:38:27 +05:00
using Mutex mutex = new(true, Name, out bool createdNew);
if (createdNew)
2021-07-26 09:08:46 +05:00
{
_ = Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ApplicationExit += OnApplicationExit;
2023-01-14 02:48:34 +05:00
Application.ThreadException += (_, e) => e.Exception.HandleFatalException();
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
2023-01-14 02:48:34 +05:00
AppDomain.CurrentDomain.UnhandledException += (_, e) => (e.ExceptionObject as Exception)?.HandleFatalException();
retry:
try
{
2022-02-25 09:12:48 +05:00
HttpClientManager.Setup();
using UpdateForm form = new();
#if DEBUG
DebugForm.Current.Attach(form);
#endif
Application.Run(form);
}
catch (Exception e)
{
2023-01-05 23:22:44 +05:00
if (e.HandleException())
goto retry;
Application.Exit();
return;
}
}
mutex.Close();
}
internal static bool Canceled;
internal static async void Cleanup(bool cancel = true)
{
Canceled = cancel;
await SteamCMD.Cleanup();
}
2021-07-26 09:08:46 +05:00
2022-02-25 10:51:11 +05:00
private static void OnApplicationExit(object s, EventArgs e)
{
Cleanup();
HttpClientManager.Dispose();
}
}