diff --git a/Aki.Core/Program.cs b/Aki.Core/Program.cs index 88bb26f..f07cd1b 100644 --- a/Aki.Core/Program.cs +++ b/Aki.Core/Program.cs @@ -2,9 +2,7 @@ using SPT_AKI_Installer.Aki.Helper; using System; using System.IO; -using System.Net.Http; -using System.Threading.Tasks; -using Newtonsoft.Json; +using System.Threading; namespace SPT_AKI_Installer.Aki.Core { @@ -14,29 +12,20 @@ namespace SPT_AKI_Installer.Aki.Core public static class SPTinstaller { - private static string akiLink; - private static string patcherLink; static void Main() { string targetPath = Environment.CurrentDirectory; #if DEBUG targetPath = @"D:\install"; #endif - - _ = DownloadFileAsync(targetPath, "https://dev.sp-tarkov.com/api/v1/repos/CWX/Installer_Test/raw/ClientVersions.json", "/ClientVersions.json"); - Console.ReadKey(); - - ReadJson(targetPath); - Console.ReadKey(); - - _ = DownloadFileAsync(targetPath, akiLink, "/RELEASE-SPT-2.3.1-17349.zip"); - Console.ReadKey(); - - _ = DownloadFileAsync(targetPath, patcherLink, "/Patcher_12.12.15.18103_to_12.12.15.17349.zip"); - Console.ReadKey(); - SpectreHelper.Figlet("SPT-AKI INSTALLER", Color.Yellow); PreCheckHelper.GameCheck(out string originalGamePath); + PreCheckHelper.DetectOriginalGameVersion(originalGamePath); + + if (originalGamePath == null) + { + CloseApp("Unable to find EFT OG directory! \n please make sure EFT is installed! \n please also run EFT once!"); + } if (originalGamePath == targetPath) { @@ -44,42 +33,96 @@ namespace SPT_AKI_Installer.Aki.Core } var checkForExistingFiles = FileHelper.FindFile(targetPath, "EscapeFromTarkov.exe"); - //Console.WriteLine(checkForExistingFiles ?? "null"); if (checkForExistingFiles != null) { CloseApp("Installer is located in a Folder that has existing Game Files \n Please make sure the installer is in a fresh folder as per the guide"); } - //Console.ReadKey(); + + LogHelper.User("We need to download files during this installation."); + LogHelper.User("Are you ok with this? type yes or no"); + var userReponse = Console.ReadLine(); + + while (!string.Equals(userReponse, "yes", StringComparison.OrdinalIgnoreCase) && + !string.Equals(userReponse, "no", StringComparison.OrdinalIgnoreCase)) + { + LogHelper.Warning("Response was not yes or no, please respond with yes or no"); + userReponse = Console.ReadLine(); + } + + if (string.Equals(userReponse, "no", StringComparison.OrdinalIgnoreCase)) + { + CloseApp("you selected no, we need to download this to continue with auto installation \n Press enter to close the app"); + } + + LogHelper.Info("Downloading ClientVersions.json..."); + var jsonDownload = DownloadHelper.DownloadFileAsync(targetPath, "https://dev.sp-tarkov.com/api/v1/repos/CWX/Installer_Test/raw/ClientVersions.json", "/ClientVersions.json"); + while (jsonDownload.Status != System.Threading.Tasks.TaskStatus.RanToCompletion) + { + } + //Thread.Sleep(3000); + LogHelper.Info("Downloading Complete, Checking Versions!"); + DownloadHelper.ReadJson(targetPath); + + LogHelper.Info($"Original game path detected, Game version: { DownloadHelper.ogClient } Detected"); + LogHelper.Info($"TargetClient version for this Game version is: { DownloadHelper.targetClient }"); + if (string.Equals(DownloadHelper.patchNeedCheck, "true", StringComparison.OrdinalIgnoreCase)) + { + LogHelper.Info("Patching IS required!"); + } + + if (string.Equals(DownloadHelper.patchNeedCheck, "false", StringComparison.OrdinalIgnoreCase)) + { + LogHelper.Info("Patching is not required!"); + } + + LogHelper.Info($"TargetAki version for this GameVersion is { DownloadHelper.targetAki }"); + LogHelper.Info("Checking if Zips already exist in directory"); PreCheckHelper.PatcherZipCheck(originalGamePath, targetPath, out string patcherZipPath); PreCheckHelper.AkiZipCheck(targetPath, out string akiZipPath); - if (patcherZipPath == null && PreCheckHelper.PatcherNeededCheck()) + if (patcherZipPath == null && string.Equals(DownloadHelper.patchNeedCheck, "true", StringComparison.OrdinalIgnoreCase)) { - CloseApp("Game Version needs to be patched to match Aki Version \n but Patcher is missing or the wrong version \n Press enter to close the app"); + LogHelper.Info("Unable to find Patcher Zip in Directory"); + LogHelper.Info("Downloading Patcher Zip now!"); + var task = DownloadHelper.DownloadFileAsync(targetPath, DownloadHelper.patcherLink, "/PATCHER.zip"); + while(task.Status != System.Threading.Tasks.TaskStatus.RanToCompletion) + { + } + LogHelper.Info("Download Complete!"); + } + else if (string.Equals(DownloadHelper.patchNeedCheck, "false", StringComparison.OrdinalIgnoreCase)) + { + LogHelper.Info("Did not check for Patcher as its not needed"); } if (akiZipPath == null) { - CloseApp("Aki's Zip could not be found \n Press enter to close the app"); + LogHelper.Info("Unable to find Aki Zip in Directory"); + LogHelper.Info("Downloading Aki Zip now!"); + var task = DownloadHelper.DownloadFileAsync(targetPath, DownloadHelper.akiLink, "/AKI.zip"); + while (task.Status != System.Threading.Tasks.TaskStatus.RanToCompletion) + { + } + LogHelper.Info("Download Complete!"); } + LogHelper.Info("Ready to continue with installation"); + Console.ReadKey(); - if (PreCheckHelper.PatcherNeededCheck() && !PreCheckHelper.PatcherAkiCheck()) - { - CloseApp("Patcher does not match downgraded version that Aki Requires \n Press enter to close the app"); - } + PreCheckHelper.PatcherZipCheck(originalGamePath, targetPath, out patcherZipPath); + PreCheckHelper.AkiZipCheck(targetPath, out akiZipPath); LogHelper.Info("Copying game files"); GameCopy(originalGamePath, targetPath); - if (PreCheckHelper.PatcherNeededCheck()) + if (string.Equals(DownloadHelper.patchNeedCheck, "true", StringComparison.OrdinalIgnoreCase)) { PatcherCopy(targetPath, patcherZipPath); PatcherProcess(targetPath); } AkiInstall(targetPath, akiZipPath); - DeleteZip(patcherZipPath, akiZipPath); + DeleteZip(patcherZipPath, akiZipPath, Path.Join(targetPath, "/ClientVersions.json")); } static void GameCopy(string originalGamePath, string targetPath) @@ -121,10 +164,11 @@ namespace SPT_AKI_Installer.Aki.Core LogHelper.Info("Aki has been extracted"); } - static void DeleteZip(string patcherZipPath, string akiZipPath) + static void DeleteZip(string patcherZipPath, string akiZipPath, string versionJson) { FileHelper.DeleteFiles(patcherZipPath, false); FileHelper.DeleteFiles(akiZipPath, false); + FileHelper.DeleteFiles(versionJson, false); LogHelper.User("Removed Zips, Press enter to close the installer, you can then delete the installer"); LogHelper.User("ENJOY SPT-AKI!"); @@ -138,37 +182,5 @@ namespace SPT_AKI_Installer.Aki.Core Console.ReadKey(); Environment.Exit(0); } - - // https://dev.sp-tarkov.com/api/v1/repos/CWX/Installer_Test/raw/ClientVersions.json - // https://dev.sp-tarkov.com/CWX/Installer_Test/src/branch/master/ClientVersions.json - - static async Task DownloadFileAsync(string targetFilePath, string targetLink, string newFileName) - { - using (var httpClient = new HttpClient()) - { - await httpClient.DownloadFile(targetLink, Path.Join(targetFilePath, newFileName)); - } - } - - static void ReadJson(string targetPath) - { - var json = FileHelper.FindFile(targetPath, "ClientVersions.json"); - var text = File.ReadAllText(json); - dynamic result = JsonConvert.DeserializeObject(text); - akiLink = result.client18103.AKI; - patcherLink = result.client18103.PATCHER; - Console.WriteLine(akiLink); - Console.WriteLine(patcherLink); - } - - public static async Task DownloadFile(this HttpClient client, string address, string fileName) - { - using (var response = await client.GetAsync(address)) - using (var stream = await response.Content.ReadAsStreamAsync()) - using (var file = File.OpenWrite(fileName)) - { - stream.CopyTo(file); - } - } } } \ No newline at end of file diff --git a/Aki.Helper/DownloadHelper.cs b/Aki.Helper/DownloadHelper.cs index 1d0bb7a..dd3463b 100644 --- a/Aki.Helper/DownloadHelper.cs +++ b/Aki.Helper/DownloadHelper.cs @@ -1,12 +1,67 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using Newtonsoft.Json; +using System; +using System.IO; +using System.Net.Http; using System.Threading.Tasks; namespace SPT_AKI_Installer.Aki.Helper { - public class DownloadHelper + public static class DownloadHelper { + public static string objToFind; + public static string patchNeedCheck; + public static string ogClient; + public static string targetClient; + public static string targetAki; + public static string akiLink; + public static string patcherLink; + + // https://dev.sp-tarkov.com/api/v1/repos/CWX/Installer_Test/raw/ClientVersions.json + // https://dev.sp-tarkov.com/CWX/Installer_Test/src/branch/master/ClientVersions.json + + public static async Task DownloadFileAsync(string targetFilePath, string targetLink, string newFileName) + { + using (var httpClient = new HttpClient()) + { + await httpClient.DownloadFile(targetLink, Path.Join(targetFilePath, newFileName)); + } + } + + public static void ReadJson(string targetPath) + { + var json = FileHelper.FindFile(targetPath, "ClientVersions.json"); + var text = File.ReadAllText(json); + dynamic result = JsonConvert.DeserializeObject(text); + + objToFind = "client" + PreCheckHelper.gameVersion; + + patchNeedCheck = result[objToFind]?.PATCHNEEDED; + ogClient = result[objToFind]?.OGCLIENT; + targetClient = result[objToFind]?.TARGETCLIENT; + targetAki = result[objToFind]?.TARGETAKI; + akiLink = result[objToFind]?.AKIDOWNLOAD; + patcherLink = result[objToFind]?.PATCHERDOWNLOAD; + + if (result[objToFind] == null) + { + LogHelper.Warning("No records found for client version"); + LogHelper.Warning("this could be because your client is a version before this installer was made or"); + LogHelper.Warning("a new client version has come out, if this is the case, please update to latest or try again later"); + LogHelper.Warning("as we need to update the available list of clients."); + LogHelper.Warning("Press enter to close the app!"); + Console.ReadKey(); + Environment.Exit(0); + } + } + + public static async Task DownloadFile(this HttpClient client, string address, string fileName) + { + using (var response = await client.GetAsync(address)) + using (var stream = await response.Content.ReadAsStreamAsync()) + using (var file = File.OpenWrite(fileName)) + { + stream.CopyTo(file); + } + } } } diff --git a/Aki.Helper/FileHelper.cs b/Aki.Helper/FileHelper.cs index d4caeec..8d28664 100644 --- a/Aki.Helper/FileHelper.cs +++ b/Aki.Helper/FileHelper.cs @@ -74,9 +74,16 @@ namespace SPT_AKI_Installer.Aki.Helper 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(targetPath, patchName)); + var dirInfo = new DirectoryInfo(targetPath).GetDirectories(); + string patchInner = null; + foreach (var file in dirInfo) + { + if (file.FullName.Contains("patcher", StringComparison.OrdinalIgnoreCase)) + { + patchInner = file.FullName; + } + } + var path = new DirectoryInfo(patchInner); if (path.Exists) { dir = path; diff --git a/Aki.Helper/PreCheckHelper.cs b/Aki.Helper/PreCheckHelper.cs index 30f461d..b3b3e19 100644 --- a/Aki.Helper/PreCheckHelper.cs +++ b/Aki.Helper/PreCheckHelper.cs @@ -9,11 +9,10 @@ namespace SPT_AKI_Installer.Aki.Helper public static class PreCheckHelper { private const string registryInstall = @"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\EscapeFromTarkov"; - private static string gameVersion; + private static string OGGamePath; + public static string gameVersion; private static string patchZip; - private static string patchToVersion; private static string akiZip; - private static string akiVersion; public static string DetectOriginalGamePath() { @@ -24,7 +23,9 @@ namespace SPT_AKI_Installer.Aki.Helper var uninstallStringValue = Registry.LocalMachine.OpenSubKey(registryInstall, false) ?.GetValue("UninstallString"); var info = (uninstallStringValue is string key) ? new FileInfo(key) : null; - return info?.DirectoryName; + OGGamePath = info?.DirectoryName; + + return OGGamePath; } public static void GameCheck(out string gamePath) @@ -41,12 +42,19 @@ namespace SPT_AKI_Installer.Aki.Helper gamePath = Path; } + public static void DetectOriginalGameVersion(string gamePath) + { + gameVersion = FileVersionInfo.GetVersionInfo(Path.Join(gamePath + "/EscapeFromTarkov.exe")).ProductVersion.Replace('-', '.').Split('.')[^2]; + } + public static void PatcherZipCheck(string gamePath, string targetPath, out string patcherZipPath) { // example patch name - Patcher.12.12.15.17861.to.12.12.15.17349.zip - gameVersion = FileVersionInfo.GetVersionInfo(Path.Join(gamePath + "/EscapeFromTarkov.exe")).ProductVersion.Replace('-', '.').Split('.')[^2]; patchZip = FileHelper.FindFile(targetPath, gameVersion, "Patcher"); - patchToVersion = patchZip?.Split('.')[^2]; + if (patchZip == null) + { + patchZip = FileHelper.FindFile(targetPath, "PATCHER"); + } patcherZipPath = patchZip; } @@ -54,26 +62,11 @@ namespace SPT_AKI_Installer.Aki.Helper { // example aki name - RELEASE-SPT-2.3.1-17349.zip akiZip = FileHelper.FindFile(targetPath, "SPT", "RELEASE"); - akiVersion = akiZip?.Replace('-', '.').Split('.')[^2]; + if (akiZip == null) + { + akiZip = FileHelper.FindFile(targetPath, "AKI"); + } akiZipPath = akiZip; } - - /// - /// will return true if Patcher version at the end of the zip matches aki zip version - /// - /// bool - public static bool PatcherAkiCheck() - { - return patchToVersion == akiVersion; - } - - /// - /// will return true if game version is not equal to aki zip version (patcher is needed) - /// - /// bool - public static bool PatcherNeededCheck() - { - return gameVersion != akiVersion; - } } }