2021-07-26 09:08:46 +05:00
|
|
|
using System;
|
2021-07-30 03:19:59 +05:00
|
|
|
using System.Diagnostics;
|
2022-01-23 13:13:45 +05:00
|
|
|
using System.Linq;
|
2021-07-26 09:08:46 +05:00
|
|
|
using System.Threading;
|
|
|
|
using System.Windows.Forms;
|
2022-12-21 02:26:35 +05:00
|
|
|
using CreamInstaller.Forms;
|
|
|
|
using CreamInstaller.Platforms.Steam;
|
|
|
|
using CreamInstaller.Utility;
|
2021-07-26 09:08:46 +05:00
|
|
|
|
2022-01-25 00:10:29 +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;
|
2023-01-14 01:15:13 +05:00
|
|
|
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
|
|
|
|
2023-01-14 01:15:13 +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;
|
2022-01-25 00:10:29 +05:00
|
|
|
|
|
|
|
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" };
|
2022-08-18 19:27:47 +05:00
|
|
|
internal static readonly string[] ProtectedGameDirectoryExceptions = Array.Empty<string>();
|
2022-01-25 00:10:29 +05:00
|
|
|
|
2022-03-15 15:08:15 +05:00
|
|
|
internal static bool IsGameBlocked(string name, string directory = null)
|
2023-05-30 00:57:12 +05:00
|
|
|
=> BlockProtectedGames && (ProtectedGames.Contains(name) || directory is not null && !ProtectedGameDirectoryExceptions.Contains(name)
|
2023-06-10 04:04:54 +05:00
|
|
|
&& ProtectedGameDirectories.Any(path => (directory + path).DirectoryExists()));
|
2022-02-25 09:12:48 +05:00
|
|
|
|
2022-01-25 00:10:29 +05:00
|
|
|
[STAThread]
|
|
|
|
private static void Main()
|
|
|
|
{
|
2022-09-20 19:38:27 +05:00
|
|
|
using Mutex mutex = new(true, Name, out bool createdNew);
|
2022-01-25 00:10:29 +05:00
|
|
|
if (createdNew)
|
2021-07-26 09:08:46 +05:00
|
|
|
{
|
2022-08-17 02:15:29 +05:00
|
|
|
_ = Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
2022-01-25 00:10:29 +05:00
|
|
|
Application.EnableVisualStyles();
|
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
2022-12-21 02:26:35 +05:00
|
|
|
Application.ApplicationExit += OnApplicationExit;
|
2023-01-14 02:48:34 +05:00
|
|
|
Application.ThreadException += (_, e) => e.Exception.HandleFatalException();
|
2022-03-25 23:21:03 +05:00
|
|
|
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
2023-01-14 02:48:34 +05:00
|
|
|
AppDomain.CurrentDomain.UnhandledException += (_, e) => (e.ExceptionObject as Exception)?.HandleFatalException();
|
2022-12-21 02:26:35 +05:00
|
|
|
retry:
|
2022-01-25 00:10:29 +05:00
|
|
|
try
|
2021-07-30 16:01:42 +05:00
|
|
|
{
|
2022-02-25 09:12:48 +05:00
|
|
|
HttpClientManager.Setup();
|
2023-03-30 11:19:45 +05:00
|
|
|
using UpdateForm form = new();
|
2022-09-20 09:55:24 +05:00
|
|
|
#if DEBUG
|
|
|
|
DebugForm.Current.Attach(form);
|
|
|
|
#endif
|
2022-03-09 04:58:52 +05:00
|
|
|
Application.Run(form);
|
2021-07-30 16:01:42 +05:00
|
|
|
}
|
2022-01-25 00:10:29 +05:00
|
|
|
catch (Exception e)
|
2022-01-23 13:13:45 +05:00
|
|
|
{
|
2023-01-05 23:22:44 +05:00
|
|
|
if (e.HandleException())
|
|
|
|
goto retry;
|
2022-01-25 00:10:29 +05:00
|
|
|
Application.Exit();
|
|
|
|
return;
|
2022-01-23 13:13:45 +05:00
|
|
|
}
|
|
|
|
}
|
2022-01-25 00:10:29 +05:00
|
|
|
mutex.Close();
|
|
|
|
}
|
2022-01-23 13:13:45 +05:00
|
|
|
|
2022-03-09 04:58:52 +05:00
|
|
|
internal static bool Canceled;
|
2022-12-21 02:26:35 +05:00
|
|
|
|
2022-01-25 00:10:29 +05:00
|
|
|
internal static async void Cleanup(bool cancel = true)
|
|
|
|
{
|
|
|
|
Canceled = cancel;
|
2022-02-12 04:25:18 +05:00
|
|
|
await SteamCMD.Cleanup();
|
2022-01-25 00:10:29 +05:00
|
|
|
}
|
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();
|
|
|
|
}
|
2023-01-14 01:15:13 +05:00
|
|
|
}
|