bump fully auto and downloads versions based on repos

This commit is contained in:
CWX 2022-06-06 15:55:46 +01:00
parent bcc1e6e9ec
commit 4c0ae768d2
8 changed files with 90 additions and 95 deletions

View File

@ -23,12 +23,12 @@ namespace SPT_AKI_Installer.Aki.Core
if (originalGamePath == null)
{
CloseApp("Unable to find EFT OG directory! \n please make sure EFT is installed! \n please also run EFT once!");
CloseApp("Unable to find EFT OG directory \n please make sure EFT is installed \n please also run EFT once");
}
if (originalGamePath == targetPath)
{
CloseApp("Installer is located in EFT's original directory! \n Please move the installer to a seperate folder as per the guide!");
CloseApp("Installer is located in EFT's original directory \n Please move the installer to a seperate folder as per the guide");
}
var checkForExistingFiles = FileHelper.FindFile(targetPath, "EscapeFromTarkov.exe");
@ -37,74 +37,40 @@ namespace SPT_AKI_Installer.Aki.Core
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");
}
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();
LogHelper.Info($"Your current game version: { PreCheckHelper.gameVersion }");
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();
}
LogHelper.Info("Checking releases for AKI and the Patcher");
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");
}
var check = DownloadHelper.ReleaseCheck();
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)
while (check.Status != System.Threading.Tasks.TaskStatus.RanToCompletion)
{
}
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 && string.Equals(DownloadHelper.patchNeedCheck, "true", StringComparison.OrdinalIgnoreCase))
if (patcherZipPath == null && DownloadHelper.patchNeedCheck)
{
LogHelper.Info("Unable to find Patcher Zip in Directory");
LogHelper.Info("Downloading Patcher Zip now!");
LogHelper.Info("No Patcher zip file present in directory, downloading...");
var task = DownloadHelper.DownloadFileAsync(targetPath, DownloadHelper.patcherLink, "/PATCHERZIP.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)
{
LogHelper.Info("Unable to find Aki Zip in Directory");
LogHelper.Info("Downloading Aki Zip now!");
LogHelper.Info("No AKI zip file present in directory, downloading...");
var task = DownloadHelper.DownloadFileAsync(targetPath, DownloadHelper.akiLink, "/AKIZIP.zip");
while (task.Status != System.Threading.Tasks.TaskStatus.RanToCompletion)
{
}
LogHelper.Info("Download Complete!");
}
LogHelper.Info("Ready to continue with installation");
PreCheckHelper.PatcherZipCheck(originalGamePath, targetPath, out patcherZipPath);
PreCheckHelper.AkiZipCheck(targetPath, out akiZipPath);
@ -112,25 +78,26 @@ namespace SPT_AKI_Installer.Aki.Core
LogHelper.Info("Copying game files");
GameCopy(originalGamePath, targetPath);
if (string.Equals(DownloadHelper.patchNeedCheck, "true", StringComparison.OrdinalIgnoreCase))
if (DownloadHelper.patchNeedCheck)
{
PatcherCopy(targetPath, patcherZipPath);
PatcherProcess(targetPath);
}
AkiInstall(targetPath, akiZipPath);
DeleteZip(patcherZipPath, akiZipPath, Path.Join(targetPath, "/ClientVersions.json"));
DeleteZip(patcherZipPath, akiZipPath);
}
static void GameCopy(string originalGamePath, string targetPath)
{
FileHelper.CopyDirectory(originalGamePath, targetPath, true);
LogHelper.Info("Game has been copied, Extracting patcher");
LogHelper.Info("Extracting patcher");
}
static void PatcherCopy(string targetPath, string patcherZipPath)
{
ZipHelper.Decompress(patcherZipPath, targetPath);
ZipHelper.ZipDecompress(patcherZipPath, targetPath);
FileHelper.FindFolder(patcherZipPath, targetPath, out DirectoryInfo dir);
FileHelper.CopyDirectory(dir.FullName, targetPath, true);
@ -148,7 +115,7 @@ namespace SPT_AKI_Installer.Aki.Core
static void PatcherProcess(string targetPath)
{
LogHelper.Info("patcher has been extracted, starting patcher");
LogHelper.Info("Starting patcher");
ProcessHelper patcherProcess = new();
patcherProcess.StartProcess(Path.Join(targetPath + "/patcher.exe"), targetPath);
@ -157,15 +124,14 @@ namespace SPT_AKI_Installer.Aki.Core
static void AkiInstall(string targetPath, string akiZipPath)
{
ZipHelper.Decompress(akiZipPath, targetPath);
ZipHelper.ZipDecompress(akiZipPath, targetPath);
LogHelper.Info("Aki has been extracted");
}
static void DeleteZip(string patcherZipPath, string akiZipPath, string versionJson)
static void DeleteZip(string patcherZipPath, string akiZipPath)
{
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!");

View File

@ -3,22 +3,19 @@ using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Gitea.Api;
using Gitea.Client;
using Gitea.Model;
using System.Collections.Generic;
namespace SPT_AKI_Installer.Aki.Helper
{
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 bool patchNeedCheck;
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())
@ -27,30 +24,58 @@ namespace SPT_AKI_Installer.Aki.Helper
}
}
public static void ReadJson(string targetPath)
public static async Task ReleaseCheck()
{
var json = FileHelper.FindFile(targetPath, "ClientVersions.json");
var text = File.ReadAllText(json);
dynamic result = JsonConvert.DeserializeObject<object>(text);
Configuration.Default.BasePath = "https://dev.sp-tarkov.com/api/v1";
objToFind = "client" + PreCheckHelper.gameVersion;
var repo = new RepositoryApi(Configuration.Default);
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)
try
{
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);
var patchRepoReleases = await repo.RepoListReleasesAsync("SPT-AKI", "Downgrade-Patches");
var akiRepoReleases = await repo.RepoListReleasesAsync("SPT-AKI", "Stable-releases");
var latestAkiRelease = akiRepoReleases.FindAll(x => !x.Prerelease)[0];
var latestAkiVersion = latestAkiRelease.Name.Replace('(', ' ').Replace(')', ' ').Split(' ')[3];
var comparePatchToAki = patchRepoReleases?.Find(x => x.Name.Contains(PreCheckHelper.gameVersion) && x.Name.Contains(latestAkiVersion));
patcherLink = comparePatchToAki?.Assets[0].BrowserDownloadUrl;
akiLink = latestAkiRelease.Assets[0].BrowserDownloadUrl;
int IntAkiVersion = int.Parse(latestAkiVersion);
int IntGameVersion = int.Parse(PreCheckHelper.gameVersion);
if (IntGameVersion > IntAkiVersion)
{
patchNeedCheck = true;
}
if (IntGameVersion < IntAkiVersion)
{
LogHelper.Info("Client is older than current Aki Version, Please update!");
LogHelper.Warning("Press enter to close the app!");
Console.ReadKey();
Environment.Exit(0);
}
if (IntGameVersion == IntAkiVersion)
{
patchNeedCheck = false;
}
if(comparePatchToAki == null && patchNeedCheck)
{
LogHelper.Warning("There is no current patcher for your client version and its needed");
LogHelper.Warning("Please try again later once a new patcher is uploaded.");
LogHelper.Warning("Press enter to close the app!");
Console.ReadKey();
Environment.Exit(0);
}
}
catch (Exception)
{
//request failed
LogHelper.Info("Request Failed");
}
}

