2021-07-26 09:08:46 +05:00
|
|
|
using System;
|
2021-07-30 03:19:59 +05:00
|
|
|
using System.Diagnostics;
|
2021-08-07 08:55:12 +05:00
|
|
|
using System.Drawing;
|
2021-07-26 09:08:46 +05:00
|
|
|
using System.IO;
|
2022-01-23 13:13:45 +05:00
|
|
|
using System.Linq;
|
2021-07-30 03:19:59 +05:00
|
|
|
using System.Reflection;
|
2021-07-26 09:08:46 +05:00
|
|
|
using System.Threading;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
2022-03-03 16:38:17 +05:00
|
|
|
using CreamInstaller.Steam;
|
|
|
|
using CreamInstaller.Utility;
|
2022-02-07 06:17:51 +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-01-25 00:10:29 +05:00
|
|
|
internal static readonly string ApplicationName = Application.CompanyName + " v" + Application.ProductVersion + ": " + Application.ProductName;
|
2022-03-03 16:38:17 +05:00
|
|
|
internal static readonly string ApplicationNameShort = Application.CompanyName + " v" + Application.ProductVersion;
|
2022-02-25 09:12:48 +05:00
|
|
|
|
2022-01-25 00:10:29 +05:00
|
|
|
internal static readonly Assembly EntryAssembly = Assembly.GetEntryAssembly();
|
|
|
|
internal static readonly Process CurrentProcess = Process.GetCurrentProcess();
|
|
|
|
internal static readonly string CurrentProcessFilePath = CurrentProcess.MainModule.FileName;
|
|
|
|
|
|
|
|
internal static bool BlockProtectedGames = true;
|
2022-03-03 16:38:17 +05:00
|
|
|
internal static readonly string[] ProtectedGameNames = { "PAYDAY 2", "Call to Arms" }; // non-functioning CreamAPI/ScreamAPI or DLL detections
|
2022-01-25 00:10:29 +05:00
|
|
|
internal static readonly string[] ProtectedGameDirectories = { @"\EasyAntiCheat", @"\BattlEye" }; // DLL detections
|
|
|
|
internal static readonly string[] ProtectedGameDirectoryExceptions = { "Arma 3" }; // Arma 3's BattlEye doesn't detect DLL changes?
|
|
|
|
|
2022-03-15 15:08:15 +05:00
|
|
|
internal static bool IsGameBlocked(string name, string directory = null)
|
2021-07-26 09:08:46 +05:00
|
|
|
{
|
2022-02-05 12:04:22 +05:00
|
|
|
if (!BlockProtectedGames) return false;
|
2022-01-25 00:10:29 +05:00
|
|
|
if (ProtectedGameNames.Contains(name)) return true;
|
2022-03-15 15:08:15 +05:00
|
|
|
if (directory is not null && !ProtectedGameDirectoryExceptions.Contains(name))
|
2022-01-25 00:10:29 +05:00
|
|
|
foreach (string path in ProtectedGameDirectories)
|
|
|
|
if (Directory.Exists(directory + path)) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2022-01-23 13:13:45 +05:00
|
|
|
|
2022-02-25 10:51:11 +05:00
|
|
|
internal static bool IsFilePathLocked(this string filePath)
|
|
|
|
{
|
|
|
|
try { File.Open(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None).Close(); }
|
|
|
|
catch (FileNotFoundException) { return false; }
|
|
|
|
catch (IOException) { return true; }
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:12:48 +05:00
|
|
|
internal static bool IsProgramRunningDialog(Form form, ProgramSelection selection)
|
|
|
|
{
|
2022-03-03 16:38:17 +05:00
|
|
|
if (selection.AreDllsLocked)
|
2022-02-25 09:12:48 +05:00
|
|
|
{
|
2022-03-09 04:58:52 +05:00
|
|
|
using DialogForm dialogForm = new(form);
|
|
|
|
if (dialogForm.Show(SystemIcons.Error,
|
2022-02-25 09:12:48 +05:00
|
|
|
$"ERROR: {selection.Name} is currently running!" +
|
|
|
|
"\n\nPlease close the program/game to continue . . . ",
|
|
|
|
"Retry", "Cancel") == DialogResult.OK)
|
|
|
|
return IsProgramRunningDialog(form, selection);
|
|
|
|
}
|
|
|
|
else return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-08 00:40:48 +05:00
|
|
|
internal static void GetCreamApiComponents(this string directory, out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config)
|
2022-02-25 10:51:11 +05:00
|
|
|
{
|
2022-03-08 00:40:48 +05:00
|
|
|
sdk32 = directory + @"\steam_api.dll";
|
|
|
|
sdk32_o = directory + @"\steam_api_o.dll";
|
|
|
|
sdk64 = directory + @"\steam_api64.dll";
|
|
|
|
sdk64_o = directory + @"\steam_api64_o.dll";
|
|
|
|
config = directory + @"\cream_api.ini";
|
2022-02-25 10:51:11 +05:00
|
|
|
}
|
|
|
|
|
2022-03-08 00:40:48 +05:00
|
|
|
internal static void GetScreamApiComponents(this string directory, out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config)
|
2022-03-03 16:38:17 +05:00
|
|
|
{
|
2022-03-08 00:40:48 +05:00
|
|
|
sdk32 = directory + @"\EOSSDK-Win32-Shipping.dll";
|
|
|
|
sdk32_o = directory + @"\EOSSDK-Win32-Shipping_o.dll";
|
2022-03-03 16:38:17 +05:00
|
|
|
sdk64 = directory + @"\EOSSDK-Win64-Shipping.dll";
|
|
|
|
sdk64_o = directory + @"\EOSSDK-Win64-Shipping_o.dll";
|
2022-03-08 00:40:48 +05:00
|
|
|
config = directory + @"\ScreamAPI.json";
|
2022-03-03 16:38:17 +05:00
|
|
|
}
|
|
|
|
|
2022-01-25 00:10:29 +05:00
|
|
|
[STAThread]
|
|
|
|
private static void Main()
|
|
|
|
{
|
2022-03-09 04:58:52 +05:00
|
|
|
using Mutex mutex = new(true, "CreamInstaller", out bool createdNew);
|
2022-01-25 00:10:29 +05:00
|
|
|
if (createdNew)
|
2021-07-26 09:08:46 +05:00
|
|
|
{
|
2022-01-25 00:10:29 +05:00
|
|
|
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
|
|
|
Application.EnableVisualStyles();
|
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
|
|
Application.ApplicationExit += new(OnApplicationExit);
|
|
|
|
retry:
|
|
|
|
try
|
2021-07-30 16:01:42 +05:00
|
|
|
{
|
2022-02-25 09:12:48 +05:00
|
|
|
HttpClientManager.Setup();
|
2022-03-09 04:58:52 +05:00
|
|
|
using MainForm form = new();
|
|
|
|
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
|
|
|
{
|
2022-01-25 00:10:29 +05:00
|
|
|
if (ExceptionHandler.OutputException(e)) goto retry;
|
|
|
|
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-02-15 04:41:10 +05:00
|
|
|
internal static void Invoke(this Control control, MethodInvoker methodInvoker) => control.Invoke(methodInvoker);
|
|
|
|
|
2022-03-09 04:58:52 +05:00
|
|
|
internal static bool Canceled;
|
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();
|
|
|
|
}
|
2022-01-25 00:10:29 +05:00
|
|
|
}
|