Skip to content

Commit

Permalink
Added: OnApplySelfUpdate event for UpdateManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Aug 18, 2022
1 parent 36b08a4 commit 255341f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sewer56.Update/Sewer56.Update/Sewer56.Update.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This framework is a hard fork of Onova.</Description>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<Authors>Sewer56, Tyrrrz</Authors>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>3.1.0</Version>
<Version>3.2.0</Version>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

Expand Down
11 changes: 8 additions & 3 deletions Sewer56.Update/Sewer56.Update/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -34,6 +31,13 @@ public class UpdateManager<T> : IUpdateManager where T : class
/// </summary>
public readonly IPackageExtractor Extractor;

/// <summary>
/// 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.
/// </summary>
public event Action<string>? OnApplySelfUpdate;

private Lazy<string> _storageDirPath;
private bool _cleanupOnDispose = true;

Expand Down Expand Up @@ -213,6 +217,7 @@ public async Task<bool> 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;
Expand Down

0 comments on commit 255341f

Please sign in to comment.