2024-04-27 14:51:54 -04:00
|
|
|
|
using SPTInstaller.Interfaces;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
using SPTInstaller.Models;
|
2022-07-09 00:33:55 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2023-07-12 09:19:33 +02:00
|
|
|
|
using SPTInstaller.Helpers;
|
2024-04-25 23:33:20 -07:00
|
|
|
|
using Newtonsoft.Json;
|
2024-04-27 14:51:54 -04:00
|
|
|
|
using SPTInstaller.Models.Mirrors;
|
2024-04-26 09:52:41 -07:00
|
|
|
|
using SPTInstaller.Models.ReleaseInfo;
|
2022-07-09 00:33:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
namespace SPTInstaller.Installer_Tasks;
|
|
|
|
|
|
|
|
|
|
public class ReleaseCheckTask : InstallerTaskBase
|
2022-07-09 00:33:55 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
private InternalData _data;
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public ReleaseCheckTask(InternalData data) : base("Release Checks")
|
|
|
|
|
{
|
|
|
|
|
_data = data;
|
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public override async Task<IResult> TaskOperation()
|
|
|
|
|
{
|
|
|
|
|
try
|
2022-07-09 00:33:55 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
SetStatus("Checking SPT Releases", "", null, ProgressStyle.Indeterminate);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-04-25 23:33:20 -07:00
|
|
|
|
var progress = new Progress<double>((d) => { SetStatus(null, null, (int)Math.Floor(d)); });
|
2024-05-21 23:07:51 +01:00
|
|
|
|
var SPTReleaseInfoFile =
|
2024-05-04 16:18:49 -04:00
|
|
|
|
await DownloadCacheHelper.GetOrDownloadFileAsync("release.json", DownloadCacheHelper.ReleaseMirrorUrl,
|
|
|
|
|
progress, DownloadCacheHelper.SuggestedTtl);
|
|
|
|
|
|
2024-05-21 23:07:51 +01:00
|
|
|
|
if (SPTReleaseInfoFile == null)
|
2024-04-25 23:33:20 -07:00
|
|
|
|
{
|
|
|
|
|
return Result.FromError("Failed to download release metadata");
|
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-05-21 23:07:51 +01:00
|
|
|
|
var SPTReleaseInfo =
|
|
|
|
|
JsonConvert.DeserializeObject<ReleaseInfo>(File.ReadAllText(SPTReleaseInfoFile.FullName));
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
SetStatus("Checking for Patches", "", null, ProgressStyle.Indeterminate);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-05-21 23:07:51 +01:00
|
|
|
|
var SPTPatchMirrorsFile =
|
2024-05-04 16:18:49 -04:00
|
|
|
|
await DownloadCacheHelper.GetOrDownloadFileAsync("mirrors.json", DownloadCacheHelper.PatchMirrorUrl,
|
|
|
|
|
progress, DownloadCacheHelper.SuggestedTtl);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-05-21 23:07:51 +01:00
|
|
|
|
if (SPTPatchMirrorsFile == null)
|
2023-07-12 09:19:33 +02:00
|
|
|
|
{
|
2024-04-27 14:51:54 -04:00
|
|
|
|
return Result.FromError("Failed to download patch mirror data");
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|
2024-04-27 14:51:54 -04:00
|
|
|
|
|
2024-05-01 10:31:55 -04:00
|
|
|
|
var patchMirrorInfo =
|
2024-05-21 23:07:51 +01:00
|
|
|
|
JsonConvert.DeserializeObject<PatchInfo>(File.ReadAllText(SPTPatchMirrorsFile.FullName));
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-05-21 23:07:51 +01:00
|
|
|
|
if (SPTReleaseInfo == null || patchMirrorInfo == null)
|
2024-04-27 14:51:54 -04:00
|
|
|
|
{
|
2024-05-21 23:07:51 +01:00
|
|
|
|
return Result.FromError("An error occurred while deserializing SPT or patch data");
|
2024-04-27 14:51:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-21 23:07:51 +01:00
|
|
|
|
_data.ReleaseInfo = SPTReleaseInfo;
|
2024-04-27 14:51:54 -04:00
|
|
|
|
_data.PatchInfo = patchMirrorInfo;
|
2024-05-21 23:07:51 +01:00
|
|
|
|
int intSPTVersion = int.Parse(SPTReleaseInfo.ClientVersion);
|
2024-04-27 14:51:54 -04:00
|
|
|
|
int intGameVersion = int.Parse(_data.OriginalGameVersion);
|
|
|
|
|
|
2024-05-21 23:07:51 +01:00
|
|
|
|
// note: it's possible the game version could be lower than the SPT version and still need a patch if the major version numbers change
|
2024-04-27 14:51:54 -04:00
|
|
|
|
// : it's probably a low chance though
|
2024-05-21 23:07:51 +01:00
|
|
|
|
bool patchNeedCheck = intGameVersion > intSPTVersion;
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-05-21 23:07:51 +01:00
|
|
|
|
if (intGameVersion < intSPTVersion)
|
2023-07-12 09:19:33 +02:00
|
|
|
|
{
|
2024-06-09 17:15:47 +01:00
|
|
|
|
return Result.FromError("Your live EFT is out of date. Please update it using the BSG Launcher then run the SPT Installer again");
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-05-21 23:07:51 +01:00
|
|
|
|
if (intGameVersion == intSPTVersion)
|
2023-07-12 09:19:33 +02:00
|
|
|
|
{
|
|
|
|
|
patchNeedCheck = false;
|
|
|
|
|
}
|
2024-06-09 17:15:47 +01:00
|
|
|
|
|
|
|
|
|
bool sptClientIsOutdated = intSPTVersion != patchMirrorInfo.TargetClientVersion && patchNeedCheck;
|
|
|
|
|
bool liveClientIsOutdated = intGameVersion != patchMirrorInfo.SourceClientVersion && patchNeedCheck;
|
|
|
|
|
|
|
|
|
|
if (liveClientIsOutdated)
|
|
|
|
|
{
|
|
|
|
|
return Result.FromError("Your live EFT is out of date. Please update it using the BSG Launcher then run the SPT Installer again");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sptClientIsOutdated)
|
2023-07-12 09:19:33 +02:00
|
|
|
|
{
|
2024-05-01 10:31:55 -04:00
|
|
|
|
return Result.FromError(
|
2024-06-09 17:15:47 +01:00
|
|
|
|
"Could not find a downgrade patcher for the version of EFT you have installed." +
|
2024-05-25 17:34:36 +01:00
|
|
|
|
"\nThis can happen due to one of the following reasons:" +
|
|
|
|
|
"\n* Live EFT just updated. The SPT team will create a new patcher within 24 hours, hold tight!" +
|
2024-06-09 17:15:47 +01:00
|
|
|
|
"\n* Live EFT just updated. You have not installed it on your computer using the BSG launcher");
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
_data.PatchNeeded = patchNeedCheck;
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
|
|
|
|
string status =
|
2024-05-21 23:07:51 +01:00
|
|
|
|
$"Current Release: {SPTReleaseInfo.ClientVersion} - {(_data.PatchNeeded ? "Patch Available" : "No Patch Needed")}";
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
SetStatus(null, status);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|