mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Refactor namespaces
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NuGet.Versioning;
|
||||
using Velopack.Compression;
|
||||
using Velopack.Exceptions;
|
||||
using Velopack.Locators;
|
||||
using Velopack.Logging;
|
||||
@@ -231,8 +232,6 @@ namespace Velopack
|
||||
EnsureInstalled();
|
||||
using var _mut = await AcquireUpdateLock().ConfigureAwait(false);
|
||||
|
||||
var appTempDir = Locator.AppTempDir!;
|
||||
|
||||
var completeFile = Locator.GetLocalPackagePath(targetRelease);
|
||||
var incompleteFile = completeFile + ".partial";
|
||||
|
||||
@@ -262,33 +261,9 @@ namespace Velopack
|
||||
$"There are too many delta's ({deltasCount} > 10) or the sum of their size ({deltasSize} > {targetRelease.Size}) is too large. " +
|
||||
$"Only full update will be available.");
|
||||
} else {
|
||||
using var _1 = TempUtil.GetTempDirectory(out var deltaStagingDir, appTempDir);
|
||||
string basePackagePath = Locator.GetLocalPackagePath(updates.BaseRelease);
|
||||
if (!File.Exists(basePackagePath))
|
||||
throw new Exception($"Unable to find base package {basePackagePath} for delta update.");
|
||||
EasyZip.ExtractZipToDirectory(Log, basePackagePath, deltaStagingDir);
|
||||
|
||||
reportProgress(10);
|
||||
await DownloadAndApplyDeltaUpdates(
|
||||
deltaStagingDir,
|
||||
updates,
|
||||
x => reportProgress(CoreUtil.CalculateProgress(x, 10, 80)),
|
||||
cancelToken)
|
||||
.ConfigureAwait(false);
|
||||
reportProgress(80);
|
||||
|
||||
Log.Info("Delta updates completed, creating final update package.");
|
||||
File.Delete(incompleteFile);
|
||||
await EasyZip.CreateZipFromDirectoryAsync(
|
||||
Log,
|
||||
incompleteFile,
|
||||
deltaStagingDir,
|
||||
x => reportProgress(CoreUtil.CalculateProgress(x, 80, 100)),
|
||||
cancelToken: cancelToken).ConfigureAwait(false);
|
||||
File.Delete(completeFile);
|
||||
File.Move(incompleteFile, completeFile);
|
||||
Log.Info("Delta release preparations complete. Package moved to: " + completeFile);
|
||||
reportProgress(100);
|
||||
await DownloadAndApplyDeltaUpdates(updates, incompleteFile, progress, cancelToken).ConfigureAwait(false);
|
||||
IoUtil.MoveFile(incompleteFile, completeFile, true);
|
||||
Log.Info("Delta update download complete. Package moved to: " + completeFile);
|
||||
return; // success!
|
||||
}
|
||||
}
|
||||
@@ -336,19 +311,17 @@ namespace Velopack
|
||||
/// Given a folder containing the extracted base package, and a list of delta updates, downloads and applies the
|
||||
/// delta updates to the base package.
|
||||
/// </summary>
|
||||
/// <param name="extractedBasePackage">A folder containing the application files to apply the delta's to.</param>
|
||||
/// <param name="updates">An update object containing one or more delta's</param>
|
||||
/// <param name="targetFile">The reconstructed full update after all delta's are applied</param>
|
||||
/// <param name="progress">A callback reporting process of delta application progress (from 0-100).</param>
|
||||
/// <param name="cancelToken">A token to use to cancel the request.</param>
|
||||
protected virtual async Task DownloadAndApplyDeltaUpdates(string extractedBasePackage, UpdateInfo updates, Action<int> progress,
|
||||
protected virtual async Task DownloadAndApplyDeltaUpdates(UpdateInfo updates, string targetFile, Action<int> progress,
|
||||
CancellationToken cancelToken)
|
||||
{
|
||||
var releasesToDownload = updates.DeltasToTarget.OrderBy(d => d.Version).ToArray();
|
||||
|
||||
var appTempDir = Locator.AppTempDir!;
|
||||
var updateExe = Locator.UpdateExePath!;
|
||||
|
||||
// downloading accounts for 0%-50% of progress
|
||||
// downloading accounts for 0%-70% of progress
|
||||
double current = 0;
|
||||
double toIncrement = 100.0 / releasesToDownload.Count();
|
||||
await releasesToDownload.ForEachAsync(
|
||||
@@ -365,7 +338,7 @@ namespace Velopack
|
||||
current -= component;
|
||||
component = toIncrement / 100.0 * p;
|
||||
var progressOfStep = (int) Math.Round(current += component);
|
||||
progress(CoreUtil.CalculateProgress(progressOfStep, 0, 50));
|
||||
progress(CoreUtil.CalculateProgress(progressOfStep, 0, 70));
|
||||
}
|
||||
},
|
||||
cancelToken).ConfigureAwait(false);
|
||||
@@ -374,23 +347,34 @@ namespace Velopack
|
||||
Log.Debug($"Download complete for delta version {x.Version}");
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
Log.Info("All delta packages downloaded and verified, applying them to the base now. The delta staging dir is: " + extractedBasePackage);
|
||||
Log.Info("All delta packages downloaded and verified, applying them to the base now.");
|
||||
|
||||
// applying deltas accounts for 50%-100% of progress
|
||||
double progressStepSize = 100d / releasesToDownload.Length;
|
||||
var builder = new DeltaUpdateExe(Log, appTempDir, updateExe);
|
||||
for (var i = 0; i < releasesToDownload.Length; i++) {
|
||||
cancelToken.ThrowIfCancellationRequested();
|
||||
var rel = releasesToDownload[i];
|
||||
double baseProgress = i * progressStepSize;
|
||||
var packageFile = Locator.GetLocalPackagePath(rel);
|
||||
builder.ApplyDeltaPackageFast(
|
||||
extractedBasePackage,
|
||||
packageFile,
|
||||
x => {
|
||||
var progressOfStep = (int) (baseProgress + (progressStepSize * (x / 100d)));
|
||||
progress(CoreUtil.CalculateProgress(progressOfStep, 50, 100));
|
||||
});
|
||||
// applying deltas accounts for 70%-100% of progress
|
||||
var baseFile = Locator.GetLocalPackagePath(updates.BaseRelease!);
|
||||
var args = new List<string> {
|
||||
"patch",
|
||||
"--old",
|
||||
baseFile,
|
||||
"--output",
|
||||
targetFile,
|
||||
};
|
||||
|
||||
foreach (var x in releasesToDownload) {
|
||||
args.Add("--delta");
|
||||
args.Add(Locator.GetLocalPackagePath(x));
|
||||
}
|
||||
|
||||
var psi = new ProcessStartInfo(updateExe);
|
||||
psi.AppendArgumentListSafe(args, out var _);
|
||||
psi.CreateNoWindow = true;
|
||||
var p = psi.StartRedirectOutputToILogger(Log, VelopackLogLevel.Debug);
|
||||
if (!p.WaitForExit((int)TimeSpan.FromMinutes(5).TotalMilliseconds)) {
|
||||
p.Kill();
|
||||
throw new TimeoutException("patch process timed out (5min).");
|
||||
}
|
||||
|
||||
if (p.ExitCode != 0) {
|
||||
throw new Exception($"patch process failed with exit code {p.ExitCode}.");
|
||||
}
|
||||
|
||||
progress(100);
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
using Velopack.Logging;
|
||||
using Velopack.Util;
|
||||
|
||||
namespace Velopack.Compression
|
||||
namespace Velopack.Util
|
||||
{
|
||||
internal static class EasyZip
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.IO;
|
||||
using Riok.Mapperly.Abstractions;
|
||||
using Velopack.Packaging;
|
||||
using Velopack.Packaging.Compression;
|
||||
using Velopack.Packaging.Unix.Commands;
|
||||
using Velopack.Packaging.Windows.Commands;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ using Velopack.NuGet;
|
||||
using Velopack.Packaging;
|
||||
using Velopack.Util;
|
||||
using System.Net;
|
||||
using Velopack.Packaging.Compression;
|
||||
|
||||
#if !NET6_0_OR_GREATER
|
||||
using System.Net.Http;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using ICSharpCode.SharpZipLib.Tar;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Velopack.Compression;
|
||||
using Velopack.Core;
|
||||
using Velopack.Util;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Velopack.Core;
|
||||
using Velopack.Core.Abstractions;
|
||||
using Velopack.Packaging.Compression;
|
||||
using Velopack.Util;
|
||||
|
||||
namespace Velopack.Packaging.Unix.Commands;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Velopack.Packaging.Abstractions;
|
||||
using Velopack.Packaging.Compression;
|
||||
|
||||
namespace Velopack.Packaging.Unix.Commands;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Velopack.Packaging.Abstractions;
|
||||
using Velopack.Packaging.Compression;
|
||||
|
||||
namespace Velopack.Packaging.Unix.Commands;
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Text.RegularExpressions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NuGet.Versioning;
|
||||
using Velopack.Compression;
|
||||
using Velopack.Core;
|
||||
using Velopack.Core.Abstractions;
|
||||
using Velopack.NuGet;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Velopack.Packaging.Windows.Commands;
|
||||
using Velopack.Packaging.Compression;
|
||||
|
||||
namespace Velopack.Packaging.Windows.Commands;
|
||||
|
||||
public class WindowsReleasifyOptions : WindowsSigningOptions
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Velopack.Packaging.Abstractions;
|
||||
using Velopack.Packaging.Compression;
|
||||
|
||||
namespace Velopack.Packaging.Abstractions;
|
||||
|
||||
public interface IPackOptions : INugetPackCommand, IPlatformOptions
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Velopack.Core.Abstractions;
|
||||
using Velopack.Packaging.Compression;
|
||||
|
||||
namespace Velopack.Packaging.Commands;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Velopack.Core;
|
||||
using Velopack.Packaging.Compression;
|
||||
|
||||
namespace Velopack.Packaging.Commands;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Velopack.Compression;
|
||||
using Velopack.Core;
|
||||
using Velopack.Core.Abstractions;
|
||||
using Velopack.Packaging.Compression;
|
||||
using Velopack.Util;
|
||||
|
||||
namespace Velopack.Packaging.Commands;
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace Velopack.Compression
|
||||
namespace Velopack.Packaging.Compression
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
internal sealed class BZip2Stream : Stream
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Threading;
|
||||
|
||||
// Adapted from https://github.com/LogosBible/bsdiff.net/blob/master/src/bsdiff/BinaryPatchUtility.cs
|
||||
|
||||
namespace Velopack.Compression
|
||||
namespace Velopack.Packaging.Compression
|
||||
{
|
||||
/*
|
||||
The original bsdiff.c source code (http://www.daemonology.net/bsdiff/) is
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Velopack.Compression;
|
||||
using Velopack.Core;
|
||||
|
||||
namespace Velopack.Packaging;
|
||||
namespace Velopack.Packaging.Compression;
|
||||
|
||||
public class DeltaEmbedded
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Velopack.Packaging;
|
||||
namespace Velopack.Packaging.Compression;
|
||||
|
||||
public enum DeltaMode
|
||||
{
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
#nullable enable
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Velopack.Exceptions;
|
||||
using Velopack.Logging;
|
||||
using Velopack.Util;
|
||||
|
||||
namespace Velopack.Compression
|
||||
namespace Velopack.Packaging.Compression
|
||||
{
|
||||
internal abstract class DeltaPackage
|
||||
{
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using System.IO.MemoryMappedFiles;
|
||||
using System.Text;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Velopack.Compression;
|
||||
using Velopack.Core;
|
||||
using Velopack.Packaging.Exceptions;
|
||||
using Velopack.Util;
|
||||
|
||||
namespace Velopack.Packaging;
|
||||
namespace Velopack.Packaging.Compression;
|
||||
|
||||
public class DeltaPackageBuilder
|
||||
{
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using Velopack.Logging;
|
||||
using Velopack.Util;
|
||||
|
||||
namespace Velopack.Compression
|
||||
namespace Velopack.Packaging.Compression
|
||||
{
|
||||
internal class DeltaUpdateExe : DeltaPackage
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
#nullable enable
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace Velopack.Compression
|
||||
namespace Velopack.Packaging.Compression
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
[SupportedOSPlatform("windows")]
|
||||
|
||||
@@ -3,11 +3,11 @@ using System.Text.RegularExpressions;
|
||||
using Markdig;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NuGet.Versioning;
|
||||
using Velopack.Compression;
|
||||
using Velopack.Core;
|
||||
using Velopack.Core.Abstractions;
|
||||
using Velopack.NuGet;
|
||||
using Velopack.Packaging.Abstractions;
|
||||
using Velopack.Packaging.Compression;
|
||||
using Velopack.Util;
|
||||
|
||||
namespace Velopack.Packaging;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Velopack.Core;
|
||||
using Velopack.Packaging.Compression;
|
||||
using Velopack.Packaging.Exceptions;
|
||||
|
||||
namespace Velopack.Packaging;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Velopack.Core;
|
||||
using Velopack.Packaging;
|
||||
using Velopack.Packaging.Compression;
|
||||
|
||||
namespace Velopack.Vpk.Commands.Packaging;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
using Velopack.Packaging;
|
||||
using Velopack.Packaging.Compression;
|
||||
|
||||
namespace Velopack.Vpk.Commands.Packaging;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public abstract class ReleaseCommandTests<T> : BaseCommandTests<T>
|
||||
string cli = GetRequiredDefaultOptions() + "--delta none";
|
||||
ParseResult parseResult = command.ParseAndApply(cli);
|
||||
|
||||
Assert.True(command.DeltaMode == Packaging.DeltaMode.None);
|
||||
Assert.True(command.DeltaMode == Packaging.Compression.DeltaMode.None);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Runtime.Versioning;
|
||||
using Velopack.Compression;
|
||||
using Velopack.Core;
|
||||
using Velopack.Util;
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ using System.Xml.Linq;
|
||||
using Microsoft.Deployment.WindowsInstaller;
|
||||
using Microsoft.Win32;
|
||||
using NuGet.Packaging;
|
||||
using Velopack.Compression;
|
||||
using Velopack.Core;
|
||||
using Velopack.Packaging.Commands;
|
||||
using Velopack.Packaging.Compression;
|
||||
using Velopack.Packaging.Windows.Commands;
|
||||
using Velopack.Util;
|
||||
using Velopack.Vpk;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.ComponentModel;
|
||||
using System.IO.Compression;
|
||||
using NCode.ReparsePoints;
|
||||
using Velopack.Compression;
|
||||
using Velopack.Logging;
|
||||
using Velopack.Util;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Text;
|
||||
using NuGet.Versioning;
|
||||
using Velopack.Compression;
|
||||
using Velopack.Core;
|
||||
using Velopack.Exceptions;
|
||||
using Velopack.Locators;
|
||||
|
||||
@@ -39,8 +39,8 @@ public class ZipPackageTests
|
||||
SymbolicLink.Create(symlink, actual);
|
||||
SymbolicLink.Create(symfile, actualFile);
|
||||
|
||||
Compression.EasyZip.CreateZipFromDirectoryAsync(logger.ToVelopackLogger(), zipFile, tempDir).GetAwaiterResult();
|
||||
Compression.EasyZip.ExtractZipToDirectory(logger.ToVelopackLogger(), zipFile, extractedDir, expandSymlinks: true);
|
||||
EasyZip.CreateZipFromDirectoryAsync(logger.ToVelopackLogger(), zipFile, tempDir).GetAwaiterResult();
|
||||
EasyZip.ExtractZipToDirectory(logger.ToVelopackLogger(), zipFile, extractedDir, expandSymlinks: true);
|
||||
|
||||
Assert.True(File.Exists(Path.Combine(extractedDir, "actual", "file.txt")));
|
||||
Assert.Equal("hello", File.ReadAllText(Path.Combine(extractedDir, "actual", "file.txt")));
|
||||
|
||||
Reference in New Issue
Block a user