From 1cb9f5e03db447a3e92618476d3e694efafafd4b Mon Sep 17 00:00:00 2001 From: CWX Date: Sat, 14 May 2022 12:19:40 +0100 Subject: [PATCH] Bump, Made ProcessHelper, PreCheckHelper, StringHelper non static, moved out methods to PreCheckHelper from Main, hopefully cleaned up Program.cs --- Aki.Core/Program.cs | 122 ++++++++++++++--------------------- Aki.Helper/FileHelper.cs | 7 +- Aki.Helper/GameHelper.cs | 23 ------- Aki.Helper/LogHelper.cs | 8 +-- Aki.Helper/PreCheckHelper.cs | 91 ++++++++++++++++++++++++++ Aki.Helper/ProcessHelper.cs | 8 +-- Aki.Helper/StatusHelper.cs | 6 +- Aki.Helper/StringHelper.cs | 4 +- 8 files changed, 154 insertions(+), 115 deletions(-) delete mode 100644 Aki.Helper/GameHelper.cs create mode 100644 Aki.Helper/PreCheckHelper.cs diff --git a/Aki.Core/Program.cs b/Aki.Core/Program.cs index 8316dfe..101e465 100644 --- a/Aki.Core/Program.cs +++ b/Aki.Core/Program.cs @@ -10,26 +10,28 @@ namespace SPT_AKI_Installer.Aki.Core //TODO: // delete patcher zip and aki zip // progress for copyDirectory - // move Game/patcher/aki check methods out of core // add figlet for SPT-AKI INSTALLER // 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 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) { + string targetPath = Environment.CurrentDirectory; + PreCheckHelper preCheckHelper = new(); #if DEBUG targetPath = @"D:\install"; #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}"); } @@ -41,7 +43,7 @@ namespace SPT_AKI_Installer.Aki.Core Environment.Exit(0); } - if (AkiCheck(out akiRef)) + if (preCheckHelper.AkiCheck(targetPath,out string 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!"); Console.ReadKey(); - // copies and pastes EFT to AKI installer test folder + GameCopy(gamePath, targetPath, akiRef); + } + + /// + /// copies and pastes EFT to AKI installer test folder + /// + /// + /// + static void GameCopy(string gamePath, string targetPath, string akiRef) + { #if !DEBUG FileHelper.CopyDirectory(gamePath, targetPath, true); +#endif LogHelper.User("GAME HAS BEEN COPIED, PRESS ENTER TO EXTRACT PATCHER!"); Console.ReadKey(); -#endif - // extracts patcher and moves out inner folders + PatcherCopy(gamePath, targetPath, akiRef); + } + + /// + /// extracts patcher and moves out inner folders + /// + /// + /// + /// + static void PatcherCopy(string patchRef, string targetPath, string akiRef) + { +#if !DEBUG ZipHelper.Decompress(patchRef, targetPath); - FileHelper.FindFolder(patchRef, out dir); + FileHelper.FindFolder(patchRef, targetPath, out DirectoryInfo dir); FileHelper.CopyDirectory(dir.FullName, targetPath, true); if (dir.Exists) { @@ -78,11 +100,22 @@ namespace SPT_AKI_Installer.Aki.Core LogHelper.Error($"please delete folder called {dir.FullName}"); } } +#endif + PatcherProcessStart(targetPath, akiRef); + } - // starts patcher and checks for user input to exit patcher and proceed + /// + /// starts patcher and checks for user input to exit patcher and proceed + /// + /// + /// + static void PatcherProcessStart(string targetPath, string akiRef) + { +#if !DEBUG LogHelper.Info("PATCHER HAS BEEN EXTRACTED, STARTING PATCHER!"); ProcessHelper patcherProcess = new(); patcherProcess.StartProcess(Path.Join(targetPath + "/patcher.exe"), targetPath); +#endif LogHelper.User("PATCHER HAS BEEN STARTED, TYPE YES ONCE THE PATCHER IS COMPLETE!"); 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 (string.Equals(complete, "yes", StringComparison.OrdinalIgnoreCase)) { +#if !DEBUG patcherProcess.EndProcess(); Thread.Sleep(1000); FileHelper.DeleteFile("file", targetPath + "/patcher.exe"); 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.User("PRESS ENTER TO CLOSE THE APP"); Console.ReadKey(); - } - } - - /// - /// checks the game is installed, out = game directory - /// - /// - 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; - } - - /// - /// checks for patcher zip path, out = patcher path - /// - /// - /// - /// bool - 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; - } - - /// - /// checks for aki zip path, out = aki path - /// - /// - /// bool - 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; } } } \ No newline at end of file diff --git a/Aki.Helper/FileHelper.cs b/Aki.Helper/FileHelper.cs index 3fc3c69..212182b 100644 --- a/Aki.Helper/FileHelper.cs +++ b/Aki.Helper/FileHelper.cs @@ -1,5 +1,4 @@ -using SPT_AKI_Installer.Aki.Core; -using System; +using System; using System.IO; namespace SPT_AKI_Installer.Aki.Helper @@ -84,11 +83,11 @@ namespace SPT_AKI_Installer.Aki.Helper /// /// /// - 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 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) { dir = path; diff --git a/Aki.Helper/GameHelper.cs b/Aki.Helper/GameHelper.cs deleted file mode 100644 index 3577eaf..0000000 --- a/Aki.Helper/GameHelper.cs +++ /dev/null @@ -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; - } - } -} diff --git a/Aki.Helper/LogHelper.cs b/Aki.Helper/LogHelper.cs index 767731f..7bf6bff 100644 --- a/Aki.Helper/LogHelper.cs +++ b/Aki.Helper/LogHelper.cs @@ -12,7 +12,7 @@ namespace SPT_AKI_Installer.Aki.Helper /// /// Outputs a string to console starting with [USER] with - /// a Green background and Black foreground + /// Green text /// public static void User(string text) { @@ -21,7 +21,7 @@ namespace SPT_AKI_Installer.Aki.Helper /// /// Outputs a string to console starting with [WARNING] with - /// a Yellow background and Black foreground + /// Yellow text /// public static void Warning(string text) { @@ -30,7 +30,7 @@ namespace SPT_AKI_Installer.Aki.Helper /// /// Outputs a string to console starting with [ERROR] with - /// a Red background and Black foreground + /// Red text /// public static void Error(string text) { @@ -39,7 +39,7 @@ namespace SPT_AKI_Installer.Aki.Helper /// /// Outputs a string to console starting with [INFO] with - /// a DarkGray background and White foreground + /// Blue text /// public static void Info(string text) { diff --git a/Aki.Helper/PreCheckHelper.cs b/Aki.Helper/PreCheckHelper.cs new file mode 100644 index 0000000..dff0f9a --- /dev/null +++ b/Aki.Helper/PreCheckHelper.cs @@ -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"; + + /// + /// gets the original EFT game path + /// + /// Path or null + 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; + } + + /// + /// checks path is not null, out = gamePath + /// + /// + 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; + } + + /// + /// Checks version of EFT installed, Then checks that matches the Zip, out = patch version number 0.12.12.*here* + /// + /// + /// + /// + /// bool + 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; + } + + /// + /// Checks Aki Zip is 2.3.1 currently + /// + /// + /// + /// bool + 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; + } + } +} diff --git a/Aki.Helper/ProcessHelper.cs b/Aki.Helper/ProcessHelper.cs index c145ca0..7a27993 100644 --- a/Aki.Helper/ProcessHelper.cs +++ b/Aki.Helper/ProcessHelper.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.IO; -using System.Diagnostics; +using System.Diagnostics; namespace SPT_AKI_Installer.Aki.Helper { diff --git a/Aki.Helper/StatusHelper.cs b/Aki.Helper/StatusHelper.cs index e93cdee..0ec6210 100644 --- a/Aki.Helper/StatusHelper.cs +++ b/Aki.Helper/StatusHelper.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace SPT_AKI_Installer.Aki.Helper { - internal class StatusHelper -{ -} + public class StatusHelper + { + } } diff --git a/Aki.Helper/StringHelper.cs b/Aki.Helper/StringHelper.cs index 8447c8a..d2f0873 100644 --- a/Aki.Helper/StringHelper.cs +++ b/Aki.Helper/StringHelper.cs @@ -1,6 +1,6 @@ namespace SPT_AKI_Installer.Aki.Helper { - public static class StringHelper + public class StringHelper { /// /// string to split, changes oldChar to newChar @@ -10,7 +10,7 @@ /// /// /// returns the string at a position using amount - 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]; }