2022-04-30 12:05:13 -04:00
|
|
|
|
using Avalonia.Threading;
|
2021-12-11 21:47:59 -05:00
|
|
|
|
using PatchClient.Models;
|
|
|
|
|
using PatcherUtils;
|
2021-12-25 01:17:01 -05:00
|
|
|
|
using ReactiveUI;
|
2021-12-11 21:47:59 -05:00
|
|
|
|
using System;
|
2021-12-25 01:17:01 -05:00
|
|
|
|
using System.Collections.ObjectModel;
|
2021-12-29 11:04:02 -05:00
|
|
|
|
using System.IO;
|
2021-12-11 21:47:59 -05:00
|
|
|
|
using System.Linq;
|
2021-12-28 19:44:25 -05:00
|
|
|
|
using System.Reactive.Disposables;
|
2021-12-29 11:04:02 -05:00
|
|
|
|
using System.Reflection;
|
2021-12-11 21:47:59 -05:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace PatchClient.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class PatcherViewModel : ViewModelBase
|
|
|
|
|
{
|
|
|
|
|
private bool initLineItemProgress = true;
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<LineItemProgress> LineItems { get; set; } = new ObservableCollection<LineItemProgress>();
|
|
|
|
|
|
2021-12-28 19:44:25 -05:00
|
|
|
|
private string _ProgressMessage = "";
|
2021-12-11 21:47:59 -05:00
|
|
|
|
public string ProgressMessage
|
|
|
|
|
{
|
|
|
|
|
get => _ProgressMessage;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _ProgressMessage, value);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-12 21:04:36 -05:00
|
|
|
|
private int _PatchPercent;
|
|
|
|
|
public int PatchPercent
|
2021-12-11 21:47:59 -05:00
|
|
|
|
{
|
2021-12-12 21:04:36 -05:00
|
|
|
|
get => _PatchPercent;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _PatchPercent, value);
|
2021-12-11 21:47:59 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 19:44:25 -05:00
|
|
|
|
private string _PatchMessage = "";
|
2021-12-11 21:47:59 -05:00
|
|
|
|
public string PatchMessage
|
|
|
|
|
{
|
|
|
|
|
get => _PatchMessage;
|
|
|
|
|
set => this.RaiseAndSetIfChanged(ref _PatchMessage, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-12-28 19:44:25 -05:00
|
|
|
|
public PatcherViewModel(IScreen Host) : base(Host)
|
2021-12-11 21:47:59 -05:00
|
|
|
|
{
|
2021-12-28 19:44:25 -05:00
|
|
|
|
this.WhenActivated((CompositeDisposable disposables) =>
|
|
|
|
|
{
|
2022-05-01 13:04:52 -04:00
|
|
|
|
//check if escapefromtarkov.exe is present
|
|
|
|
|
if(!File.Exists(Path.Join(Directory.GetCurrentDirectory(), "escapefromtarkov.exe")))
|
|
|
|
|
{
|
|
|
|
|
NavigateTo(new MessageViewModel(HostScreen, "EscapeFromTarkov.exe was not found. Please ensure you have copied the patcher to your SPT folder."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//check if patch folder is present
|
2022-04-30 12:05:13 -04:00
|
|
|
|
if(!Directory.Exists(LazyOperations.PatchFolder))
|
2021-12-28 19:44:25 -05:00
|
|
|
|
{
|
2022-04-30 12:05:13 -04:00
|
|
|
|
NavigateTo(new MessageViewModel(HostScreen, $"{LazyOperations.PatchFolder} folder is missing. Please copy it to\n'{Environment.CurrentDirectory}'\nand try patching again."));
|
|
|
|
|
return;
|
2021-12-28 19:44:25 -05:00
|
|
|
|
}
|
2021-12-25 20:24:00 -05:00
|
|
|
|
|
2022-04-30 12:05:13 -04:00
|
|
|
|
RunPatcher();
|
2021-12-28 19:44:25 -05:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RunPatcher()
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async() =>
|
|
|
|
|
{
|
2021-12-29 11:04:02 -05:00
|
|
|
|
LazyOperations.ExtractResourcesToTempDir(Assembly.GetExecutingAssembly());
|
|
|
|
|
|
2021-12-19 21:37:31 -05:00
|
|
|
|
PatchHelper patcher = new PatchHelper(Environment.CurrentDirectory, null, LazyOperations.PatchFolder);
|
2021-12-11 21:47:59 -05:00
|
|
|
|
|
2021-12-19 21:37:31 -05:00
|
|
|
|
patcher.ProgressChanged += patcher_ProgressChanged;
|
2021-12-11 21:47:59 -05:00
|
|
|
|
|
2021-12-19 21:37:31 -05:00
|
|
|
|
string message = patcher.ApplyPatches();
|
|
|
|
|
|
2021-12-29 11:04:02 -05:00
|
|
|
|
LazyOperations.CleanupTempDir();
|
|
|
|
|
|
|
|
|
|
Directory.Delete(LazyOperations.PatchFolder, true);
|
|
|
|
|
|
2021-12-28 19:44:25 -05:00
|
|
|
|
await NavigateToWithDelay(new MessageViewModel(HostScreen, message), 400);
|
2021-12-11 21:47:59 -05:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 21:37:31 -05:00
|
|
|
|
private void patcher_ProgressChanged(object Sender, int Progress, int Total, int Percent, string Message = "", params LineItem[] AdditionalLineItems)
|
2021-12-11 21:47:59 -05:00
|
|
|
|
{
|
2021-12-29 20:28:03 -05:00
|
|
|
|
Dispatcher.UIThread.InvokeAsync(() =>
|
2021-12-11 21:47:59 -05:00
|
|
|
|
{
|
2021-12-29 20:28:03 -05:00
|
|
|
|
foreach (LineItem item in AdditionalLineItems)
|
2021-12-11 21:47:59 -05:00
|
|
|
|
{
|
2021-12-12 21:04:36 -05:00
|
|
|
|
|
2021-12-29 20:28:03 -05:00
|
|
|
|
if (initLineItemProgress)
|
|
|
|
|
{
|
|
|
|
|
LineItems.Add(new LineItemProgress(item));
|
|
|
|
|
}
|
2021-12-11 21:47:59 -05:00
|
|
|
|
|
2021-12-29 20:28:03 -05:00
|
|
|
|
LineItems.FirstOrDefault(x => x.Info == item.ItemText).UpdateProgress(item.ItemValue);
|
|
|
|
|
}
|
2021-12-11 21:47:59 -05:00
|
|
|
|
|
2021-12-29 20:28:03 -05:00
|
|
|
|
initLineItemProgress = false;
|
2021-12-11 21:47:59 -05:00
|
|
|
|
|
2021-12-29 20:28:03 -05:00
|
|
|
|
PatchPercent = Percent;
|
2021-12-11 21:47:59 -05:00
|
|
|
|
|
2021-12-29 20:28:03 -05:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(Message))
|
|
|
|
|
{
|
|
|
|
|
PatchMessage = Message;
|
|
|
|
|
}
|
2021-12-11 21:47:59 -05:00
|
|
|
|
|
2021-12-29 20:28:03 -05:00
|
|
|
|
ProgressMessage = $"Patching: {Progress} / {Total} - {Percent}%";
|
|
|
|
|
});
|
2021-12-11 21:47:59 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|