From 255341f3d0491a525f46f821ac75a59766275cfc Mon Sep 17 00:00:00 2001 From: Sewer 56 Date: Thu, 18 Aug 2022 23:59:22 +0100 Subject: [PATCH] Added: OnApplySelfUpdate event for UpdateManager --- Sewer56.Update/Sewer56.Update/Sewer56.Update.csproj | 2 +- Sewer56.Update/Sewer56.Update/UpdateManager.cs | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Sewer56.Update/Sewer56.Update/Sewer56.Update.csproj b/Sewer56.Update/Sewer56.Update/Sewer56.Update.csproj index 9267786..1e6769c 100644 --- a/Sewer56.Update/Sewer56.Update/Sewer56.Update.csproj +++ b/Sewer56.Update/Sewer56.Update/Sewer56.Update.csproj @@ -20,7 +20,7 @@ This framework is a hard fork of Onova. True Sewer56, Tyrrrz True - 3.1.0 + 3.2.0 true diff --git a/Sewer56.Update/Sewer56.Update/UpdateManager.cs b/Sewer56.Update/Sewer56.Update/UpdateManager.cs index 35a3a28..caea6e0 100644 --- a/Sewer56.Update/Sewer56.Update/UpdateManager.cs +++ b/Sewer56.Update/Sewer56.Update/UpdateManager.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; -using System.Reflection; using System.Threading; using System.Threading.Tasks; using NuGet.Versioning; @@ -15,7 +13,6 @@ using Sewer56.Update.Packaging; using Sewer56.Update.Packaging.Enums; using Sewer56.Update.Packaging.Interfaces; -using Sewer56.Update.Packaging.IO; using Sewer56.Update.Packaging.Structures; using Sewer56.Update.Structures; @@ -34,6 +31,13 @@ public class UpdateManager : IUpdateManager where T : class /// public readonly IPackageExtractor Extractor; + /// + /// Executed when an update to self is about to be applied (i.e. process is about to restart). + /// Passed in argument contains the location of data to be copied into current program folder, + /// after decompression (including deltas) and right before it is applied. + /// + public event Action? OnApplySelfUpdate; + private Lazy _storageDirPath; private bool _cleanupOnDispose = true; @@ -213,6 +217,7 @@ public async Task StartUpdateAsync(NuGetVersion version, OutOfProcessOptio CleanupAfterUpdate = updateOptions.CleanupAfterUpdate }; + OnApplySelfUpdate?.Invoke(packageContentDirPath!); var startInfo = Startup.GetProcessStartInfo(Updatee.ExecutablePath!, Updatee.BaseDirectory, packageContentDirPath, startupParams); Process.Start(startInfo); _cleanupOnDispose = false;