Bump, Made ProcessHelper, PreCheckHelper, StringHelper non static, moved out methods to PreCheckHelper from Main, hopefully cleaned up Program.cs

This commit is contained in:
CWX 2022-05-14 12:19:40 +01:00
parent a0d715cb44
commit 1cb9f5e03d
8 changed files with 154 additions and 115 deletions

View File

@ -10,26 +10,28 @@ namespace SPT_AKI_Installer.Aki.Core
//TODO: //TODO:
// delete patcher zip and aki zip // delete patcher zip and aki zip
// progress for copyDirectory // progress for copyDirectory
// move Game/patcher/aki check methods out of core
// add figlet for SPT-AKI INSTALLER // add figlet for SPT-AKI INSTALLER
// locales, language selection // locales, language selection
// PreCheckHelper.AkiCheck is currently hardcoded for 2.3.1
// get waffle to add exit code on patcher
// remove all user input other than errors
//comments:
// static: FileHelper, ZipHelper, LogHelper
// nonStatic: ProcessHelper, PreCheckHelper, StringHelper
public static class SPTinstaller public static class SPTinstaller
{ {
public static string targetPath = Environment.CurrentDirectory;
private static string patchRef;
private static string akiRef;
private static DirectoryInfo dir;
private static string gamePath;
static void Main(string[] args) static void Main(string[] args)
{ {
string targetPath = Environment.CurrentDirectory;
PreCheckHelper preCheckHelper = new();
#if DEBUG #if DEBUG
targetPath = @"D:\install"; targetPath = @"D:\install";
#endif #endif
GameCheck(out gamePath); preCheckHelper.GameCheck(out string gamePath);
if (PatcherCheck(gamePath, out patchRef)) if (preCheckHelper.PatcherCheck(gamePath,targetPath, out string patchRef))
{ {
LogHelper.Info($"Correct Zip for Patcher Present: {patchRef}"); LogHelper.Info($"Correct Zip for Patcher Present: {patchRef}");
} }
@ -41,7 +43,7 @@ namespace SPT_AKI_Installer.Aki.Core
Environment.Exit(0); Environment.Exit(0);
} }
if (AkiCheck(out akiRef)) if (preCheckHelper.AkiCheck(targetPath,out string akiRef))
{ {
LogHelper.Info($"Correct Zip for SPT-AKI Present: {akiRef}"); LogHelper.Info($"Correct Zip for SPT-AKI Present: {akiRef}");
} }
@ -57,16 +59,36 @@ namespace SPT_AKI_Installer.Aki.Core
LogHelper.User("PLEASE PRESS ENTER TO COPY GAME FILES!"); LogHelper.User("PLEASE PRESS ENTER TO COPY GAME FILES!");
Console.ReadKey(); Console.ReadKey();
// copies and pastes EFT to AKI installer test folder GameCopy(gamePath, targetPath, akiRef);
}
/// <summary>
/// copies and pastes EFT to AKI installer test folder
/// </summary>
/// <param name="gamePath"></param>
/// <param name="targetPath"></param>
static void GameCopy(string gamePath, string targetPath, string akiRef)
{
#if !DEBUG #if !DEBUG
FileHelper.CopyDirectory(gamePath, targetPath, true); FileHelper.CopyDirectory(gamePath, targetPath, true);
#endif
LogHelper.User("GAME HAS BEEN COPIED, PRESS ENTER TO EXTRACT PATCHER!"); LogHelper.User("GAME HAS BEEN COPIED, PRESS ENTER TO EXTRACT PATCHER!");
Console.ReadKey(); Console.ReadKey();
#endif
// extracts patcher and moves out inner folders PatcherCopy(gamePath, targetPath, akiRef);
}
/// <summary>
/// extracts patcher and moves out inner folders
/// </summary>
/// <param name="patchRef"></param>
/// <param name="targetPath"></param>
/// <param name="akiRef"></param>
static void PatcherCopy(string patchRef, string targetPath, string akiRef)
{
#if !DEBUG
ZipHelper.Decompress(patchRef, targetPath); ZipHelper.Decompress(patchRef, targetPath);
FileHelper.FindFolder(patchRef, out dir); FileHelper.FindFolder(patchRef, targetPath, out DirectoryInfo dir);
FileHelper.CopyDirectory(dir.FullName, targetPath, true); FileHelper.CopyDirectory(dir.FullName, targetPath, true);
if (dir.Exists) if (dir.Exists)
{ {
@ -78,11 +100,22 @@ namespace SPT_AKI_Installer.Aki.Core
LogHelper.Error($"please delete folder called {dir.FullName}"); LogHelper.Error($"please delete folder called {dir.FullName}");
} }
} }
#endif
PatcherProcessStart(targetPath, akiRef);
}
// starts patcher and checks for user input to exit patcher and proceed /// <summary>
/// starts patcher and checks for user input to exit patcher and proceed
/// </summary>
/// <param name="targetPath"></param>
/// <param name="akiRef"></param>
static void PatcherProcessStart(string targetPath, string akiRef)
{
#if !DEBUG
LogHelper.Info("PATCHER HAS BEEN EXTRACTED, STARTING PATCHER!"); LogHelper.Info("PATCHER HAS BEEN EXTRACTED, STARTING PATCHER!");
ProcessHelper patcherProcess = new(); ProcessHelper patcherProcess = new();
patcherProcess.StartProcess(Path.Join(targetPath + "/patcher.exe"), targetPath); patcherProcess.StartProcess(Path.Join(targetPath + "/patcher.exe"), targetPath);
#endif
LogHelper.User("PATCHER HAS BEEN STARTED, TYPE YES ONCE THE PATCHER IS COMPLETE!"); LogHelper.User("PATCHER HAS BEEN STARTED, TYPE YES ONCE THE PATCHER IS COMPLETE!");
var complete = Console.ReadLine(); var complete = Console.ReadLine();
@ -97,72 +130,17 @@ namespace SPT_AKI_Installer.Aki.Core
// if user input "yes" kill patcher process, delete patcher.exe, extract aki zip // if user input "yes" kill patcher process, delete patcher.exe, extract aki zip
if (string.Equals(complete, "yes", StringComparison.OrdinalIgnoreCase)) if (string.Equals(complete, "yes", StringComparison.OrdinalIgnoreCase))
{ {
#if !DEBUG
patcherProcess.EndProcess(); patcherProcess.EndProcess();
Thread.Sleep(1000); Thread.Sleep(1000);
FileHelper.DeleteFile("file", targetPath + "/patcher.exe"); FileHelper.DeleteFile("file", targetPath + "/patcher.exe");
ZipHelper.Decompress(akiRef, targetPath); ZipHelper.Decompress(akiRef, targetPath);
#endif
LogHelper.Info("AKI HAS BEEN EXTRACTED, RUN THE SERVER AND WAIT TILL YOU SEE HAPPY SERVER THEN LAUNCHER AND ENJOY!"); 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"); LogHelper.User("PRESS ENTER TO CLOSE THE APP");
Console.ReadKey(); Console.ReadKey();
}
}
/// <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); 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>
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}");
string patcherRef = FileHelper.FindFile(targetPath, versionCheck);
if (patcherRef != null)
{
patchRef = patcherRef;
return true;
}
patchRef = null;
return false;
}
/// <summary>
/// checks for aki zip path, out = aki path
/// </summary>
/// <param name="akiRef"></param>
/// <returns>bool</returns>
private static bool AkiCheck(out string akiRef)
{
string aki = FileHelper.FindFile(targetPath, "2.3.1");
if (aki != null)
{
akiRef = aki;
return true;
}
akiRef = null;
return false;
} }
} }
} }

