diff --git a/Patcher/PatchClient/App.axaml.cs b/Patcher/PatchClient/App.axaml.cs index 6b4a82a..df555e1 100644 --- a/Patcher/PatchClient/App.axaml.cs +++ b/Patcher/PatchClient/App.axaml.cs @@ -17,9 +17,14 @@ namespace PatchClient { if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { + bool autoClose = false; + + if(desktop.Args != null && desktop.Args[0].ToLower() == "autoclose") + autoClose = true; + desktop.MainWindow = new MainWindow { - DataContext = new MainWindowViewModel(), + DataContext = new MainWindowViewModel(autoClose), }; } diff --git a/Patcher/PatchClient/ViewModels/MainWindowViewModel.cs b/Patcher/PatchClient/ViewModels/MainWindowViewModel.cs index 439c5ac..27bd0fb 100644 --- a/Patcher/PatchClient/ViewModels/MainWindowViewModel.cs +++ b/Patcher/PatchClient/ViewModels/MainWindowViewModel.cs @@ -18,11 +18,11 @@ namespace PatchClient.ViewModels } }); - public MainWindowViewModel() + public MainWindowViewModel(bool autoClose) { this.WhenActivated((CompositeDisposable disposable) => { - Router.Navigate.Execute(new PatcherViewModel(this)); + Router.Navigate.Execute(new PatcherViewModel(this, autoClose)); }); } } diff --git a/Patcher/PatchClient/ViewModels/PatcherViewModel.cs b/Patcher/PatchClient/ViewModels/PatcherViewModel.cs index 4ff6fa7..d8ba4e2 100644 --- a/Patcher/PatchClient/ViewModels/PatcherViewModel.cs +++ b/Patcher/PatchClient/ViewModels/PatcherViewModel.cs @@ -14,8 +14,8 @@ namespace PatchClient.ViewModels { public class PatcherViewModel : ViewModelBase { - private bool initLineItemProgress = true; - + private bool _initLineItemProgress = true; + private bool _autoClose = false; public ObservableCollection LineItems { get; set; } = new ObservableCollection(); 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) => { //check if escapefromtarkov.exe is present 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.")); return; } @@ -54,6 +62,12 @@ namespace PatchClient.ViewModels //check if patch folder is present 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.")); return; } @@ -72,13 +86,18 @@ namespace PatchClient.ViewModels patcher.ProgressChanged += patcher_ProgressChanged; - string message = patcher.ApplyPatches(); + var patchMessage = patcher.ApplyPatches(); LazyOperations.CleanupTempDir(); 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) { - if (initLineItemProgress) + if (_initLineItemProgress) { LineItems.Add(new LineItemProgress(item)); } @@ -97,7 +116,7 @@ namespace PatchClient.ViewModels LineItems.FirstOrDefault(x => x.Info == item.ItemText).UpdateProgress(item.ItemValue); } - initLineItemProgress = false; + _initLineItemProgress = false; PatchPercent = Percent; diff --git a/Patcher/PatchGenerator/Resources/PatchClient.exe b/Patcher/PatchGenerator/Resources/PatchClient.exe index 228a843..da16f7d 100644 --- a/Patcher/PatchGenerator/Resources/PatchClient.exe +++ b/Patcher/PatchGenerator/Resources/PatchClient.exe @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b7590b4a9b9184ccd086883cc14851aa9902c0cdee26ab845d1bb6201f86d40e -size 25318572 +oid sha256:30acfaaa1ec86b5ae5da5bf5efcc00393481f936d67ab7bf28e06572f59c9c90 +size 25319596 diff --git a/Patcher/PatcherUtils/Model/PatchMessage.cs b/Patcher/PatcherUtils/Model/PatchMessage.cs new file mode 100644 index 0000000..9adafdf --- /dev/null +++ b/Patcher/PatcherUtils/Model/PatchMessage.cs @@ -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; + } + } +} diff --git a/Patcher/PatcherUtils/Model/PatcherExitCode.cs b/Patcher/PatcherUtils/Model/PatcherExitCode.cs new file mode 100644 index 0000000..a33601b --- /dev/null +++ b/Patcher/PatcherUtils/Model/PatcherExitCode.cs @@ -0,0 +1,11 @@ +namespace PatchClient.Models +{ + public enum PatcherExitCode + { + Success = 0, + EftExeNotFound = 10, + NoPatchFolder = 11, + MissingFile = 12, + MissingDir = 13 + } +} diff --git a/Patcher/PatcherUtils/PatchHelper.cs b/Patcher/PatcherUtils/PatchHelper.cs index d9221a2..72f88a6 100644 --- a/Patcher/PatcherUtils/PatchHelper.cs +++ b/Patcher/PatcherUtils/PatchHelper.cs @@ -1,4 +1,6 @@ -using System; +using PatchClient.Models; +using PatcherUtils.Model; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -267,7 +269,7 @@ namespace PatcherUtils /// Apply a set of patches using the source and delta folders specified during construction. /// /// - public string ApplyPatches() + public PatchMessage ApplyPatches() { //get needed directory information DirectoryInfo sourceDir = new DirectoryInfo(SourceFolder); @@ -276,7 +278,7 @@ namespace PatcherUtils //check directories exist 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(); @@ -312,7 +314,7 @@ namespace PatcherUtils 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); @@ -358,7 +360,7 @@ namespace PatcherUtils 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); } } }