mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Drop DeltaCompressionDotNet dependency
This may be reverted after https://github.com/taspeotis/DeltaCompressionDotNet/issues/17 is fixed. Closes #1716
This commit is contained in:
@@ -6,7 +6,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Squirrel.SimpleSplat;
|
||||
using DeltaCompressionDotNet.MsDelta;
|
||||
using System.ComponentModel;
|
||||
using Squirrel.Bsdiff;
|
||||
using SharpCompress.Archives;
|
||||
|
||||
31
src/Squirrel/MsDeltaCompression.cs
Normal file
31
src/Squirrel/MsDeltaCompression.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Squirrel
|
||||
{
|
||||
internal class MsDeltaCompression
|
||||
{
|
||||
public void CreateDelta(string oldFilePath, string newFilePath, string deltaFilePath)
|
||||
{
|
||||
const string? sourceOptionsName = null;
|
||||
const string? targetOptionsName = null;
|
||||
var globalOptions = new DeltaInput();
|
||||
var targetFileTime = IntPtr.Zero;
|
||||
|
||||
if (!NativeMethods.CreateDelta(
|
||||
FileTypeSet.Executables, CreateFlags.IgnoreFileSizeLimit, CreateFlags.None, oldFilePath, newFilePath,
|
||||
sourceOptionsName, targetOptionsName, globalOptions, targetFileTime, HashAlgId.Crc32, deltaFilePath))
|
||||
{
|
||||
throw new Win32Exception();
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyDelta(string deltaFilePath, string oldFilePath, string newFilePath)
|
||||
{
|
||||
if (!NativeMethods.ApplyDelta(ApplyFlags.AllowLegacy, oldFilePath, deltaFilePath, newFilePath))
|
||||
throw new Win32Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,64 @@ namespace Squirrel
|
||||
|
||||
[DllImport("Kernel32.dll", SetLastError=true)]
|
||||
internal static extern bool EndUpdateResource(IntPtr handle, bool discard);
|
||||
|
||||
#nullable enable
|
||||
/// <summary>
|
||||
/// The ApplyDelta function use the specified delta and source files to create a new copy of the target file.
|
||||
/// </summary>
|
||||
/// <param name="applyFlags">Either DELTA_FLAG_NONE or DELTA_APPLY_FLAG_ALLOW_PA19.</param>
|
||||
/// <param name="sourceName">The name of the source file to which the delta is to be applied.</param>
|
||||
/// <param name="deltaName">The name of the delta to be applied to the source file.</param>
|
||||
/// <param name="targetName">The name of the target file that is to be created.</param>
|
||||
/// <returns>
|
||||
/// Returns TRUE on success or FALSE otherwise.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#applydeltaaw
|
||||
/// </remarks>
|
||||
[DllImport("msdelta.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool ApplyDelta(
|
||||
[MarshalAs(UnmanagedType.I8)] ApplyFlags applyFlags,
|
||||
string sourceName,
|
||||
string deltaName,
|
||||
string targetName);
|
||||
|
||||
/// <summary>
|
||||
/// The CreateDelta function creates a delta from the specified source and target files and write the output delta to the designated file name.
|
||||
/// </summary>
|
||||
/// <param name="fileTypeSet">The file type set used for Create.</param>
|
||||
/// <param name="setFlags">The file type set used for Create.</param>
|
||||
/// <param name="resetFlags">The file type set used for Create.</param>
|
||||
/// <param name="sourceName">The file type set used for Create.</param>
|
||||
/// <param name="targetName">The name of the target against which the source is compared.</param>
|
||||
/// <param name="sourceOptionsName">Reserved. Pass NULL.</param>
|
||||
/// <param name="targetOptionsName">Reserved. Pass NULL.</param>
|
||||
/// <param name="globalOptions">Reserved. Pass a DELTA_INPUT structure with lpStart set to NULL and uSize set to 0.</param>
|
||||
/// <param name="targetFileTime">The time stamp set on the target file after delta Apply. If NULL, the timestamp of the target file during delta Create will be used.</param>
|
||||
/// <param name="hashAlgId">ALG_ID of the algorithm to be used to generate the target signature.</param>
|
||||
/// <param name="deltaName">The name of the delta file to be created.</param>
|
||||
/// <returns>
|
||||
/// Returns TRUE on success or FALSE otherwise.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#createdeltaaw
|
||||
/// </remarks>
|
||||
[DllImport("msdelta.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool CreateDelta(
|
||||
[MarshalAs(UnmanagedType.I8)] FileTypeSet fileTypeSet,
|
||||
[MarshalAs(UnmanagedType.I8)] CreateFlags setFlags,
|
||||
[MarshalAs(UnmanagedType.I8)] CreateFlags resetFlags,
|
||||
string sourceName,
|
||||
string targetName,
|
||||
string? sourceOptionsName,
|
||||
string? targetOptionsName,
|
||||
DeltaInput globalOptions,
|
||||
IntPtr targetFileTime,
|
||||
[MarshalAs(UnmanagedType.U4)] HashAlgId hashAlgId,
|
||||
string deltaName);
|
||||
#nullable restore
|
||||
}
|
||||
|
||||
[Flags]
|
||||
@@ -196,4 +254,68 @@ namespace Squirrel
|
||||
STD_OUTPUT_HANDLE = -11,
|
||||
STD_ERROR_HANDLE = -12,
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#deltaflagtypeflags
|
||||
/// </remarks>
|
||||
internal enum ApplyFlags : long
|
||||
{
|
||||
/// <summary>Indicates no special handling.</summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>Allow MSDelta to apply deltas created using PatchAPI.</summary>
|
||||
AllowLegacy = 1,
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#filetypesets
|
||||
/// </remarks>
|
||||
[Flags]
|
||||
internal enum FileTypeSet : long
|
||||
{
|
||||
/// <summary>
|
||||
/// File type set that includes I386, IA64 and AMD64 Portable Executable (PE) files. Others are treated as raw.
|
||||
/// </summary>
|
||||
Executables = 0x0FL,
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#deltaflagtypeflags
|
||||
/// </remarks>
|
||||
internal enum CreateFlags : long
|
||||
{
|
||||
/// <summary>Indicates no special handling.</summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>Allow the source, target and delta files to exceed the default size limit.</summary>
|
||||
IgnoreFileSizeLimit = 1 << 17,
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#deltainputstructure
|
||||
/// </remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct DeltaInput
|
||||
{
|
||||
/// <summary>Memory address non-editable input buffer.</summary>
|
||||
public IntPtr Start;
|
||||
|
||||
/// <summary>Size of the memory buffer in bytes.</summary>
|
||||
public IntPtr Size;
|
||||
|
||||
/// <summary>
|
||||
/// Defines whether MSDelta is allowed to edit the input buffer. If you make the input editable, the buffer will
|
||||
/// be zeroed at function return. However this will cause most MSDelta functions to use less memory.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.Bool)] public bool Editable;
|
||||
}
|
||||
|
||||
internal enum HashAlgId
|
||||
{
|
||||
/// <summary>No signature.</summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>32-bit CRC defined in msdelta.dll.</summary>
|
||||
Crc32 = 32,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
|
||||
<LangVersion>9</LangVersion>
|
||||
<Description>Squirrel</Description>
|
||||
<Title>Squirrel</Title>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
@@ -13,7 +14,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DeltaCompressionDotNet" Version="2.0.0" NoWarn="NU1701" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="Microsoft.Web.Xdt" Version="3.1.0" />
|
||||
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<PostBuildEvent>
|
||||
cd "$(TargetDir)"
|
||||
"$(NuGetPackageRoot)ilrepack\1.26.0\tools\ILRepack.exe" /internalize /out:$(TargetFileName).tmp $(TargetFileName) Microsoft.Web.XmlTransform.dll DeltaCompressionDotNet.dll Squirrel.dll NuGet.Squirrel.dll Mono.Cecil.dll SharpCompress.dll
|
||||
"$(NuGetPackageRoot)ilrepack\1.26.0\tools\ILRepack.exe" /internalize /out:$(TargetFileName).tmp $(TargetFileName) Microsoft.Web.XmlTransform.dll Squirrel.dll NuGet.Squirrel.dll Mono.Cecil.dll SharpCompress.dll
|
||||
del "$(TargetFileName)"
|
||||
ren "$(TargetFileName).tmp" "$(TargetFileName)"
|
||||
</PostBuildEvent>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<PostBuildEvent>
|
||||
cd "$(TargetDir)"
|
||||
"$(NuGetPackageRoot)ilrepack\1.26.0\tools\ILRepack.exe" /internalize /out:$(TargetFileName).tmp $(TargetFileName) WpfAnimatedGif.dll SharpCompress.dll Microsoft.Web.XmlTransform.dll DeltaCompressionDotNet.dll Squirrel.dll NuGet.Squirrel.dll Mono.Cecil.dll
|
||||
"$(NuGetPackageRoot)ilrepack\1.26.0\tools\ILRepack.exe" /internalize /out:$(TargetFileName).tmp $(TargetFileName) WpfAnimatedGif.dll SharpCompress.dll Microsoft.Web.XmlTransform.dll Squirrel.dll NuGet.Squirrel.dll Mono.Cecil.dll
|
||||
del "$(TargetFileName)"
|
||||
ren "$(TargetFileName).tmp" "$(TargetFileName)"
|
||||
</PostBuildEvent>
|
||||
|
||||
Reference in New Issue
Block a user