168 lines
6.0 KiB
C#
Raw Normal View History

2022-05-13 22:41:15 +01:00
using System.IO;
using System;
using System.Diagnostics;
using System.Threading;
2022-05-14 02:58:38 +01:00
using SPT_AKI_Installer.Aki.Helper;
using Spectre.Console;
2022-05-13 22:41:15 +01:00
2022-05-14 02:58:38 +01:00
namespace SPT_AKI_Installer.Aki.Core
2022-05-13 22:41:15 +01:00
{
//TODO:
// delete patcher zip and aki zip
2022-05-14 02:58:38 +01:00
// progress for copyDirectory
// move Game/patcher/aki check methods out of core
// add figlet for SPT-AKI INSTALLER
// locales, language selection
2022-05-13 22:41:15 +01:00
public static class SPTinstaller
{
2022-05-14 02:58:38 +01:00
public static string targetPath = Environment.CurrentDirectory;
2022-05-13 22:41:15 +01:00
private static string patchRef;
private static string akiRef;
private static DirectoryInfo dir;
2022-05-14 02:58:38 +01:00
private static string gamePath;
2022-05-13 22:41:15 +01:00
static void Main(string[] args)
{
2022-05-14 02:58:38 +01:00
#if DEBUG
targetPath = @"D:\install";
#endif
GameCheck(out gamePath);
2022-05-13 22:41:15 +01:00
if (PatcherCheck(gamePath, out patchRef))
{
LogHelper.Info($"Correct Zip for Patcher Present: {patchRef}");
}
else
{
LogHelper.Error("Patcher zip is Incorrect or missing");
LogHelper.Error("Press enter to close the app");
Console.ReadKey();
Environment.Exit(0);
}
if (AkiCheck(out akiRef))
{
LogHelper.Info($"Correct Zip for SPT-AKI Present: {akiRef}");
}
else
{
LogHelper.Error("SPT-AKI zip is Incorrect or missing");
LogHelper.Error("Press enter to close the app");
Console.ReadKey();
Environment.Exit(0);
}
// checks for input to copy game files
LogHelper.User("PLEASE PRESS ENTER TO COPY GAME FILES!");
Console.ReadKey();
// copies and pastes EFT to AKI installer test folder
2022-05-14 02:58:38 +01:00
#if !DEBUG
FileHelper.CopyDirectory(gamePath, targetPath, true);
2022-05-13 22:41:15 +01:00
LogHelper.User("GAME HAS BEEN COPIED, PRESS ENTER TO EXTRACT PATCHER!");
Console.ReadKey();
2022-05-14 02:58:38 +01:00
#endif
2022-05-13 22:41:15 +01:00
// extracts patcher and moves out inner folders
2022-05-14 02:58:38 +01:00
ZipHelper.Decompress(patchRef, targetPath);
2022-05-13 22:41:15 +01:00
FileHelper.FindFolder(patchRef, out dir);
2022-05-14 02:58:38 +01:00
FileHelper.CopyDirectory(dir.FullName, targetPath, true);
2022-05-13 22:41:15 +01:00
if (dir.Exists)
{
dir.Delete(true);
dir.Refresh();
if (dir.Exists)
{
LogHelper.Error("unable to delete patcher folder");
LogHelper.Error($"please delete folder called {dir.FullName}");
}
}
// starts patcher and checks for user input to exit patcher and proceed
2022-05-14 02:58:38 +01:00
LogHelper.Info("PATCHER HAS BEEN EXTRACTED, STARTING PATCHER!");
ProcessHelper patcherProcess = new();
patcherProcess.StartProcess(Path.Join(targetPath + "/patcher.exe"), targetPath);
2022-05-13 22:41:15 +01:00
LogHelper.User("PATCHER HAS BEEN STARTED, TYPE YES ONCE THE PATCHER IS COMPLETE!");
var complete = Console.ReadLine();
// waiting for user to enter "yes", if something else is entered do while loop
while (!string.Equals(complete, "yes", StringComparison.OrdinalIgnoreCase))
{
LogHelper.Warning("YOU DIDNT TYPE YES, IF SOMETHING WENT WRONG MAKE A SUPPORT THREAD AND CLOSE THIS APP");
LogHelper.User("IF IT DID FINISH TYPE YES NOW");
complete = Console.ReadLine();
}
// if user input "yes" kill patcher process, delete patcher.exe, extract aki zip
if (string.Equals(complete, "yes", StringComparison.OrdinalIgnoreCase))
{
patcherProcess.EndProcess();
Thread.Sleep(1000);
2022-05-14 02:58:38 +01:00
FileHelper.DeleteFile("file", targetPath + "/patcher.exe");
ZipHelper.Decompress(akiRef, targetPath);
2022-05-13 22:41:15 +01:00
LogHelper.Info("AKI HAS BEEN EXTRACTED, RUN THE SERVER AND WAIT TILL YOU SEE HAPPY SERVER THEN LAUNCHER AND ENJOY!");
LogHelper.User("PRESS ENTER TO CLOSE THE APP");
Console.ReadKey();
}
}
2022-05-14 02:58:38 +01:00
/// <summary>
/// checks the game is installed, out = game directory
/// </summary>
/// <param name="gamePath"></param>
private static void GameCheck(out string gamePath)
{
string Path = GameHelper.DetectOriginalGamePath();
if (Path == null)
{
LogHelper.Error("EFT IS NOT INSTALLED!");
LogHelper.Error("Press enter to close the app");
Console.ReadKey();
Environment.Exit(0);
}
gamePath = Path;
}
/// <summary>
/// checks for patcher zip path, out = patcher path
/// </summary>
/// <param name="gamePath"></param>
/// <param name="patchRef"></param>
/// <returns>bool</returns>
2022-05-13 22:41:15 +01:00
private static bool PatcherCheck(string gamePath, out string patchRef)
{
FileVersionInfo version = FileVersionInfo.GetVersionInfo(Path.Join(gamePath + "/EscapeFromTarkov.exe"));
string versionCheck = StringHelper.Splitter(version.ProductVersion, '-', '.', 2);
LogHelper.Info($"GAME VERSION IS: {version.ProductVersion}");
2022-05-14 02:58:38 +01:00
string patcherRef = FileHelper.FindFile(targetPath, versionCheck);
2022-05-13 22:41:15 +01:00
if (patcherRef != null)
{
patchRef = patcherRef;
return true;
}
patchRef = null;
return false;
}
2022-05-14 02:58:38 +01:00
/// <summary>
/// checks for aki zip path, out = aki path
/// </summary>
/// <param name="akiRef"></param>
/// <returns>bool</returns>
2022-05-13 22:41:15 +01:00
private static bool AkiCheck(out string akiRef)
{
2022-05-14 02:58:38 +01:00
string aki = FileHelper.FindFile(targetPath, "2.3.1");
2022-05-13 22:41:15 +01:00
if (aki != null)
{
akiRef = aki;
return true;
}
akiRef = null;
return false;
}
}
}