View File

@ -50,7 +50,7 @@ namespace SPT_AKI_Installer.Aki.Helper
string[] filePaths = Directory.GetFiles(path);
foreach (string file in filePaths)
{
if (file.Contains(name))
if (file.Contains(name, StringComparison.OrdinalIgnoreCase))
{
return file;
}

View File

@ -9,6 +9,7 @@ namespace SPT_AKI_Installer.Aki.Helper
private Process _process;
private string _exeDir;
private string _workingDir;
private string response;
public void StartProcess(string exeDir, string workingDir)
{
@ -43,30 +44,25 @@ namespace SPT_AKI_Installer.Aki.Helper
{
case 0:
LogHelper.Warning("Patcher was closed before completing!");
LogHelper.Warning("If you need to start the patcher again, type RETRY");
LogHelper.Warning("If you want to close the installer, type CLOSE");
var response = Console.ReadLine();
LogHelper.Warning("If you need to start the patcher again, type retry");
LogHelper.Warning("If you want to close the installer, close the app.");
response = Console.ReadLine();
while (!string.Equals(response, "retry", StringComparison.OrdinalIgnoreCase) ||
!string.Equals(response, "close", StringComparison.OrdinalIgnoreCase))
while (!string.Equals(response, "retry", StringComparison.OrdinalIgnoreCase))
{
LogHelper.Warning("answer needs to be retry or close");
LogHelper.Warning("Try Again!");
LogHelper.Warning("Answer needs to be retry");
LogHelper.Warning("Try Again..");
response = Console.ReadLine();
}
if (string.Equals(response, "retry", StringComparison.OrdinalIgnoreCase))
{
StartProcess(_exeDir, _workingDir);
break;
}
if (string.Equals(response, "close", StringComparison.OrdinalIgnoreCase))
{
Environment.Exit(0);
break;
}
break;
case 10:
LogHelper.User("Patcher Finished Successfully, extracting Aki");
LogHelper.Info("Patcher Finished Successfully, extracting Aki");
break;
case 11:

View File

@ -8,7 +8,7 @@ namespace SPT_AKI_Installer.Aki.Helper
{
public static class ZipHelper
{
public static void Decompress(string ArchivePath, string OutputFolderPath)
public static void ZipDecompress(string ArchivePath, string OutputFolderPath)
{
AnsiConsole.Progress().Columns(
new PercentageColumn(),

View File

@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2022-05-30T12:11:30.6942032Z;True|2022-05-30T13:08:08.4269393+01:00;True|2022-05-17T01:06:33.6758525+01:00;True|2022-05-14T01:56:09.8410037+01:00;True|2022-05-14T00:54:24.0683990+01:00;True|2022-05-14T00:53:04.7105427+01:00;True|2022-05-14T00:51:00.6280767+01:00;True|2022-05-14T00:49:19.4630888+01:00;True|2022-05-14T00:47:59.2166156+01:00;</History>
<History>True|2022-06-06T14:07:18.8067168Z;True|2022-06-05T22:55:20.5192697+01:00;True|2022-05-30T13:11:30.6942032+01:00;True|2022-05-30T13:08:08.4269393+01:00;True|2022-05-17T01:06:33.6758525+01:00;True|2022-05-14T01:56:09.8410037+01:00;True|2022-05-14T00:54:24.0683990+01:00;True|2022-05-14T00:53:04.7105427+01:00;True|2022-05-14T00:51:00.6280767+01:00;True|2022-05-14T00:49:19.4630888+01:00;True|2022-05-14T00:47:59.2166156+01:00;</History>
</PropertyGroup>
</Project>

View File

@ -12,11 +12,19 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FubarCoder.RestSharp.Portable.Core" Version="4.0.8" />
<PackageReference Include="FubarCoder.RestSharp.Portable.HttpClient" Version="4.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="SharpCompress" Version="0.31.0" />
<PackageReference Include="Spectre.Console" Version="0.44.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="Gitea">
<HintPath>shared\Gitea.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Update="Aki.Asset\icon.ico">
<Pack>True</Pack>

BIN
shared/Gitea.dll Normal file

Binary file not shown.