85 lines
2.5 KiB
C#
Raw Normal View History

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;
using SPTInstaller.Helpers;
2022-07-09 00:33:55 -04:00
namespace SPTInstaller.Installer_Tasks;
2022-07-09 13:08:41 -04:00
public class SetupClientTask : InstallerTaskBase
{
private InternalData _data;
2022-07-09 13:08:41 -04:00
public SetupClientTask(InternalData data) : base("Setup Client")
{
_data = data;
}
2022-07-09 13:08:41 -04:00
public override async Task<IResult> TaskOperation()
{
var targetInstallDirInfo = new DirectoryInfo(_data.TargetInstallPath);
2023-05-11 23:11:39 -04:00
var patcherOutputDir = new DirectoryInfo(Path.Join(_data.TargetInstallPath, "patcher"));
2023-05-11 23:11:39 -04:00
var patcherEXE = new FileInfo(Path.Join(_data.TargetInstallPath, "patcher.exe"));
2022-07-09 13:08:41 -04:00
var progress = new Progress<double>((d) => { SetStatus(null, null, (int)Math.Floor(d)); });
2022-07-09 13:08:41 -04:00
if (_data.PatchNeeded)
{
// extract patcher files
SetStatus("Extrating Patcher", "", 0);
2022-07-09 13:08:41 -04:00
var extractPatcherResult = ZipHelper.Decompress(_data.PatcherZipInfo, patcherOutputDir, progress);
2022-07-09 13:08:41 -04:00
if (!extractPatcherResult.Succeeded)
{
return extractPatcherResult;
}
// copy patcher files to install directory
SetStatus("Copying Patcher", "", 0);
var patcherDirInfo = patcherOutputDir.GetDirectories("Patcher*", SearchOption.TopDirectoryOnly).First();
var copyPatcherResult = FileHelper.CopyDirectoryWithProgress(patcherDirInfo, targetInstallDirInfo, progress);
if (!copyPatcherResult.Succeeded)
{
return copyPatcherResult;
2022-07-09 13:08:41 -04:00
}
// run patcher
SetStatus("Running Patcher", "", null, ProgressStyle.Indeterminate);
2022-07-09 13:08:41 -04:00
var patchingResult = ProcessHelper.PatchClientFiles(patcherEXE, targetInstallDirInfo);
2022-07-09 13:08:41 -04:00
if (!patchingResult.Succeeded)
2022-07-09 13:08:41 -04:00
{
return patchingResult;
2022-07-09 13:08:41 -04:00
}
}
2022-07-09 13:08:41 -04:00
// extract release files
SetStatus("Extracting Release", "", 0);
2022-07-09 13:08:41 -04:00
var extractReleaseResult = ZipHelper.Decompress(_data.AkiZipInfo, targetInstallDirInfo, progress);
2022-07-09 13:08:41 -04:00
if (!extractReleaseResult.Succeeded)
{
return extractReleaseResult;
}
// cleanup temp files
SetStatus("Cleanup", "almost done :)", null, ProgressStyle.Indeterminate);
if(_data.PatchNeeded)
{
patcherOutputDir.Delete(true);
patcherEXE.Delete();
2022-07-09 00:33:55 -04:00
}
return Result.FromSuccess("SPT is Setup. Happy Playing!");
2022-07-09 00:33:55 -04:00
}
}