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