85 lines
2.7 KiB
C#
Raw Normal View History

2022-07-09 00:33:55 -04:00
using Gitea.Api;
using Gitea.Client;
2023-05-11 23:11:39 -04:00
using SPTInstaller.Interfaces;
using SPTInstaller.Models;
2022-07-09 00:33:55 -04:00
using System.Threading.Tasks;
using SPTInstaller.Helpers;
2022-07-09 00:33:55 -04:00
namespace SPTInstaller.Installer_Tasks;
public class ReleaseCheckTask : InstallerTaskBase
2022-07-09 00:33:55 -04:00
{
private InternalData _data;
2022-07-09 00:33:55 -04:00
public ReleaseCheckTask(InternalData data) : base("Release Checks")
{
_data = data;
}
2022-07-09 00:33:55 -04:00
public override async Task<IResult> TaskOperation()
{
try
2022-07-09 00:33:55 -04:00
{
var repo = new RepositoryApi(Configuration.Default);
2022-07-09 00:33:55 -04:00
SetStatus("Checking SPT Releases", "", null, ProgressStyle.Indeterminate);
2022-07-09 00:33:55 -04:00
var akiRepoReleases = await repo.RepoListReleasesAsync("SPT-AKI", "Stable-releases");
2022-07-09 00:33:55 -04:00
SetStatus("Checking for Patches", "", null, ProgressStyle.Indeterminate);
2022-07-09 00:33:55 -04:00
var patchRepoReleases = await repo.RepoListReleasesAsync("SPT-AKI", "Downgrade-Patches");
2022-07-09 00:33:55 -04:00
var latestAkiRelease = akiRepoReleases.FindAll(x => !x.Prerelease)[0];
var latestAkiVersion = latestAkiRelease.Name.Replace('(', ' ').Replace(')', ' ').Split(' ')[3];
var comparePatchToAki = patchRepoReleases?.Find(x => x.Name.Contains(_data.OriginalGameVersion) && x.Name.Contains(latestAkiVersion));
2022-07-09 00:33:55 -04:00
_data.PatcherMirrorsLink = comparePatchToAki?.Assets[0].BrowserDownloadUrl;
_data.AkiReleaseDownloadLink = latestAkiRelease.Assets[0].BrowserDownloadUrl;
_data.AkiReleaseHash = FileHashHelper.GetGiteaReleaseHash(latestAkiRelease);
2022-07-09 00:33:55 -04:00
int IntAkiVersion = int.Parse(latestAkiVersion);
int IntGameVersion = int.Parse(_data.OriginalGameVersion);
bool patchNeedCheck = false;
2022-07-09 00:33:55 -04:00
if (IntGameVersion > IntAkiVersion)
{
patchNeedCheck = true;
}
2022-07-09 00:33:55 -04:00
if (IntGameVersion < IntAkiVersion)
{
return Result.FromError("Your client is outdated. Please update EFT");
2022-07-09 00:33:55 -04:00
}
2022-07-09 00:33:55 -04:00
if (IntGameVersion == IntAkiVersion)
{
patchNeedCheck = false;
}
2022-07-09 00:33:55 -04:00
if (comparePatchToAki == null && patchNeedCheck)
{
return Result.FromError("No patcher available for your version");
}
2022-07-09 00:33:55 -04:00
_data.PatchNeeded = patchNeedCheck;
2022-07-09 00:33:55 -04:00
string status = $"Current Release: {latestAkiVersion}";
2023-05-14 22:35:06 -04:00
if (_data.PatchNeeded)
2022-07-09 00:33:55 -04:00
{
status += " - Patch Available";
2022-07-09 00:33:55 -04:00
}
SetStatus(null, status);
return Result.FromSuccess(status);
}
catch (Exception ex)
{
//request failed
return Result.FromError($"Request Failed:\n{ex.Message}");
2022-07-09 00:33:55 -04:00
}
}
}