Skip to content

Commit d854131

Browse files
authored
Merge pull request #1748 from AArnott/dropDelta
Drop DeltaCompressionDotNet dependency
2 parents 129d019 + 1b81b4c commit d854131

6 files changed

Lines changed: 156 additions & 4 deletions

File tree

src/Squirrel/DeltaPackage.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Text;
77
using System.Text.RegularExpressions;
88
using Squirrel.SimpleSplat;
9-
using DeltaCompressionDotNet.MsDelta;
109
using System.ComponentModel;
1110
using Squirrel.Bsdiff;
1211
using SharpCompress.Archives;

src/Squirrel/MsDeltaCompression.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#nullable enable
2+
3+
using System;
4+
using System.ComponentModel;
5+
6+
namespace Squirrel
7+
{
8+
internal class MsDeltaCompression
9+
{
10+
public void CreateDelta(string oldFilePath, string newFilePath, string deltaFilePath)
11+
{
12+
const string? sourceOptionsName = null;
13+
const string? targetOptionsName = null;
14+
var globalOptions = new DeltaInput();
15+
var targetFileTime = IntPtr.Zero;
16+
17+
if (!NativeMethods.CreateDelta(
18+
FileTypeSet.Executables, CreateFlags.IgnoreFileSizeLimit, CreateFlags.None, oldFilePath, newFilePath,
19+
sourceOptionsName, targetOptionsName, globalOptions, targetFileTime, HashAlgId.Crc32, deltaFilePath))
20+
{
21+
throw new Win32Exception();
22+
}
23+
}
24+
25+
public void ApplyDelta(string deltaFilePath, string oldFilePath, string newFilePath)
26+
{
27+
if (!NativeMethods.ApplyDelta(ApplyFlags.AllowLegacy, oldFilePath, deltaFilePath, newFilePath))
28+
throw new Win32Exception();
29+
}
30+
}
31+
}

src/Squirrel/NativeMethods.cs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,64 @@ internal static extern IntPtr OpenProcess(
9797

9898
[DllImport("Kernel32.dll", SetLastError=true)]
9999
internal static extern bool EndUpdateResource(IntPtr handle, bool discard);
100+
101+
#nullable enable
102+
/// <summary>
103+
/// The ApplyDelta function use the specified delta and source files to create a new copy of the target file.
104+
/// </summary>
105+
/// <param name="applyFlags">Either DELTA_FLAG_NONE or DELTA_APPLY_FLAG_ALLOW_PA19.</param>
106+
/// <param name="sourceName">The name of the source file to which the delta is to be applied.</param>
107+
/// <param name="deltaName">The name of the delta to be applied to the source file.</param>
108+
/// <param name="targetName">The name of the target file that is to be created.</param>
109+
/// <returns>
110+
/// Returns TRUE on success or FALSE otherwise.
111+
/// </returns>
112+
/// <remarks>
113+
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#applydeltaaw
114+
/// </remarks>
115+
[DllImport("msdelta.dll", CharSet = CharSet.Unicode, SetLastError = true)]
116+
[return: MarshalAs(UnmanagedType.Bool)]
117+
internal static extern bool ApplyDelta(
118+
[MarshalAs(UnmanagedType.I8)] ApplyFlags applyFlags,
119+
string sourceName,
120+
string deltaName,
121+
string targetName);
122+
123+
/// <summary>
124+
/// The CreateDelta function creates a delta from the specified source and target files and write the output delta to the designated file name.
125+
/// </summary>
126+
/// <param name="fileTypeSet">The file type set used for Create.</param>
127+
/// <param name="setFlags">The file type set used for Create.</param>
128+
/// <param name="resetFlags">The file type set used for Create.</param>
129+
/// <param name="sourceName">The file type set used for Create.</param>
130+
/// <param name="targetName">The name of the target against which the source is compared.</param>
131+
/// <param name="sourceOptionsName">Reserved. Pass NULL.</param>
132+
/// <param name="targetOptionsName">Reserved. Pass NULL.</param>
133+
/// <param name="globalOptions">Reserved. Pass a DELTA_INPUT structure with lpStart set to NULL and uSize set to 0.</param>
134+
/// <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>
135+
/// <param name="hashAlgId">ALG_ID of the algorithm to be used to generate the target signature.</param>
136+
/// <param name="deltaName">The name of the delta file to be created.</param>
137+
/// <returns>
138+
/// Returns TRUE on success or FALSE otherwise.
139+
/// </returns>
140+
/// <remarks>
141+
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#createdeltaaw
142+
/// </remarks>
143+
[DllImport("msdelta.dll", CharSet = CharSet.Unicode, SetLastError = true)]
144+
[return: MarshalAs(UnmanagedType.Bool)]
145+
internal static extern bool CreateDelta(
146+
[MarshalAs(UnmanagedType.I8)] FileTypeSet fileTypeSet,
147+
[MarshalAs(UnmanagedType.I8)] CreateFlags setFlags,
148+
[MarshalAs(UnmanagedType.I8)] CreateFlags resetFlags,
149+
string sourceName,
150+
string targetName,
151+
string? sourceOptionsName,
152+
string? targetOptionsName,
153+
DeltaInput globalOptions,
154+
IntPtr targetFileTime,
155+
[MarshalAs(UnmanagedType.U4)] HashAlgId hashAlgId,
156+
string deltaName);
157+
#nullable restore
100158
}
101159