View File

@ -1,5 +1,4 @@
using SPT_AKI_Installer.Aki.Core; using System;
using System;
using System.IO; using System.IO;
namespace SPT_AKI_Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
@ -84,11 +83,11 @@ namespace SPT_AKI_Installer.Aki.Helper
/// <param name="patchRef"></param> /// <param name="patchRef"></param>
/// <param name="dir"></param> /// <param name="dir"></param>
/// <returns></returns> /// <returns></returns>
public static bool FindFolder(string patchRef, out DirectoryInfo dir) public static bool FindFolder(string patchRef, string targetPath, out DirectoryInfo dir)
{ {
var patchInfo = new FileInfo(patchRef); var patchInfo = new FileInfo(patchRef);
var patchName = patchInfo.Name.Replace(patchInfo.Extension, ""); var patchName = patchInfo.Name.Replace(patchInfo.Extension, "");
var path = new DirectoryInfo(Path.Join(SPTinstaller.targetPath, patchName)); var path = new DirectoryInfo(Path.Join(targetPath, patchName));
if (path.Exists) if (path.Exists)
{ {
dir = path; dir = path;

View File

@ -1,23 +0,0 @@
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.IO;
namespace SPT_AKI_Installer.Aki.Helper
{
public static class GameHelper
{
private const string registryInstall = @"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\EscapeFromTarkov";
public static string DetectOriginalGamePath()
{
// We can't detect the installed path on non-Windows
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return null;
var uninstallStringValue = Registry.LocalMachine.OpenSubKey(registryInstall, false)
?.GetValue("UninstallString");
var info = (uninstallStringValue is string key) ? new FileInfo(key) : null;
return info?.DirectoryName;
}
}
}

View File

@ -12,7 +12,7 @@ namespace SPT_AKI_Installer.Aki.Helper
/// <summary> /// <summary>
/// Outputs a string to console starting with [USER] with /// Outputs a string to console starting with [USER] with
/// a Green background and Black foreground /// Green text
/// </summary> /// </summary>
public static void User(string text) public static void User(string text)
{ {
@ -21,7 +21,7 @@ namespace SPT_AKI_Installer.Aki.Helper
/// <summary> /// <summary>
/// Outputs a string to console starting with [WARNING] with /// Outputs a string to console starting with [WARNING] with
/// a Yellow background and Black foreground /// Yellow text
/// </summary> /// </summary>
public static void Warning(string text) public static void Warning(string text)
{ {
@ -30,7 +30,7 @@ namespace SPT_AKI_Installer.Aki.Helper
/// <summary> /// <summary>
/// Outputs a string to console starting with [ERROR] with /// Outputs a string to console starting with [ERROR] with
/// a Red background and Black foreground /// Red text
/// </summary> /// </summary>
public static void Error(string text) public static void Error(string text)
{ {
@ -39,7 +39,7 @@ namespace SPT_AKI_Installer.Aki.Helper
/// <summary> /// <summary>
/// Outputs a string to console starting with [INFO] with /// Outputs a string to console starting with [INFO] with
/// a DarkGray background and White foreground /// Blue text
/// </summary> /// </summary>
public static void Info(string text) public static void Info(string text)
{ {

View File

@ -0,0 +1,91 @@
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.IO;
using System;
using System.Diagnostics;
namespace SPT_AKI_Installer.Aki.Helper
{
public class PreCheckHelper
{
private const string registryInstall = @"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\EscapeFromTarkov";
/// <summary>
/// gets the original EFT game path
/// </summary>
/// <returns>Path or null</returns>
public string DetectOriginalGamePath()
{
// We can't detect the installed path on non-Windows
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return null;
var uninstallStringValue = Registry.LocalMachine.OpenSubKey(registryInstall, false)
?.GetValue("UninstallString");
var info = (uninstallStringValue is string key) ? new FileInfo(key) : null;
return info?.DirectoryName;
}
/// <summary>
/// checks path is not null, out = gamePath
/// </summary>
/// <param name="gamePath"></param>
public void GameCheck(out string gamePath)
{
string Path = 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 version of EFT installed, Then checks that matches the Zip, out = patch version number 0.12.12.*here*
/// </summary>
/// <param name="gamePath"></param>
/// <param name="targetPath"></param>
/// <param name="patchRef"></param>
/// <returns>bool</returns>
public bool PatcherCheck(string gamePath,string targetPath, out string patchRef)
{
StringHelper stringHelper = new StringHelper();
FileVersionInfo version = FileVersionInfo.GetVersionInfo(Path.Join(gamePath + "/EscapeFromTarkov.exe"));
string versionCheck = stringHelper.Splitter(version.ProductVersion, '-', '.', 2);
LogHelper.Info($"GAME VERSION IS: {version.ProductVersion}");
string patcherRef = FileHelper.FindFile(targetPath, versionCheck);
if (patcherRef != null)
{
patchRef = patcherRef;
return true;
}
patchRef = null;
return false;
}
/// <summary>
/// Checks Aki Zip is 2.3.1 currently
/// </summary>
/// <param name="targetPath"></param>
/// <param name="akiRef"></param>
/// <returns>bool</returns>
public bool AkiCheck(string targetPath,out string akiRef)
{
string aki = FileHelper.FindFile(targetPath, "2.3.1");
if (aki != null)
{
akiRef = aki;
return true;
}
akiRef = null;
return false;
}
}
}

View File

@ -1,10 +1,4 @@
using System; using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Diagnostics;
namespace SPT_AKI_Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace SPT_AKI_Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {
internal class StatusHelper public class StatusHelper
{ {
} }
} }

View File

@ -1,6 +1,6 @@
namespace SPT_AKI_Installer.Aki.Helper namespace SPT_AKI_Installer.Aki.Helper
{ {
public static class StringHelper public class StringHelper
{ {
/// <summary> /// <summary>
/// string to split, changes oldChar to newChar /// string to split, changes oldChar to newChar
@ -10,7 +10,7 @@
/// <param name="newChar"></param> /// <param name="newChar"></param>
/// <param name="amount"></param> /// <param name="amount"></param>
/// <returns>returns the string at a position using amount</returns> /// <returns>returns the string at a position using amount</returns>
public static string Splitter(string toSplit, char oldChar, char newChar, int amount) public string Splitter(string toSplit, char oldChar, char newChar, int amount)
{ {
return toSplit.Replace(oldChar, newChar).Split(newChar)[^amount]; return toSplit.Replace(oldChar, newChar).Split(newChar)[^amount];
} }