2023-07-12 09:19:33 +02: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.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-07-12 09:19:33 +02:00
|
|
|
|
using SPTInstaller.Helpers;
|
2022-07-09 00:33:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
namespace SPTInstaller.Installer_Tasks;
|
2022-07-09 13:08:41 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public class SetupClientTask : InstallerTaskBase
|
|
|
|
|
{
|
|
|
|
|
private InternalData _data;
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public SetupClientTask(InternalData data) : base("Setup Client")
|
|
|
|
|
{
|
|
|
|
|
_data = data;
|
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public override async Task<IResult> TaskOperation()
|
|
|
|
|
{
|
|
|
|
|
var targetInstallDirInfo = new DirectoryInfo(_data.TargetInstallPath);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
var patcherOutputDir = new DirectoryInfo(Path.Join(_data.TargetInstallPath, "patcher"));
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
var patcherEXE = new FileInfo(Path.Join(_data.TargetInstallPath, "patcher.exe"));
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
var progress = new Progress<double>((d) => { SetStatus(null, null, (int)Math.Floor(d)); });
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-03-25 14:28:34 -04:00
|
|
|
|
SetStatus("Preparing 7z", "", null, ProgressStyle.Indeterminate);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-03-25 14:28:34 -04:00
|
|
|
|
if (!FileHelper.StreamAssemblyResourceOut("7z.dll", Path.Join(DownloadCacheHelper.CachePath, "7z.dll")))
|
|
|
|
|
{
|
|
|
|
|
return Result.FromError("Failed to prepare 7z");
|
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
if (_data.PatchNeeded)
|
|
|
|
|
{
|
|
|
|
|
// extract patcher files
|
2024-05-17 07:57:00 +02:00
|
|
|
|
SetStatus("Extracting Patcher", "", 0);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
var extractPatcherResult = ZipHelper.Decompress(_data.PatcherZipInfo, patcherOutputDir, progress);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
if (!extractPatcherResult.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
return extractPatcherResult;
|
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
// copy patcher files to install directory
|
|
|
|
|
SetStatus("Copying Patcher", "", 0);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
var patcherDirInfo = patcherOutputDir.GetDirectories("Patcher*", SearchOption.TopDirectoryOnly).First();
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
|
|
|
|
var copyPatcherResult =
|
|
|
|
|
FileHelper.CopyDirectoryWithProgress(patcherDirInfo, targetInstallDirInfo, progress);
|
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
if (!copyPatcherResult.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
return copyPatcherResult;
|
2022-07-09 13:08:41 -04:00
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
// run patcher
|
|
|
|
|
SetStatus("Running Patcher", "", null, ProgressStyle.Indeterminate);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
var patchingResult = ProcessHelper.PatchClientFiles(patcherEXE, targetInstallDirInfo);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
if (!patchingResult.Succeeded)
|
2022-07-09 13:08:41 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
return patchingResult;
|
2022-07-09 13:08:41 -04:00
|
|
|
|
}
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
// extract release files
|
|
|
|
|
SetStatus("Extracting Release", "", 0);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2024-05-21 23:07:51 +01:00
|
|
|
|
var extractReleaseResult = ZipHelper.Decompress(_data.SPTZipInfo, targetInstallDirInfo, progress);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
if (!extractReleaseResult.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
return extractReleaseResult;
|
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
// cleanup temp files
|
|
|
|
|
SetStatus("Cleanup", "almost done :)", null, ProgressStyle.Indeterminate);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
|
|
|
|
if (_data.PatchNeeded)
|
2023-07-12 09:19:33 +02:00
|
|
|
|
{
|
|
|
|
|
patcherOutputDir.Delete(true);
|
|
|
|
|
patcherEXE.Delete();
|
2022-07-09 00:33:55 -04:00
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
return Result.FromSuccess("SPT is Setup. Happy Playing!");
|
2022-07-09 00:33:55 -04:00
|
|
|
|
}
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|