102160
[Flags]
@@ -196,4 +254,68 @@ public enum StandardHandles : int {
196254
STD_OUTPUT_HANDLE = -11,
197255
STD_ERROR_HANDLE = -12,
198256
}
257+
258+
/// <remarks>
259+
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#deltaflagtypeflags
260+
/// </remarks>
261+
internal enum ApplyFlags : long
262+
{
263+
/// <summary>Indicates no special handling.</summary>
264+
None = 0,
265+
266+
/// <summary>Allow MSDelta to apply deltas created using PatchAPI.</summary>
267+
AllowLegacy = 1,
268+
}
269+
270+
/// <remarks>
271+
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#filetypesets
272+
/// </remarks>
273+
[Flags]
274+
internal enum FileTypeSet : long
275+
{
276+
/// <summary>
277+
/// File type set that includes I386, IA64 and AMD64 Portable Executable (PE) files. Others are treated as raw.
278+
/// </summary>
279+
Executables = 0x0FL,
280+
}
281+
282+
/// <remarks>
283+
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#deltaflagtypeflags
284+
/// </remarks>
285+
internal enum CreateFlags : long
286+
{
287+
/// <summary>Indicates no special handling.</summary>
288+
None = 0,
289+
290+
/// <summary>Allow the source, target and delta files to exceed the default size limit.</summary>
291+
IgnoreFileSizeLimit = 1 << 17,
292+
}
293+
294+
/// <remarks>
295+
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#deltainputstructure
296+
/// </remarks>
297+
[StructLayout(LayoutKind.Sequential)]
298+
internal struct DeltaInput
299+
{
300+
/// <summary>Memory address non-editable input buffer.</summary>
301+
public IntPtr Start;
302+
303+
/// <summary>Size of the memory buffer in bytes.</summary>
304+
public IntPtr Size;
305+
306+
/// <summary>
307+
/// Defines whether MSDelta is allowed to edit the input buffer. If you make the input editable, the buffer will
308+
/// be zeroed at function return. However this will cause most MSDelta functions to use less memory.
309+
/// </summary>
310+
[MarshalAs(UnmanagedType.Bool)] public bool Editable;
311+
}
312+
313+
internal enum HashAlgId
314+
{
315+
/// <summary>No signature.</summary>
316+
None = 0,
317+
318+
/// <summary>32-bit CRC defined in msdelta.dll.</summary>
319+
Crc32 = 32,
320+
}
199321
}

src/Squirrel/Squirrel.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<PropertyGroup>
55
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
6+
<LangVersion>9</LangVersion>
67
<Description>Squirrel</Description>
78
<Title>Squirrel</Title>
89
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -13,7 +14,6 @@
1314
</ItemGroup>
1415

1516
<ItemGroup>
16-
<PackageReference Include="DeltaCompressionDotNet" Version="2.0.0" NoWarn="NU1701" />
1717
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
1818
<PackageReference Include="Microsoft.Web.Xdt" Version="3.1.0" />
1919
<PackageReference Include="Mono.Cecil" Version="0.11.2" />

src/Update/Update-Mono.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
3535
<PostBuildEvent>
3636
cd "$(TargetDir)"
37-
"$(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
37+
"$(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
3838
del "$(TargetFileName)"
3939
ren "$(TargetFileName).tmp" "$(TargetFileName)"
4040
</PostBuildEvent>

src/Update/Update.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
3434
<PostBuildEvent>
3535
cd "$(TargetDir)"
36-
"$(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
36+
"$(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
3737
del "$(TargetFileName)"
3838
ren "$(TargetFileName).tmp" "$(TargetFileName)"
3939
</PostBuildEvent>

0 commit comments

Comments
 (0)