Philipp Heenemann
a8b91f4ee6
Updated the existing C# code into a more modern, imperative and top-level statements style. This involves shortening the code by removing unnecessary parts like additional brackets and explicit namespace declarations. It's done to improve clarity and readability.
60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using System.Diagnostics;
|
|
using SPTInstaller.Models;
|
|
|
|
namespace SPTInstaller.Helpers;
|
|
|
|
public enum PatcherExitCode
|
|
{
|
|
ProgramClosed = 0,
|
|
Success = 10,
|
|
EftExeNotFound = 11,
|
|
NoPatchFolder = 12,
|
|
MissingFile = 13,
|
|
MissingDir = 14,
|
|
PatchFailed = 15
|
|
}
|
|
|
|
public static class ProcessHelper
|
|
{
|
|
public static Result PatchClientFiles(FileInfo executable, DirectoryInfo workingDir)
|
|
{
|
|
if (!executable.Exists || !workingDir.Exists)
|
|
{
|
|
return Result.FromError(
|
|
$"Could not find executable ({executable.Name}) or working directory ({workingDir.Name})");
|
|
}
|
|
|
|
var process = new Process();
|
|
process.StartInfo.FileName = executable.FullName;
|
|
process.StartInfo.WorkingDirectory = workingDir.FullName;
|
|
process.EnableRaisingEvents = true;
|
|
process.StartInfo.Arguments = "autoclose";
|
|
process.Start();
|
|
|
|
process.WaitForExit();
|
|
|
|
switch ((PatcherExitCode)process.ExitCode)
|
|
{
|
|
case PatcherExitCode.Success:
|
|
return Result.FromSuccess("Patcher Finished Successfully, extracting Aki");
|
|
|
|
case PatcherExitCode.ProgramClosed:
|
|
return Result.FromError("Patcher was closed before completing!");
|
|
|
|
case PatcherExitCode.EftExeNotFound:
|
|
return Result.FromError("EscapeFromTarkov.exe is missing from the install Path");
|
|
|
|
case PatcherExitCode.NoPatchFolder:
|
|
return Result.FromError("Patchers Folder called 'Aki_Patches' is missing");
|
|
|
|
case PatcherExitCode.MissingFile:
|
|
return Result.FromError("EFT files was missing a Vital file to continue");
|
|
|
|
case PatcherExitCode.PatchFailed:
|
|
return Result.FromError("A patch failed to apply");
|
|
|
|
default:
|
|
return Result.FromError("an unknown error occurred in the patcher");
|
|
}
|
|
}
|
|
} |