SPT-AKI-Installer/Aki.Core/Tasks/SetupClientTask.cs

89 lines
2.9 KiB
C#
Raw Normal View History

2022-07-09 00:33:55 -04:00
using SPT_AKI_Installer.Aki.Core.Model;
2022-07-09 13:08:41 -04:00
using SPT_AKI_Installer.Aki.Helper;
2022-07-09 00:33:55 -04:00
using System;
2022-07-09 13:08:41 -04:00
using System.IO;
2022-07-09 00:33:55 -04:00
using System.Linq;
using System.Threading.Tasks;
namespace SPT_AKI_Installer.Aki.Core.Tasks
{
public class SetupClientTask : LiveTableTask
{
private InternalData _data;
public SetupClientTask(InternalData data) : base("Setup Client", false)
{
_data = data;
}
public override async Task<GenericResult> RunAsync()
{
2022-07-09 13:08:41 -04:00
// extract patcher files
SetStatus("Extrating Patcher", false);
2022-07-09 00:33:55 -04:00
2022-07-09 13:08:41 -04:00
var extractPatcherProgress = new Progress<double>((d) => { Progress = (int)Math.Floor(d); });
var patcherOutputDir = new DirectoryInfo(Path.Join(_data.TargetInstallPath, "patcher"));
var extractPatcherResult = ZipHelper.Decompress(_data.PatcherZipInfo, patcherOutputDir, extractPatcherProgress);
2022-07-09 13:14:03 -04:00
if (!extractPatcherResult.Succeeded)
2022-07-09 13:08:41 -04:00
{
return extractPatcherResult;
}
// copy patcher files to install directory
SetStatus("Copying Patcher", false);
var patcherDirInfo = patcherOutputDir.GetDirectories("Patcher*", SearchOption.TopDirectoryOnly).First();
var targetInstallDirInfo = new DirectoryInfo(_data.TargetInstallPath);
var copyPatcherProgress = new Progress<double>((d) => { Progress = (int)Math.Floor(d); });
var copyPatcherResult = FileHelper.CopyDirectoryWithProgress(patcherDirInfo, targetInstallDirInfo, copyPatcherProgress);
2022-07-09 13:14:03 -04:00
if (!copyPatcherResult.Succeeded)
2022-07-09 13:08:41 -04:00
{
return copyPatcherResult;
}
// run patcher
SetStatus("Running Patcher");
StartDrawingIndeterminateProgress();
var patcherEXE = new FileInfo(Path.Join(_data.TargetInstallPath, "patcher.exe"));
var patchingResult = ProcessHelper.PatchClientFiles(patcherEXE, targetInstallDirInfo);
2022-07-09 13:14:03 -04:00
if (!patchingResult.Succeeded)
2022-07-09 13:08:41 -04:00
{
return patchingResult;
}
// extract release files
SetStatus("Extracting Release");
StartDrawingProgress();
var extractReleaseProgress = new Progress<double>((d) => { Progress = (int)Math.Floor(d); });
var extractReleaseResult = ZipHelper.Decompress(_data.AkiZipInfo, targetInstallDirInfo, extractReleaseProgress);
2022-07-09 13:14:03 -04:00
if (!extractReleaseResult.Succeeded)
2022-07-09 13:08:41 -04:00
{
return extractPatcherResult;
}
// cleanup temp files
SetStatus("Cleanup");
StartDrawingIndeterminateProgress();
patcherOutputDir.Delete(true);
_data.PatcherZipInfo.Delete();
_data.AkiZipInfo.Delete();
patcherEXE.Delete();
return GenericResult.FromSuccess("SPT is Setup. Happy Playing!");
2022-07-09 00:33:55 -04:00
}
}
}