0
0
mirror of https://github.com/sp-tarkov/patcher.git synced 2025-02-13 08:10:47 -05:00

add patch client exit codes and startup arg to auto-close

This commit is contained in:
IsWaffle 2022-05-15 17:36:16 -04:00
parent 334bc93ef7
commit 52b097c7f0
7 changed files with 70 additions and 17 deletions

View File

@ -17,9 +17,14 @@ namespace PatchClient
{ {
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{ {
bool autoClose = false;
if(desktop.Args != null && desktop.Args[0].ToLower() == "autoclose")
autoClose = true;
desktop.MainWindow = new MainWindow desktop.MainWindow = new MainWindow
{ {
DataContext = new MainWindowViewModel(), DataContext = new MainWindowViewModel(autoClose),
}; };
} }

View File

@ -18,11 +18,11 @@ namespace PatchClient.ViewModels
} }
}); });
public MainWindowViewModel() public MainWindowViewModel(bool autoClose)
{ {
this.WhenActivated((CompositeDisposable disposable) => this.WhenActivated((CompositeDisposable disposable) =>
{ {
Router.Navigate.Execute(new PatcherViewModel(this)); Router.Navigate.Execute(new PatcherViewModel(this, autoClose));
}); });
} }
} }

View File

@ -14,8 +14,8 @@ namespace PatchClient.ViewModels
{ {
public class PatcherViewModel : ViewModelBase public class PatcherViewModel : ViewModelBase
{ {
private bool initLineItemProgress = true; private bool _initLineItemProgress = true;
private bool _autoClose = false;
public ObservableCollection<LineItemProgress> LineItems { get; set; } = new ObservableCollection<LineItemProgress>(); public ObservableCollection<LineItemProgress> LineItems { get; set; } = new ObservableCollection<LineItemProgress>();
private string _ProgressMessage = ""; private string _ProgressMessage = "";
@ -40,13 +40,21 @@ namespace PatchClient.ViewModels
} }
public PatcherViewModel(IScreen Host) : base(Host) public PatcherViewModel(IScreen Host, bool autoClose) : base(Host)
{ {
_autoClose = autoClose;
this.WhenActivated((CompositeDisposable disposables) => this.WhenActivated((CompositeDisposable disposables) =>
{ {
//check if escapefromtarkov.exe is present //check if escapefromtarkov.exe is present
if(!File.Exists(Path.Join(Directory.GetCurrentDirectory(), "escapefromtarkov.exe"))) if(!File.Exists(Path.Join(Directory.GetCurrentDirectory(), "escapefromtarkov.exe")))
{ {
if (_autoClose)
{
Environment.Exit((int)PatcherExitCode.EftExeNotFound);
return;
}
NavigateTo(new MessageViewModel(HostScreen, "EscapeFromTarkov.exe was not found. Please ensure you have copied the patcher to your SPT folder.")); NavigateTo(new MessageViewModel(HostScreen, "EscapeFromTarkov.exe was not found. Please ensure you have copied the patcher to your SPT folder."));
return; return;
} }
@ -54,6 +62,12 @@ namespace PatchClient.ViewModels
//check if patch folder is present //check if patch folder is present
if(!Directory.Exists(LazyOperations.PatchFolder)) if(!Directory.Exists(LazyOperations.PatchFolder))
{ {
if (_autoClose)
{
Environment.Exit((int)PatcherExitCode.NoPatchFolder);
return;
}
NavigateTo(new MessageViewModel(HostScreen, $"{LazyOperations.PatchFolder} folder is missing. Please copy it to\n'{Environment.CurrentDirectory}'\nand try patching again.")); NavigateTo(new MessageViewModel(HostScreen, $"{LazyOperations.PatchFolder} folder is missing. Please copy it to\n'{Environment.CurrentDirectory}'\nand try patching again."));
return; return;
} }
@ -72,13 +86,18 @@ namespace PatchClient.ViewModels
patcher.ProgressChanged += patcher_ProgressChanged; patcher.ProgressChanged += patcher_ProgressChanged;
string message = patcher.ApplyPatches(); var patchMessage = patcher.ApplyPatches();
LazyOperations.CleanupTempDir(); LazyOperations.CleanupTempDir();
Directory.Delete(LazyOperations.PatchFolder, true); Directory.Delete(LazyOperations.PatchFolder, true);
await NavigateToWithDelay(new MessageViewModel(HostScreen, message), 400); if(_autoClose)
{
Environment.Exit((int)patchMessage.ExitCode);
}
await NavigateToWithDelay(new MessageViewModel(HostScreen, patchMessage.Message), 400);
}); });
} }
@ -89,7 +108,7 @@ namespace PatchClient.ViewModels
foreach (LineItem item in AdditionalLineItems) foreach (LineItem item in AdditionalLineItems)
{ {
if (initLineItemProgress) if (_initLineItemProgress)
{ {
LineItems.Add(new LineItemProgress(item)); LineItems.Add(new LineItemProgress(item));
} }
@ -97,7 +116,7 @@ namespace PatchClient.ViewModels
LineItems.FirstOrDefault(x => x.Info == item.ItemText).UpdateProgress(item.ItemValue); LineItems.FirstOrDefault(x => x.Info == item.ItemText).UpdateProgress(item.ItemValue);
} }
initLineItemProgress = false; _initLineItemProgress = false;
PatchPercent = Percent; PatchPercent = Percent;

Binary file not shown.

View File

@ -0,0 +1,16 @@
using PatchClient.Models;
namespace PatcherUtils.Model
{
public class PatchMessage
{
public string Message { get; private set; }
public PatcherExitCode ExitCode { get; private set; }
public PatchMessage(string message, PatcherExitCode exitCode)
{
Message = message;
ExitCode = exitCode;
}
}
}

View File

@ -0,0 +1,11 @@
namespace PatchClient.Models
{
public enum PatcherExitCode
{
Success = 0,
EftExeNotFound = 10,
NoPatchFolder = 11,
MissingFile = 12,
MissingDir = 13
}
}

View File

@ -1,4 +1,6 @@
using System; using PatchClient.Models;
using PatcherUtils.Model;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@ -267,7 +269,7 @@ namespace PatcherUtils
/// Apply a set of patches using the source and delta folders specified during construction. /// Apply a set of patches using the source and delta folders specified during construction.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public string ApplyPatches() public PatchMessage ApplyPatches()
{ {
//get needed directory information //get needed directory information
DirectoryInfo sourceDir = new DirectoryInfo(SourceFolder); DirectoryInfo sourceDir = new DirectoryInfo(SourceFolder);
@ -276,7 +278,7 @@ namespace PatcherUtils
//check directories exist //check directories exist
if (!sourceDir.Exists || !deltaDir.Exists) if (!sourceDir.Exists || !deltaDir.Exists)
{ {
return "One of the supplied directories doesn't exist"; return new PatchMessage("One of the supplied directories doesn't exist", PatcherExitCode.MissingDir);
} }
LazyOperations.ExtractResourcesToTempDir(); LazyOperations.ExtractResourcesToTempDir();
@ -312,7 +314,7 @@ namespace PatcherUtils
if (sourceFile == null) if (sourceFile == null)
{ {
return $"Failed to find matching source file for '{deltaFile.FullName}'"; return new PatchMessage($"Failed to find matching source file for '{deltaFile.FullName}'", PatcherExitCode.MissingFile);
} }
ApplyDelta(sourceFile.FullName, deltaFile.FullName); ApplyDelta(sourceFile.FullName, deltaFile.FullName);
@ -358,7 +360,7 @@ namespace PatcherUtils
RaiseProgressChanged(filesProcessed, fileCountTotal, deltaFile.Name, AdditionalInfo.ToArray()); RaiseProgressChanged(filesProcessed, fileCountTotal, deltaFile.Name, AdditionalInfo.ToArray());
} }
return $"Patching Complete. You can delete the patcher.exe file."; return new PatchMessage($"Patching Complete. You can delete the patcher.exe file.", PatcherExitCode.Success);
} }
} }
} }